Better error messages for folks coming in with a bad invitation token, whether by clicking the "view this invitation in your browser" link or by clicking the accept invitation button.

Get rid of 500 error on the "view this invitation in your browser" link
This commit is contained in:
Sarah Mei & Tim Frazer 2011-11-14 17:02:13 -08:00
parent ebad0f5ec3
commit e38cb41f85
5 changed files with 30 additions and 10 deletions

View file

@ -4,7 +4,7 @@
class InvitationsController < Devise::InvitationsController
before_filter :check_token, :only => [:edit]
before_filter :check_token, :only => [:edit, :email]
before_filter :check_if_invites_open, :only =>[:create]
def new
@ -73,8 +73,7 @@ class InvitationsController < Devise::InvitationsController
protected
def check_token
if User.find_by_invitation_token(params[:invitation_token]).nil?
flash[:error] = I18n.t 'invitations.check_token.not_found'
redirect_to root_url
render 'invitations/token_not_found'
end
end

View file

@ -0,0 +1,3 @@
.span-15.last
%h2
= t('devise.invitations.invitation_token_invalid')

View file

@ -52,7 +52,7 @@ en:
resend_unlock: "Resend unlock instructions"
invitations:
send_instructions: 'Your invitation has been sent.'
invitation_token_invalid: 'The invitation token provided is not valid!'
invitation_token_invalid: 'Our apologies! That invitation token is not valid.'
updated: 'Your password was set successfully. You are now signed in.'
mailer:
welcome: "Welcome %{email}!"
@ -73,8 +73,8 @@ en:
click_to_unlock: "Click the link below to unlock your account:"
unlock: "Unlock my account"
invitation_instructions:
displaying_correctly: "Email not displaying correctly? %{link} in your browser"
view_in: "View in"
displaying_correctly: "Email not displaying correctly? %{link}"
view_in: "View it in your browser."
finally: "Finally - it's here"
arrived: "The social network you have been waiting for has arrived. Revamped, more secure, and more fun, %{strong_diaspora} is ready to help you share and explore the web in a whole new way."
sign_up_now: "Sign up now &rarr;"

View file

@ -24,20 +24,20 @@ describe InvitationsController do
request.env["HTTP_REFERER"]= 'http://test.host/cats/foo'
end
it 'saves and invitation' do
it 'saves an invitation' do
expect {
post :create, :user => @invite
}.should change(Invitation, :count).by(1)
end
it 'handles a comma seperated list of emails' do
it 'handles a comma-separated list of emails' do
expect{
post :create, :user => @invite.merge(
:email => "foofoofoofoo@example.com, mbs@gmail.com")
}.should change(Invitation, :count).by(2)
end
it 'handles a comma seperated list of emails with whitespace' do
it 'handles a comma-separated list of emails with whitespace' do
expect {
post :create, :user => @invite.merge(
:email => "foofoofoofoo@example.com , mbs@gmail.com")
@ -70,6 +70,24 @@ describe InvitationsController do
end
end
describe "#email" do
before do
invites = Invitation.batch_invite(["foo@example.com"], :message => "hi", :sender => @user, :aspect => @user.aspects.first, :service => 'email', :language => "en-US")
invites.first.send!
@invited_user = User.find_by_email("foo@example.com")
end
it "succeeds" do
get :email, :invitation_token => @invited_user.invitation_token
response.should be_success
end
it "shows an error if there's no such invitation token" do
get :email, :invitation_token => 12345
response.should render_template(:token_not_found)
end
end
describe "#update" do
before do
invite = Factory(:invitation, :sender => @user, :service => 'email', :identifier => "a@a.com")