Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem 'nokogiri'
gem 'omniauth-mit-oauth2'
gem 'omniauth-oauth2', '~> 1.3.1'
gem 'passenger'
gem 'rubyzip', require: 'zip'
gem 'therubyracer', platforms: :ruby
gem 'twitter-bootstrap-rails'
gem 'uglifier', '>= 1.3.0'
Expand Down
24 changes: 14 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/carrierwaveuploader/carrierwave.git
revision: 08d0aea29b058c1b98db1c19f4ccd37c9105e9eb
revision: e3acabb512cb55b683b6d74a63db0723f06df091
specs:
carrierwave (0.10.0)
activemodel (>= 3.2.0)
Expand Down Expand Up @@ -67,10 +67,11 @@ GEM
rack-test (>= 0.5.4)
xpath (~> 2.0)
commonjs (0.2.7)
coveralls (0.8.9)
concurrent-ruby (1.0.0)
coveralls (0.8.10)
json (~> 1.8)
rest-client (>= 1.6.8, < 2)
simplecov (~> 0.10.0)
simplecov (~> 0.11.0)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
tins (~> 1.6.0)
Expand Down Expand Up @@ -213,12 +214,14 @@ GEM
ruby-progressbar (~> 1.7)
tins (<= 1.6.0)
ruby-progressbar (1.7.5)
simplecov (0.10.0)
rubyzip (1.1.7)
simplecov (0.11.1)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
sprockets (3.4.1)
sprockets (3.5.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (2.3.3)
actionpack (>= 3.0)
Expand All @@ -234,11 +237,11 @@ GEM
thread_safe (0.3.5)
tilt (2.0.1)
tins (1.6.0)
twitter-bootstrap-rails (3.2.0)
actionpack (~> 4.1)
execjs (~> 2.2)
rails (~> 4.1)
railties (~> 4.1)
twitter-bootstrap-rails (3.2.2)
actionpack (>= 3.1)
execjs (>= 2.2.2, >= 2.2)
less-rails (>= 2.5.0)
railties (>= 3.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.2)
Expand Down Expand Up @@ -281,6 +284,7 @@ DEPENDENCIES
rails (= 4.2.5)
rails_12factor
rubocop
rubyzip
sqlite3
therubyracer
twitter-bootstrap-rails
Expand Down
14 changes: 14 additions & 0 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,18 @@ class Submission < ActiveRecord::Base
def to_mets
Mets.new(self).to_xml
end

def sword_path
md5 = Digest::MD5.new
"tmp/#{md5.update(id.to_s)}.zip"
end

def to_sword_package
Zip::File.open(sword_path, Zip::File::CREATE) do |zipfile|
documents.each do |document|
zipfile.add(document.file.filename, document.file.file)
end
zipfile.get_output_stream('mets.xml') { |os| os.write to_mets }
end
end
end
34 changes: 34 additions & 0 deletions test/models/submission_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,38 @@ class SubmissionTest < ActiveSupport::TestCase
assert_equal(true, xsd.valid?(doc))
end
end

test '#sword_package_name' do
sub = submissions(:sub_one)
assert_equal(sub.sword_path, 'tmp/69b9156a124c96bbdb55cad753810e14.zip')
end

def setup_sword_files(sub)
FileUtils.rm_f(sub.sword_path)
FileUtils.mkdir_p('./public/uploads/submission/documents/783478147')
FileUtils.cp(['./test/fixtures/a_pdf.pdf', './test/fixtures/b_pdf.pdf'],
'./public/uploads/submission/documents/783478147')
end

def cleaup_sword_files(sub)
sub.documents.map(&:remove!)
FileUtils.rm_f(sub.sword_path)
end

test '#to_sword_package creates zip file' do
sub = submissions(:sub_one)
setup_sword_files(sub)
sub.to_sword_package
assert_equal(true, File.file?(sub.sword_path))
cleaup_sword_files(sub)
end

test '#to_sword_package zip contains correct files' do
sub = submissions(:sub_one)
setup_sword_files(sub)
sub.to_sword_package
sword = Zip::File.open(sub.sword_path)
assert_equal(['a_pdf.pdf', 'b_pdf.pdf', 'mets.xml'], sword.map(&:name).sort)
cleaup_sword_files(sub)
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'simplecov'
require 'coveralls'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
Expand Down