repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/serializers/authenticated_user_serializer.rb | app/serializers/authenticated_user_serializer.rb | class AuthenticatedUserSerializer < ActiveModel::Serializer
attributes :name,
:email,
:created_at,
:picture,
:sha,
:editor,
:admin,
:has_papers_as_submittor,
:has_papers_as_reviewer,
:has_papers_as_editor
def has_papers_as_submittor
object.papers_as_submittor.any?
end
def has_papers_as_reviewer
object.assignments_as_reviewer.any?
end
def has_papers_as_editor
object.assignments_as_editor.any?
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/serializers/assignment_serializer.rb | app/serializers/assignment_serializer.rb | class AssignmentSerializer < BaseSerializer
attributes :sha,
:role,
:public,
:completed,
:reviewer_accept
has_one :user, serializer:PublicUserSerializer
private
def filter(*)
results = super
results = results - [:user] unless object.make_user_info_public?(current_user)
results = results - [:completed] unless object.use_completed?
results = results - [:reviewer_accept] unless object.use_completed? && object.completed?
results
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/serializers/paper_serializer.rb | app/serializers/paper_serializer.rb | class PaperSerializer < BaseSerializer
attributes :typed_provider_id,
:doi,
:user_permissions,
:state,
:submitted_at,
:title,
:authors,
:pending_issues_count
has_one :submittor, serializer:BasicUserSerializer
def submitted_at
object.created_at
end
def user_permissions
if scope
object.permissions_for_user(scope)
else
[]
end
end
def pending_issues_count
object.outstanding_issues.count
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/serializers/full_paper_serializer.rb | app/serializers/full_paper_serializer.rb | class FullPaperSerializer < PaperSerializer
attributes :paper_id,
:document_location
has_many :assigned_users
has_many :versions, each_serializer: BasicPaperSerializer
def paper_id
object.id
end
def versions
object.all_versions
end
def assigned_users
object.assignments
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/serializers/base_serializer.rb | app/serializers/base_serializer.rb |
class BaseSerializer < ActiveModel::Serializer
def current_user
scope
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/serializers/basic_paper_serializer.rb | app/serializers/basic_paper_serializer.rb | class BasicPaperSerializer < BaseSerializer
attributes :typed_provider_id,
:version
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/serializers/user_serializer.rb | app/serializers/user_serializer.rb | class UserSerializer < BaseSerializer
# Make sure that a user is never fully serialized because that would
# Expose too much public information
def initialize(*)
raise "No serializer supplied for user"
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/serializers/public_user_serializer.rb | app/serializers/public_user_serializer.rb | class PublicUserSerializer < BasicUserSerializer
attributes :email,
:created_at,
:picture,
:sha
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/serializers/annotation_serializer.rb | app/serializers/annotation_serializer.rb | class AnnotationSerializer < BaseSerializer
attributes :id,
:paper_id,
:state,
:parent_id,
:body,
:assignment,
:created_at,
:page,
:xStart,
:xEnd,
:yStart,
:yEnd
has_many :responses
def assignment
object.assignment.sha
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/serializers/preview_paper_serializer.rb | app/serializers/preview_paper_serializer.rb | # Serialize a Paper in the format for previewing documents
class PreviewPaperSerializer < BaseSerializer
attributes :typed_provider_id,
:title,
:summary,
:document_location,
:authors,
:is_existing,
:is_self_owned
def is_self_owned
current_user && current_user == object.submittor
end
def is_existing
object.persisted?
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/helpers/sessions_helper.rb | app/helpers/sessions_helper.rb | module SessionsHelper
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/helpers/comments_helper.rb | app/helpers/comments_helper.rb | module CommentsHelper
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/helpers/users_helper.rb | app/helpers/users_helper.rb | module UsersHelper
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/helpers/application_helper.rb | app/helpers/application_helper.rb | module ApplicationHelper
def current_user_roles
user = current_user
if (!user)
''
elsif user.admin? && user.editor?
' (Admin, Editor)'
elsif user.admin?
' (Admin)'
elsif user.editor?
' (Editor)'
else
''
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/helpers/papers_helper.rb | app/helpers/papers_helper.rb | module PapersHelper
def state_badge_for(paper)
return image_tag('badges/unknown.svg') unless paper
case paper.state
when "submitted"
image_tag('badges/submitted.svg')
when "under_review"
image_tag('badges/review.svg')
when "review_completed"
image_tag('badges/completed.svg')
when "rejected"
image_tag('badges/rejected.svg')
when "accepted"
image_tag('badges/accepted.svg')
when "published"
image_tag('badges/published.svg')
else
image_tag('badges/unknown.svg')
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/helpers/home_helper.rb | app/helpers/home_helper.rb | module HomeHelper
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/home_controller.rb | app/controllers/home_controller.rb | class HomeController < ApplicationController
before_filter :authentication_required, only: [:index_with_auth]
def index
render :index
end
def index_with_auth
render :index
end
def temp_home
papers = Paper.published
render 'temp_home', locals: { papers: papers }
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/papers_controller.rb | app/controllers/papers_controller.rb | class PapersController < ApplicationController
respond_to :json
def badge
if stale?(paper)
respond_to do |format|
format.html { @paper = paper; render layout:false }
format.json { render json: { state: paper.state } }
end
end
end
private
def paper
@paper ||= Paper.for_identifier!( params[:identifier] )
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/admin_controller.rb | app/controllers/admin_controller.rb | class AdminController < ApplicationController
respond_to :json
layout false
before_filter :require_admin
def index
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/feed_controller.rb | app/controllers/feed_controller.rb | class FeedController < ApplicationController
# arXiv metadata https://arxiv.org/help/bib_feed
def arxiv
papers = Paper.published
.where(provider_type: Provider::ArxivProvider.type)
.where('updated_at >= ?', 3.months.ago)
attributes = papers.map { |paper| arxiv_attributes(paper) }
render 'arxiv', locals: {papers: attributes, date: Time.now}
end
private
def arxiv_attributes(paper)
{
preprint_id: "arXiv:#{paper.provider_id}",
doi: paper.doi,
journal_ref: "The Open Journal of Astrophysics, #{paper.created_at.year}"
}
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/sessions_controller.rb | app/controllers/sessions_controller.rb | require 'open-uri'
class SessionsController < ApplicationController
def new
end
def create
logger.debug("#create")
user = User.from_omniauth(env["omniauth.auth"])
#FIXME this needs to go in a worker (or better still, come back in the OAuth hash...)
name = orcid_name_for(user.uid)
user.update_attributes(:name => name)
session[:user_id] = user.id
session[:user_sha] = user.sha
redirect_url = request.env['omniauth.origin'] || root_url
redirect_to redirect_url, :notice => "Signed in!"
end
def destroy
session[:user_id] = nil
session[:user_sha] = nil
redirect_to root_url, :notice => "Signed out!"
end
def failure
message = if params[:message]
"You could not be logged in! (#{params[:message].humanize})"
else
"You could not be logged in!"
end
redirect_to root_url, :alert => message
end
protected
def auth_hash
request.env['omniauth.auth']
end
#@todo refactor this into a class
def orcid_name_for(orcid_id)
uri = "https://pub.orcid.org/v1.1/#{orcid_id}/orcid-bio"
logger.debug("URI: #{uri.inspect}")
raw = open(uri, "Accept" => 'application/orcid+json') { |f| f.read }
data = JSON.parse(raw)
given_name = data['orcid-profile']['orcid-bio']['personal-details']['given-names']['value']
surname = data['orcid-profile']['orcid-bio']['personal-details']['family-name']['value']
"#{given_name} #{surname}"
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/application_controller.rb | app/controllers/application_controller.rb | 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
# before_filter :require_user
class HttpError < StandardError
def initialize(status_code, text)
@status_code, @text, @message = status_code, text
end
attr_reader :status_code, :text
end
rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.html { redirect_to root_url }
format.json { render :json => {}, :status => :forbidden }
end
Rails.logger.debug "Access denied on #{exception.action} #{exception.subject.inspect}"
end
rescue_from Provider::Error::ProviderNotFound do render_error_internal(:not_found) end
rescue_from Provider::Error::DocumentNotFound do render_error_internal(:not_found) end
rescue_from Provider::Error::InvalidIdentifier do render_error_internal(:bad_request) end
rescue_from ActiveRecord::RecordNotFound do render_error_internal(:not_found) end
rescue_from ActiveRecord::RecordNotUnique do render_error_internal(:conflict) end
rescue_from HttpError do |ex| render_error_internal(ex.status_code, ex.text) end
private
def ability_with(user, paper=nil, annotation=nil)
Ability.new(user, paper, annotation)
end
def require_user
render_error :unauthorized unless current_user
end
#@mro, @todo - needs to be rewritten (should be editor of Paper)
def require_editor
render_error :forbidden unless current_user && current_user.editor?
end
def require_admin
render_error :forbidden unless current_user && current_user.admin?
end
def current_user
if !defined?(@current_user) && session[:user_id] && session[:user_sha]
user = User.find(session[:user_id])
@current_user = user.sha == session[:user_sha] ? user : nil
end
@current_user
end
helper_method :current_user
def signed_in?
current_user.present?
end
helper_method :signed_in?
def authentication_required
return if signed_in?
respond_to do |format|
format.html {
url = '/auth/orcid?origin=' + CGI.escape(request.url)
redirect_to url, status: :forbidden
}
format.json {
render json: { error: 'Access Denied' }, status: :forbidden
}
end
end
def render_error_internal(status_code, text=nil)
code = Rack::Utils::SYMBOL_TO_STATUS_CODE[status_code]
message = "#{code} #{Rack::Utils::HTTP_STATUS_CODES[code]}"
respond_to do |format|
format.html { render plain:text || message, status: status_code }
format.json { render json: {error:message, text:text, code:code}, status: status_code }
end
end
def render_error(status_code, text=nil)
# raise here so that we break out of any processing
raise HttpError.new(status_code, text)
end
def render_errors(object, status_code=:unprocessable_entity)
render_error(status_code, object.errors.full_messages.join(".\r\n") + "." )
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/api/v1/users_controller.rb | app/controllers/api/v1/users_controller.rb | class Api::V1::UsersController < Api::V1::ApplicationController
respond_to :json
before_filter :require_user, except: [ :show ]
before_filter :require_editor, only: [ :lookup ]
def show
if current_user
respond_with current_user, serializer:AuthenticatedUserSerializer
else
render json:{}
end
end
def update
if current_user.update_attributes(update_params)
render json:current_user, serializer:AuthenticatedUserSerializer
else
render_errors(current_user)
end
end
def lookup
guess = params["guess"]
users = User.where("name like ?", "%#{guess}%").order(:name).limit(20)
respond_with users, each_serializer:PublicUserSerializer
end
private
def update_params
params.require(:user).permit(:email)
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/api/v1/annotations_controller.rb | app/controllers/api/v1/annotations_controller.rb | class Api::V1::AnnotationsController < Api::V1::ApplicationController
respond_to :json
before_filter :require_user, except: [:index, :all]
before_filter :require_editor, only: [:update]
# Root issues
def index
if can? :view_annotations, paper
render json: paper.issues
else
render json: [], status: :no_content
end
end
# All issues
def all
if can? :view_annotations, paper
render json: paper.annotations
else
render json: [], status: :no_content
end
end
def create
authorize! :annotate, paper
render_error(:unprocessable_entity) unless paper.under_review?
assignment = paper.assignments.for_user(current_user)
annotation = paper.annotations.build(annotation_params.merge(assignment: assignment))
if annotation.save
render json:annotation, status: :created
else
render_errors(annotation)
end
end
# def update
# # There is no update code here!
# if annotation.save
# render :json => annotation, :status => :created
# else
# render :json => annotation.errors, :status => :unprocessable_entity
# end
# end
def unresolve
change_state(:unresolve)
end
def dispute
change_state(:dispute)
end
def resolve
change_state(:resolve)
end
private
def change_state(event)
ability = ability_with(current_user, paper, annotation)
ability.authorize!(event, annotation)
render_error(:unprocessable_entity) unless annotation.send("may_#{event}?")
annotation.send("#{event}!")
render json: annotation
rescue AASM::InvalidTransition
render_error :unprocessable_entity
end
def annotation_params
params.require(:annotation).permit(:body, :parent_id, :page, :xStart, :yStart, :xEnd, :yEnd)
end
def annotation
@annotation ||= paper.annotations.find( params[:id] )
end
def paper
@paper ||= Paper.for_identifier!( params[:paper_identifier] )
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/api/v1/papers_controller.rb | app/controllers/api/v1/papers_controller.rb | class Api::V1::PapersController < Api::V1::ApplicationController
respond_to :json
before_filter :require_user, except: [ :recent, :search, :index, :show, :versions ]
before_filter :require_editor, only: [ :destroy, :transition ]
def index
recent
end
def show
#@todo
# ability = ability_with(current_user, paper)
# raise CanCan::AccessDenied if ability.cannot? :show, paper
respond_with paper, serializer:FullPaperSerializer
end
# Get the details for a new submission
def preview
paper = Paper.for_identifier( params[:identifier] )
if !paper
document_attributes = Provider.get_attributes( params[:identifier] )
# Don't save this, just use it to generate some JSON
paper = Paper.new(document_attributes)
end
respond_with paper, serializer:PreviewPaperSerializer
end
def create
document_attributes = Provider.get_attributes( params[:identifier] )
document_attributes.merge!(submittor:current_user)
paper = Paper.new(document_attributes)
authorize! :create, paper
if paper.save
render json:paper, status: :created, location:paper_review_url(paper), serializer:PaperSerializer
else
render json:aper.errors, status: :unprocessable_entity
end
end
def update
ability = ability_with(current_user, paper)
raise CanCan::AccessDenied if ability.cannot?(:update, paper)
if paper.update_attributes(paper_params)
render json:paper, location:paper_review_url(paper), serializer:FullPaperSerializer
else
render json:paper.errors, status: :unprocessable_entity
end
end
def destroy
render_error(:unprocessable_entity) unless paper.can_destroy?
ActiveRecord::Base.transaction do
has_errors = false
paper.all_versions.each do |p|
p.destroy
has_errors ||= p.errors.present?
end
if has_errors
render_errors paper
else
render json:{}
end
end
end
def badge
if stale?(paper)
respond_to do |format|
format.html { @paper = paper; render layout:false }
format.json { render json: { state: paper.state } }
end
end
end
def transition
transition = params[:transition].to_sym
logger.debug('trans 1')
ability_with(current_user, paper).authorize! transition, paper
logger.debug('trans 2')
if paper.aasm.may_fire_event?(transition)
logger.debug('trans 3')
paper.send("#{transition.to_s}!")
logger.debug('trans 4')
render json:paper, location:paper_review_url(paper), serializer:FullPaperSerializer
else
logger.debug('trans e')
render_errors(paper)
end
end
def complete
render_error(:unprocessable_entity) unless paper.under_review?
authorize! :complete, paper
render_error(:bad_request, 'accept parameter not supplied') if params[:result].nil?
if paper.mark_review_completed!(current_user, params[:result], params[:comments])
paper.assignments.reload
render json:paper, location:paper_review_url(paper), serializer:FullPaperSerializer
else
render_errors(paper)
end
end
def public
authorize! :make_public, paper
case request.method_symbol
when :post, :delete
public = request.method_symbol != :delete
if paper.make_reviewer_public!(current_user, public)
paper.assignments.reload
render json:paper, location:paper_review_url(paper), serializer:FullPaperSerializer
else
render_errors(assignment)
end
else
raise 'Unsupported method'
end
end
def versions
parts = Provider.parse_identifier( params[:identifier] )
papers = Paper.versions_for( parts[:provider_type], parts[:provider_id] )
render json:papers, each_serializer: BasicPaperSerializer
end
def check_for_update
latest_paper = paper
render_error(:not_found) unless latest_paper
render_error(:forbidden) unless latest_paper.submittor == current_user or current_user.editor_of?(latest_paper)
render_error(:conflict) unless latest_paper.may_supercede?
provider = latest_paper.provider
document_attributes = provider.get_attributes(latest_paper.provider_id)
if document_attributes[:version] <= latest_paper.version
render_error(:conflict, 'There is no new version of this document.')
end
new_paper = latest_paper.create_updated!(document_attributes)
render json: new_paper,
serializer: BasicPaperSerializer,
status: :created
end
def recent
respond_with_papers Paper.recent.published
end
def search
query = params[:q]
render_error(:bad_request) unless query.present?
respond_with_papers Paper.search(query)
end
def as_reviewer
respond_with_papers current_user.papers_as_reviewer
end
def as_editor
respond_with_papers current_user.papers_as_editor
end
def as_author
respond_with_papers current_user.papers_as_submittor
end
def as_collaborator
respond_with_papers current_user.papers_as_collaborator
end
private
def paper_params
params.require(:paper).permit(:title, :document_location)
end
def respond_with_papers(root_relation)
papers = root_relation.active.with_state(params[:state])
respond_with papers
end
def paper
@paper ||= Paper.for_identifier!( params[:identifier] )
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/api/v1/assignments_controller.rb | app/controllers/api/v1/assignments_controller.rb | class Api::V1::AssignmentsController < Api::V1::ApplicationController
respond_to :json
before_filter :require_user, except: [ :index ]
before_filter :require_editor, only: [ :create, :destroy ]
def index
render json:paper.assignments, status: :ok, location: paper_review_url(paper)
end
def create
user = User.find_by_sha(params[:user])
role = params[:role] || 'reviewer'
if !paper.submitted? && !paper.under_review?
render json: 'invalid state', status: :bad_request
elsif role != 'reviewer' && role != 'collaborator'
render json: 'invalid role', status: :bad_request
elsif user && paper.add_assignee(user, role)
paper.start_review! unless paper.under_review?
render json: paper.assignments, status: :created, location: paper_review_url(paper)
else
render json: paper.errors, status: :unprocessable_entity
end
end
def destroy
if assignment && assignment.destroy
render json:paper.assignments, status: :ok, location: paper_review_url(paper)
else
render json: paper.errors, status: :unprocessable_entity
end
end
private
def assignment
@assignment ||= paper.assignments.find_by_sha(params[:id])
end
def paper
@paper ||= Paper.for_identifier!( params[:paper_identifier] )
end
end | ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/controllers/api/v1/application_controller.rb | app/controllers/api/v1/application_controller.rb | class Api::V1::ApplicationController < ApplicationController
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/models/provider.rb | app/models/provider.rb | # Lookup class for Providers
class Provider
SEPARATOR = ':'
class << self
def parse_identifier(identifier)
raise Error::InvalidIdentifier.new unless identifier.present?
provider_type, identifier = identifier.split(SEPARATOR, 2)
raise Error::InvalidIdentifier.new unless identifier.present?
provider = self[provider_type]
parsed = provider.parse_identifier(identifier)
parsed.merge(
provider_type: provider_type
)
end
def get_attributes(identifier)
raise Error::InvalidIdentifier.new unless identifier.present?
provider_type,identifier = identifier.split(SEPARATOR, 2)
raise Error::InvalidIdentifier.new unless identifier.present?
provider = self[provider_type]
provider.get_attributes(identifier)
end
def [](type)
get(type) || raise( Error::ProviderNotFound.new("Provider not found for '#{type}'") )
end
def get(type)
providers[ type && type.downcase.to_sym ]
end
def providers
load_providers unless providers_loaded?
@providers
end
private
def providers_loaded?
@providers
end
def add(provider)
raise "Provider #{provider} doesn't respond to type" if ! provider.respond_to?(:type)
@providers[ provider.type.downcase.to_sym ] = provider
end
def load_providers
@providers = {}
path = File.join( File.dirname(__FILE__), 'provider', '*_provider.rb')
Dir[path].each do |file|
klass_name = File.basename(file,'.rb').camelize
next if klass_name == 'BaseProvider'
klass = "Provider::#{klass_name}".constantize
add( klass)
end
end
end
module Error
class ProviderNotFound < StandardError; end
class DocumentNotFound < StandardError; end
class InvalidIdentifier < StandardError; end
end
end | ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/models/annotation.rb | app/models/annotation.rb | class Annotation < ActiveRecord::Base
include AASM
belongs_to :paper, inverse_of: :annotations
belongs_to :assignment, inverse_of: :annotations
has_many :responses, class_name:'Annotation', foreign_key:'parent_id'
belongs_to :parent, class_name:'Annotation', foreign_key:'parent_id'
scope :root_annotations , -> { where(parent_id: nil) }
before_validation :set_defaults
after_save :push_to_firebase
validates :body,
presence:true
validates :paper_id,
presence:true
validates :assignment_id,
presence:true
validate do
errors.add(:assignment, 'must belong to the same paper') unless !paper_id || paper.assignments.include?(assignment)
end
validate do
errors.add(:parent, 'must belong to the same paper') unless parent_id.nil? || parent.paper_id == paper_id
end
aasm column: :state, no_direct_assignment:true do
state :unresolved, initial:true
state :resolved
state :disputed
event :unresolve, guard: :can_change_state? do
transitions to: :unresolved
end
event :resolve, guard: :can_change_state? do
transitions to: :resolved
end
event :dispute, guard: :can_change_state? do
transitions to: :disputed
end
end
def base_annotation
parent_id.nil? ? self : parent
end
def user
assignment.user
end
def firebase_key
"#{paper.firebase_key}/annotations/#{base_annotation.id}"
end
def push_to_firebase
# Note this must be anonymized user data
# Rails.logger.debug("PUSHING TO FIREBASE: #{firebase_key}:: #{base_annotation.inspect}")
# FirebaseClient.set firebase_key, AnnotationSerializer.new(base_annotation).as_json
end
# Is this a root issue?
def is_issue?
parent_id.nil?
end
def is_response?
parent_id
end
def has_responses?
responses.any?
end
private
def can_change_state?
return false unless is_issue? && paper
return true if paper.under_review?
# Can resolve while paper is being accepted
return true if paper.aasm.current_event.in?([:accept, :accept!]) && aasm.to_state==:resolved
return false
end
def set_defaults
self.paper_id = parent.paper_id if parent_id && !paper_id
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/models/ability.rb | app/models/ability.rb | class Ability
include CanCan::Ability
def initialize(user, paper=nil, annotation=nil)
# HEADS UP - ordering matters here because of how CanCan defines abilities
if user
initialize_annotation(user, annotation)
initialize_author(user, paper)
initialize_collaborator(user, paper)
initialize_reviewer(user, paper)
initialize_editor(user, paper)
initialize_privileged(user)
end
end
def initialize_collaborator(user, paper)
if paper
can :read, Paper if user.collaborator_on?(paper)
# Can read someone else's annotations
can :read, Annotation if user.collaborator_on?(paper)
end
end
def initialize_author(user, paper)
# Can create papers
can :create, Paper
if paper
if user.author_of?(paper)
# Can read papers if it's theirs or...
can :read, Paper if user.author_of?(paper)
# Can respond to annotations from reviewers
# TODO this isn't actually defining a response to something
can :create, Annotation
# Can read their own annotations
can :read, Annotation, user_id: user.id
# Can read someone else's annotations
can :read, Annotation
can :update, Paper unless paper.published? || paper.accepted?
end
can :destroy, Paper, user_id: user.id
cannot :destroy, Paper
end
end
def initialize_reviewer(user, paper)
if paper && user.reviewer_of?(paper)
# If they are a reviewer of the paper
can :read, Paper
can :create, Annotation
can :read, Annotation
end
can :complete, Paper, assignments:{user_id:user.id, role:'reviewer'}
can :make_public, Paper, assignments:{user_id:user.id, role:'reviewer'}
end
def initialize_editor(user, paper)
if paper && user.editor_of?(paper)
can :create, Annotation
# If they are an editor of the paper
can :read, Paper
can :destroy, Paper
can :update, Paper
can :read, Annotation
#Paper Transitions
can :start_review, Paper
can :accept, Paper
can :reject, Paper
can :create, Assignment
can :destroy, Assignment
can :destroy, Annotation
# State changes
can [:start_review, :accept, :reject, :publish], Paper
can [:unresolve, :dispute, :resolve], Annotation
end
end
def initialize_privileged(user)
# Admins can do anything
if user.admin?
can :manage, :all
end
end
def initialize_annotation(user, annotation)
if annotation
# They can change their annotations unless there are responses to it
can :update, Annotation, :user_id => user.id unless annotation.has_responses?
# Authors can't destroy annotations
cannot :destroy, Annotation
end
can :view_annotations, Paper, assignments:{user_id:user.id}
can :annotate, Paper, assignments:{user_id:user.id}
can :comment, Paper, assignments:{user_id:user.id}
# State changes
can [:unresolve, :dispute, :resolve],
Annotation, assignment: { user_id: user.id }
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/models/assignment.rb | app/models/assignment.rb | class Assignment < ActiveRecord::Base
belongs_to :user, inverse_of: :assignments
belongs_to :paper, inverse_of: :assignments
has_many :annotations, inverse_of: :assignment
# set when the paper is being updated from an original
attr_accessor :copied
validates :role,
inclusion:{ in:['submittor', 'collaborator', 'reviewer', 'editor'] }
validates :reviewer_accept,
inclusion:{ in:['accept', 'accept_with_minor', 'accept_with_major', 'reject'], allow_nil: true }
before_create :set_initial_values
before_destroy :check_for_annotations!
# Using after commit since creating revisions happens in a transaction
after_commit :send_emails, on: :create
def self.build_copy(original)
# Note we don't copy the 'completed' field
attrs = original.attributes.symbolize_keys.slice(:role, :user_id, :public)
attrs[:copied] = true
self.new attrs
end
def use_completed?
role == 'reviewer'
end
#@mro, @todo Change to use CanCan?
def make_user_info_public?(requesting_user)
public? || requesting_user==self.user || (requesting_user && requesting_user.editor_of?(paper) )
end
private
def set_initial_values
self.sha = SecureRandom.hex
if ! copied
self.public = (role != 'reviewer')
end
true
end
def check_for_annotations!
if paper.annotations.any?{ |a| a.assignment == self }
errors.add(:base, "cannot delete customer while orders exist")
false
end
end
def send_emails
# submittor emails are sent from the Paper
return if role == 'submittor'
# We need to send the assigned email if the record is not copied
# i.e. the user is assigned after the paper is updated
if ! copied
NotificationMailer.notification(user, paper,
"You have been assigned to a paper as #{role.a_or_an} #{role}.",
'Paper Assigned'
).deliver_later
else
NotificationMailer.notification(user, paper,
"A paper that you are assigned to as #{role.a_or_an} #{role} has been updated.",
'Paper Updated'
).deliver_later
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/models/paper.rb | app/models/paper.rb |
class Paper < ActiveRecord::Base
include AASM
has_many :annotations, inverse_of: :paper, dependent: :destroy
has_many :assignments, inverse_of: :paper, dependent: :destroy do
def for_user(user, role=nil)
if role
where(user:user, role:role).first
else
where(user:user).first
end
end
end
has_one :submittor_assignment, -> { where('assignments.role = ?', 'submittor') }, class_name:'Assignment'
has_many :collaborator_assignments, -> { where('assignments.role = ?', 'collaborator') }, class_name:'Assignment'
has_many :reviewer_assignments, -> { where('assignments.role = ?', 'reviewer') }, class_name: 'Assignment'
has_many :editor_assignments, -> { where('assignments.role = ?', 'editor') }, class_name:'Assignment'
belongs_to :submittor, class_name:'User', inverse_of: :papers_as_submittor
has_many :collaborators, through: :collaborator_assignments, source: :user
has_many :reviewers, through: :reviewer_assignments, source: :user
has_many :editors, through: :editor_assignments, source: :user
has_many :assignees, through: :assignments, source: :user
scope :active, -> { where.not(state:'superceded') }
scope :recent, -> { order(created_at: :desc).limit(50) }
scope :search, ->(term) { term="%#{term}%"; joins(:submittor).where('title like ? OR summary like ? OR authors like ? OR users.name like ?', term, term, term, term) }
scope :with_state, ->(state=nil) { state.present? ? where(state:state) : all }
before_create :create_assignments
# Using after commit since creating revisions happens in a transaction
after_commit :send_submittor_emails, on: :create
validates :submittor_id,
:provider_type,
:provider_id,
:version,
presence: true
aasm column: :state do
state :submitted, initial:true
state :under_review
state :review_completed
state :superceded
state :rejected
state :accepted
state :published
event :start_review, guard: :has_reviewers?, after_commit: :send_state_change_emails do
transitions from: :submitted,
to: :under_review
end
event :complete_review, after_commit: [:send_state_change_emails, :send_review_completed_emails] do
transitions from: :under_review,
to: :review_completed
end
event :supercede do
transitions from: [:submitted, :under_review, :review_completed, :rejected, :accepted],
to: :superceded
end
event :reject, after_commit: :send_state_change_emails do
transitions from: [:under_review, :review_completed],
to: :rejected
end
event :accept, before: :resolve_all_issues, after_commit: :send_state_change_emails do
transitions from: [:under_review, :review_completed],
to: :accepted
end
event :publish, guard: :doi, after_commit: :send_state_change_emails do
transitions from: :accepted,
to: :published
end
end
def self.for_identifier(identifier)
if identifier.is_a?(Integer) || identifier =~ /^\d+$/
where(id:identifier).first
else
parsed = Provider.parse_identifier(identifier)
relation = where(provider_type:parsed[:provider_type], provider_id:parsed[:provider_id] )
relation = parsed[:version] ? relation.where(version: parsed[:version] ) : relation.order(version: :desc)
relation.first
end
end
def self.for_identifier!(identifier)
for_identifier(identifier) or raise ActiveRecord::RecordNotFound.new
end
def self.versions_for(provider_type, provider_id)
if provider_id
where(provider_type:provider_type, provider_id:provider_id).order(version: :desc)
else
none
end
end
def create_updated!(attributes)
original = self
raise 'Providers do not match' unless original.provider_type.to_sym == attributes[:provider_type]
raise 'Provider IDs do not match' unless original.provider_id == attributes[:provider_id]
raise 'Cannot update superceded original' unless original.may_supercede?
raise 'No new version available' unless original.version < attributes[:version]
new_state = original.aasm.current_state
new_state = 'under_review' if original.aasm.states.index(new_state) > original.aasm.states.index(:under_review)
ActiveRecord::Base.transaction do
attributes = attributes.merge(submittor: original.submittor, state: new_state)
new_paper = Paper.new(attributes)
original.assignments.each do |assignment|
new_paper.assignments << Assignment.build_copy(assignment)
end
new_paper.save!
original.supercede!
new_paper
end
end
def can_destroy?
submitted? || superceded?
end
def provider
@provider ||= Provider[provider_type]
end
def full_provider_id
provider.full_identifier(provider_id:provider_id, version:version)
end
def typed_provider_id
"#{provider_type}#{Provider::SEPARATOR}#{full_provider_id}"
end
def issues
annotations.root_annotations
end
def outstanding_issues
issues.where.not(state:'resolved')
end
def resolve_all_issues
issues.each(&:resolve!)
end
# Newest version first
def all_versions
@all_versions ||= (provider_id ? Paper.versions_for(provider_type, provider_id) : [self])
end
def is_revision?
all_versions.length>1 && self != all_versions.last
end
def is_latest_version?
# self == all_versions.first
# A little more efficient
! superceded?
end
def is_original_version?
all_versions.empty? || self == all_versions.last
end
def add_assignee(user, role='reviewer')
can_assign = ! assignments.for_user(user)
if can_assign && a=assignments.create(user: user, role:role)
true
else
errors.add(:assignments, 'Unable to assign user')
false
end
end
def mark_review_completed!(reviewer, result, comments=nil)
errors.add(:base, 'Review cannot be marked as complete') and return unless may_complete_review?
assignment = assignments.for_user(reviewer, :reviewer)
errors.add(:base, 'Assignee is not a reviewer') and return unless assignment
assignment.update_attributes!(completed:true, reviewer_accept:result)
if comments.present?
annotation = annotations.create(assignment: assignment,
body: comments )
end
all_reviews_completed = reviewer_assignments.all?(&:completed?)
complete_review! if all_reviews_completed
true
end
def make_reviewer_public!(reviewer, public=true)
errors.add(:base, 'Review cannot be marked as complete') and return unless is_latest_version?
assignment = assignments.for_user(reviewer, :reviewer)
errors.add(:base, 'Assignee is not a reviewer') and return unless assignment
all_versions.each do |paper|
assignment = paper.assignments.for_user(reviewer, :reviewer)
assignment.update_attributes!(public:public) if assignment
end
true
end
def permissions_for_user(user)
assignments.where(user_id:user.id).pluck(:role)
end
alias to_param typed_provider_id
def firebase_key
key = Firebase.clean_key(typed_provider_id)
"/papers/#{key}"
end
private
def has_reviewers?
reviewers.any?
end
def create_assignments
if assignments.none? { |a| a.role=='editor' }
#@todo: This is just for testing. The submittor should never be the editor
editor = submittor.editor? ? submittor : User.next_editor
assignments.build(role:'editor', user:editor) if editor
end
if assignments.none? { |a| a.role=='submittor' && a.user==submittor }
assignments.build(role:'submittor',user:submittor)
end
end
def send_submittor_emails
if is_original_version?
NotificationMailer.notification(submittor, self,
'You have submitted a new paper.',
'Paper Submitted'
).deliver_later
else
NotificationMailer.notification(submittor, self,
'You have submitted a new revision of a paper',
'Paper Revised'
).deliver_later
end
end
def send_state_change_emails
state_name = state.titleize
NotificationMailer.notification(submittor, self,
"The state of your paper has changed to #{state_name}",
"Paper #{state_name}"
).deliver_later
end
def send_review_completed_emails
editors.each do |editor|
NotificationMailer.notification(editor, self,
"Reviews have been completed on a paper you are editing",
"Review Completed"
).deliver_later
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/models/user.rb | app/models/user.rb | class User < ActiveRecord::Base
has_many :assignments, inverse_of: :user
has_many :assignments_as_collaborator, -> { where(role:'collaborator') }, class_name:'Assignment', inverse_of: :user
has_many :assignments_as_reviewer, -> { where(role:'reviewer') }, class_name:'Assignment', inverse_of: :user
has_many :assignments_as_editor, -> { where(role:'editor') }, class_name:'Assignment', inverse_of: :user
# # Submitting author relationship with paper
has_many :papers_as_submittor, class_name:'Paper', inverse_of: :submittor, foreign_key:'submittor_id'
has_many :papers_as_collaborator, through: :assignments_as_collaborator, source: :paper
has_many :papers_as_reviewer, through: :assignments_as_reviewer, source: :paper
has_many :papers_as_editor, through: :assignments_as_editor, source: :paper
serialize :extra
validates :email,
format: {with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i,
allow_nil: true,
message: "Doesn't look like an email address" }
before_create :set_sha
def self.from_omniauth(auth)
where(provider: auth["provider"], uid: auth["uid"] ).first || create_from_omniauth(auth)
end
def self.create_from_omniauth(auth)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["info"]["nickname"]
user.picture = auth["info"]["image"]
user.oauth_token = auth["credentials"]["token"]
user.oauth_expires_at = Time.at(auth["credentials"]["expires_at"]) if auth["provider"] == "facebook"
user.extra = auth
end
end
def self.next_editor
@editor ||= where(editor:true).first
end
def reviewer_of?(paper)
paper.reviewers.include?(self)
end
def editor_of?(paper)
self.editor? && paper.editors.include?(self)
end
def collaborator_on?(paper)
paper.collaborators.include?(self)
end
def author_of?(paper)
paper.submittor == self
end
def role_for(paper)
case
when editor_of?(paper)
'editor'
when reviewer_of?(paper)
'reviewer'
when author_of?(paper)
'author'
when collaborator_on?(paper)
'collaborator'
end
end
def to_param
sha
end
private
def set_sha
self.sha = SecureRandom.hex
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/models/provider/arxiv_provider.rb | app/models/provider/arxiv_provider.rb | class Provider
class ArxivProvider < BaseProvider
self.type = :arxiv
self.version_separator = 'v'
class << self
def get_attributes(id)
manuscript = Arxiv.get(id.to_s)
attributes_from_manuscript(manuscript)
rescue Arxiv::Error::ManuscriptNotFound => ex
raise Error::DocumentNotFound.new(ex.message)
end
private
def attributes_from_manuscript(manuscript)
{
provider_type: self.type,
provider_id: manuscript.arxiv_id,
version: manuscript.version,
title: manuscript.title,
summary: manuscript.summary,
document_location: manuscript.pdf_url.sub('http://', 'https://'),
authors: manuscript.authors.collect{|a| a.name}.join(", ")
}
end
private
def identifier_valid?(identifier)
Arxiv::ID_FORMAT === identifier
end
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/models/provider/test_provider.rb | app/models/provider/test_provider.rb | # Used for running specs
class Provider
class TestProvider < BaseProvider
self.type = :test
self.version_separator = '-'
class << self
def get_attributes(id)
parsed = parse_identifier(id)
{
provider_type: self.type,
provider_id: parsed[:provider_id],
version: parsed[:version] || 9,
authors: "author list",
document_location: "https://example.com/document/123-9.pdf",
title: "title",
summary: "summary"
}
end
private
def identifier_valid?(identifier)
/^[\w.-]+$/ === identifier
end
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/models/provider/base_provider.rb | app/models/provider/base_provider.rb | class Provider
class BaseProvider
class_attribute :type
class_attribute :version_separator
class << self
def full_identifier(**params)
result = params[:provider_id].dup
result << "#{version_separator}#{params[:version]}" if params[:version]
result
end
def parse_identifier(identifier)
raise Error::InvalidIdentifier unless identifier_valid?(identifier)
parts = identifier.split(version_separator, 2)
{
provider_id: parts[0],
version: parts[1] && parts[1].to_i
}.compact
end
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/mailers/notification_mailer.rb | app/mailers/notification_mailer.rb | class NotificationMailer < ApplicationMailer
def notification(user, paper, text, subject='Paper Updated')
@paper = paper
@link = paper_review_url(paper)
@text = text
subject = "#{paper.title} - #{subject}"
mail to:user, subject:subject
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/app/mailers/application_mailer.rb | app/mailers/application_mailer.rb | class ApplicationMailer < ActionMailer::Base
layout 'mailer'
def mail(headers = {}, &block)
set_users(headers)
@subject = headers[:subject] = "[TheOJ] #{headers[:subject]}"
super unless headers[:to].empty?
end
def full_email_for_user(user)
if user.name.present? && user.email.present?
%("#{user.name}" <#{user.email}>)
else
user.email
end
end
private
def set_users(headers)
raise "No 'to' parameter supplied" unless headers[:to]
users = Array(headers[:to])
raise "'to' parameter must be a user" unless users.first.is_a?(User)
@user = users.first
users = users.map do |user|
user.is_a?(User) ? full_email_for_user(user) : user
end.compact
headers[:to] = users
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/seeds.rb | db/seeds.rb | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
User.destroy_all
Paper.destroy_all
users = []
users << User.create(uid: 1, name: "stuart", extra: "blah blah", picture: "https://pbs.twimg.com/profile_images/2392941891/anq5bkkx8rtdhn8p2i9m_bigger.png")
users << User.create(uid: 2, name: "arfon", extra: "blah blah", picture: "https://pbs.twimg.com/profile_images/2392941891/anq5bkkx8rtdhn8p2i9m_bigger.png")
10.times do |no|
Paper.create( submitted_at: DateTime.now, title: "Paper no #{no}", location:"http://arxiv.org/abs/1405.103#{1+no}",user_id: users.sample.id )
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/schema.rb | db/schema.rb | # encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161228023050) do
create_table "annotations", force: :cascade do |t|
t.integer "assignment_id", limit: 4
t.integer "paper_id", limit: 4
t.string "state", limit: 255
t.integer "parent_id", limit: 4
t.text "body", limit: 65535
t.datetime "created_at"
t.datetime "updated_at"
t.integer "page", limit: 4
t.float "xStart", limit: 24
t.float "yStart", limit: 24
t.float "xEnd", limit: 24
t.float "yEnd", limit: 24
end
add_index "annotations", ["assignment_id"], name: "index_annotations_on_assignment_id", using: :btree
add_index "annotations", ["paper_id"], name: "index_annotation_paper_id", using: :btree
add_index "annotations", ["parent_id"], name: "index_annotation_parent_id", using: :btree
add_index "annotations", ["state"], name: "index_annotation_state", using: :btree
create_table "assignments", force: :cascade do |t|
t.integer "user_id", limit: 4
t.integer "paper_id", limit: 4
t.string "role", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.string "sha", limit: 255, null: false
t.boolean "public", limit: 1, default: false, null: false
t.boolean "completed", limit: 1, default: false, null: false
t.string "reviewer_accept", limit: 20
end
add_index "assignments", ["paper_id"], name: "index_assignment_paper_id", using: :btree
add_index "assignments", ["role"], name: "index_assignment_role", using: :btree
add_index "assignments", ["sha"], name: "index_assignments_on_sha", using: :btree
add_index "assignments", ["user_id"], name: "index_assignment_user_id", using: :btree
create_table "papers", force: :cascade do |t|
t.integer "submittor_id", limit: 4
t.string "document_location", limit: 255
t.string "state", limit: 255
t.string "title", limit: 255
t.integer "version", limit: 4, default: 1
t.datetime "created_at"
t.datetime "updated_at"
t.string "provider_id", limit: 255, null: false
t.text "summary", limit: 65535
t.text "authors", limit: 65535
t.string "provider_type", limit: 10, null: false
t.string "doi", limit: 255
end
add_index "papers", ["provider_type", "provider_id", "version"], name: "index_papers_on_provider_type_and_provider_id_and_version", unique: true, using: :btree
add_index "papers", ["state"], name: "index_paper_state", using: :btree
add_index "papers", ["submittor_id"], name: "index_papers_on_submittor_id", using: :btree
create_table "users", force: :cascade do |t|
t.string "provider", limit: 255
t.string "uid", limit: 255
t.string "name", limit: 255
t.boolean "admin", limit: 1, default: false
t.boolean "editor", limit: 1, default: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "oauth_token", limit: 255
t.datetime "oauth_expires_at"
t.text "extra", limit: 65535
t.string "picture", limit: 255
t.string "sha", limit: 255
t.string "email", limit: 255
end
add_index "users", ["admin"], name: "index_user_admin", using: :btree
add_index "users", ["editor"], name: "index_user_editor", using: :btree
add_index "users", ["name"], name: "index_user_name", using: :btree
add_index "users", ["oauth_token"], name: "index_users_on_oauth_token", using: :btree
add_index "users", ["provider"], name: "index_user_providers", using: :btree
add_index "users", ["sha"], name: "index_users_on_sha", using: :btree
add_index "users", ["uid"], name: "index_user_uid", using: :btree
add_foreign_key "annotations", "annotations", column: "parent_id", on_delete: :cascade
add_foreign_key "annotations", "assignments"
add_foreign_key "annotations", "papers", on_delete: :cascade
add_foreign_key "assignments", "papers", on_delete: :cascade
add_foreign_key "assignments", "users"
add_foreign_key "papers", "users", column: "submittor_id", on_delete: :cascade
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150210150759_unique_paper_indexes.rb | db/migrate/20150210150759_unique_paper_indexes.rb | class UniquePaperIndexes < ActiveRecord::Migration
def up
remove_index :papers, ["arxiv_id"]
add_index :papers, ["arxiv_id"], unique:true
remove_index :papers, ["sha"]
add_index :papers, ["sha"], unique:true
end
def down
remove_index :papers, ["arxiv_id"]
add_index :papers, ["arxiv_id"]
remove_index :papers, ["sha"]
add_index :papers, ["sha"]
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20140515135144_rename_comments.rb | db/migrate/20140515135144_rename_comments.rb | class RenameComments < ActiveRecord::Migration
def change
rename_table :comments, :annotations
Annotation.reset_column_information
remove_index("annotations", :name => "index_comment_user_id")
remove_index("annotations", :name => "index_comment_paper_id")
remove_index("annotations", :name => "index_comment_state")
remove_index("annotations", :name => "index_comment_parent_id")
add_index "annotations", ["user_id"], :name => "index_annotation_user_id"
add_index "annotations", ["paper_id"], :name => "index_annotation_paper_id"
add_index "annotations", ["state"], :name => "index_annotation_state"
add_index "annotations", ["parent_id"], :name => "index_annotation_parent_id"
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20140712015520_add_assigned_user_to_paper.rb | db/migrate/20140712015520_add_assigned_user_to_paper.rb | class AddAssignedUserToPaper < ActiveRecord::Migration
def change
add_column :papers, :fao_id, :integer
add_index :papers, ["fao_id"]
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20161228023050_reviewer_accept_to_string.rb | db/migrate/20161228023050_reviewer_accept_to_string.rb | class ReviewerAcceptToString < ActiveRecord::Migration
def change
change_column :assignments, :reviewer_accept, :string, limit: 20
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150626190052_remove_paper_sha.rb | db/migrate/20150626190052_remove_paper_sha.rb | class RemovePaperSha < ActiveRecord::Migration
def change
remove_index :papers, name: "index_papers_on_sha"
remove_column :papers, :sha
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150512025202_add_sha_to_assignment.rb | db/migrate/20150512025202_add_sha_to_assignment.rb | class AddShaToAssignment < ActiveRecord::Migration
def change
add_column :assignments, :sha, :string
reversible do |dir|
dir.up do
Assignment.find_each do |a|
a.update_attributes!(sha:SecureRandom.hex)
end
end
end
change_column_null :assignments, :sha, false
add_index :assignments, ["sha"]
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150505233549_add_email_to_user.rb | db/migrate/20150505233549_add_email_to_user.rb | class AddEmailToUser < ActiveRecord::Migration
def change
add_column :users, :email, :string, limit:255
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150626190032_change_from_arxiv_id_to_source_id.rb | db/migrate/20150626190032_change_from_arxiv_id_to_source_id.rb | class ChangeFromArxivIdToSourceId < ActiveRecord::Migration
def change
remove_index :papers, name: "index_papers_on_arxiv_id_and_version"
rename_column :papers, :arxiv_id, :provider_id
add_column :papers, :provider_type, :string, limit:10
reversible do |dir|
dir.up do
execute('DELETE FROM papers WHERE provider_id IS NULL')
execute('UPDATE papers SET provider_type="arxiv"')
end
end
change_column_null :papers, :provider_type, false
change_column_null :papers, :provider_id, false
add_index :papers, [:provider_type, :provider_id, :version], unique: true
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150224004849_fix_annotation_state.rb | db/migrate/20150224004849_fix_annotation_state.rb | class FixAnnotationState < ActiveRecord::Migration
def up
Annotation.all.where(state:'new').update_all(state:'unresolved')
end
def down
Annotation.all.where(state:'unresolved').update_all(state:'new')
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20140211220942_create_users.rb | db/migrate/20140211220942_create_users.rb | class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :provider
t.string :uid
t.string :name
t.boolean :admin, :default => false
t.boolean :editor, :default => false
t.timestamps
end
add_index "users", ["provider"], :name => "index_user_providers"
add_index "users", ["uid"], :name => "index_user_uid"
add_index "users", ["name"], :name => "index_user_name"
add_index "users", ["admin"], :name => "index_user_admin"
add_index "users", ["editor"], :name => "index_user_editor"
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150526184138_add_arxiv_id_index.rb | db/migrate/20150526184138_add_arxiv_id_index.rb | class AddArxivIdIndex < ActiveRecord::Migration
def change
remove_index :papers, name: "index_papers_on_arxiv_id"
add_index :papers, [:arxiv_id, :version], unique: true
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20140212012504_create_papers.rb | db/migrate/20140212012504_create_papers.rb | class CreatePapers < ActiveRecord::Migration
def change
create_table :papers do |t|
t.integer :user_id
t.string :location
t.string :state
t.datetime :submitted_at
t.string :title
t.integer :version, :default => 1
t.timestamps
end
add_index "papers", ["user_id"], :name => "index_paper_user_id"
add_index "papers", ["state"], :name => "index_paper_state"
add_index "papers", ["submitted_at"], :name => "index_paper_submitted_at"
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20161009043324_add_doi_to_paper.rb | db/migrate/20161009043324_add_doi_to_paper.rb | class AddDoiToPaper < ActiveRecord::Migration
def change
add_column :papers, :doi, :string
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150201224917_add_arxiv_details_to_paper.rb | db/migrate/20150201224917_add_arxiv_details_to_paper.rb | class AddArxivDetailsToPaper < ActiveRecord::Migration
def change
add_column :papers, :arxiv_id, :string
add_column :papers, :summary, :text
add_column :papers, :author_list, :text
add_index :papers, ["arxiv_id"]
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150525171135_create_fks_and_refactor.rb | db/migrate/20150525171135_create_fks_and_refactor.rb | class CreateFksAndRefactor < ActiveRecord::Migration
def change
delete_data
refactor_columns
create_foreign_keys
create_assignees
end
def delete_data
Annotation.delete_all
Assignment.delete_all
end
def refactor_columns
remove_index :annotations, name:'index_annotation_user_id'
rename_column :annotations, :user_id, :assignment_id
add_index :annotations, [:assignment_id]
remove_column :annotations, :category
remove_index :assignments, name:'index_assignment_assignee_id'
remove_column :assignments, :assignee_id
remove_index :papers, name:'index_paper_user_id'
rename_column :papers, :user_id, :submittor_id
add_index :papers, [:submittor_id]
remove_index :papers, name:'index_papers_on_fao_id'
remove_column :papers, :fao_id
end
def create_foreign_keys
Paper.all.each do |p|
p.update_attributes!(submittor:User.first) if p.submittor.nil?
end
add_foreign_key :papers, :users, on_delete: :cascade, column: :submittor_id
add_foreign_key :assignments, :users, on_delete: :restrict
add_foreign_key :assignments, :papers, on_delete: :cascade
add_foreign_key :annotations, :papers, on_delete: :cascade
add_foreign_key :annotations, :assignments, on_delete: :restrict
add_foreign_key :annotations, :annotations, on_delete: :cascade, column: 'parent_id'
end
def create_assignees
Paper.all.each do |p|
p.send(:create_assignments)
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150202233833_add_location_data_to_annotation.rb | db/migrate/20150202233833_add_location_data_to_annotation.rb | class AddLocationDataToAnnotation < ActiveRecord::Migration
def change
add_column :annotations, :page, :integer
add_column :annotations, :xStart, :float
add_column :annotations, :yStart, :float
add_column :annotations, :xEnd, :float
add_column :annotations, :yEnd, :float
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20140430233202_create_assignments.rb | db/migrate/20140430233202_create_assignments.rb | class CreateAssignments < ActiveRecord::Migration
def change
create_table :assignments do |t|
t.integer :user_id
t.integer :paper_id
t.string :role
t.integer :assignee_id
t.timestamps
end
add_index "assignments", ["user_id"], :name => "index_assignment_user_id"
add_index "assignments", ["paper_id"], :name => "index_assignment_paper_id"
add_index "assignments", ["role"], :name => "index_assignment_role"
add_index "assignments", ["assignee_id"], :name => "index_assignment_assignee_id"
end
end | ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20140212023345_create_comments.rb | db/migrate/20140212023345_create_comments.rb | class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.integer :user_id
t.integer :paper_id
t.string :state
t.integer :parent_id
t.string :category
t.text :body
t.timestamps
end
add_index "comments", ["user_id"], :name => "index_comment_user_id"
add_index "comments", ["paper_id"], :name => "index_comment_paper_id"
add_index "comments", ["state"], :name => "index_comment_state"
add_index "comments", ["parent_id"], :name => "index_comment_parent_id"
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20140609021717_add_sha_to_user.rb | db/migrate/20140609021717_add_sha_to_user.rb | class AddShaToUser < ActiveRecord::Migration
def change
add_column :users, :sha, :string
add_index :users, ["sha"]
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150404222351_remove.rb | db/migrate/20150404222351_remove.rb | class Remove < ActiveRecord::Migration
def up
execute <<-SQL
UPDATE Papers
SET state='submitted'
WHERE state='pending'
SQL
end
def down
execute <<-SQL
UPDATE Papers
SET state='pending'
WHERE state='submitted'
SQL
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150630032056_rename_to_document_location_and_authors.rb | db/migrate/20150630032056_rename_to_document_location_and_authors.rb | class RenameToDocumentLocationAndAuthors < ActiveRecord::Migration
def change
rename_column :papers, :location, :document_location
rename_column :papers, :author_list, :authors
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150607033009_remove_submitted_at_field.rb | db/migrate/20150607033009_remove_submitted_at_field.rb | class RemoveSubmittedAtField < ActiveRecord::Migration
def change
remove_column :papers, :submitted_at
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150808025904_add_complete_status_to_assignment.rb | db/migrate/20150808025904_add_complete_status_to_assignment.rb | class AddCompleteStatusToAssignment < ActiveRecord::Migration
def change
add_column :assignments, :reviewer_accept, :boolean, null:true, default:nil
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20140608024335_add_sha_to_paper.rb | db/migrate/20140608024335_add_sha_to_paper.rb | class AddShaToPaper < ActiveRecord::Migration
def change
add_column :papers, :sha, :string
add_index :papers, ["sha"]
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20140211223942_add_oauth_tokens_to_users.rb | db/migrate/20140211223942_add_oauth_tokens_to_users.rb | class AddOauthTokensToUsers < ActiveRecord::Migration
def change
add_column :users, :oauth_token, :string
add_column :users, :oauth_expires_at, :datetime
add_column :users, :extra, :text
add_column :users, :picture, :string
add_index :users, ["oauth_token"]
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/db/migrate/20150616041205_add_public_and_completed_to_assignments.rb | db/migrate/20150616041205_add_public_and_completed_to_assignments.rb | class AddPublicAndCompletedToAssignments < ActiveRecord::Migration
def change
add_column :assignments, :public, :boolean, null:false, default:false
add_column :assignments, :completed, :boolean, null:false, default:false
reversible do |dir|
dir.up do
Assignment.reset_column_information
Assignment.where(role:['editor','submittor','collaborator']).find_each do |a|
a.update_attributes(public:true)
end
end
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/rails_helper.rb | spec/rails_helper.rb | # This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'cancan/matchers'
require 'action_controller/serialization_test_case'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/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
# instead of true.
config.use_transactional_fixtures = true
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
config.include FactoryGirl::Syntax::Methods
config.include SpecHelpers
config.include ControllerSpecHelpers, type: :controller
config.include ActionController::SerializationAssertions, type: :controller
config.include Mail::Matchers
config.before(:each) do
allow(User).to receive(:next_editor).and_return(nil)
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/spec_helper.rb | spec/spec_helper.rb | # This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this
# file to always be loaded, without a need to explicitly require it in any files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, make a
# separate helper file that requires this one and then use it only in the specs
# that actually need it.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require "cancan/matchers"
RSpec.configure do |config|
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
# if config.files_to_run.one?
# # Use the documentation formatter for detailed output,
# # unless a formatter has already been configured
# # (e.g. via a command-line flag).
# config.default_formatter = 'doc'
# end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
expectations.syntax = :expect
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
mocks.syntax = :expect
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended.
mocks.verify_partial_doubles = true
end
end
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)
RSpec.configure do |config|
config.before(:each) do
stub_request(:any, /https\:\/\/theoj\.firebaseio.com\/.*/).to_return(:status => 200, :body => "", :headers => {})
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/support/spec_helpers.rb | spec/support/spec_helpers.rb | module SpecHelpers
def fixture_path
File.joing(__FILE__, '../../..', 'fixtures')
end
def fixture(filename)
filename = File.join(fixture_path, filename)
File.open(filename, 'r')
end
def fixture_text(filename)
fixture(filename).readlines.join
end
def hash_from_json(json)
return JSON.parse(json)
end
def set_paper_editor(user=nil)
if user.is_a?(Symbol)
user = create(user)
elsif user.nil?
user = create(:editor)
end
allow(User).to receive(:next_editor).and_return(user)
user
end
def deliveries
ActionMailer::Base.deliveries
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/support/has_sent_mail_patch.rb | spec/support/has_sent_mail_patch.rb |
# Existing matchers don't check multipart emails correctly
module Mail
module Matchers
class HasSentEmailMatcher
def matches_on_body?(delivery)
delivery.body == @body || delivery.body.encoded == @body
end
def matches_on_body_matcher?(delivery)
(@body_matcher.match delivery.body.raw_source) || (@body_matcher.match delivery.body.encoded)
end
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/support/controller_spec_helpers.rb | spec/support/controller_spec_helpers.rb | require 'active_support/concern'
module ControllerSpecHelpers
extend ActiveSupport::Concern
attr_reader :current_user
def authenticate(user=nil)
if user.is_a?(Symbol)
user = create(user)
elsif user.nil?
user = create(:user)
end
allow(controller).to receive(:current_user).and_return(user)
@current_user = user
end
def not_authenticated!
allow(controller).to receive(:current_user).and_return(nil)
@current_user = nil
end
def response_json
@response_json ||= JSON.parse( response.body )
end
def error_json(status_code)
code = Rack::Utils::SYMBOL_TO_STATUS_CODE[status_code]
message = "#{code} #{Rack::Utils::HTTP_STATUS_CODES[code]}"
{"error" => message, "text" => nil, "code" => code}
end
# Add default params
def process_with_default_params(action, method, parameters={}, *rest)
process_without_default_params(action, method, default_params.merge(parameters || {}), *rest)
end
included do
let(:default_params) { {format:'json'} }
alias_method_chain :process, :default_params
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/serializers/basic_paper_serializer_spec.rb | spec/serializers/basic_paper_serializer_spec.rb | require "rails_helper"
describe BasicPaperSerializer do
it "should initialize properly" do
paper = build(:paper, document_location:"https://example.com", title:"Teh awesomeness")
serializer = BasicPaperSerializer.new(paper)
hash = hash_from_json(serializer.to_json)
expect(hash.keys).to contain_exactly('typed_provider_id',
'version')
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/serializers/public_user_serializer_spec.rb | spec/serializers/public_user_serializer_spec.rb | require "rails_helper"
describe PublicUserSerializer do
it "should have the correct keys" do
user = create(:user)
serializer = PublicUserSerializer.new(user)
hash = hash_from_json(serializer.to_json)
expect(hash.keys).to contain_exactly("name", "email", "created_at", "picture", "sha")
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/serializers/authenticated_user_serializer_spec.rb | spec/serializers/authenticated_user_serializer_spec.rb | require "rails_helper"
describe AuthenticatedUserSerializer do
it "should have the correct keys" do
user = create(:user)
serializer = AuthenticatedUserSerializer.new(user)
hash = hash_from_json(serializer.to_json)
expect(hash.keys).to contain_exactly("name", "email",
"created_at", "picture", "sha",
"has_papers_as_submittor", "has_papers_as_reviewer", "has_papers_as_editor",
"editor", "admin")
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/serializers/assignment_serializer_spec.rb | spec/serializers/assignment_serializer_spec.rb | require "rails_helper"
describe AssignmentSerializer do
it "should initialize properly" do
assignment = create(:assignment)
serializer = AssignmentSerializer.new(assignment)
hash = hash_from_json(serializer.to_json)
expect(hash.keys).to contain_exactly('role', 'sha', 'user', 'public')
end
it "A reviewer should include the completed field" do
assignment = create(:assignment, :reviewer)
serializer = AssignmentSerializer.new(assignment)
hash = hash_from_json(serializer.to_json)
expect(hash.keys).to contain_exactly('role', 'sha', 'completed', 'public')
end
it "A reviewer should include the reviewer_accept field when completed" do
assignment = create(:assignment, :reviewer, completed:true, reviewer_accept:'accept_with_minor')
serializer = AssignmentSerializer.new(assignment)
hash = hash_from_json(serializer.to_json)
expect(hash.keys).to include('reviewer_accept')
end
it "Non-reviewers should not include the completed field" do
assignment = create(:assignment, :editor)
serializer = AssignmentSerializer.new(assignment)
hash = hash_from_json(serializer.to_json)
expect(hash).not_to include('completed')
end
it "should include user info based on the role when no user is logged in" do
user = create(:user, name:'John Doe')
assignment = create(:assignment, user:user, role:'submittor')
serializer = AssignmentSerializer.new(assignment)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to include('name' => 'John Doe')
assignment = create(:assignment, user:user, role:'collaborator')
serializer = AssignmentSerializer.new(assignment)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to include('name' => 'John Doe')
assignment = create(:assignment, user:user, role:'editor')
serializer = AssignmentSerializer.new(assignment)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to include('name' => 'John Doe')
assignment = create(:assignment, user:user, role:'reviewer')
serializer = AssignmentSerializer.new(assignment)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to be_nil
end
it "should include user info based on the role when a normal user is logged in" do
current_user = create(:user)
user = create(:user, name:'John Doe')
assignment = create(:assignment, user:user, role:'submittor')
serializer = AssignmentSerializer.new(assignment, scope:current_user)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to include('name' => 'John Doe')
assignment = create(:assignment, user:user, role:'collaborator')
serializer = AssignmentSerializer.new(assignment, scope:current_user)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to include('name' => 'John Doe')
assignment = create(:assignment, user:user, role:'editor')
serializer = AssignmentSerializer.new(assignment, scope:current_user)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to include('name' => 'John Doe')
assignment = create(:assignment, user:user, role:'reviewer')
serializer = AssignmentSerializer.new(assignment, scope:current_user)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to be_nil
end
it "should include reviewer info when the editor is logged in" do
current_user = set_paper_editor
user = create(:user, name:'John Doe')
assignment = create(:assignment, :reviewer, user:user)
serializer = AssignmentSerializer.new(assignment, scope:current_user)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to include('name' => 'John Doe')
end
it "should include reviewer info when the reviewer is logged in" do
user = create(:user, name:'John Doe')
assignment = create(:assignment, :reviewer, user:user)
serializer = AssignmentSerializer.new(assignment, scope:user)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to include('name' => 'John Doe')
end
it "should include reviewer info when the assignment is made public" do
current_user = create(:user)
user = create(:user, name:'John Doe')
assignment = create(:assignment, user:user, role:'reviewer')
serializer = AssignmentSerializer.new(assignment, scope:current_user)
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to be_nil
assignment.public = true
hash = hash_from_json(serializer.to_json)
expect(hash['user']).to include('name' => 'John Doe')
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/serializers/basic_user_serializer_spec.rb | spec/serializers/basic_user_serializer_spec.rb | require "rails_helper"
describe BasicUserSerializer do
it "should have the correct keys" do
user = create(:user)
serializer = BasicUserSerializer.new(user)
hash = hash_from_json(serializer.to_json)
expect(hash.keys).to contain_exactly('name')
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/serializers/paper_serializer_spec.rb | spec/serializers/paper_serializer_spec.rb | require "rails_helper"
describe PaperSerializer do
it "should serialize properly" do
user = create(:user)
paper = build(:paper, document_location:"https://example.com", title:"Teh awesomeness", submittor:user)
serializer = PaperSerializer.new(paper)
hash = hash_from_json(serializer.to_json)
expect(hash.keys).to contain_exactly('typed_provider_id',
'user_permissions',
'state',
'submitted_at',
'title',
'pending_issues_count',
'submittor',
'doi',
'authors'
)
end
it "should serialize the submittor properly" do
user = create(:user)
paper = build(:paper, submittor:user)
serializer = PaperSerializer.new(paper)
hash = hash_from_json(serializer.to_json)
expect(hash['submittor'].keys).to contain_exactly("name")
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/serializers/full_paper_serializer_spec.rb | spec/serializers/full_paper_serializer_spec.rb | require "rails_helper"
describe FullPaperSerializer do
it "should initialize properly" do
user = create(:user)
paper = create(:paper, document_location:"https://example.com", title:"Teh awesomeness", submittor:user)
serializer = FullPaperSerializer.new(paper)
hash = hash_from_json(serializer.to_json)
expect(hash.keys).to contain_exactly("paper_id",
"typed_provider_id",
"user_permissions",
"document_location",
"state",
"submitted_at",
"authors",
"title",
"pending_issues_count",
"submittor",
"assigned_users",
"doi",
"versions" )
end
it "should serialize a list of assignments" do
set_paper_editor create(:editor, name:'An Editor')
paper = create(:paper, submittor:create(:user, name:'The Submittor'), reviewer:create(:user,name:'The Reviewer') )
serializer = FullPaperSerializer.new(paper)
assignments = hash_from_json(serializer.to_json)['assigned_users']
expect(assignments[0]['role']).to eq('editor')
expect(assignments[0]['user']['name']).to eq('An Editor')
expect(assignments[1]['role']).to eq('submittor')
expect(assignments[1]['user']['name']).to eq('The Submittor')
expect(assignments[2]['role']).to eq('reviewer')
expect(assignments[2]['user']).to be_nil
end
it "should serialize a list of versions" do
paper1 = create(:paper, arxiv_id:'1111.2222', version:1 )
paper2 = create(:paper, arxiv_id:'1111.2222', version:2 )
paper3 = create(:paper, arxiv_id:'1111.2222', version:3 )
serializer = FullPaperSerializer.new(paper2)
versions = hash_from_json(serializer.to_json)['versions']
expect(versions[0]['typed_provider_id']).to eq('arxiv:1111.2222v3')
expect(versions[1]['typed_provider_id']).to eq('arxiv:1111.2222v2')
expect(versions[2]['typed_provider_id']).to eq('arxiv:1111.2222v1')
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/serializers/annotation_serializer_spec.rb | spec/serializers/annotation_serializer_spec.rb | require "rails_helper"
describe AnnotationSerializer do
it "should initialize properly" do
annotation = create(:annotation)
serializer = AnnotationSerializer.new(annotation)
hash = hash_from_json(serializer.to_json)
expect(hash).to include('id', 'paper_id', 'state', 'parent_id',
'body', 'assignment', 'created_at',
'page', 'xStart', 'xEnd', 'yStart', 'yEnd')
end
it "should serialize the assignment as a sha" do
annotation = create(:annotation)
serializer = AnnotationSerializer.new(annotation)
hash = hash_from_json(serializer.to_json)
expect(hash['assignment']).to eq(annotation.assignment.sha)
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/serializers/preview_paper_serializer_spec.rb | spec/serializers/preview_paper_serializer_spec.rb | require "rails_helper"
describe PreviewPaperSerializer do
it "should initialize properly" do
current_user = create(:user)
user = create(:user)
paper = build(:paper, document_location:"https://example.com", title:"Teh awesomeness", submittor:user)
serializer = PreviewPaperSerializer.new(paper, scope:current_user)
hash = hash_from_json(serializer.to_json)
expect(hash.keys).to contain_exactly("typed_provider_id",
"document_location",
"title",
"summary",
"authors",
"is_existing",
"is_self_owned")
end
context "self_owned field" do
it "should be false if the current_user is not the owner" do
current_user = create(:user)
user = create(:user)
paper = create(:paper, submittor:user)
serializer = PreviewPaperSerializer.new(paper, scope:current_user)
hash = hash_from_json(serializer.to_json)
expect(hash['is_self_owned']).to eq(false)
end
it "should be false if the current_user is the owner" do
current_user = create(:user)
paper = create(:paper, submittor:current_user)
serializer = PreviewPaperSerializer.new(paper, scope:current_user)
hash = hash_from_json(serializer.to_json)
expect(hash['is_self_owned']).to eq(true)
end
end
context "is_existing field" do
it "should be true if the paper is saved" do
paper = create(:paper)
serializer = PreviewPaperSerializer.new(paper)
hash = hash_from_json(serializer.to_json)
expect(hash['is_existing']).to eq(true)
end
it "should be false if the paper is not saved" do
paper = build(:paper)
serializer = PreviewPaperSerializer.new(paper)
hash = hash_from_json(serializer.to_json)
expect(hash['is_existing']).to eq(false)
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/factories/annotation.rb | spec/factories/annotation.rb | FactoryGirl.define do
factory :annotation do
body "You know, this really isn't good enough"
created_at { Time.now }
updated_at { Time.now }
ignore do
user nil
paper nil
parent nil
state nil
end
factory :root, aliases:[:issue]
factory :response do
after(:build) do |a, factory| a.parent ||= factory.association(:root, paper:a.paper) end
end
trait :unresolved do
state :unresolved
end
trait :resolved do
state :resolved
end
trait :disputed do
state :disputed
end
after(:build) do |a, factory|
if factory.paper
a.paper = factory.paper
elsif factory.parent
a.paper = factory.parent.paper
else
a.paper = factory.association(:paper)
end
case factory.state
when nil then ;
when :unresolved then a.unresolve
when :resolved then a.resolve
when :disputed then a.dispute
else raise "Missing state in factory"
end
# Do this after setting the state
a.parent = factory.parent
if factory.user
assignment = a.paper.assignments.detect { |pa| pa.user == factory.user } if a.paper
a.assignment = assignment || factory.association(:assignment, :collaborator, paper:a.paper, user:factory.user)
elsif a.paper
a.assignment = a.paper.assignments.last
else
user = create(:user)
a.assignment = factory.association(:assignment, :collaborator, paper:a.paper, user:user)
end
end
before(:create) do |a, factory|
if factory.user
a.paper.assignments.reload
end
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/factories/assignment.rb | spec/factories/assignment.rb | FactoryGirl.define do
factory :assignment do
user
paper
role 'collaborator'
created_at { Time.now }
updated_at { Time.now }
trait :collaborator do
role 'collaborator'
end
trait :reviewer do
role 'reviewer'
end
trait :editor do
role 'editor'
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/factories/paper.rb | spec/factories/paper.rb | FactoryGirl.define do
factory :paper do
document_location "https://example.com/1234"
state "submitted"
title "My awesome paper"
summary "Summary of my awesome paper"
authors "John Smith, Paul Adams, Ella Fitzgerald"
association :submittor, factory: :user
provider_type 'test'
provider_id { SecureRandom.hex }
version 1
created_at { Time.now }
updated_at { Time.now }
Paper.aasm.states.each do |s|
trait s.name do state s.name end
end
ignore do
editor nil
reviewer nil
collaborator nil
arxiv_id nil
end
after(:build) do |paper, factory|
if factory.arxiv_id
parsed = Provider::ArxivProvider.parse_identifier(factory.arxiv_id)
paper.provider_type = 'arxiv'
paper.provider_id = parsed[:provider_id]
paper.version = parsed[:version] if parsed[:version].present?
end
if factory.editor
editors = Array(factory.editor==true ? create(:user) : factory.editor)
editors.each do |e|
paper.assignments.build(role: :editor, user:e)
end
end
paper.send(:create_assignments) if paper.submittor
if factory.collaborator
collaborators = Array(factory.collaborator==true ? create(:user) : factory.collaborator)
collaborators.each do |c|
paper.assignments.build(role: :collaborator, user:c)
end
end
if factory.reviewer
reviewers = Array(factory.reviewer==true ? create(:user) : factory.reviewer)
reviewers.each do |r|
paper.assignments.build(role: :reviewer, user:r)
end
end
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/factories/user.rb | spec/factories/user.rb | FactoryGirl.define do
factory :user do
provider 'orcid'
name 'John Doe'
created_at { Time.now }
admin false
editor false
factory :admin do
name 'John Admin'
admin true
end
factory :editor do
name 'John the Editor'
editor true
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/controllers/sessions_controller_spec.rb | spec/controllers/sessions_controller_spec.rb | require "rails_helper"
describe SessionsController do
describe "#orcid_name_for" do
it "queries the ORCID API for the username based upon the ORCID ID" do
stub_request(:get, "https://pub.orcid.org/v1.1/0000-0001-7857-2795/orcid-bio").
with(headers: {'Accept'=>'application/orcid+json'}).
to_return(status: 200,
body: '{ "message-version":"1.1",
"orcid-profile":{
"orcid":null,
"orcid-identifier":{"value":null,
"uri":"https://sandbox-1.orcid.org/0000-0001-7857-2795",
"path":"0000-0001-7857-2795",
"host":"sandbox-1.orcid.org" },
"orcid-preferences":{ "locale":"EN" },
"orcid-history":{
"creation-method":"WEBSITE",
"submission-date":{ "value":1359385939842 },
"last-modified-date":{ "value":1386071959680 },
"claimed":{ "value":true },
"source":null,
"visibility":null
},
"orcid-bio":{
"personal-details":{ "given-names":{ "value":"Albert" }, "family-name":{ "value":"Einstein"} },
"biography":{ "value":"", "visibility":null },
"keywords":null,
"delegation":null,
"applications":null,
"scope":null
},
"type":"USER",
"group-type":null,
"client-type":null
}
}',
headers: {})
user = create(:user, :uid => '0000-0001-7857-2795')
expect(controller.send(:orcid_name_for, user.uid)).to eq("Albert Einstein")
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/controllers/admin_controller_spec.rb | spec/controllers/admin_controller_spec.rb | require "rails_helper"
describe AdminController do
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/controllers/home_controller_spec.rb | spec/controllers/home_controller_spec.rb | require "rails_helper"
describe HomeController do
# Testing all the things
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/controllers/papers_controller_spec.rb | spec/controllers/papers_controller_spec.rb | require "rails_helper"
describe PapersController do
describe "GET #badge" do
render_views
it "WITHOUT USER responds successfully with an HTTP 200 status code and response" do
paper = create(:paper, :review_completed)
get :badge, identifier:paper.typed_provider_id, format:'html'
expect(response).to have_http_status(:success)
expect(response.content_type).to eq("text/html")
expect(response.body).to include('completed.svg')
end
it "WITHOUT USER responds successfully with an HTTP 200 status code and JSON response" do
paper = create(:paper, :review_completed)
get :badge, identifier:paper.typed_provider_id, format:'json'
expect(response).to have_http_status(:success)
expect(response.content_type).to eq("application/json")
expect(response_json).to eq('state'=>'review_completed')
end
it "Sets an eTag" do
paper = create(:paper, :review_completed)
get :badge, identifier:paper.typed_provider_id
expect( response.header['ETag'] ).to be_present
end
it "Returns 304 if an etag is set" do
paper = create(:paper, :review_completed)
get :badge, identifier:paper.typed_provider_id
etag1 = response['ETag']
request.headers['If-None-Match'] = etag1
get :badge, identifier:paper.typed_provider_id
expect(response).to have_http_status(:not_modified)
expect(response.content_type).to eq("application/json")
expect(response.body).to be_blank
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/controllers/feed_controller_spec.rb | spec/controllers/feed_controller_spec.rb | require "rails_helper"
describe FeedController do
describe 'GET #arxiv' do
let(:a_date) { Time.new(2015, 1, 2, 12, 4, 5) }
def create_paper(attributes={})
attributes = {
state: 'published',
provider_type: 'arxiv',
created_at: a_date
}.merge(attributes)
create(:paper, attributes)
end
before do
allow(controller).to receive(:render).and_call_original
end
def expect_papers(expected)
expect(controller).to have_received(:render) do |name, options|
expect(options[:locals][:papers]).to eq(expected)
end
end
it 'should return xml' do
get :arxiv, format: 'xml'
expect(response).to have_http_status(:ok)
expect(response.content_type).to eq 'application/xml'
expect(response).to render_template('arxiv')
end
it 'should include a list of paper attributes' do
create_paper(doi:'doi-01', provider_id:'0000.0001')
create_paper(doi:'doi-02', provider_id:'0000.0002')
create_paper(doi:'doi-03', provider_id:'0000.0003')
get :arxiv, format: 'xml'
expect_papers [
{ preprint_id: 'arXiv:0000.0001',
doi: 'doi-01',
journal_ref: 'The Open Journal of Astrophysics, 2015' },
{ preprint_id: 'arXiv:0000.0002',
doi: 'doi-02',
journal_ref: 'The Open Journal of Astrophysics, 2015' },
{ preprint_id: 'arXiv:0000.0003',
doi: 'doi-03',
journal_ref: 'The Open Journal of Astrophysics, 2015' }
]
end
it 'should only include published papers' do
create_paper(doi:'doi-01', provider_id:'0000.0001')
create_paper(doi:'doi-02', provider_id:'0000.0002', state:'accepted')
create_paper(doi:'doi-03', provider_id:'0000.0003')
get :arxiv, format: 'xml'
expect_papers [
{ preprint_id: 'arXiv:0000.0001',
doi: 'doi-01',
journal_ref: 'The Open Journal of Astrophysics, 2015' },
{ preprint_id: 'arXiv:0000.0003',
doi: 'doi-03',
journal_ref: 'The Open Journal of Astrophysics, 2015' }
]
end
it 'should only include Arxiv papers' do
create_paper(doi:'doi-01', provider_id:'0000.0001')
create_paper(doi:'doi-02', provider_id:'0000.0002', provider_type:'test')
create_paper(doi:'doi-03', provider_id:'0000.0003')
get :arxiv, format: 'xml'
expect_papers [
{ preprint_id: 'arXiv:0000.0001',
doi: 'doi-01',
journal_ref: 'The Open Journal of Astrophysics, 2015' },
{ preprint_id: 'arXiv:0000.0003',
doi: 'doi-03',
journal_ref: 'The Open Journal of Astrophysics, 2015' }
]
end
it 'should only recent papers' do
create_paper(doi:'doi-01', provider_id:'0000.0001', updated_at: Time.now)
create_paper(doi:'doi-02', provider_id:'0000.0002', updated_at: 3.months.ago - 1.day)
create_paper(doi:'doi-03', provider_id:'0000.0003', updated_at: 3.months.ago)
get :arxiv, format: 'xml'
expect_papers [
{ preprint_id: 'arXiv:0000.0001',
doi: 'doi-01',
journal_ref: 'The Open Journal of Astrophysics, 2015' },
{ preprint_id: 'arXiv:0000.0003',
doi: 'doi-03',
journal_ref: 'The Open Journal of Astrophysics, 2015' }
]
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/controllers/api/v1/users_controller_spec.rb | spec/controllers/api/v1/users_controller_spec.rb | require "rails_helper"
describe Api::V1::UsersController do
describe "GET #show" do
context "when no user is authenticated" do
it "responds successfully with an HTTP 200 status code" do
get :show, :format => :json
expect(response).to have_http_status(:ok)
end
it "should return an empty object" do
get :show, :format => :json
expect( response_json ).to be_empty
end
end
context "when no user is authenticated" do
it "responds successfully with an HTTP 200 status code" do
user = authenticate
get :show, :format => :json
expect(response).to have_http_status(:ok)
end
it "should return the users details" do
user = authenticate
get :show, :format => :json
expect( response_json["name"] ).to eq(user.name)
expect( response_json["email"]).to eq(user.email)
end
context "when user has papers and assignments" do
it "should have the correct attributes" do
user = authenticate
paper = create(:paper)
create(:assignment, :reviewer, user:user, paper:paper)
get :show, :format => :json
expect(response).to have_http_status(:success)
expect(response.status).to eq(200)
hash = response_json
assert_equal hash["name"], user.name
end
end
end
end
describe "PUT #update" do
it "should fail if the user is not authenticated" do
put :update
expect(response).to have_http_status(:unauthorized)
end
it "should succeed" do
user = authenticate
put :update, format: :json, user:{ email:'1@2.com' }
expect(response).to have_http_status(:ok)
end
it "should change the user's attributes" do
user = authenticate
put :update, format: :json, user:{ email:'1@2.com' }
expect(user.reload.email).to eq('1@2.com')
end
it "should render a user" do
user = authenticate
put :update, format: :json, user:{ email:'1@2.com'}
expect(response_json['name']).to eq(user.name)
expect(response_json['email']).to eq('1@2.com')
end
it "should not change unexpected parameters" do
user = authenticate
put :update, format: :json, user:{ picture: '123' }
expect(user.reload.picture).not_to eq('123')
end
it "should not change invalid parameters" do
user = authenticate
put :update, format: :json, user:{ email: '123' }
expect(response).to have_http_status(:unprocessable_entity)
end
end
describe "GET #lookup" do
it "requires the user to be authenticated as an editor" do
get :lookup, :guess => "Scooby", :format => :json
expect(response).to have_http_status(:unauthorized)
authenticate(:user)
get :lookup, :guess => "Scooby", :format => :json
expect(response).to have_http_status(:forbidden)
authenticate(:editor)
get :lookup, :guess => "Scooby", :format => :json
expect(response).to have_http_status(:success)
end
it "responds successfully with an HTTP 200 status code and some users" do
authenticate(:editor)
user = create(:user, name:'Scooby doo')
get :lookup, :guess => "Scooby", :format => :json
expect(response).to have_http_status(:success)
expect(response.status).to eq(200)
# FIXME - this hash structure is kinda silly
assert_equal response_json.first["sha"], user.sha
end
it "responds successfully with an HTTP 200 status code and no users" do
authenticate(:editor)
get :lookup, :guess => "blah", :format => :json
expect(response).to have_http_status(:success)
expect(response.status).to eq(200)
assert response_json.empty?
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/controllers/api/v1/papers_controller_spec.rb | spec/controllers/api/v1/papers_controller_spec.rb | require "rails_helper"
describe Api::V1::PapersController do
let(:arxiv_doc) {
{
provider_type: :arxiv,
provider_id: "1311.1653",
version: 2,
authors: "Mar Álvarez-Álvarez, Angeles I. Díaz",
document_location: "https://arxiv.org/pdf/1311.1653v2.pdf",
title: "A photometric comprehensive study of circumnuclear star forming rings: the sample",
summary: "We present photometry.*in a second paper."
}
}
describe "GET #show" do
it "AS REVIEWER (with permissions)" do
user = authenticate
paper = create(:paper, :under_review)
create(:assignment, :reviewer, paper:paper, user:user)
get :show, identifier:paper.typed_provider_id
expect(response).to have_http_status(:success)
expect(response.status).to eq(200)
expect(response.content_type).to eq("application/json")
assert_serializer FullPaperSerializer
end
it "AS COLLABORATOR (with permissions)" do
user = authenticate
paper = create(:paper, :under_review)
create(:assignment, :collaborator, paper:paper, user:user)
get :show, identifier:paper.typed_provider_id
expect(response).to have_http_status(:success)
expect(response.status).to eq(200)
expect(response.content_type).to eq("application/json")
assert_serializer FullPaperSerializer
end
it "AS AUTHOR (with permissions)" do
user = authenticate
paper = create(:paper, :under_review, submittor:user)
get :show, identifier:paper.typed_provider_id
expect(response).to have_http_status(:success)
expect(response.status).to eq(200)
expect(response.content_type).to eq("application/json")
assert_serializer FullPaperSerializer
end
it "AS USER (without permissions)" do
user = authenticate
paper = create(:paper, :under_review)
get :show, identifier:paper.typed_provider_id
expect(response).to have_http_status(:success)
expect(response.status).to eq(200)
expect(response.content_type).to eq("application/json")
assert_serializer FullPaperSerializer
end
it "AS UNAUTHENTICATED USER" do
paper = create(:paper, :under_review)
get :show, identifier:paper.typed_provider_id
expect(response).to have_http_status(:success)
expect(response.status).to eq(200)
expect(response.content_type).to eq("application/json")
assert_serializer FullPaperSerializer
end
end
describe "GET #preview" do
it "should fail if no user is logged in" do
expect(Provider::TestProvider).not_to receive(:get_attributes)
get :preview, identifier:'test:1234.5678'
expect(response).to have_http_status(:unauthorized)
expect(response_json).to eq(error_json(:unauthorized))
end
it "should attempt to fetch the response from the database" do
authenticate
paper = build(:paper, provider_id:'6fd60602a51d2b16b8a3c9cd33d2d22b')
expect(Paper).to receive(:for_identifier).with('test:1234.5678').and_return( paper )
expect(Provider::TestProvider).not_to receive(:get_attributes)
get :preview, identifier:'test:1234.5678'
expect(response).to have_http_status(:success)
expect(response.content_type).to eq("application/json")
assert_serializer PreviewPaperSerializer
expect(response_json).to include("typed_provider_id" => "test:6fd60602a51d2b16b8a3c9cd33d2d22b-1",
"document_location" => "https://example.com/1234",
"authors" => "John Smith, Paul Adams, Ella Fitzgerald",
"summary" => "Summary of my awesome paper",
"title" => "My awesome paper"
)
end
it "should return a true is_existing field if the response is from the database" do
authenticate
paper = create(:paper)
expect(Paper).to receive(:for_identifier).with('test:1234.5678').and_return(paper)
get :preview, identifier:'test:1234.5678'
expect(response_json).to include("is_existing" => true)
end
it "should return a true self_owned field if you are the submittor" do
user = authenticate
paper = create(:paper, submittor:user )
expect(Paper).to receive(:for_identifier).with('test:1234.5678').and_return(paper)
get :preview, identifier:'test:1234.5678'
expect(response_json).to include("is_self_owned" => true)
end
it "should return a false self_owned field if you are not the submittor" do
user = authenticate
paper = create(:paper, submittor:create(:user) )
expect(Paper).to receive(:for_identifier).with('test:1234.5678').and_return(paper)
get :preview, identifier:'test:1234.5678'
expect(response_json).to include("is_self_owned" => false)
end
it "should fetch the paper if it is not in the database" do
authenticate
expect(Paper).to receive(:for_identifier).and_return(nil)
expect(Provider::ArxivProvider).to receive(:get_attributes).with('1311.1653').and_return(arxiv_doc)
get :preview, identifier:'arxiv:1311.1653'
expect(response).to have_http_status(:success)
expect(response.content_type).to eq("application/json")
assert_serializer PreviewPaperSerializer
expect(response_json).to include("typed_provider_id" => "arxiv:1311.1653v2",
"document_location" => "https://arxiv.org/pdf/1311.1653v2.pdf",
"authors" => "Mar Álvarez-Álvarez, Angeles I. Díaz",
"summary" => "We present photometry.*in a second paper.",
"title" => "A photometric comprehensive study of circumnuclear star forming rings: the sample"
)
end
it "should return a false is_existing field if the response is not from the database" do
authenticate
expect(Paper).to receive(:for_identifier).and_return(nil)
expect(Provider::TestProvider).to receive(:get_attributes).with('1234.5678').and_return(arxiv_doc)
get :preview, identifier:'test:1234.5678'
expect(response_json).to include("is_existing" => false)
end
it "should return a 404 if the paper is not found on Arxiv or the DB" do
authenticate
expect(Paper).to receive(:for_identifier).and_return(nil)
expect(Provider::TestProvider).to receive(:get_attributes).and_raise(Provider::Error::DocumentNotFound)
get :preview, identifier:'test:1234.5678'
expect(response).to have_http_status(:not_found)
end
end
describe "POST #create" do
before do
allow(Provider).to receive(:get_attributes).with('arxiv:1311.1653').and_return(arxiv_doc)
end
it "should create the paper" do
authenticate
expect {
post :create, identifier:'arxiv:1311.1653'
}.to change{Paper.count}.by(1)
new = Paper.last
expect( new.typed_provider_id ).to eq('arxiv:1311.1653v2')
end
it "should retrieve the Arxiv data" do
expect(Provider).to receive(:get_attributes).with('arxiv:1311.1653').and_return(arxiv_doc)
authenticate
post :create, identifier:'arxiv:1311.1653'
new = Paper.last
expect( new.title).to start_with('A photometric comprehensive study')
end
it "should set the papers submittor" do
authenticate
post :create, identifier:'arxiv:1311.1653'
new = Paper.last
expect( new.submittor ).to eq(current_user)
end
it "should return a created status code" do
authenticate
post :create, identifier:'arxiv:1311.1653'
expect(response).to have_http_status(:created)
end
it "should return a created document" do
authenticate
post :create, identifier:'arxiv:1311.1653'
assert_serializer PaperSerializer
expect(response_json).to include(
"typed_provider_id" => "arxiv:1311.1653v2",
"state" => "submitted"
)
end
it "should fail if the user is not authenticated" do
post :create, identifier:'arxiv:1311.1653'
expect(response).to have_http_status(:unauthorized)
end
end
# describe "PUT #update" do
#
# it "AS AUTHOR on submitted paper should change title" do
# user = authenticate
# paper = create(:paper, submittor:user)
#
# put :update, identifier:paper.typed_provider_id, paper:{ title:"Boo ya!"}
#
# expect(response).to have_http_status(:success)
# assert_equal response_json["title"], "Boo ya!"
# end
#
# it "AS AUTHOR responds on submitted paper should not change title" do
# user = authenticate
# paper = create(:paper, :submitted, submittor:user, title:'Hello space')
#
# put :update, identifier:paper.typed_provider_id, paper:{ title:"Boo ya!"}
#
# expect(response.status).to eq(:forbidden)
# assert_equal "Hello space", paper.title
# end
#
# end
describe "DELETE #destroy" do
it "should delete the paper" do
user = authenticate(:editor)
paper = create(:paper)
delete :destroy, identifier:paper.typed_provider_id
expect( Paper.find_by_id(paper.id)).to be_nil
end
it "should return the correct html and status code" do
user = authenticate(:editor)
paper = create(:paper)
delete :destroy, identifier:paper.typed_provider_id
expect(response).to have_http_status(:success)
end
it "should delete all versions of the paper" do
user = authenticate(:editor)
original = create(:paper, arxiv_id:'1311.1653', version:1)
updated = original.create_updated!(arxiv_doc)
delete :destroy, identifier:updated.typed_provider_id
expect( Paper.find_by_id(original.id)).to be_nil
expect( Paper.find_by_id(updated.id)).to be_nil
end
it "should fail if the paper is not in the submitted state" do
user = authenticate(:editor)
paper = create(:paper, :under_review)
delete :destroy, identifier:paper.typed_provider_id
expect(response).to have_http_status(:unprocessable_entity)
expect( Paper.find_by_id(paper.id)).not_to be_nil
end
it "should fail if the user is not an editor" do
user = authenticate(:user)
paper = create(:paper, submittor:user)
delete :destroy, identifier:paper.typed_provider_id
expect(response).to have_http_status(:forbidden)
expect( Paper.find_by_id(paper.id)).not_to be_nil
end
end
describe "PUT #transition" do
it "AS EDITOR responds successfully with a correct status and accept paper" do
editor = authenticate(:editor)
paper = create(:paper, :review_completed, editor: editor)
put :transition, identifier:paper.typed_provider_id, transition: :accept
expect(response).to have_http_status(:success)
assert_equal response_json["state"], "accepted"
end
it "AS EDITOR responds with an unprocessable entity for an invalid transition" do
editor = authenticate(:editor)
paper = create(:paper, :submitted, editor: editor)
put :transition, identifier:paper.typed_provider_id, transition: :accept
expect(response).to have_http_status(:unprocessable_entity)
end
it "AS USER responds successfully with a correct status (403) and NOT accept paper" do
authenticate
paper = create(:paper, :under_review)
put :transition, identifier:paper.typed_provider_id, transition: :accept
# Should be redirected
expect(response).to have_http_status(:forbidden)
end
it "AS AUTHOR responds successfully with a correct status (403) and NOT accept paper" do
user = authenticate
paper = create(:paper, :under_review, submittor:user)
put :transition, identifier:paper.typed_provider_id, transition: :accept
expect(response).to have_http_status(:forbidden)
expect(response_json).to eq(error_json(:forbidden))
end
end
describe "POST #complete" do
it "responds successfully with a correct status and paper" do
user = authenticate
paper = create(:paper, :under_review, reviewer:user)
post :complete, identifier:paper.typed_provider_id, result:'accept_with_minor'
expect(response).to have_http_status(:success)
expect(response_json["state"]).to eq("review_completed")
expect(response_json['assigned_users'].second['completed']).to be_truthy
end
it "updates the assignment and paper" do
user = authenticate
paper = create(:paper, :under_review, reviewer:user)
post :complete, identifier:paper.typed_provider_id, result:'accept_with_major'
expect(paper.reviewer_assignments.reload.first.completed).to be_truthy
end
context "updates the reviewer_accept field correctly" do
def test(accept_value)
user = authenticate
paper = create(:paper, :under_review, reviewer:user)
post :complete, identifier:paper.typed_provider_id, result: accept_value
expect(paper.reviewer_assignments.reload.first.reviewer_accept).to eq(accept_value)
expect(paper.reviewer_assignments.reload.first.completed).to be_truthy
end
it "should work for accept" do test('accept') end
it "should work for accept_with_minor" do test('accept_with_minor') end
it "should work for accept_with_major" do test('accept_with_major') end
it "should work for reject" do test('reject') end
end
it "adds a comment annotation" do
user = authenticate
paper = create(:paper, :under_review, reviewer:user)
post :complete, identifier:paper.typed_provider_id, result:'accept_with_major', comments:'some comment'
expect(paper.annotations.first.body).to eq('some comment')
end
it "doesn't add an unncessary annotation" do
user = authenticate
paper = create(:paper, :under_review, reviewer:user)
post :complete, identifier:paper.typed_provider_id, result:'accept_with_major'
expect(paper.annotations.reload).to be_empty
post :complete, identifier:paper.typed_provider_id, result:'accept_with_major', comments:' '
expect(paper.annotations.reload).to be_empty
end
it "should fail if the user is not authorized" do
user = authenticate
paper = create(:paper, :under_review, reviewer:true)
post :complete, identifier:paper.typed_provider_id, accept:true
expect(response).to have_http_status(:forbidden)
end
it "should fail if the result field isn't provided" do
user = authenticate
paper = create(:paper, :under_review, reviewer:user)
post :complete, identifier:paper.typed_provider_id
expect(response).to have_http_status(:bad_request)
expect(response_json['text']).to eq('accept parameter not supplied')
end
it "should fail if the paper isn't under review" do
user = authenticate
paper = create(:paper, :accepted, reviewer:user)
post :complete, identifier:paper.typed_provider_id
expect(response).to have_http_status(:unprocessable_entity)
end
end
describe "POST or DELETE #public" do
context "with a POST" do
it "it responds successfully with a correct status and paper" do
user = authenticate
paper = create(:paper, reviewer:user)
post :public, identifier:paper.typed_provider_id
expect(response).to have_http_status(:success)
expect(response_json['assigned_users'].last['public']).to be_truthy
end
it "updates the assignment and paper" do
user = authenticate
paper = create(:paper, :under_review, reviewer:user)
post :public, identifier:paper.typed_provider_id
expect(paper.reviewer_assignments.reload.last.public).to be_truthy
end
end
context "with a DELETE" do
it "it responds successfully with a correct status and paper" do
user = authenticate
paper = create(:paper, reviewer:user)
paper.reviewer_assignments.last.update_attributes(public:true)
delete :public, identifier:paper.typed_provider_id
expect(response).to have_http_status(:success)
expect(response_json['assigned_users'].last['public']).to be_falsy
end
it "updates the assignment and paper" do
user = authenticate
paper = create(:paper, :under_review, reviewer:user)
paper.reviewer_assignments.last.update_attributes(public:true)
delete :public, identifier:paper.typed_provider_id
expect(paper.reviewer_assignments.reload.last.public).to be_falsy
end
end
it "should fail if the user is not authorized" do
user = authenticate
paper = create(:paper, :under_review, reviewer:true)
post :public, identifier:paper.typed_provider_id
expect(response).to have_http_status(:forbidden)
end
end
describe "PUT #check_for_update" do
it "should create an updated paper" do
user = authenticate
paper = create(:paper, submittor:user, arxiv_id:'1311.1653')
stub_request(:get, "http://export.arxiv.org/api/query?id_list=1311.1653").to_return( fixture('arxiv/1311.1653v2.xml') )
expect {
put :check_for_update, identifier:paper.typed_provider_id
}.to change{Paper.count}.by(1)
expect(response).to have_http_status(:created)
expect(response.content_type).to eq("application/json")
assert_serializer BasicPaperSerializer
expect(response_json['typed_provider_id']).to eq('arxiv:1311.1653v2')
end
it "should fail if the user is not authenticated" do
put :check_for_update, identifier:'arxiv:0000.0000'
expect(response).to have_http_status(:unauthorized)
end
it "should succeed if the authenticated user is the submittor" do
user = authenticate(:user)
paper = create(:paper, submittor:user, arxiv_id:'1311.1653')
stub_request(:get, "http://export.arxiv.org/api/query?id_list=1311.1653").to_return( fixture('arxiv/1311.1653v2.xml') )
put :check_for_update, identifier:paper.typed_provider_id
expect(response).to have_http_status(:created)
expect(response_json['typed_provider_id']).to eq('arxiv:1311.1653v2')
end
it "should succeed if the authenticated user is the editor" do
user = authenticate(:editor)
paper = create(:paper, editor:user, arxiv_id:'1311.1653')
stub_request(:get, "http://export.arxiv.org/api/query?id_list=1311.1653").to_return( fixture('arxiv/1311.1653v2.xml') )
put :check_for_update, identifier:paper.typed_provider_id
expect(response).to have_http_status(:created)
expect(response_json['typed_provider_id']).to eq('arxiv:1311.1653v2')
end
it "should fail if the authenticated user is a reviewer" do
user = authenticate(:user)
paper = create(:paper, reviewer:user, arxiv_id:'1311.1653')
stub_request(:get, "http://export.arxiv.org/api/query?id_list=1311.1653").to_return( fixture('arxiv/1311.1653v2.xml') )
put :check_for_update, identifier:paper.typed_provider_id
expect(response).to have_http_status(:forbidden)
end
it "should fail if the authenticated user is not assigned to the paper" do
user = create(:user)
authenticate
paper = create(:paper, submittor:user, arxiv_id:'1311.1653')
put :check_for_update, identifier:paper.typed_provider_id
expect(response).to have_http_status(:forbidden)
end
it "should fail if there is no original paper" do
user = authenticate
put :check_for_update, identifier:'arxiv:0000.0000'
expect(response).to have_http_status(:not_found)
end
it "should fail if there is no new version" do
user = authenticate
paper = create(:paper, submittor:user, arxiv_id:'1311.1653', version:2)
stub_request(:get, "http://export.arxiv.org/api/query?id_list=1311.1653").to_return(fixture('arxiv/1311.1653v2.xml'))
put :check_for_update, identifier:paper.typed_provider_id
expect(response).to have_http_status(:conflict)
end
it "should fail if the original version cannot be superceded" do
user = authenticate
paper = create(:paper, :published, submittor:user, arxiv_id:'1311.1653')
put :check_for_update, identifier:paper.typed_provider_id
expect(response).to have_http_status(:conflict)
end
it "should fail if there is no document on Arxiv" do
user = authenticate
paper = create(:paper, submittor:user, arxiv_id:'1311.1653')
stub_request(:get, "http://export.arxiv.org/api/query?id_list=1311.1653").to_return(fixture('arxiv/not_found.xml'))
put :check_for_update, identifier:paper.typed_provider_id
expect(response).to have_http_status(:not_found)
end
end
describe "GET #versions" do
it "returns a list of papers" do
create(:paper, arxiv_id:'1234.5678', version:1)
create(:paper, arxiv_id:'1234.5678', version:2)
get :versions, identifier:'arxiv:1234.5678'
expect(response).to have_http_status(:ok)
expect(response.content_type).to eq("application/json")
expect(response_json.length).to eq(2)
assert_serializer BasicPaperSerializer
end
end
describe "GET #as_reviewer" do
it "should return papers" do
user = authenticate
paper = create(:paper, :under_review, reviewer:user)
get :as_reviewer, :format => :json
expect(response).to have_http_status(:success)
expect(response_json.size).to be(1)
end
it "should not return inactive papers" do
user = authenticate
paper = create(:paper, :superceded, reviewer:user)
get :as_reviewer, :format => :json
expect(response).to have_http_status(:success)
expect(response_json.size).to be(0)
end
context "with a state" do
it "should return correct papers" do
user = authenticate
paper = create(:paper, :under_review, reviewer:user)
get :as_reviewer, :format => :json, :state => 'submittted'
expect(response).to have_http_status(:success)
expect(response_json.size).to be(0)
end
end
end
describe "GET #as_collaborator" do
it "should return papers" do
user = authenticate
paper = create(:paper, :under_review, collaborator:user)
get :as_collaborator, :format => :json
expect(response).to have_http_status(:success)
expect(response_json.size).to be(1)
end
it "should not return inactive papers" do
user = authenticate
paper = create(:paper, :superceded, collaborator:user)
get :as_collaborator, :format => :json
expect(response).to have_http_status(:success)
expect(response_json.size).to be(0)
end
context "with a state" do
it "should return correct papers" do
user = authenticate
paper = create(:paper, :superceded, collaborator:user)
get :as_collaborator, :format => :json, :state => 'submittted'
expect(response).to have_http_status(:success)
expect(response_json.size).to be(0)
end
end
end
describe "GET #as_author" do
it "should return papers" do
user = authenticate
paper1 = create(:paper, :under_review, reviewer:user)
# This is the one that should be returned
paper2 = create(:paper, :under_review, submittor:user)
get :as_author, :format => :json
expect(response).to have_http_status(:success)
expect(response_json.size).to be(1)
end
it "should not return inactive papers" do
user = authenticate
paper1 = create(:paper, :under_review, reviewer:user)
paper2 = create(:paper, :superceded, submittor:user)
get :as_author, :format => :json
expect(response).to have_http_status(:success)
expect(response_json.size).to be(0)
end
end
describe "GET #as_editor" do
it "should return papers" do
user = set_paper_editor( authenticate(:editor) )
create(:paper, :under_review) # should be returned
create(:paper, :submitted) # should be returned
get :as_editor, :format => :json
expect(response).to have_http_status(:success)
expect(response_json.size).to be(2)
end
it "should not return inactive papers" do
user = set_paper_editor( authenticate(:editor) )
p1 = create(:paper, :under_review) # should be returned
p2 = create(:paper, :superceded) # should not be returned
get :as_editor
expect(response).to have_http_status(:success)
expect(response_json.size).to be(1)
expect(response_json.first['typed_provider_id']).to eq(p1.typed_provider_id)
end
end
describe "GET #search" do
it "should return papers" do
user1 = authenticate
user2 = create(:user)
create(:paper, :under_review, submittor:user1, title:'something')
create(:paper, :submitted, submittor:user2, title:'something')
get :search, q:'something'
expect(response).to have_http_status(:success)
expect(response_json.size).to be(2)
end
it "should return papers even if you are not authenticated" do
user1 = create(:user)
user2 = create(:user)
not_authenticated!
create(:paper, :under_review, submittor:user1, title:'something')
create(:paper, :submitted, submittor:user2, title:'something')
get :search, q:'something'
expect(response).to have_http_status(:success)
expect(response_json.size).to be(2)
end
it "should not return inactive papers" do
p1 = create(:paper, :under_review, title:'something') # should be returned
p2 = create(:paper, :superceded) # should not be returned
get :search, q:'something'
expect(response).to have_http_status(:success)
expect(response_json.size).to be(1)
expect(response_json.first['typed_provider_id']).to eq(p1.typed_provider_id)
end
it "should fail if you do not pass a query string" do
get :search, q:''
expect(response).to have_http_status(:bad_request)
end
end
shared_examples_for "#recent" do |action_name|
it "should return papers" do
user1 = authenticate
user2 = create(:user)
create(:paper, :published, submittor:user1)
create(:paper, :published, submittor:user2)
get action_name
expect(response).to have_http_status(:success)
expect(response_json.size).to eq(2)
end
it "should return papers even if you are not authenticated" do
user1 = create(:user)
user2 = create(:user)
not_authenticated!
create(:paper, :published, submittor:user1)
create(:paper, :published, submittor:user2)
get action_name
expect(response).to have_http_status(:success)
expect(response_json.size).to be(2)
end
it "should only return published papers" do
p1 = create(:paper, :submitted) # should not be returned
p2 = create(:paper, :under_review) # should not be returned
p3 = create(:paper, :review_completed) # should not be returned
p4 = create(:paper, :accepted) # should not be returned
p5 = create(:paper, :published)
get action_name
expect(response).to have_http_status(:success)
expect(response_json.size).to be(1)
expect(response_json.first['typed_provider_id']).to eq(p5.typed_provider_id)
end
it "should not return inactive papers" do
p1 = create(:paper, :published)
p2 = create(:paper, :superceded) # should not be returned
p3 = create(:paper, :rejected) # should not be returned
get action_name
expect(response).to have_http_status(:success)
expect(response_json.size).to be(1)
expect(response_json.first['typed_provider_id']).to eq(p1.typed_provider_id)
end
end
describe "GET #recent" do
it_should_behave_like "#recent", :recent
end
describe "GET #index" do
it_should_behave_like "#recent", :index
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/controllers/api/v1/annotations_controller_spec.rb | spec/controllers/api/v1/annotations_controller_spec.rb | require "rails_helper"
describe Api::V1::AnnotationsController do
describe "POST #create" do
it "should succeed" do
user = authenticate
paper = create(:paper, :under_review, submittor:user)
post :create, paper_identifier:paper.typed_provider_id,
annotation: { body:'An issue', page:1, xStart:0, yStart:0, xEnd:99, yEnd:99 }
expect(response).to have_http_status(:created)
expect(response_json).to include(
'paper_id' => paper.id,
'body' => 'An issue',
'parent_id' => nil,
'responses' => [] )
end
it "should create a root annotation" do
user = authenticate
paper = create(:paper, :under_review, submittor:user)
post :create, paper_identifier:paper.typed_provider_id,
annotation: { body:'An issue', page:1, xStart:0, yStart:0, xEnd:99, yEnd:99 }
annotation = paper.annotations.reload.last
expect(annotation).to have_attributes(
paper: paper,
body: 'An issue',
assignment: paper.submittor_assignment,
parent: nil
)
end
it "should succeed when create a response" do
user = authenticate
paper = create(:paper, :under_review, submittor:user)
root = create(:annotation, paper:paper)
post :create, paper_identifier:paper.typed_provider_id,
annotation: { parent_id:root.id, body:'A response' }
expect(response).to have_http_status(:created)
expect(response_json).to include(
'paper_id' => paper.id,
'body' => 'A response',
'parent_id' => root.id )
end
it "should create a response" do
user = authenticate
paper = create(:paper, :under_review, submittor:user)
root = create(:annotation, paper:paper)
post :create, paper_identifier:paper.typed_provider_id,
annotation: { parent_id:root.id, body:'A response' }
annotation = paper.annotations.reload.last
expect(annotation).to have_attributes(
paper: paper,
body: 'A response',
assignment: paper.submittor_assignment,
parent: root
)
end
it "should fail if the paper doesn't exist" do
authenticate
post :create, paper_identifier:'test:nonexistant',
annotation: { body:'An issue', page:1, xStart:0, yStart:0, xEnd:99, yEnd:99 }
expect(response).to have_http_status(:not_found)
end
it "should fail if no user is logged in" do
paper = create(:paper, :under_review, submittor:create(:user))
post :create, paper_identifier:paper.typed_provider_id,
annotation: { body:'An issue', page:1, xStart:0, yStart:0, xEnd:99, yEnd:99 }
expect(response).to have_http_status(:unauthorized)
expect(paper.annotations.reload.count).to eq(0)
end
it "should fail if the user is not assigned to the paper" do
user = authenticate
paper = create(:paper, :under_review, submittor:create(:user))
post :create, paper_identifier:paper.typed_provider_id,
annotation: { body:'An issue', page:1, xStart:0, yStart:0, xEnd:99, yEnd:99 }
expect(response).to have_http_status(:forbidden)
expect(paper.annotations.reload.count).to eq(0)
end
it "should fail if the paper is not under review" do
user = authenticate
paper = create(:paper, :submitted, submittor:user)
post :create, paper_identifier:paper.typed_provider_id,
annotation: { body:'An issue', page:1, xStart:0, yStart:0, xEnd:99, yEnd:99 }
expect(response).to have_http_status(:unprocessable_entity)
expect(paper.annotations.reload.count).to eq(0)
end
end
shared_examples "a state change" do
it "AS EDITOR responds successfully with a correct status and changed issue" do
editor = authenticate(:editor)
user = create(:user)
paper = create(:paper, :under_review, submittor:user, editor: editor)
issue = create(:issue, initial_state.to_sym, paper:paper, user:user)
put method, paper_identifier:paper.typed_provider_id, id:issue.id
expect(response).to have_http_status(:success)
expect(response_json).to include('state' => end_state)
expect(issue.reload.state).to eq(end_state)
end
it "Creating user responds successfully with a correct status and changed issue" do
user = authenticate
paper = create(:paper, :under_review, submittor:user)
issue = create(:issue, initial_state.to_sym, paper:paper, user:user)
put method, paper_identifier:paper.typed_provider_id, id:issue.id
expect(response).to have_http_status(:success)
expect(response_json).to include('state' => end_state)
expect(issue.reload.state).to eq(end_state)
end
it "As a different user fails with a forbidden status" do
user = authenticate
creator = create(:user)
paper = create(:paper, :under_review, submittor:creator, reviewer:user)
issue = create(:issue, initial_state.to_sym, paper:paper, user:creator)
put method, paper_identifier:paper.typed_provider_id, id:issue.id
expect(response).to have_http_status(:forbidden)
expect(issue.reload.state).to eq(initial_state)
end
it "When not logged in fails with a forbidden status" do
creator = create(:user)
paper = create(:paper, :under_review, submittor:creator)
issue = create(:issue, initial_state.to_sym, paper:paper, user:creator)
put method, paper_identifier:paper.typed_provider_id, id:issue.id
expect(response).to have_http_status(:unauthorized)
expect(issue.reload.state).to eq(initial_state)
end
it "When the paper is not under review it fails" do
user = authenticate
paper = create(:paper, :under_review, submittor:user)
issue = create(:issue, initial_state.to_sym, paper:paper, user:user)
paper.update_attributes!(state: 'submitted')
put method, paper_identifier:paper.typed_provider_id, id:issue.id
expect(response).to have_http_status(:unprocessable_entity)
expect(issue.reload.state).to eq(initial_state)
end
it "fails if the annotation is a response" do
user = authenticate
paper = create(:paper, :under_review, submittor:user)
issue = create(:issue, paper:paper)
comment = create(:response, initial_state.to_sym, parent:issue, user:user)
put method, paper_identifier:paper.typed_provider_id, id:comment.id
expect(response).to have_http_status(:unprocessable_entity)
expect(comment.reload.state).to eq(initial_state)
end
end
describe "PUT #resolve" do
let(:method) { :resolve }
let(:initial_state) { 'unresolved'}
let(:end_state) { 'resolved' }
it_behaves_like "a state change"
end
describe "PUT #dispute" do
let(:method) { :dispute }
let(:initial_state) { 'unresolved'}
let(:end_state) { 'disputed' }
it_behaves_like "a state change"
end
describe "PUT #unresolved" do
let(:method) { :unresolve }
let(:initial_state) { 'resolved'}
let(:end_state) { 'unresolved' }
it_behaves_like "a state change"
end
describe "GET #index" do
it "only gets the issues" do
submittor = authenticate
paper = create(:paper, submittor:submittor)
create_list(:response, 2, paper:paper)
get :index, paper_identifier:paper.typed_provider_id
expect(response).to have_http_status(:ok)
expect(response_json.length).to eq(2)
end
it "returns nothing if the user is not assigned" do
user = authenticate
submittor = create(:user)
paper = create(:paper, submittor:submittor)
create_list(:response, 2, paper:paper)
get :index, paper_identifier:paper.typed_provider_id
expect(response).to have_http_status(:no_content)
expect(response_json).to eq([])
end
it "returns nothing if the user is not authenticated" do
submittor = create(:user)
paper = create(:paper, submittor:submittor)
create_list(:response, 2, paper:paper)
get :index, paper_identifier:paper.typed_provider_id
expect(response).to have_http_status(:no_content)
expect(response_json).to eq([])
end
end
describe "GET #all" do
it "only gets the issues" do
submittor = authenticate
paper = create(:paper, submittor:submittor)
create_list(:response, 2, paper:paper)
get :all, paper_identifier:paper.typed_provider_id
expect(response).to have_http_status(:ok)
expect(response_json.length).to eq(4)
end
it "returns nothing if the user is not assigned" do
user = authenticate
submittor = create(:user)
paper = create(:paper, submittor:submittor)
create_list(:response, 2, paper:paper)
get :all, paper_identifier:paper.typed_provider_id
expect(response).to have_http_status(:no_content)
expect(response_json).to eq([])
end
it "returns nothing if the user is not authenticated" do
submittor = create(:user)
paper = create(:paper, submittor:submittor)
create_list(:response, 2, paper:paper)
get :all, paper_identifier:paper.typed_provider_id
expect(response).to have_http_status(:no_content)
expect(response_json).to eq([])
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/controllers/api/v1/assignments_controller_spec.rb | spec/controllers/api/v1/assignments_controller_spec.rb | require "rails_helper"
describe Api::V1::AssignmentsController do
describe "GET #index" do
it "should return the list of reviewers" do
paper = create(:paper)
get :index, paper_identifier:paper.typed_provider_id, format: :json
expect(response.content_type).to eq("application/json")
expect(response_json.length).to eq(1)
end
end
describe "POST #create" do
it "an unauthenticated user should be forbidden" do
paper = create(:paper)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:'abcd'
expect(response).to have_http_status(:unauthorized)
end
it "an authenticated user should be forbidden" do
authenticate
paper = create(:paper)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:'abcd'
expect(response).to have_http_status(:forbidden)
end
it "the submittor should be forbidden" do
user = authenticate
paper = create(:paper, submittor:user)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:'abcd'
expect(response).to have_http_status(:forbidden)
end
it "a collaborator should be forbidden" do
user = authenticate
paper = create(:paper, collaborator:user)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:'abcd'
expect(response).to have_http_status(:forbidden)
end
it "a reviewer should be forbidden" do
user = authenticate
paper = create(:paper, reviewer:user)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:'abcd'
expect(response).to have_http_status(:forbidden)
end
it "the editor should be allowed to add reviewers" do
authenticate(:editor)
paper = create(:paper, :submitted)
reviewer = create(:user)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:reviewer.sha
expect(response).to have_http_status(:success)
end
it "the editor should add a reviewer" do
authenticate(:editor)
paper = create(:paper, :submitted)
reviewer = create(:user)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:reviewer.sha
expect(paper.reviewers.length).to eq(1)
expect(paper.reviewers.first).to eq(reviewer)
end
it "the editor should return the list of reviewers" do
set_paper_editor authenticate(:editor)
paper = create(:paper, :submitted)
reviewer = create(:user)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:reviewer.sha
expect(response.content_type).to eq("application/json")
expect(response_json.length).to eq(3)
expect(response_json.last['user']['sha']).to eq(reviewer.sha)
end
it "should fail if you add a reviewer that is the submittor" do
authenticate(:editor)
submittor = create(:user)
paper = create(:paper, :submitted, submittor: submittor)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:submittor.sha
expect(response).to have_http_status(:unprocessable_entity)
end
it "should fail if you add a reviewer that is a collaborator" do
authenticate(:editor)
collaborator = create(:user)
paper = create(:paper, :submitted, collaborator: collaborator)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:collaborator.sha
expect(response).to have_http_status(:unprocessable_entity)
end
it "should fail if you add a reviewer that is already a reviewer" do
authenticate(:editor)
reviewer = create(:user)
paper = create(:paper, reviewer:reviewer)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:reviewer.sha
expect(response).to have_http_status(:unprocessable_entity)
end
it "should be possible to add a reviewer when the state is submitted" do
authenticate(:editor)
paper = create(:paper, :submitted)
expect(paper.assignments.reload.length).to eq(1)
reviewer = create(:user)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:reviewer.sha
expect(response).to have_http_status(:success)
expect(paper.assignments.reload.length).to eq(2)
end
it "should change the state to under_review automatically" do
authenticate(:editor)
paper = create(:paper, :submitted)
reviewer = create(:user)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:reviewer.sha
expect(paper.reload).to be_under_review
end
it "should be possible to add a reviewer when the state is under review" do
authenticate(:editor)
paper = create(:paper, :under_review)
expect(paper.assignments.reload.length).to eq(1)
reviewer = create(:user)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:reviewer.sha
expect(response).to have_http_status(:success)
expect(paper.assignments.reload.length).to eq(2)
end
it "should not be possible to add a reviewer when the state is review completed" do
authenticate(:editor)
paper = create(:paper, :review_completed)
reviewer = create(:user)
post :create, paper_identifier:paper.typed_provider_id, format: :json, user:reviewer.sha
expect(response).to have_http_status(:bad_request)
expect(paper.assignments.reload.length).to eq(1)
end
end
describe "DELETE #destroy" do
it "an unauthenticated user should be forbidden" do
paper = create(:paper)
delete :destroy, paper_identifier:paper.typed_provider_id, format: :json, id:'abcd'
expect(response).to have_http_status(:unauthorized)
end
it "an authenticated user should be forbidden" do
authenticate
paper = create(:paper)
delete :destroy, paper_identifier:paper.typed_provider_id, format: :json, id:'abcd'
expect(response).to have_http_status(:forbidden)
end
it "the submittor should be forbidden" do
user = authenticate
paper = create(:paper, submittor:user)
delete :destroy, paper_identifier:paper.typed_provider_id, format: :json, id:'abcd'
expect(response).to have_http_status(:forbidden)
end
it "a collaborator should be forbidden" do
user = authenticate
paper = create(:paper, collaborator:user)
delete :destroy, paper_identifier:paper.typed_provider_id, format: :json, id:'abcd'
expect(response).to have_http_status(:forbidden)
end
it "a reviewer should be forbidden" do
user = authenticate
paper = create(:paper, reviewer:user)
delete :destroy, paper_identifier:paper.typed_provider_id, format: :json, id:'abcd'
expect(response).to have_http_status(:forbidden)
end
it "the editor should be allowed to remove reviewers" do
authenticate(:editor)
reviewer = create(:user)
paper = create(:paper, reviewer:reviewer)
delete :destroy, paper_identifier:paper.typed_provider_id, format: :json, id:paper.reviewer_assignments.first.sha
expect(response).to have_http_status(:success)
end
it "the editor should remove a reviewer" do
authenticate(:editor)
reviewer1 = create(:user)
reviewer2 = create(:user)
paper = create(:paper, reviewer:[reviewer1,reviewer2])
delete :destroy, paper_identifier:paper.typed_provider_id, format: :json, id:paper.reviewer_assignments.first.sha
expect(paper.reviewers.length).to eq(1)
expect(paper.reviewers.first).to eq(reviewer2)
end
it "the editor should return the list of reviewers" do
set_paper_editor authenticate(:editor)
reviewer1 = create(:user)
reviewer2 = create(:user)
paper = create(:paper, reviewer:[reviewer1,reviewer2])
delete :destroy, paper_identifier:paper.typed_provider_id, format: :json, id:paper.reviewer_assignments.first.sha
expect(response.content_type).to eq("application/json")
expect(response_json.length).to eq(3)
end
it "should fail if you remove a user that is not a reviewer" do
authenticate(:editor)
reviewer1 = create(:user)
paper = create(:paper, reviewer:[reviewer1])
delete :destroy, paper_identifier:paper.typed_provider_id, format: :json, id:'some random sha'
expect(response).to have_http_status(:unprocessable_entity)
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/models/provider_spec.rb | spec/models/provider_spec.rb | require "rails_helper"
describe Provider do
describe "[]" do
it "should return a provider" do
expect( Provider[:arxiv] ).to be(Provider::ArxivProvider)
end
it "should not be case sensitive" do
expect( Provider[:Arxiv] ).to be(Provider::ArxivProvider)
end
it "should accept a string" do
expect( Provider['arxiv'] ).to be(Provider::ArxivProvider)
end
it "should fail if no provider is found" do
expect{ Provider['not_found'] }.to raise_exception(Provider::Error::ProviderNotFound)
end
end
describe "::parse_identifier" do
it "should split the identifier into correct parts" do
result = Provider.parse_identifier('test:1234-9')
expect(result.length).to eq(3)
expect(result).to eq({provider_type:'test', provider_id:'1234', version:9})
end
it "should split an identifier without version info into 2 correct parts" do
result = Provider.parse_identifier('test:1234')
expect(result.length).to eq(2)
expect(result).to eq({provider_type:'test', provider_id:'1234'})
end
it "should raise an exception if the identifier is blank" do
expect{ Provider.parse_identifier(nil) }.to raise_exception(Provider::Error::InvalidIdentifier)
expect{ Provider.parse_identifier('' ) }.to raise_exception(Provider::Error::InvalidIdentifier)
expect{ Provider.parse_identifier(' ') }.to raise_exception(Provider::Error::InvalidIdentifier)
end
it "should raise an exception if the provider is given but the identifier is blank" do
expect{ Provider.parse_identifier('test:') }.to raise_exception(Provider::Error::InvalidIdentifier)
expect{ Provider.parse_identifier('test' ) }.to raise_exception(Provider::Error::InvalidIdentifier)
end
it "should raise an exception if the provider is not known" do
expect{ Provider.parse_identifier('unknown:1234') }.to raise_exception(Provider::Error::ProviderNotFound)
end
end
describe "::get_attributes" do
it "should return attributes" do
attributes = Provider.get_attributes('test:1234-5')
expect(attributes).to be_a(Hash)
end
it "should return the attributes" do
expect(Provider.get_attributes('test:1234-5')).to match(
provider_type: :test,
provider_id: '1234',
version: 5,
authors: an_instance_of(String),
document_location: an_instance_of(String),
title: an_instance_of(String),
summary: an_instance_of(String),
)
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/models/paper_spec.rb | spec/models/paper_spec.rb | require "rails_helper"
describe Paper do
let(:arxiv_doc) do
{
provider_type: :arxiv,
provider_id: "1311.1653",
version: 2,
authors: "Mar Álvarez-Álvarez, Angeles I. Díaz",
document_location: "https://arxiv.org/pdf/1311.1653v2.pdf",
title: "A photometric comprehensive study of circumnuclear star forming rings: the sample",
summary: "We present photometry.*in a second paper."
}
end
it "should initialize properly" do
user = create(:user)
paper = Paper.create!(provider_type:'test', provider_id:'1234abcd', version:7, submittor:user)
expect(paper.provider_type).to eq('test')
expect(paper.provider_id).to eq('1234abcd')
expect(paper.version).to eq(7)
expect(paper.state).to eq("submitted")
end
describe "construction" do
it "Adds the submittor and editor as assignments" do
editor = set_paper_editor
submittor = create(:user)
p = create(:paper, submittor:submittor)
expect(p.submittor_assignment.user).to eq(submittor)
expect(p.assignments.length).to eq(2)
expect(p.assignments.first.role).to eq('editor')
expect(p.assignments.first.user).to eq(editor)
expect(p.assignments.second.role).to eq('submittor')
expect(p.assignments.second.user).to eq(submittor)
end
it "The submittor will become the editor if they are capable [for testing]" do
editor = set_paper_editor
submittor = create(:user, editor:true)
p = create(:paper, submittor:submittor)
expect(p.editors.first).to eq(submittor)
end
end
describe "::search" do
it "should find papers containing the text in the title" do
p = create(:paper, title:'This paper has a title')
results = Paper.search('has a t')
expect(results.length).to eq(1)
expect(results.first).to eq(p)
end
it "should find papers containing the text in the summary" do
p = create(:paper, summary:'This paper has a summary')
results = Paper.search('has a s')
expect(results.length).to eq(1)
expect(results.first).to eq(p)
end
it "should find papers containing the text in the authors" do
p = create(:paper, authors:'J. Doe, W. Smith')
results = Paper.search('Doe')
expect(results.length).to eq(1)
expect(results.first).to eq(p)
end
it "should find papers from the submittor" do
s = create(:user, name:'John Doe')
p = create(:paper, submittor:s)
results = Paper.search('n Doe')
expect(results.length).to eq(1)
expect(results.first).to eq(p)
end
it "should be case-insensitive" do
p = create(:paper, title:'This paper has a title')
results = Paper.search('hAs a T')
expect(results.length).to eq(1)
expect(results.first).to eq(p)
end
end
describe "emails" do
it "sends an email to the submittor" do
user = create(:user, name:'John Smith', email:'jsmith@example.com')
expect {
create(:paper, title:'My Paper', submittor:user)
}.to change { deliveries.size }.by(1)
is_expected.to have_sent_email.to('jsmith@example.com').matching_subject(/My Paper - Paper Submitted/)
end
it "sends an email to the submittor when it is revised" do
user = create(:user, name:'John Smith', email:'jsmith@example.com')
original = create(:paper, title:'My Paper', submittor:user, arxiv_id:'1311.1653', version:1)
deliveries.clear
expect {
original.create_updated!(arxiv_doc)
}.to change { deliveries.size }.by(1)
is_expected.to have_sent_email.to('jsmith@example.com').matching_subject(/A photo.* - Paper Revised/)
end
it "sends an email when the state changes" do
user = create(:user, name:'John Smith', email:'jsmith@example.com')
paper = create(:paper, title:'My Paper', submittor:user, reviewer:true)
deliveries.clear
expect {
paper.start_review!
}.to change { deliveries.size }.by(1)
is_expected.to have_sent_email.to('jsmith@example.com').matching_subject(/Paper Under Review/)
expect {
paper.complete_review!
}.to change { deliveries.size }.by(1)
expect {
paper.accept!
}.to change { deliveries.size }.by(1)
expect {
paper.doi = 'some doi'
paper.publish!
}.to change { deliveries.size }.by(1)
expect {
paper.state = :under_review
paper.reject!
}.to change { deliveries.size }.by(1)
end
it "doesn't send an email when the paper is superceded" do
user = create(:user, name:'John Smith', email:'jsmith@example.com')
paper = create(:paper, title:'My Paper', submittor:user)
deliveries.clear
expect {
paper.supercede!
}.not_to change { deliveries.size }
end
it "doesn't send an email when the state doesn't change" do
user = create(:user, name:'John Smith', email:'jsmith@example.com')
paper = create(:paper, title:'My Paper', submittor:user)
deliveries.clear
expect {
paper.update_attributes!(title:'A new title')
}.not_to change { deliveries.size }
end
end
describe "::with_scope" do
it "should return properly scoped records" do
paper1 = create(:paper, :submitted)
paper2 = create(:paper, :submitted)
papers = Paper.with_state('submitted')
expect(papers.count).to eq(2)
expect( papers ).to include(paper1)
end
it "should ignore improperly scoped records" do
paper1 = create(:paper, :under_review)
paper2 = create(:paper, :submitted)
papers = Paper.with_state('submitted')
expect(papers.count).to eq(1)
expect( papers ).not_to include(paper1)
end
it "should return all papers if no state is given" do
paper1 = create(:paper, :under_review)
paper2 = create(:paper, :submitted)
papers = Paper.with_state('')
expect(papers.count).to eq(2)
expect( papers ).to include(paper1)
end
end
describe "::for_identifier" do
it "should find a paper using an integer id" do
paper = create(:paper, provider_id:'1234', version:9)
expect(Paper.for_identifier(paper.id)).to eq(paper)
end
it "should find a paper using an integer string id" do
paper = create(:paper, provider_id:'1234', version:9)
expect(Paper.for_identifier(paper.id.to_s)).to eq(paper)
end
it "should find a paper using an identifier and version" do
paper = create(:paper, provider_id:'1234', version:9)
expect(Paper.for_identifier('test:1234-9')).to eq(paper)
end
it "should find the correct paper amongst multiple versions" do
paper1 = create(:paper, provider_id:'1234', version:7)
paper2 = create(:paper, provider_id:'1234', version:8)
paper3 = create(:paper, provider_id:'1234', version:9)
expect(Paper.for_identifier('test:1234-8')).to eq(paper2)
end
it "should find a paper using an identifier and no version" do
paper = create(:paper, provider_id:'1234', version:9)
expect(Paper.for_identifier('test:1234')).to eq(paper)
end
it "should find the latest paper amongst multiple versions" do
paper1 = create(:paper, provider_id:'1234', version:7)
paper2 = create(:paper, provider_id:'1234', version:9)
paper3 = create(:paper, provider_id:'1234', version:8)
expect(Paper.for_identifier('test:1234')).to eq(paper2)
end
it "should raise an error if no identifier is provided" do
expect{Paper.for_identifier('') }.to raise_exception(Provider::Error::InvalidIdentifier)
expect{Paper.for_identifier(nil) }.to raise_exception(Provider::Error::InvalidIdentifier)
end
it "should raise an error if a type but no id is provided" do
expect{Paper.for_identifier('test') }.to raise_exception(Provider::Error::InvalidIdentifier)
expect{Paper.for_identifier('test:') }.to raise_exception(Provider::Error::InvalidIdentifier)
end
it "should raise an error if the provider is not found" do
expect{Paper.for_identifier('unknown:1234') }.to raise_exception(Provider::Error::ProviderNotFound)
end
it "should return nil if the record is not found" do
expect(Paper.for_identifier('test:1234-9') ).to be_nil
expect(Paper.for_identifier('test:1234') ).to be_nil
end
it "should raise an error if the record is not found" do
expect{Paper.for_identifier!('test:1234-9') }.to raise_exception(ActiveRecord::RecordNotFound)
expect{Paper.for_identifier!('test:1234') }.to raise_exception(ActiveRecord::RecordNotFound)
end
end
describe "::versions_for" do
it "should return a sorted list of papers" do
create(:paper, arxiv_id:'9999.9999', version:2)
create(:paper, arxiv_id:'1234.5678', version:2)
create(:paper, arxiv_id:'1234.5678', version:1)
create(:paper, arxiv_id:'1234.5678', version:3)
create(:paper, arxiv_id:'1234.5678', version:4)
papers = Paper.versions_for(:arxiv, '1234.5678')
expect(papers[0]['version']).to eq(4)
expect(papers[1]['version']).to eq(3)
expect(papers[2]['version']).to eq(2)
expect(papers[3]['version']).to eq(1)
end
end
describe "#create_updated!" do
it "should create a new instance" do
original = create(:paper, arxiv_id:'1311.1653')
new_paper = nil
expect {
new_paper = original.create_updated!(arxiv_doc)
}.to change{Paper.count}.by(1)
expect(new_paper).to be_persisted
end
it "should change the state of the original instance to superceded" do
original = create(:paper, arxiv_id:'1311.1653')
new_paper = original.create_updated!(arxiv_doc)
expect(original).to be_superceded
end
it "should copy the attributes from the original paper" do
original = create(:paper, :under_review, arxiv_id:'1311.1653')
new_paper = original.create_updated!(arxiv_doc)
expect(new_paper.submittor).to eq(original.submittor)
expect(new_paper.state).to eq('under_review')
end
it "if the paper is in the submitted state it should stay submitted" do
original = create(:paper, :submitted, arxiv_id:'1311.1653')
new_paper = original.create_updated!(arxiv_doc)
expect(new_paper.state).to eq('submitted')
end
it "if the paper is in a state past :under_review, the new paper will be :under_review" do
original = create(:paper, :review_completed, arxiv_id:'1311.1653')
new_paper = original.create_updated!(arxiv_doc)
expect(new_paper.state).to eq('under_review')
end
it "should set the arxiv attributes on the new paper" do
original = create(:paper, arxiv_id:'1311.1653')
new_paper = original.create_updated!(arxiv_doc)
expect(new_paper.provider_type).to eq('arxiv')
expect(new_paper.provider_id).to eq('1311.1653')
expect(new_paper.version).to eq(2)
expect(new_paper.title).to eq("A photometric comprehensive study of circumnuclear star forming rings: the sample")
expect(new_paper.summary).to match /^We present.*paper.$/
expect(new_paper.document_location).to eq("https://arxiv.org/pdf/1311.1653v2.pdf")
expect(new_paper.authors).to eq("Mar Álvarez-Álvarez, Angeles I. Díaz")
end
it "should copy the assignments from the original paper" do
set_paper_editor
original = create(:paper, arxiv_id:'1311.1653',
reviewer:[ create(:user), create(:user) ])
expect(original.assignments.length).to eq(4)
new_paper = original.create_updated!(arxiv_doc)
expect(new_paper.assignments.length).to eq(original.assignments.length)
(0...original.assignments.length).each do |index|
expect(new_paper.assignments[index].role).to eq(original.assignments[index].role)
expect(new_paper.assignments[index].user).to eq(original.assignments[index].user)
expect(new_paper.assignments[index].copied).to be_truthy
end
end
it "should keep the public attribute on the assignments if it is set on the original paper" do
original = create(:paper, arxiv_id:'1311.1653',
reviewer:[ create(:user), create(:user) ])
original.assignments.second.update_attributes!(public:true)
new_paper = original.create_updated!(arxiv_doc)
expect(new_paper.assignments.second.public).to be_truthy
expect(new_paper.assignments.third.public).to be_falsy
end
it "should NOT keep the completed attribute on the assignments if it is set on the original paper" do
original = create(:paper, arxiv_id:'1311.1653',
reviewer:[ create(:user), create(:user) ])
original.assignments.second.update_attributes!(completed:true)
new_paper = original.create_updated!(arxiv_doc)
expect(new_paper.assignments.second.public).to be_falsy
end
it "should copy the original editor" do
set_paper_editor
original = create(:paper, arxiv_id:'1311.1653',
reviewer:[ create(:user), create(:user) ])
expect(original.assignments.length).to eq(4)
set_paper_editor
new_paper = original.create_updated!(arxiv_doc)
expect(new_paper.assignments.length).to eq(original.assignments.length)
(0...original.assignments.length).each do |index|
expect(new_paper.assignments[index].role).to eq(original.assignments[index].role)
expect(new_paper.assignments[index].user).to eq(original.assignments[index].user)
end
end
it "should raise an error if the arxiv_ids are different" do
original = create(:paper, arxiv_id:'9999.9999')
expect { original.create_updated!(arxiv_doc) }.to raise_exception
end
it "should raise an error if the provider's are different" do
original = create(:paper, provider_id:'1311.1653')
expect { original.create_updated!(arxiv_doc) }.to raise_exception
end
it "should raise an error if the original cannot be superceded" do
original = create(:paper, arxiv_id:'1311.1653')
expect { original.create_updated!(arxiv_doc) }.not_to raise_exception
original.state = 'superceded'
expect { original.create_updated!(arxiv_doc) }.to raise_exception
original.state = 'resolved'
expect { original.create_updated!(arxiv_doc) }.to raise_exception
end
it "should raise an error if there is no new arxiv version" do
original = create(:paper, arxiv_id:'1311.1653', version:2)
expect { original.create_updated!(arxiv_doc) }.to raise_exception
end
end
context "versioning" do
def create_papers
@paper1 = create(:paper, arxiv_id:'1234.5678', version:1, state:'superceded')
@paper2 = create(:paper, arxiv_id:'1234.5678', version:2, state:'superceded')
@paper3 = create(:paper, arxiv_id:'1234.5678', version:3)
end
describe "#is_original_version?" do
it "should work for a single paper" do
@paper1 = create(:paper, arxiv_id:'1234.5678', version:2)
expect(@paper1.is_original_version?).to be_truthy
end
it "should work for multiple papers" do
create_papers
expect(@paper1.is_original_version?).to be_truthy
expect(@paper2.is_original_version?).to be_falsey
expect(@paper3.is_original_version?).to be_falsey
end
end
describe "#is_latest_version?" do
it "should work for a single paper" do
@paper1 = create(:paper, arxiv_id:'1234.5678', version:2)
expect(@paper1.is_latest_version?).to be_truthy
end
it "should work for multiple papers" do
create_papers
expect(@paper1.is_latest_version?).to be_falsey
expect(@paper2.is_latest_version?).to be_falsey
expect(@paper3.is_latest_version?).to be_truthy
end
end
describe "#is_revision?" do
it "should work for a single paper" do
@paper1 = create(:paper, arxiv_id:'1234.5678', version:2)
expect(@paper1.is_revision?).to be_falsey
end
it "should work for multiple papers" do
create_papers
expect(@paper1.is_revision?).to be_falsey
expect(@paper2.is_revision?).to be_truthy
expect(@paper3.is_revision?).to be_truthy
end
end
end
describe "states" do
context "begin_review event" do
it "should succeed if the paper has reviewers" do
paper = create(:paper, reviewer:true)
paper.start_review!
end
it "should fail if the paper has no reviewers" do
paper = create(:paper)
expect { paper.start_review! }.to raise_exception(AASM::InvalidTransition)
end
end
context "accept event" do
it "should resolve all issues" do
paper = create(:paper, :review_completed)
create_list(:annotation, 2, paper:paper)
paper.accept!
expect(paper.annotations.reload).to all( have_attributes(state:'resolved') )
end
end
end
describe "#resolve_all_issues" do
it "should resolve any outstanding issues" do
paper = create(:paper, :under_review)
3.times { create(:annotation, paper:paper) }
expect(paper.annotations.count).to eq(3)
paper.resolve_all_issues
expect( paper.outstanding_issues ).to be_empty
end
end
describe "Abilities" do
it "should allow a user to create a Paper as author" do
user = create(:user)
ability = Ability.new(user)
assert ability.can?(:create, create(:paper, submittor:user, arxiv_id:'1234.5678'))
end
it "should allow a user to read a Paper as author" do
user = create(:user)
paper = create(:paper, submittor:user)
ability = Ability.new(user, paper)
assert ability.can?(:read, paper)
end
# it "should allow a user to update their own paper if it's not submitted" do
# user = create(:user)
# paper = create(:paper, submittor:user)
#
# ability = Ability.new(user, paper)
#
# assert ability.can?(:update, paper)
# end
it "should allow a user to update their own paper" do
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
ability = Ability.new(user, paper)
assert ability.can?(:update, paper)
end
it "should not allow a user to update their own paper if it is accepted" do
user = create(:user)
paper = create(:paper, :accepted, submittor:user)
ability = Ability.new(user, paper)
assert ability.cannot?(:update, paper)
end
it "should not allow a user to update their own paper if it is published" do
user = create(:user)
paper = create(:paper, :published, submittor:user)
ability = Ability.new(user, paper)
assert ability.cannot?(:update, paper)
end
# it "can destroy a draft paper that a user owns" do
# user = create(:user)
# paper = create(:paper, submittor:user)
#
# ability = Ability.new(user, paper)
#
# assert ability.can?(:destroy, paper)
# end
it "cannot destroy a draft paper that a user doesn't own" do
user = create(:user)
paper = create(:paper)
ability = Ability.new(user, paper)
assert ability.cannot?(:destroy, paper)
end
it "cannot destroy a submitted paper that a user owns" do
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
ability = Ability.new(user, paper)
assert ability.cannot?(:destroy, paper)
end
it "an editor can change the state of a paper" do
editor = create(:editor)
paper = create(:paper, :submitted, submittor:create(:user), editor: editor)
ability = Ability.new(editor, paper)
expect(ability).to be_able_to(:start_review, paper)
end
it "an author cannot change the state of a paper" do
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
ability = Ability.new(user, paper)
expect(ability).not_to be_able_to(:start_review, paper)
end
it "a reviewer cannot change the state of a paper" do
user = create(:user)
paper = create(:paper, :submitted, submittor:create(:user), reviewer:user )
ability = Ability.new(user, paper)
expect(ability).not_to be_able_to(:start_review, paper)
end
it "a reader cannot change the state of a paper" do
user = create(:user)
paper = create(:paper, :submitted, submittor:create(:user) )
ability = Ability.new(user, paper)
expect(ability).not_to be_able_to(:start_review, paper)
end
end
describe "#permisions_for_user" do
it "should return correct permissions for paper for user" do
user = create(:user)
paper = create(:paper, submittor:user)
create(:assignment, :reviewer, user:user, paper:paper)
create(:assignment, :collaborator, user:user, paper:paper)
["submittor", "collaborator", "reviewer"].each do |role|
assert paper.permissions_for_user(user).include?(role), "Missing #{role}"
end
end
it "should return correct permissions for paper for user as editor" do
user = set_paper_editor
paper = create(:paper, submittor:user)
create(:assignment, :reviewer, user:user, paper:paper)
create(:assignment, :collaborator, user:user, paper:paper)
["editor", "submittor", "collaborator", "reviewer"].each do |role|
assert paper.permissions_for_user(user).include?(role), "Missing #{role}"
end
end
end
describe "#assignments" do
describe "#for_user" do
it "should return the assignmnet for a user" do
submittor = create(:user)
paper = create(:paper, submittor:submittor)
assignment = paper.assignments.for_user(submittor)
expect(assignment.user).to eq(submittor)
end
it "should return the assignmnet for a user and role" do
user = create(:user)
paper = create(:paper, submittor:user, reviewer:user)
assignment = paper.assignments.for_user(user, 'submittor')
expect(assignment).to be_present
expect(assignment.user).to eq(user)
expect(assignment.role).to eq('submittor')
assignment = paper.assignments.for_user(user, 'reviewer')
expect(assignment).to be_present
expect(assignment.user).to eq(user)
expect(assignment.role).to eq('reviewer')
end
end
end
describe "#add_assignee" do
it "should add the user as a reviewer" do
user = create(:user)
paper = create(:paper)
expect(paper.add_assignee(user,'reviewer')). to be_truthy
expect(paper.reviewers.length).to eq(1)
expect(paper.reviewers.first).to eq(user)
end
it "should fail if the user is the submittor" do
user = create(:user)
paper = create(:paper, submittor:user)
expect(paper.add_assignee(user,'reviewer')). to be_falsy
expect(paper.reviewers).to be_empty
expect(paper.errors).not_to be_empty
end
it "should fail if the user is a collaborator" do
user = create(:user)
paper = create(:paper, collaborator:user)
expect(paper.add_assignee(user,'reviewer')). to be_falsy
expect(paper.reviewers).to be_empty
expect(paper.errors).not_to be_empty
end
it "should fail if the user is already a reviewer" do
user = create(:user)
paper = create(:paper, reviewer:user)
expect(paper.add_assignee(user,'reviewer')). to be_falsy
expect(paper.reviewers.length).to eq(1)
expect(paper.errors).not_to be_empty
end
end
describe "#mark_review_completed!" do
let(:reviewers) { create_list(:user, 2) }
it "should return an error if the paper is not in a reviewable state" do
paper = create(:paper, reviewer:reviewers)
expect(paper.mark_review_completed!(reviewers.first, 'accept')).to be_falsy
expect(paper.errors).to be_present
expect(paper.reload.reviewer_assignments.first.completed).to be_falsy
end
it "should return an error if the user is not a reviewer" do
paper = create(:paper, :under_review, reviewer:true)
expect(paper.mark_review_completed!(paper.submittor, 'accept')).to be_falsy
expect(paper.errors).to be_present
expect(paper.reload.submittor_assignment.completed).to be_falsy
end
it "should return an error if the reviewer_accept attribute is invalid" do
paper = create(:paper, :under_review, reviewer:reviewers)
expect {
paper.mark_review_completed!(reviewers.first, 'unknown')
}.to raise_exception(ActiveRecord::RecordInvalid)
expect(paper.reload.reviewer_assignments.first.completed).to be_falsy
end
it "should mark the reviewer as completed" do
paper = create(:paper, :under_review, reviewer:reviewers)
expect(paper.mark_review_completed!(reviewers.first, 'accept')).to be_truthy
expect(paper.errors).to be_empty
expect(paper.reviewer_assignments.first.completed).to be_truthy
expect(paper).to be_under_review
end
it "should set the reviewer_accept attribute" do
paper = create(:paper, :under_review, reviewer:reviewers)
paper.mark_review_completed!(reviewers.first, 'reject')
expect(paper.reviewer_assignments.first.reviewer_accept).to eq('reject')
end
it "when the last review is completed the state of the paper should change" do
paper = create(:paper, :under_review, reviewer:reviewers)
paper.reviewer_assignments.first.update_attributes(completed:true)
expect(paper.mark_review_completed!(reviewers.second, 'accept_with_minor')).to be_truthy
expect(paper.reviewer_assignments.second.completed).to be_truthy
expect(paper).to be_review_completed
end
it "sends an email to the editor when the review is completed by all reviewers" do
set_paper_editor create(:user, email:'editor@example.com')
paper = create(:paper, :under_review, reviewer:reviewers)
paper.reviewer_assignments.first.update_attributes(completed:true)
expect {
paper.mark_review_completed!(reviewers.second, 'accept_with_major')
}.to change { deliveries.count }.by(1)
is_expected.to have_sent_email.to('editor@example.com').matching_subject(/- Review Completed/)
end
it "should create a comment if one is provided" do
paper = create(:paper, :under_review, reviewer:reviewers)
paper.mark_review_completed!(reviewers.first, 'reject', 'some comment')
expect(paper.annotations.first.body).to eq('some comment')
end
it "should not create a comment if none is provided" do
paper = create(:paper, :under_review, reviewer:reviewers)
paper.mark_review_completed!(reviewers.first, 'reject', ' ')
expect(paper.annotations).to be_empty
end
end
describe "#make_reviewer_public!!" do
let(:reviewers) { create_list(:user, 2) }
it "should return an error if the user is not a reviewer" do
paper = create(:paper, reviewer:true)
expect(paper.make_reviewer_public!(paper.submittor, false)).to be_falsy
expect(paper.errors).to be_present
expect(paper.reload.submittor_assignment.public).to be_truthy
end
it "should return an error if the paper is not the latest version" do
original = create(:paper, reviewer:reviewers, arxiv_id:'1311.1653', version:1)
updated = original.create_updated!(arxiv_doc)
expect(original.make_reviewer_public!(reviewers.first, true)).to be_falsy
expect(original.errors).to be_present
expect(original.reload.reviewer_assignments.first.public).to be_falsy
expect(updated.reload.reviewer_assignments.first.public).to be_falsy
end
it "should mark the reviewer as public" do
paper = create(:paper, reviewer:reviewers)
expect(paper.make_reviewer_public!(reviewers.first)).to be_truthy
expect(paper.errors).to be_empty
expect(paper.reload.reviewer_assignments.first.public).to be_truthy
end
it "should mark the reviewer as not public" do
paper = create(:paper, reviewer:reviewers)
paper.reviewer_assignments.first.update_attributes!(public:true)
expect(paper.make_reviewer_public!(reviewers.first, false)).to be_truthy
expect(paper.errors).to be_empty
expect(paper.reload.reviewer_assignments.first.public).to be_falsy
end
context "if a user is a reviewer in multiple papers" do
it "should mark them all as public" do
original = create(:paper, reviewer:reviewers, arxiv_id:'1311.1653', version:1)
updated = original.create_updated!(arxiv_doc)
expect(updated.make_reviewer_public!(reviewers.first, true)).to be_truthy
expect(updated.errors).to be_empty
expect(updated.reload.reviewer_assignments.first.public).to be_truthy
expect(original.reload.reviewer_assignments.first.public).to be_truthy
end
it "should mark them all as non-public" do
original = create(:paper, reviewer:reviewers, arxiv_id:'1311.1653', version:1)
original.reviewer_assignments.first.update_attributes!(public:true)
updated = original.create_updated!(arxiv_doc)
expect(updated.make_reviewer_public!(reviewers.first, false)).to be_truthy
expect(updated.errors).to be_empty
expect(updated.reload.reviewer_assignments.first.public).to be_falsy
expect(original.reload.reviewer_assignments.first.public).to be_falsy
end
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/models/annotation_spec.rb | spec/models/annotation_spec.rb | require "rails_helper"
describe Annotation do
describe '#responses' do
it "should return responses" do
paper = create(:paper, :submitted)
first_annotation = create(:annotation, paper:paper)
second_annotation = create(:annotation, paper:paper, parent:first_annotation)
first_annotation.reload
assert first_annotation.has_responses?
assert_equal second_annotation.parent, first_annotation
end
end
it "should set the paper from the parent if a parent is provided but no paper" do
paper = create(:paper)
annotation1 = create(:annotation, paper:paper)
annotation2 = Annotation.create!(body:'Second Annotation', parent:annotation1, assignment:paper.assignments.first)
expect(annotation2.paper).to eq(paper)
end
describe '#is_issue?' do
it "should be true for a root annotation" do
root_annotation = create(:root)
expect(root_annotation.is_issue?).to be_truthy
end
it "should be true false for a reply" do
reply_annotation = create(:response)
expect(reply_annotation.is_issue?).to be_falsy
end
end
describe "State" do
it "should initiallly be unresolved" do
annotation = build(:issue, paper:build(:paper, :under_review) )
annotation.unresolve!
expect(annotation).to be_unresolved
end
context "an issue" do
let (:annotation) { build(:issue, paper:create(:paper, :under_review)) }
it "should be possible to resolve the annotation" do
expect(annotation.may_resolve?).to eq(true)
annotation.resolve!
expect(annotation).to be_resolved
end
it "should be possible to dispute the annotation" do
expect(annotation.may_dispute?).to eq(true)
annotation.dispute!
expect(annotation).to be_disputed
end
it "should be possible to unresolve the annotation" do
annotation.dispute!
expect(annotation.may_unresolve?).to eq(true)
annotation.unresolve!
expect(annotation).to be_unresolved
end
end
context "a reply" do
let (:annotation) { build(:response) }
it "should not be possible to resolve the annotation" do
expect(annotation.may_resolve?).to eq(false)
expect {
annotation.resolve!
}.to raise_error(AASM::InvalidTransition)
end
it "should not be possible to dispute the annotation" do
expect(annotation.may_dispute?).to eq(false)
expect {
annotation.dispute!
}.to raise_error(AASM::InvalidTransition)
end
end
context "if the paper is under review" do
it "should be possible to resolve the annotation" do
annotation = build(:issue, paper:create(:paper, :under_review))
expect(annotation.may_resolve?).to eq(true)
annotation.resolve!
expect(annotation).to be_resolved
end
it "should be possible to dispute the annotation" do
annotation = build(:issue, paper:create(:paper, :under_review))
expect(annotation.may_dispute?).to eq(true)
annotation.dispute!
expect(annotation).to be_disputed
end
it "should be possible to unresolve the annotation" do
annotation = build(:issue, :disputed, paper:create(:paper, :under_review))
expect(annotation.may_unresolve?).to eq(true)
annotation.unresolve!
expect(annotation).to be_unresolved
end
end
context "for any other paper state" do
Paper.aasm.states.each do |state|
next if state.name == :under_review
it "should not be possible to resolve the annotation when the paper is #{state.name}" do
annotation = build(:issue, paper:create(:paper, state:state.name))
expect(annotation.may_resolve?).to eq(false)
expect {
annotation.resolve!
}.to raise_error(AASM::InvalidTransition)
expect(annotation).not_to be_resolved
end
it "should not be possible to dispute the annotation when the paper is #{state.name}" do
annotation = build(:issue, paper:create(:paper, state:state.name))
expect(annotation.may_dispute?).to eq(false)
expect {
annotation.dispute!
}.to raise_error(AASM::InvalidTransition)
expect(annotation).not_to be_disputed
end
it "should not be possible to unresolve the annotation when the paper is #{state.name}" do
annotation = build(:issue, :disputed, paper:create(:paper, :under_review))
annotation.paper.state = state.name
expect(annotation.may_unresolve?).to eq(false)
expect {
annotation.unresolve!
}.to raise_error(AASM::InvalidTransition)
expect(annotation).not_to be_unresolved
end
end
end
context "if the paper is being accepted" do
it "should be possible to resolve the annotation" do
paper = create(:paper, :review_completed)
annotation = create(:issue, paper:paper)
expect(annotation).not_to be_resolved
paper.accept!
expect(annotation.reload).to be_resolved
end
end
end
describe "Abilities" do
context "creating a new annotation on a paper" do
it "AS AUTHOR: should be able to create an annotation on own paper" do
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
ability = Ability.new(user, paper)
expect(ability).to be_able_to(:create, Annotation)
expect(ability).to be_able_to(:annotate, paper)
end
it "WITHOUT ROLE: should not be possible to annotate someone else's paper" do
user = create(:user)
paper = create(:paper)
ability = Ability.new(user, paper)
assert ability.cannot?(:create, Annotation.new(paper: paper, body: "Blah"))
end
it "AS REVIEWER: should be possible to annotate paper" do
user = create(:user)
paper = create(:paper)
assignment = create(:assignment, :reviewer, user:user, paper:paper)
ability = Ability.new(user, paper)
assert ability.can?(:create, Annotation.new(paper: paper, assignment: assignment, body: "Blah"))
end
it "AS EDITOR: should be possible to annotate paper" do
editor = create(:editor)
paper = create(:paper, editor: editor)
ability = Ability.new(editor, paper)
assert ability.can?(:create, Annotation.new(paper: paper, body: "Blah"))
end
end
context "Reading an annotation" do
it "AS AUTHOR: should be possible to read their own annotations on their paper" do
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
annotation = create(:annotation, paper:paper)
ability = Ability.new(user, paper, annotation)
assert ability.can?(:read, annotation)
end
it "AS AUTHOR: should be possible to read someone else's annotations on their paper" do
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
commentor = create(:user)
assign = create(:assignment, paper:paper, user:commentor)
annotation = create(:annotation, paper:paper, assignment:assign)
ability = Ability.new(user, paper, annotation)
assert ability.can?(:read, annotation)
end
it "WITHOUT ROLE: should not be possible to read annotations on someone else's paper" do
user = create(:user)
paper = create(:paper) # note user doesn't own paper
ability = Ability.new(user, paper)
annotation = create(:annotation, paper: paper)
assert ability.cannot?(:read, annotation)
end
it "AS EDITOR: should be possible to read annotation on paper" do
editor = create(:editor)
user = create(:user)
paper = create(:paper, submittor:user, editor:editor)
annotation = create(:annotation, paper: paper)
ability = Ability.new(editor, paper, annotation)
assert ability.can?(:read, annotation)
end
end
context "Updating an annotation" do
it "AS AUTHOR: should not be able to update annotation if there are responses" do
editor = create(:editor)
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
annotation_1 = create(:annotation, user:user, paper:paper)
annotation_2 = create(:annotation, user:editor, paper:paper, parent:annotation_1)
annotation_1.reload
ability = Ability.new(user, paper, annotation_1)
assert ability.cannot?(:update, annotation_1)
end
end
context "Updating an annotation" do
it "AS AUTHOR: should not be able to delete own annotations" do
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
annotation = create(:annotation, user: user, paper: paper)
ability = Ability.new(user, paper, annotation)
assert ability.cannot?(:destroy, annotation)
end
it "AS EDITOR: should be possible to delete annotations" do
editor = create(:editor)
user = create(:user)
paper = create(:paper, submittor:user, editor:editor)
annotation = create(:annotation, paper:paper)
ability = Ability.new(editor, paper, annotation)
assert ability.can?(:destroy, annotation)
end
end
context "Changing the state of an annotation" do
it "should be possible to dispute your own annotations" do
user = create(:user)
paper = create(:paper, submittor:user)
annotation = build(:annotation, paper:paper, user:user)
ability = Ability.new(user, paper)
assert ability.can?(:dispute, annotation)
end
it "should be possible to resolve your own annotations" do
user = create(:user)
paper = create(:paper, submittor:user)
annotation = build(:annotation, paper:paper, user:user)
ability = Ability.new(user, paper)
assert ability.can?(:resolve, annotation)
end
it "should be possible to unresolve your own annotations" do
user = create(:user)
paper = create(:paper, submittor:user)
annotation = build(:annotation, paper:paper, user:user)
ability = Ability.new(user, paper)
assert ability.can?(:unresolve, annotation)
end
it "should not be possible to dispute annotations that are not your own" do
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
annotation = create(:annotation, user:create(:user), paper:paper)
ability = Ability.new(user, paper, annotation)
assert ability.cannot?(:dispute, annotation)
end
it "should not be possible to resolve annotations that are not your own" do
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
annotation = create(:annotation, user:create(:user), paper:paper)
ability = Ability.new(user, paper, annotation)
assert ability.cannot?(:resolve, annotation)
end
it "should not be possible to unresolve annotations that are not your own" do
user = create(:user)
paper = create(:paper, :submitted, submittor:user)
annotation = create(:annotation, user:create(:user), paper:paper)
ability = Ability.new(user, paper, annotation)
assert ability.cannot?(:unresolve, annotation)
end
it "WITHOUT ROLE: should not be possible to dispute annotations on someone else's paper" do
user = create(:user)
paper = create(:paper) # note user doesn't own paper
ability = Ability.new(user, paper)
annotation = create(:annotation, paper: paper)
assert ability.cannot?(:dispute, annotation)
end
it "WITHOUT ROLE: should not be possible to resolve annotations on someone else's paper" do
user = create(:user)
paper = create(:paper) # note user doesn't own paper
ability = Ability.new(user, paper)
annotation = create(:annotation, paper: paper)
assert ability.cannot?(:resolve, annotation)
end
it "WITHOUT ROLE: should not be possible to unresolve annotations on someone else's paper" do
user = create(:user)
paper = create(:paper) # note user doesn't own paper
ability = Ability.new(user, paper)
annotation = create(:annotation, paper: paper)
assert ability.cannot?(:unresolve, annotation)
end
it "AS EDITOR: should be possible to dispute annotation on paper" do
editor = create(:editor)
user = create(:user)
paper = create(:paper, submittor:user, editor: editor)
annotation = create(:annotation, paper: paper)
ability = Ability.new(editor, paper, annotation)
assert ability.can?(:dispute, annotation)
end
it "AS EDITOR: should be possible to resolve annotation on paper" do
editor = create(:editor)
user = create(:user)
paper = create(:paper, submittor:user, editor: editor)
annotation = create(:annotation, paper:paper)
ability = Ability.new(editor, paper, annotation)
assert ability.can?(:resolve, annotation)
end
it "AS EDITOR: should be possible to unresolve annotation on paper" do
editor = create(:editor)
user = create(:user)
paper = create(:paper, submittor:user, editor:editor)
annotation = create(:annotation, paper:paper)
ability = Ability.new(editor, paper, annotation)
assert ability.can?(:unresolve, annotation)
end
end
end
describe 'Validation' do
it "should validate if the parent is nil" do
paper = create(:paper)
annotation1 = Annotation.new(paper:paper, body:'Issue 1', assignment:paper.assignments.first)
expect(annotation1).to be_valid
end
it "should validate if the parent has the same paper" do
paper = create(:paper)
annotation1 = Annotation.create!(paper:paper, body:'Issue 1', assignment:paper.assignments.first)
annotation2 = Annotation.new(paper:paper, body:'Issue 1', parent:annotation1, assignment:paper.assignments.first)
expect(annotation2).to be_valid
end
it "should not validate if the assignee is not from the same paper" do
assignment = create(:assignment)
paper = create(:paper)
annotation = Annotation.new(paper:paper, body:'Issue 1', assignment:assignment)
expect(annotation).to be_invalid
end
it "should not validate if the parent annotation is from a different paper" do
paper1 = create(:paper)
annotation1 = Annotation.create!(paper:paper1, body:'Issue 1', assignment:paper1.assignments.first)
paper2 = create(:paper)
annotation2 = Annotation.new(paper:paper2, body:'Issue 1', parent:annotation1, assignment:paper2.assignments.first)
expect(annotation2).to be_invalid
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/models/user_spec.rb | spec/models/user_spec.rb | require "rails_helper"
describe User do
it "should initialize properly" do
user = create(:user)
assert !user.sha.nil?
expect(user.sha.length).to eq(32)
end
describe "validation" do
describe "email" do
it "should validate nil" do
u = build(:user, email:nil)
expect(u).to be_valid
end
it "should validate an email" do
u = build(:user, email:'123+4@abc.com')
expect(u).to be_valid
end
it "should flag invalid emails" do
u = build(:user, email:'123+4abc.com')
expect(u).not_to be_valid
end
it "should flag blank emails" do
u = build(:user, email:'')
expect(u).not_to be_valid
end
end
end
describe "#reviewer_of?" do
it "should return correct reviewer assignments" do
user = create(:user)
paper = create(:paper, :submitted)
create(:assignment, :reviewer, user:user, paper:paper)
assert user.reviewer_of?(paper)
assert !user.author_of?(paper)
assert !user.collaborator_on?(paper)
end
end
describe "#collaborator_on?" do
it "should return correct collaborator assignments" do
user = create(:user)
paper = create(:paper, :submitted)
create(:assignment, :collaborator, user:user, paper:paper)
assert user.collaborator_on?(paper)
assert !user.reviewer_of?(paper)
assert !user.author_of?(paper)
end
end
describe "#author_of?" do
it "should know who the author is" do
user = create(:user)
paper = create(:paper, submittor:user)
assert user.author_of?(paper)
assert !user.reviewer_of?(paper)
assert !user.collaborator_on?(paper)
end
end
describe "#editor_of?" do
it "should know who the editor is" do
user = create(:user)
editor1 = set_paper_editor
paper1 = create(:paper, submittor:user)
paper2 = create(:paper, submittor:user)
editor2 = set_paper_editor
paper3 = create(:paper, submittor:user)
assert editor1.editor_of?(paper1)
assert editor1.editor_of?(paper2)
assert !editor1.editor_of?(paper3)
assert !editor1.reviewer_of?(paper1)
assert !editor1.collaborator_on?(paper1)
end
end
end | ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/models/assignment_spec.rb | spec/models/assignment_spec.rb | require "rails_helper"
describe Assignment do
let(:arxiv_doc) do
{
provider_type: :arxiv,
provider_id: "1311.1653",
version: 2,
authors: "Mar Álvarez-Álvarez, Angeles I. Díaz",
document_location: "https://arxiv.org/pdf/1311.1653v2.pdf",
title: "A photometric comprehensive study of circumnuclear star forming rings: the sample",
summary: "We present photometry.*in a second paper."
}
end
it "WITHOUT ROLE: should not be able to assign papers" do
user_1 = create(:user)
paper = create(:paper, :submitted, submittor:user_1)
user_2 = create(:user)
ability = Ability.new(user_1, paper)
assert ability.cannot?(:create, Assignment.new(paper:paper, user:user_2) )
end
it "AS EDITOR: should be able to assign papers" do
editor = create(:editor)
reviewer = create(:user)
paper = create(:paper, :submitted, editor: editor)
ability = Ability.new(editor, paper)
assert ability.can?(:create, Assignment.new(:paper => paper, :user => reviewer, :role => "reviewer"))
end
it "AS EDITOR: should be able to delete paper assignments" do
editor = create(:editor)
reviewer = create(:user)
paper = create(:paper, :submitted, editor: editor)
assignment = create(:assignment, :reviewer, user:reviewer, paper:paper)
ability = Ability.new(editor, paper)
assert ability.can?(:destroy, assignment)
end
it "AS REVIEWER: should return correct assignments" do
reviewer = create(:user)
paper = create(:paper, :submitted)
assignment = create(:assignment, :reviewer, user:reviewer, paper:paper)
assert_includes reviewer.papers_as_reviewer, paper
assert reviewer.papers_as_collaborator.empty?
end
it "AS COLLABORATOR: should return correct assignments" do
collaborator = create(:user)
paper = create(:paper, :submitted)
assignment = create(:assignment, :collaborator, user:collaborator, paper:paper)
assert_includes collaborator.papers_as_collaborator, paper
assert collaborator.papers_as_reviewer.empty?
end
it "AS EDITOR: should be editor for all papers" do
editor1 = set_paper_editor
editor2 = create(:editor)
paper = create(:paper, :submitted)
paper = create(:paper, :submitted)
expect(editor1.papers_as_editor.length).to eq(2)
expect(editor2.papers_as_editor.length).to eq(0)
end
it "should not delete assignments if the they are used in associations" do
p = create(:paper)
a = create(:assignment, paper:p)
expect(a.destroy).to be_truthy
expect(a.errors).to be_empty
expect(a).to be_destroyed
end
it "should not delete assignments if the they are used in associations" do
p = create(:paper)
a = create(:assignment, paper:p)
p.assignments.reload
create(:annotation, paper:p, assignment:a)
expect(a.destroy).to be_falsey
expect(a.errors).not_to be_empty
expect(a).not_to be_destroyed
end
describe "emails" do
it "sends an email to the editor" do
user = create(:user, name:'John Smith', email:'jsmith@example.com')
editor = set_paper_editor( create(:user, email:'editor@example.com') )
expect {
create(:paper, title:'My Paper', submittor:user)
}.to change { deliveries.size }.by(2)
is_expected.to have_sent_email.to('editor@example.com').matching_subject(/Paper Assigned/).matching_body(/as an editor/)
end
it "sends an email when a user is assigned" do
user = create(:user, name:'John Smith', email:'jsmith@example.com')
paper = create(:paper, title:'My Paper', submittor:user)
reviewer = create(:user, email:'reviewer@example.com')
expect {
paper.add_assignee(reviewer)
}.to change { deliveries.size }.by(1)
is_expected.to have_sent_email.to('reviewer@example.com').matching_subject(/Paper Assigned/).matching_body(/as a reviewer/)
end
it "sends emails when a paper is updated" do
user = create(:user, name:'John Smith', email:'jsmith@example.com')
editor = set_paper_editor( create(:user, email:'editor@example.com') )
reviewer = create(:user, email:'reviewer@example.com')
original = create(:paper, title:'My Paper', submittor:user, arxiv_id:'1311.1653', version:1)
original.add_assignee(reviewer)
original.reload
deliveries.clear
expect {
original.create_updated!(arxiv_doc)
}.to change { deliveries.size }.by(3)
is_expected.to have_sent_email.to('editor@example.com').matching_subject(/Paper Updated/)
is_expected.to have_sent_email.to('reviewer@example.com').matching_subject(/Paper Updated/)
end
it "sends the correct emails when a user is assigned after the paper is updated" do
user = create(:user, name:'John Smith', email:'jsmith@example.com')
editor = set_paper_editor( create(:user, email:'editor@example.com') )
original = create(:paper, title:'My Paper', submittor:user, arxiv_id:'1311.1653', version:1)
updated = original.create_updated!(arxiv_doc)
deliveries.clear
reviewer = create(:user, email:'reviewer@example.com')
expect {
updated.add_assignee(reviewer)
}.to change { deliveries.size }.by(1)
is_expected.to have_sent_email.to('reviewer@example.com').matching_subject(/Paper Assigned/)
end
end
describe "#public" do
it "should set the initial value based on the role" do
expect( create(:assignment, role:'editor').public).to be_truthy
expect( create(:assignment, role:'submittor').public).to be_truthy
expect( create(:assignment, role:'collaborator').public).to be_truthy
expect( create(:assignment, role:'reviewer').public).to be_falsy
end
end
describe "#make_user_info_public?" do
it "should make editor info public" do
any_user = create(:user)
assignment = create(:assignment, role:'editor')
expect( assignment.make_user_info_public?(any_user) ).to be_truthy
end
it "should make submittor and collaborator info public" do
any_user = create(:user)
assignment = create(:assignment, role:'submittor')
expect( assignment.make_user_info_public?(any_user) ).to be_truthy
assignment = create(:assignment, role:'collaborator')
expect( assignment.make_user_info_public?(any_user) ).to be_truthy
end
it "reviewer info should not be public" do
any_user = create(:user)
assignment = create(:assignment, role:'reviewer')
expect( assignment.make_user_info_public?(any_user) ).to be_falsy
end
it "info should be available to the assigned user" do
user = create(:user)
assignment = create(:assignment, role:'reviewer', user:user)
expect( assignment.make_user_info_public?(user) ).to be_truthy
end
it "info should be available to the editor" do
editor = create(:editor)
assignment = create(:assignment, role:'reviewer')
assignment.paper.assignments.create!(user:editor, role:'editor')
expect( assignment.make_user_info_public?(editor) ).to be_truthy
end
end
describe "#use_completed?" do
it "only reviewers should use completed" do
expect( create(:assignment, role:'reviewer').use_completed?).to be_truthy
expect( create(:assignment, role:'submittor').use_completed?).to be_falsy
expect( create(:assignment, role:'collaborator').use_completed?).to be_falsy
expect( create(:assignment, role:'editor').use_completed?).to be_falsy
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/models/provider/arxiv_provider_spec.rb | spec/models/provider/arxiv_provider_spec.rb | require_relative 'shared_provider_specs'
require "rails_helper"
describe Provider::ArxivProvider do
def stub_document
stub_request(:get, "http://export.arxiv.org/api/query?id_list=1311.1653v2").to_return(fixture('arxiv/1311.1653v2.xml'))
end
def stub_document_without_version
stub_request(:get, "http://export.arxiv.org/api/query?id_list=1311.1653").to_return(fixture('arxiv/1311.1653v2.xml'))
end
def stub_document_not_found
stub_request(:get, "http://export.arxiv.org/api/query?id_list=1311.1653v2").to_return(fixture('arxiv/not_found.xml'))
end
def document_id
'1311.1653v2'
end
def document_id_without_version
'1311.1653'
end
def version
2
end
def expected_attributes
{
provider_type: :arxiv,
provider_id: "1311.1653",
version: 2,
authors: "Mar Álvarez-Álvarez, Angeles I. Díaz",
document_location: "https://arxiv.org/pdf/1311.1653v2.pdf",
title: "A photometric comprehensive study of circumnuclear star forming rings: the sample",
summary: a_string_matching(/^We present photometry.*in a second paper.$/)
}
end
it_should_behave_like 'All providers'
it "should include the original message when a document is not found" do
stub_document_not_found
expect{ described_class.get_attributes(document_id) }.to raise_exception(Provider::Error::DocumentNotFound).with_message("Manuscript 1311.1653v2 doesn't exist on arXiv")
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
openjournals/theoj | https://github.com/openjournals/theoj/blob/73c6acccc0aefe64b0030c818f405b25b7e7b589/spec/models/provider/shared_provider_specs.rb | spec/models/provider/shared_provider_specs.rb | require "rails_helper"
shared_examples 'All providers' do
def provider; described_class; end
it "should have the required class interface" do
expect(provider).to respond_to(:type).with(0).arguments
expect(provider).to respond_to(:get_attributes).with(1).argument
expect(provider).to respond_to(:full_identifier).with(0).arguments
expect(provider).to respond_to(:parse_identifier).with(1).argument
end
it "should have a symbolic name" do
expect(provider.type).to be_present
expect(provider.type).to be_a(Symbol)
end
it "should be registered" do
expect(Provider.get(provider.type)).to eq(provider)
end
describe "::get_attributes" do
shared_examples 'get attributes' do
it "should return attributes" do
stub_document
attributes = provider.get_attributes(id_to_get)
expect(attributes).to be_a(Hash)
end
it "should be able to create a paper" do
stub_document
attributes = provider.get_attributes(id_to_get)
attributes = attributes.merge( submittor: create(:user) )
expect{ Paper.create(attributes) }.not_to raise_exception
end
it "should have the key attributes" do
stub_document
expect(provider.get_attributes(id_to_get)).to include(
provider_type: an_instance_of(Symbol),
provider_id: an_instance_of(String),
version: an_instance_of(Fixnum)
)
end
it "the provider type should match" do
stub_document
attributes = provider.get_attributes(id_to_get)
expect(attributes[:provider_type]).to be_a(Symbol)
expect(attributes[:provider_type]).to eq(provider.type)
end
it "the id and version should match" do
stub_document
attributes = provider.get_attributes(id_to_get)
expect(attributes[:provider_id]).to eq(document_id_without_version)
expect(attributes[:version]).to eq(version)
end
it "the id and version should round trip" do
stub_document
attributes = provider.get_attributes(id_to_get)
paper = Paper.new(attributes)
expect(paper.full_provider_id).to eq(document_id)
end
it "should have the secondary attributes" do
stub_document
expect(provider.get_attributes(id_to_get)).to include(
:authors,
:document_location,
:title,
:summary
)
end
it "should return the correct attributes" do
stub_document
expect(provider.get_attributes(id_to_get)).to match(expected_attributes)
end
end
describe "using a document id" do
before do stub_document end
let(:id_to_get) { document_id }
it_should_behave_like 'get attributes'
end
describe "using a document id without a version" do
before do stub_document_without_version end
let(:id_to_get) { document_id_without_version }
it_should_behave_like 'get attributes'
end
it "should raise a DocumentNotFound exception if the document is not found" do
stub_document_not_found
expect{ provider.get_attributes(document_id) }.to raise_exception(Provider::Error::DocumentNotFound)
end
end
describe "::full_identifier" do
it "should create a matching full id" do
paper = Paper.new(
provider_type: provider.type,
provider_id: document_id_without_version,
version: version
)
expect(provider.full_identifier(provider_id:document_id_without_version, version:version)).to eq(document_id)
end
it "should create a matching full id without a version" do
paper = Paper.new(
provider_type: provider.type,
provider_id: document_id_without_version,
version: version
)
expect(provider.full_identifier(provider_id:document_id_without_version)).to eq(document_id_without_version)
end
end
describe "::parse_identifier" do
it "should split the identifier into 2 correct parts" do
result = provider.parse_identifier(document_id)
expect(result).to eq({provider_id:document_id_without_version, version:version})
end
it "should split an identifier without version info into 1 correct part" do
result = provider.parse_identifier(document_id_without_version)
expect(result.length).to eq(1)
expect(result).to eq({provider_id:document_id_without_version})
end
it "should fail for an invalid identifier" do
expect {
provider.parse_identifier('~!@#$%^&*()')
}.to raise_exception(Provider::Error::InvalidIdentifier)
end
end
end
| ruby | MIT | 73c6acccc0aefe64b0030c818f405b25b7e7b589 | 2026-01-04T17:49:58.613320Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.