rspec-rails 3.5.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/Capybara.md +6 -55
  4. data/Changelog.md +321 -62
  5. data/README.md +265 -493
  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 +21 -4
  9. data/lib/generators/rspec/controller/templates/request_spec.rb +14 -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 +27 -14
  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/mailbox/mailbox_generator.rb +14 -0
  20. data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
  21. data/lib/generators/rspec/mailer/mailer_generator.rb +2 -1
  22. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
  23. data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
  24. data/lib/generators/rspec/model/model_generator.rb +6 -5
  25. data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
  26. data/lib/generators/rspec/request/request_generator.rb +1 -1
  27. data/lib/generators/rspec/scaffold/scaffold_generator.rb +52 -86
  28. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +129 -0
  29. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  30. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +40 -74
  31. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +5 -1
  32. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  33. data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -1
  34. data/lib/generators/rspec/scaffold/templates/request_spec.rb +133 -0
  35. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +13 -12
  36. data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
  37. data/lib/generators/rspec/system/system_generator.rb +26 -0
  38. data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
  39. data/lib/generators/rspec/view/view_generator.rb +2 -2
  40. data/lib/generators/rspec.rb +0 -6
  41. data/lib/rspec/rails/active_record.rb +1 -1
  42. data/lib/rspec/rails/adapters.rb +11 -76
  43. data/lib/rspec/rails/configuration.rb +47 -31
  44. data/lib/rspec/rails/example/channel_example_group.rb +93 -0
  45. data/lib/rspec/rails/example/controller_example_group.rb +4 -4
  46. data/lib/rspec/rails/example/feature_example_group.rb +6 -26
  47. data/lib/rspec/rails/example/helper_example_group.rb +2 -9
  48. data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
  49. data/lib/rspec/rails/example/mailer_example_group.rb +1 -1
  50. data/lib/rspec/rails/example/rails_example_group.rb +1 -2
  51. data/lib/rspec/rails/example/request_example_group.rb +1 -3
  52. data/lib/rspec/rails/example/system_example_group.rb +124 -0
  53. data/lib/rspec/rails/example/view_example_group.rb +47 -28
  54. data/lib/rspec/rails/example.rb +3 -0
  55. data/lib/rspec/rails/extensions/active_record/proxy.rb +1 -9
  56. data/lib/rspec/rails/feature_check.rb +12 -29
  57. data/lib/rspec/rails/fixture_file_upload_support.rb +40 -0
  58. data/lib/rspec/rails/fixture_support.rb +37 -31
  59. data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +170 -0
  60. data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
  61. data/lib/rspec/rails/matchers/action_cable.rb +65 -0
  62. data/lib/rspec/rails/matchers/action_mailbox.rb +64 -0
  63. data/lib/rspec/rails/matchers/active_job.rb +208 -18
  64. data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
  65. data/lib/rspec/rails/matchers/be_a_new.rb +8 -7
  66. data/lib/rspec/rails/matchers/be_new_record.rb +3 -3
  67. data/lib/rspec/rails/matchers/be_valid.rb +1 -1
  68. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +198 -0
  69. data/lib/rspec/rails/matchers/have_http_status.rb +34 -13
  70. data/lib/rspec/rails/matchers/have_rendered.rb +2 -1
  71. data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
  72. data/lib/rspec/rails/matchers/routing_matchers.rb +14 -14
  73. data/lib/rspec/rails/matchers.rb +11 -0
  74. data/lib/rspec/rails/tasks/rspec.rake +7 -17
  75. data/lib/rspec/rails/vendor/capybara.rb +12 -13
  76. data/lib/rspec/rails/version.rb +1 -1
  77. data/lib/rspec/rails/view_path_builder.rb +2 -2
  78. data/lib/rspec/rails/view_rendering.rb +18 -5
  79. data/lib/rspec/rails.rb +1 -0
  80. data/lib/rspec-rails.rb +17 -11
  81. data.tar.gz.sig +0 -0
  82. metadata +57 -33
  83. metadata.gz.sig +0 -0
  84. data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -0,0 +1,129 @@
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 specify 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
+ # Compared to earlier versions of this generator, there is very limited use of
16
+ # stubs and message expectations in this spec. Stubs are only used when there
17
+ # is no simpler way to get a handle on the object needed for the example.
18
+ # Message expectations are only used when there is no simpler way to specify
19
+ # that an instance is receiving a specific message.
20
+ #
21
+ # Also compared to earlier versions of this generator, there are no longer any
22
+ # expectations of assigns and templates rendered. These features have been
23
+ # removed from Rails core in Rails 5, but can be added back in via the
24
+ # `rails-controller-testing` gem.
25
+
26
+ <% module_namespacing do -%>
27
+ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:controller) %> do
28
+
29
+ # This should return the minimal set of attributes required to create a valid
30
+ # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
31
+ # adjust the attributes here as well.
32
+ let(:valid_attributes) {
33
+ skip("Add a hash of attributes valid for your model")
34
+ }
35
+
36
+ let(:invalid_attributes) {
37
+ skip("Add a hash of attributes invalid for your model")
38
+ }
39
+
40
+ # This should return the minimal set of values that should be in the session
41
+ # in order to pass any filters (e.g. authentication) defined in
42
+ # <%= controller_class_name %>Controller. Be sure to keep this updated too.
43
+ let(:valid_session) { {} }
44
+
45
+ <% unless options[:singleton] -%>
46
+ describe "GET #index" do
47
+ it "returns a success response" do
48
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
49
+ get :index, params: {}, session: valid_session
50
+ expect(response).to be_successful
51
+ end
52
+ end
53
+
54
+ <% end -%>
55
+ describe "GET #show" do
56
+ it "returns a success response" do
57
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
58
+ get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
59
+ expect(response).to be_successful
60
+ end
61
+ end
62
+
63
+ describe "POST #create" do
64
+ context "with valid params" do
65
+ it "creates a new <%= class_name %>" do
66
+ expect {
67
+ post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
68
+ }.to change(<%= class_name %>, :count).by(1)
69
+ end
70
+
71
+ it "renders a JSON response with the new <%= ns_file_name %>" do
72
+ post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
73
+ expect(response).to have_http_status(:created)
74
+ expect(response.content_type).to eq('application/json')
75
+ expect(response.location).to eq(<%= ns_file_name %>_url(<%= class_name %>.last))
76
+ end
77
+ end
78
+
79
+ context "with invalid params" do
80
+ it "renders a JSON response with errors for the new <%= ns_file_name %>" do
81
+ post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
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 "PUT #update" do
89
+ context "with valid params" 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
+ put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
97
+ <%= file_name %>.reload
98
+ skip("Add assertions for updated state")
99
+ end
100
+
101
+ it "renders a JSON response with the <%= ns_file_name %>" do
102
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
103
+ put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
104
+ expect(response).to have_http_status(:ok)
105
+ expect(response.content_type).to eq('application/json')
106
+ end
107
+ end
108
+
109
+ context "with invalid params" do
110
+ it "renders a JSON response with errors for the <%= ns_file_name %>" do
111
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
112
+ put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
113
+ expect(response).to have_http_status(:unprocessable_entity)
114
+ expect(response.content_type).to eq('application/json')
115
+ end
116
+ end
117
+ end
118
+
119
+ describe "DELETE #destroy" do
120
+ it "destroys the requested <%= ns_file_name %>" do
121
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
122
+ expect {
123
+ delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
124
+ }.to change(<%= class_name %>, :count).by(-1)
125
+ end
126
+ end
127
+
128
+ end
129
+ <% 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 %>: invalid_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 %>: invalid_attributes }, headers: valid_headers, as: :json
106
+ expect(response).to have_http_status(:ok)
107
+ expect(response.content_type).to eq("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 -%>
@@ -17,6 +17,11 @@ require 'rails_helper'
17
17
  # is no simpler way to get a handle on the object needed for the example.
18
18
  # Message expectations are only used when there is no simpler way to specify
19
19
  # that an instance is receiving a specific message.
20
+ #
21
+ # Also compared to earlier versions of this generator, there are no longer any
22
+ # expectations of assigns and templates rendered. These features have been
23
+ # removed from Rails core in Rails 5, but can be added back in via the
24
+ # `rails-controller-testing` gem.
20
25
 
21
26
  <% module_namespacing do -%>
22
27
  RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:controller) %> do
@@ -39,50 +44,50 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
39
44
 
40
45
  <% unless options[:singleton] -%>
41
46
  describe "GET #index" do
42
- it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
43
- <%= file_name %> = <%= class_name %>.create! valid_attributes
44
- <% if RUBY_VERSION < '1.9.3' -%>
47
+ it "returns a success response" do
48
+ <%= class_name %>.create! valid_attributes
49
+ <% if Rails::VERSION::STRING < '5.0' -%>
45
50
  get :index, {}, valid_session
46
51
  <% else -%>
47
52
  get :index, params: {}, session: valid_session
48
53
  <% end -%>
49
- expect(assigns(:<%= table_name %>)).to eq([<%= file_name %>])
54
+ expect(response).to be_successful
50
55
  end
51
56
  end
52
57
 
53
58
  <% end -%>
54
59
  describe "GET #show" do
55
- it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
60
+ it "returns a success response" do
56
61
  <%= file_name %> = <%= class_name %>.create! valid_attributes
57
- <% if RUBY_VERSION < '1.9.3' -%>
58
- get :show, {:id => <%= file_name %>.to_param}, valid_session
62
+ <% if Rails::VERSION::STRING < '5.0' -%>
63
+ get :show, {id: <%= file_name %>.to_param}, valid_session
59
64
  <% else -%>
60
65
  get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
61
66
  <% end -%>
62
- expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
67
+ expect(response).to be_successful
63
68
  end
64
69
  end
65
70
 
66
71
  describe "GET #new" do
67
- it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
68
- <% if RUBY_VERSION < '1.9.3' -%>
72
+ it "returns a success response" do
73
+ <% if Rails::VERSION::STRING < '5.0' -%>
69
74
  get :new, {}, valid_session
70
75
  <% else -%>
71
76
  get :new, params: {}, session: valid_session
72
77
  <% end -%>
73
- expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
78
+ expect(response).to be_successful
74
79
  end
75
80
  end
76
81
 
77
82
  describe "GET #edit" do
78
- it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
83
+ it "returns a success response" do
79
84
  <%= file_name %> = <%= class_name %>.create! valid_attributes
80
- <% if RUBY_VERSION < '1.9.3' -%>
81
- get :edit, {:id => <%= file_name %>.to_param}, valid_session
85
+ <% if Rails::VERSION::STRING < '5.0' -%>
86
+ get :edit, {id: <%= file_name %>.to_param}, valid_session
82
87
  <% else -%>
83
88
  get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
84
89
  <% end -%>
85
- expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
90
+ expect(response).to be_successful
86
91
  end
87
92
  end
88
93
 
@@ -90,27 +95,17 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
90
95
  context "with valid params" do
91
96
  it "creates a new <%= class_name %>" do
92
97
  expect {
93
- <% if RUBY_VERSION < '1.9.3' -%>
94
- post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
98
+ <% if Rails::VERSION::STRING < '5.0' -%>
99
+ post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
95
100
  <% else -%>
96
101
  post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
97
102
  <% end -%>
98
103
  }.to change(<%= class_name %>, :count).by(1)
99
104
  end
100
105
 
101
- it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
102
- <% if RUBY_VERSION < '1.9.3' -%>
103
- post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
104
- <% else -%>
105
- post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
106
- <% end -%>
107
- expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
108
- expect(assigns(:<%= ns_file_name %>)).to be_persisted
109
- end
110
-
111
106
  it "redirects to the created <%= ns_file_name %>" do
112
- <% if RUBY_VERSION < '1.9.3' -%>
113
- post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
107
+ <% if Rails::VERSION::STRING < '5.0' -%>
108
+ post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
114
109
  <% else -%>
115
110
  post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
116
111
  <% end -%>
@@ -119,22 +114,13 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
119
114
  end
120
115
 
121
116
  context "with invalid params" do
122
- it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
123
- <% if RUBY_VERSION < '1.9.3' -%>
124
- post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
125
- <% else -%>
126
- post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
127
- <% end -%>
128
- expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
129
- end
130
-
131
- it "re-renders the 'new' template" do
132
- <% if RUBY_VERSION < '1.9.3' -%>
133
- post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
117
+ 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
134
120
  <% else -%>
135
121
  post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
136
122
  <% end -%>
137
- expect(response).to render_template("new")
123
+ expect(response).to be_successful
138
124
  end
139
125
  end
140
126
  end
@@ -147,8 +133,8 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
147
133
 
148
134
  it "updates the requested <%= ns_file_name %>" do
149
135
  <%= file_name %> = <%= class_name %>.create! valid_attributes
150
- <% if RUBY_VERSION < '1.9.3' -%>
151
- put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes}, valid_session
136
+ <% if Rails::VERSION::STRING < '5.0' -%>
137
+ put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session
152
138
  <% else -%>
153
139
  put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
154
140
  <% end -%>
@@ -156,20 +142,10 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
156
142
  skip("Add assertions for updated state")
157
143
  end
158
144
 
159
- it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
160
- <%= file_name %> = <%= class_name %>.create! valid_attributes
161
- <% if RUBY_VERSION < '1.9.3' -%>
162
- put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
163
- <% else -%>
164
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
165
- <% end -%>
166
- expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
167
- end
168
-
169
145
  it "redirects to the <%= ns_file_name %>" do
170
146
  <%= file_name %> = <%= class_name %>.create! valid_attributes
171
- <% if RUBY_VERSION < '1.9.3' -%>
172
- put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
147
+ <% if Rails::VERSION::STRING < '5.0' -%>
148
+ put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session
173
149
  <% else -%>
174
150
  put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
175
151
  <% end -%>
@@ -178,24 +154,14 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
178
154
  end
179
155
 
180
156
  context "with invalid params" do
181
- it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
182
- <%= file_name %> = <%= class_name %>.create! valid_attributes
183
- <% if RUBY_VERSION < '1.9.3' -%>
184
- put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
185
- <% else -%>
186
- put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
187
- <% end -%>
188
- expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
189
- end
190
-
191
- it "re-renders the 'edit' template" do
157
+ it "returns a success response (i.e. to display the 'edit' template)" do
192
158
  <%= file_name %> = <%= class_name %>.create! valid_attributes
193
- <% if RUBY_VERSION < '1.9.3' -%>
194
- put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
159
+ <% if Rails::VERSION::STRING < '5.0' -%>
160
+ put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session
195
161
  <% else -%>
196
162
  put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
197
163
  <% end -%>
198
- expect(response).to render_template("edit")
164
+ expect(response).to be_successful
199
165
  end
200
166
  end
201
167
  end
@@ -204,8 +170,8 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
204
170
  it "destroys the requested <%= ns_file_name %>" do
205
171
  <%= file_name %> = <%= class_name %>.create! valid_attributes
206
172
  expect {
207
- <% if RUBY_VERSION < '1.9.3' -%>
208
- delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
173
+ <% if Rails::VERSION::STRING < '5.0' -%>
174
+ delete :destroy, {id: <%= file_name %>.to_param}, valid_session
209
175
  <% else -%>
210
176
  delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
211
177
  <% end -%>
@@ -214,8 +180,8 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
214
180
 
215
181
  it "redirects to the <%= table_name %> list" do
216
182
  <%= file_name %> = <%= class_name %>.create! valid_attributes
217
- <% if RUBY_VERSION < '1.9.3' -%>
218
- delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
183
+ <% if Rails::VERSION::STRING < '5.0' -%>
184
+ delete :destroy, {id: <%= file_name %>.to_param}, valid_session
219
185
  <% else -%>
220
186
  delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
221
187
  <% 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,7 +16,11 @@ 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
+ assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
21
+ <% else -%>
19
22
  assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
23
+ <% end -%>
20
24
  <% end -%>
21
25
  end
22
26
  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,7 +15,11 @@ 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
+ assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
20
+ <% else -%>
18
21
  assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
22
+ <% end -%>
19
23
  <% end -%>
20
24
  end
21
25
  end