From 35aefb8887f1e49d71df4cbab1169fc424b1d833 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Mon, 2 Apr 2012 18:40:25 +0200 Subject: [PATCH] test against 1.9.2 until linecache 0.5.13 is released --- .travis.yml | 2 +- .../contact_forms_controller_spec.rb | 161 ++++++++++++++++++ spec/factories/contact_form_factory.rb | 7 + 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 spec/controllers/contact_forms_controller_spec.rb create mode 100644 spec/factories/contact_form_factory.rb diff --git a/.travis.yml b/.travis.yml index 65d0b76..7e81523 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,2 @@ rvm: -- 1.9.3 +- 1.9.2 diff --git a/spec/controllers/contact_forms_controller_spec.rb b/spec/controllers/contact_forms_controller_spec.rb new file mode 100644 index 0000000..4aa4465 --- /dev/null +++ b/spec/controllers/contact_forms_controller_spec.rb @@ -0,0 +1,161 @@ +require 'spec_helper' + +describe Cmtool::ContactFormsController do + before :each do + sign_in @user + end + + describe 'no user is signed in' do + before :each do + sign_out @user + end + it "should not allow acces when no user is logged in" do + contact_form = create :contact_form + get :index + response.should be_redirect + end + + it "should add a subscription without authentication" do + @request.env['HTTP_REFERER'] = '/' + expect { + post :add, contact_form: {email: "unauthenticated@example.com"} + }.to change(Cmtool::ContactForm, :count).by(1) + end + end + + describe "GET index" do + it "assigns all contact_forms as @contact_forms" do + contact_form = create :contact_form + get :index + assigns(:contact_forms).should eq([contact_form]) + end + end + + describe "GET show" do + it "assigns the requested contact_form as @contact_form" do + contact_form = create :contact_form + get :show, :id => contact_form.id + assigns(:contact_form).should eq(contact_form) + end + end + + describe "GET new" do + it "assigns a new contact_form as @contact_form" do + get :new + assigns(:contact_form).should be_a_new(Cmtool::ContactForm) + end + end + + describe "GET edit" do + it "assigns the requested contact_form as @contact_form" do + contact_form = create :contact_form + get :edit, :id => contact_form.id + assigns(:contact_form).should eq(contact_form) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new Cmtool::ContactForm" do + expect { + post :create, :contact_form => build(:contact_form).attributes + }.to change(Cmtool::ContactForm, :count).by(1) + end + + it "assigns a newly created contact_form as @contact_form" do + post :create, :contact_form => build(:contact_form).attributes + assigns(:contact_form).should be_a(Cmtool::ContactForm) + assigns(:contact_form).should be_persisted + end + + it "redirects to the contact_forms contact_form" do + post :create, :contact_form => build(:contact_form).attributes + response.should redirect_to(Cmtool::ContactForm.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved contact_form as @contact_form" do + # Trigger the behavior that occurs when invalid params are submitted + Cmtool::ContactForm.any_instance.stub(:save).and_return(false) + post :create, :contact_form => {} + assigns(:contact_form).should be_a_new(Cmtool::ContactForm) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + Cmtool::ContactForm.any_instance.stub(:save).and_return(false) + post :create, :contact_form => {} + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested contact_form" do + contact_form = create(:contact_form) + # Assuming there are no other contact_forms in the database, this + # specifies that the Cmtool::ContactForm created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + Cmtool::ContactForm.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, :id => contact_form.id, :contact_form => {'these' => 'params'} + end + + it "assigns the requested contact_form as @contact_form" do + contact_form = create(:contact_form) + put :update, :id => contact_form.id, :contact_form => contact_form.attributes + assigns(:contact_form).should eq(contact_form) + end + + it "redirects to the contact_form" do + contact_form = create(:contact_form) + put :update, :id => contact_form.id, :contact_form => contact_form.attributes + response.should redirect_to(contact_form) + end + end + + describe "with invalid params" do + it "assigns the contact_form as @contact_form" do + contact_form = create(:contact_form) + # Trigger the behavior that occurs when invalid params are submitted + Cmtool::ContactForm.any_instance.stub(:save).and_return(false) + put :update, :id => contact_form.id, :contact_form => {} + assigns(:contact_form).should eq(contact_form) + end + + it "re-renders the 'edit' template" do + contact_form = create(:contact_form) + # Trigger the behavior that occurs when invalid params are submitted + Cmtool::ContactForm.any_instance.stub(:save).and_return(false) + put :update, :id => contact_form.id, :contact_form => {} + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested contact_form" do + @request.env['HTTP_REFERER'] = contact_forms_path + contact_form = create(:contact_form) + expect { + delete :destroy, :id => contact_form.id + }.to change(Cmtool::ContactForm, :count).by(-1) + end + + it "redirects to the contact_forms list" do + @request.env['HTTP_REFERER'] = contact_forms_path + contact_form = create(:contact_form) + delete :destroy, :id => contact_form.id + response.should redirect_to(contact_forms_path) + end + it "redirects to the contact_forms list when called from edit page" do + contact_form = create(:contact_form) + @request.env['HTTP_REFERER'] = edit_contact_form_path(contact_form) + delete :destroy, :id => contact_form.id + response.should redirect_to(contact_forms_path) + end + end + +end diff --git a/spec/factories/contact_form_factory.rb b/spec/factories/contact_form_factory.rb new file mode 100644 index 0000000..9c97145 --- /dev/null +++ b/spec/factories/contact_form_factory.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :contact_form, class: Cmtool::ContactForm do + gender 'male' + email 'contact_form@example.com' + sequence(:created_at){|i| Time.zone.now + i.seconds} # ensure following created at + end +end