aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/type/integer_test.rb
blob: 13d6d2093ba6d935b3c92604edc6a77e6911a165 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true
require "cases/helper"
require "models/company"

module ActiveRecord
  module Type
    class IntegerTest < ActiveRecord::TestCase
      test "casting ActiveRecord models" do
        type = Type::Integer.new
        firm = Firm.create(name: "Apple")
        assert_nil type.cast(firm)
      end

      test "values which are out of range can be re-assigned" do
        klass = Class.new(ActiveRecord::Base) do
          self.table_name = "posts"
          attribute :foo, :integer
        end
        model = klass.new

        model.foo = 2147483648
        model.foo = 1

        assert_equal 1, model.foo
      end
    end
  end
end