Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add an unrate method to remove all ratings

Fixes #81

Signed-off-by: David Celis <me@davidcel.is>
  • Loading branch information...
commit f9a4218be81331efa1b0b7566c2f9f74faac363d 1 parent e1c3053
@davidcelis authored
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- recommendable (2.1.0.2)
+ recommendable (2.1.1)
activesupport (>= 3.0.0)
hooks (>= 0.2.1)
redis (>= 2.2.0)
View
5 lib/recommendable/rater.rb
@@ -113,6 +113,11 @@ def rated?(obj)
def rated_anything?
likes_count > 0 || dislikes_count > 0
end
+
+ def unrate(obj)
+ unlike(obj) || undislike(obj) || unhide(obj)
+ unbookmark(obj)
+ end
end
end
end
View
11 test/recommendable/rater_test.rb
@@ -23,6 +23,17 @@ def test_that_rated_anything_is_false_by_default
refute @user.rated_anything?
end
+ def test_that_unrate_removes_any_rating
+ @movie = Factory(:movie)
+ %w[like dislike hide bookmark].each do |action|
+ @user.send(action, @movie)
+ assert @user.send("#{action.pluralize}?", @movie)
+
+ @user.unrate(@movie)
+ refute @user.send("#{action.pluralize}?", @movie)
+ end
+ end
+
def teardown
Recommendable.redis.flushdb
end
Please sign in to comment.
Something went wrong with that request. Please try again.