action_args 2.4.0 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +88 -0
- data/README.md +3 -3
- data/Rakefile +1 -19
- data/action_args.gemspec +6 -3
- data/gemfiles/rails_50.gemfile +0 -2
- data/gemfiles/rails_51.gemfile +0 -2
- data/gemfiles/rails_52.gemfile +0 -2
- data/gemfiles/rails_60.gemfile +16 -0
- data/gemfiles/rails_61.gemfile +16 -0
- data/gemfiles/rails_70.gemfile +17 -0
- data/gemfiles/rails_edge.gemfile +1 -1
- data/lib/action_args/abstract_controller.rb +6 -2
- data/lib/action_args/callbacks.rb +64 -50
- data/lib/action_args/params_handler.rb +1 -2
- data/lib/action_args/version.rb +1 -1
- metadata +13 -34
- data/.travis.yml +0 -64
- data/test/controllers/action_args_controller_test.rb +0 -45
- data/test/controllers/hooks_test.rb +0 -31
- data/test/controllers/kwargs_controller_test.rb +0 -32
- data/test/controllers/kwargs_keyreq_controller_test.rb +0 -32
- data/test/controllers/ordinal_controller_test.rb +0 -11
- data/test/controllers/strong_parameters_test.rb +0 -59
- data/test/fake_app.rb +0 -193
- data/test/kwargs_controllers.rb +0 -10
- data/test/kwargs_keyreq_controllers.rb +0 -10
- data/test/mailers/action_mailer_test.rb +0 -15
- data/test/params_handler/params_handler_test.rb +0 -256
- data/test/test_helper.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 375a2da95a1f6a2d7b141a4e17cd057b534e03069211772ea803f5eb8a47f603
|
4
|
+
data.tar.gz: 50bfa937f5ea30b756de264837b8d63aaae5031a4018f09a2a521b5739be9c29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a0178f695e91ac00887b006201023d1cbdc11777bce68485f6b7b118cba8900763031112762f57660a2407efbb808b839edda36f03a3a2ba7ffeb81c4d5f90a
|
7
|
+
data.tar.gz: 6ab9fde7062e2160611e2b7860ad6f308fdbf3944900ef324d41257592316146c0a1766eff95a1686837708fc4239038e2bc53d6324ae4553509ef3f55ccc24a
|
@@ -0,0 +1,88 @@
|
|
1
|
+
name: build
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
include:
|
10
|
+
- ruby_version: ruby-head
|
11
|
+
gemfile: gemfiles/rails_edge.gemfile
|
12
|
+
allow_failures: 'true'
|
13
|
+
- ruby_version: '3.0'
|
14
|
+
gemfile: gemfiles/rails_70.gemfile
|
15
|
+
allow_failures: 'true'
|
16
|
+
- ruby_version: '3.0'
|
17
|
+
gemfile: gemfiles/rails_61.gemfile
|
18
|
+
allow_failures: 'true'
|
19
|
+
|
20
|
+
- ruby_version: '3.0'
|
21
|
+
gemfile: gemfiles/rails_edge.gemfile
|
22
|
+
allow_failures: 'true'
|
23
|
+
- ruby_version: '3.0'
|
24
|
+
gemfile: gemfiles/rails_70.gemfile
|
25
|
+
- ruby_version: '3.0'
|
26
|
+
gemfile: gemfiles/rails_61.gemfile
|
27
|
+
- ruby_version: '3.0'
|
28
|
+
gemfile: gemfiles/rails_60.gemfile
|
29
|
+
|
30
|
+
- ruby_version: jruby
|
31
|
+
gemfile: gemfiles/rails_61.gemfile
|
32
|
+
allow_failures: 'true'
|
33
|
+
- ruby_version: jruby
|
34
|
+
gemfile: gemfiles/rails_70.gemfile
|
35
|
+
allow_failures: 'true'
|
36
|
+
|
37
|
+
- ruby_version: '2.7'
|
38
|
+
gemfile: gemfiles/rails_edge.gemfile
|
39
|
+
allow_failures: 'true'
|
40
|
+
- ruby_version: '2.7'
|
41
|
+
gemfile: gemfiles/rails_70.gemfile
|
42
|
+
- ruby_version: '2.7'
|
43
|
+
gemfile: gemfiles/rails_61.gemfile
|
44
|
+
|
45
|
+
- ruby_version: '2.6'
|
46
|
+
gemfile: gemfiles/rails_61.gemfile
|
47
|
+
- ruby_version: '2.6'
|
48
|
+
gemfile: gemfiles/rails_52.gemfile
|
49
|
+
- ruby_version: '2.6'
|
50
|
+
gemfile: gemfiles/rails_51.gemfile
|
51
|
+
- ruby_version: '2.6'
|
52
|
+
gemfile: gemfiles/rails_50.gemfile
|
53
|
+
|
54
|
+
- ruby_version: '2.5'
|
55
|
+
gemfile: gemfiles/rails_61.gemfile
|
56
|
+
- ruby_version: '2.5'
|
57
|
+
gemfile: gemfiles/rails_52.gemfile
|
58
|
+
|
59
|
+
- ruby_version: '2.4'
|
60
|
+
gemfile: gemfiles/rails_52.gemfile
|
61
|
+
|
62
|
+
- ruby_version: '2.3'
|
63
|
+
gemfile: gemfiles/rails_52.gemfile
|
64
|
+
|
65
|
+
- ruby_version: '2.2'
|
66
|
+
gemfile: gemfiles/rails_42.gemfile
|
67
|
+
- ruby_version: '2.2'
|
68
|
+
gemfile: gemfiles/rails_41.gemfile
|
69
|
+
|
70
|
+
- ruby_version: '2.1'
|
71
|
+
gemfile: gemfiles/rails_42.gemfile
|
72
|
+
|
73
|
+
runs-on: ubuntu-latest
|
74
|
+
|
75
|
+
env:
|
76
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
77
|
+
|
78
|
+
steps:
|
79
|
+
- uses: actions/checkout@v2
|
80
|
+
|
81
|
+
- uses: ruby/setup-ruby@v1
|
82
|
+
with:
|
83
|
+
ruby-version: ${{ matrix.ruby_version }}
|
84
|
+
bundler-cache: true
|
85
|
+
continue-on-error: ${{ matrix.allow_failures == 'true' }}
|
86
|
+
|
87
|
+
- run: bundle exec rake
|
88
|
+
continue-on-error: ${{ matrix.allow_failures == 'true' }}
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# action_args
|
2
|
-
[![Build Status](https://
|
2
|
+
[![Build Status](https://github.com/asakusarb/action_args/actions/workflows/main.yml/badge.svg)](https://github.com/asakusarb/action_args/actions/actions)
|
3
3
|
|
4
4
|
Controller action arguments parameterizer for Rails
|
5
5
|
|
@@ -247,9 +247,9 @@ You may notice that
|
|
247
247
|
|
248
248
|
## Supported Versions
|
249
249
|
|
250
|
-
* Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x, 2.6.x, 2.7.0 (trunk), JRuby, & Rubinius with 2.0+ mode
|
250
|
+
* Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x, 2.6.x, 2.7.x, 3.0.x, 3.1 (trunk), JRuby, & Rubinius with 2.0+ mode
|
251
251
|
|
252
|
-
* Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, 6.0 (edge)
|
252
|
+
* Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.1 (edge)
|
253
253
|
|
254
254
|
For Rails 4.0.x, please use Version 1.5.4.
|
255
255
|
|
data/Rakefile
CHANGED
@@ -10,22 +10,4 @@ Rake::TestTask.new do |t|
|
|
10
10
|
t.verbose = true
|
11
11
|
end
|
12
12
|
|
13
|
-
task :
|
14
|
-
|
15
|
-
namespace :test do
|
16
|
-
%w(rails_41 rails_42 rails_edge).each do |gemfile|
|
17
|
-
desc "Run Tests against #{gemfile}"
|
18
|
-
task gemfile do
|
19
|
-
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
|
20
|
-
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t test"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
desc 'Run Tests against all Rails versions'
|
25
|
-
task :all do
|
26
|
-
%w(rails_41 rails_42 rails_edge).each do |gemfile|
|
27
|
-
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
|
28
|
-
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t test"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
13
|
+
task default: :test
|
data/action_args.gemspec
CHANGED
@@ -12,12 +12,15 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.email = ['ronnie@dio.jp']
|
13
13
|
s.homepage = 'http://asakusa.rubyist.net/'
|
14
14
|
s.license = 'MIT'
|
15
|
+
s.metadata = {
|
16
|
+
'source_code_uri' => 'https://github.com/asakusarb/action_args'
|
17
|
+
}
|
15
18
|
s.summary = 'Controller action arguments parameterizer for Rails 4+ & Ruby 2.0+'
|
16
19
|
s.description = 'Rails plugin gem that supports Merbish style controller action arguments.'
|
17
20
|
|
18
|
-
s.files =
|
19
|
-
|
20
|
-
|
21
|
+
s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
21
24
|
s.require_paths = ["lib"]
|
22
25
|
|
23
26
|
s.add_development_dependency 'bundler'
|
data/gemfiles/rails_50.gemfile
CHANGED
data/gemfiles/rails_51.gemfile
CHANGED
data/gemfiles/rails_52.gemfile
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gem 'rails', '~> 6.0.0'
|
6
|
+
gem 'selenium-webdriver'
|
7
|
+
|
8
|
+
gemspec path: '../'
|
9
|
+
|
10
|
+
platforms :ruby do
|
11
|
+
gem 'sqlite3'
|
12
|
+
end
|
13
|
+
|
14
|
+
platforms :jruby do
|
15
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gem 'rails', '~> 6.1.0'
|
6
|
+
gem 'selenium-webdriver'
|
7
|
+
|
8
|
+
gemspec path: '../'
|
9
|
+
|
10
|
+
platforms :ruby do
|
11
|
+
gem 'sqlite3'
|
12
|
+
end
|
13
|
+
|
14
|
+
platforms :jruby do
|
15
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gem 'rails', '~> 7.0.0'
|
6
|
+
gem 'net-smtp'
|
7
|
+
gem 'selenium-webdriver'
|
8
|
+
|
9
|
+
gemspec path: '../'
|
10
|
+
|
11
|
+
platforms :ruby do
|
12
|
+
gem 'sqlite3'
|
13
|
+
end
|
14
|
+
|
15
|
+
platforms :jruby do
|
16
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
17
|
+
end
|
data/gemfiles/rails_edge.gemfile
CHANGED
@@ -10,8 +10,12 @@ module ActionArgs
|
|
10
10
|
return super if !defined?(params) || params.nil?
|
11
11
|
|
12
12
|
strengthen_params! method_name
|
13
|
-
values = extract_method_arguments_from_params method_name
|
14
|
-
|
13
|
+
values, kwargs_values = extract_method_arguments_from_params method_name
|
14
|
+
if kwargs_values.any?
|
15
|
+
super method_name, *values, **kwargs_values
|
16
|
+
else
|
17
|
+
super method_name, *values
|
18
|
+
end
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
@@ -4,65 +4,79 @@ using ActionArgs::ParamsHandler
|
|
4
4
|
|
5
5
|
module ActionArgs
|
6
6
|
module ActiveSupport
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
if Rails::VERSION::MAJOR >= 7
|
8
|
+
module CallTemplate
|
9
|
+
module MethodCallParameterizer
|
10
|
+
def make_lambda
|
11
|
+
lambda do |target, value, &block|
|
12
|
+
if ActionController::Base === target
|
13
|
+
target.strengthen_params! @method_name
|
14
|
+
arguments, keyword_arguments = target.extract_method_arguments_from_params @method_name
|
15
|
+
if keyword_arguments.any?
|
16
|
+
target.send(@method_name, *arguments, **keyword_arguments, &block)
|
17
|
+
else
|
18
|
+
target.send(@method_name, *arguments, &block)
|
19
|
+
end
|
20
|
+
else
|
21
|
+
target.send(@method_name, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
20
25
|
end
|
21
|
-
|
22
|
-
[target, block, method, *arguments]
|
23
26
|
end
|
24
|
-
|
27
|
+
::ActiveSupport::Callbacks::CallTemplate::MethodCall.prepend ActionArgs::ActiveSupport::CallTemplate::MethodCallParameterizer
|
28
|
+
elsif Rails.version >= '5.1'
|
29
|
+
module CallbackParameterizer
|
30
|
+
# Extending AS::Callbacks::Callback's `make_lambda` not just to call specified
|
31
|
+
# method but to call the method with method parameters taken from `params`.
|
32
|
+
# This would happen only when
|
33
|
+
# * the target object is_a ActionController object
|
34
|
+
# * the filter was not defined via lambda
|
35
|
+
def make_lambda
|
36
|
+
lambda do |target, value, &block|
|
37
|
+
target, block, method, *arguments = expand(target, value, block)
|
25
38
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
if Symbol === filter
|
35
|
-
lambda do |target, _, &blk|
|
36
|
-
if ActionController::Base === target
|
37
|
-
target.strengthen_params! filter
|
38
|
-
values = target.extract_method_arguments_from_params filter
|
39
|
-
target.send filter, *values, &blk
|
39
|
+
if (ActionController::Base === target) && (method != :instance_exec) && arguments.empty?
|
40
|
+
target.strengthen_params! method
|
41
|
+
arguments, keyword_arguments = target.extract_method_arguments_from_params method
|
42
|
+
if keyword_arguments.any?
|
43
|
+
target.send(method, *arguments, **keyword_arguments, &block)
|
44
|
+
else
|
45
|
+
target.send(method, *arguments, &block)
|
46
|
+
end
|
40
47
|
else
|
41
|
-
target.send
|
48
|
+
target.send(method, *arguments, &block)
|
42
49
|
end
|
43
50
|
end
|
44
|
-
else
|
45
|
-
super
|
46
51
|
end
|
47
52
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
53
|
+
::ActiveSupport::Callbacks::CallTemplate.prepend ActionArgs::ActiveSupport::CallbackParameterizer
|
54
|
+
else
|
55
|
+
# For Rails 4 & 5.0
|
56
|
+
module CallbackParameterizerLegacy
|
57
|
+
# Extending AS::Callbacks::Callback's `make_lambda` not just to call specified
|
58
|
+
# method but to call the method with method parameters taken from `params`.
|
59
|
+
# This would happen only when
|
60
|
+
# * the filter was defined in Symbol form
|
61
|
+
# * the target object is_a ActionController object
|
62
|
+
def make_lambda(filter)
|
63
|
+
if Symbol === filter
|
64
|
+
lambda do |target, _, &blk|
|
65
|
+
if ActionController::Base === target
|
66
|
+
target.strengthen_params! filter
|
67
|
+
values, kwargs_values = target.extract_method_arguments_from_params filter
|
68
|
+
values << kwargs_values if kwargs_values.any?
|
69
|
+
target.send filter, *values, &blk
|
70
|
+
else
|
71
|
+
target.send filter, &blk
|
72
|
+
end
|
73
|
+
end
|
74
|
+
else
|
75
|
+
super
|
76
|
+
end
|
77
|
+
end
|
65
78
|
end
|
79
|
+
::ActiveSupport::Callbacks::Callback.prepend ActionArgs::ActiveSupport::CallbackParameterizerLegacy
|
66
80
|
end
|
67
81
|
end
|
68
82
|
end
|
data/lib/action_args/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_args
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,8 +59,8 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".github/workflows/main.yml"
|
62
63
|
- ".gitignore"
|
63
|
-
- ".travis.yml"
|
64
64
|
- CONTRIBUTING.md
|
65
65
|
- Gemfile
|
66
66
|
- MIT-LICENSE
|
@@ -72,6 +72,9 @@ files:
|
|
72
72
|
- gemfiles/rails_50.gemfile
|
73
73
|
- gemfiles/rails_51.gemfile
|
74
74
|
- gemfiles/rails_52.gemfile
|
75
|
+
- gemfiles/rails_60.gemfile
|
76
|
+
- gemfiles/rails_61.gemfile
|
77
|
+
- gemfiles/rails_70.gemfile
|
75
78
|
- gemfiles/rails_edge.gemfile
|
76
79
|
- lib/action_args.rb
|
77
80
|
- lib/action_args/abstract_controller.rb
|
@@ -80,23 +83,12 @@ files:
|
|
80
83
|
- lib/action_args/version.rb
|
81
84
|
- lib/generators/rails/action_args_scaffold_controller_generator.rb
|
82
85
|
- lib/generators/rails/templates/controller.rb
|
83
|
-
- test/controllers/action_args_controller_test.rb
|
84
|
-
- test/controllers/hooks_test.rb
|
85
|
-
- test/controllers/kwargs_controller_test.rb
|
86
|
-
- test/controllers/kwargs_keyreq_controller_test.rb
|
87
|
-
- test/controllers/ordinal_controller_test.rb
|
88
|
-
- test/controllers/strong_parameters_test.rb
|
89
|
-
- test/fake_app.rb
|
90
|
-
- test/kwargs_controllers.rb
|
91
|
-
- test/kwargs_keyreq_controllers.rb
|
92
|
-
- test/mailers/action_mailer_test.rb
|
93
|
-
- test/params_handler/params_handler_test.rb
|
94
|
-
- test/test_helper.rb
|
95
86
|
homepage: http://asakusa.rubyist.net/
|
96
87
|
licenses:
|
97
88
|
- MIT
|
98
|
-
metadata:
|
99
|
-
|
89
|
+
metadata:
|
90
|
+
source_code_uri: https://github.com/asakusarb/action_args
|
91
|
+
post_install_message:
|
100
92
|
rdoc_options: []
|
101
93
|
require_paths:
|
102
94
|
- lib
|
@@ -111,21 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
103
|
- !ruby/object:Gem::Version
|
112
104
|
version: '0'
|
113
105
|
requirements: []
|
114
|
-
|
115
|
-
|
116
|
-
signing_key:
|
106
|
+
rubygems_version: 3.3.0.dev
|
107
|
+
signing_key:
|
117
108
|
specification_version: 4
|
118
109
|
summary: Controller action arguments parameterizer for Rails 4+ & Ruby 2.0+
|
119
|
-
test_files:
|
120
|
-
- test/controllers/action_args_controller_test.rb
|
121
|
-
- test/controllers/hooks_test.rb
|
122
|
-
- test/controllers/kwargs_controller_test.rb
|
123
|
-
- test/controllers/kwargs_keyreq_controller_test.rb
|
124
|
-
- test/controllers/ordinal_controller_test.rb
|
125
|
-
- test/controllers/strong_parameters_test.rb
|
126
|
-
- test/fake_app.rb
|
127
|
-
- test/kwargs_controllers.rb
|
128
|
-
- test/kwargs_keyreq_controllers.rb
|
129
|
-
- test/mailers/action_mailer_test.rb
|
130
|
-
- test/params_handler/params_handler_test.rb
|
131
|
-
- test/test_helper.rb
|
110
|
+
test_files: []
|
data/.travis.yml
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
script: 'bundle exec rake -t test'
|
2
|
-
language: ruby
|
3
|
-
sudo: false
|
4
|
-
|
5
|
-
before_install:
|
6
|
-
- "ruby -e 'exit RUBY_VERSION.to_f >= 2.3' && gem up --system || (gem i rubygems-update -v '<3' && update_rubygems)"
|
7
|
-
- gem up bundler
|
8
|
-
|
9
|
-
# rvm:
|
10
|
-
# - 2.6.0
|
11
|
-
# - 2.5.3
|
12
|
-
# - 2.4.5
|
13
|
-
# - 2.3.7
|
14
|
-
# - 2.2.10
|
15
|
-
# - 2.1.10
|
16
|
-
# - 2.0.0
|
17
|
-
# - ruby-head
|
18
|
-
# gemfile:
|
19
|
-
# - gemfiles/rails_52.gemfile
|
20
|
-
# - gemfiles/rails_51.gemfile
|
21
|
-
# - gemfiles/rails_50.gemfile
|
22
|
-
# - gemfiles/rails_42.gemfile
|
23
|
-
# - gemfiles/rails_41.gemfile
|
24
|
-
# - gemfiles/rails_edge.gemfile
|
25
|
-
|
26
|
-
matrix:
|
27
|
-
include:
|
28
|
-
- rvm: 2.6.0
|
29
|
-
gemfile: gemfiles/rails_52.gemfile
|
30
|
-
- rvm: 2.6.0
|
31
|
-
gemfile: gemfiles/rails_51.gemfile
|
32
|
-
- rvm: 2.6.0
|
33
|
-
gemfile: gemfiles/rails_50.gemfile
|
34
|
-
- rvm: 2.6.0
|
35
|
-
gemfile: gemfiles/rails_edge.gemfile
|
36
|
-
- rvm: 2.5.3
|
37
|
-
gemfile: gemfiles/rails_52.gemfile
|
38
|
-
- rvm: 2.4.5
|
39
|
-
gemfile: gemfiles/rails_52.gemfile
|
40
|
-
- rvm: 2.3.8
|
41
|
-
gemfile: gemfiles/rails_52.gemfile
|
42
|
-
- rvm: 2.2.10
|
43
|
-
gemfile: gemfiles/rails_42.gemfile
|
44
|
-
- rvm: 2.2.10
|
45
|
-
gemfile: gemfiles/rails_41.gemfile
|
46
|
-
- rvm: 2.1.10
|
47
|
-
gemfile: gemfiles/rails_42.gemfile
|
48
|
-
- rvm: 2.0.0
|
49
|
-
gemfile: gemfiles/rails_42.gemfile
|
50
|
-
|
51
|
-
- rvm: ruby-head
|
52
|
-
gemfile: gemfiles/rails_52.gemfile
|
53
|
-
- rvm: ruby-head
|
54
|
-
gemfile: gemfiles/rails_edge.gemfile
|
55
|
-
|
56
|
-
- rvm: jruby-9.2.6.0
|
57
|
-
gemfile: gemfiles/rails_52.gemfile
|
58
|
-
- rvm: rubinius-3
|
59
|
-
gemfile: gemfiles/rails_52.gemfile
|
60
|
-
|
61
|
-
allow_failures:
|
62
|
-
- rvm: jruby-9.2.6.0
|
63
|
-
- rvm: rubinius-3
|
64
|
-
- gemfile: gemfiles/rails_edge.gemfile
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class BooksControllerTest < ActionController::TestCase
|
6
|
-
sub_test_case 'GET index (having an optional parameter)' do
|
7
|
-
setup do
|
8
|
-
@books = []
|
9
|
-
Book.delete_all
|
10
|
-
100.times {|i| @books << Book.create!(title: 'book'+i.to_s) }
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'without page parameter' do
|
14
|
-
get :index
|
15
|
-
assert 200, response.code
|
16
|
-
assert_equal @books[0..9], assigns(:books)
|
17
|
-
end
|
18
|
-
|
19
|
-
test 'with page parameter' do
|
20
|
-
get :index, params: {page: 3}
|
21
|
-
assert 200, response.code
|
22
|
-
assert_equal @books[20..29], assigns(:books)
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'first param is nil and second is not nil' do
|
26
|
-
rhg = Book.create! title: 'RHG'
|
27
|
-
Book.create! title: 'AWDwR'
|
28
|
-
get :index, params: {q: 'RH'}
|
29
|
-
assert_equal [rhg], assigns(:books)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
test 'GET show' do
|
34
|
-
rhg = Book.create! title: 'RHG'
|
35
|
-
get :show, params: {id: rhg.id}
|
36
|
-
assert_equal rhg, assigns(:book)
|
37
|
-
end
|
38
|
-
|
39
|
-
test 'POST create' do
|
40
|
-
Book.create! title: 'RHG'
|
41
|
-
books_count_was = Book.count
|
42
|
-
post :create, params: {book: {title: 'AWDwR', price: 24}}
|
43
|
-
assert_equal 1, Book.count - books_count_was
|
44
|
-
end
|
45
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class BooksControllerTest < ActionController::TestCase
|
6
|
-
setup do
|
7
|
-
Book.delete_all
|
8
|
-
@book = Book.create! title: 'Head First ActionArgs'
|
9
|
-
get :show, params: {id: @book.id}
|
10
|
-
end
|
11
|
-
|
12
|
-
sub_test_case 'before_action' do
|
13
|
-
test 'via Symbol' do
|
14
|
-
assert_equal @book, assigns(:book)
|
15
|
-
end
|
16
|
-
|
17
|
-
if Rails.version < '5.1'
|
18
|
-
test 'via String' do
|
19
|
-
assert assigns(:string_filter_executed)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'via Proc' do
|
24
|
-
assert assigns(:proc_filter_executed)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'around_action' do
|
29
|
-
assert_not_nil assigns(:elapsed_time)
|
30
|
-
end
|
31
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class KwBooksControllerTest < ActionController::TestCase
|
6
|
-
sub_test_case 'GET index (having an optional parameter)' do
|
7
|
-
test 'without giving any kw parameter (not even giving :required one)' do
|
8
|
-
assert_raises(ActionController::BadRequest) { get :index }
|
9
|
-
end
|
10
|
-
|
11
|
-
test 'without giving any optional kw parameter' do
|
12
|
-
get :index, params: {author_name: 'nari'}
|
13
|
-
assert 200, response.code
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'with kw parameter defaults to non-nil value' do
|
17
|
-
get :index, params: {author_name: 'nari', page: 3}
|
18
|
-
body = eval response.body
|
19
|
-
assert_equal 'nari', body[:author_name]
|
20
|
-
assert_equal '3', body[:page]
|
21
|
-
assert_nil body[:q]
|
22
|
-
end
|
23
|
-
|
24
|
-
test 'with kw parameter defaults to nil' do
|
25
|
-
get :index, params: {author_name: 'nari', q: 'Rails'}
|
26
|
-
body = eval response.body
|
27
|
-
assert_equal 'nari', body[:author_name]
|
28
|
-
assert_equal '1', body[:page]
|
29
|
-
assert_equal 'Rails', body[:q]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class KwKeyreqBooksControllerTest < ActionController::TestCase
|
6
|
-
sub_test_case 'GET index (having an optional parameter)' do
|
7
|
-
test 'without giving any kw parameter (not even giving :required one)' do
|
8
|
-
assert_raises(ActionController::BadRequest) { get :index }
|
9
|
-
end
|
10
|
-
|
11
|
-
test 'without giving any kw parameter' do
|
12
|
-
get :index, params: {author_name: 'nari'}
|
13
|
-
assert 200, response.code
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'with kw parameter defaults to non-nil value' do
|
17
|
-
get :index, params: {author_name: 'nari', page: 3}
|
18
|
-
body = eval response.body
|
19
|
-
assert_equal 'nari', body[:author_name]
|
20
|
-
assert_equal '3', body[:page]
|
21
|
-
assert_nil body[:q]
|
22
|
-
end
|
23
|
-
|
24
|
-
test 'with kw parameter defaults to nil' do
|
25
|
-
get :index, params: {author_name: 'nari', q: 'Rails'}
|
26
|
-
body = eval response.body
|
27
|
-
assert_equal 'nari', body[:author_name]
|
28
|
-
assert_equal '1', body[:page]
|
29
|
-
assert_equal 'Rails', body[:q]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end if RUBY_VERSION >= '2.1'
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class AuthorsControllerTest < ActionController::TestCase
|
6
|
-
test 'GET show' do
|
7
|
-
matz = Author.create! name: 'Matz'
|
8
|
-
get :show, params: {id: matz.id}
|
9
|
-
assert_equal matz, assigns(:author)
|
10
|
-
end
|
11
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class StoresControllerTest < ActionController::TestCase
|
6
|
-
test 'GET show' do
|
7
|
-
tatsu_zine = Store.create! name: 'Tatsu-zine'
|
8
|
-
get :show, params: {id: tatsu_zine.id}
|
9
|
-
|
10
|
-
assert_equal tatsu_zine, assigns(:store)
|
11
|
-
end
|
12
|
-
|
13
|
-
sub_test_case 'GET new' do
|
14
|
-
test 'without store parameter' do
|
15
|
-
get :new
|
16
|
-
assert 200, response.code
|
17
|
-
assert_equal 'PragProg', assigns(:store).name
|
18
|
-
end
|
19
|
-
test 'with store parameter' do
|
20
|
-
get :new, params: {store: {name: 'Tatsu-zine'}}
|
21
|
-
assert 200, response.code
|
22
|
-
assert_equal 'Tatsu-zine', assigns(:store).name
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'POST create' do
|
27
|
-
store_count_was = Store.count
|
28
|
-
post :create, params: {store: {name: 'Tatsu-zine', url: 'http://tatsu-zine.com'}}
|
29
|
-
|
30
|
-
assert_equal 1, Store.count - store_count_was
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class MoviesControllerTest < ActionController::TestCase
|
35
|
-
test 'POST create' do
|
36
|
-
movie_count_was = Movie.count
|
37
|
-
post :create, params: {movie: {title: 'Dr. No', actors_attributes: [{name: 'Bernard Lee'}]}}
|
38
|
-
|
39
|
-
assert_equal 1, Movie.count - movie_count_was
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# this controller doesn't permit price of new book do
|
44
|
-
class Admin::BooksControllerTest < ActionController::TestCase
|
45
|
-
test 'POST create' do
|
46
|
-
post :create, params: {book: {title: 'naruhoUnix', price: 30}}
|
47
|
-
|
48
|
-
assert_nil Book.last.price
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class Admin::AccountsControllerTest < ActionController::TestCase
|
53
|
-
test 'POST create' do
|
54
|
-
admin_account_count_was = Admin::Account.count
|
55
|
-
post :create, params: {admin_account: {name: 'amatsuda'}}
|
56
|
-
|
57
|
-
assert_equal 1, Admin::Account.count - admin_account_count_was
|
58
|
-
end
|
59
|
-
end
|
data/test/fake_app.rb
DELETED
@@ -1,193 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
# config
|
5
|
-
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
6
|
-
|
7
|
-
module ActionArgsTestApp
|
8
|
-
class Application < Rails::Application
|
9
|
-
config.secret_key_base = config.secret_token = [*'A'..'z'].join
|
10
|
-
config.session_store :cookie_store, :key => '_myapp_session'
|
11
|
-
config.active_support.deprecation = :log
|
12
|
-
config.eager_load = false
|
13
|
-
end
|
14
|
-
end
|
15
|
-
ActionArgsTestApp::Application.initialize!
|
16
|
-
|
17
|
-
# routes
|
18
|
-
ActionArgsTestApp::Application.routes.draw do
|
19
|
-
resources :authors
|
20
|
-
resources :books
|
21
|
-
resources :kw_books # 2.0+ only
|
22
|
-
resources :kw_keyreq_books # 2.1+ only
|
23
|
-
resources :stores
|
24
|
-
resources :movies
|
25
|
-
|
26
|
-
namespace :admin do
|
27
|
-
resources :accounts
|
28
|
-
resources :books
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# models
|
33
|
-
class Author < ActiveRecord::Base
|
34
|
-
end
|
35
|
-
class Book < ActiveRecord::Base
|
36
|
-
end
|
37
|
-
class Store < ActiveRecord::Base
|
38
|
-
end
|
39
|
-
class Movie < ActiveRecord::Base
|
40
|
-
has_many :actors
|
41
|
-
accepts_nested_attributes_for :actors
|
42
|
-
end
|
43
|
-
class Actor < ActiveRecord::Base
|
44
|
-
belongs_to :movie
|
45
|
-
end
|
46
|
-
module Admin
|
47
|
-
def self.table_name_prefix() 'admin_' end
|
48
|
-
class Account < ActiveRecord::Base
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# mailers
|
53
|
-
require "action_mailer/railtie"
|
54
|
-
class UserMailer < ActionMailer::Base
|
55
|
-
def send_email_without_args
|
56
|
-
mail(
|
57
|
-
to: 'to@example.com',
|
58
|
-
from: 'from@example.com',
|
59
|
-
subject: 'Action Args!!!',
|
60
|
-
body: 'test'
|
61
|
-
)
|
62
|
-
end
|
63
|
-
|
64
|
-
def send_email_with_optional_args(subject = 'Action Args!!!')
|
65
|
-
mail(
|
66
|
-
to: 'to@example.com',
|
67
|
-
from: 'from@example.com',
|
68
|
-
subject: subject,
|
69
|
-
body: 'test'
|
70
|
-
)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# helpers
|
75
|
-
module ApplicationHelper; end
|
76
|
-
|
77
|
-
# controllers
|
78
|
-
class ApplicationController < ActionController::Base
|
79
|
-
end
|
80
|
-
class AuthorsController < ApplicationController
|
81
|
-
def show
|
82
|
-
@author = Author.find params[:id]
|
83
|
-
render plain: @author.name
|
84
|
-
end
|
85
|
-
end
|
86
|
-
class BooksController < ApplicationController
|
87
|
-
before_action :set_book, only: :show
|
88
|
-
before_action -> { @proc_filter_executed = true }, only: :show
|
89
|
-
if Rails.version < '5.1'
|
90
|
-
before_action '@string_filter_executed = true', only: :show
|
91
|
-
end
|
92
|
-
around_action :benchmark_action
|
93
|
-
before_action :omg
|
94
|
-
skip_before_action :omg
|
95
|
-
|
96
|
-
# optional parameter
|
97
|
-
def index(page = 1, q = nil, limit = 10)
|
98
|
-
@books = Book.limit(limit.to_i).offset(([page.to_i - 1, 0].max) * 10)
|
99
|
-
@books = @books.where('title like ?', "%#{q}%") unless q.blank?
|
100
|
-
render plain: 'index', books: @books
|
101
|
-
end
|
102
|
-
|
103
|
-
def show(id)
|
104
|
-
render plain: @book.title
|
105
|
-
end
|
106
|
-
|
107
|
-
def create(book)
|
108
|
-
book = book.permit :title, :price
|
109
|
-
@book = Book.create! book
|
110
|
-
render plain: @book.title
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
def set_book(id)
|
115
|
-
@book = Book.find(id)
|
116
|
-
end
|
117
|
-
|
118
|
-
def benchmark_action
|
119
|
-
start = Time.now
|
120
|
-
yield
|
121
|
-
@elapsed_time = Time.now - start
|
122
|
-
end
|
123
|
-
|
124
|
-
def omg
|
125
|
-
raise '💣'
|
126
|
-
end
|
127
|
-
end
|
128
|
-
class MoviesController < ApplicationController
|
129
|
-
permits :title, actors_attributes: [:name]
|
130
|
-
|
131
|
-
def create(movie)
|
132
|
-
@movie = Movie.create! movie
|
133
|
-
render plain: @movie.title
|
134
|
-
end
|
135
|
-
end
|
136
|
-
class StoresController < ApplicationController
|
137
|
-
permits :name, :url
|
138
|
-
|
139
|
-
def show(id)
|
140
|
-
@store = Store.find(id)
|
141
|
-
render plain: @store.name
|
142
|
-
end
|
143
|
-
|
144
|
-
def new(store = {name: 'PragProg'})
|
145
|
-
@store = Store.new store
|
146
|
-
render plain: @store.name
|
147
|
-
end
|
148
|
-
|
149
|
-
def create(store)
|
150
|
-
@store = Store.create! store
|
151
|
-
render plain: @store.name
|
152
|
-
end
|
153
|
-
end
|
154
|
-
module Admin
|
155
|
-
class AccountsController < ::ApplicationController
|
156
|
-
permits :name, model_name: 'Admin::Account'
|
157
|
-
|
158
|
-
def create(admin_account)
|
159
|
-
@admin_account = Admin::Account.create! admin_account
|
160
|
-
render plain: @admin_account.name
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
class BooksController < ::ApplicationController
|
165
|
-
permits :title
|
166
|
-
|
167
|
-
def create(book)
|
168
|
-
@book = Book.create! book
|
169
|
-
render plain: @book.title
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
require_relative 'kwargs_controllers'
|
175
|
-
require_relative 'kwargs_keyreq_controllers' if RUBY_VERSION >= '2.1'
|
176
|
-
|
177
|
-
# migrations
|
178
|
-
class CreateAllTables < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
|
179
|
-
def self.up
|
180
|
-
create_table(:authors) {|t| t.string :name}
|
181
|
-
create_table(:books) {|t| t.string :title; t.integer :price}
|
182
|
-
create_table(:stores) {|t| t.string :name; t.string :url}
|
183
|
-
create_table(:admin_accounts) {|t| t.string :name}
|
184
|
-
create_table(:movies) {|t| t.string :title}
|
185
|
-
create_table(:actors) {|t| t.string :name; t.references :movie}
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
if ActiveRecord::Base.connection.respond_to? :data_source_exists?
|
190
|
-
CreateAllTables.up unless ActiveRecord::Base.connection.data_source_exists? 'authors'
|
191
|
-
else
|
192
|
-
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'authors'
|
193
|
-
end
|
data/test/kwargs_controllers.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# this file should not be loaded from Ruby <2.0
|
4
|
-
|
5
|
-
class KwBooksController < ApplicationController
|
6
|
-
# keyword arguments
|
7
|
-
def index(author_name, page: '1', q: nil)
|
8
|
-
render plain: {author_name: author_name, page: page, q: q}.inspect
|
9
|
-
end
|
10
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# this file should not be loaded from Ruby <2.1
|
4
|
-
|
5
|
-
class KwKeyreqBooksController < ApplicationController
|
6
|
-
# keyword arguments
|
7
|
-
def index(author_name:, page: '1', q: nil)
|
8
|
-
render plain: {author_name: author_name, page: page, q: q}.inspect
|
9
|
-
end
|
10
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class UserMailerTest < ActionMailer::TestCase
|
6
|
-
test '#send_email_without_args' do
|
7
|
-
#it should not raise NameError: undefined local variable or method `params' for ...
|
8
|
-
assert UserMailer.send_email_without_args
|
9
|
-
end
|
10
|
-
|
11
|
-
test '#send_email_with_optional_args' do
|
12
|
-
#it should not raise NoMethodError: undefined method for nil:NilClass
|
13
|
-
assert UserMailer.send_email_with_optional_args
|
14
|
-
end
|
15
|
-
end
|
@@ -1,256 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
using ActionArgs::ParamsHandler
|
5
|
-
|
6
|
-
class ActionArgs::ParamsHandlerTest < ActiveSupport::TestCase
|
7
|
-
sub_test_case 'extract_method_arguments_from_params' do
|
8
|
-
setup do
|
9
|
-
params = {a: '1', b: '2'}
|
10
|
-
@controller = Class.new(ApplicationController).new.tap {|c| c.params = params }
|
11
|
-
end
|
12
|
-
test 'no parameters' do
|
13
|
-
def @controller.m() end
|
14
|
-
|
15
|
-
assert_equal [], @controller.extract_method_arguments_from_params(:m)
|
16
|
-
end
|
17
|
-
|
18
|
-
test '1 req' do
|
19
|
-
def @controller.m(a) end
|
20
|
-
|
21
|
-
assert_equal ['1'], @controller.extract_method_arguments_from_params(:m)
|
22
|
-
end
|
23
|
-
|
24
|
-
test '1 req with args named like strong parameters' do
|
25
|
-
def @controller.m(a_params) end
|
26
|
-
|
27
|
-
assert_equal ['1'], @controller.extract_method_arguments_from_params(:m)
|
28
|
-
end
|
29
|
-
|
30
|
-
test '2 reqs' do
|
31
|
-
def @controller.m(a, b) end
|
32
|
-
|
33
|
-
assert_equal ['1', '2'], @controller.extract_method_arguments_from_params(:m)
|
34
|
-
end
|
35
|
-
|
36
|
-
test '2 reqs with args named like strong parameters' do
|
37
|
-
def @controller.m(a_params, b_params) end
|
38
|
-
|
39
|
-
assert_equal ['1', '2'], @controller.extract_method_arguments_from_params(:m)
|
40
|
-
end
|
41
|
-
|
42
|
-
test '1 opt with value' do
|
43
|
-
def @controller.m(a = 'a') end
|
44
|
-
|
45
|
-
assert_equal ['1'], @controller.extract_method_arguments_from_params(:m)
|
46
|
-
end
|
47
|
-
|
48
|
-
test '1 opt with value with args named like strong parameters' do
|
49
|
-
def @controller.m(a_params = 'a') end
|
50
|
-
|
51
|
-
assert_equal ['1'], @controller.extract_method_arguments_from_params(:m)
|
52
|
-
end
|
53
|
-
|
54
|
-
test '1 opt without value' do
|
55
|
-
def @controller.m(x = 'x') end
|
56
|
-
|
57
|
-
assert_equal [], @controller.extract_method_arguments_from_params(:m)
|
58
|
-
end
|
59
|
-
|
60
|
-
test 'req, opt with value' do
|
61
|
-
def @controller.m(a, b = 'b') end
|
62
|
-
|
63
|
-
assert_equal ['1', '2'], @controller.extract_method_arguments_from_params(:m)
|
64
|
-
end
|
65
|
-
|
66
|
-
test 'req, opt without value' do
|
67
|
-
def @controller.m(a, x = 'x') end
|
68
|
-
|
69
|
-
assert_equal ['1'], @controller.extract_method_arguments_from_params(:m)
|
70
|
-
end
|
71
|
-
|
72
|
-
test 'opt with value, opt with value' do
|
73
|
-
def @controller.m(a = 'a', b = 'b') end
|
74
|
-
|
75
|
-
assert_equal ['1', '2'], @controller.extract_method_arguments_from_params(:m)
|
76
|
-
end
|
77
|
-
|
78
|
-
test 'opt with value, opt without value' do
|
79
|
-
def @controller.m(a = 'a', x = 'x') end
|
80
|
-
|
81
|
-
assert_equal ['1'], @controller.extract_method_arguments_from_params(:m)
|
82
|
-
end
|
83
|
-
|
84
|
-
test 'opt without value, opt with value' do
|
85
|
-
def @controller.m(x = 'x', a = 'a') end
|
86
|
-
|
87
|
-
assert_equal [nil, '1'], @controller.extract_method_arguments_from_params(:m)
|
88
|
-
end
|
89
|
-
|
90
|
-
test 'opt without value, opt without value' do
|
91
|
-
def @controller.m(x = 'x', y = 'y') end
|
92
|
-
|
93
|
-
assert_equal [], @controller.extract_method_arguments_from_params(:m)
|
94
|
-
end
|
95
|
-
|
96
|
-
test 'opt with value, req' do
|
97
|
-
def @controller.m(a = 'a', b) end
|
98
|
-
|
99
|
-
assert_equal ['1', '2'], @controller.extract_method_arguments_from_params(:m)
|
100
|
-
end
|
101
|
-
|
102
|
-
test 'opt without value, req' do
|
103
|
-
def @controller.m(x = 'x', a) end
|
104
|
-
|
105
|
-
assert_equal ['1'], @controller.extract_method_arguments_from_params(:m)
|
106
|
-
end
|
107
|
-
|
108
|
-
test 'opt without value, opt with value, req' do
|
109
|
-
def @controller.m(x = 'x', b = 'b', a) end
|
110
|
-
|
111
|
-
assert_equal [nil, '2', '1'], @controller.extract_method_arguments_from_params(:m)
|
112
|
-
end
|
113
|
-
|
114
|
-
test 'opt with value, opt without value, req' do
|
115
|
-
def @controller.m(b = 'b', x = 'x', a) end
|
116
|
-
|
117
|
-
assert_equal ['2', '1'], @controller.extract_method_arguments_from_params(:m)
|
118
|
-
end
|
119
|
-
|
120
|
-
test 'req without a value' do
|
121
|
-
def @controller.m(x) end
|
122
|
-
|
123
|
-
assert_raises(ActionController::BadRequest) { @controller.extract_method_arguments_from_params(:m) }
|
124
|
-
end
|
125
|
-
|
126
|
-
test 'key' do
|
127
|
-
def @controller.m(a: nil) end
|
128
|
-
|
129
|
-
assert_equal [a: '1'], @controller.extract_method_arguments_from_params(:m)
|
130
|
-
end
|
131
|
-
|
132
|
-
test 'key with args named like strong parameters' do
|
133
|
-
def @controller.m(a_params: nil) end
|
134
|
-
|
135
|
-
assert_equal [a_params: '1'], @controller.extract_method_arguments_from_params(:m)
|
136
|
-
end
|
137
|
-
|
138
|
-
test 'key, key without value' do
|
139
|
-
def @controller.m(a: nil, x: 'x') end
|
140
|
-
|
141
|
-
assert_equal [a: '1'], @controller.extract_method_arguments_from_params(:m)
|
142
|
-
end
|
143
|
-
|
144
|
-
if RUBY_VERSION >= '2.1'
|
145
|
-
eval <<-KWARGS_KEYREQ_TEST
|
146
|
-
test 'keyreq' do
|
147
|
-
def @controller.m(a:) end
|
148
|
-
|
149
|
-
assert_equal [a: '1'], @controller.extract_method_arguments_from_params(:m)
|
150
|
-
end
|
151
|
-
|
152
|
-
test 'keyreq with args named like strong parameters' do
|
153
|
-
def @controller.m(a_params:) end
|
154
|
-
|
155
|
-
assert_equal [a_params: '1'], @controller.extract_method_arguments_from_params(:m)
|
156
|
-
end
|
157
|
-
|
158
|
-
test 'keyreq, keyreq without value' do
|
159
|
-
def @controller.m(a:, x:) end
|
160
|
-
|
161
|
-
assert_raises(ActionController::BadRequest) { @controller.extract_method_arguments_from_params(:m) }
|
162
|
-
end
|
163
|
-
KWARGS_KEYREQ_TEST
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
sub_test_case 'strengthen_params!' do
|
168
|
-
setup do
|
169
|
-
@params = ActionController::Parameters.new(x: '1', y: '2', foo: {a: 'a', b: 'b'}, bar: {a: 'a', b: 'b'}, baz: {a: 'a', b: 'b'}, hoge: {a: 'a', b: 'b'}, fuga: {a: 'a', b: 'b'}, foo_foo: {a: 'a', b: 'b'}, hoge_hoge: {a: 'a', b: 'b'}, fuga_fuga: {a: 'a', b: 'b'})
|
170
|
-
end
|
171
|
-
|
172
|
-
def execute_strengthen_params!(controller)
|
173
|
-
c = controller.new
|
174
|
-
c.instance_variable_set :@_params, @params
|
175
|
-
c.strengthen_params! :a
|
176
|
-
end
|
177
|
-
|
178
|
-
test 'requiring via :req, permitting all scalars' do
|
179
|
-
execute_strengthen_params! FooController ||= Class.new(ApplicationController) { permits :a, :b; def a(foo) end }
|
180
|
-
|
181
|
-
assert @params[:foo].permitted?
|
182
|
-
assert_not_nil @params[:foo][:a]
|
183
|
-
assert_not_nil @params[:foo][:b]
|
184
|
-
end
|
185
|
-
|
186
|
-
test 'requiring via :req, permitting all scalars with args named like strong parameters' do
|
187
|
-
execute_strengthen_params! FooFooController ||= Class.new(ApplicationController) { permits :a, :b; def a(foo_foo_params) end }
|
188
|
-
|
189
|
-
assert @params[:foo_foo].permitted?
|
190
|
-
assert_not_nil @params[:foo_foo][:a]
|
191
|
-
assert_not_nil @params[:foo_foo][:b]
|
192
|
-
end
|
193
|
-
|
194
|
-
test 'requiring via :req, not permitting all scalars' do
|
195
|
-
execute_strengthen_params! BarController ||= Class.new(ApplicationController) { permits :a; def a(bar, x = 'x') end }
|
196
|
-
|
197
|
-
assert @params[:bar].permitted?
|
198
|
-
assert_not_nil @params[:bar][:a]
|
199
|
-
assert_nil @params[:bar][:b]
|
200
|
-
end
|
201
|
-
|
202
|
-
test 'requiring via :req, not permitting any scalars' do
|
203
|
-
execute_strengthen_params! BazController ||= Class.new(ApplicationController) { def a(baz, aho = 'omg') end }
|
204
|
-
|
205
|
-
refute @params[:baz].permitted?
|
206
|
-
end
|
207
|
-
|
208
|
-
test 'requiring via :opt, permitting all scalars' do
|
209
|
-
execute_strengthen_params! HogeController ||= Class.new(ApplicationController) { permits :a, :b; def a(hoge = {}) end }
|
210
|
-
|
211
|
-
assert @params[:hoge].permitted?
|
212
|
-
assert_not_nil @params[:hoge][:a]
|
213
|
-
assert_not_nil @params[:hoge][:b]
|
214
|
-
end
|
215
|
-
|
216
|
-
test 'requiring via :opt, permitting all scalars with args named like strong parameters' do
|
217
|
-
execute_strengthen_params! HogeHogeController ||= Class.new(ApplicationController) { permits :a, :b; def a(hoge_hoge_params = {}) end }
|
218
|
-
|
219
|
-
assert @params[:hoge_hoge].permitted?
|
220
|
-
assert_not_nil @params[:hoge_hoge][:a]
|
221
|
-
assert_not_nil @params[:hoge_hoge][:b]
|
222
|
-
end
|
223
|
-
|
224
|
-
test 'requiring via :key, permitting all scalars' do
|
225
|
-
execute_strengthen_params! FugaController ||= Class.new(ApplicationController) { permits :a, :b; def a(fuga: {}) end }
|
226
|
-
|
227
|
-
assert @params[:fuga].permitted?
|
228
|
-
assert_not_nil @params[:fuga][:a]
|
229
|
-
assert_not_nil @params[:fuga][:b]
|
230
|
-
end
|
231
|
-
|
232
|
-
test 'requiring via :key, permitting all scalars with args named like strong parameters' do
|
233
|
-
execute_strengthen_params! FugaFugaController ||= Class.new(ApplicationController) { permits :a, :b; def a(fuga_fuga_params: {}) end }
|
234
|
-
|
235
|
-
assert @params[:fuga_fuga].permitted?
|
236
|
-
assert_not_nil @params[:fuga_fuga][:a]
|
237
|
-
assert_not_nil @params[:fuga_fuga][:b]
|
238
|
-
end
|
239
|
-
|
240
|
-
test '"model_name" option' do
|
241
|
-
execute_strengthen_params! PiyoController ||= Class.new(ApplicationController) { permits :a, :b, model_name: 'Foo'; def a(foo) end }
|
242
|
-
|
243
|
-
assert @params[:foo].permitted?
|
244
|
-
assert_not_nil @params[:foo][:a]
|
245
|
-
assert_not_nil @params[:foo][:b]
|
246
|
-
end
|
247
|
-
|
248
|
-
test '"model_name" option with args named like strong parameters' do
|
249
|
-
execute_strengthen_params! PiyoPiyoController = Class.new(ApplicationController) { permits :a, :b, model_name: 'Foo'; def a(foo_params) end }
|
250
|
-
|
251
|
-
assert @params[:foo].permitted?
|
252
|
-
assert_not_nil @params[:foo][:a]
|
253
|
-
assert_not_nil @params[:foo][:b]
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
-
# load Rails first
|
6
|
-
require 'rails'
|
7
|
-
require 'active_record'
|
8
|
-
require 'action_controller/railtie'
|
9
|
-
begin
|
10
|
-
require 'rails-controller-testing'
|
11
|
-
rescue LoadError
|
12
|
-
end
|
13
|
-
require 'action_args'
|
14
|
-
require 'fake_app'
|
15
|
-
require 'test/unit/rails/test_help'
|
16
|
-
Bundler.require
|
17
|
-
|
18
|
-
if Rails.version < '5'
|
19
|
-
module ActionControllerTestingMonkey
|
20
|
-
def get(path, params: nil, session: nil)
|
21
|
-
super path, params, session
|
22
|
-
end
|
23
|
-
|
24
|
-
def post(path, params: nil, session: nil)
|
25
|
-
super path, params, session
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
ActionController::TestCase.send :prepend, ActionControllerTestingMonkey
|
30
|
-
end
|