Sha256: 8e811653133684fdb47f39756ec5bb24b079533049b9cdc633e3278c3e9e5b02

Contents?: true

Size: 780 Bytes

Versions: 2

Compression:

Stored size: 780 Bytes

Contents

require 'test_helper'

class Superstore::Associations::BelongsTest < Superstore::TestCase
  class TestObject < Superstore::Base
    self.table_name = 'issues'
    attribute :user_id, type: :string
    belongs_to :user, primary_key: :special_id
  end

  test 'belongs_to' do
    user = User.create(special_id: 'abc')
    issue = TestObject.create(user: user)

    assert_equal user, issue.user
    assert_equal issue.user_id, 'abc'

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

  test 'belongs_to clear cache after reload' do
    user = User.create(special_id: 'abc')
    issue = TestObject.create(user: user)
    user.destroy

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
superstore-3.0.0 test/unit/associations/belongs_to_test.rb
superstore-2.5.0 test/unit/associations/belongs_to_test.rb