Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make sure the specs for the tease_controller do not actually use impl…

…ementation of the annoyance meter
  • Loading branch information...
commit a433775a2760a10252920044dd55d66c4c22f863 1 parent 7c18f65
@shageman authored
View
2  build.sh
@@ -14,7 +14,7 @@ rspec spec/models spec/controllers
result+=$?
echo "*** Running teaser engine request specs"
-rspec spec/reqests
+rspec spec/requests
result+=$?
echo "*** Running teaser engine javascript specs"
View
11 engines/teaser/app/controllers/teaser/tease_controller.rb
@@ -1,11 +1,12 @@
module Teaser
class TeaseController < Teaser::ApplicationController
+
+ before_filter :inject_dependencies, only: [:create]
+
def new
end
def create
- @annoyance_meter = Annoyance::Meter.new(20)
-
email = params[:new_sign_up_entry].presence
render text: "Hey! Please call this right... I need a new signUp entry!", status: 400 and return unless email
@@ -20,5 +21,11 @@ def create
render text: "Hm... something went seriously wrong.", status: 500
end
end
+
+ private
+
+ def inject_dependencies
+ @annoyance_meter = Annoyance::Meter.new(20)
+ end
end
end
View
17 engines/teaser/spec/controllers/tease_controller_spec.rb
@@ -2,6 +2,10 @@
module Teaser
describe TeaseController do
+ before do
+ controller.stub(:inject_dependencies)
+ end
+
describe "GET new" do
it "should not fail" do
expect {
@@ -11,6 +15,12 @@ module Teaser
end
describe "POST create" do
+ it "should use the annoyance meter set to 20" do
+ controller.unstub(:inject_dependencies)
+ Annoyance::Meter.should_receive(:new).with(20)
+ xhr :post, :create, use_route: "teaser"
+ end
+
it "should fail if no new_sign_up_entry parameter is given" do
xhr :post, :create, use_route: "teaser"
response.status.should == 400
@@ -21,12 +31,15 @@ module Teaser
response.body.should == "Hey! Please call this right... I need a new signUp entry!"
end
- it "should fail if the value given in the new_sign_up_entry parameter already exists in the database" do
+ it "should fail if the given new_sign_up_entry already exists (and use the annoyance meter)" do
+ mock_annoyance_meter = mock("annoyance_meter", annoyance_adjusted: "Oh I am annoyed...")
+ controller.instance_variable_set "@annoyance_meter", mock_annoyance_meter
+
entry = Teaser::Entry.create!(email: "adam", tries: 0)
xhr :post, :create, new_sign_up_entry: "adam", use_route: "teaser"
response.status.should == 400
- response.body.should == "Hm... Did you already sign up?Huh?"
+ response.body.should == "Oh I am annoyed..."
entry.reload.tries.should == 1
end
Please sign in to comment.
Something went wrong with that request. Please try again.