action_args 1.5.4 → 2.0.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -8
  3. data/CONTRIBUTING.md +5 -4
  4. data/README.md +6 -4
  5. data/Rakefile +12 -10
  6. data/action_args.gemspec +2 -2
  7. data/gemfiles/rails_edge.gemfile +19 -0
  8. data/lib/action_args.rb +2 -14
  9. data/lib/action_args/abstract_controller.rb +25 -36
  10. data/lib/action_args/callbacks.rb +3 -45
  11. data/lib/action_args/params_handler.rb +46 -40
  12. data/lib/action_args/version.rb +1 -1
  13. data/lib/generators/rails/action_args_scaffold_controller_generator.rb +0 -3
  14. data/test/controllers/action_args_controller_test.rb +43 -0
  15. data/test/controllers/hooks_test.rb +27 -0
  16. data/test/controllers/kwargs_controller_test.rb +30 -0
  17. data/test/controllers/kwargs_keyreq_controller_test.rb +30 -0
  18. data/test/controllers/ordinal_controller_test.rb +9 -0
  19. data/test/controllers/strong_parameters_test.rb +35 -0
  20. data/{spec → test}/fake_app.rb +33 -42
  21. data/{spec → test}/kwargs_controllers.rb +0 -0
  22. data/{spec → test}/kwargs_keyreq_controllers.rb +0 -0
  23. data/test/mailers/action_mailer_test.rb +8 -0
  24. data/test/params_handler/params_handler_test.rb +192 -0
  25. data/{spec/spec_helper.rb → test/test_helper.rb} +2 -7
  26. metadata +34 -45
  27. data/.rspec +0 -2
  28. data/gemfiles/rails_32.gemfile +0 -14
  29. data/gemfiles/rails_40.gemfile +0 -15
  30. data/lib/action_args/legacy/callbacks.rb +0 -71
  31. data/lib/generators/action_args/rspec/scaffold/scaffold_generator.rb +0 -18
  32. data/lib/generators/action_args/rspec/scaffold/templates/action_args_controller_spec.rb +0 -130
  33. data/spec/controllers/action_args_controller_spec.rb +0 -42
  34. data/spec/controllers/hooks_spec.rb +0 -31
  35. data/spec/controllers/kwargs_controller_spec.rb +0 -34
  36. data/spec/controllers/kwargs_keyreq_controller_spec.rb +0 -34
  37. data/spec/controllers/ordinal_controller_spec.rb +0 -11
  38. data/spec/controllers/strong_parameters_spec.rb +0 -34
  39. data/spec/mailers/action_mailer_spec.rb +0 -9
  40. data/spec/params_handler/params_handler_spec.rb +0 -218
@@ -6,10 +6,5 @@ require 'active_record'
6
6
  require 'action_controller/railtie'
7
7
  require 'action_args'
8
8
  require 'fake_app'
9
- require 'rspec/rails'
10
-
11
- RSpec.configure do |config|
12
- config.before :all do
13
- CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'authors'
14
- end
15
- end
9
+ require 'test/unit/rails/test_help'
10
+ Bundler.require
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.5.4
4
+ version: 2.0.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: 2015-07-19 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,25 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec-rails
42
+ name: test-unit-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.0'
48
- - - "<"
45
+ - - ">="
49
46
  - !ruby/object:Gem::Version
50
- version: '2.99'
47
+ version: '0'
51
48
  type: :development
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '2.0'
58
- - - "<"
52
+ - - ">="
59
53
  - !ruby/object:Gem::Version
60
- version: '2.99'
54
+ version: '0'
61
55
  description: Rails plugin gem that supports Merbish style controller action arguments.
62
56
  email:
63
57
  - ronnie@dio.jp
@@ -66,7 +60,6 @@ extensions: []
66
60
  extra_rdoc_files: []
67
61
  files:
68
62
  - ".gitignore"
69
- - ".rspec"
70
63
  - ".travis.yml"
71
64
  - CONTRIBUTING.md
72
65
  - Gemfile
@@ -74,32 +67,28 @@ files:
74
67
  - README.md
75
68
  - Rakefile
76
69
  - action_args.gemspec
77
- - gemfiles/rails_32.gemfile
78
- - gemfiles/rails_40.gemfile
79
70
  - gemfiles/rails_41.gemfile
80
71
  - gemfiles/rails_42.gemfile
72
+ - gemfiles/rails_edge.gemfile
81
73
  - lib/action_args.rb
82
74
  - lib/action_args/abstract_controller.rb
83
75
  - lib/action_args/callbacks.rb
84
- - lib/action_args/legacy/callbacks.rb
85
76
  - lib/action_args/params_handler.rb
86
77
  - lib/action_args/version.rb
87
- - lib/generators/action_args/rspec/scaffold/scaffold_generator.rb
88
- - lib/generators/action_args/rspec/scaffold/templates/action_args_controller_spec.rb
89
78
  - lib/generators/rails/action_args_scaffold_controller_generator.rb
90
79
  - lib/generators/rails/templates/controller.rb
91
- - spec/controllers/action_args_controller_spec.rb
92
- - spec/controllers/hooks_spec.rb
93
- - spec/controllers/kwargs_controller_spec.rb
94
- - spec/controllers/kwargs_keyreq_controller_spec.rb
95
- - spec/controllers/ordinal_controller_spec.rb
96
- - spec/controllers/strong_parameters_spec.rb
97
- - spec/fake_app.rb
98
- - spec/kwargs_controllers.rb
99
- - spec/kwargs_keyreq_controllers.rb
100
- - spec/mailers/action_mailer_spec.rb
101
- - spec/params_handler/params_handler_spec.rb
102
- - spec/spec_helper.rb
80
+ - test/controllers/action_args_controller_test.rb
81
+ - test/controllers/hooks_test.rb
82
+ - test/controllers/kwargs_controller_test.rb
83
+ - test/controllers/kwargs_keyreq_controller_test.rb
84
+ - test/controllers/ordinal_controller_test.rb
85
+ - test/controllers/strong_parameters_test.rb
86
+ - test/fake_app.rb
87
+ - test/kwargs_controllers.rb
88
+ - test/kwargs_keyreq_controllers.rb
89
+ - test/mailers/action_mailer_test.rb
90
+ - test/params_handler/params_handler_test.rb
91
+ - test/test_helper.rb
103
92
  homepage: http://asakusa.rubyist.net/
104
93
  licenses: []
105
94
  metadata: {}
@@ -119,20 +108,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
108
  version: '0'
120
109
  requirements: []
121
110
  rubyforge_project: action_args
122
- rubygems_version: 2.5.0
111
+ rubygems_version: 2.4.8
123
112
  signing_key:
124
113
  specification_version: 4
125
- summary: Controller action arguments parameterizer for Rails 3+ & Ruby 1.9+
114
+ summary: Controller action arguments parameterizer for Rails 4+ & Ruby 2.0+
126
115
  test_files:
