hydra-head 3.0.0pre1 → 3.0.0pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/Gemfile.lock +6 -4
  2. data/HOW_TO_GET_STARTED.textile +571 -0
  3. data/HYDRA_ACCESS_CONTROLS.textile +27 -0
  4. data/INITIAL_APP_MODS.textile +239 -0
  5. data/README.textile +22 -7
  6. data/README_RAILS3_CHANGES.textile +23 -2
  7. data/app/views/catalog/_sort_and_per_page.html.erb +3 -2
  8. data/app/views/catalog/show.html.erb +1 -1
  9. data/lib/generators/hydra/cucumber_support_generator.rb +29 -0
  10. data/lib/generators/hydra/head_generator.rb +6 -14
  11. data/lib/generators/hydra/hyhead_fixtures_generator.rb +27 -0
  12. data/lib/generators/hydra/templates/config/initializers/fedora_config.rb +3 -1
  13. data/lib/hydra-head/version.rb +1 -1
  14. data/lib/hydra/access_controls_evaluation.rb +8 -4
  15. data/lib/hydra/{fixtures.rb → fixture_loader.rb} +14 -9
  16. data/lib/railties/hydra-fixtures.rake +5 -5
  17. data/tasks/hydra-head.rake +36 -25
  18. data/test_support/features/file_upload.feature +1 -1
  19. data/test_support/features/mods_asset_search_result.feature +12 -1
  20. data/test_support/features/step_definitions/edit_metadata_steps.rb +2 -2
  21. data/test_support/features/step_definitions/show_document_steps.rb +4 -0
  22. data/test_support/spec/helpers/access_controls_enforcement_spec.rb +62 -10
  23. data/vendor/cache/addressable-2.2.6.gem +0 -0
  24. data/vendor/cache/launchy-2.0.4.gem +0 -0
  25. data/vendor/cache/mediashelf-loggable-0.4.3.gem +0 -0
  26. data/vendor/cache/multipart-post-1.1.3.gem +0 -0
  27. metadata +15 -13
  28. data/lib/generators/hydra/templates/migrations/add_user_attributes_table.rb +0 -15
  29. data/test_support/features/html_validity.feature +0 -47
  30. data/vendor/cache/launchy-2.0.3.gem +0 -0
  31. data/vendor/cache/mediashelf-loggable-0.4.2.gem +0 -0
  32. data/vendor/cache/multipart-post-1.1.2.gem +0 -0
