Skip to content

Commit

Permalink
Merge pull request #476 from sul-dlss/remove_name
Browse files Browse the repository at this point in the history
Remove Exhibit#name use a boolean column to determine the default. Fixes #473
  • Loading branch information
cbeer committed Mar 7, 2014
2 parents 4016ae4 + 1fa6689 commit fe045b5
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/controllers/spotlight/exhibits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create

def show
respond_to do |format|
format.json { send_data Spotlight::ExhibitExportSerializer.new(@exhibit).to_json, type: 'application/json', disposition: 'attachment', filename: "#{@exhibit.name}-export.json" }
format.json { send_data Spotlight::ExhibitExportSerializer.new(@exhibit).to_json, type: 'application/json', disposition: 'attachment', filename: "#{@exhibit.friendly_id}-export.json" }
end
end

Expand Down
13 changes: 2 additions & 11 deletions app/models/spotlight/exhibit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Spotlight::Exhibit < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: [:slugged,:finders]

DEFAULT = 'default'.freeze
# friendly id associations need to be 'destroy'ed to reap the slug history
has_many :searches, dependent: :destroy, extend: FriendlyId::FinderMethods
has_many :pages, dependent: :destroy
Expand Down Expand Up @@ -44,11 +43,7 @@ class Spotlight::Exhibit < ActiveRecord::Base
after_create :add_default_home_page
before_save :sanitize_description

before_validation do
self.name ||= self.title.parameterize if self.title
end

validate :name, :title, presence: true
validate :title, presence: true
acts_as_tagger

def main_about_page
Expand All @@ -57,7 +52,7 @@ def main_about_page

# Find or create the default exhibit
def self.default
self.find_or_create_by!(name: DEFAULT) do |e|
self.find_or_create_by!(default: true) do |e|
e.title = 'Default exhibit'.freeze
end
end
Expand All @@ -70,10 +65,6 @@ def to_s
title
end

def default?
name == DEFAULT
end

def import hash
# remove the default browse category -- it might be in the import
# and we don't want to have a conflicting slug
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20140128155151_create_exhibits.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class CreateExhibits < ActiveRecord::Migration
def change
create_table :spotlight_exhibits do |t|
t.string :name, null: false # This is for programatic lookup (route key perhaps)
t.boolean :default
t.string :title, null: false
t.string :subtitle
t.string :slug
t.text :description
t.timestamps
end

add_index :spotlight_exhibits, :name, unique: true
add_index :spotlight_exhibits, :default, unique: true
add_index :spotlight_exhibits, :slug, unique: true
end
end
1 change: 0 additions & 1 deletion spec/factories/exhibits.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FactoryGirl.define do
factory :exhibit, class: Spotlight::Exhibit do
sequence(:name) { |n| "exhibit#{n}" }
sequence(:title) { |n| "Exhibit Title #{n}" }
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/spotlight/exhibit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Spotlight::Exhibit do
subject { Spotlight::Exhibit.new(name: 'test', title: "Sample") }
subject { Spotlight::Exhibit.new(title: "Sample") }

it "should have a title" do
subject.title = "Test title"
Expand Down

0 comments on commit fe045b5

Please sign in to comment.