action_args 0.0.2 → 0.0.3
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.
- data/README.rdoc +4 -4
- data/lib/action_args/version.rb +1 -1
- data/lib/generators/action_args/rspec/scaffold/scaffold_generator.rb +18 -0
- data/lib/generators/action_args/rspec/scaffold/templates/action_args_controller_spec.rb +134 -0
- data/lib/generators/rails/action_args_scaffold_controller_generator.rb +5 -0
- metadata +21 -39
data/README.rdoc
CHANGED
@@ -60,9 +60,9 @@ The following beautiful controller code will be generated:
|
|
60
60
|
@user = User.new(user)
|
61
61
|
|
62
62
|
if @user.save
|
63
|
-
redirect_to @user, :
|
63
|
+
redirect_to @user, notice: 'User was successfully created.'
|
64
64
|
else
|
65
|
-
render :
|
65
|
+
render action: 'new'
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -71,9 +71,9 @@ The following beautiful controller code will be generated:
|
|
71
71
|
@user = User.find(id)
|
72
72
|
|
73
73
|
if @user.update_attributes(user)
|
74
|
-
redirect_to @user, :
|
74
|
+
redirect_to @user, notice: 'User was successfully updated.'
|
75
75
|
else
|
76
|
-
render :
|
76
|
+
render action: 'edit'
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
data/lib/action_args/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
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
|
@@ -0,0 +1,134 @@
|
|
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
|
+
{}
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
@controller = <%= controller_class_name %>Controller.new
|
13
|
+
end
|
14
|
+
|
15
|
+
<% unless options[:singleton] -%>
|
16
|
+
describe 'GET index' do
|
17
|
+
before do
|
18
|
+
@<%= file_name %> = <%= class_name %>.create! valid_attributes
|
19
|
+
@controller.index
|
20
|
+
end
|
21
|
+
describe 'assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>' do
|
22
|
+
subject { @controller.instance_variable_get('@<%= table_name %>') }
|
23
|
+
it { should eq([@<%= file_name %>]) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
<% end -%>
|
28
|
+
describe 'GET show' do
|
29
|
+
before do
|
30
|
+
@<%= file_name %> = <%= class_name %>.create! valid_attributes
|
31
|
+
@controller.show(@<%= file_name %>.to_param)
|
32
|
+
end
|
33
|
+
describe 'assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>' do
|
34
|
+
subject { @controller.instance_variable_get('@<%= ns_file_name %>') }
|
35
|
+
it { should eq(@<%= file_name %>) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'GET new' do
|
40
|
+
before do
|
41
|
+
@controller.new
|
42
|
+
end
|
43
|
+
describe 'assigns a new <%= ns_file_name %> as @<%= ns_file_name %>' do
|
44
|
+
subject { @controller.instance_variable_get('@<%= ns_file_name %>') }
|
45
|
+
it { should be_a_new(<%= class_name %>) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'GET edit' do
|
50
|
+
before do
|
51
|
+
@<%= file_name %> = <%= class_name %>.create! valid_attributes
|
52
|
+
@controller.edit(@<%= file_name %>.to_param)
|
53
|
+
end
|
54
|
+
describe 'assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>' do
|
55
|
+
subject { @controller.instance_variable_get('@<%= ns_file_name %>') }
|
56
|
+
it { should eq(@<%= file_name %>) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'POST create' do
|
61
|
+
context 'with valid params' do
|
62
|
+
before do
|
63
|
+
@controller.should_receive(:redirect_to) {|u| u.should eq(<%= class_name %>.last) }
|
64
|
+
end
|
65
|
+
describe 'creates a new <%= class_name %>' do
|
66
|
+
it { expect {
|
67
|
+
@controller.create(valid_attributes)
|
68
|
+
}.to change(<%= class_name %>, :count).by(1) }
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %> and redirects to the created <%= ns_file_name %>' do
|
72
|
+
before do
|
73
|
+
@controller.create(valid_attributes)
|
74
|
+
end
|
75
|
+
subject { @controller.instance_variable_get('@<%= ns_file_name %>') }
|
76
|
+
it { should be_a(<%= class_name %>) }
|
77
|
+
it { should be_persisted }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'with invalid params' do
|
82
|
+
describe "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>, and re-renders the 'new' template" do
|
83
|
+
before do
|
84
|
+
<%= class_name %>.any_instance.stub(:save) { false }
|
85
|
+
@controller.should_receive(:render).with(:action => 'new')
|
86
|
+
@controller.create({})
|
87
|
+
end
|
88
|
+
subject { @controller.instance_variable_get('@<%= ns_file_name %>') }
|
89
|
+
it { should be_a_new(<%= class_name %>) }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'PUT update' do
|
95
|
+
context 'with valid params' do
|
96
|
+
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
|
97
|
+
before do
|
98
|
+
@<%= file_name %> = <%= class_name %>.create! valid_attributes
|
99
|
+
@controller.should_receive(:redirect_to).with(@<%= file_name %>, anything)
|
100
|
+
@controller.update(@<%= file_name %>.to_param, valid_attributes)
|
101
|
+
end
|
102
|
+
subject { @controller.instance_variable_get('@<%= ns_file_name %>') }
|
103
|
+
it { should eq(@<%= file_name %>) }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with invalid params' do
|
108
|
+
describe "assigns the <%= ns_file_name %> as @<%= ns_file_name %>, and re-renders the 'edit' template" do
|
109
|
+
before do
|
110
|
+
@<%= file_name %> = <%= class_name %>.create! valid_attributes
|
111
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
112
|
+
<%= class_name %>.any_instance.stub(:save) { false }
|
113
|
+
@controller.should_receive(:render).with(:action => 'edit')
|
114
|
+
@controller.update(@<%= file_name %>.to_param, {})
|
115
|
+
end
|
116
|
+
subject { @controller.instance_variable_get('@<%= ns_file_name %>') }
|
117
|
+
it { should eq(@<%= file_name %>) }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'DELETE destroy' do
|
123
|
+
before do
|
124
|
+
@<%= file_name %> = <%= class_name %>.create! valid_attributes
|
125
|
+
@controller.stub(:<%= index_helper %>_url) { '/<%= index_helper %>' }
|
126
|
+
@controller.should_receive(:redirect_to).with('/<%= index_helper %>')
|
127
|
+
end
|
128
|
+
it 'destroys the requested <%= ns_file_name %>, and redirects to the <%= table_name %> list' do
|
129
|
+
expect {
|
130
|
+
@controller.destroy(@<%= file_name %>.to_param)
|
131
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# load original rails scaffold_controller generator
|
1
2
|
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
|
2
3
|
|
4
|
+
# override rails genarator to switch template directory
|
3
5
|
module Rails
|
4
6
|
module Generators
|
5
7
|
class ActionArgsScaffoldControllerGenerator < ::Rails::Generators::ScaffoldControllerGenerator
|
@@ -7,3 +9,6 @@ module Rails
|
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
12
|
+
|
13
|
+
# load custom rspec generator
|
14
|
+
require 'generators/action_args/rspec/scaffold/scaffold_generator' if defined? ::RSpec::Rails
|
metadata
CHANGED
@@ -1,33 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_args
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Akira Matsuda
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-05-17 00:00:00 Z
|
12
|
+
date: 2012-02-29 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: Rails 3 plugin gem that supports Merbish style controller action arguments.
|
22
|
-
email:
|
15
|
+
email:
|
23
16
|
- ronnie@dio.jp
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
20
|
+
files:
|
31
21
|
- .gitignore
|
32
22
|
- Gemfile
|
33
23
|
- MIT-LICENSE
|
@@ -37,40 +27,32 @@ files:
|
|
37
27
|
- lib/action_args.rb
|
38
28
|
- lib/action_args/abstract_controller.rb
|
39
29
|
- lib/action_args/version.rb
|
30
|
+
- lib/generators/action_args/rspec/scaffold/scaffold_generator.rb
|
31
|
+
- lib/generators/action_args/rspec/scaffold/templates/action_args_controller_spec.rb
|
40
32
|
- lib/generators/rails/action_args_scaffold_controller_generator.rb
|
41
33
|
- lib/generators/rails/templates/controller.rb
|
42
34
|
homepage: http://asakusa.rubyist.net/
|
43
35
|
licenses: []
|
44
|
-
|
45
36
|
post_install_message:
|
46
37
|
rdoc_options: []
|
47
|
-
|
48
|
-
require_paths:
|
38
|
+
require_paths:
|
49
39
|
- lib
|
50
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
41
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
|
57
|
-
- 0
|
58
|
-
version: "0"
|
59
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
47
|
none: false
|
61
|
-
requirements:
|
62
|
-
- -
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
|
65
|
-
segments:
|
66
|
-
- 0
|
67
|
-
version: "0"
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
68
52
|
requirements: []
|
69
|
-
|
70
53
|
rubyforge_project: action_args
|
71
|
-
rubygems_version: 1.8.
|
54
|
+
rubygems_version: 1.8.17
|
72
55
|
signing_key:
|
73
56
|
specification_version: 3
|
74
57
|
summary: Controller action arguments parameterizer for Rails 3 + Ruby 1.9
|
75
58
|
test_files: []
|
76
|
-
|