summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-07-22 12:22:16 -0600
committermo khan <mo@mokhan.ca>2013-07-22 12:22:16 -0600
commit5f2c811651ad7c64062c8a9e335a4449c9f62742 (patch)
treeb80197946a13ad4bed83c4c65bff59c2b44d9a75
parentb9e4d5e279cafef2b6d34984aa28b23da27b82b4 (diff)
add spec to ensure a new signup is subscribed to the mailing list after creation
-rw-r--r--app/controllers/sign_ups_controller.rb1
-rw-r--r--spec/controllers/sign_ups_controller_spec.rb34
2 files changed, 15 insertions, 20 deletions
diff --git a/app/controllers/sign_ups_controller.rb b/app/controllers/sign_ups_controller.rb
index fd053f9..06a0719 100644
--- a/app/controllers/sign_ups_controller.rb
+++ b/app/controllers/sign_ups_controller.rb
@@ -7,6 +7,7 @@ class SignUpsController < ApplicationController
@sign_up = SignUp.create(sign_up_params)
if @sign_up.save
+ @sign_up.subscribe
redirect_to @sign_up
else
render action: "new"
diff --git a/spec/controllers/sign_ups_controller_spec.rb b/spec/controllers/sign_ups_controller_spec.rb
index a8a778e..88341f4 100644
--- a/spec/controllers/sign_ups_controller_spec.rb
+++ b/spec/controllers/sign_ups_controller_spec.rb
@@ -1,22 +1,9 @@
require "spec_helper"
describe SignUpsController do
-
- def valid_attributes
- { sign_up: { email: "customer@example.com" } }
- end
-
- def invalid_attributes
- { sign_up: { email: "invalidemailaddress" } }
- end
-
- def valid_session
- {}
- end
-
describe "GET new" do
it "should show signup form" do
- get :new, {}, valid_session
+ get :new
assigns(:sign_up).should be_a_new(SignUp)
end
end
@@ -24,16 +11,23 @@ describe SignUpsController do
describe "POST create" do
describe "with valid params" do
it "creates a new SignUp" do
- expect {
- post :create, valid_attributes, valid_session
- }.to change(SignUp, :count).by(1)
+ SignUp.any_instance.should_receive(:subscribe)
+ post :create, { sign_up: { email: "customer@example.com" } }
+ SignUp.count.should == 1
end
end
+
describe "with invalid params" do
+ before :each do
+ post :create, { sign_up: { email: "invalidemailaddress" } }
+ end
+
it "goes back to the sign up form with errors" do
- expect {
- post :create, invalid_attributes, valid_session
- }.not_to change(SignUp, :count)
+ SignUp.count.should == 0
+ end
+
+ it "should display errors" do
+ assigns(:sign_up).errors.count.should > 0
end
end
end