Skip to content

Commit

Permalink
Merge 31e58f4 into fefc430
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgriffis committed Mar 23, 2017
2 parents fefc430 + 31e58f4 commit a38a705
Show file tree
Hide file tree
Showing 73 changed files with 1,683 additions and 47 deletions.
8 changes: 8 additions & 0 deletions .gitignore
@@ -1,10 +1,18 @@
.bundle/
log/*.log
pkg/

spec/dummy/db/*.sqlite3
spec/dummy/db/*.sqlite3-journal
spec/dummy/log/*.log
spec/dummy/tmp/
spec/dummy/.sass-cache

test/dummy/db/*.sqlite3
test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache

rvm.env
coverage/

Expand Down
2 changes: 2 additions & 0 deletions .rspec
@@ -0,0 +1,2 @@
--color
--require spec_helper
2 changes: 1 addition & 1 deletion .ruby-version
@@ -1 +1 @@
jruby-1.7.16.1
jruby-9.1.7.0
6 changes: 1 addition & 5 deletions .travis.yml
@@ -1,6 +1,2 @@
rvm:
- jruby-19mode
before_script:
- mkdir -p test/dummy/db
- touch test/dummy/db/test.sqlite3
- rake db:migrate
- jruby-9.1.7.0
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -15,7 +15,6 @@ group :assets do
end


gem "acts_as_citable", github: "NYULibraries/acts_as_citable", branch: "feature/rails4"
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -2,6 +2,7 @@ ExCite Engine Gem
======================
[![Build Status](http://jenkins.library.nyu.edu/buildStatus/icon?job=ex_cite Staging Test)](http://jenkins.library.nyu.edu/view/Citero/job/ex_cite%20Staging%20Test/)
[![Build Status](https://travis-ci.org/NYULibraries/ex_cite.png?branch=master)](https://travis-ci.org/NYULibraries/ex_cite)
[![CircleCI](https://circleci.com/gh/NYULibraries/ex_cite.svg?style=svg)](https://circleci.com/gh/NYULibraries/ex_cite)
[![Coverage Status](https://coveralls.io/repos/NYULibraries/ex_cite/badge.png?branch=master)](https://coveralls.io/r/NYULibraries/ex_cite?branch=master)
[![Dependency Status](https://gemnasium.com/NYULibraries/ex_cite.png)](https://gemnasium.com/NYULibraries/ex_cite)
[![Gem Version](https://badge.fury.io/rb/ex_cite.png)](http://badge.fury.io/rb/ex_cite)
Expand Down Expand Up @@ -49,7 +50,7 @@ Services
Some services, such as Endnote, RefWorks, and EasyBib are already included in ex_cite. These services are configurable right out of the box for your needs.

There are two ways to use services, rendering and redirect. The render method will render a view with a 200 response, and the redirect will, as expected,
redirect to another page with a 302 response.
redirect to another page with a 302 response.

To configure a built-in service, such as Endnote, Refworks, or EasyBib, simply modify the following objects

Expand Down
7 changes: 5 additions & 2 deletions Rakefile
Expand Up @@ -39,5 +39,8 @@ Rake::TestTask.new(:test) do |t|
t.verbose = false
end


task :default => :test
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.ruby_opts = "--debug --dev"
end
task default: :spec
17 changes: 17 additions & 0 deletions circle.yml
@@ -0,0 +1,17 @@
machine:
ruby:
version:
jruby-9.1.7.0
java:
version:
openjdk7
environment:
JRUBY_OPTS: '--dev'
dependencies:
pre:
- bundle config github.https true
test:
override:
- bundle exec rake:
parallel: true
pwd: app
9 changes: 6 additions & 3 deletions ex_cite.gemspec
Expand Up @@ -17,16 +17,19 @@ Gem::Specification.new do |s|
s.test_files = Dir["test/**/*"]
s.homepage = "https://github.com/NYULibraries/ex_cite"

s.add_dependency "rails", "~> 4.0"
# s.add_dependency "acts_as_citable", "~> 3.0.0-alpha"
s.add_dependency "rails", "~> 4.2.8"
s.add_dependency "acts_as_citable", "~> 4.0.0"
s.add_dependency 'citero_renderers', '~> 1.0.1'
s.add_dependency "jquery-rails", "~> 3.1.0"

s.add_development_dependency "activerecord-jdbcsqlite3-adapter"
s.add_development_dependency "rake", "~> 10.0"
s.add_development_dependency "brakeman", "~> 1.9.5"
s.add_development_dependency "simplecov"
s.add_development_dependency "simplecov-rcov"
s.add_development_dependency "test-unit"
s.add_development_dependency "coveralls"
s.add_development_dependency "pry"
s.add_development_dependency "rspec-rails", "~> 3.5"
s.add_development_dependency "rspec-html-matchers"
s.add_development_dependency "rspec-its"
end
22 changes: 15 additions & 7 deletions lib/ex_cite/engine.rb
@@ -1,26 +1,34 @@
require 'ex_cite/core_ext'
require "acts_as_citable"
require 'citero_renderers'

module ExCite
mattr_accessor :acts_as_citable_class
mattr_accessor :push_formats
mattr_accessor :endnote, :easybib, :refworks

def self.acts_as_citable_class
@@acts_as_citable_class.constantize
@@acts_as_citable_class = @@acts_as_citable_class.constantize if @@acts_as_citable_class.is_a? String
@@acts_as_citable_class
end

EASYBIB_URL = "http://www.easybib.com/cite/bulk"
ENDNOTE_URL = "http://www.myendnoteweb.com/?func=directExport&partnerName=Primo&dataIdentifier=1&dataRequestUrl="
REFWORKS_URL = "http://www.refworks.com/express/ExpressImport.asp?vendor=Primo&filter=RefWorks%20Tagged%20Format&encoding=65001&url="

class Engine < Rails::Engine
isolate_namespace ExCite
engine_name "ex_cite"
ExCite.acts_as_citable_class = "ExCite::Citation"

config.before_initialize do
ExCite.easybib ||= PushFormat.new( :name => :easybibpush, :to_format => :easybib, :url => "http://www.easybib.com/cite/bulk")
ExCite.endnote ||= PushFormat.new :name => :endnote, :to_format => :ris, :action => :redirect, :url => 'http://www.myendnoteweb.com/?func=directExport&partnerName=Primo&dataIdentifier=1&dataRequestUrl='
ExCite.refworks ||= PushFormat.new( :name => :refworks, :to_format => :refworks_tagged, :element_name=> 'ImportData', :url => "http://www.refworks.com/express/ExpressImport.asp?vendor=Primo&filter=RefWorks%20Tagged%20Format&encoding=65001&url=")
formats = Hash[ExCite.easybib.name => ExCite.easybib, ExCite.endnote.name => ExCite.endnote, ExCite.refworks.name => ExCite.refworks]
ExCite.push_formats = formats
ExCite.easybib ||= PushFormat.new(name: :easybibpush, to_format: :easybib, url: EASYBIB_URL)
ExCite.endnote ||= PushFormat.new(name: :endnote, to_format: :ris, action: :redirect, url: ENDNOTE_URL)
ExCite.refworks ||= PushFormat.new(name: :refworks, to_format: :refworks_tagged, element_name: 'ImportData', url: REFWORKS_URL)
formats = [ExCite.easybib, ExCite.endnote, ExCite.refworks]
ExCite.push_formats = formats.map{|format| [format.name, format] }.to_h
end

initializer "#{engine_name}.asset_pipeline" do |app|
app.config.assets.precompile << 'ex_cite.js'
end
Expand Down
124 changes: 124 additions & 0 deletions spec/controllers/ex_cite/export_citations_controller_spec.rb
@@ -0,0 +1,124 @@
require 'rails_helper'

describe ExCite::ExportCitationsController, type: :controller do
routes { ExCite::Engine.routes }

describe "GET index" do
subject{ response }
let(:csf_data){ "itemType: book" }
let(:ris_data){ "TY - BOOK\nER -\n\n" }
let(:openurl_data){ "https://getit.library.nyu.edu/resolve?rft_val_fmt=info:ofi/fmt:kev:mtx:book" }
let(:bibtex_data){ "@book{????\n}" }
let(:pnx_data){ "<display><type>book</type></display>" }
let(:refworks_tagged_data){ "RT Book, whole\nER \n \n" }

context "using data" do
context "with from_format" do
before { get :index, to_format: to_format, from_format: from_format, data: data }

context "valid data" do
let(:data){ public_send(:"#{from_format}_data") }

include_examples "book success for all from_format and to_format"
end

context "invalid data" do
let(:data){ "$%^$* some nonsense !@#$%^&*}" }

pending
# include_examples "bad_request for all from_format and to_format"
end
end # end with from_format
end # end using data

context "using id" do
before { get :index, to_format: to_format, id: id }

context "valid id" do
around do |example|
old_acts_as_citable_class = ExCite.acts_as_citable_class
ExCite.acts_as_citable_class = DummyPersistentCitation
example.run
ExCite.acts_as_citable_class = old_acts_as_citable_class
end
let(:citation){ DummyPersistentCitation.create(data: data, format: from_format) }
let(:id){ citation.id }

context "with valid data" do
let(:data){ public_send(:"#{from_format}_data") }

include_examples "book success for all from_format and to_format"
end

