rspec_rails_scaffold_templates 1.2.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb9fa57cda2a4744edffadd02b61ef86bce7bfd1
4
- data.tar.gz: 6e2ce7300fc7e1ac7789e5ef0036ee02a55515fc
3
+ metadata.gz: ebde8fc9113ac7c8adaaf8ab48b726da504e6fba
4
+ data.tar.gz: 7d8320c70281539067cc096656b2cbb15342f20b
5
5
  SHA512:
6
- metadata.gz: 7d706be391e38d4f159732aef7144712b14de373a759d292fe40d51a2077aa889fda41c77082f4a0aece3bedd14f75c7426ad1c07ae18b912bb4df130dc52efa
7
- data.tar.gz: 32962541aee92043cf1aa1b4fca0409dc9621049a76f408033ef6ff292a3d3d9cd89021ddaf1c653467ac839c9225da985e86e16b95fb39a222be509e0478ac9
6
+ metadata.gz: d519b0a14c7f345c797e8dcdf363bb5e7de0a2bc902919d816729c85a03042087a45b03623760cd6933de392251297077f47a036088ec8390156d740c2bbca87
7
+ data.tar.gz: ab2ed8392fdbb3edbeb37ab0bbfe03c346b4f9e62f1ee8d0ca983e9b3abbfe702c2b49bf58621042ccc21c78af62a09be75b5803a39f3023be107cead0d25881
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.5
1
+ 2.0.0
@@ -1,7 +1 @@
1
- module RspecRailsScaffoldTemplates
2
- class Railtie < Rails::Railtie
3
- config.app_generators do |g|
4
- g.templates.unshift File::expand_path('../templates', __FILE__)
5
- end
6
- end
7
- end
1
+ require 'rspec_rails_scaffold_templates/railties' if defined?(Rails)
@@ -0,0 +1,28 @@
1
+ require 'generators/rspec'
2
+ require 'rails/generators/resource_helpers'
3
+
4
+ module Rspec
5
+ module Generators
6
+ class ScaffoldGenerator < Base
7
+ class_option :with_api, type: :boolean,
8
+ desc: "Generates also API controller in 'app/contorllers/api'"
9
+ class_option :api_version, type: :string,
10
+ desc: "Adds specified path as version to 'app/contorllers/api'"
11
+
12
+ def generate_api_controller_spec
13
+ return unless options[:controller_specs]
14
+ return unless options[:with_api]
15
+
16
+ source_paths.unshift File.expand_path('../templates/rspec/scaffold/', __FILE__)
17
+ path = [
18
+ 'spec/controllers/api',
19
+ options[:api_version],
20
+ controller_class_path,
21
+ "#{controller_file_name}_controller_spec.rb"
22
+ ].compact
23
+ template_file = File.join *path
24
+ template 'api_controller_spec.rb', template_file
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,263 @@
1
+ <% if File.exist?(File.join %w[spec rails_helper.rb]) -%>
2
+ require 'rails_helper'
3
+ <% else -%>
4
+ require 'spec_helper'
5
+ <% end -%>
6
+
7
+ <% module_namespacing do -%>
8
+ describe Api::<%= options[:api_version].camelcase + '::' if options[:api_version].present? %><%= controller_class_name %>Controller, <%= type_metatag(:controller) %> do
9
+ <% if method = Rails.application.config.generators.options[:rails][:cancan] -%>
10
+ <% method = 'current_user' unless Symbol === method -%>
11
+ before :each do
12
+ allow(controller).to receive(:<%=method%>).and_return(<%=method%>)
13
+ end
14
+
15
+ <% end -%>
16
+ # This should return the minimal set of attributes required to create a valid
17
+ # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
18
+ # adjust the attributes here as well. The list could not be empty.
19
+ <% links = attributes.select{|a| [:belongs_to, :references].include? a.type} -%>
20
+ <% attribute = (attributes - links).detect{|a| a.name == 'name' || a.name == 'title' || a.name == 'code' || a.name =~ /name/ || a.name =~ /title/} || attributes.first -%>
21
+ <% attribute_name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name -%>
22
+ <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
23
+ <% factory_girl = true -%>
24
+ let(:<%= file_name %>) {create :<%= file_name %>}
25
+
26
+ <% if links.present? -%>
27
+ let(:valid_attributes) do
28
+ FactoryGirl.attributes_for(:<%=file_name%>)
29
+ .slice(*%w[<%= attribute_name %>].map(&:to_sym))
30
+ .merge(
31
+ <% links.each do |relation| -%>
32
+ <%= relation.name %>_id: create(:<%= relation.name %>).id,
33
+ <% end -%>
34
+ )
35
+ end
36
+ <% else -%>
37
+ let(:valid_attributes) {FactoryGirl.attributes_for(:<%=file_name%>).slice *%w[<%= attribute_name %>].map(&:to_sym)}
38
+ <% end -%>
39
+ <% else -%>
40
+ <% factory_girl = false -%>
41
+ let(:<%= file_name %>) {<%= class_name %>.create! valid_attributes}
42
+
43
+ let(:valid_attributes) do
44
+ skip("Add a hash of attributes valid for your model")
45
+ end
46
+ <% end -%>
47
+
48
+ let(:invalid_attributes) do
49
+ # {<%= attribute_name %>: ''}
50
+ skip("Add a hash of attributes invalid for your model")
51
+ end
52
+
53
+ # This should return the minimal set of values that should be in the session
54
+ # in order to pass any filters (e.g. authentication) defined in
55
+ # <%= controller_class_name %>Controller. Be sure to keep this updated too.
56
+ let(:valid_session) { {} }
57
+
58
+ <% unless options[:singleton] -%>
59
+ describe "GET #index" do
60
+ it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
61
+ <%= file_name %>
62
+ <% if RUBY_VERSION < '1.9.3' -%>
63
+ get :index, {}, valid_session
64
+ <% else -%>
65
+ get :index, params: {}, session: valid_session
66
+ <% end -%>
67
+ expect(assigns(:<%= table_name %>)).to be_kind_of(ActiveRecord::Relation)
68
+ expect(assigns(:<%= table_name %>)).to eq([<%= file_name %>])
69
+ end
70
+ end
71
+
72
+ <% end -%>
73
+ describe "GET #show" do
74
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
75
+ <% if RUBY_VERSION < '1.9.3' -%>
76
+ get :show, {:id => <%= file_name %>.to_param}, valid_session
77
+ <% else -%>
78
+ get :show,
79
+ params: {id: <%= file_name %>.to_param},
80
+ session: valid_session
81
+ <% end -%>
82
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
83
+ end
84
+ end
85
+
86
+ describe "POST #create" do
87
+ context "with valid params" do
88
+ it "creates a new <%= class_name %>" do
89
+ expect do
90
+ <% if RUBY_VERSION < '1.9.3' -%>
91
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
92
+ <% else -%>
93
+ post :create,
94
+ params: {<%= ns_file_name %>: valid_attributes},
95
+ session: valid_session
96
+ <% end -%>
97
+ end.to change(<%= class_name %>, :count).by(1)
98
+ end
99
+
100
+ it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
101
+ <% if RUBY_VERSION < '1.9.3' -%>
102
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
103
+ <% else -%>
104
+ post :create,
105
+ params: {<%= ns_file_name %>: valid_attributes},
106
+ session: valid_session
107
+ <% end -%>
108
+ expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
109
+ expect(assigns(:<%= ns_file_name %>)).to be_persisted
110
+ end
111
+
112
+ it 'returns the "created" status' do
113
+ <% if RUBY_VERSION < '1.9.3' -%>
114
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
115
+ <% else -%>
116
+ post :create,
117
+ params: {<%= ns_file_name %>: valid_attributes},
118
+ session: valid_session
119
+ <% end -%>
120
+ expect(response).to have_http_status :created
121
+ end
122
+ end # with valid params
123
+
124
+ context "with invalid params" do
125
+ it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
126
+ # allow_any_instance_of(<%= class_name %>).to receive(:save).and_return(false)
127
+ <% if RUBY_VERSION < '1.9.3' -%>
128
+ post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
129
+ <% else -%>
130
+ post :create,
131
+ params: {<%= ns_file_name %>: invalid_attributes},
132
+ session: valid_session
133
+ <% end -%>
134
+ expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
135
+ end
136
+
137
+ it 'returns the "unprocessable_entity" status' do
138
+ # allow_any_instance_of(<%= class_name %>).to receive(:save).and_return(false)
139
+ <% if RUBY_VERSION < '1.9.3' -%>
140
+ post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
141
+ <% else -%>
142
+ post :create,
143
+ params: {<%= ns_file_name %>: invalid_attributes},
144
+ session: valid_session
145
+ <% end -%>
146
+ expect(response).to have_http_status :unprocessable_entity
147
+ end
148
+ end # with invalid params
149
+ end # POST #create
150
+
151
+ describe "PUT #update" do
152
+ context "with valid params" do
153
+ let(:new_attributes) { {<%= attribute_name %>: 'New value'} }
154
+
155
+ it "updates the requested <%= ns_file_name %>" do
156
+ # expect_any_instance_of(<%= class_name %>)
157
+ # .to receive(:update).with(new_attributes.inject({}){|_, (k, v)| _[k] = v.to_s; _})
158
+ <% if RUBY_VERSION < '1.9.3' -%>
159
+ put :update,
160
+ {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes},
161
+ valid_session
162
+ <% else -%>
163
+ put :update,
164
+ params: {id: <%= file_name %>.to_param,
165
+ <%= ns_file_name %>: new_attributes},
166
+ session: valid_session
167
+ <% end -%>
168
+ <%= file_name %>.reload
169
+ # skip("Add assertions for updated state")
170
+ expect(<%= file_name %>.<%= attribute_name %>).to eq 'New value'
171
+ end
172
+
173
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
174
+ <% if RUBY_VERSION < '1.9.3' -%>
175
+ put :update,
176
+ {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes},
177
+ valid_session
178
+ <% else -%>
179
+ put :update,
180
+ params: {id: <%= file_name %>.to_param,
181
+ <%= ns_file_name %>: valid_attributes},
182
+ session: valid_session
183
+ <% end -%>
184
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
185
+ end
186
+
187
+ it 'returns the "OK" status' do
188
+ <% if RUBY_VERSION < '1.9.3' -%>
189
+ put :update,
190
+ {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes},
191
+ valid_session
192
+ <% else -%>
193
+ put :update,
194
+ params: {id: <%= file_name %>.to_param,
195
+ <%= ns_file_name %>: valid_attributes},
196
+ session: valid_session
197
+ <% end -%>
198
+ expect(response).to have_http_status :ok
199
+ end
200
+ end # with valid params
201
+
202
+ context "with invalid params" do
203
+ it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
204
+ # allow_any_instance_of(<%= class_name %>).to receive(:update).and_return(false)
205
+ <% if RUBY_VERSION < '1.9.3' -%>
206
+ put :update,
207
+ {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes},
208
+ valid_session
209
+ <% else -%>
210
+ put :update,
211
+ params: {id: <%= file_name %>.to_param,
212
+ <%= ns_file_name %>: invalid_attributes},
213
+ session: valid_session
214
+ <% end -%>
215
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
216
+ end
217
+
218
+ it 'returns the "unprocessable_entity" status' do
219
+ # allow_any_instance_of(<%= class_name %>).to receive(:update).and_return(false)
220
+ <% if RUBY_VERSION < '1.9.3' -%>
221
+ put :update,
222
+ {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes},
223
+ valid_session
224
+ <% else -%>
225
+ put :update,
226
+ params: {id: <%= file_name %>.to_param,
227
+ <%= ns_file_name %>: invalid_attributes},
228
+ session: valid_session
229
+ <% end -%>
230
+ expect(response).to have_http_status :unprocessable_entity
231
+ end
232
+ end # with invalid params
233
+ end # PUT #update
234
+
235
+ describe "DELETE #destroy" do
236
+ it "destroys the requested <%= ns_file_name %>" do
237
+ <%= file_name %>
238
+ expect do
239
+ <% if RUBY_VERSION < '1.9.3' -%>
240
+ delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
241
+ <% else -%>
242
+ delete :destroy,
243
+ params: {id: <%= file_name %>.to_param},
244
+ session: valid_session
245
+ <% end -%>
246
+ end.to change(<%= class_name %>, :count).by(-1)
247
+ end
248
+
249
+ it 'returns the "no_content" status' do
250
+ <%= file_name %>
251
+ <% if RUBY_VERSION < '1.9.3' -%>
252
+ delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
253
+ <% else -%>
254
+ delete :destroy,
255
+ params: {id: <%= file_name %>.to_param},
256
+ session: valid_session
257
+ <% end -%>
258
+ expect(response).to have_http_status :no_content
259
+ end
260
+ end # DELETE #destroy
261
+
262
+ end
263
+ <% end -%>
@@ -5,8 +5,7 @@ require 'spec_helper'
5
5
  <% end -%>
