Sha256: a831ee211fe56fe9b9143c5bf34c5798c692e022947ae9bc0139896a9157a8ed
Contents?: true
Size: 1.61 KB
Versions: 5
Compression:
Stored size: 1.61 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 '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 nil' 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
5 entries across 5 versions & 1 rubygems