-
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.
refactor mail previews to not use database
- Loading branch information
Showing
7 changed files
with
92 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,47 @@ | ||
class ObservationMailerPreview < ActionMailer::Preview | ||
def admin_observation_published_not_modified | ||
ObservationMailer.admin_observation_published_not_modified admin_observation, User.last | ||
ObservationMailer.admin_observation_published_not_modified observation, test_user | ||
end | ||
|
||
def admin_observation_ready_for_qc | ||
ObservationMailer.admin_observation_ready_for_qc admin_observation, User.last | ||
ObservationMailer.admin_observation_ready_for_qc observation, test_user | ||
end | ||
|
||
def observation_created | ||
ObservationMailer.observation_created observation, User.last | ||
ObservationMailer.observation_created observation, test_user | ||
end | ||
|
||
def observation_submitted_for_qc | ||
ObservationMailer.observation_submitted_for_qc observation, User.last | ||
ObservationMailer.observation_submitted_for_qc observation, test_user | ||
end | ||
|
||
def observation_needs_revision | ||
ObservationMailer.observation_needs_revision observation, User.last | ||
ObservationMailer.observation_needs_revision observation, test_user | ||
end | ||
|
||
def observation_ready_for_publication | ||
ObservationMailer.observation_ready_for_publication observation, User.last | ||
ObservationMailer.observation_ready_for_publication observation, test_user | ||
end | ||
|
||
def observation_published | ||
ObservationMailer.observation_published observation, User.last | ||
ObservationMailer.observation_published observation, test_user | ||
end | ||
|
||
private | ||
|
||
def admin_observation | ||
Observation | ||
.where.not(observation_report: nil) | ||
.where.not(monitor_comment: [nil, ""]) | ||
.last | ||
end | ||
|
||
def observation | ||
Observation | ||
.where.not(observation_report: nil) | ||
.where.not(admin_comment: [nil, ""]) | ||
.last | ||
Observation.new( | ||
id: 100, | ||
observation_type: "operator", | ||
subcategory: Subcategory.new(name: "Conflict of interest - inter or intra agency"), | ||
admin_comment: "Here are some comments made by admin", | ||
monitor_comment: "Here are some comments made by monitor", | ||
observation_report: ObservationReport.new(title: "Report 100"), | ||
modified_user: test_user | ||
) | ||
end | ||
|
||
def test_user | ||
User.new(id: 1, email: "john@example.com", observer: Observer.new(name: "Test Observer"), name: "John Tester", locale: "en", user_permission: UserPermission.new(user_role: "ngo_manager")) | ||
end | ||
end |
51 changes: 37 additions & 14 deletions
51
spec/mailers/previews/operator_document_mailer_preview.rb
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,38 +1,61 @@ | ||
class OperatorDocumentMailerPreview < ActionMailer::Preview | ||
def expiring_documents | ||
OperatorDocumentMailer.expiring_documents operator, operator.all_users.filter_actives.first, documents_expiring | ||
OperatorDocumentMailer.expiring_documents operator, test_user, documents | ||
end | ||
|
||
def expired_documents | ||
OperatorDocumentMailer.expired_documents operator, operator.all_users.filter_actives.first, documents_expired | ||
OperatorDocumentMailer.expired_documents operator, test_user, documents | ||
end | ||
|
||
def document_valid | ||
OperatorDocumentMailer.document_valid OperatorDocument.doc_valid.last, User.filter_actives.first | ||
OperatorDocumentMailer.document_valid valid_document, test_user | ||
end | ||
|
||
def document_invalid | ||
OperatorDocumentMailer.document_invalid OperatorDocument.doc_invalid.where.not(document_file: nil).last, User.filter_actives.first | ||
OperatorDocumentMailer.document_invalid invalid_document, test_user | ||
end | ||
|
||
private | ||
|
||
def documents_expired | ||
OperatorDocument.where(operator_id: operator_id).doc_expired.last(3) | ||
def invalid_document | ||
valid_document.tap do |d| | ||
d.status = "doc_invalid" | ||
d.admin_comment = "Document is invalid because of reasons." | ||
end | ||
end | ||
|
||
def documents_expiring | ||
documents_expired.each { |d| d.expire_date = 30.days.from_now } # workaround just in preview | ||
def valid_document | ||
OperatorDocumentFmu.new( | ||
start_date: 10.days.ago, | ||
expire_date: 2.years.from_now, | ||
fmu: Fmu.new(name: "Ngombe"), | ||
operator: operator, | ||
required_operator_document: RequiredOperatorDocument.new(name: "CITES permits"), | ||
document_file: DocumentFile.new(attachment: File.open(Rails.root.join("spec", "support", "files", "doc.pdf"))), | ||
status: "doc_valid" | ||
) | ||
end | ||
|
||
def operator | ||
Operator.find(operator_id) | ||
def test_user | ||
User.new(email: "john@example.com", name: "John Tester", locale: "en") | ||
end | ||
|
||
def operator_id | ||
operators_with_expired = OperatorDocument.doc_expired.pluck(:operator_id).uniq | ||
operators_with_active_users = User.filter_actives.pluck(:operator_id).uniq | ||
def documents | ||
[ | ||
OperatorDocumentFmu.new( | ||
expire_date: 7.days.from_now, | ||
fmu: Fmu.new(name: "00-100"), | ||
required_operator_document: RequiredOperatorDocument.new(name: "CITES permits") | ||
), | ||
OperatorDocumentFmu.new( | ||
expire_date: 7.days.from_now, | ||
fmu: Fmu.new(name: "Ngombe"), | ||
required_operator_document: RequiredOperatorDocument.new(name: "Required trading and transport permits") | ||
) | ||
] | ||
end | ||
|
||
(operators_with_expired & operators_with_active_users).first | ||
def operator | ||
Operator.new(name: "IFO / Interholco", slug: "ifo-interholco") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
class SystemMailerPreview < ActionMailer::Preview | ||
def user_created | ||
SystemMailer.user_created User.with_user_role("operator").last | ||
SystemMailer.user_created test_user | ||
end | ||
|
||
def operator_created | ||
SystemMailer.operator_created Operator.last | ||
SystemMailer.operator_created test_operator | ||
end | ||
|
||
private | ||
|
||
def test_user | ||
User.new(id: 1, email: "john@example.com", operator: test_operator, country: country, name: "John Tester", locale: "en", user_permission: UserPermission.new(user_role: "operator")) | ||
end | ||
|
||
def test_operator | ||
Operator.new(id: 161, name: "IFO / Interholco", slug: "ifo-interholco", country: country) | ||
end | ||
|
||
def country | ||
Country.new(name: "Congo") | ||
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,13 +1,23 @@ | ||
class UserMailerPreview < ActionMailer::Preview | ||
def user_acceptance_observer | ||
UserMailer.user_acceptance User.with_user_role("ngo").last | ||
UserMailer.user_acceptance test_user_observer | ||
end | ||
|
||
def user_acceptance_operator | ||
UserMailer.user_acceptance User.with_user_role("operator").last | ||
UserMailer.user_acceptance test_user_operator | ||
end | ||
|
||
def forgotten_password | ||
UserMailer.forgotten_password User.last | ||
UserMailer.forgotten_password test_user_operator | ||
end | ||
|
||
private | ||
|
||
def test_user_observer | ||
User.new(email: "john@example.com", name: "John Tester", locale: "en", user_permission: UserPermission.new(user_role: "ngo_manager")) | ||
end | ||
|
||
def test_user_operator | ||
User.new(email: "john@example.com", name: "John Tester", locale: "en", user_permission: UserPermission.new(user_role: "operator")) | ||
end | ||
end |