Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shared spec for change sets, fixes #330
Co-authored-by: Carolyn Cole <cam156@psu.edu>
- Loading branch information
1 parent
c6acb16
commit 3e508ac
Showing
3 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
RSpec.shared_examples 'a Valkyrie::ChangeSet' do |*_flags| | ||
before do | ||
raise 'adapter must be set with `let(:change_set)`' unless defined? change_set | ||
raise 'change_set must have at least one field' if change_set.fields.empty? | ||
end | ||
|
||
subject { change_set } | ||
|
||
it { is_expected.to respond_to :append_id } | ||
it { is_expected.to respond_to :fields } | ||
it { is_expected.to respond_to :fields= } | ||
it { is_expected.to respond_to :multiple? } | ||
it { is_expected.to respond_to :prepopulate! } | ||
it { is_expected.to respond_to :required? } | ||
it { is_expected.to respond_to :validate } | ||
it { is_expected.to respond_to :valid? } | ||
|
||
it "can set an append_id" do | ||
change_set.append_id = Valkyrie::ID.new("test") | ||
expect(change_set.append_id).to eq Valkyrie::ID.new("test") | ||
expect(change_set[:append_id]).to eq Valkyrie::ID.new("test") | ||
end | ||
|
||
describe "#fields" do | ||
it "returns an hash" do | ||
expect(change_set.fields).to be_a Hash | ||
end | ||
end | ||
|
||
describe "#fields=" do | ||
it "sets fields" do | ||
change_set.fields = { "totally_a_field" => [] } | ||
expect(change_set.fields).to eq("totally_a_field" => []) | ||
end | ||
end | ||
|
||
describe "#multiple?" do | ||
it "returns a boolean" do | ||
expect(change_set.multiple?(change_set.fields.keys.first)).to be_in [true, false] | ||
end | ||
end | ||
|
||
describe "#prepopulate!" do | ||
it "doesn't make it look changed" do | ||
expect(change_set).not_to be_changed | ||
change_set.prepopulate! | ||
expect(change_set).not_to be_changed | ||
end | ||
end | ||
|
||
describe "#required?" do | ||
it "returns a boolean" do | ||
expect(change_set.required?(change_set.fields.keys.first)).to be_in [true, false] | ||
end | ||
end | ||
|
||
describe "#valid?" do | ||
it "returns a boolean" do | ||
expect(change_set.valid?).to be_in [true, false] | ||
end | ||
end | ||
|
||
describe "#validate" do | ||
it "returns a change_set" do | ||
expect(change_set.validate(change_set.fields)).to be_in [true, false] | ||
end | ||
end | ||
|
||
describe ".validators_on" do | ||
it "the class responds to validators_on" do | ||
expect(described_class).to respond_to(:validators_on) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters