Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scaffold template with namespace and --model-name option #2534

Merged
merged 6 commits into from Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/generators/rspec/scaffold/templates/request_spec.rb
Expand Up @@ -65,25 +65,25 @@
context "with valid parameters" do
it "creates a new <%= class_name %>" do
expect {
post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
}.to change(<%= class_name %>, :count).by(1)
end

it "redirects to the created <%= ns_file_name %>" do
post <%= index_helper %>_url, params: { <%= ns_file_name %>: valid_attributes }
it "redirects to the created <%= singular_table_name %>" do
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
expect(response).to redirect_to(<%= show_helper(class_name+".last") %>)
end
end

context "with invalid parameters" do
it "does not create a new <%= class_name %>" do
expect {
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
}.to change(<%= class_name %>, :count).by(0)
end

it "renders a successful response (i.e. to display the 'new' template)" do
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
expect(response).to be_successful
end
end
Expand All @@ -95,14 +95,14 @@
skip("Add a hash of attributes valid for your model")
}

it "updates the requested <%= ns_file_name %>" do
it "updates the requested <%= singular_table_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
<%= file_name %>.reload
skip("Add assertions for updated state")
end

it "redirects to the <%= ns_file_name %>" do
it "redirects to the <%= singular_table_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
<%= file_name %>.reload
Expand All @@ -120,7 +120,7 @@
end

describe "DELETE /destroy" do
it "destroys the requested <%= ns_file_name %>" do
it "destroys the requested <%= singular_table_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
expect {
delete <%= show_helper %>
Expand Down
21 changes: 16 additions & 5 deletions spec/generators/rspec/scaffold/scaffold_generator_spec.rb
Expand Up @@ -101,11 +101,22 @@

describe 'namespaced request spec' do
subject { file('spec/requests/admin/posts_spec.rb') }
before { run_generator %w[admin/posts] }
it { is_expected.to exist }
it { is_expected.to contain(/^RSpec.describe "\/admin\/posts", #{type_metatag(:request)}/) }
it { is_expected.to contain('admin_post_url(post)') }
it { is_expected.to contain('Admin::Post.create') }

describe 'with no options' do
before { run_generator %w[admin/posts] }
it { is_expected.to exist }
it { is_expected.to contain(/^RSpec.describe "\/admin\/posts", #{type_metatag(:request)}/) }
it { is_expected.to contain('post admin_posts_url, params: { admin_post: valid_attributes }') }
it { is_expected.to contain('admin_post_url(post)') }
it { is_expected.to contain('Admin::Post.create') }
end

describe 'with --model-name' do
before { run_generator %w[admin/posts --model-name=post] }
it { is_expected.to contain('post admin_posts_url, params: { post: valid_attributes }') }
it { is_expected.not_to contain('params: { admin_post: valid_attributes }') }
it { is_expected.to contain(' Post.create') }
end
end

describe 'namespaced controller spec' do
Expand Down