Sha256: 209d4259496cc6cf1f990c7b7e9a9c7039c562105200fa8317f2bd440ea4266c

Contents?: true

Size: 1.67 KB

Versions: 33

Compression:

Stored size: 1.67 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!(:id) { model3.id }

      before { Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, model3.uri).delete }

      after do
        ActiveFedora::SolrService.instance.conn.tap do |conn|
          conn.delete_by_query "id:\"#{id}\""
          conn.commit
        end
      end

      it "should be able to skip a missing model" do
        expect(ActiveFedora::Base.logger).to receive(:error).with("Although #{id} 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

33 entries across 33 versions & 1 rubygems

Version Path
active-fedora-9.0.8 spec/integration/delete_all_spec.rb
active-fedora-9.5.0 spec/integration/delete_all_spec.rb
active-fedora-9.4.3 spec/integration/delete_all_spec.rb
active-fedora-9.4.2 spec/integration/delete_all_spec.rb
active-fedora-9.4.1 spec/integration/delete_all_spec.rb
active-fedora-9.4.0 spec/integration/delete_all_spec.rb
active-fedora-9.3.0 spec/integration/delete_all_spec.rb
active-fedora-9.2.1 spec/integration/delete_all_spec.rb
active-fedora-9.2.0 spec/integration/delete_all_spec.rb
active-fedora-9.2.0.rc2 spec/integration/delete_all_spec.rb
active-fedora-9.2.0.rc1 spec/integration/delete_all_spec.rb
active-fedora-9.1.2 spec/integration/delete_all_spec.rb
active-fedora-9.1.1 spec/integration/delete_all_spec.rb
active-fedora-9.1.0 spec/integration/delete_all_spec.rb
active-fedora-9.1.0.rc1 spec/integration/delete_all_spec.rb
active-fedora-9.0.6 spec/integration/delete_all_spec.rb
active-fedora-9.0.5 spec/integration/delete_all_spec.rb
active-fedora-9.0.4 spec/integration/delete_all_spec.rb
active-fedora-9.0.3 spec/integration/delete_all_spec.rb
active-fedora-9.0.2 spec/integration/delete_all_spec.rb