Skip to content

Instantly share code, notes, and snippets.

@skiningham
Created March 16, 2017 05:17
Show Gist options
  • Save skiningham/83f51884b1441bcf9e75703ea53fa811 to your computer and use it in GitHub Desktop.
Save skiningham/83f51884b1441bcf9e75703ea53fa811 to your computer and use it in GitHub Desktop.
Reproduction script for unable to select certain numeric values
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"
# Activate the gem you are reporting the issue against.
gem "activerecord", "5.0.2"
gem "pg"
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(adapter: "postgresql", database: "issue_reproduction_development", encoding: "utf8", pool: 5, timeout: 5000, host: "localhost")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :test_models do |t|
t.numeric :value
t.timestamps
end
end
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class TestModel < ApplicationRecord
end
class BugTest < Minitest::Test
def test_numeric_conditions
TestModel.create!(value: 1.8)
TestModel.create!(value: 2.6) # Also fails for 0.8 and 0.6??
assert_equal true, TestModel.exists?(value: '1.8')
assert_equal true, TestModel.exists?(value: '2.6')
assert_equal true, TestModel.exists?(value: 1.8)
assert_equal true, TestModel.exists?(value: 2.6)
end
end
Copy link

ghost commented Mar 19, 2017

I run the numbers from 0.0 to 9.9. 100 assertions, 76 failures.
0.0, 0.5, 1.0, 1.5 .. to 9.5 (all increments by 0.5 passed), and these numbers 1.2, 1.3, 1.7, 1.8 also passed.

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