adding a test for decremented invites, as, and check the invite is valid in the controller

This commit is contained in:
Maxwell Salzberg 2012-03-16 14:00:57 -07:00 committed by danielgrippi
parent 319b3c4d3b
commit 11505a386c
8 changed files with 26 additions and 12 deletions

View file

@ -18,6 +18,8 @@ class InvitationsController < ApplicationController
# this is for legacy invites. We try to look the person who sent them the
# invite, and use their new invite code
# owe will be removing this eventually
# @depreciated
def edit
user = User.find_by_invitation_token(params[:invitation_token])
invitation_code = user.ugly_accept_invitation_code

View file

@ -3,7 +3,7 @@
# the COPYRIGHT file.
class RegistrationsController < Devise::RegistrationsController
before_filter :check_registrations_open_or_vaild_invite!
before_filter :check_registrations_open_or_vaild_invite!, :check_valid_invite!
def create
@user = User.build(params[:user])
@ -16,7 +16,7 @@ class RegistrationsController < Devise::RegistrationsController
Rails.logger.info("event=registration status=successful user=#{@user.diaspora_handle}")
else
@user.errors.delete(:person)
flash[:error] = @user.errors.full_messages.join(";")
Rails.logger.info("event=registration status=failure errors='#{@user.errors.full_messages.join(', ')}'")
render :new
@ -28,6 +28,12 @@ class RegistrationsController < Devise::RegistrationsController
end
private
def check_valid_invite!
return true if invite.can_be_used?
flash[:error] = t('registrations.invalid_invite')
redirect_to new_user_session_path
end
def check_registrations_open_or_vaild_invite!
return true if invite.present?
if AppConfig[:registrations_closed]

View file

@ -9,6 +9,10 @@ class InvitationCode < ActiveRecord::Base
token
end
def can_be_used?
self.count > 0
end
def add_invites!
self.update_attributes(:count => self.count+100)
end

View file

@ -107,7 +107,7 @@ class User < ActiveRecord::Base
ConversationVisibility.sum(:unread, :conditions => "person_id = #{self.person.id}")
end
#should be deprecated
#@deprecated
def ugly_accept_invitation_code
begin
self.invitations_to_me.first.sender.invitation_code

View file

@ -1,9 +1,6 @@
.stream_element{:id => friend.id}
.float-right
- if friend.already_invited?
= link_to t('.resend'), service_inviter_path(:uid => friend.uid, :provider => 'facebook', :invitation_id => friend.invitation_id), :class => 'button resend'
- elsif friend.on_diaspora?
- if friend.on_diaspora?
= aspect_membership_dropdown(contact_proxy(friend), friend.person, 'left')
- else
= render 'shared/aspect_dropdown', :selected_aspects => contact_proxy(friend).aspects, :person => friend.person, :hang => 'left', :dropdown_class => 'inviter', :service_uid => friend.uid

View file

@ -682,6 +682,7 @@ en:
update: "Update"
cancel_my_account: "Cancel my account"
closed: "Signups are closed on this Diaspora pod."
invalid_invite: "The invite link you provided is no longer valid!"
requests:
manage_aspect_contacts:

View file

@ -19,7 +19,7 @@ Feature: invitation acceptance
Then I should be on the stream page
Scenario: accept invitation from user
Given I have been invited by a user
Given I have been invited by bob
And I am on my acceptance form page
And I fill in the following:
| user_username | ohai |
@ -35,6 +35,10 @@ Feature: invitation acceptance
And I preemptively confirm the alert
And I follow "awesome_button"
Then I should be on the stream page
And I log out
And I sign in as "bob@bob.bob"
And I follow "By email"
Then I should see "9 invites left"
Scenario: sends an invitation
Given a user with email "bob@bob.bob"

View file

@ -27,13 +27,13 @@ end
Given /^I have been invited by an admin$/ do
admin = Factory(:user)
bob.invitation_code
i = EmailInviter.new("new_invitee@example.com", bob)
admin.invitation_code
i = EmailInviter.new("new_invitee@example.com", admin)
i.send!
end
Given /^I have been invited by a user$/ do
@inviter = Factory(:user)
Given /^I have been invited by bob$/ do
@inviter = Factory(:user, :email => 'bob@bob.bob')
i = EmailInviter.new("new_invitee@example.com", @inviter)
i.send!
end