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
7 changes: 6 additions & 1 deletion app/commands/stories/mark_group_as_read.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
require_relative "../../repositories/story_repository"

class MarkGroupAsRead
KINDLING_GROUP_ID = 1
SPARKS_AND_KINDLING_GROUP_ID = 0

def initialize(group_id, timestamp, repository = StoryRepository)
@group_id = group_id.to_i
@repo = repository
@timestamp = timestamp
end

def mark_group_as_read
@repo.fetch_unread_by_timestamp(@timestamp).update_all(is_read: true) if @group_id == 1
if [SPARKS_AND_KINDLING_GROUP_ID, KINDLING_GROUP_ID].include? @group_id
@repo.fetch_unread_by_timestamp(@timestamp).update_all(is_read: true)
end
end
end

6 changes: 6 additions & 0 deletions spec/commands/stories/mark_group_as_read_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
let(:stories) { stub }
let(:repo){ stub(fetch_unread_by_timestamp: stories) }

it "marks group 0 as read" do
command = MarkGroupAsRead.new(0, Time.now.to_i, repo)
stories.should_receive(:update_all).with(is_read: true)
command.mark_group_as_read
end

it "marks group 1 as read" do
command = MarkGroupAsRead.new(1, Time.now.to_i, repo)
stories.should_receive(:update_all).with(is_read: true)
Expand Down