Sha256: ecae86c25e2c4c15fc7511894fa842882b14a9b0302d3cdb74d2c756e92698d4

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'test_helper'

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

  class TestIssue < CassandraObject::Base
    self.column_family = 'Issue'
    attribute :custom_column, type: CustomType, coder: CustomCoder
    integer :price
  end

  class TestChildIssue < TestIssue
    string :description
  end

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

    assert_kind_of CustomCoder, model_attribute.coder
    assert_equal CustomType, model_attribute.expected_type
  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

1 entries across 1 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.6.0 test/attributes_test.rb