zero default invites, the rake task starts people with 5 invites
This commit is contained in:
parent
5a2b3cd0a7
commit
d0d261fdae
4 changed files with 41 additions and 8 deletions
|
|
@ -19,7 +19,7 @@ class User
|
|||
|
||||
key :username
|
||||
key :serialized_private_key, String
|
||||
key :invites, Integer, :default => 5
|
||||
key :invites, Integer, :default => 0
|
||||
key :invitation_token, String
|
||||
key :invitation_sent_at, DateTime
|
||||
key :pending_request_ids, Array, :typecast => 'ObjectId'
|
||||
|
|
|
|||
|
|
@ -13,8 +13,12 @@ module RakeHelpers
|
|||
churn_through = n
|
||||
backer_name = backers[n+offset][0].to_s.strip
|
||||
backer_email = backers[n+offset][1].to_s.gsub('.ksr', '').strip
|
||||
unless User.find_by_email(backer_email)
|
||||
puts "sending email to: #{backer_name} #{backer_email}"
|
||||
Invitation.create_invitee(:email => backer_email, :name => backer_name, :invites => 5) unless User.find_by_email(backer_email)
|
||||
Invitation.create_invitee(:email => backer_email, :name => backer_name, :invites => 5)
|
||||
else
|
||||
puts "user with the email exists: #{backer_email} , #{backer_name} "
|
||||
end
|
||||
end
|
||||
churn_through
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,6 +32,14 @@ describe InvitationsController do
|
|||
}.should change(Invitation, :count).by(1)
|
||||
end
|
||||
|
||||
it 'creates an invited user with zero invites' do
|
||||
lambda{
|
||||
post :create, :user=>{:invite_messages=>"test", :aspects=> aspect.id.to_s, :email=>"abc@example.com"}
|
||||
}.should change(User, :count).by(1)
|
||||
User.find_by_email("abc@example.com").invites.should == 0
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -4,17 +4,38 @@
|
|||
|
||||
require 'spec_helper'
|
||||
require File.join(Rails.root, 'lib/rake_helpers.rb')
|
||||
include RakeHelpers
|
||||
describe RakeHelpers do
|
||||
before do
|
||||
@csv = File.join(Rails.root, 'spec/fixtures/test.csv')
|
||||
end
|
||||
describe '#process_emails' do
|
||||
before do
|
||||
Devise.mailer.deliveries = []
|
||||
end
|
||||
it 'should send emails to each backer' do
|
||||
pending
|
||||
Invitation.should_receive(:create_invitee).exactly(3).times
|
||||
RakeHelpers::process_emails(@csv, 100, 0)
|
||||
process_emails(@csv, 100, 1)
|
||||
end
|
||||
|
||||
it 'should not send the email to the same email twice' do
|
||||
process_emails(@csv, 100, 1)
|
||||
|
||||
Devise.mailer.deliveries.count.should == 3
|
||||
process_emails(@csv, 100, 1)
|
||||
|
||||
Devise.mailer.deliveries.count.should == 3
|
||||
end
|
||||
|
||||
it 'should make a user with 5 invites' do
|
||||
User.count.should == 0
|
||||
|
||||
process_emails(@csv, 1, 1)
|
||||
|
||||
User.count.should == 1
|
||||
User.first.invites.should == 5
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue