Skip to content

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

Closed
@PedroAugustoRamalhoDuarte

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions