rspec-rails 3.7.2 → 5.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/Capybara.md +5 -54
  4. data/Changelog.md +333 -71
  5. data/README.md +278 -498
  6. data/lib/generators/rspec/channel/channel_generator.rb +12 -0
  7. data/lib/generators/rspec/{observer/templates/observer_spec.rb → channel/templates/channel_spec.rb.erb} +1 -1
  8. data/lib/generators/rspec/controller/controller_generator.rb +22 -5
  9. data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
  10. data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
  11. data/lib/generators/rspec/feature/feature_generator.rb +4 -4
  12. data/lib/generators/rspec/generator/generator_generator.rb +24 -0
  13. data/lib/generators/rspec/generator/templates/generator_spec.rb +6 -0
  14. data/lib/generators/rspec/helper/helper_generator.rb +1 -1
  15. data/lib/generators/rspec/install/install_generator.rb +4 -4
  16. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +25 -12
  17. data/lib/generators/rspec/integration/integration_generator.rb +4 -4
  18. data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
  19. data/lib/generators/rspec/job/job_generator.rb +2 -1
  20. data/lib/generators/rspec/job/templates/job_spec.rb.erb +1 -1
  21. data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
  22. data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
  23. data/lib/generators/rspec/mailer/mailer_generator.rb +2 -1
  24. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
  25. data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
  26. data/lib/generators/rspec/model/model_generator.rb +6 -5
  27. data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
  28. data/lib/generators/rspec/request/request_generator.rb +1 -1
  29. data/lib/generators/rspec/scaffold/scaffold_generator.rb +47 -23
  30. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +15 -51
  31. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  32. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +17 -65
  33. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -5
  34. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  35. data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -5
  36. data/lib/generators/rspec/scaffold/templates/request_spec.rb +138 -0
  37. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +10 -13
  38. data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
  39. data/lib/generators/rspec/system/system_generator.rb +24 -0
  40. data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
  41. data/lib/generators/rspec/view/view_generator.rb +2 -2
  42. data/lib/generators/rspec.rb +0 -6
  43. data/lib/rspec/rails/adapters.rb +11 -76
  44. data/lib/rspec/rails/configuration.rb +82 -37
  45. data/lib/rspec/rails/example/channel_example_group.rb +93 -0
  46. data/lib/rspec/rails/example/controller_example_group.rb +5 -4
  47. data/lib/rspec/rails/example/feature_example_group.rb +6 -26
  48. data/lib/rspec/rails/example/helper_example_group.rb +2 -9
  49. data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
  50. data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
  51. data/lib/rspec/rails/example/rails_example_group.rb +1 -1
  52. data/lib/rspec/rails/example/request_example_group.rb +1 -4
  53. data/lib/rspec/rails/example/system_example_group.rb +36 -16
  54. data/lib/rspec/rails/example/view_example_group.rb +47 -28
  55. data/lib/rspec/rails/example.rb +2 -0
  56. data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
  57. data/lib/rspec/rails/feature_check.rb +12 -29
  58. data/lib/rspec/rails/file_fixture_support.rb +9 -11
  59. data/lib/rspec/rails/fixture_file_upload_support.rb +34 -17
  60. data/lib/rspec/rails/fixture_support.rb +35 -32
  61. data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +170 -0
  62. data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
  63. data/lib/rspec/rails/matchers/action_cable.rb +65 -0
  64. data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
  65. data/lib/rspec/rails/matchers/active_job.rb +208 -24
  66. data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
  67. data/lib/rspec/rails/matchers/be_a_new.rb +1 -1
  68. data/lib/rspec/rails/matchers/be_new_record.rb +1 -1
  69. data/lib/rspec/rails/matchers/be_valid.rb +1 -1
  70. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +226 -0
  71. data/lib/rspec/rails/matchers/have_http_status.rb +38 -17
  72. data/lib/rspec/rails/matchers/have_rendered.rb +2 -1
  73. data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
  74. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  75. data/lib/rspec/rails/matchers/routing_matchers.rb +14 -14
  76. data/lib/rspec/rails/matchers.rb +11 -0
  77. data/lib/rspec/rails/tasks/rspec.rake +7 -17
  78. data/lib/rspec/rails/vendor/capybara.rb +10 -15
  79. data/lib/rspec/rails/version.rb +1 -1
  80. data/lib/rspec/rails/view_path_builder.rb +1 -1
  81. data/lib/rspec/rails/view_rendering.rb +16 -5
  82. data/lib/rspec-rails.rb +12 -11
  83. data.tar.gz.sig +0 -0
  84. metadata +69 -36
  85. metadata.gz.sig +0 -0
  86. data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -46,12 +46,8 @@ 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
- expect(response).to be_success
50
+ expect(response).to be_successful
55
51
  end
56
52
  end
57
53
 
@@ -59,12 +55,8 @@ 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
- expect(response).to be_success
59
+ expect(response).to be_successful
68
60
  end
69
61
  end
70
62
 
@@ -72,33 +64,21 @@ 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
- post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
79
- <% end -%>
67
+ post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
80
68
  }.to change(<%= class_name %>, :count).by(1)
81
69
  end
82
70
 
83
- 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
- post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
88
- <% end -%>
71
+ it "renders a JSON response with the new <%= singular_table_name %>" do
72
+ post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
89
73
  expect(response).to have_http_status(:created)
90
74
  expect(response.content_type).to eq('application/json')
91
- expect(response.location).to eq(<%= ns_file_name %>_url(<%= class_name %>.last))
75
+ expect(response.location).to eq(<%= singular_table_name %>_url(<%= class_name %>.last))
92
76
  end
93
77
  end
94
78
 
95
79
  context "with invalid params" do
96
- 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
- post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
101
- <% end -%>
80
+ it "renders a JSON response with errors for the new <%= singular_table_name %>" do
81
+ post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
102
82
  expect(response).to have_http_status(:unprocessable_entity)
103
83
  expect(response.content_type).to eq('application/json')
104
84
  end
@@ -111,37 +91,25 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
111
91
  skip("Add a hash of attributes valid for your model")
112
92
  }
113
93
 
114
- it "updates the requested <%= ns_file_name %>" do
94
+ it "updates the requested <%= singular_table_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
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
120
- <% end -%>
96
+ put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
121
97
  <%= file_name %>.reload
122
98
  skip("Add assertions for updated state")
123
99
  end
124
100
 
125
- it "renders a JSON response with the <%= ns_file_name %>" do
101
+ it "renders a JSON response with the <%= singular_table_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
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
131
- <% end -%>
103
+ put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
132
104
  expect(response).to have_http_status(:ok)
133
105
  expect(response.content_type).to eq('application/json')
134
106
  end
135
107
  end
136
108
 
137
109
  context "with invalid params" do
138
- it "renders a JSON response with errors for the <%= ns_file_name %>" do
110
+ it "renders a JSON response with errors for the <%= singular_table_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
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
144
- <% end -%>
112
+ put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
145
113
  expect(response).to have_http_status(:unprocessable_entity)
146
114
  expect(response.content_type).to eq('application/json')
147
115
  end
@@ -149,14 +117,10 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
149
117
  end
150
118
 
151
119
  describe "DELETE #destroy" do
152
- it "destroys the requested <%= ns_file_name %>" do
120
+ it "destroys the requested <%= singular_table_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 %>, 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: { <%= singular_table_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 <%= singular_table_name %>" do
64
+ post <%= index_helper %>_url,
65
+ params: { <%= singular_table_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: { <%= singular_table_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 <%= singular_table_name %>" do
80
+ post <%= index_helper %>_url,
81
+ params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
82
+ expect(response).to have_http_status(:unprocessable_entity)
83
+ expect(response.content_type).to match(a_string_including("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 <%= singular_table_name %>" do
95
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
96
+ patch <%= show_helper %>,
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 <%= singular_table_name %>" do
103
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
104
+ patch <%= show_helper %>,
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 <%= singular_table_name %>" do
113
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
114
+ patch <%= show_helper %>,
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 match(a_string_including("application/json"))
118
+ end
119
+ end
120
+ end
121
+
122
+ describe "DELETE /destroy" do
123
+ it "destroys the requested <%= singular_table_name %>" do
124
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
125
+ expect {
126
+ delete <%= show_helper %>, headers: valid_headers, as: :json
127
+ }.to change(<%= class_name %>, :count).by(-1)
128
+ end
129
+ end
130
+ end
131
+ <% end -%>
@@ -45,13 +45,9 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
45
45
  <% unless options[:singleton] -%>
46
46
  describe "GET #index" do
47
47
  it "returns a success response" do
48
- <%= file_name %> = <%= class_name %>.create! valid_attributes
49
- <% if Rails::VERSION::STRING < '5.0' -%>
50
- get :index, {}, valid_session
51
- <% else -%>
48
+ <%= class_name %>.create! valid_attributes
52
49
  get :index, params: {}, session: valid_session
53
- <% end -%>
54
- expect(response).to be_success
50
+ expect(response).to be_successful
55
51
  end
56
52
  end
57
53
 
@@ -59,35 +55,23 @@ 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
- expect(response).to be_success
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
- expect(response).to be_success
66
+ expect(response).to be_successful
79
67
  end
80
68
  end
81
69
 
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
- expect(response).to be_success
74
+ expect(response).to be_successful
91
75
  end
92
76
  end
93
77
 
@@ -95,32 +79,20 @@ 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
- post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
102
- <% end -%>
82
+ post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
103
83
  }.to change(<%= class_name %>, :count).by(1)
104
84
  end
105
85
 
106
- 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
- post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
111
- <% end -%>
86
+ it "redirects to the created <%= singular_table_name %>" do
87
+ post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
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
- post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
122
- <% end -%>
123
- expect(response).to be_success
94
+ post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
95
+ expect(response).to be_successful
124
96
  end
125
97
  end
126
98
  end
@@ -131,24 +103,16 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
131
103
  skip("Add a hash of attributes valid for your model")
132
104
  }
133
105
 
134
- it "updates the requested <%= ns_file_name %>" do
106
+ it "updates the requested <%= singular_table_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
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
140
- <% end -%>
108
+ put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
141
109
  <%= file_name %>.reload
142
110
  skip("Add assertions for updated state")
143
111
  end
144
112
 
145
- it "redirects to the <%= ns_file_name %>" do
113
+ it "redirects to the <%= singular_table_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
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
151
- <% end -%>
115
+ put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: new_attributes}, session: valid_session
152
116
  expect(response).to redirect_to(<%= file_name %>)
153
117
  end
154
118
  end
@@ -156,35 +120,23 @@ 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
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
163
- <% end -%>
164
- expect(response).to be_success
123
+ put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
124
+ expect(response).to be_successful
165
125
  end
166
126
  end
167
127
  end
168
128
 
169
129
  describe "DELETE #destroy" do
170
- it "destroys the requested <%= ns_file_name %>" do
130
+ it "destroys the requested <%= singular_table_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
@@ -5,7 +5,7 @@ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
5
5
  before(:each) do
6
6
  @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
7
7
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
8
- :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
8
+ <%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
9
9
  <% end -%>
10
10
  <%= output_attributes.empty? ? "" : " ))\n" -%>
11
11
  end
@@ -16,11 +16,7 @@ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
16
16
  assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
17
17
  <% for attribute in output_attributes -%>
18
18
  <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
19
- <% if Rails.version.to_f >= 5.1 -%>
20
19
  assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
21
- <% else -%>
22
- assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
23
- <% end -%>
24
20
  <% end -%>
25
21
  end
26
22
  end
@@ -7,7 +7,7 @@ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
7
7
  <% [1,2].each_with_index do |id, model_index| -%>
8
8
  <%= class_name %>.create!(<%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : '' %>
9
9
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
10
- :<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
10
+ <%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
11
11
  <% end -%>
12
12
  <% if !output_attributes.empty? -%>
13
13
  <%= model_index == 1 ? ')' : '),' %>
@@ -19,7 +19,7 @@ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
19
19
  it "renders a list of <%= ns_table_name %>" do
20
20
  render
21
21
  <% for attribute in output_attributes -%>
22
- assert_select "tr>td", :text => <%= value_for(attribute) %>.to_s, :count => 2
22
+ assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 2
23
23
  <% end -%>
24
24
  end
25
25
  end
@@ -5,7 +5,7 @@ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
5
5
  before(:each) do
6
6
  assign(:<%= ns_file_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
7
7
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
8
- :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
8
+ <%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
9
9
  <% end -%>
10
10
  <%= !output_attributes.empty? ? " ))\n end" : " end" %>
11
11
 
@@ -15,11 +15,7 @@ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
15
15
  assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
16
16
  <% for attribute in output_attributes -%>
17
17
  <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
18
- <% if Rails.version.to_f >= 5.1 -%>
19
18
  assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
20
- <% else -%>
21
- assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
22
- <% end -%>
23
19
  <% end -%>
24
20
  end
25
21
  end
@@ -0,0 +1,138 @@
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
+ <% if mountable_engine? -%>
18
+ include Engine.routes.url_helpers
19
+ <% end -%>
20
+
21
+ # This should return the minimal set of attributes required to create a valid
22
+ # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
23
+ # adjust the attributes here as well.
24
+ let(:valid_attributes) {
25
+ skip("Add a hash of attributes valid for your model")
26
+ }
27
+
28
+ let(:invalid_attributes) {
29
+ skip("Add a hash of attributes invalid for your model")
30
+ }
31
+
32
+ <% unless options[:singleton] -%>
33
+ describe "GET /index" do
34
+ it "renders a successful response" do
35
+ <%= class_name %>.create! valid_attributes
36
+ get <%= index_helper %>_url
37
+ expect(response).to be_successful
38
+ end
39
+ end
40
+ <% end -%>
41
+
42
+ describe "GET /show" do
43
+ it "renders a successful response" do
44
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
45
+ get <%= show_helper %>
46
+ expect(response).to be_successful
47
+ end
48
+ end
49
+
50
+ describe "GET /new" do
51
+ it "renders a successful response" do
52
+ get <%= new_helper %>
53
+ expect(response).to be_successful
54
+ end
55
+ end
56
+
57
+ describe "GET /edit" do
58
+ it "renders a successful response" do
59
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
60
+ get <%= edit_helper %>
61
+ expect(response).to be_successful
62
+ end
63
+ end
64
+
65
+ describe "POST /create" do
66
+ context "with valid parameters" do
67
+ it "creates a new <%= class_name %>" do
68
+ expect {
69
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
70
+ }.to change(<%= class_name %>, :count).by(1)
71
+ end
72
+
73
+ it "redirects to the created <%= singular_table_name %>" do
74
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
75
+ expect(response).to redirect_to(<%= show_helper(class_name+".last") %>)
76
+ end
77
+ end
78
+
79
+ context "with invalid parameters" do
80
+ it "does not create a new <%= class_name %>" do
81
+ expect {
82
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
83
+ }.to change(<%= class_name %>, :count).by(0)
84
+ end
85
+
86
+ it "renders a successful response (i.e. to display the 'new' template)" do
87
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
88
+ expect(response).to be_successful
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "PATCH /update" do
94
+ context "with valid parameters" do
95
+ let(:new_attributes) {
96
+ skip("Add a hash of attributes valid for your model")
97
+ }
98
+
99
+ it "updates the requested <%= singular_table_name %>" do
100
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
101
+ patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
102
+ <%= file_name %>.reload
103
+ skip("Add assertions for updated state")
104
+ end
105
+
106
+ it "redirects to the <%= singular_table_name %>" do
107
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
108
+ patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
109
+ <%= file_name %>.reload
110
+ expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
111
+ end
112
+ end
113
+
114
+ context "with invalid parameters" do
115
+ it "renders a successful response (i.e. to display the 'edit' template)" do
116
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
117
+ patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
118
+ expect(response).to be_successful
119
+ end
120
+ end
121
+ end
122
+
123
+ describe "DELETE /destroy" do
124
+ it "destroys the requested <%= singular_table_name %>" do
125
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
126
+ expect {
127
+ delete <%= show_helper %>
128
+ }.to change(<%= class_name %>, :count).by(-1)
129
+ end
130
+
131
+ it "redirects to the <%= table_name %> list" do
132
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
133
+ delete <%= show_helper %>
134
+ expect(response).to redirect_to(<%= index_helper %>_url)
135
+ end
136
+ end
137
+ end
138
+ <% end -%>