Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Merge 29e809f into aef630f
Browse files Browse the repository at this point in the history
  • Loading branch information
JPrevost committed Nov 17, 2015
2 parents aef630f + 29e809f commit 21bcab5
Show file tree
Hide file tree
Showing 22 changed files with 311 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -17,3 +17,7 @@
/tmp
coverage
.env

.byebug_history

*.lock
4 changes: 2 additions & 2 deletions .rubocop.yml
Expand Up @@ -4,5 +4,5 @@ Documentation:
AllCops:
RunRailsCops: true
Exclude:
- db/**
- config/**
- db/**/*
- config/**/*
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: ruby
rvm:
- 2.2.3
sudo: false
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -2,6 +2,7 @@ source 'https://rubygems.org'
ruby '2.2.3'

gem 'rails', '4.2.5'
gem 'bootstrap_form'
gem 'devise'
gem 'http_logger'
gem 'jquery-rails'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -47,6 +47,7 @@ GEM
bcrypt (3.1.10)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap_form (2.3.0)
builder (3.2.2)
byebug (8.2.0)
capybara (2.5.0)
Expand Down Expand Up @@ -251,6 +252,7 @@ PLATFORMS

DEPENDENCIES
annotate
bootstrap_form
byebug
coveralls
devise
Expand Down
9 changes: 9 additions & 0 deletions README.md
@@ -0,0 +1,9 @@
# QuickSubmit

