From dba2f5d74a0b7a238d8dd95d69375ade2e94acf1 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sun, 2 Jun 2013 22:19:03 +0100 Subject: [PATCH] Add contacts controller spec. --- spec/controllers/contacts_controller_spec.rb | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 spec/controllers/contacts_controller_spec.rb diff --git a/spec/controllers/contacts_controller_spec.rb b/spec/controllers/contacts_controller_spec.rb new file mode 100644 index 0000000..505ce52 --- /dev/null +++ b/spec/controllers/contacts_controller_spec.rb @@ -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