-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add conference exports model to conference
- Loading branch information
Showing
13 changed files
with
171 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class ConferenceExport < ActiveRecord::Base | ||
belongs_to :conference | ||
attr_accessible :locale, :tarball | ||
has_attached_file :tarball | ||
validates_attachment_content_type :tarball, content_type: [/gzip/] | ||
validates_presence_of :locale, :conference | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateConferenceExports < ActiveRecord::Migration | ||
def change | ||
create_table :conference_exports do |t| | ||
t.string :locale | ||
t.references :conference | ||
t.string :tarball_file_name | ||
t.string :tarball_content_type | ||
t.integer :tarball_file_size | ||
t.datetime :tarball_updated_at | ||
t.timestamps | ||
end | ||
add_index :conference_exports, :conference_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'test_helper' | ||
|
||
class StaticProgramExportTask < ActionDispatch::IntegrationTest | ||
|
||
setup do | ||
@conference = create(:three_day_conference) | ||
@target_dir = File.join(Rails.root, 'tmp', 'static_export', @conference.acronym) | ||
end | ||
|
||
test "can run program export task" do | ||
locale = 'en' | ||
|
||
load File.join(Rails.root, 'lib', 'tasks', 'static_program_export.rake') | ||
Rake::Task.define_task(:environment) | ||
ENV['CONFERENCE'] = @conference.acronym | ||
ENV['CONFERENCE_LOCALE'] = locale | ||
ENV['RAILS_ENV'] = Rails.env | ||
Rake.application.invoke_task "frab:static_program_export" | ||
|
||
assert File.directory? @target_dir | ||
end | ||
|
||
teardown do | ||
FileUtils.remove_dir @target_dir | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'test_helper' | ||
|
||
class ConferenceExportTest < ActiveSupport::TestCase | ||
|
||
test "can create a conference export" do | ||
conference_export = FactoryGirl.create :conference_export | ||
assert_not_nil conference_export.tarball | ||
assert File.readable? conference_export.tarball.path | ||
assert_not_nil conference_export.conference | ||
assert_not_nil conference_export.id | ||
end | ||
|
||
test "can update a conference export attachment" do | ||
file = File.open(File.join(Rails.root, 'test', 'fixtures', 'tarball.tar.gz')) | ||
conference_export = FactoryGirl.create :conference_export, tarball: file | ||
conference_export.save | ||
assert File.readable? conference_export.tarball.path | ||
end | ||
|
||
test "can update conference export with tarball" do | ||
conference = FactoryGirl.create(:three_day_conference) | ||
locale = 'en' | ||
file = File.join(Rails.root, 'test', 'fixtures', 'tarball.tar.gz') | ||
|
||
assert_difference 'ConferenceExport.count' do | ||
conference_export = ConferenceExport.where(conference_id: conference.id, locale: locale).first_or_create | ||
conference_export.update_attributes tarball: File.open(file) | ||
end | ||
conference_export = ConferenceExport.where(conference_id: conference.id, locale: locale).first | ||
assert_not_nil conference_export.tarball | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'test_helper' | ||
|
||
class StaticProgramExportTest < ActiveSupport::TestCase | ||
setup do | ||
@conference = create(:three_day_conference) | ||
@locale = 'en' | ||
@target_dir = File.join(Rails.root, 'tmp', 'static_export', @conference.acronym) | ||
end | ||
|
||
test "static exporter can create a tarball" do | ||
exporter = StaticProgramExport.new(@conference, @locale) | ||
FileUtils.mkdir_p File.join(StaticProgramExport::EXPORT_PATH, @conference.acronym) | ||
assert_equal exporter.create_tarball, File.join(Rails.root, 'tmp', 'static_export', @conference.acronym + '-en.tar.gz') | ||
end | ||
|
||
test "static exporter can run export" do | ||
exporter = StaticProgramExport.new(@conference, @locale) | ||
exporter.run_export | ||
assert File.directory? @target_dir | ||
end | ||
|
||
teardown do | ||
FileUtils.remove_dir @target_dir | ||
end | ||
end |