forked from catima/catima
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73e4351
commit 92a6c60
Showing
10 changed files
with
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
class ExportMailer < ApplicationMailer | ||
def send_message(export) | ||
I18n.locale = export.user.primary_language | ||
@export = export | ||
|
||
mail( | ||
|
@@ -8,5 +9,7 @@ def send_message(export) | |
:from => "[email protected]", | ||
:template_name => "export" | ||
) | ||
ensure | ||
I18n.locale = I18n.default_locale | ||
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 was deleted.
Oops, something went wrong.
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,17 @@ | ||
require "test_helper" | ||
|
||
class CatalogAdmin::ExportsTest < ActionDispatch::IntegrationTest | ||
test "create a catima export" do | ||
log_in_as("[email protected]", "password") | ||
visit("/two/en/admin/_exports") | ||
|
||
assert_difference("Export.count", + 1) do | ||
first("button", :text => "New export (choose format)").click | ||
first("a", :text => "Catima").click | ||
end | ||
|
||
assert(page.has_content?("[email protected]")) | ||
assert(page.has_content?("processing")) | ||
assert(page.has_content?("valid")) | ||
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 |
---|---|---|
@@ -1,3 +1,29 @@ | ||
# Preview all emails at http://localhost:3000/rails/mailers/export_mailer | ||
class ExportMailerPreview < ActionMailer::Preview | ||
%w(de en fr it).each do |locale| | ||
# Preview this email at | ||
# http://localhost:3000/rails/mailers/export_mailer/export_available_en | ||
define_method("export_available_#{locale}") do | ||
catalog = Catalog.first_or_create!( | ||
:name => "Sample", | ||
:slug => "sample", | ||
:primary_language => "en" | ||
) | ||
user = User.new( | ||
:email => "[email protected]", | ||
:primary_language => "en" | ||
) | ||
export = Export.new( | ||
:id => 1, | ||
:user => user, | ||
:catalog => catalog, | ||
:category => "catima", | ||
:status => "ready", | ||
:file => true, | ||
:created_at => Time.zone.now, | ||
:updated_at => Time.zone.now | ||
) | ||
ExportMailer.send_message(export) | ||
end | ||
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 |
---|---|---|
@@ -1,7 +1,29 @@ | ||
require 'test_helper' | ||
|
||
class ExportTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
should validate_presence_of(:user) | ||
should validate_presence_of(:catalog) | ||
should validate_inclusion_of(:category).in_array(%w(catima)) | ||
should validate_inclusion_of(:status).in_array(%w(error processing ready)) | ||
|
||
test "export ready" do | ||
export = exports(:one) | ||
assert(export.ready?) | ||
assert(export.validity?) | ||
assert(export.file?) | ||
end | ||
|
||
test "export error but valid" do | ||
export = exports(:one_error) | ||
refute(export.ready?) | ||
assert(export.validity?) | ||
refute(export.file?) | ||
end | ||
|
||
test "export expired" do | ||
export = exports(:one_expired) | ||
assert(export.ready?) | ||
refute(export.validity?) | ||
refute(export.file?) | ||
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,50 @@ | ||
require "test_helper" | ||
|
||
class ExportPolicyTest < ActiveSupport::TestCase | ||
test "#create? allows admins of the catalog" do | ||
refute(policy(Guest.new, exports(:one)).create?) | ||
refute(policy(users(:one), exports(:one)).create?) | ||
refute(policy(users(:one_member), exports(:one)).create?) | ||
refute(policy(users(:one_editor), exports(:one)).create?) | ||
refute(policy(users(:one_super_editor), exports(:one)).create?) | ||
refute(policy(users(:one_reviewer), exports(:one)).create?) | ||
refute(policy(users(:one_admin), exports(:two)).create?) | ||
assert(policy(users(:one_admin), exports(:one)).create?) | ||
assert(policy(users(:system_admin), exports(:one)).create?) | ||
end | ||
|
||
test "#download? allows admins of the catalog" do | ||
refute(policy(Guest.new, exports(:one)).download?) | ||
refute(policy(users(:one), exports(:one)).download?) | ||
refute(policy(users(:one_member), exports(:one)).download?) | ||
refute(policy(users(:one_editor), exports(:one)).download?) | ||
refute(policy(users(:one_super_editor), exports(:one)).download?) | ||
refute(policy(users(:one_reviewer), exports(:one)).download?) | ||
refute(policy(users(:one_admin), exports(:two)).download?) | ||
assert(policy(users(:one_admin), exports(:one)).download?) | ||
assert(policy(users(:system_admin), exports(:one)).download?) | ||
end | ||
|
||
test "#download? only if export is valid, ready and has file" do | ||
refute(policy(users(:one_admin), exports(:one_expired)).download?) | ||
refute(policy(users(:one_admin), exports(:one_processing)).download?) | ||
refute(policy(users(:one_admin), exports(:one_error)).download?) | ||
assert(policy(users(:one_admin), exports(:one)).download?) | ||
end | ||
|
||
test "#index? allows admins of the catalog" do | ||
refute(policy(Guest.new, exports(:one)).index?) | ||
refute(policy(users(:one), exports(:one)).index?) | ||
refute(policy(users(:one_member), exports(:one)).index?) | ||
refute(policy(users(:one_editor), exports(:one)).index?) | ||
refute(policy(users(:one_super_editor), exports(:one)).index?) | ||
refute(policy(users(:one_reviewer), exports(:one)).index?) | ||
refute(policy(users(:one_admin), exports(:two)).index?) | ||
assert(policy(users(:one_admin), exports(:one)).index?) | ||
assert(policy(users(:system_admin), exports(:one)).index?) | ||
end | ||
|
||
def policy(user, export=exports(:one)) | ||
ExportPolicy.new(user, export) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.