Sha256: d8d92da0508301bf583b031c68aa595e3b4ede01d1702eebe0b99980290e97fb

Contents?: true

Size: 1.64 KB

Versions: 8

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

describe ActiveFedora::Base do
  
  before(:all) do
    module SpecModel
      class Basic < ActiveFedora::Base
        class_attribute :callback_counter
        
        before_destroy :inc_counter

        def inc_counter
          self.class.callback_counter += 1
        end
      end
    end
  end
  
  after(:all) do
    Object.send(:remove_const, :SpecModel)
  end

  let!(:model1) { SpecModel::Basic.create! }
  let!(:model2) { SpecModel::Basic.create! }

  before do
    SpecModel::Basic.callback_counter = 0
  end


  describe ".destroy_all" do
    it "should remove both and run callbacks" do 
      SpecModel::Basic.destroy_all
      expect(SpecModel::Basic.count).to eq(0) 
      expect(SpecModel::Basic.callback_counter).to eq(2)
    end

    describe "when a model is missing" do
      let(:model3) { SpecModel::Basic.create! }
      let!(:pid) { model3.pid }
      before { model3.inner_object.delete }
      after do
        ActiveFedora::SolrService.instance.conn.tap do |conn|
          conn.delete_by_query "id:\"#{pid}\""
          conn.commit
        end
      end
      it "should be able to skip a missing model" do 
        expect(ActiveFedora::Base.logger).to receive(:error).with("Although #{pid} was found in Solr, it doesn't seem to exist in Fedora. The index is out of synch.")
        SpecModel::Basic.destroy_all
        expect(SpecModel::Basic.count).to eq(1) 
      end
    end
  end

  describe ".delete_all" do
    it "should remove both and not run callbacks" do 
      SpecModel::Basic.delete_all
      expect(SpecModel::Basic.count).to eq(0)
      expect(SpecModel::Basic.callback_counter).to eq(0)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active-fedora-8.7.0 spec/integration/delete_all_spec.rb
active-fedora-8.6.0 spec/integration/delete_all_spec.rb
active-fedora-8.5.0 spec/integration/delete_all_spec.rb
active-fedora-8.4.2 spec/integration/delete_all_spec.rb
active-fedora-8.4.1 spec/integration/delete_all_spec.rb
active-fedora-8.4.0 spec/integration/delete_all_spec.rb
active-fedora-8.3.0 spec/integration/delete_all_spec.rb
active-fedora-8.2.2 spec/integration/delete_all_spec.rb