Skip to content

Commit

Permalink
Showing 5 changed files with 44 additions and 8 deletions.
5 changes: 4 additions & 1 deletion app/controllers/user_invite_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -55,10 +55,13 @@ def update
params[:requests].each_pair do |id, quantity|
unless quantity.blank?
request = UserInviteRequest.find(id)
user = User.find(request.user_id)
requested_total = request.quantity.to_i
request.quantity = 0
request.save!
UserMailer.invite_request_declined(request.user_id, requested_total, request.reason).deliver_later
I18n.with_locale(user.preference.locale.iso) do
UserMailer.invite_request_declined(request.user_id, requested_total, request.reason).deliver_later
end
end
end
flash[:notice] = 'All Requests were declined.'
12 changes: 5 additions & 7 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -162,12 +162,10 @@ def invite_request_declined(user_id, total, reason)
@user = User.find(user_id)
@total = total
@reason = reason
I18n.with_locale(@user.preference.locale.iso) do
mail(
to: @user.email,
subject: t("user_mailer.invite_request_declined.subject", app_name: ArchiveConfig.APP_SHORT_NAME)
)
end
mail(
to: @user.email,
subject: default_i18n_subject(app_name: ArchiveConfig.APP_SHORT_NAME)
)
end

def collection_notification(collection_id, subject, message, email)
@@ -230,7 +228,7 @@ def change_email(user_id, old_email, new_email)
I18n.with_locale(@user.preference.locale.iso) do
mail(
to: @old_email,
subject: t("user_mailer.change_email.subject", app_name: ArchiveConfig.APP_SHORT_NAME)
subject: default_i18n_subject(app_name: ArchiveConfig.APP_SHORT_NAME)
)
end
end
18 changes: 18 additions & 0 deletions features/other_a/invite_request.feature
Original file line number Diff line number Diff line change
@@ -156,3 +156,21 @@ Feature: Invite requests
When I follow "Delete"
Then I should see "Invitation successfully destroyed"
And "user1" should have "4" invitations
Scenario: Translated email is sent when invitation request is declined by admin
Given a locale with translated emails
And invitations are required
And the user "user1" exists and is activated
And the user "notuser1" exists and is activated
And the user "user1" enables translated emails
And all emails have been delivered
When as "user1" I request some invites
And as "notuser1" I request some invites
And I view requests as an admin
And I press "Decline All"
Then "user1" should be emailed
And the email should have "Additional invitation request declined" in the subject
And the email to "user1" should be translated
Then "notuser1" should be emailed
And the email should have "Additional invitation request declined" in the subject
And the email to "notuser1" should be non-translated
10 changes: 10 additions & 0 deletions features/step_definitions/invite_steps.rb
Original file line number Diff line number Diff line change
@@ -128,6 +128,16 @@ def invite(attributes = {})
step %{I press "Send Request"}
end

When "as {string} I request some invites" do |user|
step %{I am logged in as "#{user}"}
step %{I go to my user page}
step %{I follow "Invitations"}
step %{I follow "Request invitations"}
step %{I fill in "How many invitations would you like? (max 10)" with "3"}
step %{I fill in "Please specify why you'd like them:" with "I want them for a friend"}
step %{I press "Send Request"}
end

When /^I view requests as an admin$/ do
step %{I am logged in as an admin}
step %{I follow "Invitations"}
7 changes: 7 additions & 0 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -39,6 +39,13 @@ def claim_notification
creator_id = work.pseuds.first.user.id
UserMailer.claim_notification(creator_id, [work.id])
end

def invite_request_declined
user = create(:user, :for_mailer_preview)
total = params[:total] || 1
reason = "test reason"
UserMailer.invite_request_declined(user.id, total, reason)
end

private

0 comments on commit 4ad7955

Please sign in to comment.