From 373540f4cfa37d1a351b5446368aa4ff64b68ba6 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sat, 5 Nov 2016 00:23:02 +0100 Subject: [PATCH] fix specs for rails 5 --- .rubocop.yml | 3 --- .../fetch_controller_spec.rb | 8 +++--- .../h_card_controller_spec.rb | 10 ++++---- .../receive_controller_spec.rb | 25 +++++++++++-------- .../webfinger_controller_spec.rb | 10 ++++---- test/dummy/config/application.rb | 3 --- test/dummy/config/environments/test.rb | 4 +-- test/dummy/config/logging.rb | 8 ++++++ 8 files changed, 39 insertions(+), 32 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8b668f5..21c71a7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -183,6 +183,3 @@ Style/NumericPredicate: Style/FrozenStringLiteralComment: Enabled: false - -Rails/HttpPositionalArguments: - Enabled: false diff --git a/spec/controllers/diaspora_federation/fetch_controller_spec.rb b/spec/controllers/diaspora_federation/fetch_controller_spec.rb index 972701c..e9c35dc 100644 --- a/spec/controllers/diaspora_federation/fetch_controller_spec.rb +++ b/spec/controllers/diaspora_federation/fetch_controller_spec.rb @@ -10,7 +10,7 @@ module DiasporaFederation expect_callback(:fetch_public_entity, "StatusMessage", guid).and_return(post) expect_callback(:fetch_private_key, alice.diaspora_id).and_return(alice.private_key) - get :fetch, type: "status_message", guid: guid + get :fetch, params: {type: "status_message", guid: guid} expect_callback(:fetch_public_key, alice.diaspora_id).and_return(alice.public_key) @@ -29,7 +29,7 @@ module DiasporaFederation expect_callback(:fetch_public_entity, "Post", guid).and_return(post) expect_callback(:fetch_private_key, alice.diaspora_id).and_return(alice.private_key) - get :fetch, type: "post", guid: guid + get :fetch, params: {type: "post", guid: guid} expect_callback(:fetch_public_key, alice.diaspora_id).and_return(alice.public_key) @@ -50,7 +50,7 @@ module DiasporaFederation expect_callback(:fetch_person_url_to, alice.diaspora_id, "/fetch/post/#{guid}") .and_return("http://example.org/fetch/post/#{guid}") - get :fetch, type: "post", guid: guid + get :fetch, params: {type: "post", guid: guid} expect(response).to be_redirect expect(response).to redirect_to "http://example.org/fetch/post/#{guid}" @@ -59,7 +59,7 @@ module DiasporaFederation it "404s when the post does not exist" do expect_callback(:fetch_public_entity, "Post", guid).and_return(nil) - get :fetch, type: "post", guid: guid + get :fetch, params: {type: "post", guid: guid} expect(response.status).to eq(404) end diff --git a/spec/controllers/diaspora_federation/h_card_controller_spec.rb b/spec/controllers/diaspora_federation/h_card_controller_spec.rb index 113150a..c6c6342 100644 --- a/spec/controllers/diaspora_federation/h_card_controller_spec.rb +++ b/spec/controllers/diaspora_federation/h_card_controller_spec.rb @@ -4,30 +4,30 @@ module DiasporaFederation describe "GET #hcard" do it "succeeds when the person exists", fixture: true do - get :hcard, "guid" => alice.guid + get :hcard, params: {guid: alice.guid} expect(response).to be_success save_fixture(response.body, "hcard") end it "contains the guid" do - get :hcard, "guid" => alice.guid + get :hcard, params: {guid: alice.guid} expect(response.body).to include "#{alice.guid}" end it "contains the username" do - get :hcard, "guid" => alice.guid + get :hcard, params: {guid: alice.guid} expect(response.body).to include "alice" end it "404s when the person does not exist" do - get :hcard, "guid" => "unknown_guid" + get :hcard, params: {guid: "unknown_guid"} expect(response).to be_not_found end it "calls the fetch_person_for_hcard callback" do expect_callback(:fetch_person_for_hcard, alice.guid).and_call_original - get :hcard, "guid" => alice.guid + get :hcard, params: {guid: alice.guid} end end end diff --git a/spec/controllers/diaspora_federation/receive_controller_spec.rb b/spec/controllers/diaspora_federation/receive_controller_spec.rb index b349c1a..281319e 100644 --- a/spec/controllers/diaspora_federation/receive_controller_spec.rb +++ b/spec/controllers/diaspora_federation/receive_controller_spec.rb @@ -18,26 +18,27 @@ module DiasporaFederation it "returns a 202 if queued correctly" do expect_callback(:queue_public_receive, "", true) - post :public, xml: "" + post :public, params: {xml: ""} expect(response.code).to eq("202") end it "unescapes the xml before sending it to the callback" do expect_callback(:queue_public_receive, "", true) - post :public, xml: CGI.escape("") + post :public, params: {xml: CGI.escape("")} end end context "magic envelope" do before do + Mime::Type.register("application/magic-envelope+xml", :magic_envelope) @request.env["CONTENT_TYPE"] = "application/magic-envelope+xml" end it "returns a 202 if queued correctly" do expect_callback(:queue_public_receive, "", false) - post :public, "" + post :public, body: "" expect(response.code).to eq("202") end end @@ -48,32 +49,32 @@ module DiasporaFederation it "return a 404 if not queued successfully (unknown user guid)" do expect_callback(:queue_private_receive, "any-guid", "", true).and_return(false) - post :private, guid: "any-guid", xml: "" + post :private, params: {guid: "any-guid", xml: ""} expect(response.code).to eq("404") end it "returns a 422 if no xml is passed" do - post :private, guid: "any-guid" + post :private, params: {guid: "any-guid"} expect(response.code).to eq("422") end it "returns a 422 if no xml is passed with content-type application/x-www-form-urlencoded" do @request.env["CONTENT_TYPE"] = "application/x-www-form-urlencoded" - post :private, guid: "any-guid" + post :private, params: {guid: "any-guid"} expect(response.code).to eq("422") end it "returns a 202 if the callback returned true" do expect_callback(:queue_private_receive, "any-guid", "", true).and_return(true) - post :private, guid: "any-guid", xml: "" + post :private, params: {guid: "any-guid", xml: ""} expect(response.code).to eq("202") end it "unescapes the xml before sending it to the callback" do expect_callback(:queue_private_receive, "any-guid", "", true).and_return(true) - post :private, guid: "any-guid", xml: CGI.escape("") + post :private, params: {guid: "any-guid", xml: CGI.escape("")} end end @@ -87,7 +88,9 @@ module DiasporaFederation :queue_private_receive, "any-guid", "{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", false ).and_return(false) - post :private, "{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", guid: "any-guid" + post :private, + body: "{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", + params: {guid: "any-guid"} expect(response.code).to eq("404") end @@ -96,7 +99,9 @@ module DiasporaFederation :queue_private_receive, "any-guid", "{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", false ).and_return(true) - post :private, "{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", guid: "any-guid" + post :private, + body: "{\"aes_key\": \"key\", \"encrypted_magic_envelope\": \"env\"}", + params: {guid: "any-guid"} expect(response.code).to eq("202") end end diff --git a/spec/controllers/diaspora_federation/webfinger_controller_spec.rb b/spec/controllers/diaspora_federation/webfinger_controller_spec.rb index 38577ad..159cfc2 100644 --- a/spec/controllers/diaspora_federation/webfinger_controller_spec.rb +++ b/spec/controllers/diaspora_federation/webfinger_controller_spec.rb @@ -38,30 +38,30 @@ module DiasporaFederation describe "GET #legacy_webfinger" do it "succeeds when the person exists", fixture: true do - get :legacy_webfinger, "q" => "alice@localhost:3000" + get :legacy_webfinger, params: {q: "alice@localhost:3000"} expect(response).to be_success save_fixture(response.body, "legacy-webfinger") end it "succeeds with 'acct:' in the query when the person exists" do - get :legacy_webfinger, "q" => "acct:alice@localhost:3000" + get :legacy_webfinger, params: {q: "acct:alice@localhost:3000"} expect(response).to be_success end it "contains the diaspora* ID" do - get :legacy_webfinger, "q" => "acct:alice@localhost:3000" + get :legacy_webfinger, params: {q: "acct:alice@localhost:3000"} expect(response.body).to include "acct:alice@localhost:3000" end it "404s when the person does not exist" do - get :legacy_webfinger, "q" => "me@mydiaspora.pod.com" + get :legacy_webfinger, params: {q: "me@mydiaspora.pod.com"} expect(response).to be_not_found end it "calls the fetch_person_for_webfinger callback" do expect_callback(:fetch_person_for_webfinger, "alice@localhost:3000").and_call_original - get :legacy_webfinger, "q" => "acct:alice@localhost:3000" + get :legacy_webfinger, params: {q: "acct:alice@localhost:3000"} end end end diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 3ed4cd3..b29a7e8 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -22,9 +22,6 @@ module Dummy # Version of your assets, change this if you want to expire all your assets config.assets.version = "1.0" - # Do not swallow errors in after_commit/after_rollback callbacks. - config.active_record.raise_in_transactional_callbacks = true - # autoload files from test/dummy/lib config.autoload_once_paths += %W(#{config.root}/lib) end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index ab4b822..b5052f0 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -13,8 +13,8 @@ Rails.application.configure do config.eager_load = false # Configure static file server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = "public, max-age=3600" + config.public_file_server.enable = true + config.public_file_server.headers = {"Cache-Control" => "public, max-age=3600"} # Show full error reports and disable caching. config.consider_all_requests_local = true diff --git a/test/dummy/config/logging.rb b/test/dummy/config/logging.rb index 109a20a..fb4b258 100644 --- a/test/dummy/config/logging.rb +++ b/test/dummy/config/logging.rb @@ -79,3 +79,11 @@ Logging::Rails.configure do |config| Logging.logger[ActiveRecord::Base].level = :debug Logging.logger["XMLLogger"].level = :debug end + +module ActiveSupport + module Dependencies + def self.logger=(_) + # This was remove in rails 5: https://github.com/rails/rails/commit/798dc5a92537ba4202a1a8e127a5ebdae87bc78d + end + end +end