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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7957f41175cec758139ef39f6b1b1889b7d164c51b658cf09ad58f9a14fc8b9e
4
- data.tar.gz: a5775efa5e7ad60032c7915832bc86f5119bf3496e9a16269a922c6ab696ee08
3
+ metadata.gz: 1b7680411c579ad85825c31e55cb9e0e22fe2b6968a1ac47a9f4c2c5f06cd8b4
4
+ data.tar.gz: 3aaeb488a04aa4b2e8a38a85b5fc253e2ef9ed0d5e6711a1a9624b56de069e85
5
5
  SHA512:
6
- metadata.gz: 68b0628b21442f52584f689266f736e62ce810ecfb629d94208e8ea72d531c210243e0952ffcaca46bbfbe579a0cfb5ae37aebbf83910e3817ed7183e593760d
7
- data.tar.gz: 71a53c2f1d3ee226d73ea6f8f8467f76e10b35b2cd02e6cd18b5241f53c13077f038abacc2286ee5fba06d65361b6cd33c3cd6110f720885699a096498c71c20
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|
@@ -9,7 +9,7 @@ module AutoStrongParameters
9
9
  end
10
10
 
11
11
  def asp_auto_permitted_params(key)
12
- if sig = self[key][AutoStrongParameters.asp_message_key]
12
+ if sig = self[AutoStrongParameters.asp_message_key]
13
13
  AutoStrongParameters.verifier.verify(sig) rescue {}
14
14
  else
15
15
  {}
@@ -1,3 +1,3 @@
1
1
  module AutoStrongParameters
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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]
@@ -27,6 +27,7 @@ class AutoFormParamsTest < ActionController::TestCase
27
27
  "age",
28
28
  "years_of_experience",
29
29
  "password",
30
+ "location",
30
31
  "preferred_phone_os",
31
32
  {
32
33
  "parents_attributes"=>[
@@ -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.1
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-17 00:00:00.000000000 Z
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails