diff --git a/.gitignore b/.gitignore index 7d81db4a..3b40c87d 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,6 @@ /tmp Gemfile.lock Gemfile.lock -coverage \ No newline at end of file +coverage +pkg +spec/internal diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7259cf90..517b1d20 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -78,8 +78,6 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr ### Submitting Changes -[Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/) - * Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub. * Make sure your branch is up to date with its parent branch (i.e. master) * `git checkout master` diff --git a/Gemfile b/Gemfile index 9a7810a8..5f130e6a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,51 +1,6 @@ -source 'https://rubygems.org' - -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.0.0' - -# Use sqlite3 as the database for Active Record -gem 'sqlite3' - -# Use SCSS for stylesheets -gem 'sass-rails', '~> 4.0.0' - -# Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' - -# Use CoffeeScript for .js.coffee assets and views -gem 'coffee-rails', '~> 4.0.0' - -# Use jquery as the JavaScript library -gem 'jquery-rails' - -# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks -gem 'turbolinks' - -# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 1.2' - -# For bulk data imports -gem 'activerecord-import', '>= 0.4.0' - -group :doc do - # bundle exec rake doc:rails generates the API under doc/api. - gem 'sdoc', require: false -end - -gem 'curb' -gem 'nokogiri', '~> 1.6.0' - -group :development, :test do - gem 'rspec' - gem 'rspec-rails' - gem 'debugger' - # See https://github.com/sstephenson/execjs#readme for more supported runtimes - gem 'therubyracer', platforms: :ruby -end -group :test do - gem 'rspec' - gem 'rspec-rails' - gem 'webmock' - gem 'simplecov', require: false -end +source "https://rubygems.org" +# Declare your gem's dependencies in qa.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..9305749f --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +########################################################################## +# Copyright 2013 Rock and Roll Hall of Fame and Museum +# Additional copyright may be held by others, as reflected in the commit log +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index d1167606..afa406c9 100644 --- a/README.md +++ b/README.md @@ -22,25 +22,37 @@ results from a given vocabulary in the JSON format. The controller does three t ### Sub-Authorities -Some authorties, such as Library of Congress, allow sub-authorties which is an additional parameter that +Some authorities, such as Library of Congress, allow sub-authorities which is an additional parameter that further defines the kind of authority to use with the context of a larger one. +## How do use this? + +Add the gem to your Gemfile + + gem 'qa' + +Add the engine to your config/routes.rb file + + mount Qa::Engine => '/qa' + +Start questioning your authorities! + ### Examples Return a complete list of terms: - /terms/:vocab - /terms/:vocab/:sub_authority + /qa/terms/:vocab + /qa/terms/:vocab/:sub_authority Return a set of terms matching a given query - /search/:vocab?q=search_term - /search/:vocab/:sub_authority?q=search_term + /qa/search/:vocab?q=search_term + /qa/search/:vocab/:sub_authority?q=search_term Return the complete information for a specific term given its identifier - /show/:vocab/:id - /show/:vocab/:sub_authority/:id + /qa/show/:vocab/:id + /qa/show/:vocab/:sub_authority/:id ### JSON Results @@ -55,7 +67,7 @@ Results are returned in JSON in this format: Results for specific terms may vary according to the term. For example: - /show/mesh/D000001 + /qa/show/mesh/D000001 Might return: @@ -65,7 +77,7 @@ Might return: "synonyms" : ["A-23187", "A23187", "Antibiotic A23187", "A 23187", "A23187, Antibiotic"] } -This is due to the varing nature of each authority source. However, results for multiple terms, such as a search, we +This is due to the varying nature of each authority source. However, results for multiple terms, such as a search, we should always use the above id and label structure to ensure interoperability at the GUI level. # Authority Sources information @@ -131,11 +143,20 @@ This may take a few minutes to finish. # TODOs -* Make this an engine * Provide show method to TermsController to return individual terms check the issue list for more... +# Developer Notes + +To develop this gem, clone the repository, then run: + + bundle install + rake + +This will install the gems, create a dummy application under spec/internal and run the tests. After you've made changes, remove the entire spec/internal +directory so that further tests and run against a new dummy application. + # Authors * Stephen Anderson diff --git a/Rakefile b/Rakefile index 1dadac52..f3779749 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,10 @@ -# Add your own tasks in files placed in lib/tasks ending in .rake, -# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. +#!/usr/bin/env rake +require "bundler/gem_tasks" -require File.expand_path('../config/application', __FILE__) +Dir.glob('tasks/*.rake').each { |r| import r } -QuestioningAuthority::Application.load_tasks +ENV["RAILS_ROOT"] ||= 'spec/internal' + +require 'rspec/core/rake_task' + +task :default => [:spec] diff --git a/app/assets/images/.keep b/app/assets/images/qa/.keep similarity index 100% rename from app/assets/images/.keep rename to app/assets/images/qa/.keep diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/qa/application.js similarity index 90% rename from app/assets/javascripts/application.js rename to app/assets/javascripts/qa/application.js index d6925fa4..5bc2e1c8 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/qa/application.js @@ -10,7 +10,4 @@ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details // about supported directives. // -//= require jquery -//= require jquery_ujs -//= require turbolinks //= require_tree . diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/qa/application.css similarity index 100% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/qa/application.css diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb deleted file mode 100644 index d83690e1..00000000 --- a/app/controllers/application_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ApplicationController < ActionController::Base - # Prevent CSRF attacks by raising an exception. - # For APIs, you may want to use :null_session instead. - protect_from_forgery with: :exception -end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/controllers/qa/application_controller.rb b/app/controllers/qa/application_controller.rb new file mode 100644 index 00000000..c02ac82f --- /dev/null +++ b/app/controllers/qa/application_controller.rb @@ -0,0 +1,4 @@ +module Qa + class ApplicationController < ActionController::Base + end +end diff --git a/app/controllers/terms_controller.rb b/app/controllers/qa/terms_controller.rb similarity index 95% rename from app/controllers/terms_controller.rb rename to app/controllers/qa/terms_controller.rb index b22e04b9..fee90cc1 100644 --- a/app/controllers/terms_controller.rb +++ b/app/controllers/qa/terms_controller.rb @@ -2,7 +2,7 @@ # which class to instantiate based on the "vocab" param. All the authotirty classes inherit from a # super class so they implement the same methods. -class TermsController < ApplicationController +class Qa::TermsController < ApplicationController before_action :check_search_params, only:[:search] before_action :check_vocab_param, :check_authority, :check_sub_authority @@ -70,7 +70,7 @@ def check_sub_authority private def authority_class - "Authorities::"+params[:vocab].capitalize + "Qa::Authorities::"+params[:vocab].capitalize end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb deleted file mode 100644 index de6be794..00000000 --- a/app/helpers/application_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ApplicationHelper -end diff --git a/app/helpers/qa/application_helper.rb b/app/helpers/qa/application_helper.rb new file mode 100644 index 00000000..956e535a --- /dev/null +++ b/app/helpers/qa/application_helper.rb @@ -0,0 +1,2 @@ +module Qa::ApplicationHelper +end diff --git a/app/mailers/.keep b/app/mailers/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/models/.keep b/app/models/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/models/mesh_tree.rb b/app/models/qa/mesh_tree.rb similarity index 95% rename from app/models/mesh_tree.rb rename to app/models/qa/mesh_tree.rb index 897cfb2c..2f22df6c 100644 --- a/app/models/mesh_tree.rb +++ b/app/models/qa/mesh_tree.rb @@ -1,4 +1,4 @@ -class MeshTree < ActiveRecord::Base +class Qa::MeshTree < ActiveRecord::Base belongs_to :subject_mesh_term , :foreign_key => "term_id" def self.classify_all_trees diff --git a/app/models/subject_mesh_term.rb b/app/models/qa/subject_mesh_term.rb similarity index 73% rename from app/models/subject_mesh_term.rb rename to app/models/qa/subject_mesh_term.rb index 3dc0be1a..f6f8ab82 100644 --- a/app/models/subject_mesh_term.rb +++ b/app/models/qa/subject_mesh_term.rb @@ -1,12 +1,12 @@ -class SubjectMeshTerm < ActiveRecord::Base +class Qa::SubjectMeshTerm < ActiveRecord::Base has_many :mesh_trees, :foreign_key => "term_id" def self.from_tree_number(tree_id) - SubjectMeshTerm.joins('INNER JOIN mesh_trees ON subject_mesh_terms.term_id = mesh_trees.term_id').where('mesh_trees.tree_number = ?', tree_id) + Qa::SubjectMeshTerm.joins('INNER JOIN qa_mesh_trees ON qa_subject_mesh_terms.term_id = qa_mesh_trees.term_id').where('qa_mesh_trees.tree_number = ?', tree_id) end def trees - MeshTree.where(term_id: self.term_id).map { |t| t.tree_number } + Qa::MeshTree.where(term_id: self.term_id).map { |t| t.tree_number } end def synonyms @@ -25,7 +25,7 @@ def synonyms=(syn_list) def parents t = self.trees - t.map { |tn| initial_segements_of(tn) }.flatten.uniq.map { |tn| SubjectMeshTerm.from_tree_number(tn) } + t.map { |tn| initial_segements_of(tn) }.flatten.uniq.map { |tn| Qa::SubjectMeshTerm.from_tree_number(tn) } end private diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb deleted file mode 100644 index bf483d80..00000000 --- a/app/views/layouts/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - - QuestioningAuthority - <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> - <%= javascript_include_tag "application", "data-turbolinks-track" => true %> - <%= csrf_meta_tags %> - - - -<%= yield %> - - - diff --git a/app/views/layouts/qa/application.html.erb b/app/views/layouts/qa/application.html.erb new file mode 100644 index 00000000..360d5830 --- /dev/null +++ b/app/views/layouts/qa/application.html.erb @@ -0,0 +1,14 @@ + + + + Qa + <%= stylesheet_link_tag "qa/application", media: "all" %> + <%= javascript_include_tag "qa/application" %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/bin/bundle b/bin/bundle deleted file mode 100755 index 66e9889e..00000000 --- a/bin/bundle +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails deleted file mode 100755 index 728cd85a..00000000 --- a/bin/rails +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) -require_relative '../config/boot' -require 'rails/commands' diff --git a/bin/rake b/bin/rake deleted file mode 100755 index 17240489..00000000 --- a/bin/rake +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env ruby -require_relative '../config/boot' -require 'rake' -Rake.application.run diff --git a/config.ru b/config.ru deleted file mode 100644 index 5bc2a619..00000000 --- a/config.ru +++ /dev/null @@ -1,4 +0,0 @@ -# This file is used by Rack-based servers to start the application. - -require ::File.expand_path('../config/environment', __FILE__) -run Rails.application diff --git a/config/application.rb b/config/application.rb deleted file mode 100644 index cc32fa74..00000000 --- a/config/application.rb +++ /dev/null @@ -1,24 +0,0 @@ -require File.expand_path('../boot', __FILE__) - -require 'rails/all' - -# Require the gems listed in Gemfile, including any gems -# you've limited to :test, :development, or :production. -Bundler.require(:default, Rails.env) - -module QuestioningAuthority - class Application < Rails::Application - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - config.autoload_paths += Dir["#{config.root}/lib/**/"] - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - end -end diff --git a/config/boot.rb b/config/boot.rb deleted file mode 100644 index 35967366..00000000 --- a/config/boot.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) - -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) diff --git a/config/database.yml b/config/database.yml deleted file mode 100644 index 51a4dd45..00000000 --- a/config/database.yml +++ /dev/null @@ -1,25 +0,0 @@ -# SQLite version 3.x -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' -development: - adapter: sqlite3 - database: db/development.sqlite3 - pool: 5 - timeout: 5000 - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - adapter: sqlite3 - database: db/test.sqlite3 - pool: 5 - timeout: 5000 - -production: - adapter: sqlite3 - database: db/production.sqlite3 - pool: 5 - timeout: 5000 diff --git a/config/environment.rb b/config/environment.rb deleted file mode 100644 index 6ae83152..00000000 --- a/config/environment.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Load the Rails application. -require File.expand_path('../application', __FILE__) - -# Initialize the Rails application. -QuestioningAuthority::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb deleted file mode 100644 index dc41df3e..00000000 --- a/config/environments/development.rb +++ /dev/null @@ -1,29 +0,0 @@ -QuestioningAuthority::Application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development - # since you don't have to restart the web server when you make code changes. - config.cache_classes = false - - # Do not eager load code on boot. - config.eager_load = false - - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false - - # Don't care if the mailer can't send. - config.action_mailer.raise_delivery_errors = false - - # Print deprecation notices to the Rails logger. - config.active_support.deprecation = :log - - # Raise an error on page load if there are pending migrations - config.active_record.migration_error = :page_load - - # Debug mode disables concatenation and preprocessing of assets. - # This option may cause significant delays in view rendering with a large - # number of complex assets. - config.assets.debug = true -end diff --git a/config/environments/production.rb b/config/environments/production.rb deleted file mode 100644 index fe87e93e..00000000 --- a/config/environments/production.rb +++ /dev/null @@ -1,80 +0,0 @@ -QuestioningAuthority::Application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # Code is not reloaded between requests. - config.cache_classes = true - - # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both thread web servers - # and those relying on copy on write to perform better. - # Rake tasks automatically ignore this option for performance. - config.eager_load = true - - # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - config.action_controller.perform_caching = true - - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. - # config.action_dispatch.rack_cache = true - - # Disable Rails's static asset server (Apache or nginx will already do this). - config.serve_static_assets = false - - # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier - # config.assets.css_compressor = :sass - - # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false - - # Generate digests for assets URLs. - config.assets.digest = true - - # Version of your assets, change this if you want to expire all your assets. - config.assets.version = '1.0' - - # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx - - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true - - # Set to :debug to see everything in the log. - config.log_level = :info - - # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) - - # Use a different cache store in production. - # config.cache_store = :mem_cache_store - - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = "http://assets.example.com" - - # Precompile additional assets. - # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - # config.assets.precompile += %w( search.js ) - - # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false - - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found). - config.i18n.fallbacks = true - - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Disable automatic flushing of the log to improve performance. - # config.autoflush_log = false - - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new -end diff --git a/config/environments/test.rb b/config/environments/test.rb deleted file mode 100644 index 6bf39882..00000000 --- a/config/environments/test.rb +++ /dev/null @@ -1,36 +0,0 @@ -QuestioningAuthority::Application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true - - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false - - # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_assets = true - config.static_cache_control = "public, max-age=3600" - - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false - - # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false - - # Disable request forgery protection in test environment. - config.action_controller.allow_forgery_protection = false - - # Tell Action Mailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. - config.action_mailer.delivery_method = :test - - # Print deprecation notices to the stderr. - config.active_support.deprecation = :stderr -end diff --git a/config/initializers/authorities.rb b/config/initializers/authorities.rb index 2112c145..09635b7d 100644 --- a/config/initializers/authorities.rb +++ b/config/initializers/authorities.rb @@ -1 +1 @@ -AUTHORITIES_CONFIG = YAML.load_file(Rails.root.join('config', 'authorities.yml')) +AUTHORITIES_CONFIG = YAML.load_file(File.expand_path("../../authorities.yml", __FILE__)) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb deleted file mode 100644 index 59385cdf..00000000 --- a/config/initializers/backtrace_silencers.rb +++ /dev/null @@ -1,7 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } - -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. -# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb deleted file mode 100644 index 4a994e1e..00000000 --- a/config/initializers/filter_parameter_logging.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb deleted file mode 100644 index ac033bf9..00000000 --- a/config/initializers/inflections.rb +++ /dev/null @@ -1,16 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new inflection rules using the following format. Inflections -# are locale specific, and you may define rules for as many different -# locales as you wish. All of these examples are active by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' -# inflect.uncountable %w( fish sheep ) -# end - -# These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' -# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb deleted file mode 100644 index 72aca7e4..00000000 --- a/config/initializers/mime_types.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new mime types for use in respond_to blocks: -# Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb deleted file mode 100644 index de723d36..00000000 --- a/config/initializers/secret_token.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key is used for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! - -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. - -# Make sure your secret_key_base is kept private -# if you're sharing your code publicly. -QuestioningAuthority::Application.config.secret_key_base = '39f5e4d0ec896fdee9d500a0afcc1de4715e530d84c676ab996acc390065cd24ef8895d64c69992d9fdb16b475a1100e6069ad5791ae43a16e93f145a9edc0e1' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb deleted file mode 100644 index fdf031dd..00000000 --- a/config/initializers/session_store.rb +++ /dev/null @@ -1,3 +0,0 @@ -# Be sure to restart your server when you modify this file. - -QuestioningAuthority::Application.config.session_store :cookie_store, key: '_questioning_authority_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb deleted file mode 100644 index 33725e95..00000000 --- a/config/initializers/wrap_parameters.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# This file contains settings for ActionController::ParamsWrapper which -# is enabled by default. - -# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. -ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) -end - -# To enable root element in JSON for ActiveRecord objects. -# ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true -# end diff --git a/config/locales/en.yml b/config/locales/en.yml deleted file mode 100644 index 06539571..00000000 --- a/config/locales/en.yml +++ /dev/null @@ -1,23 +0,0 @@ -# Files in the config/locales directory are used for internationalization -# and are automatically loaded by Rails. If you want to use locales other -# than English, add the necessary files in this directory. -# -# To use the locales, use `I18n.t`: -# -# I18n.t 'hello' -# -# In views, this is aliased to just `t`: -# -# <%= t('hello') %> -# -# To use a different locale, set it with `I18n.locale`: -# -# I18n.locale = :es -# -# This would use the information in config/locales/es.yml. -# -# To learn more, please read the Rails Internationalization guide -# available at http://guides.rubyonrails.org/i18n.html. - -en: - hello: "Hello world" diff --git a/config/routes.rb b/config/routes.rb index 558e6e0e..9c3806dd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,4 @@ -QuestioningAuthority::Application.routes.draw do +Qa::Engine.routes.draw do match "/search/:vocab" => "terms#search", :via=>:get match "/search/:vocab/:sub_authority" => "terms#search", :via=>:get match "/terms/:vocab" => "terms#index", :via=>:get diff --git a/db/migrate/20130917200611_create_qa_subject_mesh_terms.rb b/db/migrate/20130917200611_create_qa_subject_mesh_terms.rb new file mode 100644 index 00000000..b7e4bf5a --- /dev/null +++ b/db/migrate/20130917200611_create_qa_subject_mesh_terms.rb @@ -0,0 +1,11 @@ +class CreateQaSubjectMeshTerms < ActiveRecord::Migration + def change + create_table :qa_subject_mesh_terms do |t| + t.string :term_id + t.string :term + t.text :synonyms + end + add_index :qa_subject_mesh_terms, :term_id + add_index :qa_subject_mesh_terms, :term + end +end diff --git a/db/migrate/20130917200611_create_subject_mesh_terms.rb b/db/migrate/20130917200611_create_subject_mesh_terms.rb deleted file mode 100644 index 18545a3c..00000000 --- a/db/migrate/20130917200611_create_subject_mesh_terms.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateSubjectMeshTerms < ActiveRecord::Migration - def change - create_table :subject_mesh_terms do |t| - t.string :term_id - t.string :term - t.text :synonyms - end - add_index :subject_mesh_terms, :term_id - add_index :subject_mesh_terms, :term - end -end diff --git a/db/migrate/20130917201026_create_mesh_tree.rb b/db/migrate/20130917201026_create_mesh_tree.rb deleted file mode 100644 index 8bdd0866..00000000 --- a/db/migrate/20130917201026_create_mesh_tree.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateMeshTree < ActiveRecord::Migration - def change - create_table :mesh_trees do |t| - t.string :term_id - t.string :tree_number - end - add_index :mesh_trees, :term_id - add_index :mesh_trees, :tree_number - end -end diff --git a/db/migrate/20130917201026_create_qa_mesh_tree.rb b/db/migrate/20130917201026_create_qa_mesh_tree.rb new file mode 100644 index 00000000..d7e3d531 --- /dev/null +++ b/db/migrate/20130917201026_create_qa_mesh_tree.rb @@ -0,0 +1,10 @@ +class CreateQaMeshTree < ActiveRecord::Migration + def change + create_table :qa_mesh_trees do |t| + t.string :term_id + t.string :tree_number + end + add_index :qa_mesh_trees, :term_id + add_index :qa_mesh_trees, :tree_number + end +end diff --git a/db/migrate/20130918141523_add_term_lower_to_qa_subject_mesh_terms.rb b/db/migrate/20130918141523_add_term_lower_to_qa_subject_mesh_terms.rb new file mode 100644 index 00000000..7637e514 --- /dev/null +++ b/db/migrate/20130918141523_add_term_lower_to_qa_subject_mesh_terms.rb @@ -0,0 +1,7 @@ +class AddTermLowerToQaSubjectMeshTerms < ActiveRecord::Migration + def change + add_column :qa_subject_mesh_terms, :term_lower, :string + add_index :qa_subject_mesh_terms, :term_lower + remove_index :qa_subject_mesh_terms, :term + end +end diff --git a/db/migrate/20130918141523_add_term_lower_to_subject_mesh_terms.rb b/db/migrate/20130918141523_add_term_lower_to_subject_mesh_terms.rb deleted file mode 100644 index 2d080bdd..00000000 --- a/db/migrate/20130918141523_add_term_lower_to_subject_mesh_terms.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AddTermLowerToSubjectMeshTerms < ActiveRecord::Migration - def change - add_column :subject_mesh_terms, :term_lower, :string - add_index :subject_mesh_terms, :term_lower - remove_index :subject_mesh_terms, :term - end -end diff --git a/db/schema.rb b/db/schema.rb deleted file mode 100644 index 9de47aed..00000000 --- a/db/schema.rb +++ /dev/null @@ -1,34 +0,0 @@ -# encoding: UTF-8 -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 20130918141523) do - - create_table "mesh_trees", force: true do |t| - t.string "term_id" - t.string "tree_number" - end - - add_index "mesh_trees", ["term_id"], name: "index_mesh_trees_on_term_id" - add_index "mesh_trees", ["tree_number"], name: "index_mesh_trees_on_tree_number" - - create_table "subject_mesh_terms", force: true do |t| - t.string "term_id" - t.string "term" - t.text "synonyms" - t.string "term_lower" - end - - add_index "subject_mesh_terms", ["term_id"], name: "index_subject_mesh_terms_on_term_id" - add_index "subject_mesh_terms", ["term_lower"], name: "index_subject_mesh_terms_on_term_lower" - -end diff --git a/db/seeds.rb b/db/seeds.rb deleted file mode 100644 index 4edb1e85..00000000 --- a/db/seeds.rb +++ /dev/null @@ -1,7 +0,0 @@ -# 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 rake db:seed (or created alongside the db with db:setup). -# -# Examples: -# -# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) -# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/lib/assets/.keep b/lib/assets/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/authorities.rb b/lib/authorities.rb deleted file mode 100644 index 1bbaa03f..00000000 --- a/lib/authorities.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Authorities -end \ No newline at end of file diff --git a/lib/qa.rb b/lib/qa.rb new file mode 100644 index 00000000..9e19c79d --- /dev/null +++ b/lib/qa.rb @@ -0,0 +1,9 @@ +require "qa/engine" +require "active_record" +require "activerecord-import" + +module Qa + extend ActiveSupport::Autoload + + autoload :Authorities +end diff --git a/lib/qa/authorities.rb b/lib/qa/authorities.rb new file mode 100644 index 00000000..6acfd447 --- /dev/null +++ b/lib/qa/authorities.rb @@ -0,0 +1,12 @@ +module Qa::Authorities + extend ActiveSupport::Autoload + + autoload :Base + autoload :Lcsh + autoload :Loc + autoload :Local + autoload :Mesh + autoload :MeshTools + autoload :Oclcts + autoload :Tgnlang +end \ No newline at end of file diff --git a/lib/authorities/base.rb b/lib/qa/authorities/base.rb similarity index 98% rename from lib/authorities/base.rb rename to lib/qa/authorities/base.rb index 2065a19f..7df87806 100644 --- a/lib/authorities/base.rb +++ b/lib/qa/authorities/base.rb @@ -1,6 +1,6 @@ require 'curl' -module Authorities +module Qa::Authorities class Base attr_accessor :response, :query_url, :raw_response diff --git a/lib/authorities/lcsh.rb b/lib/qa/authorities/lcsh.rb similarity index 93% rename from lib/authorities/lcsh.rb rename to lib/qa/authorities/lcsh.rb index b2610c54..129b24fd 100644 --- a/lib/authorities/lcsh.rb +++ b/lib/qa/authorities/lcsh.rb @@ -1,7 +1,7 @@ require 'uri' -module Authorities - class Lcsh < Authorities::Base +module Qa::Authorities + class Lcsh < Qa::Authorities::Base # Initialze the Lcsh class with a query and get the http response from LOC's server. # This is set to a JSON object diff --git a/lib/authorities/loc.rb b/lib/qa/authorities/loc.rb similarity index 99% rename from lib/authorities/loc.rb rename to lib/qa/authorities/loc.rb index a3e100c7..f0ed1617 100644 --- a/lib/authorities/loc.rb +++ b/lib/qa/authorities/loc.rb @@ -1,7 +1,7 @@ require 'uri' -module Authorities - class Loc < Authorities::Base +module Qa::Authorities + class Loc < Qa::Authorities::Base # Initialze the Loc class with a query and get the http response from LOC's server. # This is set to a JSON object diff --git a/lib/authorities/local.rb b/lib/qa/authorities/local.rb similarity index 82% rename from lib/authorities/local.rb rename to lib/qa/authorities/local.rb index b61745fc..0c17a018 100644 --- a/lib/authorities/local.rb +++ b/lib/qa/authorities/local.rb @@ -1,12 +1,11 @@ -module Authorities - - class Local < Authorities::Base +module Qa::Authorities + class Local < Qa::Authorities::Base attr_accessor :response def initialize(q, sub_authority) begin - sub_authority_hash = YAML.load(File.read(File.join(Authorities::Local.sub_authorities_path, "#{sub_authority}.yml"))) + sub_authority_hash = YAML.load(File.read(File.join(Qa::Authorities::Local.sub_authorities_path, "#{sub_authority}.yml"))) rescue sub_authority_hash = {} end @@ -62,10 +61,9 @@ def self.sub_authorities_path def self.sub_authorities sub_auths = [] - Dir.foreach(Authorities::Local.sub_authorities_path) { |file| sub_auths << File.basename(file, File.extname(file)) } + Dir.foreach(Qa::Authorities::Local.sub_authorities_path) { |file| sub_auths << File.basename(file, File.extname(file)) } sub_auths end end - end \ No newline at end of file diff --git a/lib/authorities/mesh.rb b/lib/qa/authorities/mesh.rb similarity index 92% rename from lib/authorities/mesh.rb rename to lib/qa/authorities/mesh.rb index 440cb2c3..be38af8b 100644 --- a/lib/authorities/mesh.rb +++ b/lib/qa/authorities/mesh.rb @@ -1,4 +1,4 @@ -module Authorities +module Qa::Authorities class Mesh def initialize(q, sub_authority=nil) @@ -15,5 +15,6 @@ def results # satisfy TermsController def parse_authority_response end + end -end +end \ No newline at end of file diff --git a/lib/qa/authorities/mesh_tools.rb b/lib/qa/authorities/mesh_tools.rb new file mode 100644 index 00000000..f77c2e32 --- /dev/null +++ b/lib/qa/authorities/mesh_tools.rb @@ -0,0 +1,6 @@ + module Qa::Authorities::MeshTools + extend ActiveSupport::Autoload + + autoload :MeshDataParser + autoload :MeshImporter + end \ No newline at end of file diff --git a/lib/authorities/mesh_tools/mesh_data_parser.rb b/lib/qa/authorities/mesh_tools/mesh_data_parser.rb similarity index 98% rename from lib/authorities/mesh_tools/mesh_data_parser.rb rename to lib/qa/authorities/mesh_tools/mesh_data_parser.rb index 37e72130..0f04aee1 100644 --- a/lib/authorities/mesh_tools/mesh_data_parser.rb +++ b/lib/qa/authorities/mesh_tools/mesh_data_parser.rb @@ -1,4 +1,4 @@ -module Authorities +module Qa::Authorities module MeshTools class MeshDataParser diff --git a/lib/authorities/mesh_tools/mesh_importer.rb b/lib/qa/authorities/mesh_tools/mesh_importer.rb similarity index 79% rename from lib/authorities/mesh_tools/mesh_importer.rb rename to lib/qa/authorities/mesh_tools/mesh_importer.rb index 2d754a39..fccfdf50 100644 --- a/lib/authorities/mesh_tools/mesh_importer.rb +++ b/lib/qa/authorities/mesh_tools/mesh_importer.rb @@ -1,10 +1,10 @@ -module Authorities +module Qa::Authorities module MeshTools class MeshImporter def import_from_file(f) entries = [] trees = [] - mesh = MeshDataParser.new(f) + mesh = Qa::Authorities::MeshTools::MeshDataParser.new(f) mesh.each_mesh_record do |record| entry = [] entry << record['UI'].first @@ -19,8 +19,8 @@ def import_from_file(f) end end end - SubjectMeshTerm.import([:term_id, :term, :term_lower, :synonyms], entries) - MeshTree.import([:term_id, :tree_number], trees) + Qa::SubjectMeshTerm.import([:term_id, :term, :term_lower, :synonyms], entries) + Qa::MeshTree.import([:term_id, :tree_number], trees) end private diff --git a/lib/authorities/oclcts.rb b/lib/qa/authorities/oclcts.rb similarity index 97% rename from lib/authorities/oclcts.rb rename to lib/qa/authorities/oclcts.rb index 17890262..879bfbef 100644 --- a/lib/authorities/oclcts.rb +++ b/lib/qa/authorities/oclcts.rb @@ -1,9 +1,8 @@ require 'open-uri' require 'nokogiri' -module Authorities - - class Oclcts < Authorities::Base +module Qa::Authorities + class Oclcts < Qa::Authorities::Base SRU_SERVER_CONFIG = YAML.load_file(Rails.root.join("config", "oclcts-authorities.yml")) @@ -59,5 +58,6 @@ def parse_full_record(raw_xml, id) def results self.response.to_json end + end end diff --git a/lib/authorities/tgnlang.rb b/lib/qa/authorities/tgnlang.rb similarity index 90% rename from lib/authorities/tgnlang.rb rename to lib/qa/authorities/tgnlang.rb index 11f7be4c..9f53b409 100644 --- a/lib/authorities/tgnlang.rb +++ b/lib/qa/authorities/tgnlang.rb @@ -1,7 +1,7 @@ require 'nokogiri' require 'json' -module Authorities +module Qa::Authorities class Tgnlang attr_accessor :response, :raw_response def initialize(q,sub_authority='') @@ -9,7 +9,7 @@ def initialize(q,sub_authority='') end def getTgnLang(q) - str = "lib/data/TGN_LANGUAGES.xml" + str = File.expand_path("../../data/TGN_LANGUAGES.xml", __FILE__) doc = Nokogiri::XML(File.open(str)) size = doc.css("Language_Name").size i=0 diff --git a/lib/data/TGN_LANGUAGES.xml b/lib/qa/data/TGN_LANGUAGES.xml similarity index 100% rename from lib/data/TGN_LANGUAGES.xml rename to lib/qa/data/TGN_LANGUAGES.xml diff --git a/lib/qa/engine.rb b/lib/qa/engine.rb new file mode 100644 index 00000000..749f4278 --- /dev/null +++ b/lib/qa/engine.rb @@ -0,0 +1,5 @@ +module Qa + class Engine < ::Rails::Engine + isolate_namespace Qa + end +end diff --git a/lib/qa/version.rb b/lib/qa/version.rb new file mode 100644 index 00000000..9f7ff7b2 --- /dev/null +++ b/lib/qa/version.rb @@ -0,0 +1,3 @@ +module Qa + VERSION = "0.0.1" +end diff --git a/lib/tasks/.keep b/lib/tasks/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/tasks/mesh.rake b/lib/tasks/mesh.rake deleted file mode 100644 index 6bcdc524..00000000 --- a/lib/tasks/mesh.rake +++ /dev/null @@ -1,35 +0,0 @@ -require 'rake' -require 'fileutils' -require 'logger' - -namespace :mesh do - def timed_action(action_name, &block) - start_time = Time.now - puts "\t ############ Starting #{action_name} at #{start_time}" - yield - end_time = Time.now - time_taken = end_time - start_time - puts "\t ############ Complete #{action_name} at #{end_time}, Duration #{time_taken.inspect}" - end - - desc "Import MeSH terms from the file $MESH_FILE, it will update any terms which are already in the database" - task :import => :environment do - fname = ENV['MESH_FILE'] - if fname.nil? - puts "Need to set $MESH_FILE with path to file to ingest" - return - end - timed_action "Importing #{fname}" do - m = Authorities::MeshTools::MeshImporter.new - File.open(fname) do |f| - m.import_from_file(f) - end - end - end - - desc "Delete all mesh terms from the database---not implemented" - task :clear do - puts "Not implemented" - end - -end diff --git a/lib/tasks/qa_tasks.rake b/lib/tasks/qa_tasks.rake new file mode 100644 index 00000000..d225fc4a --- /dev/null +++ b/lib/tasks/qa_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :qa do +# # Task goes here +# end diff --git a/lib/tasks/test.rake b/lib/tasks/test.rake deleted file mode 100644 index 2a3b2917..00000000 --- a/lib/tasks/test.rake +++ /dev/null @@ -1,5 +0,0 @@ -desc "Respect your authorities! Runs tests with Webmock turned off" -task :respect => :environment do - ENV["WEBMOCK"] ||= "disabled" - Rake::Task["spec"].invoke -end \ No newline at end of file diff --git a/log/.keep b/log/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/public/404.html b/public/404.html deleted file mode 100644 index a0daa0c1..00000000 --- a/public/404.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - The page you were looking for doesn't exist (404) - - - - - -
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

-
-

If you are the application owner check the logs for more information.

- - diff --git a/public/422.html b/public/422.html deleted file mode 100644 index fbb4b84d..00000000 --- a/public/422.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - The change you wanted was rejected (422) - - - - - -
-

The change you wanted was rejected.

-

Maybe you tried to change something you didn't have access to.

-
-

If you are the application owner check the logs for more information.

- - diff --git a/public/500.html b/public/500.html deleted file mode 100644 index e9052d35..00000000 --- a/public/500.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - We're sorry, but something went wrong (500) - - - - - -
-

We're sorry, but something went wrong.

-
-

If you are the application owner check the logs for more information.

- - diff --git a/public/favicon.ico b/public/favicon.ico deleted file mode 100644 index e69de29b..00000000 diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index 1a3a5e4d..00000000 --- a/public/robots.txt +++ /dev/null @@ -1,5 +0,0 @@ -# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file -# -# To ban all spiders from the entire site uncomment the next two lines: -# User-agent: * -# Disallow: / diff --git a/qa.gemspec b/qa.gemspec new file mode 100644 index 00000000..3d4b9915 --- /dev/null +++ b/qa.gemspec @@ -0,0 +1,32 @@ +$:.push File.expand_path("../lib", __FILE__) + +# Maintain your gem's version: +require "qa/version" + +# Describe your gem and declare its dependencies: +Gem::Specification.new do |s| + s.name = "qa" + s.version = Qa::VERSION + s.authors = ["Stephen Anderson","Don Brower","Jim Coble","Mike Dubin","Randall Floyd","Eric James","Mike Stroming","Adam Wead"] + s.email = ["amsterdamos@gmail.com"] + s.homepage = "https://github.com/projecthydra/questioning_authority" + s.summary = "You should question your authorities." + s.description = "Provides a set of uniform RESTful routes to query any controlled vocabulary or set of authority terms." + s.license = "APACHE-2" + + s.files = Dir["{app,config,db,lib}/**/*", "LICENSE", "Rakefile", "README.md"] + s.test_files = Dir["spec/**/*"] + + s.add_dependency "rails", "~> 4.0.0" + s.add_dependency "curb" + s.add_dependency "nokogiri", "~> 1.6.0" + s.add_dependency "activerecord-import", ">= 0.4.0" + + s.add_development_dependency "sqlite3" + s.add_development_dependency "rspec" + s.add_development_dependency "rspec-rails" + s.add_development_dependency "webmock" + s.add_development_dependency "simplecov" + s.add_development_dependency "sqlite3" + s.add_development_dependency "debugger" +end diff --git a/spec/controllers/terms_controller_spec.rb b/spec/controllers/terms_controller_spec.rb index 3ea064e2..dab8f7ea 100644 --- a/spec/controllers/terms_controller_spec.rb +++ b/spec/controllers/terms_controller_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' -describe TermsController do +describe Qa::TermsController do + + before :each do + @routes = Qa::Engine.routes + end describe "#index" do @@ -32,13 +36,13 @@ before :each do stub_request(:get, "http://id.loc.gov/authorities/suggest/?q=Blues"). - to_return(:body => File.new(Rails.root.join("spec/fixtures", "lcsh-response.txt")), :status => 200) + to_return(:body => webmock_fixture("lcsh-response.txt"), :status => 200) stub_request(:get, "http://id.loc.gov/search/?format=json&q="). with(:headers => {'Accept'=>'application/json'}). - to_return(:body => File.new(Rails.root.join("spec/fixtures", "loc-response.txt")), :status => 200) + to_return(:body => webmock_fixture("loc-response.txt"), :status => 200) stub_request(:get, "http://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/vocabulary/relators"). with(:headers => {'Accept'=>'application/json'}). - to_return(:body => File.new(Rails.root.join("spec/fixtures", "loc-response.txt")), :status => 200) + to_return(:body => webmock_fixture("loc-response.txt"), :status => 200) end it "should return a set of terms for a lcsh query" do diff --git a/spec/lib/authorities_lcsh_spec.rb b/spec/lib/authorities_lcsh_spec.rb index e1b869b2..caeacc3a 100644 --- a/spec/lib/authorities_lcsh_spec.rb +++ b/spec/lib/authorities_lcsh_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -describe Authorities::Lcsh do +describe Qa::Authorities::Lcsh do before :all do stub_request(:get, "http://id.loc.gov/authorities/suggest/?q=ABBA"). - to_return(:body => File.new(Rails.root.join("spec/fixtures", "lcsh-response.txt")), :status => 200) - @terms = Authorities::Lcsh.new "ABBA" + to_return(:body => webmock_fixture("lcsh-response.txt"), :status => 200) + @terms = Qa::Authorities::Lcsh.new "ABBA" end describe "response from LOC" do diff --git a/spec/lib/authorities_loc_spec.rb b/spec/lib/authorities_loc_spec.rb index 313ca96e..3555154b 100644 --- a/spec/lib/authorities_loc_spec.rb +++ b/spec/lib/authorities_loc_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' -describe Authorities::Loc do +describe Qa::Authorities::Loc do before :all do stub_request(:get, "http://id.loc.gov/search/?format=json&q=haw*&q=cs:http://id.loc.gov/vocabulary/geographicAreas"). with(:headers => {'Accept'=>'application/json'}). - to_return(:body => File.new(Rails.root.join("spec/fixtures", "loc-response.txt")), :status => 200) - @authority = Authorities::Loc.new("haw*", "geographicAreas") + to_return(:body => webmock_fixture("loc-response.txt"), :status => 200) + @authority = Qa::Authorities::Loc.new("haw*", "geographicAreas") end it "should instantiate with a query and return data" do diff --git a/spec/lib/authorities_local_spec.rb b/spec/lib/authorities_local_spec.rb index ef3d7dff..25550aa8 100644 --- a/spec/lib/authorities_local_spec.rb +++ b/spec/lib/authorities_local_spec.rb @@ -1,22 +1,22 @@ require 'spec_helper' -describe Authorities::Local do +describe Qa::Authorities::Local do before do - AUTHORITIES_CONFIG[:local_path] = File.join('spec', 'fixtures', 'authorities') + AUTHORITIES_CONFIG[:local_path] = local_authorities_path end context "valid local sub_authorities" do it "should validate the sub_authority" do - Authorities::Local.sub_authorities.should include "authority_A" - Authorities::Local.sub_authorities.should include "authority_B" + Qa::Authorities::Local.sub_authorities.should include "authority_A" + Qa::Authorities::Local.sub_authorities.should include "authority_B" end end context "retrieve all entries for a local sub_authority" do let(:expected) { [ { :id => "A1", :label => "Abc Term A1" }, { :id => "A2", :label => "Term A2" }, { :id => "A3", :label => "Abc Term A3" } ] } it "should return all the entries" do - authorities = Authorities::Local.new("", "authority_A") + authorities = Qa::Authorities::Local.new("", "authority_A") expect(authorities.parse_authority_response).to eq(expected) end end @@ -26,7 +26,7 @@ context "at least one matching entry" do let(:expected) { [ { :id => "A1", :label => "Abc Term A1" }, { :id => "A3", :label => "Abc Term A3" } ] } it "should return only entries matching the query term" do - authorities = Authorities::Local.new("Abc", "authority_A") + authorities = Qa::Authorities::Local.new("Abc", "authority_A") expect(authorities.parse_authority_response).to eq(expected) end end @@ -34,7 +34,7 @@ context "no matching entries" do let(:expected) { [] } it "should return an empty array" do - authorities = Authorities::Local.new("def", "authority_A") + authorities = Qa::Authorities::Local.new("def", "authority_A") expect(authorities.parse_authority_response).to eq(expected) end end @@ -42,7 +42,7 @@ context "search not case-sensitive" do let(:expected) { [ { :id => "A1", :label => "Abc Term A1" }, { :id => "A3", :label => "Abc Term A3" } ] } it "should return entries matching the query term without regard to case" do - authorities = Authorities::Local.new("aBc", "authority_A") + authorities = Qa::Authorities::Local.new("aBc", "authority_A") expect(authorities.parse_authority_response).to eq(expected) end end @@ -51,7 +51,7 @@ context "retrieve full record for term" do - let(:authorities) { Authorities::Local.new("", "authority_A") } + let(:authorities) { Qa::Authorities::Local.new("", "authority_A") } context "term exists" do let(:id) { "A2" } @@ -71,7 +71,7 @@ end context "term does not an id" do - let(:authorities) { Authorities::Local.new("", "authority_B") } + let(:authorities) { Qa::Authorities::Local.new("", "authority_B") } let(:expected) { [ { :id => "Term B1", :label => "Term B1" }, { :id => "Term B2", :label => "Term B2" }, { :id => "Term B3", :label => "Term B3" } ] } it "should set the id to be same as the label" do expect(authorities.parse_authority_response).to eq(expected) @@ -79,7 +79,7 @@ end context "authority YAML is a list of terms" do - let(:authorities) { Authorities::Local.new("", "authority_C") } + let(:authorities) { Qa::Authorities::Local.new("", "authority_C") } let(:expected) { [ { :id => "Term C1", :label => "Term C1" }, { :id => "Term C2", :label => "Term C2" }, { :id => "Term C3", :label => "Term C3" } ] } it "should use the terms as labels" do expect(authorities.parse_authority_response).to eq(expected) diff --git a/spec/lib/authorities_mesh_spec.rb b/spec/lib/authorities_mesh_spec.rb index 09a41019..45001095 100644 --- a/spec/lib/authorities_mesh_spec.rb +++ b/spec/lib/authorities_mesh_spec.rb @@ -1,41 +1,38 @@ require 'spec_helper' -describe Authorities::Mesh do +describe Qa::Authorities::Mesh do def where_unique_record(klass, q) klass.where(q).length.should == 1 end it "imports a mesh dump file" do - m = Authorities::MeshTools::MeshImporter.new - File.open(Rails.root + 'spec/fixtures/mesh.txt') do |f| + m = Qa::Authorities::MeshTools::MeshImporter.new + File.open(webmock_fixture('mesh.txt').path) do |f| m.import_from_file(f) end - where_unique_record(SubjectMeshTerm, {term_lower: "malaria"}) - where_unique_record(SubjectMeshTerm, {term: "Malaria"}) - where_unique_record(SubjectMeshTerm, {term_id: "D008288"}) - SubjectMeshTerm.all.length.should == 11 + where_unique_record(Qa::SubjectMeshTerm, {term_lower: "malaria"}) + where_unique_record(Qa::SubjectMeshTerm, {term: "Malaria"}) + where_unique_record(Qa::SubjectMeshTerm, {term_id: "D008288"}) + Qa::SubjectMeshTerm.all.length.should == 11 end describe "#results" do before(:all) do - SubjectMeshTerm.create(term_id: '1', term: 'Mr Plow', term_lower: 'mr plow') - SubjectMeshTerm.create(term_id: '2', term: 'Mr Snow', term_lower: 'mr snow') - SubjectMeshTerm.create(term_id: '3', term: 'Mrs Fields', term_lower: 'mrs fields') + Qa::SubjectMeshTerm.create(term_id: '1', term: 'Mr Plow', term_lower: 'mr plow') + Qa::SubjectMeshTerm.create(term_id: '2', term: 'Mr Snow', term_lower: 'mr snow') + Qa::SubjectMeshTerm.create(term_id: '3', term: 'Mrs Fields', term_lower: 'mrs fields') end after(:all) do - SubjectMeshTerm.delete_all + Qa::SubjectMeshTerm.delete_all end - # Re-enable this test once Mesh#results is changed to return a hash of results - # instead of a single json string - - it "handles queries" - #do - # m = Authorities::Mesh.new('mr') - # results = m.results - # results.should include( {id: '1', label: 'Mr Plow'} ) - # results.length.should == 3 - #end + it "handles queries" do + pending "Re-enable this test once Mesh#results is changed to return a hash of results instead of a single json string" + m = Authorities::Mesh.new('mr') + results = m.results + results.should include( {id: '1', label: 'Mr Plow'} ) + results.length.should == 3 + end end end diff --git a/spec/lib/authorities_oclcts_spec.rb b/spec/lib/authorities_oclcts_spec.rb index 799f4809..4708d592 100644 --- a/spec/lib/authorities_oclcts_spec.rb +++ b/spec/lib/authorities_oclcts_spec.rb @@ -1,19 +1,19 @@ require 'spec_helper' -describe Authorities::Oclcts do +describe Qa::Authorities::Oclcts do before :each do stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=oclcts.rootHeading%20exact%20%22ball*%22&recordPacking=xml&recordSchema=http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1"). - to_return(:body => File.new(Rails.root.join("spec/fixtures", "oclcts-response-mesh-1.txt")), :status => 200) + to_return(:body => webmock_fixture("oclcts-response-mesh-1.txt"), :status => 200) stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=oclcts.rootHeading%20exact%20%22alph*%22&recordPacking=xml&recordSchema=http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1"). - to_return(:body => File.new(Rails.root.join("spec/fixtures", "oclcts-response-mesh-2.txt")), :status => 200) + to_return(:body => webmock_fixture("oclcts-response-mesh-2.txt"), :status => 200) stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=dc.identifier%20exact%20%22D031329Q000821%22&recordPacking=xml&recordSchema=http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1"). - to_return(:body => File.new(Rails.root.join("spec/fixtures", "oclcts-response-mesh-3.txt")), :status => 200) + to_return(:body => webmock_fixture("oclcts-response-mesh-3.txt"), :status => 200) - @first_query = Authorities::Oclcts.new("ball", "mesh") + @first_query = Qa::Authorities::Oclcts.new("ball", "mesh") @terms = @first_query.parse_authority_response @term_record = @first_query.get_full_record @terms.first["id"] - @second_query = Authorities::Oclcts.new("alph", "mesh") + @second_query = Qa::Authorities::Oclcts.new("alph", "mesh") end describe "a query for terms" do diff --git a/spec/lib/authorities_tgnlang_spec.rb b/spec/lib/authorities_tgnlang_spec.rb index de480cd5..96b8d54f 100644 --- a/spec/lib/authorities_tgnlang_spec.rb +++ b/spec/lib/authorities_tgnlang_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -describe Authorities::Tgnlang do +describe Qa::Authorities::Tgnlang do before :all do - @terms = Authorities::Tgnlang.new("Tibetan") + @terms = Qa::Authorities::Tgnlang.new("Tibetan") end describe "response from dataset" do diff --git a/spec/lib/mesh_data_parser_spec.rb b/spec/lib/mesh_data_parser_spec.rb index e64e9008..7cd91093 100644 --- a/spec/lib/mesh_data_parser_spec.rb +++ b/spec/lib/mesh_data_parser_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -describe Authorities::MeshTools::MeshDataParser do +describe Qa::Authorities::MeshTools::MeshDataParser do it "parses a record correctly" do - data = <<-EOS + data = <<-EOS *NEWRECORD A = 45 B = a = b = c = d B = more than one EOS - mesh = Authorities::MeshTools::MeshDataParser.new(StringIO.new(data)) + mesh = Qa::Authorities::MeshTools::MeshDataParser.new(StringIO.new(data)) records = mesh.all_records records.length.should == 1 records[0].should == {'A'=>['45'],'B'=>['a = b = c = d','more than one']} @@ -26,7 +26,7 @@ print entry = test EOS - mesh = Authorities::MeshTools::MeshDataParser.new(StringIO.new(data)) + mesh = Qa::Authorities::MeshTools::MeshDataParser.new(StringIO.new(data)) records = mesh.all_records records.length.should == 2 records[0].should == {'A'=>['45'],'B'=>['a = b = c = d']} @@ -41,7 +41,7 @@ space at beginning of line and no = *NEWRECORD EOS - mesh = Authorities::MeshTools::MeshDataParser.new(StringIO.new(data)) + mesh = Qa::Authorities::MeshTools::MeshDataParser.new(StringIO.new(data)) records = mesh.all_records records.length.should == 2 records[0].should == {'A'=>['45']} @@ -49,7 +49,7 @@ end it 'parses a sample mesh file' do - mesh = Authorities::MeshTools::MeshDataParser.new(File.new(Rails.root + 'spec/fixtures/mesh.txt')) + mesh = Qa::Authorities::MeshTools::MeshDataParser.new(webmock_fixture('mesh.txt')) records = mesh.all_records records.length.should == 11 records[0].should == { diff --git a/spec/models/subject_mesh_term_spec.rb b/spec/models/subject_mesh_term_spec.rb index ba7baf4b..3a6ba801 100644 --- a/spec/models/subject_mesh_term_spec.rb +++ b/spec/models/subject_mesh_term_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe SubjectMeshTerm do +describe Qa::SubjectMeshTerm do before(:all) do - @term = SubjectMeshTerm.new + @term = Qa::SubjectMeshTerm.new @term.term_id = "ABCDEFG" @term.term = "Glyphon" @term.save! @@ -17,18 +17,18 @@ @term.trees.should == [] end it "saves a synonym list" do - a = SubjectMeshTerm.new + a = Qa::SubjectMeshTerm.new a.term_id = 'a' a.synonyms = ['b','c'] a.save a.synonyms.should == ['b', 'c'] end it "finds a term by tree number" do - t = MeshTree.new + t = Qa::MeshTree.new t.term_id = @term.term_id t.tree_number = "D1.2.3.4" t.save! - a = SubjectMeshTerm.from_tree_number("D1.2.3.4") + a = Qa::SubjectMeshTerm.from_tree_number("D1.2.3.4") a.length.should == 1 end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f0f19f4e..726008ca 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,8 @@ -# This file is copied to spec/ when you run 'rails generate rspec:install' +require File.expand_path("../internal/config/environment.rb", __FILE__) +require 'rspec/rails' +require 'rspec/autorun' +require 'webmock/rspec' + ENV["RAILS_ENV"] ||= 'test' if ENV['COVERAGE'] @@ -7,11 +11,6 @@ SimpleCov.command_name "spec" end -require File.expand_path("../../config/environment", __FILE__) -require 'rspec/rails' -require 'rspec/autorun' -require 'webmock/rspec' - # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } @@ -30,7 +29,7 @@ # config.mock_with :rr # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.fixture_path = "../spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false @@ -51,3 +50,11 @@ # Disable Webmock if we choose so we can test against the authorities, instead of their mocks WebMock.disable! if ENV["WEBMOCK"] == "disabled" end + +def webmock_fixture fixture + File.new File.expand_path(File.join("../fixtures", fixture), __FILE__) +end + +def local_authorities_path + File.expand_path(File.join("../fixtures/authorities"), __FILE__) +end diff --git a/spec/support/lib/generators/test_app_generator.rb b/spec/support/lib/generators/test_app_generator.rb new file mode 100644 index 00000000..3872456f --- /dev/null +++ b/spec/support/lib/generators/test_app_generator.rb @@ -0,0 +1,20 @@ +require 'rails/generators' + +class TestAppGenerator < Rails::Generators::Base + source_root File.expand_path("../../../../support", __FILE__) + + def inject_routes + insert_into_file "config/routes.rb", :after => ".draw do" do + %{ + + mount Qa::Engine => '/qa' + + } + end + end + + def copy_configs + copy_file "../../config/oclcts-authorities.yml", "config/oclcts-authorities.yml" + end + +end \ No newline at end of file diff --git a/tasks/qa-dev.rake b/tasks/qa-dev.rake new file mode 100644 index 00000000..729d60b7 --- /dev/null +++ b/tasks/qa-dev.rake @@ -0,0 +1,77 @@ +desc "Create the test rails app" +task :generate do + unless File.exists?("spec/internal/Rakefile") + puts "Generating rails app" + system "rails new spec/internal" + puts "Updating gemfile" + `echo "gem 'qa', :path=>'../../../questioning_authority'" >> spec/internal/Gemfile` + `echo "gem 'rspec-rails'" >> spec/internal/Gemfile` + `echo "gem 'webmock'" >> spec/internal/Gemfile` + puts "Copying generator" + `cp -r spec/support/lib/generators spec/internal/lib` + Bundler.with_clean_env do + within_test_app do + puts "running test_app_generator" + system "rails generate test_app" + puts "Bundle install" + system "bundle install" + puts "running migrations" + system "rake qa:install:migrations db:migrate db:test:prepare" + end + end + end + puts "Done generating test app" +end + +desc "Clean out the test rails app" +task :clean do + Rake::Task["stop"].invoke + puts "Removing sample rails app" + system "rm -rf spec/internal" +end + +desc "Start the test rails app" +task :start do + Bundler.with_clean_env do + within_test_app do + puts "Starting test app" + system "rails server -d" + end + end +end + +desc "Stop the test rails app" +task :stop do + pid_file = "tmp/pids/server.pid" + within_test_app do + if File.exists?(pid_file) + pid = File.read(pid_file) + puts "Stopping pid #{pid}" + system "kill -2 #{pid}" + end + end +end + +desc "Do a full run of tests" +task :spec do + Rake::Task["generate"].invoke + Rake::Task["generate"].reenable + Bundler.with_clean_env do + within_test_app do + Rake::Task['rspec'].invoke + end + end +end + +desc "Run rspec tests in the spec directory" +RSpec::Core::RakeTask.new(:rspec) do |t| + t.pattern = '../**/*_spec.rb' + t.rspec_opts = "--colour -I ../" +end + +def within_test_app + return unless File.exists?("spec/internal") + FileUtils.cd("spec/internal") + yield + FileUtils.cd("../..") +end \ No newline at end of file diff --git a/vendor/assets/javascripts/.keep b/vendor/assets/javascripts/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/vendor/assets/stylesheets/.keep b/vendor/assets/stylesheets/.keep deleted file mode 100644 index e69de29b..00000000