Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/repositories/feed_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def self.set_status(status, feed)
end

def self.list
Feed.order("lower(name)")
Feed.order(Feed.arel_table[:name].lower)
end

def self.in_group
Feed.where("group_id IS NOT NULL")
Feed.where.not(group_id: nil)
end

def self.valid_timestamp?(new_timestamp, current_timestamp)
Expand Down
91 changes: 76 additions & 15 deletions spec/repositories/feed_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,49 @@
app_require "repositories/feed_repository"

describe FeedRepository do
describe ".fetch" do
let(:feed) { Feed.new(id: 1) }

it "finds by id" do
expect(Feed).to receive(:find).with(feed.id).and_return(feed)
FeedRepository.fetch(feed.id)
end

it "returns found feed" do
allow(Feed).to receive(:find).with(feed.id).and_return(feed)

result = FeedRepository.fetch(feed.id)

expect(result).to eq feed
end
end

describe ".fetch_by_ids" do
it "finds all feeds by id" do
feeds = [create_feed, create_feed]

expect(FeedRepository.fetch_by_ids(feeds.map(&:id))).to match_array(feeds)
end

it "does not find other feeds" do
feed1 = create_feed
create_feed

expect(FeedRepository.fetch_by_ids(feed1.id)).to eq([feed1])
end
end

describe ".update_feed" do
it "saves the name and url" do
feed = Feed.new

FeedRepository.update_feed(feed, "Test Feed", "example.com/feed")

expect(feed.name).to eq "Test Feed"
expect(feed.url).to eq "example.com/feed"
end
end

describe ".update_last_fetched" do
let(:timestamp) { Time.now }

Expand Down Expand Up @@ -43,31 +86,49 @@
end
end

describe ".update_feed" do
it "saves the name and url" do
feed = Feed.new
describe ".delete" do
it "deletes the feed by id" do
feed = create_feed

FeedRepository.update_feed(feed, "Test Feed", "example.com/feed")
FeedRepository.delete(feed.id)

expect(feed.name).to eq "Test Feed"
expect(feed.url).to eq "example.com/feed"
expect(Feed.unscoped.find_by(id: feed.id)).to be_nil
end

it "does not delete other feeds" do
feed1 = create_feed
feed2 = create_feed

FeedRepository.delete(feed1.id)

expect(Feed.unscoped.find_by(id: feed2.id)).to eq(feed2)
end
end

describe "fetch" do
let(:feed) { Feed.new(id: 1) }
describe ".list" do
it "returns all feeds ordered by name, case insensitive" do
feed1 = create_feed(name: "foo")
feed2 = create_feed(name: "Fabulous")
feed3 = create_feed(name: "Zooby")
feed4 = create_feed(name: "zabby")

it "finds by id" do
expect(Feed).to receive(:find).with(feed.id).and_return(feed)
FeedRepository.fetch(feed.id)
expect(FeedRepository.list).to eq([feed2, feed1, feed4, feed3])
end
end

it "returns found feed" do
allow(Feed).to receive(:find).with(feed.id).and_return(feed)
describe ".in_group" do
it "returns feeds that are in a group" do
feed1 = create_feed(group_id: 5)
feed2 = create_feed(group_id: 6)

result = FeedRepository.fetch(feed.id)
expect(FeedRepository.in_group).to match_array([feed1, feed2])
end

expect(result).to eq feed
it "does not return feeds that are not in a group" do
create_feed
create_feed

expect(FeedRepository.in_group).to be_empty
end
end
end