Skip to content

Commit

Permalink
Merge pull request #2799 from i7an/main
Browse files Browse the repository at this point in the history
Improve consistency with official controller spec style
  • Loading branch information
pirj authored Sep 9, 2024
2 parents c7d4200 + 8a654c5 commit 46726b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
19 changes: 12 additions & 7 deletions features/matchers/redirect_to_matcher.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,30 @@ Feature: `redirect_to` matcher
require "rails_helper"
RSpec.describe WidgetsController do
describe "#create" do
subject { post :create, :params => { :widget => { :name => "Foo" } } }
it "redirects to widget_url(@widget)" do
expect(subject).to redirect_to(widget_url(assigns(:widget)))
post :create, :params => { :widget => { :name => "Foo" } }
expect(response).to redirect_to(widget_url(assigns(:widget)))
end
it "redirects_to :action => :show" do
expect(subject).to redirect_to :action => :show,
post :create, :params => { :widget => { :name => "Foo" } }
expect(response).to redirect_to :action => :show,
:id => assigns(:widget).id
end
it "redirects_to(@widget)" do
expect(subject).to redirect_to(assigns(:widget))
post :create, :params => { :widget => { :name => "Foo" } }
expect(response).to redirect_to(assigns(:widget))
end
it "redirects_to /widgets/:id" do
expect(subject).to redirect_to("/widgets/#{assigns(:widget).id}")
post :create, :params => { :widget => { :name => "Foo" } }
expect(response).to redirect_to("/widgets/#{assigns(:widget).id}")
end
end
end
Expand Down
24 changes: 14 additions & 10 deletions features/matchers/render_template_matcher.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ Feature: `render_template` matcher
RSpec.describe GadgetsController do
describe "GET #index" do
subject { get :index }
it "renders the index template" do
expect(subject).to render_template(:index)
expect(subject).to render_template("index")
expect(subject).to render_template("gadgets/index")
get :index
expect(response).to render_template(:index)
expect(response).to render_template("index")
expect(response).to render_template("gadgets/index")
end
it "does not render a different template" do
expect(subject).to_not render_template("gadgets/show")
get :index
expect(response).to_not render_template("gadgets/show")
end
end
end
Expand All @@ -40,14 +42,16 @@ Feature: `render_template` matcher
RSpec.describe GadgetsController do
describe "GET #index" do
subject { get :index }
it "renders the application layout" do
expect(subject).to render_template("layouts/application")
get :index
expect(response).to render_template("layouts/application")
end
it "does not render a different layout" do
expect(subject).to_not render_template("layouts/admin")
get :index
expect(response).to_not render_template("layouts/admin")
end
end
end
Expand Down

0 comments on commit 46726b8

Please sign in to comment.