Sha256: 1014dfc6016549922b02b762ecaff36a14cb6ab9a74b2d8e05a7e813536169ce

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe UnscopedAssociations do
  context 'unscoped association omits default_scope' do
    it 'belongs_to' do
      user = User.creatse(active: false)
      comment = Comment.create(user_id: user.id)

      expect(comment.unscoped_user).to eq(user)
    end

    it 'has_many' do
      user = User.create
      comment = Comment.create(user_id: user.id, public: false)

      expect(user.unscoped_comments).to be_present
    end

    it 'has_one' do
      user = User.create
      comment = Comment.create(user_id: user.id, public: false)

      expect(user.unscoped_last_comment).to be_present
    end
  end

  context 'no unscoped association takes default_scope' do
    it 'belongs_to' do
      user = User.create(active: false)
      comment = Comment.create(user_id: user.id)

      expect(comment.user).to be_nil
      expect(comment.scoped_user).to be_nil
    end

    it 'has_many' do
      user = User.create
      comment = Comment.create(user_id: user.id, public: false)

      expect(user.comments).to be_empty
    end

    it 'has_one' do
      user = User.create
      comment = Comment.create(user_id: user.id, public: false)

      expect(user.last_comment).to be_nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unscoped_associations-0.6.0 spec/unscoped_associations_spec.rb