Sha256: fcece3c19f4aa8b5cfef7e77104fefe24de82e9fc618c45e2498b6acbac1857c

Contents?: true

Size: 1.5 KB

Versions: 35

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

describe ActiveFedora::Base do
  before(:all) do
    class TestClass < ActiveFedora::Base
      property :foo, predicate: ::RDF::URI('http://example.com/foo')
      property :bar, predicate: ::RDF::URI('http://example.com/bar') do |index|
        index.as :stored_searchable
      end

      def to_solr(doc = {})
        doc = super
        doc[ActiveFedora.index_field_mapper.solr_name('foo', :sortable)] = doc[ActiveFedora.index_field_mapper.solr_name('foo', type: :string)]
        doc
      end
    end
  end

  after(:all) do
    Object.send(:remove_const, :TestClass)
  end

  describe "with multiple objects" do
    let!(:instance1) { TestClass.create!(foo: ['Beta'], bar: ['Chips']) }
    let!(:instance2) { TestClass.create!(foo: ['Alpha'], bar: ['Peanuts']) }
    let!(:instance3) { TestClass.create!(foo: ['Sigma'], bar: ['Peanuts']) }

    subject(:peanuts) { TestClass.where(bar: 'Peanuts') }

    it "maps" do
      expect(peanuts.map(&:id)).to contain_exactly instance2.id, instance3.id
    end

    it "collects" do
      expect(peanuts.collect(&:id)).to contain_exactly instance2.id, instance3.id
    end

    it "has each" do
      expect(peanuts.each.to_a.length).to eq 2
    end

    it "has all?" do
      expect(peanuts.all? { |t| t.foo == ['Alpha'] }).to be false
      expect(peanuts.all? { |t| t.bar == ['Peanuts'] }).to be true
    end

    it "has include?" do
      expect(peanuts.include?(instance1)).to be false
      expect(peanuts.include?(instance2)).to be true
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

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