strong_parameters 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -50,4 +50,4 @@ every model you want protected.
50
50
 
51
51
  == Compatibility
52
52
 
53
- Due to a testing issue, this plugin is only fully compatible with rails/3-2-stable rev 275ee0dc7b and forward as well as rails/master rev b49a7ddce1 and forward.
53
+ This plugin is only fully compatible with Rails versions 3.1 and 3.2 but not 4.0+, as it is part of Rails Core in 4.0.
@@ -22,6 +22,11 @@ module ActionController
22
22
  end
23
23
 
24
24
  def permit!
25
+ each_pair do |key, value|
26
+ convert_hashes_to_parameters(key, value)
27
+ self[key].permit! if self[key].respond_to? :permit!
28
+ end
29
+
25
30
  @permitted = true
26
31
  self
27
32
  end
@@ -39,6 +44,7 @@ module ActionController
39
44
  case filter
40
45
  when Symbol, String then
41
46
  params[filter] = self[filter] if has_key?(filter)
47
+ keys.grep(/\A#{Regexp.escape(filter)}\(\d+[if]?\)\z/).each { |key| params[key] = self[key] }
42
48
  when Hash then
43
49
  self.slice(*filter.keys).each do |key, value|
44
50
  return unless value
@@ -80,6 +86,17 @@ module ActionController
80
86
  end
81
87
  end
82
88
 
89
+ protected
90
+ def convert_value(value)
91
+ if value.class == Hash
92
+ self.class.new_from_hash_copying_default(value)
93
+ elsif value.is_a?(Array)
94
+ value.dup.replace(value.map { |e| convert_value(e) })
95
+ else
96
+ value
97
+ end
98
+ end
99
+
83
100
  private
84
101
  def convert_hashes_to_parameters(key, value)
85
102
  if value.is_a?(Parameters) || !value.is_a?(Hash)
@@ -1,3 +1,3 @@
1
1
  module StrongParameters
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -8,6 +8,7 @@ class StrongParametersControllerGeneratorTest < Rails::Generators::TestCase
8
8
  setup :prepare_destination
9
9
 
10
10
  def test_controller_content
11
+ Rails.stubs(:application).returns(nil)
11
12
  run_generator
12
13
 
13
14
  assert_file "app/controllers/users_controller.rb" do |content|
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+ require 'action_controller/parameters'
3
+
4
+ class MultiParameterAttributesTest < ActiveSupport::TestCase
5
+ test "permitted multi-parameter attribute keys" do
6
+ params = ActionController::Parameters.new({
7
+ book: {
8
+ "shipped_at(1i)" => "2012",
9
+ "shipped_at(2i)" => "3",
10
+ "shipped_at(3i)" => "25",
11
+ "shipped_at(4i)" => "10",
12
+ "shipped_at(5i)" => "15",
13
+ "published_at(1i)" => "1999",
14
+ "published_at(2i)" => "2",
15
+ "published_at(3i)" => "5",
16
+ "price(1)" => "R$",
17
+ "price(2f)" => "2.02"
18
+ }
19
+ })
20
+
21
+ permitted = params.permit book: [ :shipped_at, :price ]
22
+
23
+ assert permitted.permitted?
24
+
25
+ assert_equal "2012", permitted[:book]["shipped_at(1i)"]
26
+ assert_equal "3", permitted[:book]["shipped_at(2i)"]
27
+ assert_equal "25", permitted[:book]["shipped_at(3i)"]
28
+ assert_equal "10", permitted[:book]["shipped_at(4i)"]
29
+ assert_equal "15", permitted[:book]["shipped_at(5i)"]
30
+
31
+ assert_equal "R$", permitted[:book]["price(1)"]
32
+ assert_equal "2.02", permitted[:book]["price(2f)"]
33
+
34
+ assert_nil permitted[:book]["published_at(1i)"]
35
+ assert_nil permitted[:book]["published_at(2i)"]
36
+ assert_nil permitted[:book]["published_at(3i)"]
37
+ end
38
+ end
39
+
@@ -58,4 +58,11 @@ class ParametersTaintTest < ActiveSupport::TestCase
58
58
  @params.permit!
59
59
  assert_equal @params.permitted?, @params.dup.permitted?
60
60
  end
61
+
62
+ test "permit is recursive" do
63
+ @params.permit!
64
+ assert @params.permitted?
65
+ assert @params[:person].permitted?
66
+ assert @params[:person][:name].permitted?
67
+ end
61
68
  end
data/test/test_helper.rb CHANGED
@@ -3,6 +3,7 @@ ENV["RAILS_ENV"] = "test"
3
3
 
4
4
  require 'test/unit'
5
5
  require 'strong_parameters'
6
+ require 'mocha'
6
7
 
7
8
  module ActionController
8
9
  SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strong_parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,44 +9,75 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-21 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
16
- requirement: &2164465820 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.2.0
21
+ version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2164465820
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activemodel
27
- requirement: &2164465300 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
- - - ! '>='
35
+ - - ~>
31
36
  - !ruby/object:Gem::Version
32
- version: 3.2.0
37
+ version: '3.1'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2164465300
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.1'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: railties
38
- requirement: &2164464820 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
- - - ! '>='
51
+ - - ~>
42
52
  - !ruby/object:Gem::Version
43
- version: 3.2.0
53
+ version: '3.1'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *2164464820
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rake
49
- requirement: &2164464440 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: mocha
80
+ requirement: !ruby/object:Gem::Requirement
50
81
  none: false
51
82
  requirements:
52
83
  - - ! '>='
@@ -54,7 +85,12 @@ dependencies:
54
85
  version: '0'
55
86
  type: :development
56
87
  prerelease: false
57
- version_requirements: *2164464440
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
58
94
  description:
59
95
  email:
60
96
  - david@heinemeierhansson.com
@@ -77,6 +113,7 @@ files:
77
113
  - test/action_controller_tainted_params_test.rb
78
114
  - test/active_model_mass_assignment_taint_protection_test.rb
79
115
  - test/controller_generator_test.rb
116
+ - test/multi_parameter_attributes_test.rb
80
117
  - test/nested_parameters_test.rb
81
118
  - test/parameters_require_test.rb
82
119
  - test/parameters_taint_test.rb
@@ -101,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
138
  version: '0'
102
139
  requirements: []
103
140
  rubyforge_project:
104
- rubygems_version: 1.8.7
141
+ rubygems_version: 1.8.23
105
142
  signing_key:
106
143
  specification_version: 3
107
144
  summary: Permitted and required parameters for Action Pack
@@ -110,6 +147,7 @@ test_files:
110
147
  - test/action_controller_tainted_params_test.rb
111
148
  - test/active_model_mass_assignment_taint_protection_test.rb
112
149
  - test/controller_generator_test.rb
150
+ - test/multi_parameter_attributes_test.rb
113
151
  - test/nested_parameters_test.rb
114
152
  - test/parameters_require_test.rb
115
153
  - test/parameters_taint_test.rb