forked from hotsh/rstat.us
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes FeedService tests to actually test things.
The original tests stubbed the private methods which means they mostly just tested ruby's precedence order. :) Private methods are forced integrations... we have to allow them to operate in turn in order to assess behavior.
- Loading branch information
Showing
1 changed file
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ | |
let(:target_feed) { "505cc1beb4f2cd000200022c" } | ||
|
||
before do | ||
service.stubs(:find_feed_by_id).returns(existing_feed) | ||
Feed.stubs(:first) | ||
.with(has_entry(:id, target_feed)) | ||
.returns(existing_feed) | ||
end | ||
|
||
it "returns the feed" do | ||
|
@@ -29,12 +31,18 @@ | |
let(:user) { mock } | ||
let(:author) { mock } | ||
let(:feed) { mock } | ||
let(:uri) { mock } | ||
|
||
describe "when the feed exists" do | ||
before do | ||
User.stubs(:find_by_case_insensitive_username).returns(user) | ||
user.stubs(:author).returns(author) | ||
Kernel.stubs(:URI).returns(uri) | ||
uri.stubs(:host).returns("example.com") | ||
author.stubs(:feed).returns(feed) | ||
|
||
service.stubs(:find_feed_by_id).returns(nil) | ||
service.stubs(:find_feed_by_remote_url).returns nil | ||
end | ||
|
||
it "returns the feed" do | ||
|
@@ -45,6 +53,10 @@ | |
describe "when the feed does not exist" do | ||
before do | ||
User.stubs(:find_by_case_insensitive_username).returns(nil) | ||
Kernel.stubs(:URI).returns(uri) | ||
uri.stubs(:host).returns("example.com") | ||
|
||
service.stubs(:find_feed_by_id).returns(nil) | ||
service.stubs(:find_feed_by_remote_url).returns(existing_feed) | ||
end | ||
|
||
|
@@ -57,11 +69,19 @@ | |
describe "when the feed can by found by remote URL" do | ||
# the remote URL of user '[email protected]' (follow me!) | ||
let(:target_feed) { "https://rstat.us/feeds/505cc1beb4f2cd000200022c.atom" } | ||
let(:feed_data_cov) { mock } | ||
let(:feed_data) { mock } | ||
|
||
before do | ||
Feed.stubs(:first) | ||
.with(has_entry(:remote_url, "feed_url")) | ||
.returns(existing_feed) | ||
SubscriberToFeedDataConverter.stubs(:new).returns(feed_data_cov) | ||
feed_data_cov.stubs(:get_feed_data!).returns(feed_data) | ||
feed_data.stubs(:url).returns("feed_url") | ||
|
||
service.stubs(:find_feed_by_id).returns nil | ||
service.stubs(:find_feed_by_username).returns nil | ||
service.stubs(:find_feed_by_remote_url).returns(existing_feed) | ||
end | ||
|
||
it "returns the feed" do | ||
|
@@ -71,15 +91,21 @@ | |
|
||
describe "when the feed doesn't exist" do | ||
let(:target_feed) { "[email protected]" } # (follow me!) | ||
let(:feed_data_cov) { mock } | ||
let(:feed_data) { mock } | ||
|
||
before do | ||
service.stubs(:find_feed_by_id).returns nil | ||
service.stubs(:find_feed_by_username).returns nil | ||
service.stubs(:find_feed_by_remote_url).returns nil | ||
service.stubs(:create_feed_from_feed_data).returns(new_feed) | ||
SubscriberToFeedDataConverter.stubs(:new).returns(feed_data_cov) | ||
feed_data_cov.stubs(:get_feed_data!).returns(feed_data) | ||
end | ||
|
||
it "creates the feed" do | ||
Feed.expects(:create_and_populate!) | ||
.with(feed_data) | ||
.returns(new_feed) | ||
service.find_or_create!.must_equal new_feed | ||
end | ||
end | ||
|