rspec-rails 3.9.1 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Capybara.md +5 -54
- data/Changelog.md +207 -77
- data/README.md +27 -21
- data/lib/generators/rspec.rb +0 -6
- data/lib/generators/rspec/channel/channel_generator.rb +12 -0
- data/lib/generators/rspec/{observer/templates/observer_spec.rb → channel/templates/channel_spec.rb.erb} +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +22 -5
- data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
- data/lib/generators/rspec/feature/feature_generator.rb +2 -2
- data/lib/generators/rspec/{generators → generator}/generator_generator.rb +2 -2
- data/lib/generators/rspec/{generators → generator}/templates/generator_spec.rb +0 -0
- data/lib/generators/rspec/helper/helper_generator.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +4 -4
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +17 -16
- data/lib/generators/rspec/integration/integration_generator.rb +3 -3
- data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
- data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +2 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
- data/lib/generators/rspec/model/model_generator.rb +5 -4
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/request/request_generator.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +29 -19
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +0 -36
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +0 -48
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -5
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -5
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +137 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/system/system_generator.rb +14 -16
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/rspec-rails.rb +13 -16
- data/lib/rspec/rails/adapters.rb +11 -76
- data/lib/rspec/rails/configuration.rb +81 -37
- data/lib/rspec/rails/example.rb +2 -0
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +4 -4
- data/lib/rspec/rails/example/feature_example_group.rb +6 -26
- data/lib/rspec/rails/example/helper_example_group.rb +2 -9
- data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
- data/lib/rspec/rails/example/rails_example_group.rb +1 -1
- data/lib/rspec/rails/example/request_example_group.rb +1 -4
- data/lib/rspec/rails/example/system_example_group.rb +29 -12
- data/lib/rspec/rails/example/view_example_group.rb +38 -27
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
- data/lib/rspec/rails/feature_check.rb +12 -29
- data/lib/rspec/rails/file_fixture_support.rb +9 -11
- data/lib/rspec/rails/fixture_file_upload_support.rb +33 -17
- data/lib/rspec/rails/fixture_support.rb +34 -32
- data/lib/rspec/rails/matchers.rb +9 -0
- data/lib/rspec/rails/matchers/action_cable.rb +65 -0
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +170 -0
- data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
- data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
- data/lib/rspec/rails/matchers/active_job.rb +169 -21
- data/lib/rspec/rails/matchers/base_matcher.rb +5 -10
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +52 -28
- data/lib/rspec/rails/matchers/have_http_status.rb +11 -7
- data/lib/rspec/rails/matchers/have_rendered.rb +1 -0
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +12 -12
- data/lib/rspec/rails/tasks/rspec.rake +7 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -15
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_path_builder.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +15 -4
- metadata +47 -35
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -6,18 +6,19 @@ module Rspec
|
|
6
6
|
# @private
|
7
7
|
class ScaffoldGenerator < Base
|
8
8
|
include ::Rails::Generators::ResourceHelpers
|
9
|
-
source_paths << File.expand_path(
|
10
|
-
argument :attributes, :
|
9
|
+
source_paths << File.expand_path('../helper/templates', __dir__)
|
10
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
11
11
|
|
12
|
-
class_option :orm, :
|
13
|
-
class_option :template_engine, :
|
14
|
-
class_option :singleton, :
|
15
|
-
class_option :api, :
|
12
|
+
class_option :orm, desc: "ORM used to generate the controller"
|
13
|
+
class_option :template_engine, desc: "Template engine to generate view files"
|
14
|
+
class_option :singleton, type: :boolean, desc: "Supply to create a singleton controller"
|
15
|
+
class_option :api, type: :boolean, desc: "Skip specs unnecessary for API-only apps"
|
16
16
|
|
17
|
-
class_option :controller_specs, :
|
18
|
-
class_option :
|
19
|
-
class_option :
|
20
|
-
class_option :
|
17
|
+
class_option :controller_specs, type: :boolean, default: false, desc: "Generate controller specs"
|
18
|
+
class_option :request_specs, type: :boolean, default: true, desc: "Generate request specs"
|
19
|
+
class_option :view_specs, type: :boolean, default: true, desc: "Generate view specs"
|
20
|
+
class_option :helper_specs, type: :boolean, default: true, desc: "Generate helper specs"
|
21
|
+
class_option :routing_specs, type: :boolean, default: true, desc: "Generate routing specs"
|
21
22
|
|
22
23
|
def initialize(*args, &blk)
|
23
24
|
@generator_args = args.first
|
@@ -27,15 +28,20 @@ module Rspec
|
|
27
28
|
def generate_controller_spec
|
28
29
|
return unless options[:controller_specs]
|
29
30
|
|
30
|
-
template_file = File.join(
|
31
|
-
'spec/controllers',
|
32
|
-
controller_class_path,
|
33
|
-
"#{controller_file_name}_controller_spec.rb"
|
34
|
-
)
|
35
31
|
if options[:api]
|
36
|
-
template 'api_controller_spec.rb', template_file
|
32
|
+
template 'api_controller_spec.rb', template_file(folder: 'controllers', suffix: '_controller')
|
33
|
+
else
|
34
|
+
template 'controller_spec.rb', template_file(folder: 'controllers', suffix: '_controller')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_request_spec
|
39
|
+
return unless options[:request_specs]
|
40
|
+
|
41
|
+
if options[:api]
|
42
|
+
template 'api_request_spec.rb', template_file(folder: 'requests')
|
37
43
|
else
|
38
|
-
template '
|
44
|
+
template 'request_spec.rb', template_file(folder: 'requests')
|
39
45
|
end
|
40
46
|
end
|
41
47
|
|
@@ -60,8 +66,6 @@ module Rspec
|
|
60
66
|
template 'routing_spec.rb', template_file
|
61
67
|
end
|
62
68
|
|
63
|
-
hook_for :integration_tool, :as => :integration
|
64
|
-
|
65
69
|
protected
|
66
70
|
|
67
71
|
attr_reader :generator_args
|
@@ -74,12 +78,14 @@ module Rspec
|
|
74
78
|
# support for namespaced-resources
|
75
79
|
def ns_file_name
|
76
80
|
return file_name if ns_parts.empty?
|
81
|
+
|
77
82
|
"#{ns_prefix.map(&:underscore).join('/')}_#{ns_suffix.singularize.underscore}"
|
78
83
|
end
|
79
84
|
|
80
85
|
# support for namespaced-resources
|
81
86
|
def ns_table_name
|
82
87
|
return table_name if ns_parts.empty?
|
88
|
+
|
83
89
|
"#{ns_prefix.map(&:underscore).join('/')}/#{ns_suffix.tableize}"
|
84
90
|
end
|
85
91
|
|
@@ -114,6 +120,10 @@ module Rspec
|
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
123
|
+
def template_file(folder:, suffix: '')
|
124
|
+
File.join('spec', folder, controller_class_path, "#{controller_file_name}#{suffix}_spec.rb")
|
125
|
+
end
|
126
|
+
|
117
127
|
def banner
|
118
128
|
self.class.banner
|
119
129
|
end
|
@@ -46,11 +46,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
46
46
|
describe "GET #index" do
|
47
47
|
it "returns a success response" do
|
48
48
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
49
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
50
|
-
get :index, {}, valid_session
|
51
|
-
<% else -%>
|
52
49
|
get :index, params: {}, session: valid_session
|
53
|
-
<% end -%>
|
54
50
|
expect(response).to be_successful
|
55
51
|
end
|
56
52
|
end
|
@@ -59,11 +55,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
59
55
|
describe "GET #show" do
|
60
56
|
it "returns a success response" do
|
61
57
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
62
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
63
|
-
get :show, {:id => <%= file_name %>.to_param}, valid_session
|
64
|
-
<% else -%>
|
65
58
|
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
|
66
|
-
<% end -%>
|
67
59
|
expect(response).to be_successful
|
68
60
|
end
|
69
61
|
end
|
@@ -72,20 +64,12 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
72
64
|
context "with valid params" do
|
73
65
|
it "creates a new <%= class_name %>" do
|
74
66
|
expect {
|
75
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
76
|
-
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
77
|
-
<% else -%>
|
78
67
|
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
79
|
-
<% end -%>
|
80
68
|
}.to change(<%= class_name %>, :count).by(1)
|
81
69
|
end
|
82
70
|
|
83
71
|
it "renders a JSON response with the new <%= ns_file_name %>" do
|
84
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
85
|
-
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
86
|
-
<% else %>
|
87
72
|
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
88
|
-
<% end -%>
|
89
73
|
expect(response).to have_http_status(:created)
|
90
74
|
expect(response.content_type).to eq('application/json')
|
91
75
|
expect(response.location).to eq(<%= ns_file_name %>_url(<%= class_name %>.last))
|
@@ -94,11 +78,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
94
78
|
|
95
79
|
context "with invalid params" do
|
96
80
|
it "renders a JSON response with errors for the new <%= ns_file_name %>" do
|
97
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
98
|
-
post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
|
99
|
-
<% else %>
|
100
81
|
post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
|
101
|
-
<% end -%>
|
102
82
|
expect(response).to have_http_status(:unprocessable_entity)
|
103
83
|
expect(response.content_type).to eq('application/json')
|
104
84
|
end
|
@@ -113,22 +93,14 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
113
93
|
|
114
94
|
it "updates the requested <%= ns_file_name %>" do
|
115
95
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
116
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
117
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes}, valid_session
|
118
|
-
<% else -%>
|
119
96
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
|
120
|
-
<% end -%>
|
121
97
|
<%= file_name %>.reload
|
122
98
|
skip("Add assertions for updated state")
|
123
99
|
end
|
124
100
|
|
125
101
|
it "renders a JSON response with the <%= ns_file_name %>" do
|
126
102
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
127
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
128
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
|
129
|
-
<% else %>
|
130
103
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
|
131
|
-
<% end -%>
|
132
104
|
expect(response).to have_http_status(:ok)
|
133
105
|
expect(response.content_type).to eq('application/json')
|
134
106
|
end
|
@@ -137,11 +109,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
137
109
|
context "with invalid params" do
|
138
110
|
it "renders a JSON response with errors for the <%= ns_file_name %>" do
|
139
111
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
140
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
141
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
|
142
|
-
<% else %>
|
143
112
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
|
144
|
-
<% end -%>
|
145
113
|
expect(response).to have_http_status(:unprocessable_entity)
|
146
114
|
expect(response.content_type).to eq('application/json')
|
147
115
|
end
|
@@ -152,11 +120,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
152
120
|
it "destroys the requested <%= ns_file_name %>" do
|
153
121
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
154
122
|
expect {
|
155
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
156
|
-
delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
|
157
|
-
<% else -%>
|
158
123
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
159
|
-
<% end -%>
|
160
124
|
}.to change(<%= class_name %>, :count).by(-1)
|
161
125
|
end
|
162
126
|
end
|
@@ -0,0 +1,131 @@
|
|
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
|
+
RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
|
17
|
+
# This should return the minimal set of attributes required to create a valid
|
18
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
19
|
+
# adjust the attributes here as well.
|
20
|
+
let(:valid_attributes) {
|
21
|
+
skip("Add a hash of attributes valid for your model")
|
22
|
+
}
|
23
|
+
|
24
|
+
let(:invalid_attributes) {
|
25
|
+
skip("Add a hash of attributes invalid for your model")
|
26
|
+
}
|
27
|
+
|
28
|
+
# This should return the minimal set of values that should be in the headers
|
29
|
+
# in order to pass any filters (e.g. authentication) defined in
|
30
|
+
# <%= controller_class_name %>Controller, or in your router and rack
|
31
|
+
# middleware. Be sure to keep this updated too.
|
32
|
+
let(:valid_headers) {
|
33
|
+
{}
|
34
|
+
}
|
35
|
+
|
36
|
+
<% unless options[:singleton] -%>
|
37
|
+
describe "GET /index" do
|
38
|
+
it "renders a successful response" do
|
39
|
+
<%= class_name %>.create! valid_attributes
|
40
|
+
get <%= index_helper %>_url, headers: valid_headers, as: :json
|
41
|
+
expect(response).to be_successful
|
42
|
+
end
|
43
|
+
end
|
44
|
+
<% end -%>
|
45
|
+
|
46
|
+
describe "GET /show" do
|
47
|
+
it "renders a successful response" do
|
48
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
49
|
+
get <%= show_helper.tr('@', '') %>, as: :json
|
50
|
+
expect(response).to be_successful
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "POST /create" do
|
55
|
+
context "with valid parameters" do
|
56
|
+
it "creates a new <%= class_name %>" do
|
57
|
+
expect {
|
58
|
+
post <%= index_helper %>_url,
|
59
|
+
params: { <%= ns_file_name %>: valid_attributes }, headers: valid_headers, as: :json
|
60
|
+
}.to change(<%= class_name %>, :count).by(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "renders a JSON response with the new <%= ns_file_name %>" do
|
64
|
+
post <%= index_helper %>_url,
|
65
|
+
params: { <%= ns_file_name %>: valid_attributes }, headers: valid_headers, as: :json
|
66
|
+
expect(response).to have_http_status(:created)
|
67
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with invalid parameters" do
|
72
|
+
it "does not create a new <%= class_name %>" do
|
73
|
+
expect {
|
74
|
+
post <%= index_helper %>_url,
|
75
|
+
params: { <%= ns_file_name %>: invalid_attributes }, as: :json
|
76
|
+
}.to change(<%= class_name %>, :count).by(0)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "renders a JSON response with errors for the new <%= ns_file_name %>" do
|
80
|
+
post <%= index_helper %>_url,
|
81
|
+
params: { <%= ns_file_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
82
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
83
|
+
expect(response.content_type).to eq("application/json")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "PATCH /update" do
|
89
|
+
context "with valid parameters" do
|
90
|
+
let(:new_attributes) {
|
91
|
+
skip("Add a hash of attributes valid for your model")
|
92
|
+
}
|
93
|
+
|
94
|
+
it "updates the requested <%= ns_file_name %>" do
|
95
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
96
|
+
patch <%= show_helper.tr('@', '') %>,
|
97
|
+
params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
|
98
|
+
<%= file_name %>.reload
|
99
|
+
skip("Add assertions for updated state")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "renders a JSON response with the <%= ns_file_name %>" do
|
103
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
104
|
+
patch <%= show_helper.tr('@', '') %>,
|
105
|
+
params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
|
106
|
+
expect(response).to have_http_status(:ok)
|
107
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "with invalid parameters" do
|
112
|
+
it "renders a JSON response with errors for the <%= ns_file_name %>" do
|
113
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
114
|
+
patch <%= show_helper.tr('@', '') %>,
|
115
|
+
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
|
116
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
117
|
+
expect(response.content_type).to eq("application/json")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "DELETE /destroy" do
|
123
|
+
it "destroys the requested <%= ns_file_name %>" do
|
124
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
125
|
+
expect {
|
126
|
+
delete <%= show_helper.tr('@', '') %>, headers: valid_headers, as: :json
|
127
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
<% end -%>
|
@@ -46,11 +46,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
46
46
|
describe "GET #index" do
|
47
47
|
it "returns a success response" do
|
48
48
|
<%= class_name %>.create! valid_attributes
|
49
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
50
|
-
get :index, {}, valid_session
|
51
|
-
<% else -%>
|
52
49
|
get :index, params: {}, session: valid_session
|
53
|
-
<% end -%>
|
54
50
|
expect(response).to be_successful
|
55
51
|
end
|
56
52
|
end
|
@@ -59,22 +55,14 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
59
55
|
describe "GET #show" do
|
60
56
|
it "returns a success response" do
|
61
57
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
62
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
63
|
-
get :show, {:id => <%= file_name %>.to_param}, valid_session
|
64
|
-
<% else -%>
|
65
58
|
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
|
66
|
-
<% end -%>
|
67
59
|
expect(response).to be_successful
|
68
60
|
end
|
69
61
|
end
|
70
62
|
|
71
63
|
describe "GET #new" do
|
72
64
|
it "returns a success response" do
|
73
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
74
|
-
get :new, {}, valid_session
|
75
|
-
<% else -%>
|
76
65
|
get :new, params: {}, session: valid_session
|
77
|
-
<% end -%>
|
78
66
|
expect(response).to be_successful
|
79
67
|
end
|
80
68
|
end
|
@@ -82,11 +70,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
82
70
|
describe "GET #edit" do
|
83
71
|
it "returns a success response" do
|
84
72
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
85
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
86
|
-
get :edit, {:id => <%= file_name %>.to_param}, valid_session
|
87
|
-
<% else -%>
|
88
73
|
get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
|
89
|
-
<% end -%>
|
90
74
|
expect(response).to be_successful
|
91
75
|
end
|
92
76
|
end
|
@@ -95,31 +79,19 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
95
79
|
context "with valid params" do
|
96
80
|
it "creates a new <%= class_name %>" do
|
97
81
|
expect {
|
98
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
99
|
-
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
100
|
-
<% else -%>
|
101
82
|
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
102
|
-
<% end -%>
|
103
83
|
}.to change(<%= class_name %>, :count).by(1)
|
104
84
|
end
|
105
85
|
|
106
86
|
it "redirects to the created <%= ns_file_name %>" do
|
107
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
108
|
-
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
109
|
-
<% else -%>
|
110
87
|
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
111
|
-
<% end -%>
|
112
88
|
expect(response).to redirect_to(<%= class_name %>.last)
|
113
89
|
end
|
114
90
|
end
|
115
91
|
|
116
92
|
context "with invalid params" do
|
117
93
|
it "returns a success response (i.e. to display the 'new' template)" do
|
118
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
119
|
-
post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
|
120
|
-
<% else -%>
|
121
94
|
post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
|
122
|
-
<% end -%>
|
123
95
|
expect(response).to be_successful
|
124
96
|
end
|
125
97
|
end
|
@@ -133,22 +105,14 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
133
105
|
|
134
106
|
it "updates the requested <%= ns_file_name %>" do
|
135
107
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
136
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
137
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes}, valid_session
|
138
|
-
<% else -%>
|
139
108
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
|
140
|
-
<% end -%>
|
141
109
|
<%= file_name %>.reload
|
142
110
|
skip("Add assertions for updated state")
|
143
111
|
end
|
144
112
|
|
145
113
|
it "redirects to the <%= ns_file_name %>" do
|
146
114
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
147
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
148
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
|
149
|
-
<% else -%>
|
150
115
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
|
151
|
-
<% end -%>
|
152
116
|
expect(response).to redirect_to(<%= file_name %>)
|
153
117
|
end
|
154
118
|
end
|
@@ -156,11 +120,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
156
120
|
context "with invalid params" do
|
157
121
|
it "returns a success response (i.e. to display the 'edit' template)" do
|
158
122
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
159
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
160
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
|
161
|
-
<% else -%>
|
162
123
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
|
163
|
-
<% end -%>
|
164
124
|
expect(response).to be_successful
|
165
125
|
end
|
166
126
|
end
|
@@ -170,21 +130,13 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
170
130
|
it "destroys the requested <%= ns_file_name %>" do
|
171
131
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
172
132
|
expect {
|
173
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
174
|
-
delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
|
175
|
-
<% else -%>
|
176
133
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
177
|
-
<% end -%>
|
178
134
|
}.to change(<%= class_name %>, :count).by(-1)
|
179
135
|
end
|
180
136
|
|
181
137
|
it "redirects to the <%= table_name %> list" do
|
182
138
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
183
|
-
<% if Rails::VERSION::STRING < '5.0' -%>
|
184
|
-
delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
|
185
|
-
<% else -%>
|
186
139
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
187
|
-
<% end -%>
|
188
140
|
expect(response).to redirect_to(<%= index_helper %>_url)
|
189
141
|
end
|
190
142
|
end
|