diff --git a/Gemfile b/Gemfile index 4194a1caad..8dfe608c04 100644 --- a/Gemfile +++ b/Gemfile @@ -212,9 +212,9 @@ group :test do gem 'rspec_api_documentation' gem 'rspec-html-matchers', github: '3scale/rspec-html-matchers', branch: 'fix/rspec-3-with-xml-document', require: false - gem 'shoulda', '~> 3.5.0', require: false - gem 'shoulda-context', '~> 1.2.2' - gem 'shoulda-matchers', '~> 2.8.0' + gem 'shoulda', '~> 4.0.0' + gem 'shoulda-context', '~> 2.0.0' + gem 'shoulda-matchers', '~> 4.5.1' gem 'timecop', '~> 0.9' gem 'ci_reporter_shell', github: '3scale/ci_reporter_shell', require: false diff --git a/Gemfile.lock b/Gemfile.lock index c3b9767f13..4591d18cb7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1810,12 +1810,12 @@ GEM selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) - shoulda (3.5.0) - shoulda-context (~> 1.0, >= 1.0.1) - shoulda-matchers (>= 1.4.1, < 3.0) - shoulda-context (1.2.2) - shoulda-matchers (2.8.0) - activesupport (>= 3.0.0) + shoulda (4.0.0) + shoulda-context (~> 2.0) + shoulda-matchers (~> 4.0) + shoulda-context (2.0.0) + shoulda-matchers (4.5.1) + activesupport (>= 4.2.0) sidekiq (5.2.9) connection_pool (~> 2.2, >= 2.2.2) rack (~> 2.0) @@ -2108,9 +2108,9 @@ DEPENDENCIES sass-rails (~> 5.0) secure_headers (~> 6.3.0) selenium-webdriver (~> 3.142) - shoulda (~> 3.5.0) - shoulda-context (~> 1.2.2) - shoulda-matchers (~> 2.8.0) + shoulda (~> 4.0.0) + shoulda-context (~> 2.0.0) + shoulda-matchers (~> 4.5.1) sidekiq (< 6) sidekiq-batch (~> 0.1.6) sidekiq-cron diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index fa664629a1..27853f498b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -146,3 +146,10 @@ config.curl_host = 'http://localhost:3000' config.api_name = "Example App API" end + +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end diff --git a/test/functional/partners/providers_controller_test.rb b/test/functional/partners/providers_controller_test.rb index 18a6d5e5ce..16076b124b 100644 --- a/test/functional/partners/providers_controller_test.rb +++ b/test/functional/partners/providers_controller_test.rb @@ -2,8 +2,6 @@ class Partners::ProvidersControllerTest < ActionController::TestCase - should route(:post, "http://#{master_account.domain}/partners/providers").to(action: 'create', format: :json) - def setup @request.host = master_account.domain @partner = FactoryBot.create(:partner, system_name: 'someone') @@ -23,6 +21,11 @@ def provider_params {subdomain: 'troloro', org_name: 'foo-org', email: 'foo@example.net', first_name: 'Tyler', last_name: 'Durden', api_key: @partner.api_key, open_id: "openid"} end + test 'should route partners/providers to correct controller' do + assert_routing({ method: :post, path: "http://#{master_account.domain}/partners/providers" }, + { action: 'create', format: 'json', controller: 'partners/providers' }) + end + test 'required api_key' do post :create assert_response :unauthorized diff --git a/test/monkey_patches/route_params.rb b/test/monkey_patches/route_params.rb new file mode 100644 index 0000000000..b999969c2f --- /dev/null +++ b/test/monkey_patches/route_params.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# TODO: remove when you see similar error but actual format is: "format"=>:json +# PARAMS_TO_SYMBOLIZE causes errors in the tests regarding the format. +# It always converts format to symbol which causes a failure in the tests: +# Stats::Api::ApplicationsController should route GET /stats/api/applications/42/usage.json +# --- expected +# +++ actual +# @@ -1 +1 @@ +# -{"application_id"=>"42", "action"=>"usage", "format"=>:json, "controller"=>"stats/api/applications"} +# +{"controller"=>"stats/api/applications", "action"=>"usage", "application_id"=>"42", "format"=>"json"} +module Shoulda + module Matchers + module ActionController + class RouteParams + PARAMS_TO_SYMBOLIZE = [].freeze + end + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 33a9314cb4..cc279801cb 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -50,6 +50,7 @@ WebMock.disable_net_connect! require 'monkey_patches/active_job_test_helper' +require 'monkey_patches/route_params' class ActiveSupport::TestCase self.use_transactional_tests = true self.use_instantiated_fixtures = false @@ -86,3 +87,10 @@ def teardown include TestHelpers::SectionsPermissions ActiveJob::Uniqueness.test_mode! + +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :minitest + with.library :rails + end +end \ No newline at end of file