6
6
 
7
7
  <% module_namespacing do -%>
8
- describe <%= controller_class_name %>Controller, type: :controller do
9
-
8
+ describe <%= controller_class_name %>Controller, <%= type_metatag(:controller) %> do
10
9
  <% if method = Rails.application.config.generators.options[:rails][:cancan] -%>
11
10
  <% method = 'current_user' unless Symbol === method -%>
12
11
  before :each do
@@ -22,6 +21,8 @@ describe <%= controller_class_name %>Controller, type: :controller do
22
21
  <% attribute_name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name -%>
23
22
  <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
24
23
  <% factory_girl = true -%>
24
+ let(:<%= file_name %>) {create :<%= file_name %>}
25
+
25
26
  <% if links.present? -%>
26
27
  let(:valid_attributes) do
27
28
  FactoryGirl.attributes_for(:<%=file_name%>)
@@ -37,6 +38,8 @@ describe <%= controller_class_name %>Controller, type: :controller do
37
38
  <% end -%>
38
39
  <% else -%>
39
40
  <% factory_girl = false -%>
41
+ let(:<%= file_name %>) {<%= class_name %>.create! valid_attributes}
42
+
40
43
  let(:valid_attributes) do
41
44
  skip("Add a hash of attributes valid for your model")
42
45
  end
