Skip to content

Instantly share code, notes, and snippets.

@edzhelyov
Created August 22, 2018 08:12
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 edzhelyov/ffdbc26ffc6dc218c8764dd50f6cc0e7 to your computer and use it in GitHub Desktop.
Save edzhelyov/ffdbc26ffc6dc218c8764dd50f6cc0e7 to your computer and use it in GitHub Desktop.
Bug report for ActiveModel 5.2.1 and ActiveAttr
# 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" }
gem "activemodel", "5.2.1"
gem "active_attr"
gem "shoulda-matchers", github: 'thoughtbot/shoulda-matchers'
gem 'minitest-matchers_vaccine'
end
require 'active_support'
require "active_attr"
require 'shoulda-matchers'
require "minitest/autorun"
require "logger"
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :minitest
with.library :active_model
end
end
class User
include ActiveAttr::Model
attribute :account_crn, type: Integer
attribute :total, type: Integer, default: 0
validates :account_crn, presence: true, numericality: {only_integer: true}
validates :total, presence: true, numericality: {greater_than: 0}
end
class BugTest < Minitest::Test
def test_shoulda_numericality
user = User.new account_crn: 1, total: 10
assert_must validate_numericality_of(:account_crn), user
end
def test_shoulda_numericality_greater_than
user = User.new account_crn: 1, total: 10
assert_must validate_numericality_of(:total).is_greater_than(0), user
end
def test_validate_numericality
user = User.new account_crn: 1.1, total: 10
user.validate
assert_equal ['must be an integer'], user.errors[:account_crn]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment