rspec_rails_scaffold_templates 2.3 → 3.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
  SHA256:
3
- metadata.gz: ad10fd3f93fc8e6f8bc9fc57b2558e33ec8f37fdbdcb031d303d1aed0ba1d7b0
4
- data.tar.gz: 83117df7955ca4577567cf6c996c8ad14de395d9cdd0df1b6382a644b923a156
3
+ metadata.gz: eac43d4dbda7c0184d1530a02e53374a4e68a8819d64ee82f684106e7add14d7
4
+ data.tar.gz: 895477e980276a655294a1cbcabdea7e38a77bccad9075129ad11a1d9b1165e6
5
5
  SHA512:
6
- metadata.gz: 621656d22d2a62138abb3879dd144d66c87893836bbf921e0f50e2488dc1a487d65a720a61825688334c9dbe64ffe9b50c56e691ade7ea5965df80e022b6be55
7
- data.tar.gz: 48e92b04edce2e1f538d6b754091b6d601af28e5ce50a21deccccc2a91f2f70abeae4368bd3a9408f9f41e42373e60e58eae5fab5234b7f7a995d3b521c00f0e
6
+ metadata.gz: 0ef790015a289fbdcc9b95003ce09520fb49a29d40d9e29b1279474c48af1e808b00e66db7b2752486fcdc4d20776a5141a20d2d14e9cae1a6101de3b006621d
7
+ data.tar.gz: e777a1104fa6c916a600b2034a3d4dddaccc47953ed46355c032c32b822d0f6298db5905a9b4c6d389068dbea506348ce9aff90a85c66d7e0dd0d56ff0c04ce3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3
1
+ 3.0
@@ -1,3 +1,5 @@
1
+ require 'rails/generators'
2
+
1
3
  if defined?(Rails)
2
4
  require 'rspec_rails_scaffold_templates/generators/scaffold_generator'
3
5
  require 'rspec_rails_scaffold_templates/generators/integration_generator'
@@ -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(*%w[<%= attribute_name %>].map(&:to_sym))
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 *%w[<%= attribute_name %>].map(&:to_sym)}
37
+ let(:valid_attributes) {attributes_for(:<%=file_name%>).slice *%i[<%= attribute_name %>]}
38
38
  <% end -%>
39
39
  <% else -%>
40
40
  <% factory_bot = false -%>
@@ -26,7 +26,7 @@ describe <%= controller_class_name %>Controller, <%= type_metatag(:controller) %
26
26
  <% if links.present? -%>
27
27
  let(:valid_attributes) do
28
28
  attributes_for(:<%=file_name%>)
29
- .slice(*%w[<%= attribute_name %>].map(&:to_sym))
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 <%= controller_class_name %>Controller, <%= type_metatag(:controller) %
34
34
  )
35
35
  end
36
36
  <% else -%>
37
- let(:valid_attributes) {attributes_for(:<%=file_name%>).slice *%w[<%= attribute_name %>].map(&:to_sym)}
37
+ let(:valid_attributes) {attributes_for(:<%=file_name%>).slice *%i[<%= attribute_name %>]}
38
38
  <% end -%>
39
39
  <% else -%>
40
40
  <% factory_bot = false -%>
@@ -38,12 +38,12 @@ describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
38
38
  <% for attribute in output_attributes -%>
39
39
  <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_bot -%>
40
40
  <% if attribute.reference? -%>
41
- assert_select 'tr>td', text: <%= ns_file_name %>.<%= attribute.name %>.name, count: 1
41
+ assert_select 'tr>td.<%= attribute.name %>', text: <%= ns_file_name %>.<%= attribute.name %>.name, count: 1
42
42
  <% else -%>
43
- assert_select 'tr>td', text: <%= ns_file_name %>.<%= attribute.name %>.to_s, count: 1
43
+ assert_select 'tr>td.<%= attribute.name %>', text: <%= ns_file_name %>.<%= attribute.name %>.to_s, count: 1
44
44
  <% end -%>
45
45
  <% else -%>
46
- assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 1
46
+ assert_select "tr>td.<%= attribute.name %>", text: <%= value_for(attribute) %>.to_s, count: 1
47
47
  <% end -%>
48
48
  <% end -%>
49
49
  end
@@ -56,12 +56,12 @@ describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
56
56
  <% for attribute in output_attributes -%>
57
57
  <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_bot -%>
58
58
  <% if attribute.reference? -%>
59
- assert_select 'tr>td', text: <%= ns_file_name %>.<%= attribute.name %>.name, count: 1
59
+ assert_select 'tr>td.<%= attribute.name %>', text: <%= ns_file_name %>.<%= attribute.name %>.name, count: 1
60
60
  <% else -%>
61
- assert_select 'tr>td', text: <%= ns_file_name %>.<%= attribute.name %>.to_s, count: 1
61
+ assert_select 'tr>td.<%= attribute.name %>', text: <%= ns_file_name %>.<%= attribute.name %>.to_s, count: 1
62
62
  <% end -%>
63
63
  <% else -%>
64
- assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 1
64
+ assert_select "tr>td.<%= attribute.name %>", text: <%= value_for(attribute) %>.to_s, count: 1
65
65
  <% end -%>
66
66
  <% end -%>
67
67
  end
@@ -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 -%>
@@ -32,12 +32,12 @@ describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
32
32
  <% for attribute in output_attributes -%>
33
33
  <% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_bot -%>
34
34
  <% if attribute.reference? -%>
35
- assert_select 'dl>dd', text: Regexp.new(<%= ns_file_name %>.<%= attribute.name %>.name)
35
+ assert_select 'dl>dd.<%= attribute.name %>', text: Regexp.new(<%= ns_file_name %>.<%= attribute.name %>.name)
36
36
  <% else -%>
37
- assert_select 'dl>dd', text: Regexp.new(<%= ns_file_name %>.<%= attribute.name %>.to_s)
37
+ assert_select 'dl>dd.<%= attribute.name %>', text: Regexp.new(<%= ns_file_name %>.<%= attribute.name %>.to_s)
38
38
  <% end -%>
39
39
  <% else -%>
40
- assert_select 'dl>dd', text: <%= value_for(attribute) %>
40
+ assert_select 'dl>dd.<%= attribute.name %>', text: <%= value_for(attribute) %>
41
41
  <% end -%>
42
42
  <% end -%>
43
43
  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 2.3 ruby lib
5
+ # stub: rspec_rails_scaffold_templates 3.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "rspec_rails_scaffold_templates".freeze
9
- s.version = "2.3"
9
+ s.version = "3.0"
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 = "2019-05-22"
14
+ s.date = "2020-06-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.0.3".freeze
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
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
- s.add_development_dependency(%q<rspec>.freeze, ["~> 3.1"])
53
- s.add_development_dependency(%q<rdoc>.freeze, ["~> 4.1"])
54
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.6"])
55
- s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.0"])
56
- s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.0"])
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: '2.3'
4
+ version: '3.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: 2019-05-22 00:00:00.000000000 Z
11
+ date: 2020-06-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.0.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