@@ -0,0 +1,27 @@
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.
@@ -0,0 +1,239 @@
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
+ h3. 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
+
12
+
13
+ h2. Making local changes to your Hydra Application
14
+
15
+ 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.
16
+
17
+ Luckily, rails engines has made this easy - the Hydra code is organized so your localizations are kept separate from the core hydra application code.
18
+
19
+ Moreover, to ensure your localizations won't be broken by upgrading the Hydra core code, you should have tests for all your localizations.
20
+
21
+ The two key points:
22
+
23
+ <b>
24
+ # always write tests for your local modifications
25
+ # always change code at the app level, and never change anything in vendor/plugins.
26
+ </b>
27
+
28
+ h3. tests tests tests
29
+
30
+ We STRONGLY recommend that you write tests for every local change you make. This will allow you to ensure that upgrading the core code doesn't break any local changes you have made.
31
+
32
+ (when should it be a feature rather than a spec)
33
+ very basic rule: if it's testing something created with view, use a cucumber feature to test. If it's not created by view code, use a spec to test.
34
+
35
+ h4. Run generator for specs
36
+
37
+ To create the infrastructure pieces to write specs:
38
+
39
+ <pre>
40
+ ./script/generate rspec
41
+ </pre>
42
+
43
+ h4. Run generator for features
44
+
45
+ To create the infrastructure pieces to write cucumber features:
46
+
47
+ <pre>
48
+ ./script/generate cucumber
49
+ </pre>
50
+
51
+
52
+ h3. Easy Changes for Practice.
53
+
54
+ h3. Changing the Facets
55
+
56
+ h4. Write the cucumber tests for the facets you want
57
+
58
+ 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.
59
+
60
+ <pre>
61
+ Feature: Homepage Facets
62
+ I want the home page to include the facets I chose
63
+
64
+ Scenario: home page facets
65
+ When I am on the home page
66
+ Then I should see "Fedora Model"
67
+ And I should see "info:fedora/afmodel:ModsAsset"
68
+ Then I should see "Topic"
69
+ Then I should see "Journal"
70
+ And I should see "The Journal of Mock Object"
71
+ And I should see "Pediatric Nursing"
72
+ Then I should see "Conference"
73
+ And I should see "some conference Host"
74
+ </pre>
75
+
76
+ Now run the test and watch it fail
77
+
78
+ <pre>
79
+ cucumber features
80
+ </pre>
81
+
82
+ h4. Modify blacklight_config.rb to use the facets you want
83
+
84
+ In config/initializers/blacklight_config.rb, find the section that begins "config[:facet] =" (around line 45) and replace it with this:
85
+
86
+ <pre>
87
+ config[:facet] = {
88
+ :field_names => (facet_fields = [
89
+ "has_model_s",
90
+ "subject_topic_facet",
91
+ "journal_title_info_main_title_facet",
92
+ "conference_facet"
93
+ ]),
94
+ :labels => {
95
+ "has_model_s" => "Fedora Model",
96
+ "subject_topic_facet" => "Topic",
97
+ "journal_title_info_main_title_facet" => "Journal",
98
+ "conference_facet" => "Conference"
99
+ },
100
+ </pre>
101
+
102
+ Now run the test and watch it pass!
103
+
104
+ <pre>
105
+ cucumber features
106
+ </pre>
107
+
108
+ To see the changes for yourself, restart the application.
109
+
110
+ h3. Changing the Home Text (also Demonstrates Writing a Feature)
111
+
112
+ The home text is set in the view partial (vendor/plugins/hydra-head/)app/views/catalog/_home_text.html.erb
113
+
114
+ Because it is set in a view, a cucumber feature is the most appropriate test (rather than an rspec test).
115
+
116
+ h4. (1) Write the test.
117
+
118
+ Create a file "features/home_page.feature" containing this:
119
+
120
+ <pre>
121
+ Feature: Homepage
122
+ I want the home page to reflect localizations properly
123
+ </pre>
124
+
125
+ A test for checking the home text might be inserted like so:
126
+
127
+ <pre>
128
+ Feature: Homepage
129
+ I want the home page to reflect localizations properly
130
+
131
+ Scenario: home page text
132
+ When I am on the home page
133
+ Then I should not see "override"
134
+ And I should see "My Local Hydra App"
135
+ And I should see "Isn't it great?"
136
+ And I should see "Search"
137
+ </pre>
138
+
139
+ h4. (2) Run the test - it should fail
140
+
141
+ When you run this feature, the feature should run, but this test should fail (because you haven't changed anything yet.)
142
+
143
+ h4. (3) Change the code
144
+
145
+ We want to override the text on the home page locally, keeping our local changes separate from upstream changes to the plugins' code.
146
+
147
+ 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.
148
+
149
+ Our app/views/catalog/_home_text.html.erb might look like this
150
+
151
+ <pre>
152
+ <div id="results">
153
+
154
+ <%= render :partial=>'search_form' %>
155
+
156
+ <div class="home_text">
157
+ <h1>Welcome to My Local Hydra App</h1>
158
+ <br/>
159
+ <p>This is my local Hydra application. Isn't it great?
160
+ </p>
161
+ </div>
162
+
163
+ </div>
164
+ </pre>
165
+
166
+ h4. (4) Run the test - it should now pass
167
+
168
+ Now when you run the feature, it should pass. If it doesn't, iterate until it does.
169
+
170
+
171
+ h3. Overriding a Helper Method (also Demonstrates Writing a Spec)
172
+
173
+ 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).
174
+
175
+ h4. (1) Write the test.
176
+
177
+ 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.
178
+
179
+ Create a file "spec/helpers/application_helper_spec.rb" containing this:
180
+
181
+ <pre>
182
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
183
+
184
+ describe ApplicationHelper do
185
+ include ApplicationHelper
186
+ end
187
+ </pre>
188
+
189
+ A test for checking the application name might be inserted like so:
190
+
191
+ <pre>
192
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
193
+
194
+ describe ApplicationHelper do
195
+ include ApplicationHelper
196
+
197
+ describe "Overall UI methods" do
198
+ it "should get the local application name" do
199
+ application_name.should == "My Hydra"
200
+ end
201
+ end
202
+
203
+ end
204
+ </pre>
205
+
206
+ h4. (2) Run the test - it should fail
207
+
208
+ When you run this spec, the spec should run, but this test should fail (because you haven't changed anything yet.)
209
+
210
+ h4. (3) Change the code
211
+
212
+ We want to override the application name locally, keeping our local changes separate from upstream changes to the plugins' code.
213
+
214
+ 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:
215
+
216
+ <pre>
217
+ # Methods added to this helper will be available to all templates in the application.
218
+ module ApplicationHelper
219
+ end
220
+ </pre>
221
+
222
+ Code for changing the application name might be inserted like so:
223
+
224
+ <pre>
225
+ # Methods added to this helper will be available to all templates in the application.
226
+ module ApplicationHelper
227
+
228
+ def application_name
229
+ 'My Hydra'
230
+ end
231
+
232
+ end
233
+ </pre>
234
+
235
+ h4. (4) Run the test - it should now pass
236
+
237
+ Now when you run the spec, it should pass. If it doesn't, iterate until it does.
238
+
239
+
data/README.textile CHANGED
@@ -50,15 +50,15 @@ First, add them to the Gemfile of your application:
50
50
  <pre>
51
51
  source 'http://rubygems.org'
52
52
 
53
- gem 'rails', '>=3.0.4'
53
+ gem 'rails', '~>3.0.4'
54
54
 
55
55
  gem 'blacklight', '~> 3.0.0'
56
56
  gem 'hydra-head', '3.0.0pre1'
57
-
57
+
58
58
  # We will assume that you're using sqlite3 for testing/demo,
59
59
  # but in a production setup you probably want to use a real sql database like mysql or postgres
60
60
  gem 'sqlite3-ruby', :require => 'sqlite3'
61
-
61
+
62
62
  # We will assume you're using devise in tutorials/documentation.
63
63
  # You are free to implement your own User/Authentication solution in its place.
64
64
  gem 'devise'
@@ -76,7 +76,6 @@ First, add them to the Gemfile of your application:
76
76
  gem 'capybara'
77
77
  #gem 'webrat'
78
78
  #gem 'aruba'
79
- gem 'factory_girl'
80
79
  gem 'bcrypt-ruby'
81
80
  end
82
81
  </pre>
@@ -87,15 +86,24 @@ To install all of the dependencies, run:
87
86
  bundle install
88
87
  </pre>
89
88
 
89
+ This will take a _very_ long time the first time you run it. IF you become impatient, hit Ctl+C then enter this:
90
+
91
+ <pre>
92
+ gem install blacklight
93
+ gem install hydra-head -v 3.0.0pre1
94
+ </pre>
95
+
96
+ Then re-run bundle install and it will run slightly faster.
97
+
90
98
  h3. Run the generators and migrations:
91
99
 
92
100
  Run the blacklight generator
93
101
 
94
- <pre>rails g blackight -devise</pre>
102
+ <pre>rails g blacklight -devise</pre>
95
103
 
96
104
  Run the hydra-head generator
97
105
 
98
- <pre>rails g hydra-head -df</pre>
106
+ <pre>rails g hydra:head -df</pre>
99
107
 
100
108
  Run the database migrations
101
109
 
@@ -122,8 +130,15 @@ The Hydra project provides a copy of Jetty with Fedora and Solr pre-installed.
122
130
  Most projects add hydra jetty to their code as a git submodule
123
131
 
124
132
  <pre>
125
- git submodule add git@github.com:projecthydra/hydra-jetty.git jetty
133
+ git submodule add git://github.com/projecthydra/hydra-jetty.git jetty
126
134
  git commit -m"added jetty submodule"
135
+ cd jetty
136
+ git fetch --tags
137
+ git checkout last_solr_multicore
138
+ git checkout -b last_solr_multicore
139
+ cd ..
140
+ git add jetty
141
+ git commit -m "Pinned jetty to last_solr_multicore"
127
142
  </pre>
128
143
 
129
144
  Now that you've added the submodule to your git repository, whenever you grab a new working copy of the code, you can get hydra-jetty by running:
@@ -3,9 +3,15 @@ h2. Fixtures
3
3
 
4
4
  Fixtures are loaded from a directory _within the test app_, which is updated when you run rake hyhead:setup_test_app so in order to update a fixture, you must change it in test_support/fixtures and then either re-run rake hyhead:setup_test_app or copy the fixture into tmp/test_app/test_support/fixtures
5
5
 
6
+ h2. Cucumber tests
7
+
8
+ We have switched from Webrat to Capybara as the driver for our Cucumber tests. If you have been writing your own cucumber tests (you should!) and want to stay in sync with the rest of the hydra developers, you should switch to Capybara and pull all of the "step definitions from the hydra code":https://github.com/projecthydra/hydra-head/tree/rails3/test_support/features/step_definitions into your local app.
9
+
10
+ Sometime soon, we hope to wrap our step definitions into the Hydra code itself so that you can use them without having to manually copy the files into your step_definitions directory. This will probably be done in a way that imitates the "Factory Girl step definitions":http://robots.thoughtbot.com/post/284805810/gimme-three-steps
11
+
6
12
  h2. User objects
7
13
 
8
- Blacklight has switched to using devise instead of authlogic as its default user/authentication system. As part of this switch, no longer have a "login" attribute as their unique identifier. Instead, you must use email as the unique identifier.
14
+ Blacklight has switched to using devise instead of authlogic as its default user/authentication system. As part of this switch, no longer have a "login" attribute as their unique identifier. Instead, you must use email as the unique identifier. We have added a "login" method that
9
15
 
10
16
  h2. User Attributes
11
17
 
@@ -32,11 +38,26 @@ Change your features and role_map YAML files accordingly.
32
38
 
33
39
  h2. How to upgrade
34
40
 
41
+ The sureest and easiest path to upgrading a hydra head application from Rails 2 to Rails 3, is to start a new project from scratch.
42
+
35
43
  * Create a new rails 3 project
36
44
  * Add ```gem 'blacklight'``` and ```gem 'hydra-head'``` to the Gemfile
37
45
  * run ```bundle install```
38
46
  * cp -r old_project/vendor/plugin/old_project_plugin/app/* new_project/app
39
47
  * cp -r old_project/vendor/plugin/old_project_plugin/lib/* new_project/lib
48
+ <<<<<<< HEAD
49
+ * copy any tests (test, spec, feature, etc) from the old_project_plugin directory to the new project
50
+ * Run the generators
51
+ ```rails g blackight -devise```
52
+ Run the hydra-head generator
53
+ ```rails g hydra:head -df```
54
+ Run the database migrations
55
+ ```rake db:migrate
56
+ rake db:migrate RAILS_ENV=test```
57
+
58
+ * If you will be writing cucumber tests, run the cucumber generator
59
+ ```rails g cucumber:install```
40
60
  * copy any tests (test, spec, feature, etc) from the old_project_plugin directory to the new project
41
-
61
+ * update your solrconfig.xml
62
+ * update your role_map_...yml files to use appropriate identifiers
42
63
 
@@ -1,8 +1,9 @@
1
1
  <div id="sortAndPerPage">
2
2
  <% unless @response.response['numFound'] < 2 %>
3
3
  <%= form_tag catalog_index_path, :method=>:get, :class=>'per_page' do %>
4
- <%= label_tag(:per_page, "Show " + select_tag(:per_page, options_for_select(['10', '20', '50', '100'], h(params[:per_page])), :title => "Number of results to display per page", :onchange => 'this.form.submit()') + " per page") %>
5
-
4
+ <%= label_tag(:per_page, "Show") %>
5
+ <%= select_tag(:per_page, options_for_select(['10', '20', '50', '100'], h(params[:per_page])), :title => "Number of results to display per page", :onchange => 'this.form.submit()') %>
6
+ per page
6
7
  <%= search_as_hidden_fields(:omit_keys => [:page, :per_page]) %>
7
8
 
8
9
  <noscript><%= submit_tag 'update' %></noscript>
@@ -26,7 +26,7 @@
26
26
  <% end -%>
27
27
  <div id="document" class="<%= controller.action_name == "edit" ? "document_edit" : "document_show" %>">
28
28
  <div id="<%= format_pid(@document[:id]) %>">
29
- <h1><%= render_document_heading.html_safe %></h1>
29
+ <%= render_document_heading.html_safe %>
30
30
  <div class="document">
31
31
  <%= render_document_partial @document, params["action"] %>
32
32
  </div>
@@ -0,0 +1,29 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ module Hydra
6
+ class CucumberSupportGenerator < Rails::Generators::Base
7
+
8
+ source_root File.expand_path('../../../../test_support/features', __FILE__)
9
+
10
+ argument :features_dir, :type => :string , :default => "features"
11
+
12
+ desc """
13
+ This Generator copies Hydra's cucumber step definitions and paths into your application's features directory.
14
+ We have plans to provide the step definitions directly through the hydra-head gem without requiring this step of copying the files.
15
+ In the meantime, you need to copy the files in order to use them.
16
+
17
+ Defaults to assuming that your cucumber features live in a directory called \"features\". To pass in an alternative path to your features directory,
18
+
19
+ rails generate hydra:cucumber_support test_support/features
20
+
21
+ """
22
+
23
+ def copy_cucumber_support
24
+ directory("step_definitions", "#{features_dir}/step_definitions")
25
+ copy_file("support/paths.rb", "#{features_dir}/support/paths.rb")
26
+ end
27
+
28
+ end
29
+ end
@@ -2,8 +2,6 @@
2
2
  require 'rails/generators'
3
3
  require 'rails/generators/migration'
4
4
 
5
- # require "generators/blacklight/blacklight_generator"
6
-
7
5
  module Hydra
8
6
  class HeadGenerator < Rails::Generators::Base
9
7
  include Rails::Generators::Migration
@@ -14,7 +12,7 @@ class HeadGenerator < Rails::Generators::Base
14
12
 
15
13
  desc """
16
14
  This generator makes the following changes to your application:
17
- 1. Creates several database migrations if they do not exist in /db/migrate
15
+ 1. Creates a database migration for superusers if they do not exist in /db/migrate
18
16
  2. Adds additional mime types to you application in the file '/config/initializers/mime_types.rb'
19
17
  3. Creates config/initializers/hydra_config.rb
20
18
  4. Creates config/initializers/fedora_config.rb
@@ -77,16 +75,12 @@ EOF
77
75
  # Implement the required interface for Rails::Generators::Migration.
78
76
  # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
79
77
  def self.next_migration_number(dirname)
80
- unless @previous_migration_nr
81
- if ActiveRecord::Base.timestamped_migrations
82
- @previous_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
83
- else
84
- @previous_migration_nr = "%.3d" % (current_migration_number(dirname) + 1).to_i
85
- end
78
+ unless @prev_migration_nr
79
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
86
80
  else
87
- @previous_migration_nr +=1
81
+ @prev_migration_nr += 1
88
82
  end
89
- @previous_migration_nr.to_s
83
+ @prev_migration_nr.to_s
90
84
  end
91
85
 
92
86
  # Add Hydra behaviors to the user model
@@ -98,7 +92,7 @@ EOF
98
92
  "\n include Hydra::User\n"
99
93
  end
100
94
  else
101
- puts " \e[31mFailure\e[0m Hydra requires a user object in order to apply access controls. This generators assumes that the model is defined in the file /app/models/user.rb, which does not exist. If you used a different name, please re-run the migration and provide that name as an argument. Such as \b rails -g hydra:head client"
95
+ puts " \e[31mFailure\e[0m Hydra requires a user object in order to apply access controls. This generators assumes that the model is defined in the file /app/models/user.rb, which does not exist. If you used a different name, please re-run the generator and provide that name as an argument. Such as \b rails -g hydra:head client"
102
96
  end
103
97
  end
104
98
 
@@ -139,8 +133,6 @@ EOF
139
133
  end
140
134
 
141
135
  def create_migration_file
142
- migration_template 'migrations/add_user_attributes_table.rb', 'db/migrate/add_user_attributes_table.rb'
143
- sleep 1 # ensure scripts have different time stamps
144
136
  migration_template 'migrations/create_superusers.rb', 'db/migrate/create_superusers.rb'
145
137
  end
146
138