Scope request parameters according to Rails version
This commit is contained in:
parent
8406964654
commit
ce9624b3c5
|
@ -250,7 +250,12 @@ module Shoulda
|
||||||
parameters_double_registry.register
|
parameters_double_registry.register
|
||||||
|
|
||||||
Doublespeak.with_doubles_activated do
|
Doublespeak.with_doubles_activated do
|
||||||
context.__send__(verb, action, request_params)
|
Shoulda::Matchers::RailsShim.make_controller_request(
|
||||||
|
context,
|
||||||
|
verb,
|
||||||
|
action,
|
||||||
|
request_params,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
unpermitted_parameter_names.empty?
|
unpermitted_parameter_names.empty?
|
||||||
|
|
|
@ -7,6 +7,10 @@ module Shoulda
|
||||||
Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
|
Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def action_pack_gte_5?
|
||||||
|
Gem::Requirement.new('>= 5').satisfied_by?(action_pack_version)
|
||||||
|
end
|
||||||
|
|
||||||
def action_pack_version
|
def action_pack_version
|
||||||
Gem::Version.new(::ActionPack::VERSION::STRING)
|
Gem::Version.new(::ActionPack::VERSION::STRING)
|
||||||
end
|
end
|
||||||
|
@ -43,7 +47,7 @@ module Shoulda
|
||||||
|
|
||||||
def make_controller_request(context, verb, action, request_params)
|
def make_controller_request(context, verb, action, request_params)
|
||||||
params =
|
params =
|
||||||
if active_record_major_version >= 5
|
if action_pack_gte_5?
|
||||||
{ params: request_params }
|
{ params: request_params }
|
||||||
else
|
else
|
||||||
request_params
|
request_params
|
||||||
|
@ -123,17 +127,6 @@ module Shoulda
|
||||||
I18n.translate(primary_translation_key, translate_options)
|
I18n.translate(primary_translation_key, translate_options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.make_controller_request(context, verb, action, request_params)
|
|
||||||
params =
|
|
||||||
if active_record_major_version >= 5
|
|
||||||
{ params: request_params }
|
|
||||||
else
|
|
||||||
request_params
|
|
||||||
end
|
|
||||||
|
|
||||||
context.__send__(verb, action, params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
module UnitTests
|
||||||
|
module ActionPackVersions
|
||||||
|
extend self
|
||||||
|
|
||||||
|
def self.configure_example_group(example_group)
|
||||||
|
example_group.include(self)
|
||||||
|
example_group.extend(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
def action_pack_gte_5?
|
||||||
|
action_pack_version =~ '>= 5'
|
||||||
|
end
|
||||||
|
|
||||||
|
def action_pack_version
|
||||||
|
Tests::Version.new(ActionPack::VERSION::STRING)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -498,7 +498,12 @@ describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller d
|
||||||
|
|
||||||
matcher.matches?(controller)
|
matcher.matches?(controller)
|
||||||
|
|
||||||
expect(context).to have_received(:post).with(:create, {})
|
expect_to_have_made_controller_request(
|
||||||
|
verb: :post,
|
||||||
|
action: :create,
|
||||||
|
params: {},
|
||||||
|
context: context,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -511,7 +516,12 @@ describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller d
|
||||||
|
|
||||||
matcher.matches?(controller)
|
matcher.matches?(controller)
|
||||||
|
|
||||||
expect(context).to have_received(:patch).with(:update, {})
|
expect_to_have_made_controller_request(
|
||||||
|
verb: :patch,
|
||||||
|
action: :update,
|
||||||
|
params: {},
|
||||||
|
context: context,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
it 'PUTs to the controller' do
|
it 'PUTs to the controller' do
|
||||||
|
@ -521,7 +531,12 @@ describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller d
|
||||||
|
|
||||||
matcher.matches?(controller)
|
matcher.matches?(controller)
|
||||||
|
|
||||||
expect(context).to have_received(:put).with(:update, {})
|
expect_to_have_made_controller_request(
|
||||||
|
verb: :put,
|
||||||
|
action: :update,
|
||||||
|
params: {},
|
||||||
|
context: context,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -536,7 +551,12 @@ describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller d
|
||||||
|
|
||||||
matcher.matches?(controller)
|
matcher.matches?(controller)
|
||||||
|
|
||||||
expect(context).to have_received(:delete).with(:hide, {})
|
expect_to_have_made_controller_request(
|
||||||
|
verb: :delete,
|
||||||
|
action: :hide,
|
||||||
|
params: {},
|
||||||
|
context: context,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -598,4 +618,12 @@ describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller d
|
||||||
def build_context
|
def build_context
|
||||||
double('context', post: nil, put: nil, patch: nil, delete: nil)
|
double('context', post: nil, put: nil, patch: nil, delete: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expect_to_have_made_controller_request(context:, verb:, action:, params:)
|
||||||
|
if action_pack_gte_5?
|
||||||
|
expect(context).to have_received(verb).with(action, params: params)
|
||||||
|
else
|
||||||
|
expect(context).to have_received(verb).with(action, params)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@ Dir[ File.join(File.expand_path('../support/unit/**/*.rb', __FILE__)) ].sort.eac
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
UnitTests::ActionPackVersions.configure_example_group(config)
|
||||||
UnitTests::ActiveModelHelpers.configure_example_group(config)
|
UnitTests::ActiveModelHelpers.configure_example_group(config)
|
||||||
UnitTests::ActiveModelVersions.configure_example_group(config)
|
UnitTests::ActiveModelVersions.configure_example_group(config)
|
||||||
UnitTests::ClassBuilder.configure_example_group(config)
|
UnitTests::ClassBuilder.configure_example_group(config)
|
||||||
|
|
Loading…
Reference in New Issue