[![Build Status](https://travis-ci.org/MITLibraries/QuickSubmit.svg)](https://travis-ci.org/MITLibraries/QuickSubmit)
[![Dependency Status](https://gemnasium.com/MITLibraries/QuickSubmit.svg)](https://gemnasium.com/MITLibraries/QuickSubmit)
[![Code Climate](https://codeclimate.com/github/MITLibraries/QuickSubmit/badges/gpa.svg)](https://codeclimate.com/github/MITLibraries/QuickSubmit)

## What is this?

QuickSubmit will be a brief form where users can upload an article along with sparse metadata. This will be transformed into METS and then SWORD and submitted to an Institutional Repository (DSpace for now).
28 changes: 0 additions & 28 deletions README.rdoc

This file was deleted.

1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css
Expand Up @@ -12,4 +12,5 @@
*
*= require_tree .
*= require_self
*= require rails_bootstrap_forms
*/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/submission.css
@@ -0,0 +1,3 @@
label.required:after {
content:" *";
}
26 changes: 26 additions & 0 deletions app/controllers/submissions_controller.rb
@@ -0,0 +1,26 @@
class SubmissionsController < ApplicationController
before_action :authenticate_user!

def new
@submission = Submission.new
@submission.user = current_user
end

def create
@submission = Submission.new(submission_params)
@submission.user = current_user
if @submission.save
flash.notice = 'Your Submission is now in progress.'
redirect_to root_path
else
render 'new'
end
end

private

def submission_params
params.require(:submission).permit(:title, :agreed_to_license, :author,
:journal, :doi, :grant_number, :doe)
end
end
23 changes: 23 additions & 0 deletions app/models/submission.rb
@@ -0,0 +1,23 @@
# == Schema Information
#
# Table name: submissions
#
# id :integer not null, primary key
# user_id :integer
# title :string not null
# journal :string
# doi :string
# author :string
# doe :boolean
# grant_number :string
# agreed_to_license :boolean
# created_at :datetime not null
# updated_at :datetime not null
#

class Submission < ActiveRecord::Base
belongs_to :user
validates :user, presence: true
validates :title, presence: true
validates :agreed_to_license, inclusion: { in: [true] }
end
1 change: 1 addition & 0 deletions app/models/user.rb
Expand Up @@ -11,6 +11,7 @@

class User < ActiveRecord::Base
devise :omniauthable, omniauth_providers: [:mit_oauth2]
has_many :submissions

def self.from_omniauth(auth)
where(uid: auth.uid).first_or_create do |user|
Expand Down
23 changes: 23 additions & 0 deletions app/views/submissions/new.html.erb
@@ -0,0 +1,23 @@
<h1>MIT DSpace Quick Submit</h1>

<%= bootstrap_form_for(@submission, layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10") do |f| %>
<%= f.alert_message "Please fix the errors below." %>
<%= f.text_field :author %>
<%= f.text_field :title %>
<%= f.text_field :journal %>
<%= f.text_field :doi %>
<%= f.text_field :grant_number %>
<%= f.form_group :doe do %>
<%= f.check_box :doe, label: "This submission was funded in part by grants from the DOE." %>
<% end %>
<%= f.form_group :agreed_to_license do %>
<%= f.check_box :agreed_to_license,
label: "I am authorized to submit this article." %>
<% end %>
<%= f.form_group do %>
<%= f.submit %>
<% end %>
<% end %>
4 changes: 3 additions & 1 deletion config/routes.rb
@@ -1,10 +1,12 @@
Rails.application.routes.draw do
resources :submissions, only: [:new, :create]

devise_for :users, :controllers => {
:omniauth_callbacks => 'users/omniauth_callbacks'
}

devise_scope :user do
get 'sign_in', to: 'devise/sessions#new', as: :new_user_session
get 'sign_in', to: 'devise/sessions#new', as: :user_session
delete 'sign_out', to: 'devise/sessions#destroy', as: :destroy_user_session
end

Expand Down
17 changes: 17 additions & 0 deletions db/migrate/20151116184904_create_submissions.rb
@@ -0,0 +1,17 @@
class CreateSubmissions < ActiveRecord::Migration
def change
create_table :submissions do |t|
t.belongs_to :user, index: true

t.string :title, null: false
t.string :journal
t.string :doi
t.string :author
t.boolean :doe
t.string :grant_number
t.boolean :agreed_to_license

t.timestamps null: false
end
end
end
17 changes: 16 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,22 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150101010101) do
ActiveRecord::Schema.define(version: 20151116184904) do

create_table "submissions", force: :cascade do |t|
t.integer "user_id"
t.string "title", null: false
t.string "journal"
t.string "doi"
t.string "author"
t.boolean "doe"
t.string "grant_number"
t.boolean "agreed_to_license"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "submissions", ["user_id"], name: "index_submissions_on_user_id"

create_table "users", force: :cascade do |t|
t.string "email", null: false
Expand Down
25 changes: 25 additions & 0 deletions test/controllers/submissions_controller_test.rb
@@ -0,0 +1,25 @@
require 'test_helper'

class SubmissionsControllerTest < ActionController::TestCase
test 'non signed in user should redirect to login requesting new' do
get :new
assert_response :redirect
end

test 'signed in user should get new' do
sign_in users(:one)
get :new
assert_response :success
end

test 'non signed in user should redirect to login posting to create' do
post :create
assert_response :redirect
end

test 'signed in user can post to create' do
sign_in users(:one)
post :create, submission: { 'title': '' }
assert_response :success
end
end
8 changes: 4 additions & 4 deletions test/features/static_test.rb
Expand Up @@ -15,8 +15,8 @@ def teardown

test 'sign in link' do
visit root_path
assert page.has_link?('Sign in')
refute page.has_link?('Sign out')
assert_link('Sign in')
refute_link('Sign out')
end

test 'sign out link' do
Expand All @@ -27,7 +27,7 @@ def teardown

visit '/users/auth/mit_oauth2/callback'
visit root_path
assert page.has_link?('Sign out')
refute page.has_link?('Sign in')
assert_link('Sign out')
refute_link('Sign in')
end
end
70 changes: 70 additions & 0 deletions test/features/submission_test.rb
@@ -0,0 +1,70 @@
require 'test_helper'

class SubmissionPagesTest < Capybara::Rails::TestCase
def setup
Rails.application.env_config['devise.mapping'] = Devise.mappings[:user]
Rails.application.env_config['omniauth.auth'] =
OmniAuth.config.mock_auth[:mit_oauth2]
OmniAuth.config.test_mode = true
end

def teardown
OmniAuth.config.test_mode = false
OmniAuth.config.mock_auth[:mit_oauth2] = nil
end

def mock_auth
OmniAuth.config.mock_auth[:mit_oauth2] =
OmniAuth::AuthHash.new(provider: 'mit_oauth2',
uid: '123545',
info: { email: 'bob@asdf.com' })
visit '/users/auth/mit_oauth2/callback'
end

test 'requires signed_in user' do
visit new_submission_path
assert_equal(root_path, current_path)
assert_text('Sign in')
assert_text('You need to sign in or sign up before continuing.')
end

test 'authenticated users can view the form' do
mock_auth
visit new_submission_path
assert_equal(new_submission_path, current_path)
end

test 'invalid form retains valid portions' do
mock_auth
visit new_submission_path
fill_in('Journal', with: 'Super Mega Journal')
click_on('Create Submission')
assert_text('Please fix the errors below')
assert_text("Title can't be blank")
assert_text('Agreed to license is not included in the list')
assert_selector("input[value='Super Mega Journal']")
end

test 'invalid form submit does not create new submissions' do
mock_auth
subs = Submission.count
visit new_submission_path
fill_in('Journal', with: 'Super Mega Journal')
click_on('Create Submission')
assert_equal(Submission.count, subs)
end

test 'valid form creates new submission' do
mock_auth
subs = Submission.count
visit new_submission_path
fill_in('Journal', with: 'Super Mega Journal')
fill_in('Title', with: 'Alphabetical Order is Good Enough')
check('I am authorized to submit this article.')
click_on('Create Submission')
assert_equal(Submission.count, (subs + 1))
assert_equal('bob@asdf.com', Submission.last.user.email)
assert_equal(root_path, current_path)
assert_text('Your Submission is now in progress')
end
end
33 changes: 33 additions & 0 deletions test/fixtures/submissions.yml
@@ -0,0 +1,33 @@
# == Schema Information
#
# Table name: submissions
#
# id :integer not null, primary key
# user_id :integer
# title :string not null
# journal :string
# doi :string
# author :string
# doe :boolean
# grant_number :string
# agreed_to_license :boolean
# created_at :datetime not null
# updated_at :datetime not null
#

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

sub_one:
title: 'Popcorn is a fruit.'
agreed_to_license: true
user: one

sub_two:
title: 'Simple Secret Substitution Songs'
user: two
journal: 'Journal of Popcorn Management'
doi: 'doi:10.10.1038/nphys1170'
author: 'Lastname, Firstname'
doe: true
grant_number: 'asdf123'
agreed_to_license: true
2 changes: 1 addition & 1 deletion test/integration/authentication_test.rb
Expand Up @@ -15,7 +15,7 @@ def teardown

def silence_omniauth
previous_logger = OmniAuth.config.logger
# OmniAuth.config.logger = Logger.new('/dev/null')
OmniAuth.config.logger = Logger.new('/dev/null')
yield
ensure
OmniAuth.config.logger = previous_logger
Expand Down

0 comments on commit 21bcab5

Please sign in to comment.