removed user invite counter, as it was already depricated
This commit is contained in:
parent
669cd8578e
commit
32ae21a213
14 changed files with 80 additions and 156 deletions
|
|
@ -8,18 +8,6 @@ class AdminsController < ApplicationController
|
||||||
@users = params[:user].empty? ? [] : User.where(params[:user])
|
@users = params[:user].empty? ? [] : User.where(params[:user])
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_invites
|
|
||||||
user = User.find(params[:user_id])
|
|
||||||
|
|
||||||
if user.increment(:invites, 10).save
|
|
||||||
flash[:notice] = "Great Job!"
|
|
||||||
else
|
|
||||||
flash[:alert] = "there was a problem adding invites"
|
|
||||||
end
|
|
||||||
|
|
||||||
redirect_to user_search_path(:user => { :id => user.id })
|
|
||||||
end
|
|
||||||
|
|
||||||
def admin_inviter
|
def admin_inviter
|
||||||
opts = {:service => 'email', :identifier => params[:identifier]}
|
opts = {:service => 'email', :identifier => params[:identifier]}
|
||||||
existing_user = Invitation.find_existing_user('email', params[:identifier])
|
existing_user = Invitation.find_existing_user('email', params[:identifier])
|
||||||
|
|
|
||||||
|
|
@ -16,35 +16,35 @@ class InvitationsController < Devise::InvitationsController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if !AppConfig[:open_invitations] && current_user.invites == 0
|
unless AppConfig[:open_invitations]
|
||||||
flash[:error] = I18n.t 'invitations.create.no_more'
|
flash[:error] = I18n.t 'invitations.create.no_more'
|
||||||
|
redirect_to :back
|
||||||
|
return
|
||||||
|
end
|
||||||
|
aspect = params[:user].delete(:aspects)
|
||||||
|
message = params[:user].delete(:invite_messages)
|
||||||
|
emails = params[:user][:email].to_s.gsub(/\s/, '').split(/, */)
|
||||||
|
|
||||||
|
good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)}
|
||||||
|
|
||||||
|
if good_emails.include?(current_user.email)
|
||||||
|
if good_emails.length == 1
|
||||||
|
flash[:error] = I18n.t 'invitations.create.own_address'
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
return
|
return
|
||||||
end
|
|
||||||
aspect = params[:user].delete(:aspects)
|
|
||||||
message = params[:user].delete(:invite_messages)
|
|
||||||
emails = params[:user][:email].to_s.gsub(/\s/, '').split(/, */)
|
|
||||||
|
|
||||||
good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)}
|
|
||||||
|
|
||||||
if good_emails.include?(current_user.email)
|
|
||||||
if good_emails.length == 1
|
|
||||||
flash[:error] = I18n.t 'invitations.create.own_address'
|
|
||||||
redirect_to :back
|
|
||||||
return
|
|
||||||
else
|
|
||||||
bad_emails.push(current_user.email)
|
|
||||||
good_emails.delete(current_user.email)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
good_emails.each{|e| Resque.enqueue(Job::Mail::InviteUserByEmail, current_user.id, e, aspect, message)}
|
|
||||||
|
|
||||||
if bad_emails.any?
|
|
||||||
flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ')
|
|
||||||
else
|
else
|
||||||
flash[:notice] = I18n.t('invitations.create.sent') + good_emails.join(', ')
|
bad_emails.push(current_user.email)
|
||||||
|
good_emails.delete(current_user.email)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
good_emails.each{|e| Resque.enqueue(Job::Mail::InviteUserByEmail, current_user.id, e, aspect, message)}
|
||||||
|
|
||||||
|
if bad_emails.any?
|
||||||
|
flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ')
|
||||||
|
else
|
||||||
|
flash[:notice] = I18n.t('invitations.create.sent') + good_emails.join(', ')
|
||||||
|
end
|
||||||
|
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ class RegistrationsController < Devise::RegistrationsController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@user = User.build(params[:user])
|
@user = User.build(params[:user])
|
||||||
@user.invites = 20
|
|
||||||
if @user.save
|
if @user.save
|
||||||
flash[:notice] = I18n.t 'registrations.create.success'
|
flash[:notice] = I18n.t 'registrations.create.success'
|
||||||
@user.seed_aspects
|
@user.seed_aspects
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ class Invitation < ActiveRecord::Base
|
||||||
|
|
||||||
def self.invite(opts = {})
|
def self.invite(opts = {})
|
||||||
opts[:identifier].downcase! if opts[:identifier]
|
opts[:identifier].downcase! if opts[:identifier]
|
||||||
|
# return if the current user is trying to invite himself via email
|
||||||
return false if opts[:identifier] == opts[:from].email
|
return false if opts[:identifier] == opts[:from].email
|
||||||
|
|
||||||
existing_user = self.find_existing_user(opts[:service], opts[:identifier])
|
existing_user = self.find_existing_user(opts[:service], opts[:identifier])
|
||||||
|
|
@ -51,10 +52,11 @@ class Invitation < ActiveRecord::Base
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_invitee(opts = {})
|
# @params opts [Hash] Takes :from, :existing_user, :service, :identifier, :message
|
||||||
|
# @return [User]
|
||||||
|
def self.create_invitee(opts={})
|
||||||
invitee = opts[:existing_user] || new_user_by_service_and_identifier(opts[:service], opts[:identifier])
|
invitee = opts[:existing_user] || new_user_by_service_and_identifier(opts[:service], opts[:identifier])
|
||||||
return invitee if opts[:service] == 'email' && !opts[:identifier].match(Devise.email_regexp)
|
return invitee if opts[:service] == 'email' && !opts[:identifier].match(Devise.email_regexp)
|
||||||
invitee.invites = opts[:invites] || 10
|
|
||||||
if invitee.new_record?
|
if invitee.new_record?
|
||||||
invitee.errors.clear
|
invitee.errors.clear
|
||||||
invitee.serialized_private_key = User.generate_key if invitee.serialized_private_key.blank?
|
invitee.serialized_private_key = User.generate_key if invitee.serialized_private_key.blank?
|
||||||
|
|
@ -69,9 +71,6 @@ class Invitation < ActiveRecord::Base
|
||||||
:recipient => invitee,
|
:recipient => invitee,
|
||||||
:aspect => opts[:into],
|
:aspect => opts[:into],
|
||||||
:message => opts[:message])
|
:message => opts[:message])
|
||||||
|
|
||||||
opts[:from].invites -= 1 unless opts[:from].invites == 0
|
|
||||||
opts[:from].save!
|
|
||||||
invitee.reload
|
invitee.reload
|
||||||
end
|
end
|
||||||
invitee.skip_invitation = (opts[:service] != 'email')
|
invitee.skip_invitation = (opts[:service] != 'email')
|
||||||
|
|
|
||||||
|
|
@ -269,8 +269,7 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
###Invitations############
|
###Invitations############
|
||||||
def invite_user(aspect_id, service, identifier, invite_message = "")
|
def invite_user(aspect_id, service, identifier, invite_message = "")
|
||||||
aspect = aspects.find(aspect_id)
|
if aspect = aspects.find(aspect_id)
|
||||||
if aspect
|
|
||||||
Invitation.invite(:service => service,
|
Invitation.invite(:service => service,
|
||||||
:identifier => identifier,
|
:identifier => identifier,
|
||||||
:from => self,
|
:from => self,
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@
|
||||||
= user.person.profile.inspect
|
= user.person.profile.inspect
|
||||||
%br
|
%br
|
||||||
= "invite token: #{accept_invitation_url(user, :invitation_token => user.invitation_token)}" if user.invitation_token
|
= "invite token: #{accept_invitation_url(user, :invitation_token => user.invitation_token)}" if user.invitation_token
|
||||||
= link_to "add 10 invites for this user", add_invites_path(:user_id => user.id)
|
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,6 @@ Diaspora::Application.routes.draw do
|
||||||
scope 'admins', :controller => :admins do
|
scope 'admins', :controller => :admins do
|
||||||
match :user_search
|
match :user_search
|
||||||
get :admin_inviter
|
get :admin_inviter
|
||||||
get :add_invites, :as => 'add_invites'
|
|
||||||
get :stats, :as => 'pod_stats'
|
get :stats, :as => 'pod_stats'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
class RemoveInviteCounterFromUser < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
remove_column :users, :invites
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
add_column :users, :invites, :integer, :default => 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20110812175614) do
|
ActiveRecord::Schema.define(:version => 20110815210933) do
|
||||||
|
|
||||||
create_table "aspect_memberships", :force => true do |t|
|
create_table "aspect_memberships", :force => true do |t|
|
||||||
t.integer "aspect_id", :null => false
|
t.integer "aspect_id", :null => false
|
||||||
|
|
@ -386,7 +386,6 @@ ActiveRecord::Schema.define(:version => 20110812175614) do
|
||||||
create_table "users", :force => true do |t|
|
create_table "users", :force => true do |t|
|
||||||
t.string "username"
|
t.string "username"
|
||||||
t.text "serialized_private_key"
|
t.text "serialized_private_key"
|
||||||
t.integer "invites", :default => 0, :null => false
|
|
||||||
t.boolean "getting_started", :default => true, :null => false
|
t.boolean "getting_started", :default => true, :null => false
|
||||||
t.boolean "disable_mail", :default => false, :null => false
|
t.boolean "disable_mail", :default => false, :null => false
|
||||||
t.string "language"
|
t.string "language"
|
||||||
|
|
|
||||||
|
|
@ -60,33 +60,6 @@ describe AdminsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#add_invites' do
|
|
||||||
context 'admin not signed in' do
|
|
||||||
it 'is behind redirect_unless_admin' do
|
|
||||||
get :add_invites
|
|
||||||
response.should redirect_to root_url
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'admin signed in' do
|
|
||||||
before do
|
|
||||||
AppConfig[:admins] = [@user.username]
|
|
||||||
end
|
|
||||||
|
|
||||||
it "redirects to :back with user id" do
|
|
||||||
get :add_invites, :user_id => @user.id
|
|
||||||
response.should redirect_to user_search_path(:user => { :id => @user.id })
|
|
||||||
end
|
|
||||||
|
|
||||||
it "increases user's invite by 10" do
|
|
||||||
expect {
|
|
||||||
get :add_invites, :user_id => @user.id
|
|
||||||
}.to change { @user.reload.invites }.by(10)
|
|
||||||
flash.notice.should include('Great Job')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#admin_inviter' do
|
describe '#admin_inviter' do
|
||||||
context 'admin not signed in' do
|
context 'admin not signed in' do
|
||||||
it 'is behind redirect_unless_admin' do
|
it 'is behind redirect_unless_admin' do
|
||||||
|
|
@ -110,6 +83,7 @@ describe AdminsController do
|
||||||
get :admin_inviter, :identifier => 'bob@moms.com'
|
get :admin_inviter, :identifier => 'bob@moms.com'
|
||||||
response.should be_redirect
|
response.should be_redirect
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'invites a new user' do
|
it 'invites a new user' do
|
||||||
Invitation.should_receive(:create_invitee).with(:service => 'email', :identifier => 'bob@moms.com')
|
Invitation.should_receive(:create_invitee).with(:service => 'email', :identifier => 'bob@moms.com')
|
||||||
get :admin_inviter, :identifier => 'bob@moms.com'
|
get :admin_inviter, :identifier => 'bob@moms.com'
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ describe InvitationsController do
|
||||||
include Devise::TestHelpers
|
include Devise::TestHelpers
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
AppConfig[:open_invitations] = true
|
||||||
@user = alice
|
@user = alice
|
||||||
@aspect = @user.aspects.first
|
@aspect = @user.aspects.first
|
||||||
|
|
||||||
|
|
@ -17,8 +18,6 @@ describe InvitationsController do
|
||||||
|
|
||||||
describe "#create" do
|
describe "#create" do
|
||||||
before do
|
before do
|
||||||
@user.invites = 5
|
|
||||||
|
|
||||||
sign_in :user, @user
|
sign_in :user, @user
|
||||||
@invite = {:invite_message=>"test", :aspect_id=> @aspect.id.to_s, :email=>"abc@example.com"}
|
@invite = {:invite_message=>"test", :aspect_id=> @aspect.id.to_s, :email=>"abc@example.com"}
|
||||||
@controller.stub!(:current_user).and_return(@user)
|
@controller.stub!(:current_user).and_return(@user)
|
||||||
|
|
@ -50,19 +49,9 @@ describe InvitationsController do
|
||||||
flash[:error].should =~ /lala@foo/
|
flash[:error].should =~ /lala@foo/
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't invite anyone if you have 0 invites" do
|
it "allows invitations without if invitations are open" do
|
||||||
@user.invites = 0
|
|
||||||
@user.save!
|
|
||||||
|
|
||||||
Resque.should_not_receive(:enqueue)
|
|
||||||
post :create, :user => @invite.merge(:email => "mbs@gmail.com, foo@bar.com, foo.com, lala@foo, cool@bar.com")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "allows invitations without limit if invitations are open" do
|
|
||||||
open_bit = AppConfig[:open_invitations]
|
open_bit = AppConfig[:open_invitations]
|
||||||
AppConfig[:open_invitations] = true
|
AppConfig[:open_invitations] = true
|
||||||
@user.invites = 0
|
|
||||||
@user.save!
|
|
||||||
|
|
||||||
Resque.should_receive(:enqueue).once
|
Resque.should_receive(:enqueue).once
|
||||||
post :create, :user => @invite
|
post :create, :user => @invite
|
||||||
|
|
@ -87,7 +76,6 @@ describe InvitationsController do
|
||||||
|
|
||||||
describe "#update" do
|
describe "#update" do
|
||||||
before do
|
before do
|
||||||
@user.invites = 5
|
|
||||||
@invited_user = @user.invite_user(@aspect.id, 'email', "a@a.com")
|
@invited_user = @user.invite_user(@aspect.id, 'email', "a@a.com")
|
||||||
@accept_params = {:user=>
|
@accept_params = {:user=>
|
||||||
{:password_confirmation =>"password",
|
{:password_confirmation =>"password",
|
||||||
|
|
@ -145,8 +133,6 @@ describe InvitationsController do
|
||||||
|
|
||||||
describe '#resend' do
|
describe '#resend' do
|
||||||
before do
|
before do
|
||||||
@user.invites = 5
|
|
||||||
|
|
||||||
sign_in :user, @user
|
sign_in :user, @user
|
||||||
@controller.stub!(:current_user).and_return(@user)
|
@controller.stub!(:current_user).and_return(@user)
|
||||||
request.env["HTTP_REFERER"]= 'http://test.host/cats/foo'
|
request.env["HTTP_REFERER"]= 'http://test.host/cats/foo'
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@ describe ServicesController do
|
||||||
before do
|
before do
|
||||||
@user = alice
|
@user = alice
|
||||||
@aspect = @user.aspects.first
|
@aspect = @user.aspects.first
|
||||||
@user.invites = 100
|
|
||||||
@user.save
|
|
||||||
|
|
||||||
sign_in :user, @user
|
sign_in :user, @user
|
||||||
@controller.stub!(:current_user).and_return(@user)
|
@controller.stub!(:current_user).and_return(@user)
|
||||||
|
|
@ -114,6 +112,13 @@ describe ServicesController do
|
||||||
@invite_params = {:provider => 'facebook', :uid => @uid, :aspect_id => @user.aspects.first.id}
|
@invite_params = {:provider => 'facebook', :uid => @uid, :aspect_id => @user.aspects.first.id}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'enqueues an invite job if the fb user has a username' do
|
||||||
|
pending
|
||||||
|
@invite_params[:provider] = "email"
|
||||||
|
@invite_params[:uid] = "username@facebook.com"
|
||||||
|
put :inviter, @invite_params
|
||||||
|
end
|
||||||
|
|
||||||
it 'sets the subject' do
|
it 'sets the subject' do
|
||||||
put :inviter, @invite_params
|
put :inviter, @invite_params
|
||||||
assigns[:subject].should_not be_nil
|
assigns[:subject].should_not be_nil
|
||||||
|
|
@ -152,7 +157,6 @@ describe ServicesController do
|
||||||
it 'disregares the amount of invites if open_invitations are enabled' do
|
it 'disregares the amount of invites if open_invitations are enabled' do
|
||||||
open_bit = AppConfig[:open_invitations]
|
open_bit = AppConfig[:open_invitations]
|
||||||
AppConfig[:open_invitations] = true
|
AppConfig[:open_invitations] = true
|
||||||
@user.invites = 0
|
|
||||||
|
|
||||||
lambda {
|
lambda {
|
||||||
put :inviter, @invite_params
|
put :inviter, @invite_params
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ describe Invitation do
|
||||||
let(:aspect) { user.aspects.first }
|
let(:aspect) { user.aspects.first }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
user.invites = 20
|
|
||||||
user.save
|
|
||||||
@email = 'maggie@example.com'
|
@email = 'maggie@example.com'
|
||||||
Devise.mailer.deliveries = []
|
Devise.mailer.deliveries = []
|
||||||
end
|
end
|
||||||
|
|
@ -165,22 +163,6 @@ describe Invitation do
|
||||||
Invitation.invite(:from => user, :service => 'email', :identifier => eve.email, :into => aspect)
|
Invitation.invite(:from => user, :service => 'email', :identifier => eve.email, :into => aspect)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'decrements the invite count of the from user' do
|
|
||||||
message = "How've you been?"
|
|
||||||
lambda {
|
|
||||||
new_user = Invitation.invite(:from => user, :service => 'email', :identifier => @email, :into => aspect, :message => message)
|
|
||||||
}.should change(user, :invites).by(-1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "doesn't decrement counter past zero" do
|
|
||||||
user.invites = 0
|
|
||||||
user.save!
|
|
||||||
message = "How've you been?"
|
|
||||||
lambda {
|
|
||||||
Invitation.invite(:from => user, :service => 'email', :identifier => @email, :into => aspect, :message => message)
|
|
||||||
}.should_not change(user, :invites)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'invalid email' do
|
context 'invalid email' do
|
||||||
it 'return a user with errors' do
|
it 'return a user with errors' do
|
||||||
new_user = Invitation.invite(:service => 'email', :identifier => "fkjlsdf", :from => user, :into => aspect)
|
new_user = Invitation.invite(:service => 'email', :identifier => "fkjlsdf", :from => user, :into => aspect)
|
||||||
|
|
|
||||||
|
|
@ -5,97 +5,84 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe User do
|
describe User do
|
||||||
let(:inviter) {new_user = eve; new_user.invites = 5; new_user.save; new_user;}
|
|
||||||
let(:aspect) {inviter.aspects.create(:name => "awesome")}
|
|
||||||
let(:another_user) {alice}
|
|
||||||
let(:wrong_aspect) {another_user.aspects.create(:name => "super")}
|
|
||||||
let(:inviter_with_3_invites) { new_user = Factory.create(:user); new_user.invites = 3; new_user.save; new_user;}
|
|
||||||
let(:aspect2) {inviter_with_3_invites.aspects.create(:name => "Jersey Girls")}
|
|
||||||
|
|
||||||
before do
|
|
||||||
@email = "bob@bob.com"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "creating invites" do
|
context "creating invites" do
|
||||||
|
before do
|
||||||
|
@aspect = eve.aspects.first
|
||||||
|
@email = "bob@bob.com"
|
||||||
|
end
|
||||||
|
|
||||||
it 'requires your aspect' do
|
it 'requires your aspect' do
|
||||||
lambda {
|
lambda {
|
||||||
inviter.invite_user(wrong_aspect.id, "email", "maggie@example.com")
|
eve.invite_user(alice.aspects.first.id, "email", "maggie@example.com")
|
||||||
}.should raise_error ActiveRecord::RecordNotFound
|
}.should raise_error ActiveRecord::RecordNotFound
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'takes a service parameter' do
|
it 'takes a service parameter' do
|
||||||
@invite_params = {:service => 'email'}
|
@invite_params = {:service => 'email'}
|
||||||
Invitation.should_receive(:invite).with(hash_including(@invite_params))
|
Invitation.should_receive(:invite).with(hash_including(@invite_params))
|
||||||
inviter.invite_user(aspect.id, 'email', @email)
|
eve.invite_user(@aspect.id, 'email', @email)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'takes an indentifier parameter' do
|
it 'takes an indentifier parameter' do
|
||||||
@invite_params = {:identifier => @email}
|
@invite_params = {:identifier => @email}
|
||||||
Invitation.should_receive(:invite).with(hash_including(@invite_params))
|
Invitation.should_receive(:invite).with(hash_including(@invite_params))
|
||||||
inviter.invite_user(aspect.id, 'email', @email)
|
eve.invite_user(@aspect.id, 'email', @email)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls Invitation.invite' do
|
it 'calls Invitation.invite' do
|
||||||
Invitation.should_receive(:invite)
|
Invitation.should_receive(:invite)
|
||||||
inviter.invite_user(aspect.id, 'email', @email)
|
eve.invite_user(@aspect.id, 'email', @email)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has an invitation' do
|
it 'has an invitation' do
|
||||||
inviter.invite_user(aspect.id, 'email', @email).invitations_to_me.count.should == 1
|
eve.invite_user(@aspect.id, 'email', @email).invitations_to_me.count.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates it with an email' do
|
it 'creates it with an email' do
|
||||||
inviter.invite_user(aspect.id, 'email', @email).email.should == @email
|
eve.invite_user(@aspect.id, 'email', @email).email.should == @email
|
||||||
end
|
end
|
||||||
|
|
||||||
it "throws if you try to add someone you're connected to" do
|
it "throws if you try to add someone you're connected to" do
|
||||||
connect_users(inviter, aspect, another_user, wrong_aspect)
|
connect_users(eve, @aspect, alice, alice.aspects.first)
|
||||||
proc{
|
lambda {
|
||||||
inviter.invite_user(aspect.id, 'email', another_user.email)
|
eve.invite_user(@aspect.id, 'email', alice.email)
|
||||||
}.should raise_error ActiveRecord::RecordNotUnique
|
}.should raise_error ActiveRecord::RecordNotUnique
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
context "limit on invites" do
|
|
||||||
|
|
||||||
it 'does not invite people I already invited' do
|
it 'does not invite people I already invited' do
|
||||||
inviter_with_3_invites.invite_user(aspect2.id, 'email', "email1@example.com")
|
eve.invite_user(@aspect.id, 'email', "email1@example.com")
|
||||||
proc{
|
lambda {
|
||||||
inviter_with_3_invites.invite_user(aspect2.id, 'email', "email1@example.com")
|
eve.invite_user(@aspect.id, 'email', "email1@example.com")
|
||||||
}.should raise_error /You already invited this person/
|
}.should raise_error /You already invited this person/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe "#accept_invitation!" do
|
describe "#accept_invitation!" do
|
||||||
let(:invited_user) {@invited_user_pre.accept_invitation!(:invitation_token => "abc",
|
|
||||||
:email => "a@a.com",
|
|
||||||
:username => "user",
|
|
||||||
:password => "secret",
|
|
||||||
:password_confirmation => "secret",
|
|
||||||
:person => {:profile => {:first_name => "Bob",
|
|
||||||
:last_name => "Smith"}} )}
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@invited_user_pre = Invitation.invite(:from => inviter, :service => 'email', :identifier => 'invitee@example.org', :into => aspect).reload
|
invite_pre = Invitation.invite(:from => eve, :service => 'email', :identifier => 'invitee@example.org', :into => eve.aspects.first).reload
|
||||||
@person_count = Person.count
|
@person_count = Person.count
|
||||||
|
@invited_user = invite_pre.accept_invitation!(:invitation_token => "abc",
|
||||||
|
:email => "a@a.com",
|
||||||
|
:username => "user",
|
||||||
|
:password => "secret",
|
||||||
|
:password_confirmation => "secret",
|
||||||
|
:person => {:profile => {:first_name => "Bob",
|
||||||
|
:last_name => "Smith"}} )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'after invitation acceptance' do
|
context 'after invitation acceptance' do
|
||||||
before do
|
|
||||||
invited_user.reload
|
|
||||||
end
|
|
||||||
it 'destroys the invitations' do
|
it 'destroys the invitations' do
|
||||||
invited_user.invitations_to_me.count.should == 0
|
@invited_user.invitations_to_me.count.should == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should create the person with the passed in params" do
|
it "should create the person with the passed in params" do
|
||||||
Person.count.should == @person_count + 1
|
Person.count.should == @person_count + 1
|
||||||
invited_user.person.profile.first_name.should == "Bob"
|
@invited_user.person.profile.first_name.should == "Bob"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'resolves incoming invitations into contact requests' do
|
it 'resolves incoming invitations into contact requests' do
|
||||||
inviter.contacts.where(:person_id => invited_user.person.id).count.should == 1
|
eve.contacts.where(:person_id => @invited_user.person.id).count.should == 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue