Skip to content

Instantly share code, notes, and snippets.

@axlekb
Last active April 25, 2018 20:10

Revisions

  1. axlekb revised this gist Apr 25, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bug_test.rb
    Original file line number Diff line number Diff line change
    @@ -48,7 +48,7 @@ class Payment < ActiveRecord::Base

    class BugTest < Minitest::Test
    def test_numeric_validation
    payment = Payment.create!(:cash: 2.0)
    payment = Payment.create!(cash: 2.0)

    payment.reload

  2. axlekb revised this gist Apr 11, 2018. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions bug_test.rb
    Original file line number Diff line number Diff line change
    @@ -48,8 +48,7 @@ class Payment < ActiveRecord::Base

    class BugTest < Minitest::Test
    def test_numeric_validation
    payment = Payment.create!
    payment.update_column(:cash, 2.0)
    payment = Payment.create!(:cash: 2.0)

    payment.reload

  3. axlekb created this gist Apr 11, 2018.
    59 changes: 59 additions & 0 deletions bug_test.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    # 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!
    payment.update_column(:cash, 2.0)

    payment.reload

    assert payment.cash == 2.0
    assert payment.valid?
    end
    end