rspec_rails_scaffold_templates 2.5 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rspec_rails_scaffold_templates.rb +2 -0
- data/lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/api_controller_spec.rb +2 -2
- data/lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/edit_spec.rb +1 -1
- data/lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/index_spec.rb +1 -1
- data/lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/new_spec.rb +1 -1
- data/lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/request_spec.rb +205 -0
- data/lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/show_spec.rb +1 -1
- data/rspec_rails_scaffold_templates.gemspec +12 -17
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60f8a6127b7c515cace39291ed0fcdffed531442fcc9888273295fae976cd8c2
|
4
|
+
data.tar.gz: ad5710bb5ac8bae1283e922d4668bba99f44292731c34d21d758f2103fd67b5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0156fc08c1111046004ea5699b52b4931fb87d6cde139792bbce4f6731a874c05d9c5f3aadd7eb4d490129b792d7ef1d08690efcc53b3f34d483dd5c76d78b8
|
7
|
+
data.tar.gz: 6826bde0af17e066b2dede6726f98f29889cdf38a282a99e6649f9c3735ad61193f165d35afa15d15b133f42d0424e725a318d5aafce91eafd3de7adc1734bde
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.1
|
data/lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/api_controller_spec.rb
CHANGED
@@ -26,7 +26,7 @@ describe Api::<%= options[:api_version].camelcase + '::' if options[:api_version
|
|
26
26
|
<% if links.present? -%>
|
27
27
|
let(:valid_attributes) do
|
28
28
|
attributes_for(:<%=file_name%>)
|
29
|
-
.slice(*%
|
29
|
+
.slice(*%i[<%= attribute_name %>])
|
30
30
|
.merge(
|
31
31
|
<% links.each do |relation| -%>
|
32
32
|
<%= relation.name %>_id: create(:<%= relation.name %>).id,
|
@@ -34,7 +34,7 @@ describe Api::<%= options[:api_version].camelcase + '::' if options[:api_version
|
|
34
34
|
)
|
35
35
|
end
|
36
36
|
<% else -%>
|
37
|
-
let(:valid_attributes) {attributes_for(:<%=file_name%>).slice *%
|
37
|
+
let(:valid_attributes) {attributes_for(:<%=file_name%>).slice *%i[<%= attribute_name %>]}
|
38
38
|
<% end -%>
|
39
39
|
<% else -%>
|
40
40
|
<% factory_bot = false -%>
|
@@ -10,7 +10,7 @@ require 'spec_helper'
|
|
10
10
|
<% end -%>
|
11
11
|
|
12
12
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
13
|
-
describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
|
13
|
+
describe "<%= ns_table_name %>/edit.html.<%= options[:template_engine] %>", <%= type_metatag(:view) %> do
|
14
14
|
<% if factory_bot -%>
|
15
15
|
let(:<%= ns_file_name %>) {create :<%= ns_file_name %>}
|
16
16
|
<% else -%>
|
@@ -10,7 +10,7 @@ require 'spec_helper'
|
|
10
10
|
<% end -%>
|
11
11
|
|
12
12
|
<% output_attributes = attributes.reject{|attribute| [:created_at, :deleted_at, :updated_at].index(attribute.name) or attribute.password_digest? } -%>
|
13
|
-
describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
|
13
|
+
describe "<%= ns_table_name %>/index.html.<%= options[:template_engine] %>", <%= type_metatag(:view) %> do
|
14
14
|
<% if factory_bot -%>
|
15
15
|
let!(:<%= ns_file_name %>) {create :<%= ns_file_name %>}
|
16
16
|
<% else -%>
|
@@ -10,7 +10,7 @@ require 'spec_helper'
|
|
10
10
|
<% end -%>
|
11
11
|
|
12
12
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
13
|
-
describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
|
13
|
+
describe "<%= ns_table_name %>/new.html.<%= options[:template_engine] %>", <%= type_metatag(:view) %> do
|
14
14
|
<% if factory_bot -%>
|
15
15
|
let(:<%= ns_file_name %>) {build :<%= ns_file_name %>}
|
16
16
|
<% else -%>
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
|
+
# It demonstrates how one might use RSpec to test the controller code that
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
6
|
+
#
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
9
|
+
# controller code, this generated spec may or may not pass.
|
10
|
+
#
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
14
|
+
|
15
|
+
<% module_namespacing do -%>
|
16
|
+
describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
|
17
|
+
<% if method = Rails.application.config.generators.options[:rails][:cancan] -%>
|
18
|
+
<% method = 'current_user' unless Symbol === method -%>
|
19
|
+
before :each do
|
20
|
+
allow_any_instance_of(<%= controller_class_name %>Controller).to receive(:<%=method%>)
|
21
|
+
.and_return(<%=method%>)
|
22
|
+
end
|
23
|
+
|
24
|
+
<% end -%>
|
25
|
+
# This should return the minimal set of attributes required to create a valid
|
26
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
27
|
+
# adjust the attributes here as well. The list could not be empty.
|
28
|
+
<% links = attributes.select{|a| [:belongs_to, :references].include? a.type} -%>
|
29
|
+
<% attribute = (attributes - links).detect{|a| a.name == 'name' || a.name == 'title' || a.name == 'code' || a.name =~ /name/ || a.name =~ /title/} || attributes.first -%>
|
30
|
+
<% attribute_name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name -%>
|
31
|
+
<% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_bot -%>
|
32
|
+
<% factory_bot = true -%>
|
33
|
+
let(:<%= file_name %>) {create :<%= file_name %>}
|
34
|
+
|
35
|
+
<% if links.present? -%>
|
36
|
+
let(:valid_attributes) do
|
37
|
+
attributes_for(:<%=file_name%>)
|
38
|
+
.slice(*%i[<%= attribute_name %>])
|
39
|
+
.merge(
|
40
|
+
<% links.each do |relation| -%>
|
41
|
+
<%= relation.name %>_id: create(:<%= relation.name %>).id,
|
42
|
+
<% end -%>
|
43
|
+
)
|
44
|
+
end
|
45
|
+
<% else -%>
|
46
|
+
let(:valid_attributes) {attributes_for(:<%=file_name%>).slice *%i[<%= attribute_name %>]}
|
47
|
+
<% end -%>
|
48
|
+
<% else -%>
|
49
|
+
<% factory_bot = false -%>
|
50
|
+
let(:<%= file_name %>) {<%= class_name %>.create! valid_attributes}
|
51
|
+
|
52
|
+
let(:valid_attributes) do
|
53
|
+
skip("Add a hash of attributes valid for your model")
|
54
|
+
end
|
55
|
+
<% end -%>
|
56
|
+
|
57
|
+
let(:invalid_attributes) do
|
58
|
+
# {<%= attribute_name %>: ''}
|
59
|
+
skip("Add a hash of attributes invalid for your model")
|
60
|
+
end
|
61
|
+
|
62
|
+
<% unless options[:singleton] -%>
|
63
|
+
describe "GET /index" do
|
64
|
+
subject(:get_index) {get <%= index_helper %>_url}
|
65
|
+
|
66
|
+
it "renders a successful response" do
|
67
|
+
<%= class_name %>.create! valid_attributes
|
68
|
+
get_index
|
69
|
+
expect(response).to be_successful
|
70
|
+
end
|
71
|
+
end
|
72
|
+
<% end -%>
|
73
|
+
|
74
|
+
describe "GET /show" do
|
75
|
+
subject(:get_show) {get <%= show_helper.sub(/@([^)]+)/, 'id: \1.to_param') %>}
|
76
|
+
|
77
|
+
it "renders a successful response" do
|
78
|
+
<% unless factory_bot -%>
|
79
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
80
|
+
<% end -%>
|
81
|
+
get_show
|
82
|
+
expect(response).to be_successful
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "GET /new" do
|
87
|
+
subject(:get_new) {get <%= new_helper %>}
|
88
|
+
|
89
|
+
it "renders a successful response" do
|
90
|
+
get_new
|
91
|
+
expect(response).to be_successful
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "GET /edit" do
|
96
|
+
subject(:get_edit) {get <%= edit_helper.sub(/@([^)]*)/, 'id: \1.to_param') %>}
|
97
|
+
|
98
|
+
it "render a successful response" do
|
99
|
+
<% unless factory_bot -%>
|
100
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
101
|
+
<% end -%>
|
102
|
+
get_edit
|
103
|
+
expect(response).to be_successful
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "POST /create" do
|
108
|
+
subject(:post_create) do
|
109
|
+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: attributes }
|
110
|
+
end
|
111
|
+
|
112
|
+
context "with valid parameters" do
|
113
|
+
let(:attributes) {valid_attributes}
|
114
|
+
|
115
|
+
it "creates a new <%= class_name %>" do
|
116
|
+
expect{post_create}.to change(<%= class_name %>, :count).by(1)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "redirects to the created <%= ns_file_name %>" do
|
120
|
+
post_create
|
121
|
+
expect(response).to redirect_to(<%= show_helper.gsub("\@#{file_name}", 'id: ' + class_name + ".last.to_param") %>)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "with invalid parameters" do
|
126
|
+
let(:attributes) {invalid_attributes}
|
127
|
+
|
128
|
+
it "does not create a new <%= class_name %>" do
|
129
|
+
expect {post_create}.not_to change(<%= class_name %>, :count)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "renders a successful response (i.e. to display the 'new' template)" do
|
133
|
+
post_create
|
134
|
+
expect(response).to be_successful
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "PATCH /update" do
|
140
|
+
subject(:patch_update) do
|
141
|
+
patch <%= show_helper.sub(/@([^)]+)/, 'id: \1.to_param') %>, params: { <%= singular_table_name %>: attributes }
|
142
|
+
end
|
143
|
+
|
144
|
+
context "with valid parameters" do
|
145
|
+
let(:attributes) { {<%= attribute_name %>: 'New value'} }
|
146
|
+
|
147
|
+
it "updates the requested <%= ns_file_name %>" do
|
148
|
+
# expect_any_instance_of(<%= class_name %>)
|
149
|
+
# .to receive(:update).with(attributes.inject({}){|_, (k, v)| _[k] = v.to_s; _})
|
150
|
+
<% unless factory_bot -%>
|
151
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
152
|
+
<% end -%>
|
153
|
+
patch_update
|
154
|
+
<%= file_name %>.reload
|
155
|
+
# skip("Add assertions for updated state")
|
156
|
+
expect(<%= file_name %>.<%= attribute_name %>).to eq 'New value'
|
157
|
+
end
|
158
|
+
|
159
|
+
it "redirects to the <%= ns_file_name %>" do
|
160
|
+
<% unless factory_bot -%>
|
161
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
162
|
+
<% end -%>
|
163
|
+
patch_update
|
164
|
+
<%= file_name %>.reload
|
165
|
+
expect(response).to redirect_to(<%= singular_table_name %>_url(id: <%= file_name %>.to_param))
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "with invalid parameters" do
|
170
|
+
let(:attributes) {invalid_attributes}
|
171
|
+
|
172
|
+
it "renders a successful response (i.e. to display the 'edit' template)" do
|
173
|
+
<% unless factory_bot -%>
|
174
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
175
|
+
<% end -%>
|
176
|
+
patch_update
|
177
|
+
expect(response).to be_successful
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "DELETE /destroy" do
|
183
|
+
subject(:delete_destroy) {delete <%= show_helper.sub(/@([^)]+)/, 'id: \1.to_param') %>}
|
184
|
+
|
185
|
+
it "destroys the requested <%= ns_file_name %>" do
|
186
|
+
<% if factory_bot -%>
|
187
|
+
<%= file_name %>
|
188
|
+
<% else -%>
|
189
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
190
|
+
<% end -%>
|
191
|
+
expect {delete_destroy}.to change(<%= class_name %>, :count).by(-1)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "redirects to the <%= table_name %> list" do
|
195
|
+
<% if factory_bot -%>
|
196
|
+
<%= file_name %>
|
197
|
+
<% else -%>
|
198
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
199
|
+
<% end -%>
|
200
|
+
delete_destroy
|
201
|
+
expect(response).to redirect_to(<%= index_helper %>_url)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
<% end -%>
|
@@ -5,7 +5,7 @@ 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_metatag(:view) %> do
|
8
|
+
describe "<%= ns_table_name %>/show.html.<%= options[:template_engine] %>", <%= type_metatag(:view) %> do
|
9
9
|
<% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_bot -%>
|
10
10
|
let(:<%= ns_file_name %>) {create :<%= ns_file_name %>}
|
11
11
|
<% else -%>
|
@@ -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
|
5
|
+
# stub: rspec_rails_scaffold_templates 3.1.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "rspec_rails_scaffold_templates".freeze
|
9
|
-
s.version = "
|
9
|
+
s.version = "3.1.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Dmitri Koulikoff".freeze]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2020-07-17"
|
15
15
|
s.description = "RSpec scaffold generator templates that use FactoryGirl and WiceGrid".freeze
|
16
16
|
s.email = "dima@koulikoff.ru".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/edit_spec.rb",
|
36
36
|
"lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/index_spec.rb",
|
37
37
|
"lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/new_spec.rb",
|
38
|
+
"lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/request_spec.rb",
|
38
39
|
"lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/show_spec.rb",
|
39
40
|
"rspec_rails_scaffold_templates.gemspec",
|
40
41
|
"spec/rspec_rails_scaffold_templates_spec.rb",
|
@@ -42,25 +43,19 @@ Gem::Specification.new do |s|
|
|
42
43
|
]
|
43
44
|
s.homepage = "http://github.com/dima4p/rspec_rails_scaffold_templates".freeze
|
44
45
|
s.licenses = ["MIT".freeze]
|
45
|
-
s.rubygems_version = "3.
|
46
|
+
s.rubygems_version = "3.1.2".freeze
|
46
47
|
s.summary = "RSpec scaffold generator templates that use FactoryGirl and WiceGrid".freeze
|
47
48
|
|
48
49
|
if s.respond_to? :specification_version then
|
49
50
|
s.specification_version = 4
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
else
|
58
|
-
s.add_dependency(%q<rspec>.freeze, ["~> 3.1"])
|
59
|
-
s.add_dependency(%q<rdoc>.freeze, ["~> 4.1"])
|
60
|
-
s.add_dependency(%q<bundler>.freeze, ["~> 1.6"])
|
61
|
-
s.add_dependency(%q<jeweler>.freeze, ["~> 2.0"])
|
62
|
-
s.add_dependency(%q<simplecov>.freeze, ["~> 0.0"])
|
63
|
-
end
|
53
|
+
if s.respond_to? :add_runtime_dependency then
|
54
|
+
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.1"])
|
55
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 4.1"])
|
56
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.6"])
|
57
|
+
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.0"])
|
58
|
+
s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.0"])
|
64
59
|
else
|
65
60
|
s.add_dependency(%q<rspec>.freeze, ["~> 3.1"])
|
66
61
|
s.add_dependency(%q<rdoc>.freeze, ["~> 4.1"])
|
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:
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitri Koulikoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/edit_spec.rb
|
105
105
|
- lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/index_spec.rb
|
106
106
|
- lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/new_spec.rb
|
107
|
+
- lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/request_spec.rb
|
107
108
|
- lib/rspec_rails_scaffold_templates/generators/templates/rspec/scaffold/show_spec.rb
|
108
109
|
- rspec_rails_scaffold_templates.gemspec
|
109
110
|
- spec/rspec_rails_scaffold_templates_spec.rb
|
@@ -127,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
128
|
- !ruby/object:Gem::Version
|
128
129
|
version: '0'
|
129
130
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
131
|
+
rubygems_version: 3.1.2
|
131
132
|
signing_key:
|
132
133
|
specification_version: 4
|
133
134
|
summary: RSpec scaffold generator templates that use FactoryGirl and WiceGrid
|