From 381793243e0af6a8083be34ca0e720cdc8fa717a Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 6 Feb 2019 19:19:00 +0530 Subject: [PATCH] FIX: include error message if the "accept invite" process fails --- app/controllers/invites_controller.rb | 3 ++- config/locales/server.en.yml | 1 + spec/requests/invites_controller_spec.rb | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index a178e401da..884f67ec8f 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -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 diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 286a8f2553..c525fe1f90 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -208,6 +208,7 @@ en:

If you remember your password you can Login.

Otherwise please Reset Password.

+ error_message: "There was an error accepting invite. Please contact the site's administrator." user_exists: "There's no need to invite %{email}, they already have an account!" confirm_email: "

You’re almost done! We sent an activation mail to your email address. Please follow the instructions in the mail to activate your account.

If it doesn’t arrive, check your spam folder.

" diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rb index 037d2aa047..b2b7f4152c 100644 --- a/spec/requests/invites_controller_spec.rb +++ b/spec/requests/invites_controller_spec.rb @@ -213,6 +213,18 @@ describe InvitesController do end end + context 'with an invalid invite record' do + let(:invite) { Fabricate(:invite, email: "John Doe ") } + 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) }