Skip to content

Instantly share code, notes, and snippets.

@mdeering
Created February 15, 2010 18:21
Show Gist options
  • Save mdeering/304857 to your computer and use it in GitHub Desktop.
Save mdeering/304857 to your computer and use it in GitHub Desktop.
#...
# Added in your example and it passed without your pull request.
describe 'will perform its actions before type cast' do
before do
User.class_eval do
normalize_attribute :price do |value|
value.to_s.gsub(",",".").to_f
end
end
end
{ '44,8' => 44.8 }.each do |key, value|
it "should normalize '#{key}' to '#{value}'" do
user = User.new(:price => key)
user.price.should == value
end
end
end
#...
# Added in the price column
ActiveRecord::Schema.define do
create_table :users, :force => true do |t|
t.string :name
t.float :price
end
end
#...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment