Sha256: 82d5a21341f688c98c1562e14335f4059a804ec15d85e63a74f7aaac55e02400

Contents?: true

Size: 1.16 KB

Versions: 47

Compression:

Stored size: 1.16 KB

Contents

require 'test_helper'

class CassandraObject::BelongsToTest < CassandraObject::TestCase
  class TestObject < Issue
    string :issue_id
    belongs_to :issue

    string :widget_id
    belongs_to :widget, class_name: 'Issue'

    string :target_id
    string :target_type
    belongs_to :target, polymorphic: true
  end

  test 'belongs_to' do
    issue = Issue.create

    record = TestObject.create(issue: issue)

    assert_equal issue, record.issue
    assert_equal issue.id, record.issue_id

    record = TestObject.find(record.id)
    assert_equal issue, record.issue
  end

  test 'belongs_to with class_name' do
    issue = Issue.create

    record = TestObject.create(widget: issue)

    assert_equal issue, record.widget
    assert_equal issue.id, record.widget_id

    record = TestObject.find(record.id)
    assert_equal issue, record.widget
  end

  test 'belongs_to with polymorphic' do
    issue = Issue.create

    record = TestObject.create(target: issue)

    assert_equal issue, record.target
    assert_equal issue.id, record.target_id
    assert_equal 'Issue', record.target_type

    record = TestObject.find(record.id)
    assert_equal issue, record.target
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

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