Permalink
Browse files

Fixed toggle code and tests

  • Loading branch information...
1 parent cd0eae4 commit be75e171226fcdddb0fe44237b681d74eaca3f09 @cmer committed Mar 1, 2012
@@ -52,8 +52,10 @@ def unfollow!(followable)
def toggle_follow!(followable)
if follows?(followable)
unfollow!(followable)
+ false
else
follow!(followable)
+ true
end
end
@@ -51,8 +51,10 @@ def unlike!(likeable)
def toggle_like!(likeable)
if likes?(likeable)
unlike!(likeable)
+ false
else
like!(likeable)
+ true
end
end
@@ -50,8 +50,10 @@ def unmention!(mentionable)
def toggle_mention!(mentionable)
if mentions?(mentionable)
unmention!(mentionable)
+ false
else
mention!(mentionable)
+ true
end
end
View
@@ -37,12 +37,13 @@ class FollowTest < Test::Unit::TestCase
end
should "be able to toggle following on/off" do
- @follower1.toggle_follow!(@followable1)
- assert_equal true, @follower1.follows?(@followable1)
- @follower1.toggle_follow!(@followable1)
- assert_equal false, @follower1.follows?(@followable1)
- @follower1.toggle_follow!(@followable1)
- assert_equal true, @follower1.follows?(@followable1)
+ assert_false @follower1.follows?(@followable1)
+ assert_true @follower1.toggle_follow!(@followable1)
+ assert_true @follower1.follows?(@followable1)
+ assert_false @follower1.toggle_follow!(@followable1)
+ assert_false @follower1.follows?(@followable1)
+ assert_true @follower1.toggle_follow!(@followable1)
+ assert_true @follower1.follows?(@followable1)
end
should "expose a list of its followees" do
View
@@ -37,12 +37,13 @@ class LikeTest < Test::Unit::TestCase
end
should "be able to toggle likes on/off" do
- @liker1.toggle_like!(@likeable1)
- assert_equal true, @liker1.likes?(@likeable1)
- @liker1.toggle_like!(@likeable1)
- assert_equal false, @liker1.likes?(@likeable1)
- @liker1.toggle_like!(@likeable1)
- assert_equal true, @liker1.likes?(@likeable1)
+ assert_false @liker1.likes?(@likeable1)
+ assert_true @liker1.toggle_like!(@likeable1)
+ assert_true @liker1.likes?(@likeable1)
+ assert_false @liker1.toggle_like!(@likeable1)
+ assert_false @liker1.likes?(@likeable1)
+ assert_true @liker1.toggle_like!(@likeable1)
+ assert_true @liker1.likes?(@likeable1)
end
should "expose a list of its likes" do
View
@@ -41,12 +41,13 @@ class MentionTest < Test::Unit::TestCase
end
should "be able to toggle mentions on/off" do
- @mentioner1.toggle_mention!(@mentionable1)
- assert_equal true, @mentioner1.mentions?(@mentionable1)
- @mentioner1.toggle_mention!(@mentionable1)
- assert_equal false, @mentioner1.mentions?(@mentionable1)
- @mentioner1.toggle_mention!(@mentionable1)
- assert_equal true, @mentioner1.mentions?(@mentionable1)
+ assert_false @mentioner1.mentions?(@mentionable1)
+ assert_true @mentioner1.toggle_mention!(@mentionable1)
+ assert_true @mentioner1.mentions?(@mentionable1)
+ assert_false @mentioner1.toggle_mention!(@mentionable1)
+ assert_false @mentioner1.mentions?(@mentionable1)
+ assert_true @mentioner1.toggle_mention!(@mentionable1)
+ assert_true @mentioner1.mentions?(@mentionable1)
end
should "expose a list of its mentionees" do
View
@@ -8,6 +8,16 @@
$:.push File.expand_path("../lib", __FILE__)
require "socialization"
+module Test::Unit::Assertions
+ def assert_true(object, message="")
+ assert_equal(true, object, message)
+ end
+
+ def assert_false(object, message="")
+ assert_equal(false, object, message)
+ end
+end
+
ActiveRecord::Base.configurations = {'sqlite3' => {:adapter => 'sqlite3', :database => ':memory:'}}
ActiveRecord::Base.establish_connection('sqlite3')

0 comments on commit be75e17

Please sign in to comment.