Skip to content

Commit

Permalink
Dropdown select for collections from Plum.
Browse files Browse the repository at this point in the history
Closes #20.
  • Loading branch information
Trey Terrell committed Jan 14, 2016
1 parent 48e5367 commit e82aab0
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ group :development, :test do
gem 'rubocop-rspec', require: false
gem 'vcr'
gem 'webmock', require: false
gem 'capybara'
gem 'factory_girl_rails'
end

group :development do
Expand Down
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ GEM
builder (3.2.2)
byebug (8.2.1)
cancancan (1.13.1)
capybara (2.5.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
carrierwave (0.10.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
Expand Down Expand Up @@ -167,6 +173,11 @@ GEM
erubis (2.7.0)
execjs (2.6.0)
extlib (0.9.16)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.5.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.10.0)
Expand Down Expand Up @@ -433,6 +444,8 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
xpath (2.0.0)
nokogiri (~> 1.3)

PLATFORMS
ruby
Expand All @@ -443,11 +456,13 @@ DEPENDENCIES
blacklight-oembed
blacklight-spotlight!
byebug
capybara
coffee-rails (~> 4.1.0)
coveralls
devise
devise-guests (~> 0.3)
devise_invitable
factory_girl_rails
friendly_id
iiif-presentation
jbuilder (~> 2.0)
Expand Down
16 changes: 16 additions & 0 deletions app/controllers/exhibits_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class ExhibitsController < Spotlight::ExhibitsController
prepend_before_action :find_exhibit

private

def find_exhibit
@exhibit ||=
decorate(
Spotlight::Exhibit.new
)
end

def decorate(obj)
AppliesTitleFromSlug.new(obj, params[:exhibit][:slug])
end
end
24 changes: 24 additions & 0 deletions app/decorators/applies_title_from_slug.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class AppliesTitleFromSlug < SimpleDelegator
delegate :class, to: :__getobj__
attr_reader :slug
def initialize(record, slug)
@slug = slug
super(record)
end

def save(*args)
__getobj__.title = title
__getobj__.slug = slug
super
end

private

def manifest
@manifest ||= CollectionManifest.find_by_slug(slug)
end

def title
manifest.label
end
end
6 changes: 6 additions & 0 deletions app/models/collection_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ def self.load(url)
new(ExternalManifest.load(url).send(:data))
end

def self.find_by_slug(slug)
ExternalCollectionsQuery.all.find do |manifest|
manifest.slug == slug
end
end

def slug
metadata.find do |entry|
entry["label"] == slug_key
Expand Down
5 changes: 2 additions & 3 deletions app/views/spotlight/exhibits/_new_exhibit_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<%= bootstrap_form_for @exhibit, url: ((spotlight.exhibit_path(@exhibit) if @exhibit.persisted?) || spotlight.exhibits_path), layout: :horizontal, label_col: 'col-md-2', control_col: 'col-md-10', html: {class: "row"} do |f| %>
<%= bootstrap_form_for @exhibit, url: ((spotlight.exhibit_path(@exhibit) if @exhibit.persisted?) || exhibits_path), layout: :horizontal, label_col: 'col-md-2', control_col: 'col-md-10', html: {class: "row"} do |f| %>
<div class="row col-md-12">
<%= f.text_field :title, label: t(:'.fields.title.label'), help: t(:'.fields.title.help_block') %>
<%= f.text_field :slug, label: t(:'.fields.slug.label'), help: t(:'.fields.slug.help_block') %>
<%= f.collection_select(:slug, ExternalCollectionsQuery.all, :slug, :label, label: t(:'.fields.slug.label')) %>
<%= f.text_field :tag_list %>
<%= render 'initial_resources_form', locals: { f: f } %>
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@

en:
hello: "Hello world"
spotlight:
exhibits:
new_exhibit_form:
fields:
slug:
label: Plum Collection
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Rails.application.routes.draw do
mount Blacklight::Oembed::Engine, at: 'oembed'
root to: 'spotlight/exhibits#index'
resources :exhibits, path: '/spotlight', only: [:create]
mount Spotlight::Engine, at: 'spotlight'
# root to: "catalog#index" # replaced by spotlight root path
blacklight_for :catalog
Expand Down
27 changes: 27 additions & 0 deletions spec/controllers/exhibits_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'rails_helper'

RSpec.describe ExhibitsController, vcr: { cassette_name: "all_collections" } do
before do
allow(Spotlight::DefaultThumbnailJob).to receive(:perform_later)
sign_in FactoryGirl.create(:site_admin)
end
describe "#create" do
context "when given just a slug" do
let(:params) do
{
exhibit: {
slug: "princeton-best"
}
}
end
it "works and pulls the title" do
post :create, params

expect(response).not_to render_template "new"
last_exhibit = Spotlight::Exhibit.last
expect(last_exhibit.title).to eq "princeton"
expect(last_exhibit.slug).to eq "princeton-best"
end
end
end
end
9 changes: 9 additions & 0 deletions spec/routing/exhibits_routing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rails_helper'

RSpec.describe "exhibit routing" do
describe "POST /exhibits" do
it "routes to local exhibits controller" do
expect(post "/spotlight").to route_to controller: "exhibits", action: "create"
end
end
end
4 changes: 4 additions & 0 deletions spec/support/devise_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller
config.include Devise::TestHelpers, type: :view
end
6 changes: 6 additions & 0 deletions spec/support/solr_cleanup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RSpec.configure do |config|
config.before(:each) do
Blacklight.default_index.connection.delete_by_query("*:*")
Blacklight.default_index.connection.commit
end
end
16 changes: 16 additions & 0 deletions spec/views/spotlight/exhibits/_new_exhibit_form.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rails_helper'

RSpec.describe "spotlight/exhibits/_new_exhibit_form.html.erb", vcr: { cassette_name: 'all_collections' } do
it "displays a select of all available exhibits" do
assign(:exhibit, Spotlight::Exhibit.new)
render

expect(rendered).to have_select("Plum Collection", options: ['princeton', 'Test Collection 2'])
end
it "posts to the correct place" do
assign(:exhibit, Spotlight::Exhibit.new)
render

expect(rendered).to have_selector "form[action='/spotlight']"
end
end

0 comments on commit e82aab0

Please sign in to comment.