action_args 2.3.2 → 2.4.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 +3 -3
 - data/README.md +68 -43
 - data/gemfiles/rails_41.gemfile +1 -1
 - data/gemfiles/rails_42.gemfile +1 -1
 - data/gemfiles/rails_50.gemfile +1 -1
 - data/gemfiles/rails_51.gemfile +1 -1
 - data/gemfiles/rails_52.gemfile +1 -1
 - data/gemfiles/rails_edge.gemfile +1 -4
 - data/lib/action_args/params_handler.rb +11 -9
 - data/lib/action_args/version.rb +1 -1
 - data/test/params_handler/params_handler_test.rb +63 -1
 - metadata +4 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4b4a8d847e94c900a71e3ce0c0bc9e5fb1f33c195a2b30222fad4ca5f4574d73
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: d557de21bbcb6eb76f88c4d4bc70fb899f58449192e9125f7c8548e2f8d17ab8
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 43ee46cb44156ad2cd9a47aab03e312b00058d2173c416e6f60152c3b423ddadfa92c0ebf41c4c22b17d6c0daac3e029a3042a1d3b5272fcf18a18a5a1e03d58
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: fea23dadb984ed9d43250ead66849f38ed45d5a5ca053b1c6513e7235d0dd7d961ba9d6b7773126af104d1ed93a31d99f01b168403dded36074fcea12b273e38
         
     | 
    
        data/.travis.yml
    CHANGED
    
    | 
         @@ -3,7 +3,7 @@ language: ruby 
     | 
|
| 
       3 
3 
     | 
    
         
             
            sudo: false
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            before_install:
         
     | 
| 
       6 
     | 
    
         
            -
              - "ruby -e 'exit RUBY_VERSION.to_f >= 2.3' && gem up --system || gem i rubygems-update -v '<3' && update_rubygems"
         
     | 
| 
      
 6 
     | 
    
         
            +
              - "ruby -e 'exit RUBY_VERSION.to_f >= 2.3' && gem up --system || (gem i rubygems-update -v '<3' && update_rubygems)"
         
     | 
| 
       7 
7 
     | 
    
         
             
              - gem up bundler
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            # rvm:
         
     | 
| 
         @@ -53,12 +53,12 @@ matrix: 
     | 
|
| 
       53 
53 
     | 
    
         
             
                - rvm: ruby-head
         
     | 
| 
       54 
54 
     | 
    
         
             
                  gemfile: gemfiles/rails_edge.gemfile
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
                - rvm: jruby-9.2. 
     | 
| 
      
 56 
     | 
    
         
            +
                - rvm: jruby-9.2.6.0
         
     | 
| 
       57 
57 
     | 
    
         
             
                  gemfile: gemfiles/rails_52.gemfile
         
     | 
| 
       58 
58 
     | 
    
         
             
                - rvm: rubinius-3
         
     | 
| 
       59 
59 
     | 
    
         
             
                  gemfile: gemfiles/rails_52.gemfile
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
       61 
61 
     | 
    
         
             
              allow_failures:
         
     | 
| 
       62 
     | 
    
         
            -
                - rvm: jruby-9.2. 
     | 
| 
      
 62 
     | 
    
         
            +
                - rvm: jruby-9.2.6.0
         
     | 
| 
       63 
63 
     | 
    
         
             
                - rvm: rubinius-3
         
     | 
| 
       64 
64 
     | 
    
         
             
                - gemfile: gemfiles/rails_edge.gemfile
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,12 +1,12 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #  
     | 
| 
      
 1 
     | 
    
         
            +
            # action_args
         
     | 
| 
       2 
