-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from projecthydra-labs/extract_initialize_field
Extract new method initialize_field for easier overrides
- Loading branch information
Showing
2 changed files
with
63 additions
and
8 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,52 @@ | ||
require 'spec_helper' | ||
|
||
describe HydraEditor::Form do | ||
class TestModel < ActiveFedora::Base | ||
property :title, predicate: ::RDF::DC.title | ||
property :creator, predicate: ::RDF::DC.creator, multiple: false | ||
end | ||
|
||
class TestForm | ||
include HydraEditor::Form | ||
self.model_class = TestModel | ||
# Terms is the list of fields displayed by app/views/records/_form.html.erb | ||
self.terms = [:title, :creator] | ||
end | ||
|
||
describe "class methods" do | ||
subject { TestForm.model_name } | ||
it { is_expected.to eq 'TestModel' } | ||
end | ||
|
||
let(:object) { TestModel.new(title: ['foo', 'bar'], creator: 'baz') } | ||
let(:form) { TestForm.new(object) } | ||
|
||
describe "#terms" do | ||
subject { form.terms } | ||
it { is_expected.to eq [:title, :creator] } | ||
end | ||
|
||
describe "the term accessors" do | ||
it "should have the accessors" do | ||
expect(form.title).to eq ['foo', 'bar'] | ||
expect(form.creator).to eq 'baz' | ||
end | ||
|
||
it "should have the hash accessors" do | ||
expect(form[:title]).to eq ['foo', 'bar'] | ||
expect(form[:creator]).to eq 'baz' | ||
end | ||
end | ||
|
||
describe "#initialize_field" do | ||
before do | ||
form[:title] = nil | ||
end | ||
|
||
it "should put an empty element in the value" do | ||
expect { form.send(:initialize_field, :title) }.to change { form[:title] }. | ||
from(nil).to(['']) | ||
end | ||
end | ||
|
||
end |