-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dropdown select for collections from Plum.
Closes #20.
- Loading branch information
Trey Terrell
committed
Jan 14, 2016
1 parent
48e5367
commit e82aab0
Showing
13 changed files
with
134 additions
and
3 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
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,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 |
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,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 |
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
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 |
---|---|---|
|
@@ -21,3 +21,9 @@ | |
|
||
en: | ||
hello: "Hello world" | ||
spotlight: | ||
exhibits: | ||
new_exhibit_form: | ||
fields: | ||
slug: | ||
label: Plum Collection |
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,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 |
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,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 |
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,4 @@ | ||
RSpec.configure do |config| | ||
config.include Devise::TestHelpers, type: :controller | ||
config.include Devise::TestHelpers, type: :view | ||
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
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
16
spec/views/spotlight/exhibits/_new_exhibit_form.html.erb_spec.rb
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,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 |