hydra-head 4.0.0.rc5 → 4.0.0.rc6
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.textile +1 -1
- data/HOW_TO_GET_STARTED.textile +2 -2
- data/INSTALL_PREREQ.textile +1 -20
- data/README.textile +12 -16
- data/app/assets/stylesheets/hydra/html_refactor.css +1 -5
- data/app/assets/stylesheets/hydra/hydrangea.css +0 -4
- data/app/assets/stylesheets/hydra/styles.css +12 -595
- data/app/controllers/downloads_controller.rb +2 -1
- data/app/controllers/hydra/permissions_controller.rb +2 -6
- data/app/models/ability.rb +1 -98
- data/app/models/hydra/ability.rb +128 -0
- data/app/views/_flash_msg.html.erb +1 -1
- data/app/views/catalog/_home.html.erb +2 -2
- data/app/views/catalog/_home_text.html.erb +2 -8
- data/app/views/catalog/_show_partials/_default.html.erb +0 -4
- data/app/views/generic_images/_edit.html.erb +0 -2
- data/app/views/layouts/hydra-head.html.erb +22 -35
- data/lib/hydra-head/version.rb +1 -1
- data/lib/hydra/mods_article.rb +22 -2
- data/lib/railties/hydra-fixtures.rake +17 -24
- data/tasks/hydra-head-fixtures.rake +32 -28
- data/tasks/hydra-head.rake +39 -57
- data/{lib/railties → tasks}/hyhead_rspec.rake +7 -26
- data/test_support/features/file_upload.feature +3 -3
- data/test_support/features/step_definitions/edit_metadata_steps.rb +1 -1
- data/test_support/features/step_definitions/user_steps.rb +7 -4
- data/test_support/spec/models/ability_spec.rb +3 -9
- metadata +36 -51
- data/DEVELOP_PLUGIN.textile +0 -90
- data/GIT_WORKFLOW.textile +0 -106
- data/HOW_TO_DEFINE_A_HYDRA_CONTROLLER.textile +0 -21
- data/HOW_TO_DEFINE_A_HYDRA_MODEL.textile +0 -64
- data/HYDRA_ACCESS_CONTROLS.textile +0 -27
- data/INITIAL_APP_MODS.textile +0 -223
- data/README_RAILS3_CHANGES.textile +0 -67
- data/README_RAKE_TASKS.textile +0 -107
- data/README_SUBTREE.textile +0 -87
- data/README_TERSE.textile +0 -92
- data/RELEASE_NOTES.textile +0 -8
- data/TESTING.textile +0 -85
- data/TESTING_PLUGIN.textile +0 -133
- data/app/views/layouts/application.html.erb +0 -49
- data/lib/railties/all_tests.rake +0 -23
- data/lib/railties/hyhead_cucumber.rake +0 -126
data/DEVELOP_PLUGIN.textile
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
h1. Setting Up the Hydra-Head Plugin as a Project Containing a Rails Application for Testing or Demo
|
2
|
-
|
3
|
-
This document describes how to set up a project for the hydra-head plugin code itself - primarily intended for the hydra-head plugin developers. It will contain a pre-configured rails application for testing the hydra-head plugin.
|
4
|
-
|
5
|
-
It does NOT describe how to set up a rails application that uses the hydra-head plugin. For that, see "CREATE_RAILS_APP":https://github.com/projecthydra/hydra-head/blob/master/CREATE_RAILS_APP.textile.
|
6
|
-
|
7
|
-
h2. Install the Hydra-Plugin and its Contained Test Host Application
|
8
|
-
|
9
|
-
h4. (0) Install Prerequisites.
|
10
|
-
|
11
|
-
See "INSTALL_PREREQ":/projecthydra/hydra-head/blob/master/INSTALL_PREREQ.textile
|
12
|
-
|
13
|
-
h4. (1) Get the hydra-head engines plugin from github and include the testing rails application.
|
14
|
-
|
15
|
-
<pre>
|
16
|
-
git clone --recursive git@github.com:projecthydra/hydra-head.git
|
17
|
-
cd hydra-head
|
18
|
-
</pre>
|
19
|
-
|
20
|
-
This will also initialize and update the jetty and hydra-plugin_test_host git submodules. The former is a copy of Jetty pre-configured for Hydra with Fedora and Solr installed. The latter is a preconfigured Rails application to house and test the hydra-head engines plugin.
|
21
|
-
|
22
|
-
This <b>hydra-head directory</b> is the <b><i>root of the plugin</i>.</b>
|
23
|
-
|
24
|
-
h4. (2) Use bundler to install the gem dependencies.
|
25
|
-
|
26
|
-
<pre>
|
27
|
-
bundle install
|
28
|
-
</pre>
|
29
|
-
|
30
|
-
Note that if you have RVM installed, it will create/use a gemset called "hyhead".
|
31
|
-
|
32
|
-
|
33
|
-
h4. (3) Put a copy of the hydra-head plugin into the testing application
|
34
|
-
|
35
|
-
The rails application used for testing MUST have a copy of the hydra-head plugin added to its vendor/plugins directory. We provide a "rake task":http://hudson.projecthydra.org/job/hydra-head-rails2-plugin/Documentation/file.README_RAKE_TASKS.html#hyhead_Test_Host_Setup__setup_test_host for this which copies your current hydra-head plugin code into hydra-plugin_test_host/vendor/plugins as well as the fixtures and cucumber features required for testing.
|
36
|
-
|
37
|
-
<pre>
|
38
|
-
rake hyhead:setup_test_host
|
39
|
-
</pre>
|
40
|
-
|
41
|
-
h4. (5) Migrate the test databases
|
42
|
-
|
43
|
-
See below to reset the test databases when re-running tests.
|
44
|
-
|
45
|
-
You must do this within the <b><i>hydra-plugin_test_host</i> directory</b>, not at the root of the plugin.
|
46
|
-
|
47
|
-
<pre>
|
48
|
-
cd hydra-plugin_test_host
|
49
|
-
</pre>
|
50
|
-
|
51
|
-
To ensure that the tests do not rely on non-test data, do this:
|
52
|
-
|
53
|
-
<pre>
|
54
|
-
rake db:drop:all
|
55
|
-
</pre>
|
56
|
-
|
57
|
-
Migrate the test databases:
|
58
|
-
|
59
|
-
<pre>
|
60
|
-
rake db:migrate RAILS_ENV=test
|
61
|
-
</pre>
|
62
|
-
|
63
|
-
In case you ever run the server in development mode, you will need to migrate the databases without RAILS_ENV set to test:
|
64
|
-
|
65
|
-
<pre>
|
66
|
-
rake db:migrate
|
67
|
-
</pre>
|
68
|
-
|
69
|
-
Now cd back up to the root of the <b><i>hydra-head plugin</i> directory</b>:
|
70
|
-
|
71
|
-
<pre>
|
72
|
-
cd ../
|
73
|
-
</pre>
|
74
|
-
|
75
|
-
h3. Now you're ready to run the tests
|
76
|
-
|
77
|
-
If you want to run the tests, see "TESTING_PLUGIN":/projecthydra/hydra-head/blob/master/TESTING_PLUGIN.textile
|
78
|
-
|
79
|
-
h2. Running the Testing Application
|
80
|
-
|
81
|
-
The test host app is a regular Rails app with Blacklight installed. It's configured with the assumption that the hydra-head plugin is installed into vendor/plugins/hydra-head.
|
82
|
-
|
83
|
-
Hydra expects Fedora and Solr instances to be running (for testing, a jetty instance is provided in the hydra-head plugin directory. See also config/solr.yml and config/fedora.yml).
|
84
|
-
|
85
|
-
Change into the root of the test app and start it like you normally start any rails app.
|
86
|
-
|
87
|
-
<pre>
|
88
|
-
cd hydra-plugin_test_host
|
89
|
-
script/server
|
90
|
-
</pre>
|
data/GIT_WORKFLOW.textile
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
h1. Using a checkout from git as your hydra-head or active-fedora gem:
|
2
|
-
|
3
|
-
h2. Advanced usage: Running against the freshest version of the hydra-head code from Github
|
4
|
-
|
5
|
-
*We don't recommend this for new users or for production applications*, but it is very useful during active development.
|
6
|
-
|
7
|
-
If you are in a position where you want/need to run your application with the very latest hydra-head code from Github, this is easy to do. Simply update the line in your Gemfile that lists hydra-head as a dependency and enter this instead:
|
8
|
-
|
9
|
-
<pre>
|
10
|
-
gem "hydra-head", :git => "git://github.com/projecthydra/hydra-head.git"
|
11
|
-
</pre>
|
12
|
-
|
13
|
-
After updating the Gemfile, re-run 'bundle install'.
|
14
|
-
|
15
|
-
You can also do this with other gems. For example, if you want to force your app to use the latest active-fedora code from the "HYDRA-721" branch on GitHub, you can put this in your Gemfile:
|
16
|
-
|
17
|
-
<pre>
|
18
|
-
gem "active-fedora", :git=>'git://github.com/mediashelf/active_fedora.git'
|
19
|
-
</pre>
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
h1. Git Workflow (with command line examples) for working on Hydra Projects
|
24
|
-
|
25
|
-
h2. Reference Material/Reading:
|
26
|
-
|
27
|
-
Good places to read about git workflows:
|
28
|
-
|
29
|
-
* "Diaspora Git Workflow":https://github.com/diaspora/diaspora/wiki/Git-Workflow
|
30
|
-
* "Thinkup Developer Documentation":http://thinkupapp.com/docs/contribute/developers/devfromsource.html
|
31
|
-
|
32
|
-
You might want to set up your shell prompt to tell you which git branch you're in.
|
33
|
-
|
34
|
-
* "Displaying git branch info in your bash prompt":http://yourmediashelf.com/2011/08/displaying-git-branch-info-in-bash-prompt/
|
35
|
-
|
36
|
-
h2. Creating a Feature Branch then Rebasing, Merging and Cleaning Up
|
37
|
-
|
38
|
-
*Scenario:* You're working on the HYDRA-333 ticket.
|
39
|
-
|
40
|
-
# You already have a working copy of hydra-head cloned to your local machine.
|
41
|
-
# Your work is starting from the contents of hydra-head/master
|
42
|
-
|
43
|
-
The steps:
|
44
|
-
|
45
|
-
# Create a feature branch
|
46
|
-
# If necessary, push a copy of the working branch to github
|
47
|
-
# Rebase the feature branch
|
48
|
-
# Merge the finished work into Master
|
49
|
-
# Clean up after yourself
|
50
|
-
|
51
|
-
Here's how to do the right thing with git on the command line. *Note*: the parts in parentheses indicates which branch you should be on when you run the command. If it doesn't matter which branch you're on, this is indicated with (*).
|
52
|
-
|
53
|
-
h3. Create your feature branch
|
54
|
-
|
55
|
-
<pre>
|
56
|
-
cd hydra-head
|
57
|
-
(master) git checkout -b HYDRA-333
|
58
|
-
</pre>
|
59
|
-
|
60
|
-
Make changes and commit them to your feature branch like normal.
|
61
|
-
|
62
|
-
<pre>
|
63
|
-
(HYDRA-333) git add …
|
64
|
-
(HYDRA-333) git commit …
|
65
|
-
</pre>
|
66
|
-
|
67
|
-
h3. If necessary, push a copy of the feature branch to github
|
68
|
-
|
69
|
-
If you need to share your feature branch, push it to github
|
70
|
-
|
71
|
-
<pre>
|
72
|
-
(HYDRA-333) git push origin HYDRA-333
|
73
|
-
</pre>
|
74
|
-
|
75
|
-
h3. Rebase the feature branch
|
76
|
-
|
77
|
-
Repeat work until the HYDRA-333 ticket is ready to close, then rebase that work & merge it into the master branch ...
|
78
|
-
|
79
|
-
<pre>
|
80
|
-
(*) git checkout master
|
81
|
-
(master) git pull origin master
|
82
|
-
(master) git checkout HYDRA-333
|
83
|
-
(HYDRA-333) git rebase master
|
84
|
-
... walk through the rebase ...
|
85
|
-
</pre>
|
86
|
-
|
87
|
-
At this point, you should *rerun your full test suite* to make sure that the rebase did not break anything.
|
88
|
-
|
89
|
-
h3. Merge the finished work into Master
|
90
|
-
|
91
|
-
If all of the tests pass after the rebase, you're ready to merge your work into master and push it to github.
|
92
|
-
|
93
|
-
<pre>
|
94
|
-
(HYDRA-333) git checkout master
|
95
|
-
(master) git merge HYDRA-333
|
96
|
-
(master) git push origin master
|
97
|
-
</pre>
|
98
|
-
|
99
|
-
h3. Clean up after yourself
|
100
|
-
|
101
|
-
Now delete the local & remote copies of the feature branch
|
102
|
-
|
103
|
-
<pre>
|
104
|
-
(master) git branch -d HYDRA-333
|
105
|
-
(master) git push origin :HYDRA-333
|
106
|
-
</pre>
|
@@ -1,21 +0,0 @@
|
|
1
|
-
h1. Defining a custom Controller that Manipulates Hydra Assets
|
2
|
-
|
3
|
-
h2. Depositor/Owner Permissions
|
4
|
-
|
5
|
-
Two steps are necessary in order to ensure that your Controller will set the permissions properly on Assets. If you don't follow these steps, users will be able to create objects but won't be able to edit them.
|
6
|
-
|
7
|
-
h3. (1) include AssetsControllerHelper in any Custom Controllers
|
8
|
-
|
9
|
-
This will provide {AssetsControllerHelper#apply_depositor_metadata} method within your Controllers.
|
10
|
-
|
11
|
-
<pre>
|
12
|
-
# in your custom Controllers
|
13
|
-
include Hydra::AssetsControllerHelper
|
14
|
-
</pre>
|
15
|
-
|
16
|
-
h3. (2) call apply_depositor_metadata when you create assets
|
17
|
-
|
18
|
-
In your controllers, whenever you create an asset, call apply_depositor_metadata to update the rightsMetadata and apply any other metadata about the depositor.
|
19
|
-
|
20
|
-
*Important* You must make sure that your models support apply_depositor_metadata. See "HOW_TO_DEFINE_A_HYDRA_MODEL":http://hudson.projecthydra.org/job/hydra-head-rails3-plugin/Documentation/file.HOW_TO_DEFINE_A_HYDRA_MODEL.html for more information about doing this in your custom models.
|
21
|
-
|
@@ -1,64 +0,0 @@
|
|
1
|
-
h1. Defining a custom Hydra Model
|
2
|
-
|
3
|
-
h2. General Introduction/Tutorial
|
4
|
-
|
5
|
-
The "HOW_TO_GET_STARTED":http://hudson.projecthydra.org/job/hydra-head-rails3-plugin/Documentation/file.HOW_TO_GET_STARTED.html tutorial includes a detailed section on defining a JournalArticle model. Read that to get a sense of how to create a working Hydra Model.
|
6
|
-
|
7
|
-
h2. Steps to Defining Your Model
|
8
|
-
|
9
|
-
# Pick xml schema(s)
|
10
|
-
# Create "fixture" XML
|
11
|
-
# Define or reuse OM Terminologies & Datastream Classes for your XML
|
12
|
-
# Write rspec tests for your Datastream classes
|
13
|
-
# Define the Model
|
14
|
-
# Write rspec tests for your Model
|
15
|
-
# Decide what relationships your Model will have & which predicates to use
|
16
|
-
# Add relationship methods to your Model
|
17
|
-
|
18
|
-
Set up rightsMetadata and Depositor/Owner Permissions
|
19
|
-
# make sure objects have a rightsMetadata datastream
|
20
|
-
# include Hydra::ModelMethods in your model
|
21
|
-
|
22
|
-
OM Topics:
|
23
|
-
|
24
|
-
* namespaces
|
25
|
-
* Indexing
|
26
|
-
** index_as
|
27
|
-
** suppressing fields
|
28
|
-
** advanced indexing with custom solr schemas (:displayable and :searchable)
|
29
|
-
* retrieving Terms & Values
|
30
|
-
|
31
|
-
h2. rightsMetadata and Depositor/Owner Permissions
|
32
|
-
|
33
|
-
Two steps are necessary in order to ensure that your controllers will be able to set the permissions on your Assets. If you don't follow these steps, users will be able to create objects but won't be able to edit them.
|
34
|
-
|
35
|
-
Before reading this, make sure to read the page on "Hydra Access Controls":http://hudson.projecthydra.org/job/hydra-head-rails3-plugin/Documentation/file.HYDRA_ACCESS_CONTROLS.html
|
36
|
-
|
37
|
-
h3. (1) make sure objects have a rightsMetadata datastream
|
38
|
-
|
39
|
-
If you are adhering to the formal Hydra commonMetadata cModel, which says that you must have a descMetadata datastream and a rightsMetadata datastream, you can put this line in your model:
|
40
|
-
|
41
|
-
<pre>
|
42
|
-
# This model adheres to the formal Hydra commonMetadata cModel, meaning that it has a descMetadata datastream and a rightsMetadata datastream
|
43
|
-
include Hydra::ModelMixins::CommonMetadata
|
44
|
-
</pre>
|
45
|
-
|
46
|
-
If you are not adhering to the formal Hydra commonMetadata cModel and simply want to have a rightsMetadata datastream, declare the datastream directly in your Model
|
47
|
-
|
48
|
-
<pre>
|
49
|
-
# Explicitly declaring rightsMetadata datastream
|
50
|
-
has_metadata :name => "rightsMetadata", :type => Hydra::RightsMetadata
|
51
|
-
</pre>
|
52
|
-
|
53
|
-
h3. (2) include Hydra::ModelMethods in your model or define custom apply_depositor_metadata method on yoru Model
|
54
|
-
|
55
|
-
{Hydra::ModelMethods} will provide {Hydra::ModelMethods#apply_depositor_metadata} method within your Controllers.
|
56
|
-
|
57
|
-
You might want to override that method with model-specific behavior. The most important behavior to retain is adding +depositor_id+ to the asset's individual edit permissions if the asset has a rightsMetadata datastream.
|
58
|
-
|
59
|
-
<pre>
|
60
|
-
# in your model
|
61
|
-
include Hydra::ModelMethods
|
62
|
-
</pre>
|
63
|
-
|
64
|
-
|
@@ -1,27 +0,0 @@
|
|
1
|
-
h1. Understanding Hydra Access Controls
|
2
|
-
|
3
|
-
h2. How Permissions are Expressed in Hydra rightsMetadata
|
4
|
-
|
5
|
-
h2. How Permissions are Indexed into Solr Documents
|
6
|
-
|
7
|
-
h2. How you can use Alternative Field Names in Solr to Enforce Permissions
|
8
|
-
|
9
|
-
h3. The Access Controls Evaluation helpers
|
10
|
-
|
11
|
-
In your controllers and views you can test whether the current user has read or edit permissions on the current document by calling {reader?} or {editor?}
|
12
|
-
|
13
|
-
To test another type of permission, you can use {test_permission?}
|
14
|
-
|
15
|
-
h2. Assigning "Public" permissions
|
16
|
-
|
17
|
-
In order to give permissions to the public (including users who are not logged in), simply grant group permissions for the "public" group. For example, to give the public "read" permissions, add this to the rightsMetadata
|
18
|
-
|
19
|
-
<pre>
|
20
|
-
<access type="read">
|
21
|
-
<machine>
|
22
|
-
<group>public</group>
|
23
|
-
</machine>
|
24
|
-
</access>
|
25
|
-
</pre>
|
26
|
-
|
27
|
-
This will add "public" to read_access_t in solr.
|
data/INITIAL_APP_MODS.textile
DELETED
@@ -1,223 +0,0 @@
|
|
1
|
-
h1. Initial Modifications to Your Own Hydra Application
|
2
|
-
|
3
|
-
This document explains how to make two basic changes to your hydra rails application and how to write the appropriate tests for them.
|
4
|
-
|
5
|
-
h2. What you will learn from this document:
|
6
|
-
|
7
|
-
# How to Write a Simple Spec (an RSpec test)
|
8
|
-
# How to Change the Rails Application Name of Your Hydra Application
|
9
|
-
# How to Write a Simple Cucumber Feature
|
10
|
-
# How to Change the Home Page Text for Your Hydra Application
|
11
|
-
# How to Change the Facets displayed for Limiting your Search
|
12
|
-
# How to Override a Helper Method
|
13
|
-
|
14
|
-
h2. Making local changes to your Hydra Application
|
15
|
-
|
16
|
-
In order to make it easy to get any new functionality added to the hydra stack (see "README":http://hudson.projecthydra.org/job/hydra-head-rails3-plugin/Documentation/file.README.html), while retaining your Hydra application's localizations, your local hydra application code should be set up to override the upstream Hydra stack code.
|
17
|
-
|
18
|
-
Luckily, rails engines has made this easy - the Hydra code is organized so your localizations are kept separate from the core hydra application code.
|
19
|
-
|
20
|
-
Moreover, to ensure your localizations won't be broken by upgrading the Hydra core code, you should have tests for all your localizations.
|
21
|
-
|
22
|
-
The two key points:
|
23
|
-
|
24
|
-
<b>
|
25
|
-
# always write tests for your local modifications
|
26
|
-
# always change code at the app level, and never change anything in vendor/plugins.
|
27
|
-
</b>
|
28
|
-
|
29
|
-
h3. Easy Changes for Practice.
|
30
|
-
|
31
|
-
h3. Changing the Home Text (also Demonstrates Writing a Feature)
|
32
|
-
|
33
|
-
The home text is set in the view partial (vendor/plugins/hydra-head/)app/views/catalog/_home_text.html.erb
|
34
|
-
|
35
|
-
Because it is set in a view, a cucumber feature is the most appropriate test (rather than an rspec test).
|
36
|
-
|
37
|
-
h4. (1) Write the test.
|
38
|
-
|
39
|
-
Create a file "features/home_page.feature" containing this:
|
40
|
-
|
41
|
-
<pre>
|
42
|
-
Feature: Homepage
|
43
|
-
I want the home page to reflect localizations properly
|
44
|
-
</pre>
|
45
|
-
|
46
|
-
A test for checking the home text might be inserted like so:
|
47
|
-
|
48
|
-
<pre>
|
49
|
-
Feature: Homepage
|
50
|
-
I want the home page to reflect localizations properly
|
51
|
-
|
52
|
-
Scenario: home page text
|
53
|
-
When I am on the home page
|
54
|
-
Then I should not see "override"
|
55
|
-
And I should see "My Local Hydra App"
|
56
|
-
And I should see "Isn't it great?"
|
57
|
-
And I should see "Search"
|
58
|
-
</pre>
|
59
|
-
|
60
|
-
h4. (2) Run the test - it should fail
|
61
|
-
|
62
|
-
When you run this feature, the feature should run, but this test should fail (because you haven't changed anything yet.)
|
63
|
-
|
64
|
-
h4. (3) Change the code
|
65
|
-
|
66
|
-
We want to override the text on the home page locally, keeping our local changes separate from upstream changes to the plugins' code.
|
67
|
-
|
68
|
-
Since the home text is set in vendor/plugins/hydra-head/app/views/catalog/_home_text.html.erb, we will override that code by creating a local app/views/catalog/_home_text.html.erb file.
|
69
|
-
|
70
|
-
Our app/views/catalog/_home_text.html.erb might look like this
|
71
|
-
|
72
|
-
<pre>
|
73
|
-
<div id="results">
|
74
|
-
|
75
|
-
<%= render :partial=>'search_form' %>
|
76
|
-
|
77
|
-
<div class="home_text">
|
78
|
-
<h1>Welcome to My Local Hydra App</h1>
|
79
|
-
<br/>
|
80
|
-
<p>This is my local Hydra application. Isn't it great?
|
81
|
-
</p>
|
82
|
-
</div>
|
83
|
-
|
84
|
-
</div>
|
85
|
-
</pre>
|
86
|
-
|
87
|
-
h4. (4) Run the test - it should now pass
|
88
|
-
|
89
|
-
Now when you run the feature, it should pass. If it doesn't, iterate until it does.
|
90
|
-
|
91
|
-
h3. Changing the Facets
|
92
|
-
|
93
|
-
h4. (1) Write the test.
|
94
|
-
|
95
|
-
Write the cucumber tests for the facets you want
|
96
|
-
|
97
|
-
Create a file in your features directory called homepage_facets.feature and put the following feature description in it. Note that this cucumber test is assuming you have imported the Hydra sample/fixture objects.
|
98
|
-
|
99
|
-
<pre>
|
100
|
-
Feature: Homepage Facets
|
101
|
-
I want the home page to include the facets I chose
|
102
|
-
|
103
|
-
Scenario: home page facets
|
104
|
-
When I am on the home page
|
105
|
-
Then I should see "Fedora Model"
|
106
|
-
And I should see "info:fedora/afmodel:ModsAsset"
|
107
|
-
Then I should see "Topic"
|
108
|
-
Then I should see "Journal"
|
109
|
-
And I should see "The Journal of Mock Object"
|
110
|
-
And I should see "Pediatric Nursing"
|
111
|
-
Then I should see "Conference"
|
112
|
-
And I should see "some conference Host"
|
113
|
-
</pre>
|
114
|
-
|
115
|
-
h4. (2) Run the test - it should fail
|
116
|
-
|
117
|
-
Now run the test and watch it fail
|
118
|
-
|
119
|
-
<pre>
|
120
|
-
cucumber features
|
121
|
-
</pre>
|
122
|
-
|
123
|
-
h4. (3) Change the code
|
124
|
-
|
125
|
-
Modify blacklight_config.rb to use the facets you want.
|
126
|
-
|
127
|
-
In config/initializers/blacklight_config.rb, find the section that begins "config[:facet] =" (around line 45) and replace it with this:
|
128
|
-
|
129
|
-
<pre>
|
130
|
-
config[:facet] = {
|
131
|
-
:field_names => (facet_fields = [
|
132
|
-
"has_model_s",
|
133
|
-
"subject_topic_facet",
|
134
|
-
"journal_title_info_main_title_facet",
|
135
|
-
"conference_facet"
|
136
|
-
]),
|
137
|
-
:labels => {
|
138
|
-
"has_model_s" => "Fedora Model",
|
139
|
-
"subject_topic_facet" => "Topic",
|
140
|
-
"journal_title_info_main_title_facet" => "Journal",
|
141
|
-
"conference_facet" => "Conference"
|
142
|
-
},
|
143
|
-
</pre>
|
144
|
-
|
145
|
-
h4. (4) Run the test - it should now pass
|
146
|
-
|
147
|
-
Now run the test and watch it pass!
|
148
|
-
|
149
|
-
<pre>
|
150
|
-
cucumber features
|
151
|
-
</pre>
|
152
|
-
|
153
|
-
To see the changes for yourself, restart the application.
|
154
|
-
|
155
|
-
h3. Overriding a Helper Method (also Demonstrates Writing a Spec)
|
156
|
-
|
157
|
-
We want to change the application name (what displays as the html page's title). This is set in a plugin's app/helper/application_helper.rb file. Because it is set in a helper file, it is a good candidate for an rspec test (rather than a feature).
|
158
|
-
|
159
|
-
h4. (1) Write the test.
|
160
|
-
|
161
|
-
Since the application name is set in (vendor/plugins/hydra-head/)app/helpers/application_helper.rb, we need a spec to run against the application_helper file.
|
162
|
-
|
163
|
-
Create a file "spec/helpers/application_helper_spec.rb" containing this:
|
164
|
-
|
165
|
-
<pre>
|
166
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
167
|
-
|
168
|
-
describe ApplicationHelper do
|
169
|
-
include ApplicationHelper
|
170
|
-
end
|
171
|
-
</pre>
|
172
|
-
|
173
|
-
A test for checking the application name might be inserted like so:
|
174
|
-
|
175
|
-
<pre>
|
176
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
177
|
-
|
178
|
-
describe ApplicationHelper do
|
179
|
-
include ApplicationHelper
|
180
|
-
|
181
|
-
describe "Overall UI methods" do
|
182
|
-
it "should get the local application name" do
|
183
|
-
application_name.should == "My Hydra"
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
end
|
188
|
-
</pre>
|
189
|
-
|
190
|
-
h4. (2) Run the test - it should fail
|
191
|
-
|
192
|
-
When you run this spec, the spec should run, but this test should fail (because you haven't changed anything yet.)
|
193
|
-
|
194
|
-
h4. (3) Change the code
|
195
|
-
|
196
|
-
We want to override the application name locally, keeping our local changes separate from upstream changes to the plugins' code.
|
197
|
-
|
198
|
-
Since the application name is set in vendor/plugins/hydra-head/app/helpers/application_helper.rb, we will override that code by putting a method of the same name in app/helpers/application_helper.rb. The current app/helpers/application_helper.rb file may look like this:
|
199
|
-
|
200
|
-
<pre>
|
201
|
-
# Methods added to this helper will be available to all templates in the application.
|
202
|
-
module ApplicationHelper
|
203
|
-
end
|
204
|
-
</pre>
|
205
|
-
|
206
|
-
Code for changing the application name might be inserted like so:
|
207
|
-
|
208
|
-
<pre>
|
209
|
-
# Methods added to this helper will be available to all templates in the application.
|
210
|
-
module ApplicationHelper
|
211
|
-
|
212
|
-
def application_name
|
213
|
-
'My Hydra'
|
214
|
-
end
|
215
|
-
|
216
|
-
end
|
217
|
-
</pre>
|
218
|
-
|
219
|
-
h4. (4) Run the test - it should now pass
|
220
|
-
|
221
|
-
Now when you run the spec, it should pass. If it doesn't, iterate until it does.
|
222
|
-
|
223
|
-
|