Skip to content

Commit f9a4218

Browse files
committed
Add an unrate method to remove all ratings
Fixes #81 Signed-off-by: David Celis <me@davidcel.is>
1 parent e1c3053 commit f9a4218

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
recommendable (2.1.0.2)
4+
recommendable (2.1.1)
55
activesupport (>= 3.0.0)
66
hooks (>= 0.2.1)
77
redis (>= 2.2.0)

lib/recommendable/rater.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def rated?(obj)
113113
def rated_anything?
114114
likes_count > 0 || dislikes_count > 0
115115
end
116+
117+
def unrate(obj)
118+
unlike(obj) || undislike(obj) || unhide(obj)
119+
unbookmark(obj)
120+
end
116121
end
117122
end
118123
end

test/recommendable/rater_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ def test_that_rated_anything_is_false_by_default
2323
refute @user.rated_anything?
2424
end
2525

26+
def test_that_unrate_removes_any_rating
27+
@movie = Factory(:movie)
28+
%w[like dislike hide bookmark].each do |action|
29+
@user.send(action, @movie)
30+
assert @user.send("#{action.pluralize}?", @movie)
31+
32+
@user.unrate(@movie)
33+
refute @user.send("#{action.pluralize}?", @movie)
34+
end
35+
end
36+
2637
def teardown
2738
Recommendable.redis.flushdb
2839
end

0 commit comments

Comments
 (0)