fd477916a9dfd299536f8518d6758afbcaf76c5a
[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, feed_name: "test_feed", title: "item 1") }
35 let!(:feed_item2) { FactoryGirl.create(:feed_item, feed_name: "test_feed", title: "item 2") }
36
37 it "redirects an emtpy feed to the index" do
38 get :show, feed_name: "empty_feed"
39 expect(response).to redirect_to(index_path)
40 end
41
42 it "responds successfully with an HTTP 200 status code" do
43 get :show, feed_name: "test_feed"
44 expect(response).to be_success
45 expect(response.status).to eq(200)
46 end
47
48 it "renders the index template" do
49 get :show, feed_name: "test_feed"
50 expect(response).to render_template("show")
51 end
52
53 it "loads all of the items of a feed into @feed_items" do
54 get :show, feed_name: "test_feed"
55 expect(assigns(:feed_items)).to match_array([feed_item1, feed_item2])
56 end
57 end
58
59
60 end
61
62
63 # describe MessagesController do
64 # describe "POST create" do
65 # let(:message) { mock_model(Message).as_null_object }
66 # before do
67 # Message.stub(:new).and_return(message)
68 # end
69 # it "creates a new message" do
70 # Message.should_receive(:new).
71 # with("text" => "a quick brown fox").
72 # and_return(message)
73 # post :create, :message => { "text" => "a quick brown fox" }
74 # end
75 # it "saves the message" do
76 # message.should_receive(:save)
77 # post :create
78 # end
79 # it "redirects to the Messages index" do
80 # post :create
81 # response.should redirect_to(:action => "index")
82 # end
83 # end
84 # end
85 #