Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Travis rubies #18

Merged
merged 15 commits into from Apr 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -10,3 +10,5 @@ test/dummy/tmp/
test/dummy/config/database.yml
Gemfile.lock
tmp/
coverage/
.rbx
5 changes: 3 additions & 2 deletions .travis.yml
@@ -1,8 +1,9 @@
language: ruby
rvm:
- 1.9.3
# - jruby-19mode # JRuby (1.9)
# - rbx-19mode # Rubinius (1.9)
- jruby-19mode
# - rbx-19mode
- 2.0.0
before_script:
- mysql -e 'create database umlaut3_test;'
- mysql -e 'create database sfxlcl41_test;'
Expand Down
15 changes: 7 additions & 8 deletions Gemfile
Expand Up @@ -8,22 +8,21 @@ gemspec
# jquery is used by the dummy application
group :development, :test do
platforms :jruby do
gem 'activerecord-jdbc-adapter', :require => false
gem 'jdbc-mysql', :require => false
gem 'activerecord-jdbc-adapter', "~> 1.2.9"
gem 'jdbc-mysql', "~> 5.1.24", :require => false
gem 'jruby-rack'
gem 'therubyrhino'
gem 'jruby-prof'
gem 'jruby-openssl'
end

platforms :ruby do
gem 'mysql2'
gem 'therubyracer', "~> 0.10.0"
gem 'ruby-prof'
gem 'mysql2', "~> 0.3.11"
gem 'therubyracer', "~> 0.11.4"
end

platforms :mri_19 do
gem 'debugger'
platforms :mri do
gem 'ruby-prof', "~> 0.13.0"
gem 'debugger', "~> 1.5.0"
end

gem 'jquery-rails'
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/emailer_helper.rb
@@ -1,5 +1,7 @@
module EmailerHelper
include ApplicationHelper
include Umlaut::Helper


# returns a plain text short citation
def brief_citation(request, options = {})
Expand Down
2 changes: 1 addition & 1 deletion app/mixin_logic/marc_helper.rb
Expand Up @@ -222,7 +222,7 @@ def edition_statement(marc, options = {})
if options[:include_repro_info] && marc['533']
marc['533'].subfields.each do |s|
if ( s.code == 'a' )
parts.push('<em>' + s.value.gsub(/[^\w\s]/, '') + '</em>:' )
parts.push(s.value.gsub(/[^\w\s]/, '') + ':' )
elsif (! options[:exclude_533_fields].include?( s.code ))
parts.push(s.value)
end
Expand Down
82 changes: 64 additions & 18 deletions app/models/service_store.rb
@@ -1,27 +1,66 @@
# Loads Service definitions from Rails.root/config/umlaut_services.yml
# instantiates services from definitions, by id.
# A ServiceStore is a collection of umlaut service definitions, with identifiers.
#
# It's terrible we need to do this globally like this, but
# too hard to back out of legacy design now.
# There is one default global one that is typically used; originally this
# was all neccesarily global state, but we refactored to be an actual object,
# although there's still a default global one used, with class methods
# that delegate to it, for backwards compat and convenience.
#
# By default, a ServiceStore loads service definitions from
# Rails.root/config/umlaut_services.yml . Although in testing,
# or for future architectural expansion, services can be manually supplied
# instead.
#
# A ServiceStore instantiates services from definitions, by id,
# ServiceStore.instantiate_service!("our_sfx")
#
# A ServiceStore's cached service definitions can be reset, useful in
# testing: ServiceStore.reset!
#
# They'll then be lazily reloaded on next access, unless manually set.
class ServiceStore
@@global_service_store = ServiceStore.new
def self.global_service_store
@@global_service_store
end

# certain class methods all default to global default ServiceStore,
# for global ServiceStore. For convenience, and backwards-compat.
[ :config, :"config=", :service_definitions, :service_definition_for,
:'instantiate_service!', :'reset!' ].each do |method|
self.define_singleton_method(method) do |*args|
global_service_store.send(method, *args)
end
end


# Returns complete hash loaded from services.yml
def self.config
def config
# cache hash loaded from YAML, ensure it has the keys we expect.
unless defined? @@services_config_list
unless defined? @services_config_list
yaml_path = File.expand_path("config/umlaut_services.yml", Rails.root)
@@services_config_list = (File.exists? yaml_path) ? YAML::load(File.open(yaml_path)) : {}
@@services_config_list["default"] ||= {}
@@services_config_list["default"]["services"] ||= {}
@services_config_list = (File.exists? yaml_path) ? YAML::load(File.open(yaml_path)) : {}
@services_config_list["default"] ||= {}
@services_config_list["default"]["services"] ||= {}
end
return @@services_config_list
return @services_config_list
end

# Manually set a config hash, as would normally be found serialized
# in config/umlaut_services.yml. Useful in testing. All keys
# should be strings!!
#
# Needs to have the somewhat cumbersome expected structure:
# ["default"]["services"] => { "service_id" => definition_hash }
def config=(hash)
reset!
@services_config_list = hash
end

# Returns hash keyed by unique service name, value service definition
# hash.
def self.service_definitions
unless defined? @@service_definitions
@@service_definitions = {}
def service_definitions
unless defined? @service_definitions
@service_definitions = {}
config.each_pair do |group_name, group|
if group["services"]
# Add the group name to each service
Expand All @@ -30,25 +69,32 @@ def self.service_definitions
service["group"] = group_name
end
# Merge the group's services into the service definitions.
@@service_definitions.merge!( group["services"] )
@service_definitions.merge!( group["services"] )
end
end
# set service_id key in each based on hash key
@@service_definitions.each_pair do |key, hash|
@service_definitions.each_pair do |key, hash|
hash["service_id"] = key
end
end
return @@service_definitions
return @service_definitions
end

# Reset cached service definitions. They'll be lazily loaded when asked for,
# typically by being looked up from disk again. Typically used for testing.
def reset!
remove_instance_variable "@service_definitions" if defined? @service_definitions
remove_instance_variable "@services_config_list" if defined? @services_config_list
end

def self.service_definition_for(service_id)
def service_definition_for(service_id)
return service_definitions[service_id]
end

# pass in string unique key OR a service definition hash,
# and a current UmlautRequest.
# get back instantiated Service object.
def self.instantiate_service!(service, request)
def instantiate_service!(service, request)
definition = service.kind_of?(Hash) ? service : service_definition_for(service.to_s)
raise "Service '#{service}'' does not exist in umlaut-services.yml" if definition.nil?
className = definition["type"] || definition["service_id"]
Expand Down
35 changes: 22 additions & 13 deletions app/service_adaptors/isi.rb
Expand Up @@ -18,6 +18,8 @@
# http://scientific.thomson.com/scientific/techsupport/cpe/form.html.
# to request a change.
#
# File support/outage tickets at http://ip-science.thomsonreuters.com/support/
#
# Note, as of 13 april 09, there's a bug in ISI where journal titles including
# ampersands cause an error. We will catch those errors and output a 'warning'
# instead of an 'error', since it's a known problem.
Expand Down Expand Up @@ -61,7 +63,16 @@ def handle(request)


begin
add_responses( request, isi_response )
#raise if it's an error HTTP response
isi_response.value

response_xml = Nokogiri::XML(isi_response.body)
# Check for errors.
if (error = (response_xml.at('val[@name = "error"]') || response_xml.at("error") || response_xml.at('null[@name = "error"]')))
raise IsiResponseException.new("ISI service reported error: #{error.inner_text}")
end

add_responses( request, response_xml )
rescue IsiResponseException => e
# Is this the known problem with ampersands?
# if so, output a warning, but report success not exception,
Expand All @@ -73,7 +84,14 @@ def handle(request)
return request.dispatched(self, true)
else
# Log the error, return exception condition.
Rails.logger.error("#{e.message} ; OpenURL: ?#{request.to_context_object.kev}")

error_parts = []
error_parts << "ISI URI: #{@api_url}"
error_parts << "Request XML: #{xml}"
error_parts << "ISI Response body: #{response_xml}"


Rails.logger.error("#{e.message} ; " + error_parts.join("\n ") )
return request.dispatched(self, false, e)
end
end
Expand Down Expand Up @@ -193,17 +211,8 @@ def do_lamr_request(xml)
return http.post(uri.request_uri, xml, headers)
end

