class ActiveRecord::ConnectionAdapters::TypeCastingTest

Public Instance Methods

id() click to toggle source
# File activerecord/test/cases/quoting_test.rb, line 217
def id
  10
end
quoted_id() click to toggle source
# File activerecord/test/cases/quoting_test.rb, line 213
def quoted_id
  "'zomg'"
end
setup() click to toggle source
# File activerecord/test/cases/quoting_test.rb, line 169
def setup
  @conn = ActiveRecord::Base.connection
end
test_type_cast_date() click to toggle source
# File activerecord/test/cases/quoting_test.rb, line 177
def test_type_cast_date
  date = Date.today
  if current_adapter?(:Mysql2Adapter)
    expected = date
  else
    expected = @conn.quoted_date(date)
  end
  assert_equal expected, @conn.type_cast(date)
end
test_type_cast_nil() click to toggle source
# File activerecord/test/cases/quoting_test.rb, line 202
def test_type_cast_nil
  assert_nil @conn.type_cast(nil)
end
test_type_cast_numeric() click to toggle source
# File activerecord/test/cases/quoting_test.rb, line 197
def test_type_cast_numeric
  assert_equal 10, @conn.type_cast(10)
  assert_equal 2.2, @conn.type_cast(2.2)
end
test_type_cast_object_which_responds_to_quoted_id() click to toggle source
# File activerecord/test/cases/quoting_test.rb, line 211
def test_type_cast_object_which_responds_to_quoted_id
  quoted_id_obj = Class.new {
    def quoted_id
      "'zomg'"
    end

    def id
      10
    end
  }.new
  assert_equal 10, @conn.type_cast(quoted_id_obj)

  quoted_id_obj = Class.new {
    def quoted_id
      "'zomg'"
    end
  }.new
  assert_raise(TypeError) { @conn.type_cast(quoted_id_obj) }
end
test_type_cast_symbol() click to toggle source
# File activerecord/test/cases/quoting_test.rb, line 173
def test_type_cast_symbol
  assert_equal "foo", @conn.type_cast(:foo)
end
test_type_cast_time() click to toggle source
# File activerecord/test/cases/quoting_test.rb, line 187
def test_type_cast_time
  time = Time.now
  if current_adapter?(:Mysql2Adapter)
    expected = time
  else
    expected = @conn.quoted_date(time)
  end
  assert_equal expected, @conn.type_cast(time)
end
test_type_cast_unknown_should_raise_error() click to toggle source
# File activerecord/test/cases/quoting_test.rb, line 206
def test_type_cast_unknown_should_raise_error
  obj = Class.new.new
  assert_raise(TypeError) { @conn.type_cast(obj) }
end