Sha256: 2bc0c980da97a931b919b257ad799fe5c2c054e3413fd1e69e1635415bf55335

Contents?: true

Size: 1.42 KB

Versions: 24

Compression:

Stored size: 1.42 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

  test 'belongs_to clear cache after reload' do
    issue = Issue.create
    record = TestObject.create(issue: issue)
    issue.destroy

    assert_not_nil record.issue
    assert_nil TestObject.find(record.id).issue
    assert_nil record.reload.issue
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
gotime-cassandra_object-4.12.2 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.12.1 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.12.0 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.11.6 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.11.5 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.11.4 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.11.3 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.11.2 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.11.1 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.11.0 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.10.5 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.10.4 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.10.3 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.10.2 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.10.1 test/unit/belongs_to_test.rb
cassandra_object_rails-0.0.1 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.10.0 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.9.2 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.9.1 test/unit/belongs_to_test.rb
gotime-cassandra_object-4.9.0 test/unit/belongs_to_test.rb