def add_responses(request, isi_response)
#raise if it's an error HTTP response
isi_response.value

response_xml = Nokogiri::XML(isi_response.body)

# Check for errors.
if (error = (response_xml.at('val[@name = "error"]') || response_xml.at("error") || response_xml.at('null[@name = "error"]')))
raise IsiResponseException.new("ISI service reported error: #{error.inner_text}")
end

def add_responses(request, response_xml)

results = response_xml.at('map[@name ="cite_id"] map[@name="WOS"]')
unless (results)
error_message = "#{self.id}: "
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/application.rb
Expand Up @@ -6,6 +6,8 @@
require "umlaut"
require "sunspot_rails"

require 'jquery-rails' # Oddly neccesary in our dummy app see http://www.ruby-forum.com/topic/2484569#1021529

module Dummy
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
Expand Down
10 changes: 5 additions & 5 deletions test/dummy/config/travis_database.yml
Expand Up @@ -32,7 +32,7 @@
# pool: 30

development:
adapter: mysql2
adapter: <%= defined?(JRUBY_VERSION) ? "mysql" : "mysql2" %>
encoding: utf8
reconnect: false
database: umlaut3_development
Expand All @@ -44,14 +44,14 @@ development:
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
adapter: <%= defined?(JRUBY_VERSION) ? "mysql" : "mysql2" %>
database: umlaut3_test
pool: 5
username: root
encoding: utf8

production:
adapter: mysql2
adapter: <%= defined?(JRUBY_VERSION) ? "mysql" : "mysql2" %>
encoding: utf8
reconnect: false
database: umlaut3
Expand All @@ -69,7 +69,7 @@ production:
# In this dummy app, the sfx_db configuation is used for SFX search testing.
# DO NOT SET THIS FOR ANYTHING LIKE A REAL SFX DATABASE.
sfx_db:
adapter: mysql2
adapter: <%= defined?(JRUBY_VERSION) ? "mysql" : "mysql2" %>
database: sfxlcl41_test # or other sfx instance db
username: root
password:
Expand All @@ -83,7 +83,7 @@ sfx_db:
# This is used for SFX search testing.
# DO NOT SET THIS FOR ANYTHING LIKE A REAL SFX DATABASE.
sfx4_global:
adapter: mysql2
adapter: <%= defined?(JRUBY_VERSION) ? "mysql" : "mysql2" %>
database: sfxglb41_test
username: root
password:
Expand Down
18 changes: 18 additions & 0 deletions test/functional/export_email_controller_test.rb
@@ -1,4 +1,8 @@
require 'test_helper'


# The ExportEmailController provides custom interactions
# for the ExportEmail service.
class ExportEmailControllerTest < ActionController::TestCase
fixtures :requests, :referents, :referent_values, :dispatched_services, :service_responses

Expand All @@ -22,4 +26,18 @@ class ExportEmailControllerTest < ActionController::TestCase
assert_select "div.umlaut.container", 0
assert_select "div.email", 1
end

test "send email" do
to_addr = "nobody@example.org"
post :send_email, :id => @email_service_response.id, :email => to_addr


# Mail was sent
assert !ActionMailer::Base.deliveries.empty?
assert ActionMailer::Base.deliveries.find do |message|
message.to.include? to_addr
end

assert_select "div", :text => /Sent to #{to_addr}/
end
end
6 changes: 3 additions & 3 deletions test/functional/search_controller_test.rb
Expand Up @@ -21,7 +21,7 @@ class SearchControllerTest < ActionController::TestCase
assert_select "title", "Find It | Journal titles that begin with &#x27;Account&#x27;"
assert_select ".citationLinker", 1
assert_select ".list", 1
assert_select ".list .citation", 5
assert_select ".list .citation", :minimum => 1
assert_select ".pagination", 2
assert_select ".azNav", 0
end
Expand All @@ -33,8 +33,8 @@ class SearchControllerTest < ActionController::TestCase
assert_select "title", "Find It | Browse by Journal Title: A"
assert_select ".citationLinker", 1
assert_select ".list", 1
assert_select ".list .citation", 16
assert_select ".list .citation", :minimum => 1
assert_select ".pagination", 2
assert_select ".azNav", 2
end
end
end