Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephen-puiszis/e7cdf547facd5c2cc90b1acfc1176b2c to your computer and use it in GitHub Desktop.
Save stephen-puiszis/e7cdf547facd5c2cc90b1acfc1176b2c to your computer and use it in GitHub Desktop.
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 'activerecord', '5.0.0.1'
gem 'pg', '~> 0.18'
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection('postgres://username:password@hostname/dbname')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :items, force: true do |t|
t.money :price
end
end
class Item < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_price_as_int
item = Item.create!(price: 45)
assert_equal 45.to_d, item.reload.price
end
def test_price_as_string
item = Item.create!(price: '34.33')
assert_equal 34.33.to_d, item.reload.price
end
def test_price_as_string_with_dollar_sign
item = Item.create!(price: '$12.12')
assert_equal 12.12.to_d, item.reload.price
end
def test_price_as_float
item = Item.create!(price: 14.0)
assert_equal 14.0.to_d, item.reload.price
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment