FIX: include error message if the "accept invite" process fails

This commit is contained in:
Arpit Jalan 2019-02-06 19:19:00 +05:30
parent ff12c4b2d4
commit 381793243e
3 changed files with 15 additions and 1 deletions

View File

@ -63,7 +63,8 @@ class InvitesController < ApplicationController
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
render json: {
success: false,
errors: e.record&.errors&.to_hash || {}
errors: e.record&.errors&.to_hash || {},
message: I18n.t('invite.error_message')
}
end
else

View File

@ -208,6 +208,7 @@ en:
<p>If you remember your password you can <a href="%{base_url}/login">Login</a>.</p>
<p>Otherwise please <a href="%{base_url}/password-reset">Reset Password</a>.</p>
error_message: "There was an error accepting invite. Please contact the site's administrator."
user_exists: "There's no need to invite <b>%{email}</b>, they <a href='%{base_path}/u/%{username}/summary'>already have an account!</a>"
confirm_email: "<p>Youre almost done! We sent an activation mail to your email address. Please follow the instructions in the mail to activate your account.</p><p>If it doesnt arrive, check your spam folder.</p>"

View File

@ -213,6 +213,18 @@ describe InvitesController do
end
end
context 'with an invalid invite record' do
let(:invite) { Fabricate(:invite, email: "John Doe <john.doe@example.com>") }
it "responds with error message" do
put "/invites/show/#{invite.invite_key}.json"
expect(response.status).to eq(200)
json = JSON.parse(response.body)
expect(json["success"]).to eq(false)
expect(json["message"]).to eq(I18n.t('invite.error_message'))
expect(session[:current_user_id]).to be_blank
end
end
context 'with a deleted invite' do
let(:topic) { Fabricate(:topic) }