Skip to content

Upgrade guide from Rails 2 (HydraHead 2.x) to Rails 3

ndushay edited this page Apr 6, 2012 · 6 revisions

How to upgrade

The surest and easiest path to upgrading a Hydra application from Rails 2 to Rails 3 is to start a new project from scratch.

  1. Create a new Rails 3 project
    rails new my_new_project
  2. Add the following to the Gemfile

    gem ‘blacklight’
    gem ‘hydra-head’
  3. run
    bundle install
  4. Copy your local code to the new app

    cp -r old_project/vendor/plugin/old_project_plugin/app/* my_new_project/app
    cp -r old_project/vendor/plugin/old_project_plugin/lib/* my_new_project/lib
  5. Run the generators

    rails g blackight -devise
    rails g hydra:head -df
  6. Run the database migrations

    rake db:migrate
    rake db:migrate RAILS_ENV=test
  7. If you will be writing cucumber tests, run the cucumber generator
    rails g cucumber:install

    Note that RSpec is registered with Rails 3 as the test framework, so whenever you generate application components like models, controllers, etc, RSpec specs are generated instead of Test::Unit tests.
  8. Copy any tests (test, spec, feature, fixtures, etc) from the old_project_plugin directory to the new project

    cp -r old_project/vendor/plugin/old_project_plugin/feature/* my_new_project/feature
    cp -r old_project/vendor/plugin/old_project_plugin/spec/* my_new_project/spec
    cp -r old_project/vendor/plugin/old_project_plugin/test/* my_new_project/test
  9. Update your solrconfig.xml
  10. Update your role_map_…yml files to use appropriate identifiers

Significant Differences between Rails 3 and Rails 2 HydraHead

HydraHead is now a Gem

Rails 3 enables engines to be gems, rather than plugins. This is a much cleaner way to implement HydraHead, greatly simplifying installation and testing. Blacklight, a dependency of HydraHead, has also become a gem in Rails 3.

Controllers

  • Removed Djatoka (JPEG 2000) support and the GetController.
  • CatalogController: filter out objects that you want to exclude from search results. By default, this will filter out FileAssets:
    CatalogController.solr_search_params_logic << :exclude_unwanted_models

Views

Security has been tightened in Rails3, forcing you to include authenticity_token with all requests. If you have forms or javascript that submits requests without this token, Rails will destroy the user session, effectively logging the user out (see http://weblog.rubyonrails.org/2011/2/8/csrf-protection-bypass-in-ruby-on-rails). The easiest way to make sure this token is properly included in your forms is to generate the forms using the form_tag or form_for view helpers from Rails.

Also

  • removed fluid infusion javascript
  • moved javascripts from the plugin directory. Update your views to remove “:plugin=>:hydra_repository”

User objects

Blacklight has switched to using devise instead of authlogic as its default user/authentication system. As part of this switch, users 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 … “Shiny!”

User Attributes

User attributes (first_name, last_name, full_name, affiliation and photo) have been removed from HydraHead.

What this means:

  • Our sample user “archivist1” is now “[email protected]”.
  • Your cucumber features and rspec tests must use email addresses as the unique identifier for Users

Change your features and role_map YAML files accordingly.

Fixtures

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.

Cucumber tests

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 into your local app.

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 .