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

Feature/improve tests #45

Merged
merged 69 commits into from Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
e99ad74
Include the citero-renderers gem and update acts_as_citable
hab278 Mar 8, 2017
dfc43cc
Remove space from filename...
hab278 Mar 8, 2017
f9c5dda
Move dependencies to gemspec
ericgriffis Mar 8, 2017
957e53d
Move require from dummy to engine
ericgriffis Mar 8, 2017
42097a6
Update JRuby
ericgriffis Mar 8, 2017
eff8ed4
Update travis jruby
ericgriffis Mar 8, 2017
a1ecbcb
Install Rspec with dummy app; add trivial test
ericgriffis Mar 8, 2017
39331f6
Remove travis before_script
ericgriffis Mar 8, 2017
272613f
Add output for travis
ericgriffis Mar 8, 2017
97a8615
Remove failing test of deprecated functionality
ericgriffis Mar 8, 2017
e1ae072
Add version spec
ericgriffis Mar 9, 2017
e042c58
Use RSpec in Travis
ericgriffis Mar 9, 2017
1d26312
Use coveralls
ericgriffis Mar 9, 2017
081bc5c
Add rspec rake task and make default
ericgriffis Mar 9, 2017
d4b5428
Add some model specs
ericgriffis Mar 10, 2017
857733c
Add helpers spec
ericgriffis Mar 13, 2017
8c338d4
Add pending resource key spec
ericgriffis Mar 13, 2017
efc4992
Add engine tests
ericgriffis Mar 13, 2017
455cebc
Refactor engine
ericgriffis Mar 15, 2017
1a3a49a
Add basic controller tests (incomplete)
ericgriffis Mar 17, 2017
ca178b8
Add controller tests for redirect templates
ericgriffis Mar 17, 2017
bb50097
Expand invalid ID tests
ericgriffis Mar 17, 2017
eb0cb7f
Expand invalid ID tests >> add support file
ericgriffis Mar 17, 2017
eb79ba2
Add controller tests for bad data
ericgriffis Mar 17, 2017
5984152
Add CircleCI config
ericgriffis Mar 20, 2017
f1805f0
Add files to Circle config
ericgriffis Mar 20, 2017
7c3891d
Remove files from circle config
ericgriffis Mar 20, 2017
61934eb
CircleCI - Set version to jruby
ericgriffis Mar 20, 2017
60c6aa8
CircleCI - remove install commands; simplify test command
ericgriffis Mar 20, 2017
da0b2f3
CircleCI - simplify test command
ericgriffis Mar 20, 2017
7dd6fd2
CircleCI - use rake instead of rspec
ericgriffis Mar 20, 2017
41ae474
Remove controller cache line causing strange behavior
ericgriffis Mar 20, 2017
dcea57b
Convert status checks to give better error messages
ericgriffis Mar 20, 2017
85ba36b
Disable invalid data spec
ericgriffis Mar 20, 2017
a013f99
Engine - allow assigning acts_as_citable_class as a constant (in addi…
ericgriffis Mar 20, 2017
6debef3
Add controller tests for successful ID lookup
ericgriffis Mar 20, 2017
55812ba
Reorganize controller spec contexts
ericgriffis Mar 21, 2017
8e267f4
Consolidate stubbing
ericgriffis Mar 21, 2017
7285b0a
Begin tests for resource_key
ericgriffis Mar 21, 2017
782494c
Add back controller caching
ericgriffis Mar 21, 2017
6907ab4
Add tests for successful resource key requests
ericgriffis Mar 22, 2017
3d8295e
Reorganize contexts
ericgriffis Mar 22, 2017
4d2357a
Reorganize contexts
ericgriffis Mar 22, 2017
cc63def
Add tests for successful resource key requests with multiple resources
ericgriffis Mar 22, 2017
fdde417
Consolidate controller examples further
ericgriffis Mar 23, 2017
a5c8c85
Move and rename some files
ericgriffis Mar 23, 2017
89a26c0
Refactor resource_key specs
ericgriffis Mar 23, 2017
ee2f094
Remove controller data spec without from_format
ericgriffis Mar 23, 2017
6fadd6c
Add controller tests for openurl
ericgriffis Mar 23, 2017
31e58f4
Add CircleCi badge
ericgriffis Mar 23, 2017
640b239
Use latest ruby
hab278 Nov 2, 2017
6f6b2a5
Change gems to be mri
hab278 Nov 2, 2017
783d2fd
Clean up gemspec
hab278 Nov 2, 2017
48bf551
Remove any and all CSL tests
hab278 Nov 2, 2017
bd72038
Remove CSL mimetype, switch to citero-renderers
hab278 Nov 2, 2017
56ef891
Remove an old bundler require..
hab278 Nov 2, 2017
643b138
Use symbol instead of string for formats
hab278 Nov 2, 2017
d48cd15
Remove CSL stuff
hab278 Nov 2, 2017
ef07710
Up the version to be non backwards compatible
hab278 Nov 2, 2017
c1c1b14
All PNX records begin with <record>
hab278 Nov 3, 2017
26214ce
Remove old from_formats in test
hab278 Nov 3, 2017
1f43aad
Update acts_as_citable_dependency
hab278 Nov 3, 2017
a8b0164
Rename process
hab278 Nov 3, 2017
ec69783
Use glob require for testing
hab278 Nov 3, 2017
b985f75
Use constants for HTTP codes
hab278 Nov 3, 2017
d328462
Get rid of travis, go all in on Circle
hab278 Nov 3, 2017
94a9d35
use new circle config
hab278 Nov 3, 2017
290b4ca
set up the config for circle
hab278 Nov 3, 2017
a1005d3
Merge pull request #46 from NYULibraries/chore/rename-everything
hab278 Nov 3, 2017
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
42 changes: 42 additions & 0 deletions .circleci/config.yml
@@ -0,0 +1,42 @@
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/ruby:2.4.1-node

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run:
name: install dependencies
command: |
bundle install --jobs=4 --retry=3 --path ./vendor/bundle

- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}

