spec/validators/uniqueness_validator_spec.rb in hydra-validations-0.3.0 vs spec/validators/uniqueness_validator_spec.rb in hydra-validations-0.3.1
- old
+ new
@@ -1,7 +1,6 @@
require 'spec_helper'
-require 'active_fedora'
require 'support/shared_examples_for_validators'
shared_examples "it validates the uniqueness of the attribute value" do
context "when the value is not taken" do
before { allow(Validatable).to receive(:exists?).with(conditions) { false } }
@@ -18,15 +17,27 @@
end
describe Hydra::Validations::UniquenessValidator do
before(:all) do
- class Validatable < ActiveFedora::Base
+ class Validatable
+ def self.exists?(*args)
+ end
+ def self.name
+ 'Validatable'
+ end
+ def persisted?
+ end
+ def initialize(attributes = {})
+ attributes.each do |k,v|
+ send("#{k}=", v)
+ end
+ end
+ include ActiveModel::Validations
include Hydra::Validations
- has_metadata name: 'descMetadata', type: ActiveFedora::QualifiedDublinCoreDatastream
- has_attributes :title, datastream: 'descMetadata', multiple: false
- has_attributes :source, datastream: 'descMetadata', multiple: true
+ attr_accessor :pid, :title, :source
+ alias_method :id, :pid
end
end
after(:all) { Object.send(:remove_const, :Validatable) }
@@ -86,9 +97,9 @@
context "when the record is persisted" do
before { allow(subject).to receive(:persisted?) { true } }
it_behaves_like "it validates the uniqueness of the attribute value" do
let(:conditions) { {"source_ssim" => subject.source.first, "-id" => subject.pid} }
end
- end
+ end
end
end
end