@@ -53,173 +56,232 @@ describe <%= controller_class_name %>Controller, type: :controller do
53
56
  let(:valid_session) { {} }
54
57
 
55
58
  <% unless options[:singleton] -%>
56
- describe "GET index" do
59
+ describe "GET #index" do
57
60
  it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
58
- <% if factory_girl -%>
59
- <%= file_name %> = create :<%= file_name %>
61
+ <%= file_name %>
62
+ <% if RUBY_VERSION < '1.9.3' -%>
63
+ get :index, {}, valid_session
60
64
  <% else -%>
61
- <%= file_name %> = <%= class_name %>.create! valid_attributes
65
+ get :index, params: {}, session: valid_session
62
66
  <% end -%>
63
- get :index, {}, valid_session
64
67
  expect(assigns(:<%= table_name %>)).to be_kind_of(ActiveRecord::Relation)
65
68
  expect(assigns(:<%= table_name %>)).to eq([<%= file_name %>])
66
69
  end
67
70
  end
68
71
 
69
72
  <% end -%>
70
- describe "GET show" do
73
+ describe "GET #show" do
71
74
  it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
72
- <% if factory_girl -%>
73
- <%= file_name %> = create :<%= file_name %>
75
+ <% if RUBY_VERSION < '1.9.3' -%>
76
+ get :show, {:id => <%= file_name %>.to_param}, valid_session
74
77
  <% else -%>
