Skip to content

Commit

Permalink
Scopes: Check param to be persistent User (having an id)
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Jan 27, 2013
1 parent ffe2389 commit 45b20d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 2 additions & 3 deletions lib/unread/acts_as_readable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ def reset_read_marks!(user = :all)
def assert_reader(user)
assert_reader_class

unless user.is_a?(ReadMark.reader_class)
raise ArgumentError, "Class #{user.class.name} is not registered by acts_as_reader!"
end
raise ArgumentError, "Class #{user.class.name} is not registered by acts_as_reader!" unless user.is_a?(ReadMark.reader_class)
raise ArgumentError, "The given user has no id!" unless user.id
end

def assert_reader_class
Expand Down
12 changes: 8 additions & 4 deletions test/unread_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ def test_with_read_marks_for
assert_equal true, emails[1].unread?(@reader)
end

def scope_param_check
[ 42, nil, 'foo', :foo, {} ].each do |not_a_user|
assert_raise(ArgumentError) { Email.unread_by(not_a_user)}
assert_raise(ArgumentError) { Email.with_read_marks_for(not_a_user)}
def test_scope_param_check
[ 42, nil, 'foo', :foo, {} ].each do |not_a_reader|
assert_raise(ArgumentError) { Email.unread_by(not_a_reader)}
assert_raise(ArgumentError) { Email.with_read_marks_for(not_a_reader)}
end

unsaved_reader = Reader.new
assert_raise(ArgumentError) { Email.unread_by(unsaved_reader)}
assert_raise(ArgumentError) { Email.with_read_marks_for(unsaved_reader)}
end

def test_scope_after_reset
Expand Down

0 comments on commit 45b20d6

Please sign in to comment.