spec/specs/follow_spec.rb in mongoid_follow-0.0.2 vs spec/specs/follow_spec.rb in mongoid_follow-0.1.0
- old
+ new
@@ -3,21 +3,15 @@
describe Mongoid::Follower do
describe User do
before do
- @bonnie = User.new
- @bonnie.save
+ @bonnie = User.create(:name => 'Bonnie')
+ @clyde = User.create(:name => 'Clyde')
+ @alec = User.create(:name => 'Alec')
- @clyde = User.new
- @clyde.save
-
- @alec = User.new
- @alec.save
-
- @gang = Group.new
- @gang.save
+ @gang = Group.create(:name => 'Gang')
end
it "should have no follows or followers" do
@bonnie.follows?(@clyde).should be_false
@@ -31,10 +25,20 @@
@bonnie.follows?(@clyde).should be_true
@clyde.follower?(@bonnie).should be_true
end
+ it "should decline to follow self" do
+ @bonnie.follow(@bonnie).should be_false
+ end
+
+ it "should decline two follows" do
+ @bonnie.follow(@clyde)
+
+ @bonnie.follow(@clyde).should be_false
+ end
+
it "can unfollow another User" do
@bonnie.follows?(@clyde).should be_false
@clyde.follower?(@bonnie).should be_false
@bonnie.follow(@clyde)
@@ -44,13 +48,82 @@
@bonnie.unfollow(@clyde)
@bonnie.follows?(@clyde).should be_false
@clyde.follower?(@bonnie).should be_false
end
+ it "should decline unfollow of non-followed User" do
+ @bonnie.unfollow(@clyde).should be_false
+ end
+
+ it "should decline unfollow of self" do
+ @bonnie.unfollow(@bonnie).should be_false
+ end
+
it "can follow a group" do
@bonnie.follow(@gang)
@bonnie.follows?(@gang).should be_true
@gang.follower?(@bonnie).should be_true
+ end
+
+ it "should increment / decrement counters" do
+ @clyde.followers_count.should == 0
+
+ @bonnie.follow(@clyde)
+
+ @bonnie.followees_count.should == 1
+ @clyde.followers_count.should == 1
+
+ @alec.follow(@clyde)
+ @clyde.followers_count.should == 2
+ @bonnie.followers_count.should == 0
+
+ @alec.unfollow(@clyde)
+ @alec.followees_count.should == 0
+ @clyde.followers_count.should == 1
+
+ @bonnie.unfollow(@clyde)
+ @bonnie.followees_count.should == 0
+ @clyde.followers_count.should == 0
+ end
+
+ it "should list all followers" do
+ @bonnie.follow(@clyde)
+ # @clyde.all_followers.should == [@bonnie] # spec has an error on last #all_followers when this is called
+
+ @alec.follow(@clyde)
+ @clyde.all_followers.should == [@bonnie, @alec]
+ end
+
+ it "should list all followee" do
+ @bonnie.follow(@clyde)
+ # @bonnie.all_followees.should == [@clyde] # spec has an error on last #all_followees when this is called
+
+ @bonnie.follow(@gang)
+ @bonnie.all_followees.should == [@clyde, @gang]
+ end
+
+ it "should have common followers" do
+ @bonnie.follow(@clyde)
+ @bonnie.follow(@gang)
+
+ @gang.common_followers_with(@clyde).should == [@bonnie]
+
+ @alec.follow(@clyde)
+ @alec.follow(@gang)
+
+ @clyde.common_followers_with(@gang).should == [@bonnie, @alec]
+ end
+
+ it "should have common followees" do
+ @bonnie.follow(@gang)
+ @alec.follow(@gang)
+
+ @alec.common_followees_with(@bonnie).should == [@gang]
+
+ @bonnie.follow(@clyde)
+ @alec.follow(@clyde)
+
+ @bonnie.common_followees_with(@alec).should == [@gang, @clyde]
end
end
end