127
- - spec/controllers/action_args_controller_spec.rb
128
- - spec/controllers/hooks_spec.rb
129
- - spec/controllers/kwargs_controller_spec.rb
130
- - spec/controllers/kwargs_keyreq_controller_spec.rb
131
- - spec/controllers/ordinal_controller_spec.rb
132
- - spec/controllers/strong_parameters_spec.rb
133
- - spec/fake_app.rb
134
- - spec/kwargs_controllers.rb
135
- - spec/kwargs_keyreq_controllers.rb
136
- - spec/mailers/action_mailer_spec.rb
137
- - spec/params_handler/params_handler_spec.rb
138
- - spec/spec_helper.rb
116
+ - test/controllers/action_args_controller_test.rb
117
+ - test/controllers/hooks_test.rb
118
+ - test/controllers/kwargs_controller_test.rb
119
+ - test/controllers/kwargs_keyreq_controller_test.rb
120
+ - test/controllers/ordinal_controller_test.rb
121
+ - test/controllers/strong_parameters_test.rb
122
+ - test/fake_app.rb
123
+ - test/kwargs_controllers.rb
124
+ - test/kwargs_keyreq_controllers.rb
125
+ - test/mailers/action_mailer_test.rb
126
+ - test/params_handler/params_handler_test.rb
127
+ - test/test_helper.rb
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --warnings
@@ -1,14 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'rails', '~> 3.2.9'
4
-
5
- gemspec :path => '../'
6
-
7
- platforms :ruby do
8
- gem 'sqlite3'
9
- end
10
-
11
- platforms :jruby do
12
- gem 'activerecord-jdbcsqlite3-adapter'
13
- end
14
- gem 'test-unit'
@@ -1,15 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'rails', '~> 4.0.0'
4
-
5
- gemspec :path => '../'
6
-
7
- platforms :ruby do
8
- gem 'sqlite3'
9
- end
10
-
11
- platforms :jruby do
12
- gem 'activerecord-jdbcsqlite3-adapter'
13
- end
14
-
15
- gem 'test-unit'
@@ -1,71 +0,0 @@
1
- module ActiveSupport
2
- module Callbacks
3
- class Callback
4
- if Rails.version > '4.1'
5
- # Extending AS::Callbacks::Callback's `make_lambda` not just to call specified
6
- # method but to call the method with method parameters taken from `params`.
7
- # This would happen only when
8
- # * the filter was defined in Symbol form
9
- # * the target object is_a ActionController object
10
- def make_lambda_with_method_parameters(filter)
11
- if Symbol === filter
12
- lambda do |target, _, &blk|
13
- if ActionController::Base === target
14
- meth = target.method filter
15
- method_parameters = meth.parameters
16
- ActionArgs::ParamsHandler.strengthen_params!(target.class, method_parameters, target.params)
17
- values = ActionArgs::ParamsHandler.extract_method_arguments_from_params method_parameters, target.params
18
- target.send filter, *values, &blk
19
- else
20
- target.send filter, &blk
21
- end
22
- end
23
- else
24
- make_lambda_without_method_parameters filter
25
- end
26
- end
27
- alias_method_chain :make_lambda, :method_parameters
28
-
29
- elsif Rails.version > '4.0'
30
- def apply_with_method_parameters(code)
31
- if (Symbol === @filter) && (@klass < ActionController::Base)
32
- method_body = <<-FILTER
33
- meth = method :#{@filter}
34
- method_parameters = meth.parameters
35
- ActionArgs::ParamsHandler.strengthen_params!(self.class, method_parameters, params)
36
- values = ActionArgs::ParamsHandler.extract_method_arguments_from_params method_parameters, params
37
- send :#{@filter}, *values
38
- FILTER
39
- if @kind == :before
40
- @filter = "begin\n#{method_body}\nend"
41
- else
42
- @filter = method_body.chomp
43
- end
44
- end
45
- apply_without_method_parameters code
46
- end
47
- alias_method_chain :apply, :method_parameters
48
-
49
- else # Rails 3.2
50
- def start_with_method_parameters(key=nil, object=nil)
51
- if (Symbol === @filter) && (@klass < ActionController::Base)
52
- method_body = <<-FILTER
53
- meth = method :#{@filter}
54
- method_parameters = meth.parameters
55
- ActionArgs::ParamsHandler.strengthen_params!(self.class, method_parameters, params)
56
- values = ActionArgs::ParamsHandler.extract_method_arguments_from_params method_parameters, params
57
- send :#{@filter}, *values
58
- FILTER
59
- if @kind == :before
60
- @filter = "begin\n#{method_body}\nend"
61
- else
62
- @filter = method_body.chomp
63
- end
64
- end
65
- start_without_method_parameters key, object
66
- end
67
- alias_method_chain :start, :method_parameters
68
- end
69
- end
70
- end
71
- end
@@ -1,18 +0,0 @@
1
- # load original rspec scaffold generator
2
- require 'generators/rspec/scaffold/scaffold_generator'
3
-
4
- # override rspec genarator to switch template file
5
- module Rspec
6
- module Generators
7
- class ScaffoldGenerator < Base
8
- source_paths << File.expand_path('../templates', __FILE__)
9
-
10
- def generate_controller_spec
11
- return unless options[:controller_specs]
12
-
13
- template 'action_args_controller_spec.rb',
14
- File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
15
- end
16
- end
17
- end
18
- end
@@ -1,130 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe <%= controller_class_name %>Controller do
4
- # This should return the minimal set of attributes required to create a valid
5
- # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
6
- # update the return value of this method accordingly.
7
- def valid_attributes
8
- <%= formatted_hash(example_valid_attributes) %>
9
- end
10
-
11
- <% unless options[:singleton] -%>
12
- describe 'GET index' do
13
- before do
14
- @<%= file_name %> = <%= class_name %>.create! valid_attributes
15
- controller.index
16
- end
17
- describe 'assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>' do
18
- subject { controller.instance_variable_get('@<%= table_name %>') }
19
- it { should eq([@<%= file_name %>]) }
20
- end
21
- end
22
-
23
- <% end -%>
24
- describe 'GET show' do
25
- before do
26
- @<%= file_name %> = <%= class_name %>.create! valid_attributes
27
- controller.show(@<%= file_name %>.to_param)
28
- end
29
- describe 'assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>' do
30
- subject { controller.instance_variable_get('@<%= ns_file_name %>') }
31
- it { should eq(@<%= file_name %>) }
32
- end
33
- end
34
-
35
- describe 'GET new' do
36
- before do
37
- controller.new
38
- end
39
- describe 'assigns a new <%= ns_file_name %> as @<%= ns_file_name %>' do
40
- subject { controller.instance_variable_get('@<%= ns_file_name %>') }
41
- it { should be_a_new(<%= class_name %>) }
42
- end
43
- end
44
-
45
- describe 'GET edit' do
46
- before do
47
- @<%= file_name %> = <%= class_name %>.create! valid_attributes
48
- controller.edit(@<%= file_name %>.to_param)
49
- end
50
- describe 'assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>' do
51
- subject { controller.instance_variable_get('@<%= ns_file_name %>') }
52
- it { should eq(@<%= file_name %>) }
53
- end
54
- end
55
-
56
- describe 'POST create' do
57
- context 'with valid params' do
58
- before do
59
- controller.should_receive(:redirect_to) {|u| u.should eq(<%= class_name %>.last) }
60
- end
61
- describe 'creates a new <%= class_name %>' do
62
- it { expect {
63
- controller.create(valid_attributes)
64
- }.to change(<%= class_name %>, :count).by(1) }
65
- end
66
-
67
- describe 'assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %> and redirects to the created <%= ns_file_name %>' do
68
- before do
69
- controller.create(valid_attributes)
70
- end
71
- subject { controller.instance_variable_get('@<%= ns_file_name %>') }
72
- it { should be_a(<%= class_name %>) }
73
- it { should be_persisted }
74
- end
75
- end
76
-
77
- context 'with invalid params' do
78
- describe "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>, and re-renders the 'new' template" do
79
- before do
80
- <%= class_name %>.any_instance.stub(:save) { false }
81
- controller.should_receive(:render).with(:action => 'new')
82
- controller.create(<%= formatted_hash(example_invalid_attributes) %>)
83
- end
84
- subject { controller.instance_variable_get('@<%= ns_file_name %>') }
85
- it { should be_a_new(<%= class_name %>) }
86
- end
87
- end
88
- end
89
-
90
- describe 'PUT update' do
91
- context 'with valid params' do
92
- describe 'updates the requested <%= ns_file_name %>, assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>, and redirects to the <%= ns_file_name %>' do
93
- before do
94
- @<%= file_name %> = <%= class_name %>.create! valid_attributes
95
- controller.should_receive(:redirect_to).with(@<%= file_name %>, anything)
96
- controller.update(@<%= file_name %>.to_param, valid_attributes)
97
- end
98
- subject { controller.instance_variable_get('@<%= ns_file_name %>') }
99
- it { should eq(@<%= file_name %>) }
100
- end
101
- end
102
-
103
- context 'with invalid params' do
104
- describe "assigns the <%= ns_file_name %> as @<%= ns_file_name %>, and re-renders the 'edit' template" do
105
- before do
106
- @<%= file_name %> = <%= class_name %>.create! valid_attributes
107
- # Trigger the behavior that occurs when invalid params are submitted
108
- <%= class_name %>.any_instance.stub(:save) { false }
109
- controller.should_receive(:render).with(:action => 'edit')
110
- controller.update(@<%= file_name %>.to_param, <%= formatted_hash(example_invalid_attributes) %>)
111
- end
112
- subject { controller.instance_variable_get('@<%= ns_file_name %>') }
113
- it { should eq(@<%= file_name %>) }
114
- end
115
- end
116
- end
117
-
118
- describe 'DELETE destroy' do
119
- before do
120
- @<%= file_name %> = <%= class_name %>.create! valid_attributes
121
- controller.stub(:<%= index_helper %>_url) { '/<%= index_helper %>' }
122
- controller.should_receive(:redirect_to).with('/<%= index_helper %>')
123
- end
124
- it 'destroys the requested <%= ns_file_name %>, and redirects to the <%= table_name %> list' do
125
- expect {
126
- controller.destroy(@<%= file_name %>.to_param)
127
- }.to change(<%= class_name %>, :count).by(-1)
128
- end
129
- end
130
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe BooksController do
4
- describe 'GET index (having an optional parameter)' do
5
- before do
6
- @books = []
7
- Book.delete_all
8
- 100.times {|i| @books << Book.create!(title: 'book'+i.to_s) }
9
- end
10
- context 'without page parameter' do
11
- before { get :index }
12
- its(:response) { should be_success }
13
- it { expect(assigns(:books)).to match_array(@books[0..9]) }
14
- end
15
-
16
- context 'with page parameter' do
17
- before { get :index, page: 3 }
18
- its(:response) { should be_success }
19
- it { expect(assigns(:books)).to match_array(@books[20..29]) }
20
- end
21
-
22
- context 'first param is nil and second is not nil' do
23
- let!(:rhg) { Book.create! title: 'RHG' }
24
- let!(:awdwr) { Book.create! title: 'AWDwR' }
25
- before { get :index, q: 'RH' }
26
- subject { assigns :books }
27
- it { should == [rhg] }
28
- end
29
- end
30
-
31
- describe 'GET show' do
32
- let(:rhg) { Book.create! title: 'RHG' }
33
- before { get :show, :id => rhg.id }
34
- subject { assigns :book }
35
- it { should == rhg }
36
- end
37
-
38
- describe 'POST create' do
39
- let(:rhg) { Book.create! title: 'RHG' }
40
- it { expect { post :create, :book => {title: 'AWDwR', price: 24} }.to change(Book, :count).by(1) }
41
- end
42
- end