Sha256: a6537f780ba34af90054e369ea51d33f864b4d4c480b7246380e2bd15180e653

Contents?: true

Size: 1.5 KB

Versions: 12

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

describe ActiveFedora::Base do
  before :all do
    class ValidationStub < ActiveFedora::Base
      has_metadata type: ActiveFedora::SimpleDatastream, name: "someData" do |m|
        m.field "fubar", :string
        m.field "swank", :text
      end
      Deprecation.silence(ActiveFedora::Attributes) do
        has_attributes :fubar, datastream: 'someData', multiple: true
        has_attributes :swank, datastream: 'someData', multiple: false
      end

      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

12 entries across 12 versions & 1 rubygems

Version Path
active-fedora-9.7.3 spec/unit/validations_spec.rb
active-fedora-9.7.2 spec/unit/validations_spec.rb
active-fedora-9.10.0.pre1 spec/unit/validations_spec.rb
active-fedora-9.9.1 spec/unit/validations_spec.rb
active-fedora-9.9.0 spec/unit/validations_spec.rb
active-fedora-9.8.2 spec/unit/validations_spec.rb
active-fedora-9.8.1 spec/unit/validations_spec.rb
active-fedora-9.8.0 spec/unit/validations_spec.rb
active-fedora-9.7.1 spec/unit/validations_spec.rb
active-fedora-9.7.0 spec/unit/validations_spec.rb
active-fedora-9.6.2 spec/unit/validations_spec.rb
active-fedora-9.6.1 spec/unit/validations_spec.rb