rspec_rails_scaffold_templates 2.6 → 2.9

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: fb7bc6888d5364143c617f1ee568bafcd547a05bf8ddccc23e1877900e924292
4
- data.tar.gz: a675eb7daebd54272b81164f88539bbc378c18a8744d5c1ed2282167efca9ee6
3
+ metadata.gz: 8ec8ea48a6ea7009069519882ce7e773352bd849024ee27fe07b69b107e3d350
4
+ data.tar.gz: 00f96f62cb04489429c4fc98b8fa84a23762eb583e405b7b707994bf068ad09d
5
5
  SHA512:
6
- metadata.gz: eaf4e76ebf113d5fd03c443dcb8e7b36c7362bf3d8fe517bc070564f487120d6ceffc73e092a33192084539844ed22247dfb1417ef80780f363ce2740bcc30f5
7
- data.tar.gz: 3491258ae90fb1b4d01962d8c01b8fb7f9965b2d8f8bc39361c826964ed80eeac976fff3be0709a2d9ad9f45fc3215c64bface440ee2e84f5c4366e81b496bd5
6
+ metadata.gz: afad47b879090bfef2738163d772a15a4ad9674614be6c94c1881da7b6d0ee16583760f36b57fb7d15e93af427eb5a2fcf1dedfa71ff643e070f4c70cf804aa7
7
+ data.tar.gz: 257fc01ef8153da000b22f844897bce3944c6ea8037446a038405f308fc82339ed4c717ed6fbe12f154784a28901ef46aec67a5a2e1bf8d73f7dfec52b3dde33
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.6
1
+ 2.9
@@ -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'
@@ -0,0 +1,187 @@
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
+ it "renders a successful response" do
65
+ <%= class_name %>.create! valid_attributes
66
+ get <%= index_helper %>_url
67
+ expect(response).to be_successful
68
+ end
69
+ end
70
+ <% end -%>
71
+
72
+ describe "GET /show" do
73
+ it "renders a successful response" do
74
+ <% unless factory_bot -%>
75
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
76
+ <% end -%>
77
+ get <%= show_helper.sub(/@([^)]+)/, 'id: \1.to_param') %>
78
+ expect(response).to be_successful
79
+ end
80
+ end
81
+
82
+ describe "GET /new" do
83
+ it "renders a successful response" do
84
+ get <%= new_helper %>
85
+ expect(response).to be_successful
86
+ end
87
+ end
88
+
89
+ describe "GET /edit" do
90
+ it "render a successful response" do
91
+ <% unless factory_bot -%>
92
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
93
+ <% end -%>
94
+ get <%= edit_helper.tr('@','id: ') %>
95
+ expect(response).to be_successful
96
+ end
97
+ end
98
+
99
+ describe "POST /create" do
100
+ context "with valid parameters" do
101
+ it "creates a new <%= class_name %>" do
102
+ expect {
103
+ post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
104
+ }.to change(<%= class_name %>, :count).by(1)
105
+ end
106
+
107
+ it "redirects to the created <%= ns_file_name %>" do
108
+ post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
109
+ expect(response).to redirect_to(<%= show_helper.gsub("\@#{file_name}", class_name+".last") %>)
110
+ end
111
+ end
112
+
113
+ context "with invalid parameters" do
114
+ it "does not create a new <%= class_name %>" do
115
+ expect {
116
+ post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
117
+ }.to change(<%= class_name %>, :count).by(0)
118
+ end
119
+
120
+ it "renders a successful response (i.e. to display the 'new' template)" do
121
+ post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
122
+ expect(response).to be_successful
123
+ end
124
+ end
125
+ end
126
+
127
+ describe "PATCH /update" do
128
+ context "with valid parameters" do
129
+ let(:new_attributes) { {<%= attribute_name %>: 'New value'} }
130
+
131
+ it "updates the requested <%= ns_file_name %>" do
132
+ # expect_any_instance_of(<%= class_name %>)
133
+ # .to receive(:update).with(new_attributes.inject({}){|_, (k, v)| _[k] = v.to_s; _})
134
+ <% unless factory_bot -%>
135
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
136
+ <% end -%>
137
+ patch <%= show_helper.sub(/@([^)]+)/, 'id: \1.to_param') %>, params: { <%= singular_table_name %>: new_attributes }
138
+ <%= file_name %>.reload
139
+ # skip("Add assertions for updated state")
140
+ expect(<%= file_name %>.<%= attribute_name %>).to eq 'New value'
141
+ end
142
+
143
+ it "redirects to the <%= ns_file_name %>" do
144
+ <% unless factory_bot -%>
145
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
146
+ <% end -%>
147
+ patch <%= show_helper.sub(/@([^)]+)/, 'id: \1.to_param') %>, params: { <%= singular_table_name %>: new_attributes }
148
+ <%= file_name %>.reload
149
+ expect(response).to redirect_to(<%= singular_table_name %>_url(id: <%= file_name %>.to_param))
150
+ end
151
+ end
152
+
153
+ context "with invalid parameters" do
154
+ it "renders a successful response (i.e. to display the 'edit' template)" do
155
+ <% unless factory_bot -%>
156
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
157
+ <% end -%>
158
+ patch <%= show_helper.sub(/@([^)]+)/, 'id: \1.to_param') %>, params: { <%= singular_table_name %>: invalid_attributes }
159
+ expect(response).to be_successful
160
+ end
161
+ end
162
+ end
163
+
164
+ describe "DELETE /destroy" do
165
+ it "destroys the requested <%= ns_file_name %>" do
166
+ <% if factory_bot -%>
167
+ <%= file_name %>
168
+ <% else -%>
169
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
170
+ <% end -%>
171
+ expect {
172
+ delete <%= show_helper.sub(/@([^)]+)/, 'id: \1.to_param') %>
173
+ }.to change(<%= class_name %>, :count).by(-1)
174
+ end
175
+
176
+ it "redirects to the <%= table_name %> list" do
177
+ <% if factory_bot -%>
178
+ <%= file_name %>
179
+ <% else -%>
180
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
181
+ <% end -%>
182
+ delete <%= show_helper.sub(/@([^)]+)/, 'id: \1.to_param') %>
183
+ expect(response).to redirect_to(<%= index_helper %>_url)
184
+ end
185
+ end
186
+ end
187
+ <% 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.6 ruby lib
5
+ # stub: rspec_rails_scaffold_templates 2.9 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "rspec_rails_scaffold_templates".freeze
9
- s.version = "2.6"
9
+ s.version = "2.9"
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 = "2020-01-05"
14
+ s.date = "2020-06-05"
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.6'
4
+ version: '2.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitri Koulikoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-05 00:00:00.000000000 Z
11
+ date: 2020-06-05 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