diff --git a/config/application.rb b/config/application.rb index 3772825d5..87498fa4d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -56,5 +56,6 @@ module Diaspora config.filter_parameters += [:text] config.filter_parameters += [:caption] config.filter_parameters += [:bio] + end end diff --git a/config/cucumber.yml b/config/cucumber.yml index 621a14cea..f13837205 100644 --- a/config/cucumber.yml +++ b/config/cucumber.yml @@ -3,6 +3,6 @@ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip" %> -default: <%= std_opts %> features -wip: --tags @wip:3 --wip features +default: <%= std_opts %> -r features +wip: -r features --tags @wip:3 --wip features rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip diff --git a/config/environment.rb b/config/environment.rb index 0586220b5..402354a1c 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -6,6 +6,7 @@ require File.expand_path('../application', __FILE__) Haml::Template.options[:format] = :html5 Haml::Template.options[:escape_html] = true +ActionController::Base.config.relative_url_root = "/daspora" if File.exists?(File.expand_path("./config/languages.yml")) languages = YAML::load(File.open(File.expand_path("./config/languages.yml"))) @@ -24,6 +25,7 @@ else LANGUAGE_CODES_MAP = {} end +#config.action_controller.relative_url_root = "/diaspora" + # Initialize the rails application Diaspora::Application.initialize! - diff --git a/features/step_definitions/uri-step.rb b/features/step_definitions/uri-step.rb new file mode 100644 index 000000000..02aa4064e --- /dev/null +++ b/features/step_definitions/uri-step.rb @@ -0,0 +1,33 @@ +Given /^configuration parameter (\w+) is ([^ ]+)$/ do |key, value| + require Rails.root.join('config', "initializers", "_load_app_config.rb") + app_value = AppConfig[ key.to_sym] + assert_equal value, app_value, + "You must set #{key} to #{value} and kill running server" +end + +When /^I visit url ([^ ]+)$/ do |url| + visit( url) +end + +Then /^I should find '([^']*)' in ([^ ]+)$/ do |pattern,file| + found = %x!fgrep -o #{pattern} #{file}! + assert_equal pattern, found.chomp, "Can't find pattern in #{file}" +end + +Then /^I should match '([^']*)' in ([^ ]+)$/ do |pattern,file| + found = `egrep -o '#{pattern}' #{file}` + assert_match /#{pattern}/, found.chomp, "Can't find #{pattern} in #{file}" +end + +When /^I retrieve ([^ ]+) into ([^ ]+)$/ do |url,file| + system( "wget -q -O #{file} #{url}") +end + +Then /^a page\-asset should be ([^ ]+)$/ do |asset_path| + page.has_content?(asset_path) +end + + + + + diff --git a/features/support/env.rb b/features/support/env.rb index 0e70c173d..f5a338cd1 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -71,3 +71,14 @@ Before do UserFixer.regenerate_user_fixtures UserFixer.load_user_fixtures end + +Before('@localserver') do + TestServerFixture.start_if_needed + CapybaraSettings.instance.save + Capybara.current_driver = :selenium + Capybara.run_server = false +end + +After('@localserver') do + CapybaraSettings.instance.restore +end diff --git a/features/support/server.rb b/features/support/server.rb new file mode 100644 index 000000000..8a9cf5c9a --- /dev/null +++ b/features/support/server.rb @@ -0,0 +1,73 @@ + +ENV["RAILS_ENV"] ||= "test" +require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') + +require 'timeout' +require 'socket' +require 'singleton' + +require 'capybara/rails' +require 'capybara/cucumber' +require 'capybara/session' + +class TestServerFixture +# simple interface to script/server + + def self.is_port_open(host, port, tries) + for i in (1..tries) + begin + Timeout::timeout(2) do + begin + s = TCPSocket.new(host, port) + s.close + return true + rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH + sleep( 2) + end + end + rescue Timeout::Error + return false + end + end + return false + end + + def self.start_if_needed + unless TestServerFixture.is_port_open( "localhost", 3000, 2) + system( "script/server -d") + if TestServerFixture.is_port_open( "localhost", 3000, 30) + puts "script/server started" + else + puts "Error: can't start script/server" + end + end + end + +end + +class CapybaraSettings +# simple save/restore for Capybara + + include Singleton + + def save + begin + @run_server = Capybara.run_server + @driver = Capybara.current_driver + @host = Capybara.app_host + rescue => e + puts "Saving exception: " + e.inspect + end + end + + def restore + begin + Capybara.current_driver = @driver + Capybara.app_host = @host + Capybara.run_server = @run_server + rescue => e + puts "Restore exception: " + e.inspect + end + end + +end diff --git a/features/uri-tests/uri.feature b/features/uri-tests/uri.feature new file mode 100644 index 000000000..124dc821a --- /dev/null +++ b/features/uri-tests/uri.feature @@ -0,0 +1,19 @@ +@localserver +Feature: Flexible uri deployment + To make it possible to use Diaspora on small home servers, + which might house also other sw, it should be possible to deploy + diaspora on a sub-uri such as http://example.org/diaspora. + + Scenario: Serve webfinger request + Given configuration parameter pod_url is http://localhost:3000/diaspora + When I retrieve http://localhost:3000/.well-known/host-meta into tmp/host-meta + Then I should find 'http://localhost:3000/diaspora/webfinger?q={uri}' in tmp/host-meta + + Scenario: Present application to user + Given configuration parameter pod_url is http://localhost:3000/diaspora + When I visit url http://localhost:3000/diaspora + And I retrieve http://localhost:3000/diaspora into tmp/index.html + Then I should see "put something in" + And a page-asset should be http://localhost:3000/diaspora/stylesheets/ui.css + And I should match 'http://localhost:3000/diaspora/stylesheets/blueprint/print.css.[0-9]+"' in tmp/index.html + diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake index 92c0a8d26..244b948c2 100644 --- a/lib/tasks/cucumber.rake +++ b/lib/tasks/cucumber.rake @@ -18,6 +18,7 @@ begin t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. t.fork = true # You may get faster startup if you set this to false t.profile = 'default' + t.cucumber_opts = "features --exclude features/uri-tests/*" end Cucumber::Rake::Task.new(:wip, 'Run features that are being worked on') do |t|