Sha256: 7f77f2d9afeda8eb5d51a42de6bf027186c87c49036127e6af38e3304f772fbc

Contents?: true

Size: 762 Bytes

Versions: 11

Compression:

Stored size: 762 Bytes

Contents

require 'test_helper'

class Superstore::Associations::BelongsTest < Superstore::TestCase
  class TestObject < Superstore::Base
    self.table_name = 'issues'
    string :user_id
    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

11 entries across 11 versions & 1 rubygems

Version Path
superstore-2.4.4 test/unit/associations/belongs_to_test.rb
superstore-2.4.3 test/unit/associations/belongs_to_test.rb
superstore-2.4.2 test/unit/associations/belongs_to_test.rb
superstore-2.4.1 test/unit/associations/belongs_to_test.rb
superstore-2.4.0 test/unit/associations/belongs_to_test.rb
superstore-2.3.0 test/unit/associations/belongs_to_test.rb
superstore-2.2.0 test/unit/associations/belongs_to_test.rb
superstore-2.1.3 test/unit/associations/belongs_to_test.rb
superstore-2.1.2 test/unit/associations/belongs_to_test.rb
superstore-2.1.1 test/unit/associations/belongs_to_test.rb
superstore-2.1.0 test/unit/associations/belongs_to_test.rb