2 
     | 
    
         
             
            [](https://travis-ci.org/asakusarb/action_args)
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            Controller action arguments parameterizer for Rails 
     | 
| 
      
 4 
     | 
    
         
            +
            Controller action arguments parameterizer for Rails
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
            ## What  
     | 
| 
      
 7 
     | 
    
         
            +
            ## What Is This?
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
            action_args is a Rails plugin that extends your controller action methods to allow you to specify arguments of interest in the method definition for any action. - in short, this makes your Rails controller Merb-ish.
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
            ## The Controllers
         
     | 
| 
         @@ -14,24 +14,24 @@ ActionArgs is a Rails plugin that extends your controller action methods to allo 
     | 
|
| 
       14 
14 
     | 
    
         
             
            Having the following controller code:
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            ```ruby
         
     | 
| 
       17 
     | 
    
         
            -
            class  
     | 
| 
       18 
     | 
    
         
            -
              def  
     | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
      
 17 
     | 
    
         
            +
            class UsersController < ApplicationController
         
     | 
| 
      
 18 
     | 
    
         
            +
              def show(id)
         
     | 
| 
      
 19 
     | 
    
         
            +
                @user = User.find id
         
     | 
| 
       20 
20 
     | 
    
         
             
              end
         
     | 
| 
       21 
21 
     | 
    
         
             
            end
         
     | 
| 
       22 
22 
     | 
    
         
             
            ```
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
            This allows you to explicitly state which members of the `params` Hash are used in your controller actions 
     | 
| 
      
 24 
     | 
    
         
            +
            When a request visits "/users/777", it calls `UsersController#show` passing 777 as the method parameter.
         
     | 
| 
      
 25 
     | 
    
         
            +
            This allows you to explicitly state the most important API for the action -- which members of the `params` Hash are used in your controller actions -- in a perfectly natural Ruby way!
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
            ## Method  
     | 
| 
      
 28 
     | 
    
         
            +
            ## Method Parameter Types in Ruby, and How action_args Handles Parameters
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
            ### Required Parameters (:req)
         
     | 
| 
       31 
     | 
    
         
            -
            Method parameters that you specify are required. If a key of the same name does not exist in the params Hash,
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
            Method parameters that you specify are required. If a key of the same name does not exist in the params Hash, ActionContrller::BadRequest is raised.
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            In this `show` action, action_args will require that `id` parameter is provided.
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
            In this `show` action, ActionArgs will require that `id` parameter is provided.
         
     | 
| 
       35 
35 
     | 
    
         
             
            ```ruby
         
     | 
| 
       36 
36 
     | 
    
         
             
            class UsersController < ApplicationController
         
     | 
| 
       37 
37 
     | 
    
         
             
              # the `id` parameter is mandatory
         
     | 
| 
         @@ -55,7 +55,7 @@ end 
     | 
|
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
            ### Keyword Argument (:key)
         
     | 
| 
       57 
57 
     | 
    
         
             
            If you think this Ruby 2.0 syntax reads better, you can choose this style for defining your action methods.
         
     | 
| 
       58 
     | 
    
         
            -
            This just works in the same way as  
     | 
| 
      
 58 
     | 
    
         
            +
            This just works in the same way as `:opt` here.
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
60 
     | 
    
         
             
            ```ruby
         
     | 
| 
       61 
61 
     | 
    
         
             
            class UsersController < ApplicationController
         
     | 
| 
         @@ -67,8 +67,8 @@ end 
     | 
|
| 
       67 
67 
     | 
    
         
             
            ```
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
       69 
69 
     | 
    
         
             
            ### Required Keyword Argument (:keyreq)
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
            You can use this syntax instead of  
     | 
| 
      
 70 
     | 
    
         
            +
            `:keyreq` is the required version of `:key`, which was introduced in Ruby 2.1.
         
     | 
| 
      
 71 
     | 
    
         
            +
            You can use this syntax instead of `:req`.
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
            ```ruby
         
     | 
| 
       74 
74 
     | 
    
         
             
            class CommentsController < ApplicationController
         
     | 
| 
         @@ -80,9 +80,9 @@ class CommentsController < ApplicationController 
     | 
|
| 
       80 
80 
     | 
    
         
             
            end
         
     | 
| 
       81 
81 
     | 
    
         
             
            ```
         
     | 
| 
       82 
82 
     | 
    
         | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
      
 83 
     | 
    
         
            +
            ## StrongParameters - permit
         
     | 
| 
       84 
84 
     | 
    
         | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
      
 85 
     | 
    
         
            +
            action_args plays very nice with Rails 4 StrongParameters.
         
     | 
| 
       86 
86 
     | 
    
         | 
| 
       87 
87 
     | 
    
         
             
            1. Inline declaration
         
     | 
| 
       88 
88 
     | 
    
         | 
| 
         @@ -97,17 +97,17 @@ class UsersController < ApplicationController 
     | 
|
| 
       97 
97 
     | 
    
         
             
            end
         
     | 
| 
       98 
98 
     | 
    
         
             
            ```
         
     | 
| 
       99 
99 
     | 
    
         | 
| 
       100 
     | 
    
         
            -
            2. Declarative  
     | 
| 
      
 100 
     | 
    
         
            +
            2. Declarative allow-listing
         
     | 
| 
       101 
101 
     | 
    
         | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
      
 102 
     | 
    
         
            +
            action_args also provides a declarative `permits` method for controller classes.
         
     | 
| 
       103 
103 
     | 
    
         
             
            Use this to keep your `permit` calls DRY in a comprehensible way.
         
     | 
| 
       104 
104 
     | 
    
         | 
| 
       105 
105 
     | 
    
         
             
            ```ruby
         
     | 
| 
       106 
106 
     | 
    
         
             
            class UsersController < ApplicationController
         
     | 
| 
       107 
     | 
    
         
            -
              #  
     | 
| 
      
 107 
     | 
    
         
            +
              # allow-lists User model's attributes
         
     | 
| 
       108 
108 
     | 
    
         
             
              permits :name, :age
         
     | 
| 
       109 
109 
     | 
    
         | 
| 
       110 
     | 
    
         
            -
              # the given `user` parameter would be automatically permitted by  
     | 
| 
      
 110 
     | 
    
         
            +
              # the given `user` parameter would be automatically permitted by action_args
         
     | 
| 
       111 
111 
     | 
    
         
             
              def create(user)
         
     | 
| 
       112 
112 
     | 
    
         
             
                @user = User.new(user)
         
     | 
| 
       113 
113 
     | 
    
         
             
              end
         
     | 
| 
         @@ -116,18 +116,19 @@ end 
     | 
|
| 
       116 
116 
     | 
    
         | 
| 
       117 
117 
     | 
    
         
             
            By default, action_args deduces the target model name from the controller name.
         
     | 
| 
       118 
118 
     | 
    
         
             
            For example, the `permits` call in `UsersController` expects the model name to be `User`.
         
     | 
| 
       119 
     | 
    
         
            -
            If this is not the case, you can specify the  
     | 
| 
      
 119 
     | 
    
         
            +
            If this is not the case, you can specify the `:model_name` option:
         
     | 
| 
       120 
120 
     | 
    
         | 
| 
       121 
121 
     | 
    
         
             
            ```ruby
         
     | 
| 
       122 
122 
     | 
    
         
             
            class MembersController < ApplicationController
         
     | 
| 
       123 
     | 
    
         
            -
              #  
     | 
| 
      
 123 
     | 
    
         
            +
              # allow-lists User model's attributes
         
     | 
| 
       124 
124 
     | 
    
         
             
              permits :name, :age, model_name: 'User'
         
     | 
| 
       125 
125 
     | 
    
         
             
            end
         
     | 
| 
       126 
126 
     | 
    
         
             
            ```
         
     | 
| 
       127 
127 
     | 
    
         | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
       128 
129 
     | 
    
         
             
            ## Filters
         
     | 
| 
       129 
130 
     | 
    
         | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
      
 131 
     | 
    
         
            +
            action_args works in filters, in the same way as it works in controller actions.
         
     | 
| 
       131 
132 
     | 
    
         | 
| 
       132 
133 
     | 
    
         
             
            ```ruby
         
     | 
| 
       133 
134 
     | 
    
         
             
            class UsersController < ApplicationController
         
     | 
| 
         @@ -136,17 +137,44 @@ class UsersController < ApplicationController 
     | 
|
| 
       136 
137 
     | 
    
         
             
              def show
         
     | 
| 
       137 
138 
     | 
    
         
             
              end
         
     | 
| 
       138 
139 
     | 
    
         | 
| 
       139 
     | 
    
         
            -
               
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
                 
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
                end
         
     | 
| 
      
 140 
     | 
    
         
            +
              # `params[:id]` will be dynamically assigned to the method parameter `id` here
         
     | 
| 
      
 141 
     | 
    
         
            +
              private def set_user(id)
         
     | 
| 
      
 142 
     | 
    
         
            +
                @user = User.find(id)
         
     | 
| 
      
 143 
     | 
    
         
            +
              end
         
     | 
| 
       144 
144 
     | 
    
         
             
            end
         
     | 
| 
       145 
145 
     | 
    
         
             
            ```
         
     | 
| 
       146 
146 
     | 
    
         | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
            ## The *_params Convention
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
            For those who are familiar with the Rails scaffold's default naming style, you can add `_params` suffix to any of the parameter names in the method signatures.
         
     | 
| 
      
 151 
     | 
    
         
            +
            It just matches with the params name without `_params`.
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
            For instance, these two actions both pass `params[:user]` as the method parameter.
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 156 
     | 
    
         
            +
            # without _params
         
     | 
| 
      
 157 
     | 
    
         
            +
            def create(user)
         
     | 
| 
      
 158 
     | 
    
         
            +
              @user = User.new(user)
         
     | 
| 
      
 159 
     | 
    
         
            +
              ...
         
     | 
| 
      
 160 
     | 
    
         
            +
            end
         
     | 
| 
      
 161 
     | 
    
         
            +
            ```
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 164 
     | 
    
         
            +
            # with _params
         
     | 
| 
      
 165 
     | 
    
         
            +
            def create(user_params)
         
     | 
| 
      
 166 
     | 
    
         
            +
              @user = User.new(user_params)
         
     | 
| 
      
 167 
     | 
    
         
            +
              ...
         
     | 
| 
      
 168 
     | 
    
         
            +
            end
         
     | 
| 
      
 169 
     | 
    
         
            +
            ```
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
            This naming convention makes your controller code look much more compatible with the Rails' default scaffolded code,
         
     | 
| 
      
 172 
     | 
    
         
            +
            and so it may be actually super easy for you to manually migrate from the legacy scaffold controller to the action_args style.
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
       147 
175 
     | 
    
         
             
            ## The Scaffold Generator
         
     | 
| 
       148 
176 
     | 
    
         | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
      
 177 
     | 
    
         
            +
            action_args provides a custom scaffold controller generator that overwrites the default scaffold generator.
         
     | 
| 
       150 
178 
     | 
    
         
             
            Thus, by hitting the scaffold generator command like this:
         
     | 
| 
       151 
179 
     | 
    
         | 
| 
       152 
180 
     | 
    
         
             
            ```sh
         
     | 
| 
         @@ -212,37 +240,33 @@ end 
     | 
|
| 
       212 
240 
     | 
    
         
             
            ```
         
     | 
| 
       213 
241 
     | 
    
         | 
| 
       214 
242 
     | 
    
         
             
            You may notice that
         
     | 
| 
       215 
     | 
    
         
            -
            * There are no  
     | 
| 
      
 243 
     | 
    
         
            +
            * There are no global-ish `params` reference
         
     | 
| 
       216 
244 
     | 
    
         
             
            * It's quite easy to comprehend what's the actual input value for each action
         
     | 
| 
       217 
     | 
    
         
            -
            * You may write the unit test code as if the actions are just normal Ruby methods
         
     | 
| 
      
 245 
     | 
    
         
            +
            * You may be able to write the unit test code without mocking `params` as if the actions are just normal Ruby methods
         
     | 
| 
       218 
246 
     | 
    
         | 
| 
       219 
247 
     | 
    
         | 
| 
       220 
     | 
    
         
            -
            ## Supported  
     | 
| 
      
 248 
     | 
    
         
            +
            ## Supported Versions
         
     | 
| 
       221 
249 
     | 
    
         | 
| 
       222 
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
         
     | 
| 
       223 
251 
     | 
    
         | 
| 
       224 
252 
     | 
    
         
             
            * Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, 6.0 (edge)
         
     | 
| 
       225 
253 
     | 
    
         | 
| 
       226 
     | 
    
         
            -
             
     | 
| 
      
 254 
     | 
    
         
            +
            For Rails 4.0.x, please use Version 1.5.4.
         
     | 
| 
       227 
255 
     | 
    
         | 
| 
       228 
256 
     | 
    
         | 
| 
       229 
257 
     | 
    
         
             
            ## Installation
         
     | 
| 
       230 
258 
     | 
    
         | 
| 
       231 
     | 
    
         
            -
             
     | 
| 
      
 259 
     | 
    
         
            +
            Bundle the gem to your Rails app by putting this line in your Gemfile:
         
     | 
| 
      
 260 
     | 
    
         
            +
             
     | 
| 
       232 
261 
     | 
    
         
             
            ```ruby
         
     | 
| 
       233 
262 
     | 
    
         
             
            gem 'action_args'
         
     | 
| 
       234 
263 
     | 
    
         
             
            ```
         
     | 
| 
       235 
264 
     | 
    
         | 
| 
       236 
     | 
    
         
            -
            Then bundle:
         
     | 
| 
       237 
     | 
    
         
            -
            ```sh
         
     | 
| 
       238 
     | 
    
         
            -
            % bundle
         
     | 
| 
       239 
     | 
    
         
            -
            ```
         
     | 
| 
       240 
     | 
    
         
            -
             
     | 
| 
       241 
265 
     | 
    
         
             
            ## Notes
         
     | 
| 
       242 
266 
     | 
    
         | 
| 
       243 
267 
     | 
    
         
             
            ### Plain Old Action Methods
         
     | 
| 
       244 
268 
     | 
    
         | 
| 
       245 
     | 
    
         
            -
            Of course you still can use both  
     | 
| 
      
 269 
     | 
    
         
            +
            Of course you still can use both Merb-like style and plain old Rails style action methods even if this plugin is loaded. `params` parameter is still alive as well. That means, this plugin won't break any existing controller API.
         
     | 
| 
       246 
270 
     | 
    
         | 
| 
       247 
271 
     | 
    
         
             
            ### Argument Naming Convention
         
     | 
| 
       248 
272 
     | 
    
         | 
| 
         @@ -264,7 +288,7 @@ class BooksController < ApplicationController 
     | 
|
| 
       264 
288 
     | 
    
         
             
            end
         
     | 
| 
       265 
289 
     | 
    
         
             
            ```
         
     | 
| 
       266 
290 
     | 
    
         | 
| 
       267 
     | 
    
         
            -
            ### Default  
     | 
| 
      
 291 
     | 
    
         
            +
            ### Default Parameter Values
         
     | 
| 
       268 
292 
     | 
    
         | 
| 
       269 
293 
     | 
    
         
             
            You are of course able to specify default values for action parameters such as:
         
     | 
| 
       270 
294 
     | 
    
         | 
| 
         @@ -290,6 +314,7 @@ end 
     | 
|
| 
       290 
314 
     | 
    
         | 
| 
       291 
315 
     | 
    
         
             
            This way, the `page` parameter will be defaulted to 1 as everyone might expect.
         
     | 
| 
       292 
316 
     | 
    
         | 
| 
      
 317 
     | 
    
         
            +
             
     | 
| 
       293 
318 
     | 
    
         
             
            ## Copyright
         
     | 
| 
       294 
319 
     | 
    
         | 
| 
       295 
320 
     | 
    
         
             
            Copyright (c) 2011- Asakusa.rb. See MIT-LICENSE for further details.
         
     | 
    
        data/gemfiles/rails_41.gemfile
    CHANGED
    
    
    
        data/gemfiles/rails_42.gemfile
    CHANGED
    
    
    
        data/gemfiles/rails_50.gemfile
    CHANGED
    
    
    
        data/gemfiles/rails_51.gemfile
    CHANGED
    
    
    
        data/gemfiles/rails_52.gemfile
    CHANGED
    
    
    
        data/gemfiles/rails_edge.gemfile
    CHANGED
    
    | 
         @@ -7,11 +7,8 @@ git_source(:github) do |repo_name| 
     | 
|
| 
       7 
7 
     | 
    
         
             
            end
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            gem 'rails', github: 'rails/rails'
         
     | 
| 
       10 
     | 
    
         
            -
            gem 'rack', github: 'rack/rack'
         
     | 
| 
       11 
     | 
    
         
            -
            gem 'arel', github: 'rails/arel'
         
     | 
| 
       12 
     | 
    
         
            -
            gem 'sprockets', github: 'rails/sprockets'
         
     | 
| 
       13 
     | 
    
         
            -
            gem 'sprockets-rails', github: 'rails/sprockets-rails'
         
     | 
| 
       14 
10 
     | 
    
         
             
            gem 'rails-controller-testing'
         
     | 
| 
      
 11 
     | 
    
         
            +
            gem 'selenium-webdriver'
         
     | 
| 
       15 
12 
     | 
    
         | 
| 
       16 
13 
     | 
    
         
             
            gemspec :path => '../'
         
     | 
| 
       17 
14 
     | 
    
         | 
| 
         @@ -9,20 +9,21 @@ module ActionArgs 
     | 
|
| 
       9 
9 
     | 
    
         
             
                    kwargs, missing_required_params = {}, []
         
     | 
| 
       10 
10 
     | 
    
         
             
                    parameter_names = method_parameters.map(&:last)
         
     | 
| 
       11 
11 
     | 
    
         
             
                    method_parameters.reverse_each do |type, key|
         
     | 
| 
      
 12 
     | 
    
         
            +
                      trimmed_key = key.to_s.sub(/_params\z/, '').to_sym
         
     | 
| 
       12 
13 
     | 
    
         
             
                      case type
         
     | 
| 
       13 
14 
     | 
    
         
             
                      when :req
         
     | 
| 
       14 
     | 
    
         
            -
                        missing_required_params << key unless params.key?  
     | 
| 
      
 15 
     | 
    
         
            +
                        missing_required_params << key unless params.key? trimmed_key
         
     | 
| 
       15 
16 
     | 
    
         
             
                        next
         
     | 
| 
       16 
17 
     | 
    
         
             
                      when :keyreq
         
     | 
| 
       17 
     | 
    
         
            -
                        if params.key?  
     | 
| 
       18 
     | 
    
         
            -
                          kwargs[key] = params[ 
     | 
| 
      
 18 
     | 
    
         
            +
                        if params.key? trimmed_key
         
     | 
| 
      
 19 
     | 
    
         
            +
                          kwargs[key] = params[trimmed_key]
         
     | 
| 
       19 
20 
     | 
    
         
             
                        else
         
     | 
| 
       20 
21 
     | 
    
         
             
                          missing_required_params << key
         
     | 
| 
       21 
22 
     | 
    
         
             
                        end
         
     | 
| 
       22 
23 
     | 
    
         
             
                      when :key
         
     | 
| 
       23 
     | 
    
         
            -
                        kwargs[key] = params[ 
     | 
| 
      
 24 
     | 
    
         
            +
                        kwargs[key] = params[trimmed_key] if params.key? trimmed_key
         
     | 
| 
       24 
25 
     | 
    
         
             
                      when :opt
         
     | 
| 
       25 
     | 
    
         
            -
                        break if params.key?  
     | 
| 
      
 26 
     | 
    
         
            +
                        break if params.key? trimmed_key
         
     | 
| 
       26 
27 
     | 
    
         
             
                      end
         
     | 
| 
       27 
28 
     | 
    
         
             
                      # omitting parameters that are :block, :rest, :opt without a param, and :key without a param
         
     | 
| 
       28 
29 
     | 
    
         
             
                      parameter_names.delete key
         
     | 
| 
         @@ -36,7 +37,7 @@ module ActionArgs 
     | 
|
| 
       36 
37 
     | 
    
         
             
                      end
         
     | 
| 
       37 
38 
     | 
    
         
             
                    end
         
     | 
| 
       38 
39 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
                    values = parameter_names.map {|k| params[k]}
         
     | 
| 
      
 40 
     | 
    
         
            +
                    values = parameter_names.map {|k| params[k.to_s.sub(/_params\z/, '').to_sym]}
         
     | 
| 
       40 
41 
     | 
    
         
             
                    values << kwargs if kwargs.any?
         
     | 
| 
       41 
42 
     | 
    
         
             
                    values
         
     | 
| 
       42 
43 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -50,9 +51,10 @@ module ActionArgs 
     | 
|
| 
       50 
51 
     | 
    
         | 
| 
       51 
52 
     | 
    
         
             
                    method_parameters = method(method_name).parameters
         
     | 
| 
       52 
53 
     | 
    
         
             
                    method_parameters.each do |type, key|
         
     | 
| 
       53 
     | 
    
         
            -
                       
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                        params 
     | 
| 
      
 54 
     | 
    
         
            +
                      trimmed_key = key.to_s.sub(/_params\z/, '').to_sym
         
     | 
| 
      
 55 
     | 
    
         
            +
                      if (trimmed_key == target_model_name) && permitted_attributes
         
     | 
| 
      
 56 
     | 
    
         
            +
                        params.require(trimmed_key) if %i[req keyreq].include?(type)
         
     | 
| 
      
 57 
     | 
    
         
            +
                        params[trimmed_key] = params[trimmed_key].try :permit, *permitted_attributes if params.key? trimmed_key
         
     | 
| 
       56 
58 
     | 
    
         
             
                      end
         
     | 
| 
       57 
59 
     | 
    
         
             
                    end
         
     | 
| 
       58 
60 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/action_args/version.rb
    CHANGED
    
    
| 
         @@ -21,18 +21,36 @@ class ActionArgs::ParamsHandlerTest < ActiveSupport::TestCase 
     | 
|
| 
       21 
21 
     | 
    
         
             
                  assert_equal ['1'], @controller.extract_method_arguments_from_params(:m)
         
     | 
| 
       22 
22 
     | 
    
         
             
                end
         
     | 
| 
       23 
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 
     | 
    
         
            +
             
     | 
| 
       24 
30 
     | 
    
         
             
                test '2 reqs' do
         
     | 
| 
       25 
31 
     | 
    
         
             
                  def @controller.m(a, b) end
         
     | 
| 
       26 
32 
     | 
    
         | 
| 
       27 
33 
     | 
    
         
             
                  assert_equal ['1', '2'], @controller.extract_method_arguments_from_params(:m)
         
     | 
| 
       28 
34 
     | 
    
         
             
                end
         
     | 
| 
       29 
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 
     | 
    
         
            +
             
     | 
| 
       30 
42 
     | 
    
         
             
                test '1 opt with value' do
         
     | 
| 
       31 
43 
     | 
    
         
             
                  def @controller.m(a = 'a') end
         
     | 
| 
       32 
44 
     | 
    
         | 
| 
       33 
45 
     | 
    
         
             
                  assert_equal ['1'], @controller.extract_method_arguments_from_params(:m)
         
     | 
| 
       34 
46 
     | 
    
         
             
                end
         
     | 
| 
       35 
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 
     | 
    
         
            +
             
     | 
| 
       36 
54 
     | 
    
         
             
                test '1 opt without value' do
         
     | 
| 
       37 
55 
     | 
    
         
             
                  def @controller.m(x = 'x') end
         
     | 
| 
       38 
56 
     | 
    
         | 
| 
         @@ -111,6 +129,12 @@ class ActionArgs::ParamsHandlerTest < ActiveSupport::TestCase 
     | 
|
| 
       111 
129 
     | 
    
         
             
                  assert_equal [a: '1'], @controller.extract_method_arguments_from_params(:m)
         
     | 
| 
       112 
130 
     | 
    
         
             
                end
         
     | 
| 
       113 
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 
     | 
    
         
            +
             
     | 
| 
       114 
138 
     | 
    
         
             
                test 'key, key without value' do
         
     | 
| 
       115 
139 
     | 
    
         
             
                  def @controller.m(a: nil, x: 'x') end
         
     | 
| 
       116 
140 
     | 
    
         | 
| 
         @@ -125,6 +149,12 @@ class ActionArgs::ParamsHandlerTest < ActiveSupport::TestCase 
     | 
|
| 
       125 
149 
     | 
    
         
             
                      assert_equal [a: '1'], @controller.extract_method_arguments_from_params(:m)
         
     | 
| 
       126 
150 
     | 
    
         
             
                    end
         
     | 
| 
       127 
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 
     | 
    
         
            +
             
     | 
| 
       128 
158 
     | 
    
         
             
                    test 'keyreq, keyreq without value' do
         
     | 
| 
       129 
159 
     | 
    
         
             
                      def @controller.m(a:, x:) end
         
     | 
| 
       130 
160 
     | 
    
         | 
| 
         @@ -136,7 +166,7 @@ class ActionArgs::ParamsHandlerTest < ActiveSupport::TestCase 
     | 
|
| 
       136 
166 
     | 
    
         | 
| 
       137 
167 
     | 
    
         
             
              sub_test_case 'strengthen_params!' do
         
     | 
| 
       138 
168 
     | 
    
         
             
                setup do
         
     | 
| 
       139 
     | 
    
         
            -
                  @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'})
         
     | 
| 
      
 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'})
         
     | 
| 
       140 
170 
     | 
    
         
             
                end
         
     | 
| 
       141 
171 
     | 
    
         | 
| 
       142 
172 
     | 
    
         
             
                def execute_strengthen_params!(controller)
         
     | 
| 
         @@ -153,6 +183,14 @@ class ActionArgs::ParamsHandlerTest < ActiveSupport::TestCase 
     | 
|
| 
       153 
183 
     | 
    
         
             
                  assert_not_nil @params[:foo][:b]
         
     | 
| 
       154 
184 
     | 
    
         
             
                end
         
     | 
| 
       155 
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 
     | 
    
         
            +
             
     | 
| 
       156 
194 
     | 
    
         
             
                test 'requiring via :req, not permitting all scalars' do
         
     | 
| 
       157 
195 
     | 
    
         
             
                  execute_strengthen_params! BarController ||= Class.new(ApplicationController) { permits :a; def a(bar, x = 'x') end }
         
     | 
| 
       158 
196 
     | 
    
         | 
| 
         @@ -175,6 +213,14 @@ class ActionArgs::ParamsHandlerTest < ActiveSupport::TestCase 
     | 
|
| 
       175 
213 
     | 
    
         
             
                  assert_not_nil @params[:hoge][:b]
         
     | 
| 
       176 
214 
     | 
    
         
             
                end
         
     | 
| 
       177 
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 
     | 
    
         
            +
             
     | 
| 
       178 
224 
     | 
    
         
             
                test 'requiring via :key, permitting all scalars' do
         
     | 
| 
       179 
225 
     | 
    
         
             
                  execute_strengthen_params! FugaController ||= Class.new(ApplicationController) { permits :a, :b; def a(fuga: {}) end }
         
     | 
| 
       180 
226 
     | 
    
         | 
| 
         @@ -183,6 +229,14 @@ class ActionArgs::ParamsHandlerTest < ActiveSupport::TestCase 
     | 
|
| 
       183 
229 
     | 
    
         
             
                  assert_not_nil @params[:fuga][:b]
         
     | 
| 
       184 
230 
     | 
    
         
             
                end
         
     | 
| 
       185 
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 
     | 
    
         
            +
             
     | 
| 
       186 
240 
     | 
    
         
             
                test '"model_name" option' do
         
     | 
| 
       187 
241 
     | 
    
         
             
                  execute_strengthen_params! PiyoController ||= Class.new(ApplicationController) { permits :a, :b, model_name: 'Foo'; def a(foo) end }
         
     | 
| 
       188 
242 
     | 
    
         | 
| 
         @@ -190,5 +244,13 @@ class ActionArgs::ParamsHandlerTest < ActiveSupport::TestCase 
     | 
|
| 
       190 
244 
     | 
    
         
             
                  assert_not_nil @params[:foo][:a]
         
     | 
| 
       191 
245 
     | 
    
         
             
                  assert_not_nil @params[:foo][:b]
         
     | 
| 
       192 
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
         
     | 
| 
       193 
255 
     | 
    
         
             
              end
         
     | 
| 
       194 
256 
     | 
    
         
             
            end
         
     | 
    
        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.4.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: 2019- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-02-15 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -111,7 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       111 
111 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       112 
112 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       113 
113 
     | 
    
         
             
            requirements: []
         
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
      
 114 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 115 
     | 
    
         
            +
            rubygems_version: 2.7.8
         
     | 
| 
       115 
116 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       116 
117 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       117 
118 
     | 
    
         
             
            summary: Controller action arguments parameterizer for Rails 4+ & Ruby 2.0+
         
     |