Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Clear inflections after test.
  • Loading branch information
zuhao committed May 28, 2014
1 parent 0f80a52 commit 781f8a8
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions actionpack/test/controller/params_wrapper_test.rb
Expand Up @@ -337,14 +337,26 @@ def parse
tests ParamswrappernewsController

def test_uses_model_attribute_names_with_irregular_inflection
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'paramswrappernews_item', 'paramswrappernews'
end
with_dup do
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'paramswrappernews_item', 'paramswrappernews'
end

with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, { 'username' => 'sikachu', 'test_attr' => 'test_value' }
assert_parameters({ 'username' => 'sikachu', 'test_attr' => 'test_value', 'paramswrappernews_item' => { 'test_attr' => 'test_value' }})
with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, { 'username' => 'sikachu', 'test_attr' => 'test_value' }
assert_parameters({ 'username' => 'sikachu', 'test_attr' => 'test_value', 'paramswrappernews_item' => { 'test_attr' => 'test_value' }})
end
end
end

private

def with_dup
original = ActiveSupport::Inflector::Inflections.instance_variable_get(:@__instance__)[:en]
ActiveSupport::Inflector::Inflections.instance_variable_set(:@__instance__, en: original.dup)
yield
ensure
ActiveSupport::Inflector::Inflections.instance_variable_set(:@__instance__, en: original)
end
end

0 comments on commit 781f8a8

Please sign in to comment.