forked from railsbump/app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add controller spec to check post :create
- Loading branch information
1 parent
c189deb
commit a503ac3
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe GemmiesController, type: :controller do | ||
describe "create" do | ||
context "when the gemmy params are valid" do | ||
it "redirects to the new gemmy page" do | ||
post :create, params: { gemmy: { name: "next_rails" } } | ||
|
||
expect(response).to redirect_to(gemmy_path(Gemmy.find_by(name: "next_rails"))) | ||
end | ||
|
||
it "creates a record in the database" do | ||
expect do | ||
post :create, params: { gemmy: { name: "next_rails" } } | ||
end.to change(Gemmy, :count).by(1) | ||
end | ||
|
||
context "when the gemmy params are invalid" do | ||
it "renders the new gemmy page" do | ||
post :create, params: { gemmy: { name: "" } } | ||
|
||
expect(response).to render_template(:new) | ||
end | ||
|
||
it "does not create a record in the database" do | ||
expect do | ||
post :create, params: { gemmy: { name: "" } } | ||
end.not_to change(Gemmy, :count) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters