Skip to content

Commit

Permalink
don't typecast if it's not an Attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgolick committed Jan 3, 2010
1 parent 17732d9 commit 95bc9bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/friendly/document/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def assign_default_values
end

def assign(name, value)
send(:"#{name}=", self.class.attributes[name.to_sym].typecast(value))
send(:"#{name}=", typecast(name, value))
end

protected
Expand All @@ -43,6 +43,11 @@ def assert_no_duplicate_keys(hash)
raise ArgumentError, "Duplicate keys: #{hash.inspect}"
end
end

def typecast(name, value)
attribute = self.class.attributes[name.to_sym]
attribute ? attribute.typecast(value) : value
end
end
end
end
7 changes: 7 additions & 0 deletions spec/unit/document/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,12 @@
@object.assign(:id, uuid.to_guid)
@object.id.should == uuid
end

it "doesn't try to typecast if there's no Attribute object" do
@klass.send(:attr_accessor, :height)
@object = @klass.new
@object.assign(:height, "5'11")
@object.height.should == "5'11"
end
end
end

0 comments on commit 95bc9bc

Please sign in to comment.