Sha256: 4adb70375f41f7c809dc63cac9332c5e54b5b94f4603715587d18cfed75a3b63

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'

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

  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unscoped_associations-0.6.2 spec/unscoped_associations_spec.rb