Sha256: 18a9b6df1a5d0d5a9933409942709a10e7b9e5d8429b3021888b0f3d8256987a

Contents?: true

Size: 1.35 KB

Versions: 21

Compression:

Stored size: 1.35 KB

Contents

require 'test_helper'

class CassandraObject::AttributeMethods::DirtyTest < CassandraObject::TestCase
  test 'save clears dirty' do
    record = temp_object do
      string :name
    end.new name: 'foo'

    assert record.changed?

    record.save!

    assert !record.changed?
  end

  test 'reload clears dirty' do
    record = temp_object do
      string :name
    end.create! name: 'foo'

    record.name = 'bar'
    assert record.changed?

    record.reload

    assert !record.changed?
  end

  test 'typecast float before dirty check' do
    record = temp_object do
      float :price
    end.create(price: 5.01)

    record.price = '5.01'
    assert !record.changed?

    record.price = '7.12'
    assert record.changed?
  end

  test 'typecast boolean before dirty check' do
    record = temp_object do
      boolean :awesome
    end.create(awesome: false)

    record.awesome = false
    assert !record.changed?

    record.awesome = true
    assert record.changed?
  end

  test 'write_attribute' do
    object = temp_object do
      string :name
    end

    expected = {"name"=>[nil, "foo"]}

    object.new.tap do |record|
      record.name = 'foo'
      assert_equal expected, record.changes
    end

    object.new.tap do |record|
      record[:name] = 'foo'
      # record.write_attribute(:name, 'foo')
      assert_equal expected, record.changes
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
gotime-cassandra_object-4.11.3 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.11.2 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.11.1 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.11.0 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.10.5 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.10.4 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.10.3 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.10.2 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.10.1 test/unit/attribute_methods/dirty_test.rb
cassandra_object_rails-0.0.1 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.10.0 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.9.2 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.9.1 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.9.0 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.8.1 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.8.0 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.7.3 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.7.2 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.7.1 test/unit/attribute_methods/dirty_test.rb
gotime-cassandra_object-4.7.0 test/unit/attribute_methods/dirty_test.rb