1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

An error is now raised if you try to define the same attribute twice

This commit is contained in:
Joe Ferris 2008-07-30 14:04:43 -04:00
parent 38bc8965db
commit 13d988cd98
2 changed files with 15 additions and 0 deletions

View file

@ -91,6 +91,11 @@ class Factory
# If no block is given, this value will be used for this attribute.
def add_attribute (name, value = nil, &block)
attribute = Attribute.new(name, value, block)
if attribute_defined?(attribute.name)
raise AttributeDefinitionError, "Attribute already defined: #{name}"
end
@attributes << attribute
end
@ -250,4 +255,8 @@ class Factory
end
end
def attribute_defined? (name)
!@attributes.detect {|attr| attr.name == name }.nil?
end
end

View file

@ -91,6 +91,12 @@ class FactoryTest < Test::Unit::TestCase
assert_equal @class, @factory.build_class
end
should "not allow the same attribute to be added twice" do
assert_raise(Factory::AttributeDefinitionError) do
2.times { @factory.add_attribute @name }
end
end
context "when adding an attribute with a value parameter" do
setup do