Repository navigation
Expand file tree
/
Copy pathfeeds_controller_spec.rb
More file actions
128 lines (94 loc) · 3.49 KB
/
Copy pathfeeds_controller_spec.rb
File metadata and controls
128 lines (94 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require "spec_helper"
app_require "controllers/feeds_controller"
describe "FeedsController" do
let(:feeds) { [FeedFactory.build, FeedFactory.build] }
describe "GET /feeds" do
it "renders a list of feeds" do
FeedRepository.should_receive(:list).and_return(feeds)
get "/feeds"
page = last_response.body
page.should have_tag("ul#feed-list")
page.should have_tag("li.feed", count: 2)
end
it "displays message to add feeds if there are none" do
FeedRepository.should_receive(:list).and_return([])
get "/feeds"
page = last_response.body
page.should have_tag("#add-some-feeds")
end
end
describe "DELETE /feeds/:feed_id" do
it "deletes a feed given the id" do
FeedRepository.should_receive(:delete).with("123")
delete "/feeds/123"
end
end
describe "GET /feeds/new" do
it "displays a form and submit button" do
get "/feeds/new"
page = last_response.body
page.should have_tag("form#add-feed-setup")
page.should have_tag("input#submit")
end
end
describe "POST /feeds" do
context "when the feed url is valid" do
let(:feed_url) { "http://example.com/" }
let(:valid_feed) { double(valid?: true) }
it "adds the feed and queues it to be fetched" do
AddNewFeed.should_receive(:add).with(feed_url).and_return(valid_feed)
FetchFeeds.should_receive(:enqueue).with([valid_feed])
post "/feeds", feed_url: feed_url
last_response.status.should be 302
URI::parse(last_response.location).path.should eq "/"
end
end
context "when the feed url is invalid" do
let(:feed_url) { "http://not-a-valid-feed.com/" }
it "adds the feed and queues it to be fetched" do
AddNewFeed.should_receive(:add).with(feed_url).and_return(false)
post "/feeds", feed_url: feed_url
page = last_response.body
page.should have_tag(".error")
end
end
context "when the feed url is one we already subscribe to" do
let(:feed_url) { "http://example.com/" }
let(:invalid_feed) { double(valid?: false) }
it "adds the feed and queues it to be fetched" do
AddNewFeed.should_receive(:add).with(feed_url).and_return(invalid_feed)
post "/feeds", feed_url: feed_url
page = last_response.body
page.should have_tag(".error")
end
end
end
describe "GET /feeds/import" do
it "displays the import options" do
get "/feeds/import"
page = last_response.body
page.should have_tag("input#opml_file")
page.should have_tag("a#skip")
end
end
describe "POST /feeds/import" do
let(:opml_file) { Rack::Test::UploadedFile.new("spec/sample_data/subscriptions.xml", "application/xml") }
it "parse OPML and starts fetching" do
ImportFromOpml.should_receive(:import).once
post "/feeds/import", {"opml_file" => opml_file}
last_response.status.should be 302
URI::parse(last_response.location).path.should eq "/setup/tutorial"
end
end
describe "GET /feeds/export" do
let(:some_xml) { "<xml>some dummy opml</xml>"}
before { Feed.stub(:all) }
it "returns an OPML file" do
ExportToOpml.any_instance.should_receive(:to_xml).and_return(some_xml)
get "/feeds/export"
last_response.body.should eq some_xml
last_response.header["Content-Type"].should include 'application/xml'
last_response.header["Content-Disposition"].should == "attachment; filename=\"stringer.opml\""
end
end
end