Sha256: 150fd762b01fab2f6de837e871626f99898b4740a67e7471622ff2a455c94af0

Contents?: true

Size: 1.65 KB

Versions: 75

Compression:

Stored size: 1.65 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 "removes 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 "is able to skip a missing model" do
        expect(described_class.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 "removes 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

75 entries across 75 versions & 1 rubygems

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