Sha256: 510f39235b42b0bd2f56d1383f291009e952cb72e8c0d61faeb992be1cb3561b

Contents?: true

Size: 1.31 KB

Versions: 14

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'

describe ActiveFedora::Base do
  before :all do
    class ValidationStub < ActiveFedora::Base
      property :fubar, predicate: ::RDF::URI('http://example.com/fubar')
      property :swank, predicate: ::RDF::URI('http://example.com/swank'), multiple: false

      validates_presence_of :fubar
      validates_length_of :swank, minimum: 5
    end
  end

  subject { ValidationStub.new }

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

  describe "a valid object" do
    before do
      subject.attributes = { fubar: ['here'], swank: 'long enough' }
    end

    it { should be_valid }
  end
  describe "an invalid object" do
    before do
      subject.attributes = { swank: 'smal' }
    end
    it "has errors" do
      expect(subject).to_not be_valid
      expect(subject.errors[:fubar]).to eq ["can't be blank"]
      expect(subject.errors[:swank]).to eq ["is too short (minimum is 5 characters)"]
    end
  end

  describe "required terms" do
    it { should be_required(:fubar) }
    it { should_not be_required(:swank) }
  end

  describe "#save!" do
    before { allow(subject).to receive(:_create_record) } # prevent saving to Fedora/Solr

    it "validates only once" do
      expect(subject).to receive(:perform_validations).once.and_return(true)
      subject.save!
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
active-fedora-10.3.0 spec/unit/validations_spec.rb
active-fedora-10.3.0.rc2 spec/unit/validations_spec.rb
active-fedora-10.3.0.rc1 spec/unit/validations_spec.rb
active-fedora-10.2.1 spec/unit/validations_spec.rb
active-fedora-10.2.0 spec/unit/validations_spec.rb
active-fedora-11.0.0.rc1 spec/unit/validations_spec.rb
active-fedora-10.1.0 spec/unit/validations_spec.rb
active-fedora-10.1.0.rc1 spec/unit/validations_spec.rb
active-fedora-10.0.0 spec/unit/validations_spec.rb
active-fedora-10.0.0.beta4 spec/unit/validations_spec.rb
active-fedora-10.0.0.beta3 spec/unit/validations_spec.rb
active-fedora-10.0.0.beta2 spec/unit/validations_spec.rb
active-fedora-10.0.0.beta1 spec/unit/validations_spec.rb
active-fedora-9.13.0 spec/unit/validations_spec.rb