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 @@ - - -
-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 @@ - - - -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 @@ - - - -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