Commit db4b657c

mo khan <mo@mokhan.ca>
2014-05-31 03:36:08
add specs to ensure tweets are not blasted for naughty or un published cakes.
1 parent f58764e
Changed files (1)
spec
spec/services/handlers/publish_cake_to_twitter_spec.rb
@@ -13,17 +13,20 @@ describe PublishCakeToTwitter do
   end
 
   describe "#handle" do
-    context "when the cake is published and safe for kids" do
-      let(:artist) { User.new(name: 'joe') }
-      let(:cake) { Creation.new(id: id, name: 'yummy') }
-      let(:id) { 88 }
+    let(:artist) { User.new(name: 'joe') }
+    let(:cake) { Creation.new(id: id, name: 'yummy') }
+    let(:id) { 88 }
+
+    before :each do
+      Rails.application.routes.default_url_options[:host]= 'localhost:3000' 
+      cake.stub(:user).and_return(artist)
+      cakes.stub(:find).with(id).and_return(cake)
+    end
 
+    context "when the cake is published and safe for kids" do
       before :each do
-        Rails.application.routes.default_url_options[:host]= 'localhost:3000' 
         cake.stub(:is_safe_for_children?).and_return(true)
         cake.stub(:published?).and_return(true)
-        cake.stub(:user).and_return(artist)
-        cakes.stub(:find).with(id).and_return(cake)
       end
 
       it "tweets new cakes" do
@@ -31,5 +34,29 @@ describe PublishCakeToTwitter do
         twitter.should have_received(:tweet).with("yummy By joe on http://localhost:3000/creations/88-yummy!")
       end
     end
+
+    context "when the cake is not published" do
+      before :each do
+        cake.stub(:is_safe_for_children?).and_return(true)
+        cake.stub(:published?).and_return(false)
+      end
+
+      it "should not publish any tweets" do
+        subject.handle(cake_id: id)
+        twitter.should_not have_received(:tweet)
+      end
+    end
+
+    context "when the cake is not safe for children" do
+      before :each do
+        cake.stub(:is_safe_for_children?).and_return(false)
+        cake.stub(:published?).and_return(true)
+      end
+
+      it "should not publish any tweets" do
+        subject.handle(cake_id: id)
+        twitter.should_not have_received(:tweet)
+      end
+    end
   end
 end