action_args 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -36,7 +36,7 @@ Hence, raises an error if the `id` value has not been specified, in the same way
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
If you don't want ActionArgs to check the existence of some action parameters, you can make them optional by defining
|
39
|
+
If you don't want ActionArgs to check the existence of some action parameters, you can make them optional by defining their default values.
|
40
40
|
Again, it just acts in the same way as usual Ruby methods do.
|
41
41
|
|
42
42
|
class UsersController < ApplicationController
|
@@ -6,17 +6,16 @@ module AbstractController
|
|
6
6
|
values = if defined? ActionController::StrongParameters
|
7
7
|
target_model_name = self.class.name.sub(/Controller$/, '').singularize.underscore.to_sym
|
8
8
|
permitted_attributes = self.class.instance_variable_get '@permitted_attributes'
|
9
|
-
method(method_name).parameters.
|
10
|
-
next if type == :block
|
9
|
+
method(method_name).parameters.reject {|type, _| type == :block }.map do |type, key|
|
11
10
|
params.require key if type == :req
|
12
11
|
if (key == target_model_name) && permitted_attributes
|
13
12
|
params[key].try :permit, *permitted_attributes
|
14
13
|
else
|
15
14
|
params[key]
|
16
15
|
end
|
17
|
-
|
16
|
+
end
|
18
17
|
else
|
19
|
-
method(method_name).parameters.
|
18
|
+
method(method_name).parameters.reject {|type, _| type == :block }.map(&:last).map {|key| params[key]}
|
20
19
|
end
|
21
20
|
send method_name, *values
|
22
21
|
end
|
data/lib/action_args/version.rb
CHANGED
@@ -11,6 +11,14 @@ describe BooksController do
|
|
11
11
|
before { get :index, page: 3 }
|
12
12
|
its(:response) { should be_success }
|
13
13
|
end
|
14
|
+
|
15
|
+
context 'first param is nil and second is not nil' do
|
16
|
+
let!(:rhg) { Book.create! title: 'RHG' }
|
17
|
+
let!(:awdwr) { Book.create! title: 'AWDwR' }
|
18
|
+
before { get :index, q: 'RH' }
|
19
|
+
subject { assigns :books }
|
20
|
+
it { should == [rhg] }
|
21
|
+
end
|
14
22
|
end
|
15
23
|
|
16
24
|
describe 'GET show' do
|
data/spec/fake_app.rb
CHANGED
@@ -40,8 +40,9 @@ class AuthorsController < ApplicationController
|
|
40
40
|
end
|
41
41
|
class BooksController < ApplicationController
|
42
42
|
# optional parameter
|
43
|
-
def index(page = 1)
|
44
|
-
@books = Book.limit(10).offset((page.to_i - 1) * 10)
|
43
|
+
def index(page = 1, q = nil)
|
44
|
+
@books = Book.limit(10).offset(([page.to_i - 1, 0].max) * 10)
|
45
|
+
@books = @books.where('title like ?', "%#{q}%") unless q.blank?
|
45
46
|
render text: 'index'
|
46
47
|
end
|
47
48
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_args
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|