# run tests!
- run:
name: run tests
command: bundle exec rspec
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
2.4.1
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

15 changes: 0 additions & 15 deletions Gemfile
@@ -1,22 +1,7 @@
source "http://rubygems.org"

# Declare your gem's dependencies in ex_cite.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# jquery-rails is used by the dummy application
gem "jquery-rails"

group :assets do
gem "therubyrhino", "~> 2.0.4", platform: :jruby
gem "therubyracer", "~> 0.12.1", platform: :ruby
gem "uglifier", "~> 2.6.0"
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
# your gem to rubygems.org.
33 changes: 17 additions & 16 deletions README.md
@@ -1,11 +1,12 @@
ExCite Engine Gem
CiteroEngine 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)
[![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)
[![Code Climate](https://codeclimate.com/github/NYULibraries/ex_cite.png)](https://codeclimate.com/github/NYULibraries/ex_cite)
[![Build Status](http://jenkins.library.nyu.edu/buildStatus/icon?job=citero_engine Staging Test)](http://jenkins.library.nyu.edu/view/Citero/job/citero_engine%20Staging%20Test/)
[![Build Status](https://travis-ci.org/NYULibraries/citero_engine.png?branch=master)](https://travis-ci.org/NYULibraries/citero_engine)
[![CircleCI](https://circleci.com/gh/NYULibraries/citero_engine.svg?style=svg)](https://circleci.com/gh/NYULibraries/citero_engine)
[![Coverage Status](https://coveralls.io/repos/NYULibraries/citero_engine/badge.png?branch=master)](https://coveralls.io/r/NYULibraries/citero_engine?branch=master)
[![Dependency Status](https://gemnasium.com/NYULibraries/citero_engine.png)](https://gemnasium.com/NYULibraries/citero_engine)
[![Gem Version](https://badge.fury.io/rb/citero_engine.png)](http://badge.fury.io/rb/citero_engine)
[![Code Climate](https://codeclimate.com/github/NYULibraries/citero_engine.png)](https://codeclimate.com/github/NYULibraries/citero_engine)

A JRuby wrapper for the citero tool, enables use of the citero tool in JRuby distributed as a Rails 3 Engine Gem.

Expand All @@ -15,7 +16,7 @@ Install
Mount the engine gem to your rails project like so:

```ruby
mount ExCite::Engine, :at => '/MOUNT_LOCATION'
mount CiteroEngine::Engine, :at => '/MOUNT_LOCATION'
```

You'll need to require the [jquery-rails](https://github.com/rails/jquery-rails) gem also.
Expand Down Expand Up @@ -46,17 +47,17 @@ Finally, you can send an OpenURL request, simply define the :to_format and pass
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.
Some services, such as Endnote, RefWorks, and EasyBib are already included in citero_engine. 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

```ruby
ExCite.easybib
ExCite.refworks
ExCite.endnote
CiteroEngine.easybib
CiteroEngine.refworks
CiteroEngine.endnote
```

The available options are as follow, with available defaults shown
Expand All @@ -65,7 +66,7 @@ The available options are as follow, with available defaults shown
:name => 'Service' # What you want to call this service, and how it will be accessed, i.e. 'easybibpush'
:to_format => # The format that the service is expecting
:action => 'render' # Either :redirect or :render is supported
:template => 'ex_cite/cite/external_form' # The template view to render. You are free to use your own, ex_cite provides one for free!
:template => 'citero_engine/cite/external_form' # The template view to render. You are free to use your own, citero_engine provides one for free!
:url => # The url to redirect to or the url to send the form to
:method => 'POST' # This is the form action
:enctype => 'application/x-www-form-urlencoded' # This is the enctype for the form
Expand All @@ -77,8 +78,8 @@ alias :protocol :callback_protocol # An alias, should you wish to use this outda
To add a new service, simply

```ruby
easybib = PushFormat.new( :name => :easybibpush, :to_format => :easybib, :action => :render, :template => "ex_cite/cite/external_form", :url => "http://www.easybib.com/cite/bulk")
ExCite.push_formats['easybib'] = easybib
easybib = PushFormat.new( :name => :easybibpush, :to_format => :easybib, :action => :render, :template => "citero_engine/cite/external_form", :url => "http://www.easybib.com/cite/bulk")
CiteroEngine.push_formats['easybib'] = easybib
```
Examples
========
Expand Down
9 changes: 6 additions & 3 deletions Rakefile
Expand Up @@ -15,7 +15,7 @@ end

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = 'ExCite'
rdoc.title = 'CiteroEngine'
rdoc.options << '--line-numbers'
rdoc.options << '--markup markdown'
rdoc.rdoc_files.include('README.md')
Expand All @@ -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
Expand Up @@ -3,4 +3,4 @@
//
// This engine requires jquery.
//= require jquery
//= require_tree './ex_cite'
//= require_tree './citero_engine'
@@ -1,15 +1,15 @@
require "ex_cite/engine"
require "citero_engine/engine"
require 'digest/sha1'
require 'open-uri'
module ExCite
module CiteroEngine
# Logic behind the webservice. First it gathers all the resource keys and creates Citation objects out of them and then
# it gathers any and all from formats and data variables that were sent via post and creates an array out of them. If the
# array is still empty it uses the URL as an OpenURL. It then loops through the array and translates and caches (or fetches)
# each one using acts_as_citable. It then either downloads the data or redirects to another webservice.
class ExportCitationsController < ActionController::Base
class CiteroEngineController < ActionController::Base
# There must be a destination format, or else this whole thing doesnt make sense
before_filter :valid_to_format?
layout "ex_cite/application"
layout "citero_engine/application"

# Sends bad request if there is no destination format
def valid_to_format?
Expand All @@ -36,7 +36,7 @@ def citations
def record_citation
(params[:id].nil?) ? [] :
params[:id].collect do |id|
record = ExCite.acts_as_citable_class.find_by_id id if ExCite.acts_as_citable_class.respond_to? :find_by_id
record = CiteroEngine.acts_as_citable_class.find_by_id id if CiteroEngine.acts_as_citable_class.respond_to? :find_by_id
(record.nil?) ? (raise(ArgumentError, "This ID cannot be found.")) : record
end
end
Expand All @@ -48,7 +48,7 @@ def resource_citation
resources << Rails.cache.fetch(params[:resource_key])
resources.flatten!
resources.collect do |key|
citation = ExCite.acts_as_citable_class.new()
citation = CiteroEngine.acts_as_citable_class.new()
citation.resource_key = key
citation
end
Expand All @@ -58,13 +58,13 @@ def resource_citation
def format_citation
(params[:from_format].nil? || params[:data].nil?) ? [] :
params[:from_format].collect.with_index do |format, index|
ExCite.acts_as_citable_class.new ExCite.acts_as_citable_class.data_field.to_sym => params[:data].to_a[index], ExCite.acts_as_citable_class.format_field.to_sym => (whitelist_formats :from, format)
CiteroEngine.acts_as_citable_class.new CiteroEngine.acts_as_citable_class.data_field.to_sym => params[:data].to_a[index], CiteroEngine.acts_as_citable_class.format_field.to_sym => (whitelist_formats :from, format)
end
end

# Returns a single citation object with data and format set as the url and openurl respectively
def open_url_citation
ExCite.acts_as_citable_class.new ExCite.acts_as_citable_class.data_field.to_sym => CGI::unescape(request.protocol+request.host_with_port+request.fullpath), ExCite.acts_as_citable_class.format_field.to_sym => (whitelist_formats :from, 'openurl')
CiteroEngine.acts_as_citable_class.new CiteroEngine.acts_as_citable_class.data_field.to_sym => CGI::unescape(request.protocol+request.host_with_port+request.fullpath), CiteroEngine.acts_as_citable_class.format_field.to_sym => (whitelist_formats :from, 'openurl')
end

# Maps the output and caches it, alternatively it fetches the already cached result. Seperates each output with two new lines.
Expand Down Expand Up @@ -95,15 +95,16 @@ def whitelist_formats direction, format
return
end
# if the to format is found, it returns the method name for that to format
if (direction == :to && (Citero.to_formats.include?(format.downcase) || Citero.citation_styles.include?(format.downcase)))
return "#{:to.to_s}_#{format.downcase}"
format_sym = format.downcase.to_sym
if (direction == :to && (Citero.to_formats.include?(format_sym) || Citero.citation_styles.include?(format_sym)))
return "to_#{format_sym}"
# if the from format is found, it returns just that because the object already knows what method to call
elsif (direction == :from && Citero.from_formats.include?(format.downcase))
elsif (direction == :from && Citero.from_formats.include?(format_sym))
return format.downcase
end
# if the format is still not found, it might be a push request, check if that is the case
if ExCite.push_formats.include? format.to_sym
@push_to = ExCite.push_formats[format.to_sym]
if CiteroEngine.push_formats.include? format_sym
@push_to = CiteroEngine.push_formats[format_sym]
@to_format = @push_to.to_format.downcase
return "#{direction.to_s}_#{@to_format}"
end
Expand Down Expand Up @@ -179,7 +180,7 @@ def render_push

def delimiters
case @to_format
when "to_easybib", "to_csl"
when "to_easybib"
return [",\n","[","]"]
else
return ["\n\n"]
Expand Down
@@ -1,4 +1,4 @@
module ExCite
module CiteroEngine
module ApplicationHelper
def build_external_form
return "<textarea name=\"#{@push_to.element_name}\" id=\"#{@push_to.element_name}\">#{@output}</textarea>"
Expand Down
@@ -1,4 +1,4 @@
module ExCite
module CiteroEngine
# Citation class, holds data from format and/or resource key
class Citation
extend ActsAsCitable
Expand Down
@@ -1,4 +1,4 @@
module ExCite
module CiteroEngine
# Citation class, holds data from format and/or resource key
class PushFormat
# Required fields
Expand All @@ -8,7 +8,7 @@ def initialize args = {}
self.name = (args[:name] or 'Service')
self.to_format = args[:to_format]
self.action = (args[:action] or :render)
self.template = (args[:template] or "ex_cite/cite/external_form")
self.template = (args[:template] or "citero_engine/cite/external_form")
self.url = args[:url]
self.method = (args[:method] or "POST")
self.enctype = (args[:enctype] or "application/x-www-form-urlencoded")
Expand Down
@@ -1,4 +1,4 @@
module ExCite
module CiteroEngine
module ResourceKey
def self.included(klass)
klass.class_eval do
Expand Down
@@ -1,4 +1,4 @@
<%= javascript_include_tag "ex_cite" %>
<%= javascript_include_tag "citero_engine" %>
<div class="inner_form_dialog">
<form id="<%= @id %>" action="<%= @push_to.url %>" method="<%= @push_to.method %>" class="external_form" enctype="<%= @push_to.enctype %>">
<h2>Push to <%= @push_to.name.capitalize %></h2>
Expand Down
1 change: 1 addition & 0 deletions app/views/citero_engine/cite/external_form.html.erb
@@ -0,0 +1 @@
<div class="no_js"><%= render :partial=>"citero_engine/cite/external_form" %></div>
1 change: 0 additions & 1 deletion app/views/ex_cite/cite/external_form.html.erb

This file was deleted.

34 changes: 34 additions & 0 deletions citero_engine.gemspec
@@ -0,0 +1,34 @@
$:.push File.expand_path("../lib", __FILE__)

# Maintain your gem's version:
require "citero_engine/version"

# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "citero_engine"
s.version = CiteroEngine::VERSION
s.platform = Gem::Platform::RUBY
s.date = '2014-01-22'
s.summary = "Web engine to allow download and push capabilities to an array of bibiligraphic records."
s.description = "Leverages citero-jruby gem and acts_as_citable to deliver a download and push mechanism."
s.authors = ["hab278"]
s.email = 'hab278@nyu.edu'
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
s.test_files = Dir["test/**/*"]
s.homepage = "https://github.com/NYULibraries/citero_engine"

s.add_dependency "rails", "~> 4.2.10"
s.add_dependency "acts_as_citable", "~> 5.0.0.alpha3"
s.add_dependency 'citero-renderers', '~> 1.0.4'
s.add_dependency "jquery-rails", "~> 4.3.1"

s.add_development_dependency "sqlite3", "~> 1.3.13"
s.add_development_dependency "rake", "~> 10.0"
s.add_development_dependency "simplecov-rcov", "~> 0.2.3"
s.add_development_dependency "test-unit", "~> 3.2.6"
s.add_development_dependency "coveralls", "~> 0.8.21"
s.add_development_dependency "pry", "~> 0.11.2"
s.add_development_dependency "rspec-rails", "~> 3.5"
s.add_development_dependency "rspec-html-matchers", "~> 0.9.1"
s.add_development_dependency "rspec-its", "~> 1.2.0"
end
5 changes: 0 additions & 5 deletions config/initializers/mime_types.rb
Expand Up @@ -2,8 +2,3 @@
Mime::Type.register_alias "text/plain", :csf
Mime::Type.register_alias "application/json", :easybib
Mime::Type.register_alias "text/plain", :refworks_tagged
Mime::Type.register_alias "application/json", :csl

Mime::Type.register_alias "text/html", :apa
Mime::Type.register_alias "text/html", :mla
Mime::Type.register_alias "text/html", :chicago_author_date
4 changes: 2 additions & 2 deletions config/routes.rb
@@ -1,3 +1,3 @@
ExCite::Engine.routes.draw do
match "export_citations(/:to_format)(/:id)" => 'export_citations#index', :via => [:get, :post], :as => "export_citations"
CiteroEngine::Engine.routes.draw do
match "citero_engine(/:to_format)(/:id)" => 'citero_engine#index', :via => [:get, :post], :as => "citero_engine"
end