forked from thoughtbot/factory_bot
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first attribute groups specs passing
- Loading branch information
1 parent
e39d6e6
commit 36fb3fb
Showing
6 changed files
with
84 additions
and
14 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,29 @@ | ||
module FactoryGirl | ||
|
||
class AttributeGroup | ||
attr_reader :name | ||
attr_reader :attributes | ||
|
||
def initialize(name, &block) #:nodoc: | ||
@name = name | ||
@attributes = [] | ||
proxy = FactoryGirl::DefinitionProxy.new(self) | ||
proxy.instance_eval(&block) if block_given? | ||
end | ||
|
||
def define_attribute(attribute) | ||
name = attribute.name | ||
if attribute_defined?(name) | ||
raise AttributeDefinitionError, "Attribute already defined: #{name}" | ||
end | ||
@attributes << attribute | ||
end | ||
|
||
private | ||
|
||
def attribute_defined? (name) | ||
!@attributes.detect {|attr| attr.name == name && !attr.is_a?(Attribute::Callback) }.nil? | ||
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
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