Skip to content

Fix routing spec scaffold format #1929

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

Merged
merged 2 commits into from
Dec 19, 2017
Merged

Fix routing spec scaffold format #1929

merged 2 commits into from
Dec 19, 2017

Conversation

nikolalsvk
Copy link
Contributor

@nikolalsvk nikolalsvk commented Dec 18, 2017

When I scaffold an User model in Rails 5 API application, I get this in spec/routing/users_routing_spec.rb:

require "rails_helper"

RSpec.describe UsersController, type: :routing do
  describe "routing" do

    it "routes to #index" do
      expect(:get => "/users").to route_to("users#index")
    end


    it "routes to #show" do
      expect(:get => "/users/1").to route_to("users#show", :id => "1")
    end


    it "routes to #create" do
      expect(:post => "/users").to route_to("users#create")
    end

    it "routes to #update via PUT" do
      expect(:put => "/users/1").to route_to("users#update", :id => "1")
    end

    it "routes to #update via PATCH" do
      expect(:patch => "/users/1").to route_to("users#update", :id => "1")
    end

    it "routes to #destroy" do
      expect(:delete => "/users/1").to route_to("users#destroy", :id => "1")
    end

  end
end

Preferably, it should look like this:

require "rails_helper"

RSpec.describe UsersController, type: :routing do
  describe "routing" do
    it "routes to #index" do
      expect(:get => "/users").to route_to("users#index")
    end

    it "routes to #show" do
      expect(:get => "/users/1").to route_to("users#show", :id => "1")
    end

    it "routes to #create" do
      expect(:post => "/users").to route_to("users#create")
    end

    it "routes to #update via PUT" do
      expect(:put => "/users/1").to route_to("users#update", :id => "1")
    end

    it "routes to #update via PATCH" do
      expect(:patch => "/users/1").to route_to("users#update", :id => "1")
    end

    it "routes to #destroy" do
      expect(:delete => "/users/1").to route_to("users#destroy", :id => "1")
    end
  end
end

This PR aims to solve this issue.

@JonRowe JonRowe merged commit 399a740 into rspec:master Dec 19, 2017
@JonRowe
Copy link
Member

JonRowe commented Dec 19, 2017

Thanks ❤️

@nikolalsvk nikolalsvk deleted the patch-1 branch December 19, 2017 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants