Skip to content

Commit

Permalink
add a non-required ref_id to the subject model
Browse files Browse the repository at this point in the history
  • Loading branch information
quoideneuf committed Dec 11, 2012
1 parent 689a371 commit 9e2588f
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions backend/app/model/migrations/001_create_base_schema.rb
Expand Up @@ -375,6 +375,7 @@
Integer :vocab_id, :null => false

String :terms_sha1, :unique => true
String :ref_id, :unique => true

DateTime :create_time, :null => false
DateTime :last_modified, :null => false
Expand Down
1 change: 1 addition & 0 deletions backend/app/model/subject.rb
Expand Up @@ -68,6 +68,7 @@ def self.sequel_to_jsonmodel(obj, type, opts = {})
def validate
super
validates_unique([:vocab_id, :terms_sha1], :message => "Subject must be unique")
validates_unique([:vocab_id, :ref_id], :message => "Subject heading identifier must be unique")
map_validation_to_json_property([:vocab_id, :terms_sha1], :terms)
end

Expand Down
3 changes: 2 additions & 1 deletion backend/spec/factories.rb
Expand Up @@ -258,8 +258,9 @@
end

factory :json_subject, class: JSONModel(:subject) do
terms { [build(:json_term)] }
terms { [build(:json_term).to_hash] }
vocabulary { create(:json_vocab).uri }
ref_id { generate(:url) }
end

factory :json_term, class: JSONModel(:term) do
Expand Down
19 changes: 19 additions & 0 deletions backend/spec/model_subject_spec.rb
Expand Up @@ -85,5 +85,24 @@ def createTerm
}))
}.to raise_error(Sequel::ValidationFailed)
end

it "ensures subject heading identifiers are unique within a vocab" do
vocab = create(:json_vocab)

heading_id = 1 == rand(2) ? "http://example.com/example" : "12aBCD12"

subject_a = create(:json_subject, {:vocabulary => vocab.uri, :ref_id => heading_id})

expect {
create(:json_subject, {:vocabulary => vocab.uri})
}.to_not raise_error(JSONModel::ValidationException)

expect {
create(:json_subject, {:vocabulary => vocab.uri, :ref_id => heading_id})
}.to raise_error(JSONModel::ValidationException)


end


end
1 change: 1 addition & 0 deletions common/schemas/subject.rb
Expand Up @@ -9,6 +9,7 @@
"terms" => {"type" => "array", "items" => {"type" => "JSONModel(:term) uri_or_object"}, "ifmissing" => "error", "minItems" => 1},

"vocabulary" => {"type" => "JSONModel(:vocabulary) uri", "ifmissing" => "error"},
"ref_id" => {"type" => "string", "pattern" => "^[\\S]*$"},

"external_documents" => {"type" => "array", "items" => {"type" => "JSONModel(:external_document) object"}},
},
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/views/subjects/_form.html.erb
Expand Up @@ -29,6 +29,11 @@
<fieldset>
<%= form.hidden_input "vocabulary", current_vocabulary['uri'] %>

<section id="identifier">
<h3>Identifier</h3>
<%= form.label_and_textfield "ref_id" %>
</section>

<section id="terms">
<h3>Terms</h3>
<div class="row-fluid">
Expand Down
1 change: 1 addition & 0 deletions frontend/app/views/subjects/_sidebar.html.erb
@@ -1,5 +1,6 @@
<div id="archivesSpaceSidebar">
<ul class="nav nav-list as-nav-list">
<li><a href="#basic_information">Basic Information <span class="icon-chevron-right"></span></a></li>
<li><a href="#terms">Terms <span class="icon-chevron-right"></span></a></li>

<% if not controller.action_name === "show" or @subject.external_documents.length > 0 %>
Expand Down
8 changes: 7 additions & 1 deletion frontend/app/views/subjects/show.html.erb
Expand Up @@ -5,8 +5,14 @@
<%= render :partial => "sidebar" %>
</div>
<div class="span9 record-pane">
<%= readonly_context :subject, @subject.to_hash do |readonly| %>
<h2><%= @subject.display_string %> <span class="label label-info">Subject</span></h2>
<section id="basic_information">
<h3>Basic Information</h3>

<%= readonly.label_and_textfield "ref_id" %>
</section>

<section id="terms">
<h3>Terms</h3>
<div class="row-fluid">
Expand All @@ -24,6 +30,6 @@
<% if @subject.external_documents.length > 0 %>
<%= render :partial => "external_documents/show", :locals => { :external_documents => @subject.external_documents } %>
<% end %>

<% end %>
</div>
</div>
1 change: 1 addition & 0 deletions frontend/config/locales/en.yml
Expand Up @@ -1093,6 +1093,7 @@ en:
term_type: Type
subject:
terms: Terms
ref_id: Subject Heading Identifier
_terms:
<<: *term_attributes
_external_documents:
Expand Down

0 comments on commit 9e2588f

Please sign in to comment.