Permalink
Browse files

Update Factory helpers to handle protected attributes

  • Loading branch information...
1 parent a6eb537 commit a3851fd3722fa0d539107fc455c42503054c75ce @obrie obrie committed Oct 26, 2008
Showing with 5 additions and 1 deletion.
  1. +5 −1 test/factory.rb
View
@@ -13,12 +13,16 @@ def self.build(model, &block)
def valid_attributes_for(model, attributes = {})
name = model.to_s.underscore
send("#{name}_attributes", attributes)
+ attributes.stringify_keys!
attributes
end
# Build an unsaved record
def new_record(model, *args)
- model.new(valid_attributes_for(model, *args))
+ attributes = valid_attributes_for(model, *args)
+ record = model.new(attributes)
+ attributes.each {|attr, value| record.send("#{attr}=", value) if model.accessible_attributes && !model.accessible_attributes.include?(attr) || model.protected_attributes && model.protected_attributes.include?(attr)}
+ record
end
# Build and save/reload a record

0 comments on commit a3851fd

Please sign in to comment.