mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
Add contacts controller spec.
This commit is contained in:
parent
1c44d54b51
commit
dba2f5d74a
31
spec/controllers/contacts_controller_spec.rb
Normal file
31
spec/controllers/contacts_controller_spec.rb
Normal file
@ -0,0 +1,31 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ContactsController do
|
||||
describe "GET new" do
|
||||
it "renders the contact form" do
|
||||
get :new
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
end
|
||||
|
||||
let(:contact_params) do
|
||||
{ name: "Dan Barber",
|
||||
email: "danbee@gmail.com",
|
||||
message: "This is a message." }
|
||||
end
|
||||
|
||||
describe "POST create" do
|
||||
it "saves a new contact" do
|
||||
Contact.any_instance.should_receive(:save).once.and_return(true)
|
||||
post :create, contact: contact_params
|
||||
expect(flash[:notice]).to eql(I18n.t("contact.thanks"))
|
||||
expect(response).to redirect_to(:new_contact)
|
||||
end
|
||||
|
||||
it "re-renders the form if params are missing" do
|
||||
post :create, contact: {}
|
||||
expect(flash[:alert]).to eql(I18n.t("contact.invalid"))
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user