action_args 1.1.1 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bc1d9d90cd395b886fc828a35a63c5d0064af53
4
- data.tar.gz: 15bbdff4daa2bfa5413ed8a1a14f54770359fd87
3
+ metadata.gz: 3ccd1f7e360a0022028839049722507a17dd7cee
4
+ data.tar.gz: 47dbf523322610689ceebdab7262f48b5a1c81f4
5
5
  SHA512:
6
- metadata.gz: 03ab97f8deb9229b3c1c158ad0d4a414324e848665c8ee3bf090dc4d9367a3bdf87d9991b9c054ae19436201dd10f942b1b401200d2b16949af994c2e1789c98
7
- data.tar.gz: d1e480e53600b3a14e39741c85678f76fc8f3f1c3dba7a31b3fd27c9b1a5c7b40e911cfe37200e19e8dd7e05a5fa60b48ddc2789cbc93aefd6482f21c9ac6ea8
6
+ metadata.gz: 4120e5d6c4e0ad9e6d264859d98211cd9448f52138cf3fcb4918479195ab6f5c785dec3c8ea0335bc1d4573f7f86d926194965adc8da15feaaadf817d3b7036c
7
+ data.tar.gz: a6d93141be8036c6f3728489f9a305be1ca48a826342fa3d01af43bdbcff5b1d0716d0f123bbadd4a33b2685fbec853f4f390345872db6232dd904741af3523f
data/README.md CHANGED
@@ -86,6 +86,16 @@ class UsersController < ApplicationController
86
86
  end
87
87
  ```
88
88
 
89
+ By default, action_args deduces the target model name from the controller name.
90
+ For example, the `permits` call in `UsersController` expects the model name to be `User`.
91
+ If this is not the case, you can specify the :model_name option:
92
+
93
+ ```ruby
94
+ class MembersController < ApplicationController
95
+ # white-lists User model's attributes
96
+ permits :name, :age, model_name: 'User'
97
+ end
98
+ ```
89
99
 
90
100
  ## The Scaffold Generator
91
101
 
@@ -24,6 +24,8 @@ module AbstractController
24
24
  # end
25
25
  #
26
26
  def self.permits(*attributes)
27
+ options = attributes.extract_options!
28
+ @permitting_model_name = options[:model_name] if options.has_key? :model_name
27
29
  @permitted_attributes = attributes
28
30
  end
29
31
  # no StrongParameters
@@ -25,8 +25,8 @@ module ActionArgs
25
25
  # permits declared model attributes in the params Hash
26
26
  # note that this method mutates the given params Hash
27
27
  def self.strengthen_params!(controller_class, method_parameters, params)
28
- target_model_name = controller_class.name.sub(/.+::/, '').sub(/Controller$/, '').singularize.underscore.to_sym
29
- permitted_attributes = controller_class.instance_variable_get '@permitted_attributes'
28
+ target_model_name = (controller_class.instance_variable_get(:'@permitting_model_name') || controller_class.name.sub(/.+::/, '').sub(/Controller$/, '')).singularize.underscore.to_sym
29
+ permitted_attributes = controller_class.instance_variable_get :'@permitted_attributes'
30
30
 
31
31
  method_parameters.each do |type, key|
32
32
  if (key == target_model_name) && permitted_attributes
@@ -1,3 +1,3 @@
1
1
  module ActionArgs
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe UserMailer do
4
4
  describe '#send_email_without_args' do
5
5
  it "should not raise NameError: undefined local variable or method `params' for ..." do
6
- expect{ UserMailer.send_email_without_args }.to_not raise_error(NameError)
6
+ expect{ UserMailer.send_email_without_args }.to_not raise_error
7
7
  end
8
8
  end
9
9
  end
@@ -157,6 +157,14 @@ describe ActionArgs::ParamsHandler do
157
157
  end
158
158
  KWARGS_TEST
159
159
  end
160
+
161
+ describe '"model_name" option' do
162
+ let(:controller) { PiyoController ||= Class.new(ApplicationController) { permits :a, :b, model_name: 'Foo'; def a(foo) end } }
163
+ subject { params[:foo] }
164
+ it { should be_permitted }
165
+ its([:a]) { should be }
166
+ its([:b]) { should be }
167
+ end
160
168
  end
161
169
  end
162
170
  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: 1.1.1
4
+ version: 1.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: 2013-07-25 00:00:00.000000000 Z
11
+ date: 2013-08-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rails plugin gem that supports Merbish style controller action arguments.
14
14
  email:
@@ -76,3 +76,4 @@ test_files:
76
76
  - spec/mailers/action_mailer_spec.rb
77
77
  - spec/params_handler/params_handler_spec.rb
78
78
  - spec/spec_helper.rb
79
+ has_rdoc: