when a user is invited from a beta user, they are also beta
This commit is contained in:
parent
bae47a10eb
commit
e79d78302e
6 changed files with 25 additions and 1 deletions
|
|
@ -14,6 +14,7 @@ class RegistrationsController < Devise::RegistrationsController
|
|||
if @user.save
|
||||
flash[:notice] = I18n.t 'registrations.create.success'
|
||||
@user.seed_aspects
|
||||
Role.add_beta(@user.person) if invite.present? && invite.beta?
|
||||
sign_in_and_redirect(:user, @user)
|
||||
Rails.logger.info("event=registration status=successful user=#{@user.diaspora_handle}")
|
||||
else
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ class InvitationCode < ActiveRecord::Base
|
|||
|
||||
before_create :generate_token, :set_default_invite_count
|
||||
|
||||
delegate :beta?, :to => :user
|
||||
def to_param
|
||||
token
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class Role < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.is_beta?(person)
|
||||
find_by_person_id_and_name(person.id, 'beta')
|
||||
find_by_person_id_and_name(person.id, 'beta').present?
|
||||
end
|
||||
|
||||
def self.add_beta(person)
|
||||
|
|
|
|||
|
|
@ -106,6 +106,10 @@ class User < ActiveRecord::Base
|
|||
ConversationVisibility.sum(:unread, :conditions => "person_id = #{self.person.id}")
|
||||
end
|
||||
|
||||
def beta?
|
||||
Role.is_beta?(self.person)
|
||||
end
|
||||
|
||||
#@deprecated
|
||||
def ugly_accept_invitation_code
|
||||
begin
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ describe RegistrationsController do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
describe "#create" do
|
||||
context "with valid parameters" do
|
||||
before do
|
||||
|
|
@ -84,6 +86,12 @@ describe RegistrationsController do
|
|||
response.should be_redirect
|
||||
response.location.should match /^#{root_url}\??$/
|
||||
end
|
||||
|
||||
it 'with an invite code from a beta users, make the user beta' do
|
||||
Role.add_beta(bob.person)
|
||||
get :create, @valid_params.merge(:invite => {:token => bob.invitation_code.token})
|
||||
User.last.should be_beta
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid parameters" do
|
||||
|
|
|
|||
|
|
@ -20,6 +20,16 @@ describe InvitationCode do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.beta?' do
|
||||
it 'returns true if the invite code user is beta' do
|
||||
code = Factory(:invitation_code)
|
||||
Role.add_beta(code.user.person)
|
||||
code.user.should be_beta
|
||||
code.should be_beta
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe '.default_inviter_or' do
|
||||
before do
|
||||
@old_account = AppConfig[:admin_account]
|
||||
|
|
|
|||
Loading…
Reference in a new issue