75
- <%= file_name %> = <%= class_name %>.create! valid_attributes
78
+ get :show,
79
+ params: {id: <%= file_name %>.to_param},
80
+ session: valid_session
76
81
  <% end -%>
77
- get :show, {id: <%= file_name %>.to_param}, valid_session
78
82
  expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
79
83
  end
80
84
  end
81
85
 
82
- describe "GET new" do
86
+ describe "GET #new" do
83
87
  it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
88
+ <% if RUBY_VERSION < '1.9.3' -%>
84
89
  get :new, {}, valid_session
90
+ <% else -%>
91
+ get :new, params: {}, session: valid_session
92
+ <% end -%>
85
93
  expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
86
94
  end
87
95
  end
88
96
 
89
- describe "GET edit" do
97
+ describe "GET #edit" do
90
98
  it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
91
- <% if factory_girl -%>
92
- <%= file_name %> = create :<%= file_name %>
99
+ <% if RUBY_VERSION < '1.9.3' -%>
100
+ get :edit, {:id => <%= file_name %>.to_param}, valid_session
93
101
  <% else -%>
94
- <%= file_name %> = <%= class_name %>.create! valid_attributes
102
+ get :edit, params: {id: <%= file_name %>.to_param},
103
+ session: valid_session
95
104
  <% end -%>
96
- get :edit, {id: <%= file_name %>.to_param}, valid_session
97
105
  expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
98
106
  end
99
107
  end
100
108
 
101
- describe "POST create" do
102
- describe "with valid params" do
109
+ describe "POST #create" do
110
+ context "with valid params" do
103
111
  it "creates a new <%= class_name %>" do
104
112
  expect do
105
- post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
113
+ <% if RUBY_VERSION < '1.9.3' -%>
114
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
115
+ <% else -%>
116
+ post :create,
117
+ params: {<%= ns_file_name %>: valid_attributes},
118
+ session: valid_session
119
+ <% end -%>
106
120
  end.to change(<%= class_name %>, :count).by(1)
107
121
  end
108
122
 
109
123
  it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
110
- post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
124
+ <% if RUBY_VERSION < '1.9.3' -%>
125
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
126
+ <% else -%>
127
+ post :create,
128
+ params: {<%= ns_file_name %>: valid_attributes},
129
+ session: valid_session
130
+ <% end -%>
111
131
  expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
112
132
  expect(assigns(:<%= ns_file_name %>)).to be_persisted
113
133
  end
114
134
 
115
135
  it "redirects to the created <%= ns_file_name %>" do
116
- post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
136
+ <% if RUBY_VERSION < '1.9.3' -%>
137
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
138
+ <% else -%>
139
+ post :create,
140
+ params: {<%= ns_file_name %>: valid_attributes},
141
+ session: valid_session
142
+ <% end -%>
117
143
  expect(response).to redirect_to(<%= class_name %>.last)
118
144
  # expect(response).to redirect_to(<%= index_helper %>_url)
119
145
  end
120
- end
146
+ end # with valid params
121
147
 
122
- describe "with invalid params" do
148
+ context "with invalid params" do
123
149
  it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
124
150
  # allow_any_instance_of(<%= class_name %>).to receive(:save).and_return(false)
125
- post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session
151
+ <% if RUBY_VERSION < '1.9.3' -%>
152
+ post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
153
+ <% else -%>
154
+ post :create,
155
+ params: {<%= ns_file_name %>: invalid_attributes},
156
+ session: valid_session
157
+ <% end -%>
126
158
  expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
127
159
  end
128
160
 
129
161
  it "re-renders the 'new' template" do
130
162
  # allow_any_instance_of(<%= class_name %>).to receive(:save).and_return(false)
131
- post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session
163
+ <% if RUBY_VERSION < '1.9.3' -%>
164
+ post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
165
+ <% else -%>
166
+ post :create,
167
+ params: {<%= ns_file_name %>: invalid_attributes},
168
+ session: valid_session
169
+ <% end -%>
132
170
  expect(response).to render_template("new")
133
171
  end
134
- end
135
- end # describe "POST create"
172
+ end # with invalid params
173
+ end # POST #create
136
174
 
137
- describe "PUT update" do
138
- describe "with valid params" do
175
+ describe "PUT #update" do
176
+ context "with valid params" do
139
177
  let(:new_attributes) { {<%= attribute_name %>: 'New value'} }
140
178
 
141
179
  it "updates the requested <%= ns_file_name %>" do
142
- <% if factory_girl -%>
143
- <%= file_name %> = create :<%= file_name %>
144
- <% else -%>
145
- <%= file_name %> = <%= class_name %>.create! valid_attributes
146
- <% end -%>
147
180
  # expect_any_instance_of(<%= class_name %>)
148
181
  # .to receive(:update).with(new_attributes.inject({}){|_, (k, v)| _[k] = v.to_s; _})
149
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session
182
+ <% if RUBY_VERSION < '1.9.3' -%>
183
+ put :update,
184
+ {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes},
185
+ valid_session
186
+ <% else -%>
187
+ put :update,
188
+ params: {id: <%= file_name %>.to_param,
189
+ <%= ns_file_name %>: new_attributes},
190
+ session: valid_session
191
+ <% end -%>
150
192
  <%= file_name %>.reload
151
193
  # skip("Add assertions for updated state")
152
194
  expect(<%= file_name %>.<%= attribute_name %>).to eq 'New value'
153
195
  end
154
196
 
155
197
  it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
156
- <% if factory_girl -%>
157
- <%= file_name %> = create :<%= file_name %>
198
+ <% if RUBY_VERSION < '1.9.3' -%>
199
+ put :update,
200
+ {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes},
201
+ valid_session
158
202
  <% else -%>
159
- <%= file_name %> = <%= class_name %>.create! valid_attributes
203
+ put :update,
204
+ params: {id: <%= file_name %>.to_param,
205
+ <%= ns_file_name %>: valid_attributes},
206
+ session: valid_session
160
207
  <% end -%>
161
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session
162
208
  expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
163
209
  end
164
210
 
165
211
  it "redirects to the <%= ns_file_name %>" do
166
- <% if factory_girl -%>
167
- <%= file_name %> = create :<%= file_name %>
212
+ <% if RUBY_VERSION < '1.9.3' -%>
213
+ put :update,
214
+ {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes},
215
+ valid_session
168
216
  <% else -%>
169
- <%= file_name %> = <%= class_name %>.create! valid_attributes
217
+ put :update,
218
+ params: {id: <%= file_name %>.to_param,
219
+ <%= ns_file_name %>: valid_attributes},
220
+ session: valid_session
170
221
  <% end -%>
171
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session
172
222
  expect(response).to redirect_to(<%= file_name %>)
173
223
  end
174
- end
224
+ end # with valid params
175
225
 
176
- describe "with invalid params" do
226
+ context "with invalid params" do
177
227
  it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
178
- <% if factory_girl -%>
179
- <%= file_name %> = create :<%= file_name %>
228
+ # allow_any_instance_of(<%= class_name %>).to receive(:update).and_return(false)
229
+ <% if RUBY_VERSION < '1.9.3' -%>
230
+ put :update,
231
+ {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes},
232
+ valid_session
180
233
  <% else -%>
181
- <%= file_name %> = <%= class_name %>.create! valid_attributes
234
+ put :update,
235
+ params: {id: <%= file_name %>.to_param,
236
+ <%= ns_file_name %>: invalid_attributes},
237
+ session: valid_session
182
238
  <% end -%>
183
- # allow_any_instance_of(<%= class_name %>).to receive(:update).and_return(false)
184
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session
185
- expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
239
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
186
240
  end
187
241
 
188
242
  it "re-renders the 'edit' template" do
189
- <% if factory_girl -%>
190
- <%= file_name %> = create :<%= file_name %>
243
+ # allow_any_instance_of(<%= class_name %>).to receive(:update).and_return(false)
244
+ <% if RUBY_VERSION < '1.9.3' -%>
245
+ put :update,
246
+ {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes},
247
+ valid_session
191
248
  <% else -%>
192
- <%= file_name %> = <%= class_name %>.create! valid_attributes
249
+ put :update,
250
+ params: {id: <%= file_name %>.to_param,
251
+ <%= ns_file_name %>: invalid_attributes},
252
+ session: valid_session
193
253
  <% end -%>
194
- # allow_any_instance_of(<%= class_name %>).to receive(:update).and_return(false)
195
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session
196
254
  expect(response).to render_template("edit")
197
255
  end
198
- end
199
- end # describe "PUT update"
256
+ end # with invalid params
257
+ end # PUT #update
200
258
 
201
- describe "DELETE destroy" do
259
+ describe "DELETE #destroy" do
202
260
  it "destroys the requested <%= ns_file_name %>" do
203
- <% if factory_girl -%>
204
- <%= file_name %> = create :<%= file_name %>
261
+ <%= file_name %>
262
+ expect do
263
+ <% if RUBY_VERSION < '1.9.3' -%>
264
+ delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
205
265
  <% else -%>
