action_args 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +24 -16
- data/README.md +2 -2
- data/action_args.gemspec +6 -3
- data/gemfiles/rails_61.gemfile +16 -0
- data/lib/action_args/callbacks.rb +15 -9
- data/lib/action_args/version.rb +1 -1
- metadata +10 -32
- 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 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8be56bb5bd7e6183a1f68f1cfeb7baa5da32287d11a50dddc53248561755ee1c
|
4
|
+
data.tar.gz: 14b0d9da9608f4d0cdc465039d202eb35eabb2abe7471f12cdf28af205d0bd01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a112b0b811700d98a8f5c65958d1f9566b0401bcb885bcd160f2d6d7fdcbbc47b55b72e8b3258f9f3c6a461e3256e5d4c97409fe2ccc3373fbdb2deb5db55d4
|
7
|
+
data.tar.gz: d10fdf287ee66df67eee06cfd9c515bbaab7567cac69a84dbbdf11732ca86609ecafc7d437e3e2c89dff9b4001f9757edc4887061cc5d0c3d606d68629850ed6
|
data/.travis.yml
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
script: 'bundle exec rake -t test'
|
2
2
|
language: ruby
|
3
3
|
|
4
|
+
cache: bundler
|
5
|
+
|
4
6
|
before_install:
|
5
7
|
- "ruby -e 'exit RUBY_VERSION.to_f >= 2.3' && gem up --system || (gem i rubygems-update -v '<3' && update_rubygems)"
|
6
8
|
- gem up bundler
|
7
9
|
|
8
10
|
# rvm:
|
9
|
-
# - 2.6.
|
10
|
-
# - 2.5.
|
11
|
+
# - 2.6.7
|
12
|
+
# - 2.5.9
|
11
13
|
# - 2.4.10
|
12
14
|
# - 2.3.8
|
13
15
|
# - 2.2.10
|
@@ -24,21 +26,27 @@ before_install:
|
|
24
26
|
|
25
27
|
matrix:
|
26
28
|
include:
|
27
|
-
- rvm:
|
28
|
-
gemfile: gemfiles/
|
29
|
-
- rvm:
|
29
|
+
- rvm: 3.0.1
|
30
|
+
gemfile: gemfiles/rails_61.gemfile
|
31
|
+
- rvm: 3.0.1
|
30
32
|
gemfile: gemfiles/rails_60.gemfile
|
31
|
-
- rvm:
|
33
|
+
- rvm: 3.0.1
|
34
|
+
gemfile: gemfiles/rails_edge.gemfile
|
35
|
+
- rvm: 2.7.3
|
36
|
+
gemfile: gemfiles/rails_61.gemfile
|
37
|
+
- rvm: 2.7.3
|
38
|
+
gemfile: gemfiles/rails_edge.gemfile
|
39
|
+
- rvm: 2.6.7
|
40
|
+
gemfile: gemfiles/rails_61.gemfile
|
41
|
+
- rvm: 2.6.7
|
32
42
|
gemfile: gemfiles/rails_52.gemfile
|
33
|
-
- rvm: 2.6.
|
43
|
+
- rvm: 2.6.7
|
34
44
|
gemfile: gemfiles/rails_51.gemfile
|
35
|
-
- rvm: 2.6.
|
45
|
+
- rvm: 2.6.7
|
36
46
|
gemfile: gemfiles/rails_50.gemfile
|
37
|
-
- rvm: 2.
|
38
|
-
gemfile: gemfiles/
|
39
|
-
- rvm: 2.5.
|
40
|
-
gemfile: gemfiles/rails_60.gemfile
|
41
|
-
- rvm: 2.5.8
|
47
|
+
- rvm: 2.5.9
|
48
|
+
gemfile: gemfiles/rails_61.gemfile
|
49
|
+
- rvm: 2.5.9
|
42
50
|
gemfile: gemfiles/rails_52.gemfile
|
43
51
|
- rvm: 2.4.10
|
44
52
|
gemfile: gemfiles/rails_52.gemfile
|
@@ -54,17 +62,17 @@ matrix:
|
|
54
62
|
gemfile: gemfiles/rails_42.gemfile
|
55
63
|
|
56
64
|
- rvm: ruby-head
|
57
|
-
gemfile: gemfiles/
|
65
|
+
gemfile: gemfiles/rails_61.gemfile
|
58
66
|
- rvm: ruby-head
|
59
67
|
gemfile: gemfiles/rails_edge.gemfile
|
60
68
|
|
61
|
-
- rvm: jruby-9.2.
|
69
|
+
- rvm: jruby-9.2.17.0
|
62
70
|
gemfile: gemfiles/rails_52.gemfile
|
63
71
|
- rvm: rubinius-3
|
64
72
|
gemfile: gemfiles/rails_52.gemfile
|
65
73
|
|
66
74
|
allow_failures:
|
67
75
|
- rvm: ruby-head
|
68
|
-
- rvm: jruby-9.2.
|
76
|
+
- rvm: jruby-9.2.17.0
|
69
77
|
- rvm: rubinius-3
|
70
78
|
- gemfile: gemfiles/rails_edge.gemfile
|
data/README.md
CHANGED
@@ -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.x,
|
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, 6.1 (edge)
|
252
|
+
* Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0 (edge)
|
253
253
|
|
254
254
|
For Rails 4.0.x, please use Version 1.5.4.
|
255
255
|
|
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'
|
@@ -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
|
@@ -6,21 +6,27 @@ module ActionArgs
|
|
6
6
|
module ActiveSupport
|
7
7
|
# For Rails >= 5.1
|
8
8
|
module CallbackParameterizer
|
9
|
-
# Extending AS::Callbacks::Callback's `
|
9
|
+
# Extending AS::Callbacks::Callback's `make_lambda` not just to call specified
|
10
10
|
# method but to call the method with method parameters taken from `params`.
|
11
11
|
# This would happen only when
|
12
12
|
# * the target object is_a ActionController object
|
13
13
|
# * the filter was not defined via lambda
|
14
|
-
def
|
15
|
-
target,
|
14
|
+
def make_lambda
|
15
|
+
lambda do |target, value, &block|
|
16
|
+
target, block, method, *arguments = expand(target, value, block)
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
if (ActionController::Base === target) && (method != :instance_exec) && arguments.empty?
|
19
|
+
target.strengthen_params! method
|
20
|
+
arguments, keyword_arguments = target.extract_method_arguments_from_params method
|
21
|
+
if keyword_arguments.any?
|
22
|
+
target.send(method, *arguments, **keyword_arguments, &block)
|
23
|
+
else
|
24
|
+
target.send(method, *arguments, &block)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
target.send(method, *arguments, &block)
|
28
|
+
end
|
21
29
|
end
|
22
|
-
|
23
|
-
[target, block, method, *arguments]
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
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.6.0
|
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-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- gemfiles/rails_51.gemfile
|
74
74
|
- gemfiles/rails_52.gemfile
|
75
75
|
- gemfiles/rails_60.gemfile
|
76
|
+
- gemfiles/rails_61.gemfile
|
76
77
|
- gemfiles/rails_edge.gemfile
|
77
78
|
- lib/action_args.rb
|
78
79
|
- lib/action_args/abstract_controller.rb
|
@@ -81,23 +82,12 @@ files:
|
|
81
82
|
- lib/action_args/version.rb
|
82
83
|
- lib/generators/rails/action_args_scaffold_controller_generator.rb
|
83
84
|
- lib/generators/rails/templates/controller.rb
|
84
|
-
- test/controllers/action_args_controller_test.rb
|
85
|
-
- test/controllers/hooks_test.rb
|
86
|
-
- test/controllers/kwargs_controller_test.rb
|
87
|
-
- test/controllers/kwargs_keyreq_controller_test.rb
|
88
|
-
- test/controllers/ordinal_controller_test.rb
|
89
|
-
- test/controllers/strong_parameters_test.rb
|
90
|
-
- test/fake_app.rb
|
91
|
-
- test/kwargs_controllers.rb
|
92
|
-
- test/kwargs_keyreq_controllers.rb
|
93
|
-
- test/mailers/action_mailer_test.rb
|
94
|
-
- test/params_handler/params_handler_test.rb
|
95
|
-
- test/test_helper.rb
|
96
85
|
homepage: http://asakusa.rubyist.net/
|
97
86
|
licenses:
|
98
87
|
- MIT
|
99
|
-
metadata:
|
100
|
-
|
88
|
+
metadata:
|
89
|
+
source_code_uri: https://github.com/asakusarb/action_args
|
90
|
+
post_install_message:
|
101
91
|
rdoc_options: []
|
102
92
|
require_paths:
|
103
93
|
- lib
|
@@ -112,20 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
102
|
- !ruby/object:Gem::Version
|
113
103
|
version: '0'
|
114
104
|
requirements: []
|
115
|
-
rubygems_version: 3.2.
|
116
|
-
signing_key:
|
105
|
+
rubygems_version: 3.2.15
|
106
|
+
signing_key:
|
117
107
|
specification_version: 4
|
118
108
|
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
|
109
|
+
test_files: []
|
@@ -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,35 +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
|
-
require 'action_args'
|
10
|
-
require 'fake_app'
|
11
|
-
require 'test/unit/rails/test_help'
|
12
|
-
Bundler.require
|
13
|
-
|
14
|
-
module ActionController::TestCase::Assigns
|
15
|
-
def assigns(key = nil)
|
16
|
-
assigns = {}.with_indifferent_access
|
17
|
-
@controller.view_assigns.each { |k, v| assigns.regular_writer(k, v) }
|
18
|
-
key.nil? ? assigns : assigns[key]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
ActionController::TestCase.include ActionController::TestCase::Assigns
|
22
|
-
|
23
|
-
if Rails.version < '5'
|
24
|
-
module ActionControllerTestingMonkey
|
25
|
-
def get(path, params: nil, session: nil)
|
26
|
-
super path, params, session
|
27
|
-
end
|
28
|
-
|
29
|
-
def post(path, params: nil, session: nil)
|
30
|
-
super path, params, session
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
ActionController::TestCase.send :prepend, ActionControllerTestingMonkey
|
35
|
-
end
|