spec/specs/follow_spec.rb in mongoid_follow-0.2.1 vs spec/specs/follow_spec.rb in mongoid_follow-0.2.2

- old
+ new

@@ -6,10 +6,11 @@ before do @bonnie = User.create(:name => 'Bonnie') @clyde = User.create(:name => 'Clyde') @alec = User.create(:name => 'Alec') + @just_another_user = OtherUser.create(:name => 'Another User') @gang = Group.create(:name => 'Gang') end it "should have no follows or followers" do @@ -63,77 +64,147 @@ @bonnie.follows?(@gang).should be_true @gang.follower?(@bonnie).should be_true end - it "should increment / decrement counters" do - @clyde.followers_count.should == 0 + describe "counting stuff" do + it "should increment / decrement cache counters" do + @clyde.followers_count.should == 0 - @bonnie.follow(@clyde) + @bonnie.follow(@clyde) + @bonnie.followees_count.should == 1 + @clyde.followers_count.should == 1 - @bonnie.followees_count.should == 1 - @clyde.followers_count.should == 1 + @alec.follow(@clyde) + @clyde.followers_count.should == 2 + @bonnie.followers_count.should == 0 - @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 - @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 - @bonnie.unfollow(@clyde) - @bonnie.followees_count.should == 0 - @clyde.followers_count.should == 0 - end + it "should allow to count followees by model" do + @alec.follow(@gang) + @alec.followees_count.should == 1 + @alec.followees_count_by_model(Group).should == 1 - 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) + @alec.followees_count.should == 2 + @alec.followees_count_by_model(Group).should == 1 + end - @alec.follow(@clyde) - @clyde.all_followers.should == [@bonnie, @alec] - end + it "should also allow to count followees by model with dynamic method" do + @alec.follow(@gang) + @alec.follow(@clyde) - 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 + @alec.group_followees_count.should == 1 + end - @bonnie.follow(@gang) - @bonnie.all_followees.should == [@clyde, @gang] + it "should allow to count followers by model" do + @just_another_user.follow(@gang) + @gang.followers_count.should == 1 + @gang.followers_count_by_model(OtherUser).should == 1 + + @alec.follow(@gang) + @gang.followers_count.should == 2 + @gang.followers_count_by_model(OtherUser).should == 1 + end + + it "should also allow to count followers by model with dynamic method" do + @just_another_user.follow(@gang) + @alec.follow(@gang) + + @gang.user_followers_count.should == 1 + end end - it "should have common followers" do - @bonnie.follow(@clyde) - @bonnie.follow(@gang) + describe "listing stuff" do + 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 - @gang.common_followers_with(@clyde).should == [@bonnie] + @alec.follow(@clyde) + @clyde.all_followers.should == [@bonnie, @alec] + end - @alec.follow(@clyde) - @alec.follow(@gang) + it "should list all followers by model" do + @bonnie.follow(@gang) + @just_another_user.follow(@gang) - @clyde.common_followers_with(@gang).should == [@bonnie, @alec] - end + @gang.all_followers.should == [@bonnie, @just_another_user] + @gang.all_followers_by_model(User).should == [@bonnie] + end - it "should have common followees" do - @bonnie.follow(@gang) - @alec.follow(@gang) + it "should list all followers by model with dynamic method" do + @bonnie.follow(@gang) + @just_another_user.follow(@gang) - @alec.common_followees_with(@bonnie).should == [@gang] + @gang.all_user_followers(User).should == [@bonnie] + end - @bonnie.follow(@clyde) - @alec.follow(@clyde) + it "should list all followees" do + @bonnie.follow(@clyde) + # @bonnie.all_followees.should == [@clyde] # spec has an error on last #all_followees when this is called - @bonnie.common_followees_with(@alec).should == [@gang, @clyde] + @bonnie.follow(@gang) + @bonnie.all_followees.should == [@clyde, @gang] + end + + it "should list all followees by model" do + @bonnie.follow(@gang) + @bonnie.follow(@clyde) + + @bonnie.all_followees.should == [@gang, @clyde] + @bonnie.all_followees_by_model(User).should == [@clyde] + end + + it "should list all followees by model with dynamic method" do + @bonnie.follow(@gang) + @bonnie.follow(@clyde) + + @bonnie.all_user_followees.should == [@clyde] + 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 - # Duh... this is a useless spec... Hrmn... - it "should respond on callbacks" do - @bonnie.respond_to?('after_follow').should be_true - @bonnie.respond_to?('after_unfollowed_by').should be_true - @bonnie.respond_to?('before_follow').should be_false + describe "callback stuff" do + # Duh... this is a useless spec... Hrmn... + it "should respond on callbacks" do + @bonnie.respond_to?('after_follow').should be_true + @bonnie.respond_to?('after_unfollowed_by').should be_true + @bonnie.respond_to?('before_follow').should be_false - @gang.respond_to?('before_followed_by').should be_true - @gang.respond_to?('after_followed_by').should be_false + @gang.respond_to?('before_followed_by').should be_true + @gang.respond_to?('after_followed_by').should be_false + end end + end end