Skip to content

Commit

Permalink
fix: Factory story unread default and memoization (#1176)
Browse files Browse the repository at this point in the history
Update stories factories:
- Removed :unread trait from stories factory
- Removed :unread from create(:story) throughout specs

Removed memoization:
- spec/requests/stories_repository_spec
- spec/requests/tutorials_controller_spec

Updated rubocop_todo

Co-authored-by: Rob Young <[email protected]>
  • Loading branch information
RobBoothAppDev21 and rhyoung214 authored Mar 24, 2024
1 parent 1af7783 commit a898eda
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 103 deletions.
13 changes: 4 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 400`
# on 2024-03-14 03:12:58 UTC using RuboCop version 1.62.0.
# on 2024-03-23 21:41:23 UTC using RuboCop version 1.62.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -144,7 +144,7 @@ RSpec/ExampleLength:
- 'spec/utils/feed_discovery_spec.rb'
- 'spec/utils/opml_parser_spec.rb'

# Offense count: 16
# Offense count: 17
# Configuration parameters: EnforcedStyle.
# SupportedStyles: allow, expect
RSpec/MessageExpectation:
Expand All @@ -170,7 +170,7 @@ RSpec/MultipleExpectations:
- 'spec/utils/i18n_support_spec.rb'
- 'spec/utils/opml_parser_spec.rb'

# Offense count: 35
# Offense count: 24
# Configuration parameters: AllowSubject, Max.
RSpec/MultipleMemoizedHelpers:
Exclude:
Expand All @@ -180,11 +180,6 @@ RSpec/MultipleMemoizedHelpers:
- 'spec/repositories/story_repository_spec.rb'
- 'spec/requests/feeds_controller_spec.rb'
- 'spec/requests/imports_controller_spec.rb'
- 'spec/requests/stories_controller_spec.rb'
- 'spec/requests/tutorials_controller_spec.rb'
- 'spec/tasks/remove_old_stories_spec.rb'
- 'spec/utils/feed_discovery_spec.rb'
- 'spec/utils/i18n_support_spec.rb'

# Offense count: 5
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
Expand All @@ -199,7 +194,7 @@ RSpec/NestedGroups:
Exclude:
- 'spec/integration/feed_importing_spec.rb'

# Offense count: 25
# Offense count: 26
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
Expand Down
6 changes: 3 additions & 3 deletions spec/commands/fever_api/read_items_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe FeverAPI::ReadItems do
it "returns a list of unread items including total count" do
stories = create_list(:story, 3, :unread)
stories = create_list(:story, 3)
authorization = Authorization.new(default_user)

items = stories.map(&:as_fever_json)
Expand All @@ -11,7 +11,7 @@
end

it "returns a list of unread items with empty since_id" do
stories = create_list(:story, 3, :unread)
stories = create_list(:story, 3)
authorization = Authorization.new(default_user)

items = stories.map(&:as_fever_json)
Expand All @@ -20,7 +20,7 @@
end

it "returns a list of unread items since id including total count" do
story, *other_stories = create_list(:story, 3, :unread)
story, *other_stories = create_list(:story, 3)
authorization = Authorization.new(default_user)

expect(described_class.call(authorization:, items: nil, since_id: story.id))
Expand Down
2 changes: 1 addition & 1 deletion spec/commands/fever_api/sync_unread_item_ids_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe FeverAPI::SyncUnreadItemIds do
it "returns a list of unread items if requested" do
stories = create_list(:story, 3, :unread)
stories = create_list(:story, 3)
authorization = Authorization.new(default_user)

expect(described_class.call(authorization:, unread_item_ids: nil))
Expand Down
4 changes: 2 additions & 2 deletions spec/commands/fever_api/write_mark_feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ def params(feed, before:)

it "marks the feed stories as read before the given timestamp" do
feed = create(:feed)
story = create(:story, :unread, feed:, created_at: 1.week.ago)
story = create(:story, feed:, created_at: 1.week.ago)

expect { described_class.call(**params(feed, before: 1.day.ago.to_i)) }
.to change { story.reload.is_read? }.from(false).to(true)
end

it "does not mark the feed stories as read after the given timestamp" do
feed = create(:feed)
story = create(:story, :unread, feed:)
story = create(:story, feed:)

expect { described_class.call(**params(feed, before: 1.day.ago.to_i)) }
.to not_change { story.reload.is_read? }.from(false)
Expand Down
2 changes: 1 addition & 1 deletion spec/commands/fever_api/write_mark_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def authorization
end

it "marks the group stories as read before the given timestamp" do
story = create(:story, :unread, :with_group, created_at: 1.week.ago)
story = create(:story, :with_group, created_at: 1.week.ago)
before = 1.day.ago
id = story.group_id

Expand Down
2 changes: 1 addition & 1 deletion spec/commands/fever_api/write_mark_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe FeverAPI::WriteMarkItem do
context "when as: 'read'" do
it "marks the story as read" do
story = create(:story, :unread)
story = create(:story)
authorization = Authorization.new(story.user)
params = { authorization:, mark: "item", as: "read", id: story.id }

Expand Down
2 changes: 1 addition & 1 deletion spec/commands/story/mark_all_as_read_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe MarkAllAsRead do
it "marks all stories as read" do
stories = create_pair(:story, :unread)
stories = create_pair(:story)

expect { described_class.call(stories.map(&:id)) }
.to change_all_records(stories, :is_read).from(false).to(true)
Expand Down
2 changes: 1 addition & 1 deletion spec/commands/story/mark_feed_as_read_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe MarkFeedAsRead do
it "marks feed stories as read before timestamp" do
story = create(:story, :unread, created_at: 1.week.ago)
story = create(:story, created_at: 1.week.ago)
before = 1.day.ago

expect { described_class.call(story.feed_id, before) }
Expand Down
8 changes: 4 additions & 4 deletions spec/commands/story/mark_group_as_read_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
RSpec.describe MarkGroupAsRead do
describe "#mark_group_as_read" do
it "marks group as read" do
story = create(:story, :with_group, :unread, created_at: 1.week.ago)
story = create(:story, :with_group, created_at: 1.week.ago)
timestamp = 1.day.ago

expect { described_class.call(story.group_id, timestamp) }
.to change_record(story, :is_read).from(false).to(true)
end

it "does not mark any group as read when group is not provided" do
story = create(:story, :with_group, :unread, created_at: 1.week.ago)
story = create(:story, :with_group, created_at: 1.week.ago)
timestamp = 1.day.ago

expect { described_class.call(nil, timestamp) }
.not_to change_record(story, :is_read).from(false)
end

it "marks as read all feeds when group is 0 (KINDLING_GROUP_ID)" do
story = create(:story, :with_group, :unread, created_at: 1.week.ago)
story = create(:story, :with_group, created_at: 1.week.ago)
timestamp = 1.day.ago

expect { described_class.call(0, timestamp) }
.to change_record(story, :is_read).from(false).to(true)
end

it "marks as read all feeds when group is -1 (SPARKS_GROUP_ID)" do
story = create(:story, :with_group, :unread, created_at: 1.week.ago)
story = create(:story, :with_group, created_at: 1.week.ago)
timestamp = 1.day.ago

expect { described_class.call(-1, timestamp) }
Expand Down
4 changes: 0 additions & 4 deletions spec/factories/stories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
is_starred { true }
end

trait :unread do
is_read { false }
end

trait :with_group do
feed factory: [:feed, :with_group]
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe "Feed" do
describe ".with_unread_stories_counts" do
it "returns feeds with unread stories counts" do
create(:story, :unread)
create(:story)

feed = Feed.with_unread_stories_counts.first

Expand All @@ -22,7 +22,7 @@
describe "#unread_stories" do
it "returns stories where is_read is false" do
feed = create(:feed)
story = create(:story, :unread, feed:)
story = create(:story, feed:)

expect(feed.unread_stories).to eq([story])
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/story_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe "Story" do
describe ".unread" do
it "returns stories where is_read is false" do
story = create(:story, :unread)
story = create(:story)

expect(Story.unread).to eq([story])
end
Expand Down
42 changes: 21 additions & 21 deletions spec/repositories/story_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")
describe ".fetch_unread_by_timestamp_and_group" do
it "returns unread stories before timestamp for group_id" do
feed = create(:feed, group_id: 52)
story = create(:story, :unread, feed:, created_at: 5.minutes.ago)
story = create(:story, feed:, created_at: 5.minutes.ago)
time = Time.zone.now

stories = described_class.fetch_unread_by_timestamp_and_group(time, 52)
Expand All @@ -141,7 +141,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")

it "does not return unread stories after timestamp for group_id" do
feed = create(:feed, group_id: 52)
create(:story, :unread, feed:, created_at: 5.minutes.ago)
create(:story, feed:, created_at: 5.minutes.ago)
time = 6.minutes.ago

stories = described_class.fetch_unread_by_timestamp_and_group(time, 52)
Expand All @@ -151,7 +151,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")

it "does not return stories before timestamp for other group_id" do
feed = create(:feed, group_id: 52)
create(:story, :unread, feed:, created_at: 5.minutes.ago)
create(:story, feed:, created_at: 5.minutes.ago)
time = Time.zone.now

stories = described_class.fetch_unread_by_timestamp_and_group(time, 55)
Expand All @@ -161,7 +161,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")

it "does not return stories with no group_id before timestamp" do
feed = create(:feed)
create(:story, :unread, feed:, created_at: 5.minutes.ago)
create(:story, feed:, created_at: 5.minutes.ago)
time = Time.zone.now

stories = described_class.fetch_unread_by_timestamp_and_group(time, 52)
Expand All @@ -171,7 +171,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")

it "returns unread stories before timestamp for nil group_id" do
feed = create(:feed)
story = create(:story, :unread, feed:, created_at: 5.minutes.ago)
story = create(:story, feed:, created_at: 5.minutes.ago)
time = Time.zone.now

stories = described_class.fetch_unread_by_timestamp_and_group(time, nil)
Expand All @@ -183,7 +183,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")
describe ".fetch_unread_for_feed_by_timestamp" do
it "returns unread stories for the feed before timestamp" do
feed = create(:feed)
story = create(:story, :unread, feed:, created_at: 5.minutes.ago)
story = create(:story, feed:, created_at: 5.minutes.ago)
time = 4.minutes.ago

stories =
Expand All @@ -194,7 +194,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")

it "returns unread stories for the feed before string timestamp" do
feed = create(:feed)
story = create(:story, :unread, feed:, created_at: 5.minutes.ago)
story = create(:story, feed:, created_at: 5.minutes.ago)
timestamp = Integer(4.minutes.ago).to_s

stories =
Expand All @@ -216,7 +216,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")

it "does not return unread stories for the feed after timestamp" do
feed = create(:feed)
create(:story, :unread, feed:, created_at: 5.minutes.ago)
create(:story, feed:, created_at: 5.minutes.ago)
time = 6.minutes.ago

stories =
Expand All @@ -227,7 +227,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")

it "does not return unread stories for another feed before timestamp" do
feed = create(:feed)
create(:story, :unread, created_at: 5.minutes.ago)
create(:story, created_at: 5.minutes.ago)
time = 4.minutes.ago

stories =
Expand All @@ -239,8 +239,8 @@ def create_feed(url: "http://blog.golang.org/feed.atom")

describe ".unread" do
it "returns unread stories ordered by published date descending" do
story1 = create(:story, :unread, published: 5.minutes.ago)
story2 = create(:story, :unread, published: 4.minutes.ago)
story1 = create(:story, published: 5.minutes.ago)
story2 = create(:story, published: 4.minutes.ago)

expect(described_class.unread).to eq([story2, story1])
end
Expand All @@ -253,31 +253,31 @@ def create_feed(url: "http://blog.golang.org/feed.atom")
end

it "allows to override the order" do
story1 = create(:story, :unread, published: 5.minutes.ago)
story2 = create(:story, :unread, published: 4.minutes.ago)
story1 = create(:story, published: 5.minutes.ago)
story2 = create(:story, published: 4.minutes.ago)

expect(described_class.unread(order: :asc)).to eq([story1, story2])
end
end

describe ".unread_since_id" do
it "returns unread stories with id greater than given id" do
story1 = create(:story, :unread)
story2 = create(:story, :unread)
story1 = create(:story)
story2 = create(:story)

expect(described_class.unread_since_id(story1.id)).to eq([story2])
end

it "does not return read stories with id greater than given id" do
story1 = create(:story, :unread)
story1 = create(:story)
create(:story, :read)

expect(described_class.unread_since_id(story1.id)).to be_empty
end

it "does not return unread stories with id less than given id" do
create(:story, :unread)
story2 = create(:story, :unread)
create(:story)
story2 = create(:story)

expect(described_class.unread_since_id(story2.id)).to be_empty
end
Expand Down Expand Up @@ -322,7 +322,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")
end

it "does not return unread stories" do
create(:story, :unread)
create(:story)

expect(described_class.read).to be_empty
end
Expand Down Expand Up @@ -380,7 +380,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")
end

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

expect(described_class.unstarred_read_stories_older_than(5)).to be_empty
end
Expand All @@ -402,7 +402,7 @@ def create_feed(url: "http://blog.golang.org/feed.atom")
end

it "does not count unread stories" do
create_list(:story, 3, :unread)
create_list(:story, 3)

expect(described_class.read_count).to eq(0)
end
Expand Down
Loading

0 comments on commit a898eda

Please sign in to comment.