Sha256: a4141d8fc61315f17c1d7144e8027ae499543b5b53d771d1a791b7c381a234eb

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

describe UnscopedAssociations do
  let(:user) { User.create active: false }
  let(:comment) { Comment.create user_id: user.id, public: false }
  let(:user_vote) { user.votes.create public: false }
  let(:comment_vote) { comment.votes.create }

  context 'a belongs to association' do
    subject { comment }

    context 'scoped' do
      its(:user) { should be_nil }
      its(:scoped_user) { should be_nil }
    end

    context 'unscoped' do
      its(:unscoped_user) { should eq user }
    end
  end

  context 'a has one association' do
    subject { user }

    context 'scoped' do
      its(:last_comment) { should be_nil }
    end

    context 'unscoped' do
      its(:unscoped_last_comment) { should eq comment }
    end
  end

  context 'a has many association' do
    subject { user }

    context 'scoped' do
      its(:comments) { should be_empty }

      context 'with an extension' do
        its('comments.today') { should be_empty }
      end
    end

    context 'unscoped' do
      its(:unscoped_comments) { should eq [comment] }

      context 'with an extension' do
        # Extended methods take the default_scope
        its('unscoped_comments.today') { should be_empty }
        # Ideally, it should skip the default_scope
        # its('unscoped_comments.today') { should eq [comment] }
      end
    end
  end

  context 'has_many with unscoped polymorphic' do
    subject { user }

    context 'unscoped_votable' do
      its(:votes) { should eq [user_vote] }
    end
  end

  context 'belongs_to with unscoped polymorphic' do
    subject { comment_vote }

    context 'unscoped_votable' do
      its(:votable) { should eq comment }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unscoped_associations-0.6.4 spec/unscoped_associations_spec.rb
unscoped_associations-0.6.3 spec/unscoped_associations_spec.rb