9481d3a2413e3ea62c7619455f961b226fb837b0
[feedcatcher.git] / spec / requests / format_spec.rb
1 require 'spec_helper'
2
3 describe "format" do
4 let!(:feed_item1) { FactoryGirl.create(:feed_item,
5 title: "item 1") }
6 let!(:feed_item2) { FactoryGirl.create(:feed_item,
7 title: "item 2") }
8 let!(:other_feed_item) { FactoryGirl.create(:feed_item,
9 feed_name: "other_test_feed") }
10
11 it "changes the description of an existing item" do
12 post_via_redirect '',
13 FactoryGirl.attributes_for(:feed_item,
14 title: "item 1", description: "New description")
15 expect(assigns(:feed_items).map{|f| f.description}).to include("New description")
16 expect(assigns(:feed_items).length).to eq(2)
17 get '/index'
18 expect(assigns(:feeds).length).to eq(2)
19 end
20
21 it "adds the item when inserting a new title into an existing feed" do
22 post_via_redirect '',
23 FactoryGirl.attributes_for(:feed_item, title: "item 99",
24 description: "New description")
25 expect(assigns(:feed_items).map{|f| f.description}).to include("New description")
26 expect(assigns(:feed_items).length).to eq(3)
27 get '/index'
28 expect(assigns(:feeds).length).to eq(2)
29 end
30
31 it "adds a new feed when inserting a new item into a new feed" do
32 post_via_redirect '',
33 FactoryGirl.attributes_for(:feed_item, feed_name: "new_feed")
34 expect(assigns(:feed_items).length).to eq(1)
35 expect(assigns(:feed_items)[0].feed_name).to eq("new_feed")
36 get '/index'
37 expect(assigns(:feeds).length).to eq(3)
38 end
39
40 it "removes the item when updated with a blank description" do
41 post_via_redirect '',
42 FactoryGirl.attributes_for(:feed_item, title: "item 1",
43 description: "")
44 expect(assigns(:feed_items).map{|f| f.title}).not_to include("item 1")
45 expect(assigns(:feed_items).length).to eq(1)
46 get '/index'
47 expect(assigns(:feeds).length).to eq(2)
48 end
49
50 it "removes the feed when deleting the last item from a feed" do
51 post_via_redirect '',
52 FactoryGirl.attributes_for(:feed_item, feed_name: "other_test_feed",
53 description: "")
54 get '/index'
55 expect(assigns(:feeds).length).to eq(1)
56 end
57 end
58