Skip to content

Commit

Permalink
Fix for view counts
Browse files Browse the repository at this point in the history
  • Loading branch information
snowblink committed Oct 30, 2013
1 parent 18e5a78 commit ed2e8c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/exercism/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def viewed!(user)
end

def view_count
@view_count ||= viewers.count
viewers.count
end

def generate_key
Expand Down
9 changes: 9 additions & 0 deletions test/exercism/submission_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ def test_viewing_submission_twice_is_fine
assert_equal %w(alice), submission.viewers.map(&:username)
end

def test_viewing_with_increase_in_viewers
alice = User.create(username: 'alice')
bob = User.create(username: 'bob')
submission.viewed!(alice)
assert_equal 1, submission.view_count
submission.viewed!(bob)
assert_equal 2, submission.view_count
end

def test_comments_are_sorted
submission.comments << Comment.new(body: 'second', created_at: Time.now, user: submission.user)
submission.comments << Comment.new(body: 'first', created_at: Time.now - 1000, user: submission.user)
Expand Down

0 comments on commit ed2e8c5

Please sign in to comment.