Skip to content

Instantly share code, notes, and snippets.

@zarqman
Created August 18, 2018 23:45
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 zarqman/075179677c21c7aa58d7a7ba3376bac9 to your computer and use it in GitHub Desktop.
Save zarqman/075179677c21c7aa58d7a7ba3376bac9 to your computer and use it in GitHub Desktop.
Rails 5.2.1 / Mongoid 7.0.1 incompatibility
# frozen_string_literal: true
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" }
# Activate the gem you are reporting the issue against.
gem "activemodel", "5.2.1"
gem "activerecord", "5.2.1"
gem "mongoid", "7.0.1"
gem "sqlite3"
end
require "active_model"
require "active_record"
require "mongoid"
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: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :items, force: true do |t|
t.integer :quantity
end
end
class Item < ActiveRecord::Base
validates :quantity,
numericality: {only_integer: true, greater_than: 0}
end
class Item1
include ActiveModel::Model
attr_accessor :quantity
validates :quantity,
numericality: {only_integer: true, greater_than: 0}
end
class Item2
include Mongoid::Document
field :quantity, type: Integer
validates :quantity,
numericality: {only_integer: true, greater_than: 0}
end
class BugTest < Minitest::Test
def test_active_record
item = Item.new(quantity: 1)
assert item.valid?
item = Item.new(quantity: 'invalid')
refute item.valid?
assert_match /not a number/, item.errors.to_a.first
end
def test_active_model
item = Item1.new(quantity: 1)
assert item.valid?
item = Item1.new(quantity: 'invalid')
refute item.valid?
assert_match /not a number/, item.errors.to_a.first
end
def test_mongoid
item = Item2.new(quantity: 1)
assert item.valid?
item = Item2.new(quantity: 'invalid')
refute item.valid?
assert_match /not a number/, item.errors.to_a.first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment