Controller testing done
[feedcatcher.git] / spec / controllers / feed_controller_spec.rb
1 require 'spec_helper'
2
3 describe FeedController do
4 # describe "POST create" do
5 # let (:feed_item1) { mock_model(FeedItem).as_null_object }
6 #
7 # before do
8 # FeedItem.stub(:new).and_return(feed_item)
9 # end
10 # end
11
12 describe "GET #index" do
13 let!(:feed_item1) { FactoryGirl.create(:feed_item, feed_name: "feed1") }
14 let!(:feed_item2) { FactoryGirl.create(:feed_item, feed_name: "feed2") }
15
16 it "responds successfully with an HTTP 200 status code" do
17 get :index
18 expect(response).to be_success
19 expect(response.status).to eq(200)
20 end
21
22 it "renders the index template" do
23 get :index
24 expect(response).to render_template("index")
25 end
26
27 it "loads all the feed names into @feeds" do
28 get :index
29 expect(assigns(:feeds).map {|f| f.feed_name}).to match_array(["feed1", "feed2"])
30 end
31 end
32
33 describe "GET #feed" do
34 let!(:feed_item1) { FactoryGirl.create(:feed_item,
35 feed_name: "test_feed", title: "item 1") }
36 let!(:feed_item2) { FactoryGirl.create(:feed_item,
37 feed_name: "test_feed", title: "item 2") }
38
39 it "redirects an emtpy feed to the index" do
40 get :show, feed_name: "empty_feed"
41 expect(response).to redirect_to(index_path)
42 end
43
44 it "responds successfully with an HTTP 200 status code" do
45 get :show, feed_name: "test_feed"
46 expect(response).to be_success
47 expect(response.status).to eq(200)
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
76 end
77
78
79 end
80
81
82 # describe MessagesController do
83 # describe "POST create" do
84 # let(:message) { mock_model(Message).as_null_object }
85 # before do
86 # Message.stub(:new).and_return(message)
87 # end
88 # it "creates a new message" do
89 # Message.should_receive(:new).
90 # with("text" => "a quick brown fox").
91 # and_return(message)
92 # post :create, :message => { "text" => "a quick brown fox" }
93 # end
94 # it "saves the message" do
95 # message.should_receive(:save)
96 # post :create
97 # end
98 # it "redirects to the Messages index" do
99 # post :create
100 # response.should redirect_to(:action => "index")
101 # end
102 # end
103 # end
104 #