vrfs-775: integrating new musician emails
This commit is contained in:
parent
cc3994e950
commit
ee9b203f99
|
|
@ -78,5 +78,15 @@
|
|||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def new_musicians(user, new_nearby)
|
||||
@user, @new_nearby = user, new_nearby
|
||||
sendgrid_unique_args :type => "new_musicians"
|
||||
mail(:to => user.email, :subject => "JamKazam New Musicians in Your Area") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<% provide(:title, 'Confirm Email') %>
|
||||
|
||||
<p>New JamKazam Musicians in your Area, <%= @user.first_name %>!</p>
|
||||
|
||||
<p></p>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<% provide(:title, 'Confirm Email') %>
|
||||
|
||||
New JamKazam Musicians in your Area, <%= @user.first_name %>!
|
||||
|
||||
|
||||
|
|
@ -250,16 +250,14 @@ module JamRuby
|
|||
false
|
||||
end
|
||||
|
||||
def self.new_musicians(since_date=Time.now - 1.week, max_count=100, radius=M_MILES_DEFAULT)
|
||||
def self.new_musicians(usr, since_date=Time.now - 1.week, max_count=50, radius=M_MILES_DEFAULT)
|
||||
return unless block_given?
|
||||
User.where(['lat IS NOT NULL AND lng IS NOT NULL']).find_each do |usr|
|
||||
rel = User.musicians
|
||||
.where(['created_at >= ? AND users.id != ?', since_date, usr.id])
|
||||
.within(radius, :origin => [usr.lat, usr.lng])
|
||||
.order('created_at DESC')
|
||||
.limit(max_count)
|
||||
yield(rel) if 0 < rel.count
|
||||
end
|
||||
rel = User.musicians
|
||||
.where(['created_at >= ? AND users.id != ?', since_date, usr.id])
|
||||
.within(radius, :origin => [usr.lat, usr.lng])
|
||||
.order('created_at DESC')
|
||||
.limit(max_count)
|
||||
yield(rel) if 0 < rel.count
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -139,7 +139,8 @@ module JamRuby
|
|||
validate :update_email_case_insensitive_uniqueness, :if => :updating_email
|
||||
|
||||
scope :musicians, where(:musician => true)
|
||||
scope :musicians_geocoded, where(['musician = ? AND lat IS NOT NULL AND lng IS NOT NULL',true])
|
||||
scope :geocoded_users, where(['lat IS NOT NULL AND lng IS NOT NULL'])
|
||||
scope :musicians_geocoded, musicians.geocoded_users
|
||||
|
||||
def user_progression_fields
|
||||
@user_progression_fields ||= Set.new ["first_downloaded_client_at", "first_ran_client_at", "first_music_session_at", "first_real_music_session_at", "first_good_music_session_at", "first_certified_gear_at", "first_invited_at", "first_friended_at", "first_social_promoted_at" ]
|
||||
|
|
@ -988,6 +989,14 @@ module JamRuby
|
|||
.order('follows.created_at DESC')
|
||||
.limit(3)
|
||||
end
|
||||
|
||||
def self.deliver_new_musician_notifications
|
||||
self.geocoded_users.find_each do |usr|
|
||||
Search.new_musicians(usr) do |new_nearby|
|
||||
UserMailer.password_changed(self, new_nearby).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# devise compatibility
|
||||
|
||||
|
|
|
|||
|
|
@ -204,15 +204,31 @@ describe 'Musician search' do
|
|||
end
|
||||
|
||||
context 'new users' do
|
||||
|
||||
it "find nearby" do
|
||||
# create new user to ensure its excluded from results
|
||||
usr = FactoryGirl.create(:user, {city: "Austin", state: "TX", country: "US"})
|
||||
Search.new_musicians do |usrs|
|
||||
# the newly created user is not nearby the existing users (which are in Apex, NC)
|
||||
# and that user is not included in query
|
||||
expect(usrs.count).to eq(User.musicians.count - 1)
|
||||
# create new user outside 500 from Apex to ensure its excluded from results
|
||||
FactoryGirl.create(:user, {city: "Austin", state: "TX", country: "US"})
|
||||
User.geocoded_users.find_each do |usr|
|
||||
Search.new_musicians(usr) do |new_usrs|
|
||||
# the newly created user is not nearby the existing users (which are in Apex, NC)
|
||||
# and that user is not included in query
|
||||
expect(new_usrs.count).to eq(User.musicians.count - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "sends new musician email" do
|
||||
# create new user outside 500 from Apex to ensure its excluded from results
|
||||
FactoryGirl.create(:user, {city: "Austin", state: "TX", country: "US"})
|
||||
User.geocoded_users.find_each do |usr|
|
||||
Search.new_musicians(usr) do |new_usrs|
|
||||
# the newly created user is not nearby the existing users (which are in Apex, NC)
|
||||
# and that user is not included in query
|
||||
expect(new_usrs.count).to eq(User.musicians.count - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -137,4 +137,23 @@ describe UserMailer do
|
|||
end
|
||||
|
||||
|
||||
describe "sends new musicians email" do
|
||||
|
||||
let(:mail) { UserMailer.deliveries[0] }
|
||||
|
||||
before(:each) do
|
||||
UserMailer.new_musicians(user, User.musicians).deliver
|
||||
end
|
||||
|
||||
it { UserMailer.deliveries.length.should == 1 }
|
||||
|
||||
it { mail['from'].to_s.should == UserMailer::DEFAULT_SENDER }
|
||||
it { mail['to'].to_s.should == user.email }
|
||||
it { mail.multipart?.should == true } # because we send plain + html
|
||||
|
||||
# verify that the messages are correctly configured
|
||||
it { mail.html_part.body.include?("New JamKazam Musicians in your Area").should be_true }
|
||||
it { mail.text_part.body.include?("New JamKazam Musicians in your Area").should be_true }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue