More tinkering with feed controller spec
[feedcatcher.git] / spec / controllers / feed_controller_spec.rb
1 require 'spec_helper'
2
3 describe FeedController do
4 describe "GET #index" do
5 let!(:feed_item1) { FactoryGirl.create(:feed_item, feed_name: "feed1") }
6 let!(:feed_item2) { FactoryGirl.create(:feed_item, feed_name: "feed2") }
7
8 it "responds successfully with an HTTP 200 status code" do
9 get :index
10 expect(response).to be_success
11 end
12
13 it "renders the index template" do
14 get :index
15 expect(response).to render_template("index")
16 end
17
18 it "loads all the feed names into @feeds" do
19 get :index
20 expect(assigns(:feeds).map {|f| f.feed_name}).to match_array(["feed1", "feed2"])
21 end
22 end
23
24 describe "GET #feed" do
25 let!(:feed_item1) { FactoryGirl.create(:feed_item,
26 feed_name: "test_feed", title: "item 1") }
27 let!(:feed_item2) { FactoryGirl.create(:feed_item,
28 feed_name: "test_feed", title: "item 2") }
29
30 it "redirects an emtpy html feed to the index" do
31 get :show, feed_name: "empty_feed"
32 expect(response).to redirect_to(index_path)
33 end
34
35 it "does not redirect an emtpy rss document for an empty feed" do
36 get :show, feed_name: "empty_feed", format: "rss"
37 expect(response).to be_success
38 end
39
40 it "returns an emtpy rss document for an empty feed" do
41 get :show, feed_name: "empty_feed", format: "rss"
42 expect(assigns(:feed_items)).to be_empty
43 end
44
45 it "responds successfully with an HTTP 200 status code" do
46 get :show, feed_name: "test_feed"
47 expect(response).to be_success
48 end
49
50 it "renders the index template" do
51 get :show, feed_name: "test_feed"
52 expect(response).to render_template("show")
53 end
54
55 it "loads all of the items of a feed into @feed_items" do
56 get :show, feed_name: "test_feed"
57 expect(assigns(:feed_items)).to match_array([feed_item1, feed_item2])
58 end
59 end
60
61
62 describe "POST #feed" do
63 let!(:feed_item1) { FactoryGirl.create(:feed_item,
64 title: "item 1") }
65 let!(:feed_item2) { FactoryGirl.create(:feed_item,
66 title: "item 2") }
67 let!(:other_feed_item) { FactoryGirl.create(:feed_item,
68 feed_name: "other_test_feed", title: "item") }
69
70 it "redirects an update the feed path" do
71 post :update, FactoryGirl.attributes_for(:feed_item,
72 title: "item 1", description: "New description")
73 expect(response).to redirect_to(feed_path("test_feed"))
74 end
75 end
76 end