Last active
August 16, 2016 20:40
-
-
Save prakashmurthy/d03093d8f7f135ad91e5567308a61428 to your computer and use it in GitHub Desktop.
Executable script for https://github.com/rails/rails/issues/26108
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
# decimal_rounding_error.rb | |
# Script for https://github.com/rails/rails/issues/26108 | |
############################################################################## | |
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" | |
# gem 'rails', '5.0.0' # fails | |
# gem 'rails', '4.2.7.1' # fails | |
# gem "rails", '4.2.1' # works | |
# gem "rails", github: "rails/rails", branch: '4-2-stable' # works | |
gem "rails", github: "rails/rails", branch: '4-1-stable' # fails | |
gem "sqlite3" | |
gem 'pry' | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :things, force: true do |t| | |
t.decimal :price, precision: 4, scale: 4 | |
end | |
end | |
class Thing < ActiveRecord::Base | |
end | |
class BugTest < Minitest::Test | |
def test_decimal_rounding | |
thing = Thing.create! | |
thing.price = 0.0001 | |
assert_equal '0.0001', thing.price.to_s | |
thing.price = 0.00001 | |
assert_equal '0.00001', thing.price.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment