diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index c5e89750a..8448bd6c2 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -57,6 +57,12 @@ class InvitationsController < Devise::InvitationsController end end + def resend + invitation = current_user.invitations_from_me.where(:id => params[:id]).first + Resque.enqueue(Job::ResendInvitation, invitation.id) if invitation + redirect_to :back + end + protected def check_token diff --git a/config/routes.rb b/config/routes.rb index f64a29be3..9c6f061f5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,6 +31,7 @@ Diaspora::Application.routes.draw do match 'photos/make_profile_photo' => 'photos#make_profile_photo' resources :photos, :except => [:index] + match 'invitations/resend/:id' => 'invitations#resend' devise_for :users, :controllers => {:registrations => "registrations", :password => "devise/passwords", :invitations => "invitations"} diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 118025b1b..51fad80ba 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -117,5 +117,33 @@ describe InvitationsController do get :new end end + + describe '#resend' do + before do + @user.invites = 5 + + sign_in :user, @user + @controller.stub!(:current_user).and_return(@user) + request.env["HTTP_REFERER"]= 'http://test.host/cats/foo' + + @invited_user = @user.invite_user("a@a.com", @aspect.id) + end + + it 'calls resend invitation if one exists' do + @user.reload.invitations_from_me.count.should == 1 + invitation = @user.invitations_from_me.first + Resque.should_receive(:enqueue) + put :resend, :id => invitation.id + end + + it 'does not send an invitation for a different user' do + @user2 = bob + @aspect2 = @user2.aspects.create(:name => "cats") + @user2.invite_user("b@b.com", @aspect2.id) + invitation2 = @user2.reload.invitations_from_me.first + Resque.should_not_receive(:enqueue) + put :resend, :id => invitation2.id + end + end end diff --git a/spec/models/invitation_spec.rb b/spec/models/invitation_spec.rb index 2e3755956..0e9a72742 100644 --- a/spec/models/invitation_spec.rb +++ b/spec/models/invitation_spec.rb @@ -298,6 +298,17 @@ describe Invitation do end end + describe '.resend' do + before do + aspect + @invitation = Invitation.new(:sender => user, :recipient => user2, :aspect => aspect) + end + + it 'sends another email' do + lambda{@invitation.resend}.should change(Devise.mailer.deliveries, :count).by(1) + end + end + describe '#to_request!' do before do @new_user = Invitation.invite(:from => user, :service => 'email', :identifier => @email, :into => aspect)