Created
June 29, 2012 15:25
-
-
Save Peeja/3018590 to your computer and use it in GitHub Desktop.
Conditional Whac-A-Mole: Another solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < Struct.new(:username, :followability) | |
def follow | |
followability.follow(self) | |
end | |
end | |
class Follow | |
def self.follow(user) | |
user.follow | |
end | |
end | |
class PublicFollowability | |
def follow(user) | |
Follow.actually_follow(user) | |
end | |
end | |
class PrivateFollowability | |
def follow(user) | |
Follow.actually_follow(user) if Follow.confirm_follow(user) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "toot" | |
describe Follow do | |
context "when the user is public" do | |
it "follows immediately" do | |
user = User.new("garybernhardt", PublicFollowability.new) | |
Follow.should_receive(:actually_follow).with(user) | |
Follow.follow(user) | |
end | |
end | |
context "when the user is private" do | |
let(:user) { User.new("garybernhardt", PrivateFollowability.new) } | |
it "does not follow if the user declines the prompt" do | |
Follow.stub(:confirm_follow).with(user) { false } | |
Follow.should_not_receive(:actually_follow).with(user) | |
Follow.follow(user) | |
end | |
it "does not follow if the user declines the prompt" do | |
Follow.stub(:confirm_follow).with(user) { true } | |
Follow.should_receive(:actually_follow).with(user) | |
Follow.follow(user) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment