Skip to content

Instantly share code, notes, and snippets.

View elrayle's full-sized avatar

E. Lynette Rayle elrayle

View GitHub Profile
@elrayle
elrayle / collection_form.rb
Created June 6, 2018 15:50
prepending Hyrax::Forms::CollectionForm example
# Based on the Module#prepend pattern in ruby which is used in some Hyrax.
# Uses the to_prepare Rails hook in application.rb to inject this module to override Hyrax::Forms::CollectionForm module
module PrependedForms::CollectionForm
module ClassMethods
# Override Hyrax::Forms::CollectionForm.terms method
# self.terms = [:parent_agency, :title, :acronym, :description, :contact_email, :contact_phone,
# :location_city, :location_state, :homepage_url, :is_division]
def terms
[:title, :acronym, :description, :contact_email, :contact_phone,
:location_city, :location_state, :homepage_url, :thumbnail_id]
@elrayle
elrayle / gist:efb3a1fe1b10cc62d7499274c295bd0b
Last active May 24, 2018 19:20
seed_1col_1work_1000childworks_with_files.rb
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
#
# To use this file, run the following command in the .internal_test_app:
# rails generate hyrax:sample_data
$ cap sandbox deploy
00:00 git:wrapper
01 mkdir -p /tmp
Enter passphrase for /Users/elr37/.ssh/id_rsa:
Enter passphrase for /Users/elr37/.ssh/id_rsa:
✔ 01 [email protected] 59.954s
Uploading /tmp/git-ssh-nurax-sandbox-elr37.sh 100.0%
02 chmod 700 /tmp/git-ssh-nurax-sandbox-elr37.sh
✔ 02 [email protected] 0.161s
01:00 git:check
<http://id.loc.gov/authorities/names/n2003044800> <http://vivoweb.org/ontology/core#rank> "1" .
_:-4a492ab5:16105c43b14:-7f2d <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:c93f456ec2cdc6e0219ac57697d76c8b .
_:-4a492ab5:16105c43b14:-7f2d <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
_:1186338e9511e1579dddf70844bc7d2a <http://purl.org/vocab/changeset/schema#changeReason> "new" .
_:1186338e9511e1579dddf70844bc7d2a <http://purl.org/vocab/changeset/schema#createdDate> "2003-05-06T00:00:00" .
_:1186338e9511e1579dddf70844bc7d2a <http://purl.org/vocab/changeset/schema#creatorName> <http://id.loc.gov/vocabulary/organizations/dlc> .
_:1186338e9511e1579dddf70844bc7d2a <http://purl.org/vocab/changeset/schema#subjectOfChange> <http://id.loc.gov/authorities/names/n2003044800> .
_:1186338e9511e1579dddf70844bc7d2a <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/vocab/changeset/schema#ChangeSet> .
_:1dd46d0e335f32fdbc20e8f106da6b24 <http://www.w3
<!DOCTYPE html>
<html lang="en" prefix="og:http://ogp.me/ns#">
<head>
<meta name="csrf-param" content="authenticity_token" />
<meta name="csrf-token" content="bjhCeuj9K057odJU7+RNlFabTgXdV6ADo2c7WnLB//WkDGoF4bz/vktKyA0/6n9mvVwd1TrPjKlm11B/HeyWtg==" />
<meta charset="utf-8" />
<meta name="current-user" data-user-key="[email protected]" />
<!-- added for use on small devices like phones -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="resourcesync" href="http://localhost:3000/capabilitylist?locale=en"/>
gem 'hyrax', '2.0.0'
run 'bundle install'
generate 'hyrax:install', '-f'

Setup

child_col1 = Collection.create(id: 'cc1', title: ['Child Collection 1'])
child_col2 = Collection.create(id: 'cc2', title: ['Child Collection 2'])
child_col3 = Collection.create(id: 'cc3', title: ['Child Collection 3'])
parent_col1 = Collection.create(id: 'pc1', title: ['Parent Collection 1'])
parent_col2 = Collection.create(id: 'pc2', title: ['Parent Collection 2'])
parent_col3 = Collection.create(id: 'pc3', title: ['Parent Collection 3'])
work1 = GenericWork.create(id: 'w1', title: ['Work 1'])
@elrayle
elrayle / migrate_1.rb
Created November 14, 2017 14:37
Process sqlite separately
class AddSourceTypeToPermissionTemplates < ActiveRecord::Migration[4.2]
def self.up
add_column :permission_templates, :source_type, :string, default: 'admin_set'
unless connection.adapter_name.downcase.starts_with?('sqlite') && Hyrax::PermissionTemplate.any?
# if this is not sqlite, then we can simply rename
# if this is sqlite, we can rename if the table is empty
rename_column :permission_templates, :admin_set_id, :source_id
else
# otherwise, sqlite throws an error when renaming a foreign key that already has values,
@elrayle
elrayle / permissions_service.rb
Last active September 1, 2017 15:22
add this file at... /app/services/hyrax/collection_types/permissions_service.rb
module Hyrax
module CollectionTypes
class PermissionsService
# @api public
#
# Get a list of collection types that a user can create
#
# @param user [User] the user that will be creating a collection (default: current_user)
# @return [Array<Hyrax::CollectionType>] array of collection types the user can create
def self.can_create_collection_types(user: current_user)
1) hyrax/dashboard/collections/show.html.erb draws the page
Failure/Error: expect(rendered).to have_css('.stubbed-actions', text: 'THE ACTIONS')
expected to find visible css ".stubbed-actions" with text "THE ACTIONS" but there were no matches
# ./spec/views/hyrax/dashboard/collections/show.html.erb_spec.rb:40:in `block (2 levels) in <top (required)>'
2) hyrax/admin/collection_types/index.html.erb has delete buttons for non-special collection types