Update request spec done
authorNeil Smith <neil.git@njae.me.uk>
Mon, 6 Jan 2014 16:17:06 +0000 (16:17 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Mon, 6 Jan 2014 16:17:06 +0000 (16:17 +0000)
spec/controllers/feed_controller_spec.rb
spec/factories.rb
spec/requests/update_spec.rb [new file with mode: 0644]
spec/spec_helper.rb

index fd533ba2ebca8c60efd997fafabc4840597efce9..8c065036f09830786c002b5f6027c1a752b94c57 100644 (file)
@@ -1,14 +1,6 @@
 require 'spec_helper'
 
-describe FeedController do
-#   describe "POST create" do
-#     let (:feed_item1) { mock_model(FeedItem).as_null_object }
-#     
-#     before do
-#       FeedItem.stub(:new).and_return(feed_item)
-#     end
-#   end
-    
+describe FeedController do    
   describe "GET #index" do
     let!(:feed_item1) { FactoryGirl.create(:feed_item, feed_name: "feed1") }
     let!(:feed_item2) { FactoryGirl.create(:feed_item, feed_name: "feed2") }
@@ -69,36 +61,8 @@ describe FeedController do
     
     it "redirects an update the feed path" do
       post :update, FactoryGirl.attributes_for(:feed_item, 
-                       title: "item 1", description: "New description")
+                title: "item 1", description: "New description")
       expect(response).to redirect_to(feed_path("test_feed"))
     end
-    
   end
-  
-  
 end
-
-
-# describe MessagesController do
-# describe "POST create" do
-# let(:message) { mock_model(Message).as_null_object }
-# before do
-# Message.stub(:new).and_return(message)
-# end
-# it "creates a new message" do
-# Message.should_receive(:new).
-# with("text" => "a quick brown fox").
-# and_return(message)
-# post :create, :message => { "text" => "a quick brown fox" }
-# end
-# it "saves the message" do
-# message.should_receive(:save)
-# post :create
-# end
-# it "redirects to the Messages index" do
-# post :create
-# response.should redirect_to(:action => "index")
-# end
-# end
-# end
-# 
index a94df2cfcd5772626fce4e95af629177fb00228f..c7ebae6829f14b15dc130a276e0ec687f8f5e074 100644 (file)
@@ -5,4 +5,4 @@ FactoryGirl.define do
     title "Test feed item"
     description "Test feed description"
   end
-end
\ No newline at end of file
+end
diff --git a/spec/requests/update_spec.rb b/spec/requests/update_spec.rb
new file mode 100644 (file)
index 0000000..bfe8647
--- /dev/null
@@ -0,0 +1,58 @@
+require 'spec_helper'
+
+describe "update" do
+  let!(:feed_item1) { FactoryGirl.create(:feed_item, 
+      title: "item 1") }
+  let!(:feed_item2) { FactoryGirl.create(:feed_item, 
+      title: "item 2") }
+  let!(:other_feed_item) { FactoryGirl.create(:feed_item, 
+      feed_name: "other_test_feed") }
+
+  it "changes the description of an existing item" do
+    post_via_redirect '', 
+      FactoryGirl.attributes_for(:feed_item, 
+              title: "item 1", description: "New description")
+    expect(assigns(:feed_items).map{|f| f.description}).to include("New description")
+    expect(assigns(:feed_items).length).to eq(2)
+    get '/index'
+    expect(assigns(:feeds).length).to eq(2)
+  end
+  
+  it "adds the item when inserting a new title into an existing feed" do
+    post_via_redirect '', 
+      FactoryGirl.attributes_for(:feed_item, title: "item 99", 
+                                 description: "New description")
+    expect(assigns(:feed_items).map{|f| f.description}).to include("New description")
+    expect(assigns(:feed_items).length).to eq(3)
+    get '/index'
+    expect(assigns(:feeds).length).to eq(2)
+  end
+    
+  it "adds a new feed when inserting a new item into a new feed" do
+    post_via_redirect '', 
+      FactoryGirl.attributes_for(:feed_item, feed_name: "new_feed")
+    expect(assigns(:feed_items).length).to eq(1)
+    expect(assigns(:feed_items)[0].feed_name).to eq("new_feed")
+    get '/index'
+    expect(assigns(:feeds).length).to eq(3)
+  end
+    
+  it "removes the item when updated with a blank description" do
+    post_via_redirect '', 
+      FactoryGirl.attributes_for(:feed_item, title: "item 1", 
+                                 description: "")
+    expect(assigns(:feed_items).map{|f| f.title}).not_to include("item 1")
+    expect(assigns(:feed_items).length).to eq(1)
+    get '/index'
+    expect(assigns(:feeds).length).to eq(2)
+  end
+    
+  it "removes the feed when deleting the last item from a feed" do
+    post_via_redirect '', 
+      FactoryGirl.attributes_for(:feed_item, feed_name: "other_test_feed",
+                                 description: "")
+    get '/index'
+    expect(assigns(:feeds).length).to eq(1)
+  end
+end
+
index 943bc1919035458c29f95f3b14522784e44e5d10..a5970b7089b61128dc3ed3316a66d94857b54162 100644 (file)
@@ -3,7 +3,8 @@ ENV["RAILS_ENV"] ||= 'test'
 require File.expand_path("../../config/environment", __FILE__)
 require 'rspec/rails'
 require 'rspec/autorun'
-
+require 'capybara/rspec'
+  
 # Requires supporting ruby files with custom matchers and macros, etc,
 # in spec/support/ and its subdirectories.
 Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }