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-3.0.0 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.13.0 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.12.5 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.12.4 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.12.3 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.12.2 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.12.1 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.12.0 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.11.9 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.11.8 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.11.7 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.11.6 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.11.5 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.11.4 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.11.3 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.11.2 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.11.1 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.11.0 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.10.11 test/unit/belongs_to_test.rb
gotime-cassandra_object-2.10.10 test/unit/belongs_to_test.rb