context "with invalid data" do
let(:data){ "%^&%^&cbdsds" }

pending
# include_examples "bad_request for all from_format and to_format"
end
end # end valid id

context "invalid id" do
let(:id) { "error" }

include_examples "bad_request for all from_format and to_format"
end # end invalid id
end # end using id

context "using resource_key" do
let(:resource_key){ "abcd" }
let(:converted_to_format) do
return "refworks_tagged" if to_format == "refworks"
return "easybib" if to_format == "easybibpush"
to_format
end

context "valid resource_key" do
context "for single resource" do
let(:nested_resource_key){ "wxyz" }
let(:nested_resource_cache_key){ nested_resource_key + "to_" + converted_to_format }
before do
allow(Rails.cache).to receive(:fetch).once.with(resource_key).and_return(nested_resource_key)
allow(Rails.cache).to receive(:fetch).once.with(nested_resource_cache_key).and_return(cached_data_converted) if defined?(cached_data_converted)
end
before { get :index, to_format: to_format, resource_key: resource_key }

include_examples "resource_key-stubbed success for all from_format and to_format"
end # end for single resource

context "for collection of resources" do
let(:nested_resource_keys){ [nested_resource_key1, nested_resource_key2, nested_resource_key3] }
let(:nested_resource_key1){ "1234" }
let(:nested_resource_key2){ "5678" }
let(:nested_resource_key3){ "wxyz" }
let(:nested_resource_cache_key1){ nested_resource_key1 + "to_" + converted_to_format }
let(:nested_resource_cache_key2){ nested_resource_key2 + "to_" + converted_to_format }
let(:nested_resource_cache_key3){ nested_resource_key3 + "to_" + converted_to_format }
before do
allow(Rails.cache).to receive(:fetch).once.with(resource_key).and_return(nested_resource_keys)
allow(Rails.cache).to receive(:fetch).once.with(nested_resource_cache_key1).and_return(cached_data_converted) if defined?(cached_data_converted)
allow(Rails.cache).to receive(:fetch).once.with(nested_resource_cache_key2).and_return(cached_data_converted) if defined?(cached_data_converted)
allow(Rails.cache).to receive(:fetch).once.with(nested_resource_cache_key3).and_return(cached_data_converted) if defined?(cached_data_converted)
end
before { get :index, to_format: to_format, resource_key: resource_key }

include_examples "resource_key-stubbed success for all from_format and to_format"
end
end # end valid resource_key

context "invalid resource_key" do
before { allow(Rails.cache).to receive(:fetch).once.with(resource_key).and_return(nil) }
before { get :index, to_format: to_format, resource_key: resource_key }

include_examples "bad_request for all from_format and to_format"
end # end invalid resource_key
end

context "using openurl" do
before { get :index, to_format: to_format, rft_val_fmt: "info:ofi/fmt:kev:mtx:book" }
let(:data){ "http://test.host" + URI.decode(request.fullpath) }

include_examples "book success for all to_format", "openurl"
end
end
end
28 changes: 28 additions & 0 deletions spec/dummy/README.rdoc
@@ -0,0 +1,28 @@
== README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...


Please feel free to use a different markup language if you do not plan to run
<tt>rake doc:app</tt>.
6 changes: 6 additions & 0 deletions spec/dummy/Rakefile
@@ -0,0 +1,6 @@
# 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.

require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks
Empty file.
13 changes: 13 additions & 0 deletions spec/dummy/app/assets/javascripts/application.js
@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
15 changes: 15 additions & 0 deletions spec/dummy/app/assets/stylesheets/application.css
@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
5 changes: 5 additions & 0 deletions spec/dummy/app/controllers/application_controller.rb
@@ -0,0 +1,5 @@
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
Empty file.
2 changes: 2 additions & 0 deletions spec/dummy/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
module ApplicationHelper
end
Empty file added spec/dummy/app/mailers/.keep
Empty file.
Empty file added spec/dummy/app/models/.keep
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions spec/dummy/app/models/dummy_persistent_citation.rb
@@ -0,0 +1,3 @@
class DummyPersistentCitation < ActiveRecord::Base
acts_as_citable
end
2 changes: 2 additions & 0 deletions spec/dummy/app/models/empty_model.rb
@@ -0,0 +1,2 @@
class EmptyModel < ActiveRecord::Base
end
14 changes: 14 additions & 0 deletions spec/dummy/app/views/layouts/application.html.erb
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
3 changes: 3 additions & 0 deletions spec/dummy/bin/bundle
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 4 additions & 0 deletions spec/dummy/bin/rails
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 4 additions & 0 deletions spec/dummy/bin/rake
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run

0 comments on commit a38a705

Please sign in to comment.