Sha256: 10041461eeb8ac2ebc866361282a8df0a1148e19daf56d10e8cef4858cd4e67c

Contents?: true

Size: 1.48 KB

Versions: 64

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe ActiveFedora::Scoping::Default do
  describe "when default_scope is overridden" do
    before do
      class Book < ActiveFedora::Base
        property :published, predicate: ::RDF::Vocab::EBUCore.pubStatus do |index|
          index.as :symbol
        end

        def self.default_scope
          where published_ssim: 'true'
        end
      end

      Book.destroy_all
      Book.create!(published: [true])
      Book.create!(published: [true])
      Book.create!(published: [false])
    end

    after do
      Object.send(:remove_const, :Book)
    end

    it "returns only the scoped records" do
      expect(Book.all.size).to eq 2
    end

    it "returns all the records" do
      Book.unscoped do
        expect(Book.all.size).to eq 3
      end
    end
  end

  describe "when default_scope is called" do
    before do
      class Book < ActiveFedora::Base
        property :published, predicate: ::RDF::Vocab::EBUCore.pubStatus do |index|
          index.as :symbol
        end

        default_scope -> { where published_ssim: 'true' }
      end

      Book.destroy_all
      Book.create!(published: [true])
      Book.create!(published: [true])
      Book.create!(published: [false])
    end

    after do
      Object.send(:remove_const, :Book)
    end

    it "returns only the scoped records" do
      expect(Book.all.size).to eq 2
    end

    it "returns all the records" do
      Book.unscoped do
        expect(Book.all.size).to eq 3
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
active-fedora-12.2.4 spec/unit/scoping_spec.rb
active-fedora-12.2.3 spec/unit/scoping_spec.rb
active-fedora-11.5.6 spec/unit/scoping_spec.rb
active-fedora-12.2.2 spec/unit/scoping_spec.rb
active-fedora-11.2.1 spec/unit/scoping_spec.rb
active-fedora-12.2.1 spec/unit/scoping_spec.rb
active-fedora-12.0.3 spec/unit/scoping_spec.rb
active-fedora-11.5.5 spec/unit/scoping_spec.rb
active-fedora-13.1.2 spec/unit/scoping_spec.rb
active-fedora-13.1.1 spec/unit/scoping_spec.rb
active-fedora-13.1.0 spec/unit/scoping_spec.rb
active-fedora-13.0.0 spec/unit/scoping_spec.rb
active-fedora-12.1.1 spec/unit/scoping_spec.rb
active-fedora-12.1.0 spec/unit/scoping_spec.rb
active-fedora-11.5.4 spec/unit/scoping_spec.rb
active-fedora-11.5.3 spec/unit/scoping_spec.rb
active-fedora-12.0.2 spec/unit/scoping_spec.rb
active-fedora-12.0.1 spec/unit/scoping_spec.rb
active-fedora-11.5.2 spec/unit/scoping_spec.rb
active-fedora-12.0.0 spec/unit/scoping_spec.rb