auto_strong_parameters 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/auto_strong_parameters/auto_form_params.rb +2 -1
- data/lib/auto_strong_parameters/auto_permit.rb +1 -1
- data/lib/auto_strong_parameters/version.rb +1 -1
- data/lib/auto_strong_parameters.rb +21 -14
- data/test/apps/basic_controller.rb +1 -0
- data/test/apps/user.rb +1 -1
- data/test/auto_form_params_test.rb +1 -0
- data/test/auto_strong_parameters_test.rb +41 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b7680411c579ad85825c31e55cb9e0e22fe2b6968a1ac47a9f4c2c5f06cd8b4
|
4
|
+
data.tar.gz: 3aaeb488a04aa4b2e8a38a85b5fc253e2ef9ed0d5e6711a1a9624b56de069e85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae5976a91ea2a2941ce5ebd71aa997042b37103a1fa01735a3211f725fe34a098e6098b67261170bd0309ba0a977ad9539d916c54499a1341200b6e5b072b496
|
7
|
+
data.tar.gz: 9e5c0ab8ce1774f750d6000d43b77c84a563764a0d0706df359ac11a3fed5beb5b00b488377abe4a2bd6372273f491493778ad781c149ef9e77b9a6093470c58
|
@@ -13,7 +13,8 @@ module AutoStrongParameters::AutoFormParams
|
|
13
13
|
TRACKED_FIELDS = %w(
|
14
14
|
search_field telephone_field date_field time_field datetime_field
|
15
15
|
month_field week_field url_field email_field number_field range_field
|
16
|
-
file_field password_field text_area text_field radio_button
|
16
|
+
file_field password_field text_area text_field radio_button phone_field
|
17
|
+
select
|
17
18
|
)
|
18
19
|
|
19
20
|
TRACKED_FIELDS.each do |name|
|
@@ -4,20 +4,6 @@ require 'rails'
|
|
4
4
|
require 'auto_strong_parameters/railtie'
|
5
5
|
|
6
6
|
module AutoStrongParameters
|
7
|
-
# Rails' message_verifier exists with a stable API in all versions of Rails
|
8
|
-
# since 4.2.
|
9
|
-
def self.verifier
|
10
|
-
@verifier ||=
|
11
|
-
ActiveSupport::MessageVerifier.new("auto_strong_parameters", serializer: JSON)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Provide your own custom verifier for AutoStrongParameters. Must respond to
|
15
|
-
# #generate which takes an object and returns a string and #verify which
|
16
|
-
# takes a string and returns an object.
|
17
|
-
def self.verifier=(custom_verifier)
|
18
|
-
@verifier = custom_verifier
|
19
|
-
end
|
20
|
-
|
21
7
|
def self.asp_message_key
|
22
8
|
@asp_message_key ||= :"_asp_params"
|
23
9
|
end
|
@@ -26,6 +12,14 @@ module AutoStrongParameters
|
|
26
12
|
@asp_message_key = val
|
27
13
|
end
|
28
14
|
|
15
|
+
def self.secret=(secret)
|
16
|
+
@secret = secret
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.secret
|
20
|
+
@secret ||= Rails.application.config.secret_key_base
|
21
|
+
end
|
22
|
+
|
29
23
|
def self.to_strong_params_shape(obj)
|
30
24
|
items = Set.new
|
31
25
|
hsh = {}
|
@@ -76,4 +70,17 @@ module AutoStrongParameters
|
|
76
70
|
nil
|
77
71
|
end
|
78
72
|
end
|
73
|
+
|
74
|
+
# Rails' message_verifier exists with a stable API in all versions of Rails
|
75
|
+
# since 4.2.
|
76
|
+
def self.verifier
|
77
|
+
@verifier ||= ActiveSupport::MessageVerifier.new(secret, serializer: JSON)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Provide your own custom verifier for AutoStrongParameters. Must respond to
|
81
|
+
# #generate which takes an object and returns a string and #verify which
|
82
|
+
# takes a string and returns an object.
|
83
|
+
def self.verifier=(custom_verifier)
|
84
|
+
@verifier = custom_verifier
|
85
|
+
end
|
79
86
|
end
|
@@ -17,6 +17,7 @@ class BasicController < ActionController::Base
|
|
17
17
|
<%= f.number_field :age %>
|
18
18
|
<%= f.range_field :years_of_experience %>
|
19
19
|
<%= f.password_field :password %>
|
20
|
+
<%= f.select :location, [['Home',1], ['Work', 2]] %>
|
20
21
|
<%= f.radio_button :preferred_phone_os, :iphone %>
|
21
22
|
<%= f.radio_button :preferred_phone_os, :android %>
|
22
23
|
<%= f.fields_for :parents do |parf| %>
|
data/test/apps/user.rb
CHANGED
@@ -3,7 +3,7 @@ class User
|
|
3
3
|
|
4
4
|
attr_accessor :name, :email, :description, :phone, :dob, :lunch_time,
|
5
5
|
:confirmed_at, :birth_month, :birthday_week, :favorite_url, :age,
|
6
|
-
:years_of_experience, :password, :preferred_phone_os
|
6
|
+
:years_of_experience, :password, :preferred_phone_os, :location
|
7
7
|
|
8
8
|
def parents
|
9
9
|
@parents ||= [Parent.new]
|
@@ -13,4 +13,45 @@ class AutoStrongParametersTest < Minitest::Test
|
|
13
13
|
assert_equal ["name", {"pet" => ["name"]}], to_strong_params_shape({"name" => "Steve", "pet" => { "name" => "Fluffy" }})
|
14
14
|
assert_equal ["name", {"pet" => ["name"]}], to_strong_params_shape({"name" => "Steve", "pet" => { "name" => "Fluffy" }})
|
15
15
|
end
|
16
|
+
|
17
|
+
def test_nested_params
|
18
|
+
params = {
|
19
|
+
"user"=>{
|
20
|
+
"first_name"=>"Steve",
|
21
|
+
"last_name"=>"Sample",
|
22
|
+
"email"=>"steve@example.com",
|
23
|
+
"phone"=>"(123) 234-2345",
|
24
|
+
"work_location"=>"Chicago",
|
25
|
+
"birth_date"=>"1980-01-01",
|
26
|
+
},
|
27
|
+
"address"=>{
|
28
|
+
"id"=>"7",
|
29
|
+
"street_address"=>"123 Example St",
|
30
|
+
"city"=>"Chicago",
|
31
|
+
"state"=>"IL",
|
32
|
+
"zip"=>"12345"
|
33
|
+
},
|
34
|
+
"emergency_contact"=>{
|
35
|
+
"id"=>"16",
|
36
|
+
"first_name"=>"Mary",
|
37
|
+
"last_name"=>"Example",
|
38
|
+
"phone"=>"(123) 123-1234",
|
39
|
+
},
|
40
|
+
}
|
41
|
+
exp = {
|
42
|
+
"user"=>[
|
43
|
+
"first_name", "last_name", "email", "phone", "work_location", "birth_date"
|
44
|
+
],
|
45
|
+
"address"=>[
|
46
|
+
"id", "street_address", "city", "state", "zip"
|
47
|
+
],
|
48
|
+
"emergency_contact"=>[
|
49
|
+
"id", "first_name", "last_name", "phone"
|
50
|
+
],
|
51
|
+
}
|
52
|
+
actual = to_strong_params_shape(params)
|
53
|
+
assert_equal exp["user"], actual["user"]
|
54
|
+
assert_equal exp["address"], actual["address"]
|
55
|
+
assert_equal exp["emergency_contact"], actual["emergency_contact"]
|
56
|
+
end
|
16
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_strong_parameters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drew Ulmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|