auto_strong_parameters 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +26 -0
- data/lib/auto_strong_parameters/auto_form_params.rb +54 -7
- data/lib/auto_strong_parameters/auto_permit.rb +14 -2
- data/lib/auto_strong_parameters/version.rb +1 -1
- data/lib/auto_strong_parameters.rb +25 -0
- data/test/apps/rails52.rb +1 -2
- data/test/apps/rails71.rb +56 -0
- data/test/apps/rails72.rb +56 -0
- data/test/apps/rails80.rb +56 -0
- data/test/auto_form_params_test.rb +310 -3
- data/test/test_helper.rb +10 -1
- metadata +19 -14
- data/lib/auto_strong_parameters/controller_permitter.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fabd8f4e0268992eefe957cfe8c6787bd7d37c96f866859c4badd2e1b3ac11bd
|
4
|
+
data.tar.gz: cee5efc7064816c8787e4b0c59a4909cade8f63620db9a4f6c49fc119ee47ae4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d02baee4ff7f2a36c05f6dd5efb1309fe9656bcc1880c58ac30bf09b6c0c841b5b34c5b2572d1a4b0f494d701e5d7c7ed5f9fcb9e7579f66b6f238329732a9d
|
7
|
+
data.tar.gz: e1ca46986d421cb6d1c1a10efed5624644d493853806b6db64d43eb611f9cd0981a7b865783df5481aa497c2d8cff6d6b1ff2e832fd14c750cae2227dc279438
|
data/Rakefile
CHANGED
@@ -9,3 +9,29 @@ end
|
|
9
9
|
|
10
10
|
desc "Run tests"
|
11
11
|
task default: :test
|
12
|
+
|
13
|
+
task :appr_31 do
|
14
|
+
cmd = <<~CMD
|
15
|
+
# Run appraisals under Ruby 3.1
|
16
|
+
rbenv local 3.1.7
|
17
|
+
echo "Testing Ruby 3.1 Rails versions..." &&
|
18
|
+
bundle exec appraisal rails-4-2 rake test > /dev/null 2>&1 && echo "✅ Rails 4.2: PASSED" || echo "❌ Rails 4.2: FAILED" &&
|
19
|
+
bundle exec appraisal rails-5-2 rake test > /dev/null 2>&1 && echo "✅ Rails 5.2: PASSED" || echo "❌ Rails 5.2: FAILED"
|
20
|
+
CMD
|
21
|
+
system cmd
|
22
|
+
end
|
23
|
+
|
24
|
+
task :appr_33 do
|
25
|
+
cmd = <<~CMD
|
26
|
+
# Run Ruby 3.3 appraisals
|
27
|
+
rbenv local 3.3.7
|
28
|
+
echo "Testing Ruby 3.3 Rails versions..." &&
|
29
|
+
bundle exec appraisal rails-6-0 rake test > /dev/null 2>&1 && echo "✅ Rails 6.0: PASSED" || echo "❌ Rails 6.0: FAILED" &&
|
30
|
+
bundle exec appraisal rails-6-1 rake test > /dev/null 2>&1 && echo "✅ Rails 6.1: PASSED" || echo "❌ Rails 6.1: FAILED" &&
|
31
|
+
bundle exec appraisal rails-7-0 rake test > /dev/null 2>&1 && echo "✅ Rails 7.0: PASSED" || echo "❌ Rails 7.0: FAILED" &&
|
32
|
+
bundle exec appraisal rails-7-1 rake test > /dev/null 2>&1 && echo "✅ Rails 7.1: PASSED" || echo "❌ Rails 7.1: FAILED" &&
|
33
|
+
bundle exec appraisal rails-7-2 rake test > /dev/null 2>&1 && echo "✅ Rails 7.2: PASSED" || echo "❌ Rails 7.2: FAILED" &&
|
34
|
+
bundle exec appraisal rails-8-0 rake test > /dev/null 2>&1 && echo "✅ Rails 8.0: PASSED" || echo "❌ Rails 8.0: FAILED"
|
35
|
+
CMD
|
36
|
+
system cmd
|
37
|
+
end
|
@@ -4,10 +4,10 @@ module AutoStrongParameters::AutoFormParams
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
attr_reader :_asp_fields
|
7
|
+
attr_reader :_asp_fields, :_asp_original_options
|
8
8
|
end
|
9
9
|
|
10
|
-
ASP_NAME_REGEX = /\
|
10
|
+
ASP_NAME_REGEX = /\bname=\"(.+?)\"/
|
11
11
|
ASP_DIGIT_REGEX = /\[\d+\]/
|
12
12
|
|
13
13
|
TRACKED_FIELDS = %w(
|
@@ -22,7 +22,6 @@ module AutoStrongParameters::AutoFormParams
|
|
22
22
|
email_field
|
23
23
|
file_field
|
24
24
|
grouped_collection_select
|
25
|
-
grouped_collection_select
|
26
25
|
hidden_field
|
27
26
|
month_field
|
28
27
|
number_field
|
@@ -31,10 +30,12 @@ module AutoStrongParameters::AutoFormParams
|
|
31
30
|
radio_button
|
32
31
|
range_field
|
33
32
|
rich_text_area
|
33
|
+
rich_textarea
|
34
34
|
search_field
|
35
35
|
select
|
36
36
|
telephone_field
|
37
37
|
text_area
|
38
|
+
textarea
|
38
39
|
text_field
|
39
40
|
time_field
|
40
41
|
time_zone_select
|
@@ -53,19 +54,41 @@ module AutoStrongParameters::AutoFormParams
|
|
53
54
|
RUBY_EVAL
|
54
55
|
end
|
55
56
|
|
57
|
+
# Override form_for to capture original options (Rails 4+). This is the only
|
58
|
+
# way to capture data attributes that are provided via string like
|
59
|
+
# "data-asp-disabled".
|
60
|
+
def form_for(record, options = {}, &block)
|
61
|
+
@_asp_original_options = options.dup
|
62
|
+
super
|
63
|
+
end
|
64
|
+
|
65
|
+
# Override form_with to capture original options (Rails 5+).
|
66
|
+
def form_with(**args, &block)
|
67
|
+
@_asp_original_options = args.dup
|
68
|
+
|
69
|
+
# Rails 8 requires model to be an object or false, not nil
|
70
|
+
# If model is nil and url is provided, set model to false for Rails 8 compatibility
|
71
|
+
if args[:model].nil? && args[:url]
|
72
|
+
args[:model] = false
|
73
|
+
end
|
74
|
+
|
75
|
+
super(**args, &block)
|
76
|
+
end
|
77
|
+
|
56
78
|
private
|
57
79
|
|
58
80
|
def _asp_track_field(field)
|
59
81
|
@_asp_fields ||= []
|
60
|
-
|
82
|
+
|
83
|
+
if match_data = field.match(ASP_NAME_REGEX)
|
84
|
+
@_asp_fields << match_data[1].gsub(ASP_DIGIT_REGEX, '[]')
|
85
|
+
end
|
61
86
|
end
|
62
87
|
|
63
88
|
# Generate a hidden input with the signed value of the params shape for this
|
64
89
|
# form. Append to the form.
|
65
90
|
def _asp_hidden_tag
|
66
91
|
if _asp_fields.present?
|
67
|
-
# puts "========= Adding tag =========="
|
68
|
-
# puts _asp_fields.inspect
|
69
92
|
name = AutoStrongParameters.asp_message_key
|
70
93
|
to_sign = asp_fields_to_shape
|
71
94
|
signature = AutoStrongParameters.verifier.generate(to_sign)
|
@@ -83,7 +106,9 @@ module AutoStrongParameters::AutoFormParams
|
|
83
106
|
def form_tag_with_body(html_options, content)
|
84
107
|
output = form_tag_html(html_options)
|
85
108
|
output << content.to_s if content
|
86
|
-
|
109
|
+
if auto_strong_parameters_enabled?(html_options)
|
110
|
+
output << _asp_hidden_tag
|
111
|
+
end
|
87
112
|
output.safe_concat("</form>")
|
88
113
|
end
|
89
114
|
|
@@ -95,4 +120,26 @@ module AutoStrongParameters::AutoFormParams
|
|
95
120
|
Rack::Utils.parse_nested_query(_asp_fields.join("=&") + "=")
|
96
121
|
)
|
97
122
|
end
|
123
|
+
|
124
|
+
def auto_strong_parameters_enabled?(opts)
|
125
|
+
return false if AutoStrongParameters.disabled?
|
126
|
+
|
127
|
+
# Check both processed options and original options
|
128
|
+
# Use trailing predicates instead of ||= to handle false values.
|
129
|
+
inline_val = opts.dig("data", :asp_disabled)
|
130
|
+
inline_val = opts["data-asp-disabled"] if inline_val.nil?
|
131
|
+
inline_val = opts[:data_asp_disabled] if inline_val.nil?
|
132
|
+
inline_val = opts[:'data-asp-disabled'] if inline_val.nil?
|
133
|
+
|
134
|
+
# If not found in processed options, check original options from form_for
|
135
|
+
if inline_val.nil? && defined?(@_asp_original_options) && @_asp_original_options
|
136
|
+
inline_val = @_asp_original_options["data-asp-disabled"]
|
137
|
+
inline_val = @_asp_original_options[:'data-asp-disabled'] if inline_val.nil?
|
138
|
+
end
|
139
|
+
|
140
|
+
# If inline_val is blank, ASP is enabled by default
|
141
|
+
# If inline_val is explicitly set to disable ASP, honor that
|
142
|
+
# Otherwise ASP is enabled (including for 'enabled' and 'false' values)
|
143
|
+
!inline_val.to_s.in?(['disabled', 'true'])
|
144
|
+
end
|
98
145
|
end
|
@@ -5,12 +5,24 @@ module AutoStrongParameters
|
|
5
5
|
def auto_permit!(key)
|
6
6
|
shape = asp_auto_permitted_params
|
7
7
|
|
8
|
-
|
8
|
+
permitted_shape = shape[key]
|
9
|
+
|
10
|
+
# Log the shape we're permitting so that developers who may need to use
|
11
|
+
# StrongParameters directly can easily copy the shape into a regular
|
12
|
+
# #permit call.
|
13
|
+
AutoStrongParameters.logger.debug("AutoStrongParameters: Permitting params for key '#{key}' with shape: #{permitted_shape.inspect}")
|
14
|
+
|
15
|
+
require(key).permit(permitted_shape)
|
9
16
|
end
|
10
17
|
|
11
18
|
def asp_auto_permitted_params
|
12
19
|
if sig = self[AutoStrongParameters.asp_message_key]
|
13
|
-
|
20
|
+
begin
|
21
|
+
AutoStrongParameters.verifier.verify(sig)
|
22
|
+
rescue => e
|
23
|
+
AutoStrongParameters.logger.warn("AutoStrongParameters: Error verifying signature for params: #{e.message}")
|
24
|
+
{}
|
25
|
+
end
|
14
26
|
else
|
15
27
|
{}
|
16
28
|
end.with_indifferent_access
|
@@ -20,6 +20,23 @@ module AutoStrongParameters
|
|
20
20
|
@secret ||= Rails.application.config.secret_key_base
|
21
21
|
end
|
22
22
|
|
23
|
+
def self.enabled
|
24
|
+
@enabled = true if !defined?(@enabled)
|
25
|
+
@enabled
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.enabled?
|
29
|
+
!!enabled
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.disabled?
|
33
|
+
!enabled
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.enabled=(value)
|
37
|
+
@enabled = value
|
38
|
+
end
|
39
|
+
|
23
40
|
def self.to_strong_params_shape(obj)
|
24
41
|
items = Set.new
|
25
42
|
hsh = {}
|
@@ -83,4 +100,12 @@ module AutoStrongParameters
|
|
83
100
|
def self.verifier=(custom_verifier)
|
84
101
|
@verifier = custom_verifier
|
85
102
|
end
|
103
|
+
|
104
|
+
def self.logger
|
105
|
+
@logger ||= Rails.logger
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.logger=(custom_logger)
|
109
|
+
@logger = custom_logger
|
110
|
+
end
|
86
111
|
end
|
data/test/apps/rails52.rb
CHANGED
@@ -29,8 +29,7 @@ module Rails52
|
|
29
29
|
config.cache_classes = true
|
30
30
|
|
31
31
|
config.eager_load = false
|
32
|
-
config.
|
33
|
-
config.static_cache_control = "public, max-age=3600"
|
32
|
+
config.public_file_server.enabled = false
|
34
33
|
|
35
34
|
config.consider_all_requests_local = true
|
36
35
|
config.action_controller.perform_caching = false
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "rails"
|
2
|
+
|
3
|
+
[
|
4
|
+
#'active_record',
|
5
|
+
'active_model',
|
6
|
+
'action_controller',
|
7
|
+
'action_view',
|
8
|
+
#'action_mailer',
|
9
|
+
#'active_job',
|
10
|
+
'rails/test_unit',
|
11
|
+
#'sprockets',
|
12
|
+
].each do |framework|
|
13
|
+
begin
|
14
|
+
require "#{framework}/railtie"
|
15
|
+
rescue LoadError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'action_view/testing/resolvers'
|
20
|
+
require 'rails/test_help'
|
21
|
+
|
22
|
+
require 'auto_strong_parameters'
|
23
|
+
|
24
|
+
require_relative './test_app'
|
25
|
+
|
26
|
+
module Rails71
|
27
|
+
class Application < Rails::Application
|
28
|
+
config.root = File.expand_path("../../..", __FILE__)
|
29
|
+
config.cache_classes = true
|
30
|
+
|
31
|
+
config.eager_load = false
|
32
|
+
config.serve_static_files = true
|
33
|
+
config.static_cache_control = "public, max-age=3600"
|
34
|
+
|
35
|
+
config.consider_all_requests_local = true
|
36
|
+
config.action_controller.perform_caching = false
|
37
|
+
|
38
|
+
config.action_dispatch.show_exceptions = false
|
39
|
+
|
40
|
+
config.action_controller.allow_forgery_protection = false
|
41
|
+
|
42
|
+
config.active_support.deprecation = :stderr
|
43
|
+
|
44
|
+
config.active_support.test_order = :sorted
|
45
|
+
|
46
|
+
config.middleware.delete Rack::Lock
|
47
|
+
config.middleware.delete ActionDispatch::Flash
|
48
|
+
config.secret_key_base = TestApp.secret_key_base
|
49
|
+
routes.append(&TestApp.routes)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
require_relative './models'
|
54
|
+
require_relative './basic_controller'
|
55
|
+
|
56
|
+
Rails71::Application.initialize!
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "rails"
|
2
|
+
|
3
|
+
[
|
4
|
+
#'active_record',
|
5
|
+
'active_model',
|
6
|
+
'action_controller',
|
7
|
+
'action_view',
|
8
|
+
#'action_mailer',
|
9
|
+
#'active_job',
|
10
|
+
'rails/test_unit',
|
11
|
+
#'sprockets',
|
12
|
+
].each do |framework|
|
13
|
+
begin
|
14
|
+
require "#{framework}/railtie"
|
15
|
+
rescue LoadError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'action_view/testing/resolvers'
|
20
|
+
require 'rails/test_help'
|
21
|
+
|
22
|
+
require 'auto_strong_parameters'
|
23
|
+
|
24
|
+
require_relative './test_app'
|
25
|
+
|
26
|
+
module Rails72
|
27
|
+
class Application < Rails::Application
|
28
|
+
config.root = File.expand_path("../../..", __FILE__)
|
29
|
+
config.cache_classes = true
|
30
|
+
|
31
|
+
config.eager_load = false
|
32
|
+
config.serve_static_files = true
|
33
|
+
config.static_cache_control = "public, max-age=3600"
|
34
|
+
|
35
|
+
config.consider_all_requests_local = true
|
36
|
+
config.action_controller.perform_caching = false
|
37
|
+
|
38
|
+
config.action_dispatch.show_exceptions = false
|
39
|
+
|
40
|
+
config.action_controller.allow_forgery_protection = false
|
41
|
+
|
42
|
+
config.active_support.deprecation = :stderr
|
43
|
+
|
44
|
+
config.active_support.test_order = :sorted
|
45
|
+
|
46
|
+
config.middleware.delete Rack::Lock
|
47
|
+
config.middleware.delete ActionDispatch::Flash
|
48
|
+
config.secret_key_base = TestApp.secret_key_base
|
49
|
+
routes.append(&TestApp.routes)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
require_relative './models'
|
54
|
+
require_relative './basic_controller'
|
55
|
+
|
56
|
+
Rails72::Application.initialize!
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "rails"
|
2
|
+
|
3
|
+
[
|
4
|
+
#'active_record',
|
5
|
+
'active_model',
|
6
|
+
'action_controller',
|
7
|
+
'action_view',
|
8
|
+
#'action_mailer',
|
9
|
+
#'active_job',
|
10
|
+
'rails/test_unit',
|
11
|
+
#'sprockets',
|
12
|
+
].each do |framework|
|
13
|
+
begin
|
14
|
+
require "#{framework}/railtie"
|
15
|
+
rescue LoadError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'action_view/testing/resolvers'
|
20
|
+
require 'rails/test_help'
|
21
|
+
|
22
|
+
require 'auto_strong_parameters'
|
23
|
+
|
24
|
+
require_relative './test_app'
|
25
|
+
|
26
|
+
module Rails80
|
27
|
+
class Application < Rails::Application
|
28
|
+
config.root = File.expand_path("../../..", __FILE__)
|
29
|
+
config.cache_classes = true
|
30
|
+
|
31
|
+
config.eager_load = false
|
32
|
+
config.serve_static_files = true
|
33
|
+
config.static_cache_control = "public, max-age=3600"
|
34
|
+
|
35
|
+
config.consider_all_requests_local = true
|
36
|
+
config.action_controller.perform_caching = false
|
37
|
+
|
38
|
+
config.action_dispatch.show_exceptions = false
|
39
|
+
|
40
|
+
config.action_controller.allow_forgery_protection = false
|
41
|
+
|
42
|
+
config.active_support.deprecation = :stderr
|
43
|
+
|
44
|
+
config.active_support.test_order = :sorted
|
45
|
+
|
46
|
+
config.middleware.delete Rack::Lock
|
47
|
+
config.middleware.delete ActionDispatch::Flash
|
48
|
+
config.secret_key_base = TestApp.secret_key_base
|
49
|
+
routes.append(&TestApp.routes)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
require_relative './models'
|
54
|
+
require_relative './basic_controller'
|
55
|
+
|
56
|
+
Rails80::Application.initialize!
|
@@ -5,6 +5,12 @@ require 'test_helper'
|
|
5
5
|
class AutoFormParamsTest < ActionController::TestCase
|
6
6
|
setup do
|
7
7
|
@controller = BasicController.new
|
8
|
+
@original_view_paths = BasicController.view_paths
|
9
|
+
end
|
10
|
+
|
11
|
+
teardown do
|
12
|
+
# Restore original view paths
|
13
|
+
BasicController.view_paths = @original_view_paths
|
8
14
|
end
|
9
15
|
|
10
16
|
def signature
|
@@ -45,11 +51,312 @@ class AutoFormParamsTest < ActionController::TestCase
|
|
45
51
|
|
46
52
|
def test_new
|
47
53
|
get :new
|
48
|
-
assert_response :ok
|
49
|
-
|
50
|
-
assert_select "form[id='new_user']"
|
51
54
|
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']" do
|
52
55
|
assert_select "[value=?]", signature
|
53
56
|
end
|
54
57
|
end
|
58
|
+
|
59
|
+
def test_form_with_malformed_field_does_not_crash
|
60
|
+
# This test demonstrates the bug where _asp_track_field fails when regex doesn't match
|
61
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
62
|
+
"basic/new.html.erb" => <<~MALFORMED_FORM
|
63
|
+
<%= form_for @user, url: "/auto_permit" do |f| %>
|
64
|
+
<%= f.text_field :name, name: nil %>
|
65
|
+
<%= f.email_field :email %>
|
66
|
+
<% end %>
|
67
|
+
MALFORMED_FORM
|
68
|
+
)]
|
69
|
+
|
70
|
+
get :new
|
71
|
+
# Form should still render and include ASP hidden tag
|
72
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']"
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_disabled_form_does_not_include_asp_hidden_tag
|
76
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
77
|
+
"basic/new.html.erb" => <<~DISABLED_FORM
|
78
|
+
<%= form_for @user, url: "/auto_permit", data: { asp_disabled: true } do |f| %>
|
79
|
+
<%= f.text_field :name %>
|
80
|
+
<%= f.email_field :email %>
|
81
|
+
<% end %>
|
82
|
+
DISABLED_FORM
|
83
|
+
)]
|
84
|
+
|
85
|
+
get :new
|
86
|
+
# Should NOT have the ASP hidden tag
|
87
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']", false
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_globally_disabled_does_not_include_asp_hidden_tag
|
91
|
+
# Temporarily disable globally
|
92
|
+
AutoStrongParameters.enabled = false
|
93
|
+
|
94
|
+
get :new
|
95
|
+
# Should NOT have the ASP hidden tag when globally disabled
|
96
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']", false
|
97
|
+
|
98
|
+
# Re-enable for other tests
|
99
|
+
AutoStrongParameters.enabled = true
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_enabled_methods
|
103
|
+
# Test default state
|
104
|
+
assert AutoStrongParameters.enabled?
|
105
|
+
refute AutoStrongParameters.disabled?
|
106
|
+
|
107
|
+
# Test setting to false
|
108
|
+
AutoStrongParameters.enabled = false
|
109
|
+
refute AutoStrongParameters.enabled?
|
110
|
+
assert AutoStrongParameters.disabled?
|
111
|
+
|
112
|
+
# Test setting back to true
|
113
|
+
AutoStrongParameters.enabled = true
|
114
|
+
assert AutoStrongParameters.enabled?
|
115
|
+
refute AutoStrongParameters.disabled?
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_form_with_data_asp_disabled_attribute
|
119
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
120
|
+
"basic/new.html.erb" => <<~DATA_DISABLED_FORM
|
121
|
+
<%= form_for @user, url: "/auto_permit", data: { asp_disabled: "true" } do |f| %>
|
122
|
+
<%= f.text_field :name %>
|
123
|
+
<% end %>
|
124
|
+
DATA_DISABLED_FORM
|
125
|
+
)]
|
126
|
+
|
127
|
+
get :new
|
128
|
+
# Should NOT have the ASP hidden tag
|
129
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']", false
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_form_with_data_asp_boolean_disabled_true
|
133
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
134
|
+
"basic/new.html.erb" => <<~DATA_DISABLED_FORM
|
135
|
+
<%= form_for @user, url: "/auto_permit", data: { asp_disabled: true } do |f| %>
|
136
|
+
<%= f.text_field :name %>
|
137
|
+
<% end %>
|
138
|
+
DATA_DISABLED_FORM
|
139
|
+
)]
|
140
|
+
|
141
|
+
get :new
|
142
|
+
# Should NOT have the ASP hidden tag
|
143
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']", false
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_form_with_data_asp_boolean_disabled_false
|
147
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
148
|
+
"basic/new.html.erb" => <<~DATA_DISABLED_FORM
|
149
|
+
<%= form_for @user, url: "/auto_permit", data: { asp_disabled: false } do |f| %>
|
150
|
+
<%= f.text_field :name %>
|
151
|
+
<% end %>
|
152
|
+
DATA_DISABLED_FORM
|
153
|
+
)]
|
154
|
+
|
155
|
+
get :new
|
156
|
+
# Should have the ASP hidden tag
|
157
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']"
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_form_with_data_asp_disabled_string_disabled
|
161
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
162
|
+
"basic/new.html.erb" => <<~DATA_DISABLED_FORM
|
163
|
+
<%= form_for @user, url: "/auto_permit", data: { asp_disabled: "disabled" } do |f| %>
|
164
|
+
<%= f.text_field :name %>
|
165
|
+
<% end %>
|
166
|
+
DATA_DISABLED_FORM
|
167
|
+
)]
|
168
|
+
|
169
|
+
get :new
|
170
|
+
# Should NOT have the ASP hidden tag
|
171
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']", false
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_form_with_data_asp_disabled_string_enabled
|
175
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
176
|
+
"basic/new.html.erb" => <<~DATA_DISABLED_FORM
|
177
|
+
<%= form_for @user, url: "/auto_permit", data: { asp_disabled: "enabled" } do |f| %>
|
178
|
+
<%= f.text_field :name %>
|
179
|
+
<% end %>
|
180
|
+
DATA_DISABLED_FORM
|
181
|
+
)]
|
182
|
+
|
183
|
+
get :new
|
184
|
+
# Should have the ASP hidden tag
|
185
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']"
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_form_with_data_asp_disable_long_name
|
189
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
190
|
+
"basic/new.html.erb" => <<~DATA_DISABLED_FORM
|
191
|
+
<%= form_for @user, url: "/auto_permit", "data-asp-disabled": "disabled" do |f| %>
|
192
|
+
<%= f.text_field :name %>
|
193
|
+
<% end %>
|
194
|
+
DATA_DISABLED_FORM
|
195
|
+
)]
|
196
|
+
|
197
|
+
get :new
|
198
|
+
# Should NOT have the ASP hidden tag
|
199
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']", false
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_form_without_data_asp_disabled_false_works
|
203
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
204
|
+
"basic/new.html.erb" => <<~NORMAL_FORM
|
205
|
+
<%= form_for @user, url: "/auto_permit", "data-asp-disabled": false do |f| %>
|
206
|
+
<%= f.text_field :name %>
|
207
|
+
<%= f.email_field :email %>
|
208
|
+
<% end %>
|
209
|
+
NORMAL_FORM
|
210
|
+
)]
|
211
|
+
|
212
|
+
get :new
|
213
|
+
# Should have the ASP hidden tag
|
214
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']"
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_form_without_data_asp_disabled_works
|
218
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
219
|
+
"basic/new.html.erb" => <<~NORMAL_FORM
|
220
|
+
<%= form_for @user, url: "/auto_permit" do |f| %>
|
221
|
+
<%= f.text_field :name %>
|
222
|
+
<%= f.email_field :email %>
|
223
|
+
<% end %>
|
224
|
+
NORMAL_FORM
|
225
|
+
)]
|
226
|
+
|
227
|
+
get :new
|
228
|
+
# Should have the ASP hidden tag
|
229
|
+
assert_select "form[id='new_user'] input[name='#{AutoStrongParameters.asp_message_key}']"
|
230
|
+
end
|
231
|
+
|
232
|
+
# ===== form_with tests (Rails 5+) =====
|
233
|
+
|
234
|
+
unless defined? Rails42
|
235
|
+
def test_form_with_basic_functionality
|
236
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
237
|
+
"basic/new.html.erb" => <<~FORM_WITH_BASIC
|
238
|
+
<%= form_with model: @user, url: "/auto_permit" do |f| %>
|
239
|
+
<%= f.text_field :name %>
|
240
|
+
<%= f.email_field :email %>
|
241
|
+
<% end %>
|
242
|
+
FORM_WITH_BASIC
|
243
|
+
)]
|
244
|
+
|
245
|
+
get :new
|
246
|
+
# Should have the ASP hidden tag
|
247
|
+
assert_select "form input[name='#{AutoStrongParameters.asp_message_key}']"
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_form_with_data_asp_disabled_hash_true
|
251
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
252
|
+
"basic/new.html.erb" => <<~FORM_WITH_DISABLED
|
253
|
+
<%= form_with model: @user, url: "/auto_permit", data: { asp_disabled: true } do |f| %>
|
254
|
+
<%= f.text_field :name %>
|
255
|
+
<% end %>
|
256
|
+
FORM_WITH_DISABLED
|
257
|
+
)]
|
258
|
+
|
259
|
+
get :new
|
260
|
+
# Should NOT have the ASP hidden tag
|
261
|
+
assert_select "form input[name='#{AutoStrongParameters.asp_message_key}']", false
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_form_with_data_asp_disabled_hash_string_true
|
265
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
266
|
+
"basic/new.html.erb" => <<~FORM_WITH_DISABLED
|
267
|
+
<%= form_with model: @user, url: "/auto_permit", data: { asp_disabled: "true" } do |f| %>
|
268
|
+
<%= f.text_field :name %>
|
269
|
+
<% end %>
|
270
|
+
FORM_WITH_DISABLED
|
271
|
+
)]
|
272
|
+
|
273
|
+
get :new
|
274
|
+
# Should NOT have the ASP hidden tag
|
275
|
+
assert_select "form input[name='#{AutoStrongParameters.asp_message_key}']", false
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_form_with_data_asp_disabled_hash_disabled
|
279
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
280
|
+
"basic/new.html.erb" => <<~FORM_WITH_DISABLED
|
281
|
+
<%= form_with model: @user, url: "/auto_permit", data: { asp_disabled: "disabled" } do |f| %>
|
282
|
+
<%= f.text_field :name %>
|
283
|
+
<% end %>
|
284
|
+
FORM_WITH_DISABLED
|
285
|
+
)]
|
286
|
+
|
287
|
+
get :new
|
288
|
+
# Should NOT have the ASP hidden tag
|
289
|
+
assert_select "form input[name='#{AutoStrongParameters.asp_message_key}']", false
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_form_with_data_asp_disabled_hash_false
|
293
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
294
|
+
"basic/new.html.erb" => <<~FORM_WITH_ENABLED
|
295
|
+
<%= form_with model: @user, url: "/auto_permit", data: { asp_disabled: false } do |f| %>
|
296
|
+
<%= f.text_field :name %>
|
297
|
+
<% end %>
|
298
|
+
FORM_WITH_ENABLED
|
299
|
+
)]
|
300
|
+
|
301
|
+
get :new
|
302
|
+
# Should have the ASP hidden tag
|
303
|
+
assert_select "form input[name='#{AutoStrongParameters.asp_message_key}']"
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_form_with_data_asp_disabled_hash_enabled
|
307
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
308
|
+
"basic/new.html.erb" => <<~FORM_WITH_ENABLED
|
309
|
+
<%= form_with model: @user, url: "/auto_permit", data: { asp_disabled: "enabled" } do |f| %>
|
310
|
+
<%= f.text_field :name %>
|
311
|
+
<% end %>
|
312
|
+
FORM_WITH_ENABLED
|
313
|
+
)]
|
314
|
+
|
315
|
+
get :new
|
316
|
+
# Should have the ASP hidden tag
|
317
|
+
assert_select "form input[name='#{AutoStrongParameters.asp_message_key}']"
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_form_with_data_asp_disable_string_key_disabled
|
321
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
322
|
+
"basic/new.html.erb" => <<~FORM_WITH_STRING_DISABLED
|
323
|
+
<%= form_with model: @user, url: "/auto_permit", "data-asp-disabled": "disabled" do |f| %>
|
324
|
+
<%= f.text_field :name %>
|
325
|
+
<% end %>
|
326
|
+
FORM_WITH_STRING_DISABLED
|
327
|
+
)]
|
328
|
+
|
329
|
+
get :new
|
330
|
+
# Should NOT have the ASP hidden tag
|
331
|
+
assert_select "form input[name='#{AutoStrongParameters.asp_message_key}']", false
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_form_with_data_asp_disable_string_key_false
|
335
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
336
|
+
"basic/new.html.erb" => <<~FORM_WITH_STRING_ENABLED
|
337
|
+
<%= form_with model: @user, url: "/auto_permit", "data-asp-disabled": false do |f| %>
|
338
|
+
<%= f.text_field :name %>
|
339
|
+
<% end %>
|
340
|
+
FORM_WITH_STRING_ENABLED
|
341
|
+
)]
|
342
|
+
|
343
|
+
get :new
|
344
|
+
# Should have the ASP hidden tag
|
345
|
+
assert_select "form input[name='#{AutoStrongParameters.asp_message_key}']"
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_form_with_url_syntax
|
349
|
+
BasicController.view_paths = [ActionView::FixtureResolver.new(
|
350
|
+
"basic/new.html.erb" => <<~FORM_WITH_URL
|
351
|
+
<%= form_with url: "/auto_permit", "data-asp-disabled": "disabled" do |f| %>
|
352
|
+
<%= f.text_field :name %>
|
353
|
+
<% end %>
|
354
|
+
FORM_WITH_URL
|
355
|
+
)]
|
356
|
+
|
357
|
+
get :new
|
358
|
+
# Should NOT have the ASP hidden tag
|
359
|
+
assert_select "form input[name='#{AutoStrongParameters.asp_message_key}']", false
|
360
|
+
end
|
361
|
+
end
|
55
362
|
end
|
data/test/test_helper.rb
CHANGED
@@ -5,6 +5,9 @@ require 'pry'
|
|
5
5
|
ENV["RAILS_ENV"] = "test"
|
6
6
|
ENV['DATABASE_URL'] = 'sqlite3://localhost/:memory:'
|
7
7
|
|
8
|
+
# Fix for Ruby 3.1+ logger compatibility with Rails 6.0+
|
9
|
+
require 'logger' if RUBY_VERSION >= "3.0"
|
10
|
+
|
8
11
|
require 'rails'
|
9
12
|
|
10
13
|
case Rails.version.slice(0, 3)
|
@@ -18,6 +21,12 @@ when "6.1"
|
|
18
21
|
require "apps/rails61"
|
19
22
|
when "7.0"
|
20
23
|
require "apps/rails70"
|
24
|
+
when "7.1"
|
25
|
+
require "apps/rails71"
|
26
|
+
when "7.2"
|
27
|
+
require "apps/rails72"
|
28
|
+
when "8.0"
|
29
|
+
require "apps/rails80"
|
21
30
|
else
|
22
|
-
raise "
|
31
|
+
raise "Version #{Rails.version} of Rails is not configured for testing."
|
23
32
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drew Ulmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -91,7 +91,6 @@ files:
|
|
91
91
|
- lib/auto_strong_parameters.rb
|
92
92
|
- lib/auto_strong_parameters/auto_form_params.rb
|
93
93
|
- lib/auto_strong_parameters/auto_permit.rb
|
94
|
-
- lib/auto_strong_parameters/controller_permitter.rb
|
95
94
|
- lib/auto_strong_parameters/railtie.rb
|
96
95
|
- lib/auto_strong_parameters/version.rb
|
97
96
|
- test/apps/basic_controller.rb
|
@@ -103,6 +102,9 @@ files:
|
|
103
102
|
- test/apps/rails60.rb
|
104
103
|
- test/apps/rails61.rb
|
105
104
|
- test/apps/rails70.rb
|
105
|
+
- test/apps/rails71.rb
|
106
|
+
- test/apps/rails72.rb
|
107
|
+
- test/apps/rails80.rb
|
106
108
|
- test/apps/routes.rb
|
107
109
|
- test/apps/test_app.rb
|
108
110
|
- test/apps/user.rb
|
@@ -129,24 +131,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
131
|
- !ruby/object:Gem::Version
|
130
132
|
version: '0'
|
131
133
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
134
|
+
rubygems_version: 3.5.22
|
133
135
|
signing_key:
|
134
136
|
specification_version: 4
|
135
|
-
summary: Automatic require and permit of Strong
|
137
|
+
summary: Automatic require and permit of Strong Parameters for your Rails forms.
|
136
138
|
test_files:
|
137
|
-
- test/auto_form_params_test.rb
|
138
|
-
- test/test_helper.rb
|
139
|
-
- test/apps/routes.rb
|
140
|
-
- test/apps/test_app.rb
|
141
|
-
- test/apps/rails52.rb
|
142
|
-
- test/apps/rails42.rb
|
143
139
|
- test/apps/basic_controller.rb
|
140
|
+
- test/apps/models.rb
|
144
141
|
- test/apps/parent.rb
|
145
142
|
- test/apps/pet.rb
|
146
|
-
- test/apps/
|
147
|
-
- test/apps/
|
143
|
+
- test/apps/rails42.rb
|
144
|
+
- test/apps/rails52.rb
|
148
145
|
- test/apps/rails60.rb
|
146
|
+
- test/apps/rails61.rb
|
149
147
|
- test/apps/rails70.rb
|
148
|
+
- test/apps/rails71.rb
|
149
|
+
- test/apps/rails72.rb
|
150
|
+
- test/apps/rails80.rb
|
151
|
+
- test/apps/routes.rb
|
152
|
+
- test/apps/test_app.rb
|
150
153
|
- test/apps/user.rb
|
151
|
-
- test/
|
154
|
+
- test/auto_form_params_test.rb
|
152
155
|
- test/auto_permit_test.rb
|
156
|
+
- test/auto_strong_parameters_test.rb
|
157
|
+
- test/test_helper.rb
|