Skip to content

Commit

Permalink
Fix to use collections instead of manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Terrell committed Jan 18, 2016
1 parent 1a6561f commit aca86e2
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 146 deletions.
11 changes: 9 additions & 2 deletions app/decorators/applies_title_from_slug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ def initialize(record, slug)
end

def save(*args)
__getobj__.title = title
__getobj__.slug = slug
__getobj__.title = title
return false unless valid?
super
end

def valid?(*args)
super
errors.add :slug, "can't be blank" if slug.blank?
errors.blank?
end

private
Expand All @@ -19,6 +26,6 @@ def manifest
end

def title
manifest.label
manifest.try(:label)
end
end
10 changes: 2 additions & 8 deletions app/queries/external_collections_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def initialize(remote_url)
end

def collection_manifests
@collection_manifests ||= manifest_urls.map do |url|
CollectionManifest.load(url)
@collection_manifests ||= all_manifest.collections.map do |collection|
CollectionManifest.new(collection.send(:data))
end
end

Expand All @@ -27,10 +27,4 @@ def collection_manifests
def all_manifest
@all_manifest ||= ExternalManifest.load(remote_url)
end

def manifest_urls
all_manifest.manifests.map do |manifest|
manifest['@id']
end
end
end
191 changes: 57 additions & 134 deletions spec/cassettes/all_collections.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions spec/controllers/exhibits_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,20 @@
expect(last_exhibit.slug).to eq "princeton-best"
end
end
context "when not given a slug" do
let(:params) do
{
exhibit: {
slug: ""
}
}
end
it "renders an error" do
post :create, params

expect(response).to render_template "new"
expect(assigns["exhibit"].errors.messages[:slug]).to eq ["can't be blank"]
end
end
end
end
2 changes: 1 addition & 1 deletion spec/models/external_manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
subject { described_class.load(manifest_url) }
let(:manifest_url) { "https://hydra-dev.princeton.edu/collections/manifest" }
it "loads up a manifest" do
expect(subject.manifests.length).to eql 2
expect(subject.collections.length).to eql 2
end
end
end
2 changes: 1 addition & 1 deletion spec/queries/external_collections_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
subject { described_class }
describe ".all" do
it "queries plum for all collections" do
expect(subject.all.map(&:slug)).to eq ["test-collection-2", "princeton-best"]
expect(subject.all.map(&:slug)).to eq ["princeton-best", "test-collection-2"]
end
end
end

0 comments on commit aca86e2

Please sign in to comment.