Sha256: 0f85139d6b496896bbb5d99efe0c959e161dd955a48f094813f02015d2a03eff

Contents?: true

Size: 1.7 KB

Versions: 18

Compression:

Stored size: 1.7 KB

Contents

require 'test_helper'

class CassandraObject::Types::ArrayTypeTest < CassandraObject::Types::TestCase
  test 'encode' do
    assert_equal ['1', '2'].to_json, coder.encode(['1', '2'])
    
    assert_raise ArgumentError do
      coder.encode('wtf')
    end
  end

  test 'decode' do
    assert_equal ['1', '2'], coder.decode(['1', '2'].to_json)
    assert_equal [], coder.decode(nil)
    assert_equal [], coder.decode('')
  end

  class TestIssue < CassandraObject::Base
    self.column_family = 'Issues'
    array :favorite_colors, unique: true
  end

  test 'default' do
    assert_equal [], TestIssue.new.favorite_colors
  end

  test 'append marks dirty' do
    issue = TestIssue.create favorite_colors: []
    assert !issue.changed?

    issue.favorite_colors << 'red'
    assert issue.changed?
    assert_equal({'favorite_colors' => [[], ['red']]}, issue.changes)
  end

  test 'delete marks dirty' do
    issue = TestIssue.create favorite_colors: ['red']
    assert !issue.changed?

    issue.favorite_colors.delete('red')
    assert issue.changed?
    assert_equal({'favorite_colors' => [['red'], []]}, issue.changes)
  end

  test 'unique array removes blank' do
    issue = TestIssue.create favorite_colors: ['blue', 'red', '', nil]
    assert_equal ['blue', 'red'], issue.favorite_colors
  end

  test 'unique array uniquifies' do
    issue = TestIssue.create favorite_colors: ['blue', 'red']
    
    issue.favorite_colors = ['red', 'red', 'blue']
    assert !issue.changed?
    
    issue.favorite_colors = ['red', 'green']
    assert issue.changed?
  end

  test 'unique array rescues argument error' do
    issue = TestIssue.create favorite_colors: [1, 'red']

    assert_equal [1, 'red'], issue.favorite_colors
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
gotime-cassandra_object-4.5.1 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.5.0 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.4.5 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.4.4 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.4.3 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.4.0 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.3.2 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.3.1 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.3.0 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.2.2 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.2.0 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.1.0 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.0.2 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.0.1 test/unit/types/array_type_test.rb
gotime-cassandra_object-4.0.0 test/unit/types/array_type_test.rb
gotime-cassandra_object-3.0.5 test/unit/types/array_type_test.rb
gotime-cassandra_object-3.0.4 test/unit/types/array_type_test.rb
gotime-cassandra_object-3.0.3 test/unit/types/array_type_test.rb