Skip to content

Instantly share code, notes, and snippets.

@prakashmurthy
Last active August 17, 2016 13:54
Show Gist options
  • Save prakashmurthy/474966b0e2fcab1e4fbd055908dce4e5 to your computer and use it in GitHub Desktop.
Save prakashmurthy/474966b0e2fcab1e4fbd055908dce4e5 to your computer and use it in GitHub Desktop.
Files for adding a new test in rails codebase
# activerecord/test/cases/decimal_rounding_test.rb
require "cases/helper"
require "models/thing"
class DecimalRoundingTest < ActiveRecord::TestCase
ActiveRecord::Schema.define do
create_table :things, force: true do |t|
t.decimal :price, precision: 4, scale: 4
end
end
def test_decimal_rounding
thing = Thing.create!
thing.price = 0.00001
assert_equal '0.00001', thing.price.to_s
end
end
# activerecord/test/models/thing.rb
class Thing < ActiveRecord::Base
end
# Script to run the above test
bundle exec ruby -I activerecord/lib:activerecord/test activerecord/test/cases/decimal_rounding_test.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment