diff --git a/.rubocop.yml b/.rubocop.yml index 21c71a7..39a64ee 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -183,3 +183,7 @@ Style/NumericPredicate: Style/FrozenStringLiteralComment: Enabled: false + +Rails/HttpPositionalArguments: + Exclude: + - "spec/controllers/diaspora_federation/fixtures_rails4_spec.rb" diff --git a/.travis.yml b/.travis.yml index 1568c6f..ffd4f39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: ruby rvm: - 2.3.1 - 2.2.5 + - 2.1 sudo: false cache: @@ -13,7 +14,7 @@ branches: - 'master' - 'develop' -before_install: gem install bundler +before_install: test/scripts/prepare-travis.sh bundler_args: "--deployment --without development --jobs=3 --retry=3" -script: bundle exec rake --trace +script: test/scripts/travis.sh diff --git a/lib/tasks/rails4.rake b/lib/tasks/rails4.rake new file mode 100644 index 0000000..fcae71e --- /dev/null +++ b/lib/tasks/rails4.rake @@ -0,0 +1,15 @@ +if defined?(RSpec) + namespace :rails4 do + desc "Run all specs that generate fixtures for rspec with rails 4" + RSpec::Core::RakeTask.new(:generate_fixtures) do |t| + t.rspec_opts = ["--tag fixture4"] + end + + desc "Run all specs in spec directory (exluding controller specs)" + RSpec::Core::RakeTask.new(:spec) do |task| + task.pattern = FileList["spec/**/*_spec.rb"].exclude("spec/controllers/**/*_spec.rb") + end + + task test: %w(spec:prepare_db generate_fixtures spec) + end +end diff --git a/spec/controllers/diaspora_federation/fixtures_rails4_spec.rb b/spec/controllers/diaspora_federation/fixtures_rails4_spec.rb new file mode 100644 index 0000000..26db5c8 --- /dev/null +++ b/spec/controllers/diaspora_federation/fixtures_rails4_spec.rb @@ -0,0 +1,21 @@ +module DiasporaFederation + describe WebfingerController, type: :controller do + routes { DiasporaFederation::Engine.routes } + + it "generates webfinger fixture", fixture4: true, rails4: true do + get :legacy_webfinger, q: "alice@localhost:3000" + expect(response).to be_success + save_fixture(response.body, "legacy-webfinger") + end + end + + describe HCardController, type: :controller do + routes { DiasporaFederation::Engine.routes } + + it "generates hcard fixture", fixture4: true, rails4: true do + get :hcard, guid: alice.guid + expect(response).to be_success + save_fixture(response.body, "hcard") + end + end +end diff --git a/spec/controllers/diaspora_federation/webfinger_controller_spec.rb b/spec/controllers/diaspora_federation/webfinger_controller_spec.rb index 159cfc2..b4fb5d7 100644 --- a/spec/controllers/diaspora_federation/webfinger_controller_spec.rb +++ b/spec/controllers/diaspora_federation/webfinger_controller_spec.rb @@ -8,7 +8,7 @@ module DiasporaFederation WebfingerController.instance_variable_set(:@host_meta_xml, nil) # clear cache end - it "succeeds", fixture: true do + it "succeeds", fixture: true, fixture4: true do get :host_meta expect(response).to be_success save_fixture(response.body, "host-meta") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 33dc68a..431d8f3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -66,6 +66,8 @@ RSpec.configure do |config| config.fixture_path = "#{::Rails.root}/test/fixtures" config.global_fixtures = :all + config.filter_run_excluding rails4: true if Rails::VERSION::MAJOR == 5 + # whitelist codeclimate.com so test coverage can be reported config.after(:suite) do WebMock.disable_net_connect!(allow: "codeclimate.com") diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index b5052f0..76daa24 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -13,8 +13,13 @@ Rails.application.configure do config.eager_load = false # Configure static file server for tests with Cache-Control for performance. - config.public_file_server.enable = true - config.public_file_server.headers = {"Cache-Control" => "public, max-age=3600"} + if Rails::VERSION::MAJOR == 5 + config.public_file_server.enable = true + config.public_file_server.headers = {"Cache-Control" => "public, max-age=3600"} + else + config.serve_static_files = true + config.static_cache_control = "public, max-age=3600" + end # Show full error reports and disable caching. config.consider_all_requests_local = true diff --git a/test/scripts/prepare-travis.sh b/test/scripts/prepare-travis.sh new file mode 100755 index 0000000..61449b7 --- /dev/null +++ b/test/scripts/prepare-travis.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -x + +gem install bundler + +if [[ ${TRAVIS_RUBY_VERSION} == "2.1" ]]; then + # use rails 4 for ruby 2.1, because rails 5 needs ruby >= 2.2.2 + echo "gem 'rails', '4.2.7.1'" >> Gemfile + bundle install --without development --jobs=3 --retry=3 + bundle update rails +fi diff --git a/test/scripts/travis.sh b/test/scripts/travis.sh new file mode 100755 index 0000000..7c28996 --- /dev/null +++ b/test/scripts/travis.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -x + +if [[ ${TRAVIS_RUBY_VERSION} == "2.1" ]]; then + # ruby 2.1 + export NO_COVERAGE="true" # No coverage for rails 4, because controller specs are disabled + bundle exec rake rails4:test --trace +else + # ruby >= 2.2 + bundle exec rake --trace +fi