Skip to content

Commit ba672e8

Browse files
committed
Fix api request spec template for --model-name option.
related: #2532
1 parent 5dd83b4 commit ba672e8

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
it "creates a new <%= class_name %>" do
5757
expect {
5858
post <%= index_helper %>_url,
59-
params: { <%= ns_file_name %>: valid_attributes }, headers: valid_headers, as: :json
59+
params: { <%= singular_table_name %>: valid_attributes }, headers: valid_headers, as: :json
6060
}.to change(<%= class_name %>, :count).by(1)
6161
end
6262
63-
it "renders a JSON response with the new <%= ns_file_name %>" do
63+
it "renders a JSON response with the new <%= singular_table_name %>" do
6464
post <%= index_helper %>_url,
65-
params: { <%= ns_file_name %>: valid_attributes }, headers: valid_headers, as: :json
65+
params: { <%= singular_table_name %>: valid_attributes }, headers: valid_headers, as: :json
6666
expect(response).to have_http_status(:created)
6767
expect(response.content_type).to match(a_string_including("application/json"))
6868
end
@@ -72,13 +72,13 @@
7272
it "does not create a new <%= class_name %>" do
7373
expect {
7474
post <%= index_helper %>_url,
75-
params: { <%= ns_file_name %>: invalid_attributes }, as: :json
75+
params: { <%= singular_table_name %>: invalid_attributes }, as: :json
7676
}.to change(<%= class_name %>, :count).by(0)
7777
end
7878
79-
it "renders a JSON response with errors for the new <%= ns_file_name %>" do
79+
it "renders a JSON response with errors for the new <%= singular_table_name %>" do
8080
post <%= index_helper %>_url,
81-
params: { <%= ns_file_name %>: invalid_attributes }, headers: valid_headers, as: :json
81+
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
8282
expect(response).to have_http_status(:unprocessable_entity)
8383
expect(response.content_type).to match(a_string_including("application/json"))
8484
end
@@ -91,15 +91,15 @@
9191
skip("Add a hash of attributes valid for your model")
9292
}
9393
94-
it "updates the requested <%= ns_file_name %>" do
94+
it "updates the requested <%= singular_table_name %>" do
9595
<%= file_name %> = <%= class_name %>.create! valid_attributes
9696
patch <%= show_helper %>,
9797
params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
9898
<%= file_name %>.reload
9999
skip("Add assertions for updated state")
100100
end
101101
102-
it "renders a JSON response with the <%= ns_file_name %>" do
102+
it "renders a JSON response with the <%= singular_table_name %>" do
103103
<%= file_name %> = <%= class_name %>.create! valid_attributes
104104
patch <%= show_helper %>,
105105
params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
@@ -109,7 +109,7 @@
109109
end
110110
111111
context "with invalid parameters" do
112-
it "renders a JSON response with errors for the <%= ns_file_name %>" do
112+
it "renders a JSON response with errors for the <%= singular_table_name %>" do
113113
<%= file_name %> = <%= class_name %>.create! valid_attributes
114114
patch <%= show_helper %>,
115115
params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
@@ -120,7 +120,7 @@
120120
end
121121
122122
describe "DELETE /destroy" do
123-
it "destroys the requested <%= ns_file_name %>" do
123+
it "destroys the requested <%= singular_table_name %>" do
124124
<%= file_name %> = <%= class_name %>.create! valid_attributes
125125
expect {
126126
delete <%= show_helper %>, headers: valid_headers, as: :json

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
it { is_expected.not_to contain('params: { admin_post: valid_attributes }') }
118118
it { is_expected.to contain(' Post.create') }
119119
end
120+
121+
describe 'with --model-name & --api' do
122+
before { run_generator %w[admin/posts --api --model-name=post] }
123+
it { is_expected.to contain('params: { post: valid_attributes }') }
124+
it { is_expected.not_to contain('params: { admin_post: valid_attributes }') }
125+
end
120126
end
121127

122128
describe 'namespaced controller spec' do

0 commit comments

Comments
 (0)