action_args 2.1.0 → 2.2.0
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/.travis.yml +20 -10
- data/Gemfile +1 -0
- data/README.md +2 -2
- data/action_args.gemspec +1 -0
- data/gemfiles/rails_41.gemfile +2 -0
- data/gemfiles/rails_42.gemfile +2 -0
- data/gemfiles/rails_50.gemfile +8 -2
- data/gemfiles/rails_51.gemfile +21 -0
- data/gemfiles/rails_edge.gemfile +7 -1
- data/lib/action_args.rb +1 -0
- data/lib/action_args/abstract_controller.rb +3 -6
- data/lib/action_args/callbacks.rb +52 -21
- data/lib/action_args/params_handler.rb +1 -0
- data/lib/action_args/version.rb +2 -1
- data/lib/generators/rails/action_args_scaffold_controller_generator.rb +1 -0
- data/test/controllers/action_args_controller_test.rb +1 -0
- data/test/controllers/hooks_test.rb +5 -2
- data/test/controllers/kwargs_controller_test.rb +1 -0
- data/test/controllers/kwargs_keyreq_controller_test.rb +1 -0
- data/test/controllers/ordinal_controller_test.rb +1 -0
- data/test/controllers/strong_parameters_test.rb +1 -0
- data/test/fake_app.rb +5 -2
- data/test/kwargs_controllers.rb +1 -0
- data/test/kwargs_keyreq_controllers.rb +1 -0
- data/test/mailers/action_mailer_test.rb +1 -0
- data/test/params_handler/params_handler_test.rb +1 -0
- data/test/test_helper.rb +5 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f9cb11e1b130b2399db5822b438360194f84367e
|
|
4
|
+
data.tar.gz: 9206b615c8d47577a55fc1e30e5ee4958842546f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c0e862e70f26c6fd50866fc95021c418f749e03b6b4ff9ae01a20d537e1744f29f73c7f8a79913cb99beeffdeaf9123ea9cb0148149ad9b9f7ccb606abcec83
|
|
7
|
+
data.tar.gz: e47c8285b8a7aae7e568cc91745607c03a6c43ff456955b7d8d608c374e41f9c999ba62e11861973a80864009b157d2a2b5d6d324c51f18ebd98027632382464
|
data/.travis.yml
CHANGED
|
@@ -5,30 +5,40 @@ sudo: false
|
|
|
5
5
|
rvm:
|
|
6
6
|
- 2.0.0
|
|
7
7
|
- 2.1.10
|
|
8
|
-
- 2.2.
|
|
9
|
-
- 2.3.
|
|
8
|
+
- 2.2.6
|
|
9
|
+
- 2.3.3
|
|
10
|
+
- 2.4.0
|
|
10
11
|
- ruby-head
|
|
11
|
-
- jruby-9.1.
|
|
12
|
-
-
|
|
12
|
+
- jruby-9.1.8.0
|
|
13
|
+
- rubinius-3
|
|
13
14
|
matrix:
|
|
14
15
|
exclude:
|
|
15
|
-
- rvm: ruby-head
|
|
16
|
-
gemfile: gemfiles/rails_41.gemfile
|
|
17
|
-
- rvm: ruby-head
|
|
18
|
-
gemfile: gemfiles/rails_42.gemfile
|
|
19
16
|
- rvm: 2.0.0
|
|
20
17
|
gemfile: gemfiles/rails_50.gemfile
|
|
21
18
|
- rvm: 2.1.10
|
|
22
19
|
gemfile: gemfiles/rails_50.gemfile
|
|
20
|
+
- rvm: 2.0.0
|
|
21
|
+
gemfile: gemfiles/rails_51.gemfile
|
|
22
|
+
- rvm: 2.1.10
|
|
23
|
+
gemfile: gemfiles/rails_51.gemfile
|
|
23
24
|
- rvm: 2.0.0
|
|
24
25
|
gemfile: gemfiles/rails_edge.gemfile
|
|
25
26
|
- rvm: 2.1.10
|
|
26
27
|
gemfile: gemfiles/rails_edge.gemfile
|
|
28
|
+
- rvm: 2.4.0
|
|
29
|
+
gemfile: gemfiles/rails_41.gemfile
|
|
30
|
+
- rvm: 2.4.0
|
|
31
|
+
gemfile: gemfiles/rails_42.gemfile
|
|
32
|
+
- rvm: ruby-head
|
|
33
|
+
gemfile: gemfiles/rails_41.gemfile
|
|
34
|
+
- rvm: ruby-head
|
|
35
|
+
gemfile: gemfiles/rails_42.gemfile
|
|
27
36
|
allow_failures:
|
|
28
|
-
- rvm: jruby-9.1.
|
|
29
|
-
- rvm:
|
|
37
|
+
- rvm: jruby-9.1.8.0
|
|
38
|
+
- rvm: rubinius-3
|
|
30
39
|
gemfile:
|
|
31
40
|
- gemfiles/rails_41.gemfile
|
|
32
41
|
- gemfiles/rails_42.gemfile
|
|
33
42
|
- gemfiles/rails_50.gemfile
|
|
43
|
+
- gemfiles/rails_51.gemfile
|
|
34
44
|
- gemfiles/rails_edge.gemfile
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -213,14 +213,14 @@ end
|
|
|
213
213
|
```
|
|
214
214
|
|
|
215
215
|
You may notice that
|
|
216
|
-
* There are no globalish `params`
|
|
216
|
+
* There are no globalish `params` reference
|
|
217
217
|
* It's quite easy to comprehend what's the actual input value for each action
|
|
218
218
|
* You may write the unit test code as if the actions are just normal Ruby methods
|
|
219
219
|
|
|
220
220
|
|
|
221
221
|
## Supported versions
|
|
222
222
|
|
|
223
|
-
* Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.0 (trunk), JRuby, & Rubinius with 2.0+ mode
|
|
223
|
+
* Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.0 (trunk), JRuby, & Rubinius with 2.0+ mode
|
|
224
224
|
|
|
225
225
|
* Rails 4.1.x, 4.2.x, 5.0, 5.1 (edge)
|
|
226
226
|
|
data/action_args.gemspec
CHANGED
data/gemfiles/rails_41.gemfile
CHANGED
data/gemfiles/rails_42.gemfile
CHANGED
data/gemfiles/rails_50.gemfile
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
source 'https://rubygems.org'
|
|
3
|
+
git_source(:github) do |repo_name|
|
|
4
|
+
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
|
5
|
+
"https://github.com/#{repo_name}.git"
|
|
6
|
+
end
|
|
2
7
|
|
|
3
|
-
gem 'rails', '~> 5.0.
|
|
8
|
+
gem 'rails', '~> 5.0.1'
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
# FIXME: bundle from GH master until > 1.0.1 release
|
|
11
|
+
gem 'rails-controller-testing', github: 'rails/rails-controller-testing'
|
|
6
12
|
|
|
7
13
|
gemspec :path => '../'
|
|
8
14
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
source 'https://rubygems.org'
|
|
3
|
+
git_source(:github) do |repo_name|
|
|
4
|
+
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
|
5
|
+
"https://github.com/#{repo_name}.git"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
gem 'rails', '~> 5.1.0.beta1'
|
|
9
|
+
|
|
10
|
+
# FIXME: bundle from GH master until > 1.0.1 release
|
|
11
|
+
gem 'rails-controller-testing', github: 'rails/rails-controller-testing'
|
|
12
|
+
|
|
13
|
+
gemspec :path => '../'
|
|
14
|
+
|
|
15
|
+
platforms :ruby do
|
|
16
|
+
gem 'sqlite3'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
platforms :jruby do
|
|
20
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
|
21
|
+
end
|
data/gemfiles/rails_edge.gemfile
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
source 'https://rubygems.org'
|
|
3
|
+
git_source(:github) do |repo_name|
|
|
4
|
+
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
|
5
|
+
"https://github.com/#{repo_name}.git"
|
|
6
|
+
end
|
|
2
7
|
|
|
3
8
|
gem 'rails', github: 'rails/rails'
|
|
4
9
|
gem 'rack', github: 'rack/rack'
|
|
@@ -6,7 +11,8 @@ gem 'arel', github: 'rails/arel'
|
|
|
6
11
|
gem 'sprockets', github: 'rails/sprockets'
|
|
7
12
|
gem 'sprockets-rails', github: 'rails/sprockets-rails'
|
|
8
13
|
gem 'sass-rails', github: 'rails/sass-rails'
|
|
9
|
-
|
|
14
|
+
# FIXME: bundle from GH master until > 1.0.1 release
|
|
15
|
+
gem 'rails-controller-testing', github: 'rails/rails-controller-testing'
|
|
10
16
|
|
|
11
17
|
gemspec :path => '../'
|
|
12
18
|
|
data/lib/action_args.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require_relative 'params_handler'
|
|
2
3
|
using ActionArgs::ParamsHandler
|
|
3
4
|
|
|
@@ -26,12 +27,8 @@ module ActionArgs
|
|
|
26
27
|
# end
|
|
27
28
|
# end
|
|
28
29
|
#
|
|
29
|
-
def permits(*attributes)
|
|
30
|
-
|
|
31
|
-
options = attributes.pop
|
|
32
|
-
@permitting_model_name = options[:model_name]
|
|
33
|
-
end
|
|
34
|
-
@permitted_attributes = attributes
|
|
30
|
+
def permits(*attributes, model_name: nil)
|
|
31
|
+
@permitted_attributes, @permitting_model_name = attributes, model_name
|
|
35
32
|
end
|
|
36
33
|
end
|
|
37
34
|
end
|
|
@@ -1,36 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
using ActionArgs::ParamsHandler
|
|
2
3
|
|
|
3
4
|
module ActionArgs
|
|
4
5
|
module ActiveSupport
|
|
6
|
+
# For Rails >= 5.1
|
|
5
7
|
module CallbackParameterizer
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
# Extending AS::Callbacks::Callback's `expand` not just to call specified
|
|
9
|
+
# method but to call the method with method parameters taken from `params`.
|
|
10
|
+
# This would happen only when
|
|
11
|
+
# * the target object is_a ActionController object
|
|
12
|
+
# * the filter was not defined via lambda
|
|
13
|
+
def expand(*)
|
|
14
|
+
target, block, method, *arguments = super
|
|
15
|
+
|
|
16
|
+
if (ActionController::Base === target) && (method != :instance_exec) && arguments.empty?
|
|
17
|
+
target.strengthen_params! method
|
|
18
|
+
arguments = target.extract_method_arguments_from_params method
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
[target, block, method, *arguments]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# For Rails 4 & 5.0
|
|
26
|
+
module CallbackParameterizerLegacy
|
|
27
|
+
# Extending AS::Callbacks::Callback's `make_lambda` not just to call specified
|
|
28
|
+
# method but to call the method with method parameters taken from `params`.
|
|
29
|
+
# This would happen only when
|
|
30
|
+
# * the filter was defined in Symbol form
|
|
31
|
+
# * the target object is_a ActionController object
|
|
32
|
+
def make_lambda(filter)
|
|
33
|
+
if Symbol === filter
|
|
34
|
+
lambda do |target, _, &blk|
|
|
35
|
+
if ActionController::Base === target
|
|
36
|
+
target.strengthen_params! filter
|
|
37
|
+
values = target.extract_method_arguments_from_params filter
|
|
38
|
+
target.send filter, *values, &blk
|
|
39
|
+
else
|
|
40
|
+
target.send filter, &blk
|
|
21
41
|
end
|
|
22
|
-
else
|
|
23
|
-
super
|
|
24
42
|
end
|
|
43
|
+
else
|
|
44
|
+
super
|
|
25
45
|
end
|
|
46
|
+
end
|
|
26
47
|
end
|
|
27
48
|
end
|
|
28
49
|
end
|
|
29
50
|
|
|
30
|
-
|
|
31
|
-
module
|
|
32
|
-
|
|
33
|
-
|
|
51
|
+
if Rails.version >= '5.1'
|
|
52
|
+
module ActiveSupport
|
|
53
|
+
module Callbacks
|
|
54
|
+
class CallTemplate
|
|
55
|
+
prepend ActionArgs::ActiveSupport::CallbackParameterizer
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
else
|
|
60
|
+
module ActiveSupport
|
|
61
|
+
module Callbacks
|
|
62
|
+
class Callback
|
|
63
|
+
prepend ActionArgs::ActiveSupport::CallbackParameterizerLegacy
|
|
64
|
+
end
|
|
34
65
|
end
|
|
35
66
|
end
|
|
36
67
|
end
|
data/lib/action_args/version.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
4
|
class BooksControllerTest < ActionController::TestCase
|
|
@@ -12,8 +13,10 @@ class BooksControllerTest < ActionController::TestCase
|
|
|
12
13
|
assert_equal @book, assigns(:book)
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
if Rails.version < '5.1'
|
|
17
|
+
test 'via String' do
|
|
18
|
+
assert assigns(:string_filter_executed)
|
|
19
|
+
end
|
|
17
20
|
end
|
|
18
21
|
|
|
19
22
|
test 'via Proc' do
|
data/test/fake_app.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
# config
|
|
4
5
|
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
|
@@ -68,7 +69,9 @@ end
|
|
|
68
69
|
class BooksController < ApplicationController
|
|
69
70
|
before_action :set_book, only: :show
|
|
70
71
|
before_action -> { @proc_filter_executed = true }, only: :show
|
|
71
|
-
|
|
72
|
+
if Rails.version < '5.1'
|
|
73
|
+
before_action '@string_filter_executed = true', only: :show
|
|
74
|
+
end
|
|
72
75
|
around_action :benchmark_action
|
|
73
76
|
before_action :omg
|
|
74
77
|
skip_before_action :omg
|
|
@@ -147,7 +150,7 @@ require_relative 'kwargs_controllers'
|
|
|
147
150
|
require_relative 'kwargs_keyreq_controllers' if RUBY_VERSION >= '2.1'
|
|
148
151
|
|
|
149
152
|
# migrations
|
|
150
|
-
class CreateAllTables < ActiveRecord::Migration
|
|
153
|
+
class CreateAllTables < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
|
|
151
154
|
def self.up
|
|
152
155
|
create_table(:authors) {|t| t.string :name}
|
|
153
156
|
create_table(:books) {|t| t.string :title; t.integer :price}
|
data/test/kwargs_controllers.rb
CHANGED
data/test/test_helper.rb
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
4
|
# load Rails first
|
|
4
5
|
require 'rails'
|
|
5
6
|
require 'active_record'
|
|
6
7
|
require 'action_controller/railtie'
|
|
8
|
+
begin
|
|
9
|
+
require 'rails-controller-testing'
|
|
10
|
+
rescue LoadError
|
|
11
|
+
end
|
|
7
12
|
require 'action_args'
|
|
8
13
|
require 'fake_app'
|
|
9
14
|
require 'test/unit/rails/test_help'
|
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.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Akira Matsuda
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-03-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -70,6 +70,7 @@ files:
|
|
|
70
70
|
- gemfiles/rails_41.gemfile
|
|
71
71
|
- gemfiles/rails_42.gemfile
|
|
72
72
|
- gemfiles/rails_50.gemfile
|
|
73
|
+
- gemfiles/rails_51.gemfile
|
|
73
74
|
- gemfiles/rails_edge.gemfile
|
|
74
75
|
- lib/action_args.rb
|
|
75
76
|
- lib/action_args/abstract_controller.rb
|
|
@@ -109,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
109
110
|
version: '0'
|
|
110
111
|
requirements: []
|
|
111
112
|
rubyforge_project:
|
|
112
|
-
rubygems_version: 2.6.
|
|
113
|
+
rubygems_version: 2.6.10
|
|
113
114
|
signing_key:
|
|
114
115
|
specification_version: 4
|
|
115
116
|
summary: Controller action arguments parameterizer for Rails 4+ & Ruby 2.0+
|