Sha256: 0338399e9ce36e7b474fa77fc0a48eaf95cc1949d74c1cb4105282d61f8e199d

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

require 'test_helper'

class CassandraObject::AttributeMethodsTest < CassandraObject::TestCase
  class CustomType
  end
  
  class CustomCoder < CassandraObject::Types::BaseType
  end

  class TestIssue < CassandraObject::Base
    key :uuid
    self.column_family = 'Issues'

    attribute :custom_column, type: CustomType, coder: CustomCoder
    integer :price
    json :orders
  end

  class TestChildIssue < TestIssue
    string :description
  end

  test 'custom attribute definer' do
    model_attribute = TestIssue.attribute_definitions[:custom_column]

    assert_kind_of CustomCoder, model_attribute.coder
    assert_equal 'custom_column', model_attribute.name
  end

  test 'json attribute' do
    issue = TestIssue.create! orders: {'a' => 'b'}

    issue = TestIssue.find issue.id

    assert_equal({'a' => 'b'}, issue.orders)
  end

  test 'instantiate_attribute' do
    assert_equal 1, TestIssue.instantiate_attribute(TestIssue.new, 'price', 1)
    assert_equal 1, TestIssue.instantiate_attribute(TestIssue.new, :price, 1)

    assert_raise NoMethodError do
      TestIssue.instantiate_attribute(TestIssue.new, 'wtf', 1)
    end
  end

  test 'attributes not shared' do
    assert_nothing_raised { Issue.new.description }
    assert_raise(NoMethodError) { TestIssue.new.description }
    assert_nothing_raised { TestChildIssue.new.description }
  end

  test 'attributes setter' do
    issue = Issue.new

    issue.attributes = {
      description: 'foo'
    }

    assert_equal 'foo', issue.description
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.7.8 test/attribute_methods_test.rb
gotime-cassandra_object-2.7.7 test/attribute_methods_test.rb
gotime-cassandra_object-2.7.6 test/attribute_methods_test.rb
gotime-cassandra_object-2.7.5 test/attribute_methods_test.rb
gotime-cassandra_object-2.7.4 test/attribute_methods_test.rb
gotime-cassandra_object-2.7.3 test/attribute_methods_test.rb