Created
February 6, 2012 09:28
-
-
Save Chris927/1751045 to your computer and use it in GitHub Desktop.
DCI experiment, using the R82 domain
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
# the role | |
# TODO: should the class be named 'MatchCreator'? What the role does | |
# is independent of needs | |
module NeedToOtherNeedConnector | |
def connect_needs(from, to) | |
match = Match.new(:user => self, :from => from, :to => to) | |
end | |
end | |
# the context | |
class MatchNeedToOtherNeedContext | |
attr_reader :user | |
def self.call(user, need_from, need_to) | |
MatchNeedToOtherNeedContext.new(user, need_from, need_to).call | |
end | |
def initialize(user, need_from, need_to) | |
@from = need_from | |
@to = need_to | |
@user = user | |
@user.extend NeedToOtherNeedConnector | |
end | |
def call | |
# now what? | |
@matcher.connect_needs @from, @to | |
end | |
end | |
# the specs - the role | |
describe NeedToOtherNeedConnector do | |
before(:each) do | |
@need1 = Factory(:need) | |
@need2 = Factory(:need) | |
@connector = Factory(:user) | |
@connector.extend NeedToOtherNeedConnector | |
end | |
describe '#connect_needs' do | |
it 'connects two needs together' do | |
@connector.connect_needs(@need1, @need2) | |
@need1.connected_needs.should include(@need2) | |
@need2.connected_needs.should include(@need1) | |
end | |
end | |
end | |
# the specs - the context | |
describe MatchNeedToOtherNeedContext do | |
before(:each) do | |
@need1 = Factory(:need) | |
@need2 = Factory(:need) | |
@user = Factory(:user) | |
end | |
it 'connects the needs' do | |
context = MatchNeedToOtherNeedContext.new(@user, @need1, @need2) | |
context.user.should_receive(:connect_needs).with(@need1, @need2) | |
context.call | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment