Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jun 7, 2012
1 parent 1f37fa1 commit 28d882e
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 25 deletions.
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
source "http://rubygems.org"

gemspec

group :test do
gem 'cucumber-rails', '>=1.2.0', :require=>false
gem 'rcov', :platform => :mri_18
gem 'simplecov', :platform => :mri_19
gem 'simplecov-rcov', :platform => :mri_19
end
24 changes: 0 additions & 24 deletions app/models/mods_asset.rb

This file was deleted.

7 changes: 6 additions & 1 deletion hydra-mods.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ Gem::Specification.new do |s|
s.summary = "Hydra MODS components split out from hydra-head"
s.description = "Hydra MODS components split out from hydra-head"

s.add_dependency "hydra-head"
s.add_dependency 'active-fedora', "~>4.1"
s.add_development_dependency "hydra-head"
s.add_development_dependency "rspec"
s.add_development_dependency "mocha"
s.add_development_dependency "rspec-rails"
s.add_development_dependency "cucumber"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Expand Down
37 changes: 37 additions & 0 deletions spec/fixtures/example_mods.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<mods version="3.4" xsi:schemaLocation="http://www.loc.gov/mods/v3
http://www.loc.gov/standards/mods/v3/mods-3-4.xsd" xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- this is meant to be a fairly simple MODS example. -->
<titleInfo>
<title>main title</title>
<subTitle>subtitle</subTitle>
</titleInfo>

<name type="personal">
<namePart type="family">Hydra</namePart>
<namePart type="given">Hubert</namePart>
<affiliation>Project Hydra</affiliation>
<role>
<roleTerm authority="marcrelator" type="text">Creator</roleTerm>
</role>
</name>
<name type="conference">
<namePart>some conference</namePart>
<role>
<roleTerm authority="marcrelator" type="text">Host</roleTerm>
</role>
</name>

<abstract>abstract</abstract>

<subject>
<topic>topic 1</topic>
<topic>topic 2</topic>
</subject>
<subject authority="authority source (RFCD, LCSH)">
<topic>authority controlled topic</topic>
</subject>

<identifier type="uri">http://projecthydra.org/testdata/</identifier>
<identifier type="doi">doi:10.1006/jmbi.1995.0238</identifier>

</mods>
99 changes: 99 additions & 0 deletions spec/fixtures/mods_article.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<mods version="3.0" xsi:schemaLocation="http://www.loc.gov/mods/v3
http://www.loc.gov/standards/mods/v3/mods-3-0.xsd" xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<titleInfo>
<nonSort>THE</nonSort>
<title>ARTICLE TITLE</title>
<subTitle>SUBTITLE</subTitle>
</titleInfo>
<titleInfo type="alternative">
<title>VARYING FORM OF TITLE</title>
</titleInfo>

<name type="personal">
<namePart type="family">FAMILY NAME</namePart>
<namePart type="given">GIVEN NAMES</namePart>
<namePart type="termsOfAddress">DR.</namePart>
<displayForm>NAME AS IT APPEARS</displayForm>
<affiliation>FACULTY, UNIVERSITY</affiliation>
<role>
<roleTerm authority="marcrelator" type="text">Creator</roleTerm>
</role>
</name>
<name type="personal">
<namePart type="family">Lacks</namePart>
<namePart type="given">Henrietta</namePart>
<displayForm>HeLa</displayForm>
<affiliation>Baltimore</affiliation>
<role>
<roleTerm authority="marcrelator" type="text">Contributor</roleTerm>
</role>
</name>
<name type="corporate">
<namePart>NSF</namePart>
<role>
<roleTerm authority="marcrelator" type="text">Funder</roleTerm>
</role>
</name>
<name type="conference">
<namePart>some conference</namePart>
<role>
<roleTerm authority="marcrelator" type="text">Host</roleTerm>
</role>
</name>

<typeOfResource>text</typeOfResource>
<genre authority="local">journal article</genre>

<abstract>ABSTRACT</abstract>
<subject>
<topic>TOPIC 1</topic>
<topic>TOPIC 2</topic>
</subject>
<subject authority="AUTHORITY SOURCE (RFCD, LCSH)">
<topic>CONTROLLED TERM</topic>
</subject>

<language>
<languageTerm authority="iso639-2b" type="code">en-aus </languageTerm>
</language>

<physicalDescription>
<internetMediaType>application/pdf</internetMediaType>
<extent>36 p.</extent>
</physicalDescription>

<relatedItem type="host">
<titleInfo>
<title>TITLE OF HOST JOURNAL</title>
</titleInfo>
<originInfo>
<publisher>PUBLISHER</publisher>
<dateIssued>DATE</dateIssued>
</originInfo>
<identifier type="issn">0013-8908</identifier>
<part>
<detail type="volume">
<number>2</number>
</detail>
<detail type="level">
<number>2</number>
</detail>
<extent unit="pages">
<start>195</start>
<end>230</end>
</extent>
<date>FEB. 2007</date>
</part>
</relatedItem>

<identifier type="uri">http://URL.edu.au/</identifier>
<identifier type="doi">doi:10.1006/jmbi.1995.0238</identifier>
<location>
<url>http://URL.edu.au/</url>
</location>
<accessCondition type="restrictionOnAccess">EMBARGO NOTE</accessCondition>
<accessCondition type="use and reproduction">OPEN ACCESS</accessCondition>

</mods>

3 changes: 3 additions & 0 deletions spec/internal/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test:
adapter: sqlite3
database: db/combustion_test.sqlite
3 changes: 3 additions & 0 deletions spec/internal/config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rails.application.routes.draw do
#
end
Binary file added spec/internal/db/combustion_test.sqlite
Binary file not shown.
3 changes: 3 additions & 0 deletions spec/internal/db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ActiveRecord::Schema.define do
#
end
1 change: 1 addition & 0 deletions spec/internal/log/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.log
Empty file.
29 changes: 29 additions & 0 deletions spec/models/common_mods_index_methods_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Need way to find way to stub current_user and RoleMapper in order to run these tests
require 'spec_helper'


require 'hydra/datastream/mods_article'
describe Hydra::Datastream::CommonModsIndexMethods do

subject { Hydra::Datastream::ModsArticle.from_xml(fixture("mods_article.xml")) }

describe "extract_person_full_names" do
it "should return an array of Solr::Field objects for :person_full_name_facet" do
full_names = subject.extract_person_full_names
full_names.should be_kind_of Hash
full_names["person_full_name_facet"].should == ["FAMILY NAME, GIVEN NAMES", "Lacks, Henrietta"]
end
end
describe "extract_person_organizations" do
it "should return an array of Solr::Field objects for :mods_organization_facet" do
orgs = subject.extract_person_organizations
orgs.should be_kind_of Hash
orgs["mods_organization_facet"].should be_kind_of Array
orgs["mods_organization_facet"].length.should == 2
orgs["mods_organization_facet"].first.should == "FACULTY, UNIVERSITY"
orgs["mods_organization_facet"].last.should == "Baltimore"
end
end
end


104 changes: 104 additions & 0 deletions spec/models/mods_basic_ds_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
require 'spec_helper'
require "nokogiri"

describe Hydra::Datastream::ModsBasic do

context "general behaviors" do
subject { Hydra::Datastream::ModsBasic.new(nil, nil) }

it "should be a kind of ActiveFedora::NokogiriDatastream" do
subject.should be_kind_of(ActiveFedora::NokogiriDatastream)
end

it "should include mods name behaviors" do
subject.class.included_modules.should include(Hydra::Datastream::CommonModsIndexMethods)
subject.should respond_to(:extract_person_full_names)
end

it "should have relator terms translation methods specific to this model" do
subject.class.should respond_to(:person_relator_terms)
subject.class.should respond_to(:conference_relator_terms)
subject.class.should respond_to(:organization_relator_terms)
end
end

MODS_NS = 'http://www.loc.gov/mods/v3'

context "creating new mods xml" do
subject { Hydra::Datastream::ModsBasic.new(nil, nil) }

it "should have an xml_template method returning desired xml" do
empty_xml = subject.class.xml_template
empty_xml.should be_a_kind_of(Nokogiri::XML::Document)
root = empty_xml.root
root.namespace.href.should == MODS_NS
root.get_attribute("version").should == "3.4"
# Ruby 1.8.7:
# root.get_attribute("xsi:schemaLocation").end_with?("http://www.loc.gov/standards/mods/v3/mods-3-4.xsd").should be_true
# Ruby 1.9.3:
#root.get_attribute("schemaLocation").end_with?("http://www.loc.gov/standards/mods/v3/mods-3-4.xsd").should be_true

# check some descendant nodes
title_node = root.at_xpath('mods:titleInfo/mods:title', {'mods' => MODS_NS} )
title_node.should_not be_nil
title_node.text.should == ""
personal_name_node = root.at_xpath("mods:name[@type='personal']", {'mods' => MODS_NS} )
personal_name_node.should_not be_nil
personal_name_node.text.should == ""
end
end


context "reading existing Mods xml" do
subject { Hydra::Datastream::ModsBasic.from_xml(fixture("example_mods.xml")) }

it "should get correct values from OM terminology" do
tests = [
[:main_title, 'main title'],
[[:title_info, :subtitle], 'subtitle'],

[:abstract, 'abstract'],

# FIXME: whitespace issues
# [[:subject, :topic], ['topic 1', 'topic 2', 'authority controlled topic']],
# [:topic_tag, ['topic 1', 'topic 2', 'authority controlled topic']],

[:identifier, ['http://projecthydra.org/testdata/', 'doi:10.1006/jmbi.1995.0238']],
[:doi, 'doi:10.1006/jmbi.1995.0238'],
[:uri, 'http://projecthydra.org/testdata/'],

[[:name, :namePart], ['Hydra', 'Hubert', 'some conference']],
[[:name, :last_name], 'Hydra'],
[[:person, :last_name], 'Hydra'],
[[:name, :first_name], 'Hubert'],
[[:person, :first_name], 'Hubert'],
# FIXME: whitespace issues
# [:role, ['Creator', 'Host']],
# [:person, 'Hydra Hubert Project Hydra Creator'],
# [:conference, 'some conference Host'],
]

tests.each do |terms, exp|
terms = [terms] unless terms.class == Array
exp = [exp] unless exp.class == Array
subject.term_values(*terms).should == exp
end
end
end
=begin
context "updating Mods xml" do
it "should do something" do
pending "to be implemented"
end
it "should be able to insert new name nodes" do
pending "test to be implemented"
end
it "should be able to add additional topics" do
pending "to be implemented"
end
it "should be able to remove nodes, including the last of a node" do
pending "to be implemented"
end
end
=end
end
51 changes: 51 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- encoding : utf-8 -*-
# This file is copied to spec/ when you run 'rails generate rspec:install'
# Has been customized by Blacklight to work when application is in one place,
# and actual spec/ stuff is in another (the blacklight gem checkout).

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'app', 'models'))

ENV["RAILS_ENV"] ||= 'test'


if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
require 'simplecov'
require 'simplecov-rcov'

SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
SimpleCov.start do
add_filter "/test_support/"
add_filter "/tmp/"

add_filter do |source_file|
source_file.lines.count < 5
end
end
end

require 'combustion'
Combustion.initialize!
require 'rspec/rails'
require 'hydra'
require 'hydra-head/engine'
require 'hydra/mods'
require 'hydra/datastream/common_mods_index_methods'
require 'hydra/datastream/mods_basic'

RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
config.mock_with :mocha

config.color_enabled = true

end

def fixture(file)
File.new(File.join(File.dirname(__FILE__), 'fixtures', file))
end


0 comments on commit 28d882e

Please sign in to comment.