Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored Factory#association to use a new Attribute class
- Loading branch information
Showing
5 changed files
with
93 additions
and
57 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Factory | ||
class Attribute #:nodoc: | ||
|
||
class Association < Attribute #:nodoc: | ||
|
||
def initialize(name, factory, overrides) | ||
super(name) | ||
@factory = factory | ||
@overrides = overrides | ||
end | ||
|
||
def add_to(proxy) | ||
proxy.associate(name, @factory, @overrides) | ||
end | ||
end | ||
|
||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require(File.join(File.dirname(__FILE__), 'test_helper')) | ||
|
||
class AssociationAttributeTest < Test::Unit::TestCase | ||
|
||
context "an association" do | ||
setup do | ||
@name = :author | ||
@factory = :user | ||
@overrides = { :first_name => 'John' } | ||
@attr = Factory::Attribute::Association.new(@name, | ||
@factory, | ||
@overrides) | ||
end | ||
|
||
should "have a name" do | ||
assert_equal @name, @attr.name | ||
end | ||
|
||
should "tell the proxy to associate when being added to a proxy" do | ||
proxy = mock('proxy') | ||
proxy.expects(:associate).with(@name, @factory, @overrides) | ||
@attr.add_to(proxy) | ||
end | ||
end | ||
|
||
should "convert names to symbols" do | ||
assert_equal :name, | ||
Factory::Attribute::Association.new('name', :user, {}).name | ||
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