Skip to content

Commit

Permalink
Specs: add more tests for StoryRepository (#562)
Browse files Browse the repository at this point in the history
This brings test coverage up to 100%, so I'm also enabling the
`minimum_coverage` threshold to make sure it stays there.
  • Loading branch information
mockdeep committed Mar 30, 2021
1 parent a92e562 commit 765da7b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/factories/stories.rb
@@ -1,6 +1,7 @@
module Factories
STORY_TRAITS = {
read: -> { { is_read: true } },
starred: -> { { is_starred: true } },
unread: -> { { is_read: false } }
}.freeze

Expand Down
55 changes: 55 additions & 0 deletions spec/repositories/story_repository_spec.rb
Expand Up @@ -293,6 +293,61 @@
end
end

describe ".starred" do
it "returns starred stories" do
story = create_story(:starred)

expect(StoryRepository.starred).to eq([story])
end

it "sorts stories by published" do
story1 = create_story(:starred, published: 1.day.ago)
story2 = create_story(:starred, published: 1.hour.ago)

expect(StoryRepository.starred).to eq([story2, story1])
end

it "does not return unstarred stories" do
create_story

expect(StoryRepository.starred).to be_empty
end

it "paginates results" do
stories =
21.times.map { |num| create_story(:starred, published: num.days.ago) }

expect(StoryRepository.starred).to eq(stories[0...20])
expect(StoryRepository.starred(2)).to eq([stories.last])
end
end

describe ".unstarred_read_stories_older_than" do
it "returns unstarred read stories older than given number of days" do
story = create_story(:read, published: 6.days.ago)

expect(StoryRepository.unstarred_read_stories_older_than(5)).to eq([story])
end

it "does not return starred stories older than the given number of days" do
create_story(:read, :starred, published: 6.days.ago)

expect(StoryRepository.unstarred_read_stories_older_than(5)).to be_empty
end

it "does not return unread stories older than the given number of days" do
create_story(:unread, published: 6.days.ago)

expect(StoryRepository.unstarred_read_stories_older_than(5)).to be_empty
end

it "does not return stories newer than given number of days" do
create_story(:read, published: 4.days.ago)

expect(StoryRepository.unstarred_read_stories_older_than(5)).to be_empty
end
end

describe ".read_count" do
it "returns the count of read stories" do
create_story(:read)
Expand Down
2 changes: 2 additions & 0 deletions spec/support/coverage.rb
Expand Up @@ -14,4 +14,6 @@
add_group("Repositories", "app/repositories")
add_group("Tasks", "app/tasks")
add_group("Utils", "app/utils")
add_filter("/db/migrate/")
end
SimpleCov.minimum_coverage(100)

0 comments on commit 765da7b

Please sign in to comment.