206
- <%= file_name %> = <%= class_name %>.create! valid_attributes
266
+ delete :destroy,
267
+ params: {id: <%= file_name %>.to_param},
268
+ session: valid_session
207
269
  <% end -%>
208
- expect do
209
- delete :destroy, {id: <%= file_name %>.to_param}, valid_session
210
270
  end.to change(<%= class_name %>, :count).by(-1)
211
271
  end
212
272
 
213
273
  it "redirects to the <%= table_name %> list" do
214
- <% if factory_girl -%>
215
- <%= file_name %> = create :<%= file_name %>
274
+ <%= file_name %>
275
+ <% if RUBY_VERSION < '1.9.3' -%>
276
+ delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
216
277
  <% else -%>
217
- <%= file_name %> = <%= class_name %>.create! valid_attributes
278
+ delete :destroy,
279
+ params: {id: <%= file_name %>.to_param},
280
+ session: valid_session
218
281
  <% end -%>
219
- delete :destroy, {id: <%= file_name %>.to_param}, valid_session
220
282
  expect(response).to redirect_to(<%= index_helper %>_url)
221
283
  end
222
- end # describe "DELETE destroy"
284
+ end # DELETE #destroy
223
285
 
224
286
  end
225
287
  <% end -%>
@@ -3,28 +3,37 @@ require 'rails_helper'
3
3
  <% else -%>
4
4
  require 'spec_helper'
5
5
  <% end -%>
6
+ <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
7
+ <% factory_girl = true -%>
8
+ <% else -%>
9
+ <% factory_girl = false -%>
10
+ <% end -%>
6
11
 
7
12
  <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
8
- describe "<%= ns_table_name %>/edit", type: :view do
9
- before(:each) do
10
- <% if Rails.application.config.generators.options[:rails][:cancan] -%>
11
- allow(controller).to receive(:can?).and_return(true)
12
- <% end -%>
13
- <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
14
- @<%= ns_file_name %> = assign(:<%= ns_file_name %>, create(:<%= ns_file_name %>))
13
+ describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
14
+ <% if factory_girl -%>
15
+ let(:<%= ns_file_name %>) {create :<%= ns_file_name %>}
15
16
  <% else -%>
16
- @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
17
+ let(:<%= ns_file_name %>) do
18
+ <%= class_name %>.create!(<%= ')' if output_attributes.empty? %>
17
19
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
18
20
  <%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
19
21
  <% end -%>
20
- <%= output_attributes.empty? ? "" : " ))\n" -%>
22
+ <%= output_attributes.empty? ? "" : " )\n" -%>
23
+ end
24
+ <% end -%>
25
+
26
+ before(:each) do
27
+ <% if Rails.application.config.generators.options[:rails][:cancan] -%>
28
+ allow(controller).to receive(:can?).and_return(true)
21
29
  <% end -%>
30
+ assign(:<%= ns_file_name %>, <%= ns_file_name %>)
22
31
  end
23
32
 
24
33
  it "renders the edit <%= ns_file_name %> form" do
25
34
  render
26
35
 
27
- assert_select "form[action='#{<%= ns_file_name %>_path(@<%= ns_file_name %>)}'][method='post']" do
36
+ assert_select "form[action='#{<%= ns_file_name %>_path(<%= ns_file_name %>)}'][method='post']" do
28
37
  <% for attribute in output_attributes -%>
29
38
  <% name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name -%>
30
39
  <% input_type = attribute.reference? ? 'select' : attribute.input_type -%>
@@ -3,27 +3,31 @@ require 'rails_helper'
3
3
  <% else -%>
4
4
  require 'spec_helper'
5
5
  <% end -%>
6
+ <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
7
+ <% factory_girl = true -%>
8
+ <% else -%>
9
+ <% factory_girl = false -%>
10
+ <% end -%>
6
11
 
7
12
  <% output_attributes = attributes.reject{|attribute| [:created_at, :deleted_at, :updated_at].index(attribute.name) or attribute.password_digest? } -%>
8
- describe "<%= ns_table_name %>/index", type: :view do
9
- before(:each) do
10
- <% if Rails.application.config.generators.options[:rails][:cancan] -%>
11
- allow(controller).to receive(:can?).and_return(true)
12
- <% end -%>
13
- <% if options[:fixture_replacement] == :factory_girl -%>
14
- # options[:fixture_replacement] == :factory_girl
15
- <% end -%>
16
- <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
17
- @<%= ns_file_name %> = create(:<%= ns_file_name %>)
18
- <% else # no factory_girl -%>
19
- <%= class_name %>.create(<%= output_attributes.empty? ? ')' : '' %>
13
+ describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
14
+ <% if factory_girl -%>
15
+ let(:<%= ns_file_name %>) {create :<%= ns_file_name %>}
16
+ <% else -%>
17
+ let(:<%= ns_file_name %>) do
18
+ <%= class_name %>.create!(<%= ')' if output_attributes.empty? %>
20
19
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
21
20
  <%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
22
21
  <% end -%>
23
- <% if !output_attributes.empty? -%>
24
- )
22
+ <%= output_attributes.empty? ? "" : " )\n" -%>
23
+ end
25
24
  <% end -%>
25
+
26
+ before(:each) do
27
+ <% if Rails.application.config.generators.options[:rails][:cancan] -%>
28
+ allow(controller).to receive(:can?).and_return(true)
26
29
  <% end -%>
30
+ <%= ns_file_name %> # to create
27
31
  assign :<%= table_name %>, <%= class_name %>.all
28
32
  end
29
33
 
@@ -33,9 +37,9 @@ describe "<%= ns_table_name %>/index", type: :view do
33
37
  <% for attribute in output_attributes -%>
34
38
  <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
35
39
  <% if attribute.reference? -%>
36
- assert_select 'tr>td', text: @<%= ns_file_name %>.<%= attribute.name %>.name, count: 1
40
+ assert_select 'tr>td', text: <%= ns_file_name %>.<%= attribute.name %>.name, count: 1
37
41
  <% else -%>
38
- assert_select 'tr>td', text: @<%= ns_file_name %>.<%= attribute.name %>.to_s, count: 1
42
+ assert_select 'tr>td', text: <%= ns_file_name %>.<%= attribute.name %>.to_s, count: 1
39
43
  <% end -%>
40
44
  <% else -%>
41
45
  assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 1
@@ -51,9 +55,9 @@ describe "<%= ns_table_name %>/index", type: :view do
51
55
  <% for attribute in output_attributes -%>
52
56
  <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
53
57
  <% if attribute.reference? -%>
54
- assert_select 'tr>td', text: @<%= ns_file_name %>.<%= attribute.name %>.name, count: 1
58
+ assert_select 'tr>td', text: <%= ns_file_name %>.<%= attribute.name %>.name, count: 1
55
59
  <% else -%>
56
- assert_select 'tr>td', text: @<%= ns_file_name %>.<%= attribute.name %>.to_s, count: 1
60
+ assert_select 'tr>td', text: <%= ns_file_name %>.<%= attribute.name %>.to_s, count: 1
57
61
  <% end -%>
58
62
  <% else -%>
59
63
  assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 1
@@ -3,23 +3,32 @@ require 'rails_helper'
3
3
  <% else -%>
4
4
  require 'spec_helper'
5
5
  <% end -%>
6
+ <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
7
+ <% factory_girl = true -%>
8
+ <% else -%>
9
+ <% factory_girl = false -%>
10
+ <% end -%>
6
11
 
7
12
  <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
8
- describe "<%= ns_table_name %>/new", type: :view do
9
- before(:each) do
10
- <% if Rails.application.config.generators.options[:rails][:cancan] -%>
11
- allow(controller).to receive(:can?).and_return(true)
12
- <% end -%>
13
- <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
14
- @<%= ns_file_name %> = assign(:<%= ns_file_name %>, build(:<%= ns_file_name %>))
15
- end
13
+ describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
14
+ <% if factory_girl -%>
15
+ let(:<%= ns_file_name %>) {build :<%= ns_file_name %>}
16
16
  <% else -%>
17
- assign(:<%= ns_file_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
17
+ let(:<%= ns_file_name %>) do
18
+ <%= class_name %>.new(<%= ')' if output_attributes.empty? %>
18
19
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
19
20
  <%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
20
21
  <% end -%>
21
- <%= !output_attributes.empty? ? " ))\n end" : " end" %>
22
+ <%= output_attributes.empty? ? "" : " )\n" -%>
23
+ end
24
+ <% end -%>
25
+
26
+ before(:each) do
27
+ <% if Rails.application.config.generators.options[:rails][:cancan] -%>
28
+ allow(controller).to receive(:can?).and_return(true)
22
29
  <% end -%>
30
+ assign(:<%= ns_file_name %>, <%= ns_file_name %>)
31
+ end
23
32
 
24
33
  it "renders new <%= ns_file_name %> form" do
25
34
  render
@@ -5,32 +5,36 @@ require 'spec_helper'
5
5
  <% end -%>
6
6
 
7
7
  <% output_attributes = attributes.reject{|attribute| [:created_at, :deleted_at, :updated_at].index(attribute.name) or attribute.password_digest? } -%>
8
- describe "<%= ns_table_name %>/show", type: :view do
9
- before(:each) do
10
- <% if Rails.application.config.generators.options[:rails][:cancan] -%>
11
- allow(controller).to receive(:can?).and_return(true)
12
- <% end -%>
8
+ describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
13
9
  <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
14
- @<%= ns_file_name %> = assign(:<%= ns_file_name %>, create(:<%= ns_file_name %>))
10
+ let(:<%= ns_file_name %>) {create :<%= ns_file_name %>}
15
11
  <% else -%>
16
- @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
12
+ let(:<%= ns_file_name %>) do
13
+ <%= class_name %>.create!(<%= ')' if output_attributes.empty? %>
17
14
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
18
15
  <%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
19
16
  <% end -%>
20
17
  <% if !output_attributes.empty? -%>
21
- ))
18
+ )
19
+ <% end -%>
20
+ end
22
21
  <% end -%>
22
+
23
+ before(:each) do
24
+ <% if Rails.application.config.generators.options[:rails][:cancan] -%>
25
+ allow(controller).to receive(:can?).and_return(true)
23
26
  <% end -%>
27
+ assign :<%= ns_file_name %>, <%= ns_file_name %>
24
28
  end
25
29
 
26
- it "renders attributes in <dl>" do
30
+ it "renders attributes in dl>dd" do
27
31
  render
28
32
  <% for attribute in output_attributes -%>
29
33
  <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
30
34
  <% if attribute.reference? -%>
31
- assert_select 'dl>dd', text: Regexp.new(@<%= ns_file_name %>.<%= attribute.name %>.name)
35
+ assert_select 'dl>dd', text: Regexp.new(<%= ns_file_name %>.<%= attribute.name %>.name)
32
36
  <% else -%>
33
- assert_select 'dl>dd', text: Regexp.new(@<%= ns_file_name %>.<%= attribute.name %>.to_s)
37
+ assert_select 'dl>dd', text: Regexp.new(<%= ns_file_name %>.<%= attribute.name %>.to_s)
34
38
  <% end -%>
35
39
  <% else -%>
36
40
  assert_select 'dl>dd', text: <%= value_for(attribute) %>
@@ -0,0 +1,9 @@
1
+ module RspecRailsScaffoldTemplates
2
+ class Railtie < Rails::Railtie
3
+ config.app_generators do |g|
4
+ g.templates.unshift File::expand_path('../generators/templates', __FILE__)
5
+ end
6
+
7
+ require 'rspec_rails_scaffold_templates/generators/scaffold_generator'
8
+ end
9
+ end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: rspec_rails_scaffold_templates 1.2.5 ruby lib
5
+ # stub: rspec_rails_scaffold_templates 2.0.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "rspec_rails_scaffold_templates"
9
- s.version = "1.2.5"
9
+ s.version = "2.0.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Dmitri Koulikoff"]
14
- s.date = "2016-03-23"
14
+ s.date = "2016-09-19"
15
15
  s.description = "RSpec scaffold generator templates that use FactoryGirl and WiceGrid"
16
16
  s.email = "dima@koulikoff.ru"
17
17
  s.extra_rdoc_files = [
@@ -27,12 +27,15 @@ Gem::Specification.new do |s|
27
27
  "Rakefile",
28
28
  "VERSION",
29
29
  "lib/rspec_rails_scaffold_templates.rb",
30
- "lib/templates/rspec/integration/request_spec.rb",
31
- "lib/templates/rspec/scaffold/controller_spec.rb",
32
- "lib/templates/rspec/scaffold/edit_spec.rb",
33
- "lib/templates/rspec/scaffold/index_spec.rb",
34
- "lib/templates/rspec/scaffold/new_spec.rb",
35
- "lib/templates/rspec/scaffold/show_spec.rb",
30
+ "lib/rspec_rails_scaffold_templates/generators/scaffold_generator.rb",
31
+ "lib/rspec_rails_scaffold_templates/generators/templates/rspec/integration/request_spec.rb",
32
+ "lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/api_controller_spec.rb",
33
+ "lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/controller_spec.rb",
34
+ "lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/edit_spec.rb",
35
+ "lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/index_spec.rb",
36
+ "lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/new_spec.rb",
37
+ "lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/show_spec.rb",
38
+ "lib/rspec_rails_scaffold_templates/railties.rb",
36
39
  "rspec_rails_scaffold_templates.gemspec",
37
40
  "spec/rspec_rails_scaffold_templates_spec.rb",
38
41
  "spec/spec_helper.rb"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_rails_scaffold_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitri Koulikoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -96,12 +96,15 @@ files:
96
96
  - Rakefile
97
97
  - VERSION
98
98
  - lib/rspec_rails_scaffold_templates.rb
99
- - lib/templates/rspec/integration/request_spec.rb
100
- - lib/templates/rspec/scaffold/controller_spec.rb
101
- - lib/templates/rspec/scaffold/edit_spec.rb
102
- - lib/templates/rspec/scaffold/index_spec.rb
103
- - lib/templates/rspec/scaffold/new_spec.rb
104
- - lib/templates/rspec/scaffold/show_spec.rb
99
+ - lib/rspec_rails_scaffold_templates/generators/scaffold_generator.rb
100
+ - lib/rspec_rails_scaffold_templates/generators/templates/rspec/integration/request_spec.rb
101
+ - lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/api_controller_spec.rb
102
+ - lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/controller_spec.rb
103
+ - lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/edit_spec.rb
104
+ - lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/index_spec.rb
105
+ - lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/new_spec.rb
106
+ - lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/show_spec.rb
107
+ - lib/rspec_rails_scaffold_templates/railties.rb
105
108
  - rspec_rails_scaffold_templates.gemspec
106
109
  - spec/rspec_rails_scaffold_templates_spec.rb
107
110
  - spec/spec_helper.rb