Skip to content

Instantly share code, notes, and snippets.

@axlekb
Last active April 25, 2018 20:10
Show Gist options
  • Save axlekb/6dfbfa45dd5e6137cb172e9cb37f4909 to your computer and use it in GitHub Desktop.
Save axlekb/6dfbfa45dd5e6137cb172e9cb37f4909 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
gem "bundler", "< 1.16"
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"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "pg", "<1.0"
#gem "rails", "5.1.4" # success!
gem "rails", "5.2.0" # fails!
end
require "active_record"
require "minitest/autorun"
require "logger"
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
ActiveRecord::Base.establish_connection(
adapter: "postgresql",
database: "rails_test",
username: "user",
password: "",
host: 'localhost'
)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :payments, force: true do |t|
t.money :cash
end
end
class Payment < ActiveRecord::Base
validates :cash, numericality: true, unless: :new_record?
end
class BugTest < Minitest::Test
def test_numeric_validation
payment = Payment.create!(cash: 2.0)
payment.reload
assert payment.cash == 2.0
assert payment.valid?
end
end
@arkiver
Copy link

arkiver commented Apr 12, 2018

Found a syntax error -
https://gist.github.com/axlekb/6dfbfa45dd5e6137cb172e9cb37f4909#file-bug_test-rb-L51
Should be Payment.create!(cash: 2.0)

test.rb:49: syntax error, unexpected ':', expecting ')'
    payment = Payment.create!(:cash: 2.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment