Skip to content

Commit 973ced4

Browse files
committed
Fix scaffolded CREATE specs
1 parent c4d34da commit 973ced4

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/generators/rspec/scaffold/templates/request_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,16 @@
5353
end
5454

5555
it "redirects to the created <%= ns_file_name %>" do
56-
expect {
57-
post <%= "#{index_helper}_path" %>, params: { <%= ns_file_name %>: valid_attributes }
58-
}.to redirect_to("<%= ns_table_name %>/#{<%= class_name %>.last}")
56+
post <%= "#{index_helper}_path" %>, params: { <%= ns_file_name %>: valid_attributes }
57+
expect(response).to redirect_to(<%= singular_table_name %>_url(<%= class_name %>.last))
5958
end
6059
end
6160

6261
context "with invalid parameters" do
6362
it "does not create a new <%= class_name %>" do
6463
expect {
6564
post <%= "#{index_helper}_path" %>, params: { <%= ns_file_name %>: invalid_attributes }
66-
}.not_to change(<%= class_name %>, :count).by(1)
65+
}.to change(<%= class_name %>, :count).by(0)
6766
end
6867

6968
it "renders a successful response (i.e. to display the 'new' template)" do

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
it { is_expected.to contain(/^RSpec.describe PostsController, #{type_metatag(:request)}/) }
1616
it { is_expected.to contain('GET /new') }
1717
it { is_expected.to contain(/"redirects to the created post"/) }
18-
it { is_expected.to contain('posts/#{Post.last}') }
18+
it { is_expected.to contain('post_url(Post.last)') }
1919
it { is_expected.to contain(/"redirects to the \w+ list"/) }
2020
end
2121

@@ -76,7 +76,7 @@
7676
before { run_generator %w[admin/posts --request_specs] }
7777
it { is_expected.to exist }
7878
it { is_expected.to contain(/^RSpec.describe Admin::PostsController, #{type_metatag(:request)}/) }
79-
it { is_expected.to contain('admin/posts/#{Admin::Post.last}') }
79+
it { is_expected.to contain('admin_post_url(Admin::Post.last)') }
8080
end
8181

8282
describe 'namespaced controller spec' do

0 commit comments

Comments
 (0)