Skip to content

Wrong variable name when generate requests specs with scaffold and namespace models #2491

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

Closed
PedroAugustoRamalhoDuarte opened this issue Apr 11, 2021 · 0 comments · Fixed by #2492

Comments

@PedroAugustoRamalhoDuarte
Copy link
Contributor

What Ruby, Rails and RSpec versions are you using?

Ruby version: 2.7.2
Rails version: 6.1.3.1
RSpec-core version: 3.10.1
Rspec-rails version: 5.0.1
Rails API

Observed behaviour

When is generated a namespace model with scaffold

rails g scaffold accounts/user name:string

The generator creates wrong variable in request url , example:

describe "GET /show" do
   it "renders a successful response" do
     user = Accounts::User.create! valid_attributes
     get accounts_user_url(accounts_user), as: :json
     expect(response).to be_successful
   end
 end

Expected behaviour

Same variable name when create spec data and request url

OPTION 1

describe "GET /show" do
   it "renders a successful response" do
     user = Accounts::User.create! valid_attributes
     get accounts_user_url(user), as: :json
     expect(response).to be_successful
   end
 end

or

OPTION 2

describe "GET /show" do
   it "renders a successful response" do
     accounts_user = Accounts::User.create! valid_attributes
     get accounts_user_url(accounts_user), as: :json
     expect(response).to be_successful
   end
 end

Solution

The main problem is the method show_helper uses table_names to build request url, while the spec variable data uses file_name
I recon the first option is better to keep the pattern of another templates and i would like to create a PR to this fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant