Merge branch 'musicians_page' into develop

This commit is contained in:
Jonathan Kolyer 2013-11-26 09:01:08 -06:00
commit 2c30b51048
9 changed files with 143 additions and 16 deletions

View File

@ -78,5 +78,15 @@
format.html
end
end
def new_musicians(user, new_nearby, host='www.jamkazam.com')
@user, @new_nearby, @host = user, new_nearby, host
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

View File

@ -0,0 +1,22 @@
<% provide(:title, 'New JamKazam Musicians in your Area') %>
<% link_style = "background-color:#ED3618; margin:0px 8px 0px 8px; border: solid 1px #F27861; outline: solid 2px #ED3618; padding:3px 10px; font-family:raleway; font-size:12px; font-weight:300; cursor:pointer; color:#FC9; text-decoration:none;" %>
<p>
<table bgcolor="#242323" cellpadding="3px" cellspacing="5px">
<% @new_nearby.each do |user| %>
<tr valign="top">
<td width="10%"><img src="http://<%= @host %>/assets/shared/avatar_generic.png" /></td>
<td width="20%"><font color="#ccc"><%= user.name %><br />
<%= user.location %></font><br />
<% user.instruments.each do |inst| %>
<img src="http://<%= @host %>/assets/content/icon_instrument_<%= inst.icon_name %>24.png" width="24" height="24" />
<% end %>
</td>
<td width="70%"><font color="#ccc"><%= user.biography %></font><br /><br />
<a style="<%= link_style %>" href="http://<%= @host %>/#/profile/<%= user.id %>">Profile</a>&nbsp;&nbsp;<!--<a style="<%= link_style %>" href="">Friend</a>-->
</td>
</tr>
<tr><td colspan="3"></td></tr>
<% end %>
</table>
</p>

View File

@ -0,0 +1,9 @@
<% provide(:title, 'New JamKazam Musicians in your Area') %>
<% @new_nearby.each do |user| %>
<%= user.name %> (http://<%= @host %>/#/profile/<%= user.id %>)
<%= user.location %>
<% user.instruments.collect { |inst| inst.description }.join(', ') %>
<%= user.biography %>
<% end %>

View File

@ -1,6 +1,35 @@
module JamRuby
class Instrument < ActiveRecord::Base
MAP_ICON_NAME = {
"accordion" => "accordion",
"acoustic guitar" => "acoustic",
"banjo" => "banjo",
"bass guitar" => "bass",
"cello" => "cello",
"clarinet" => "clarinet",
"computer" => "computer",
"default" => "default",
"drums" => "drums",
"electric guitar" => "guitar",
"euphonium" => "euphonium",
"flute" => "flute",
"french horn" => "frenchhorn",
"harmonica" => "harmonica",
"keyboard" => "keyboard",
"mandolin" => "mandolin",
"oboe" => "oboe",
"other" => "other",
"saxophone" => "saxophone",
"trombone" => "trombone",
"trumpet" => "trumpet",
"tuba" => "tuba",
"ukulele" => "ukelele",
"viola" => "viola",
"violin" => "violin",
"voice" => "vocals"
}
self.primary_key = 'id'
# users
@ -16,5 +45,9 @@ module JamRuby
return Instrument.where('instruments.popularity > 0').order('instruments.popularity DESC, instruments.description ASC')
end
def icon_name
MAP_ICON_NAME[self.id]
end
end
end

View File

@ -250,15 +250,17 @@ module JamRuby
false
end
def self.new_musicians(since_date=Time.now - 1.week, max_count=100, 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
def self.new_musicians(usr, since_date=Time.now - 1.week, max_count=50, radius=M_MILES_DEFAULT)
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)
objs = rel.all.to_a
if block_given?
yield(objs) if 0 < objs.count
else
return objs
end
end

View File

@ -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(since_date=Time.now-1.week)
self.geocoded_users.find_each do |usr|
Search.new_musicians(usr, since_date) do |new_nearby|
UserMailer.new_musicians(usr, new_nearby).deliver
end
end
end
# devise compatibility

View File

@ -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

View File

@ -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

7
web/lib/tasks/users.rake Normal file
View File

@ -0,0 +1,7 @@
namespace :users do
desc "Import a maxmind database; run like this: rake db:import_maxmind_geo file=<path_to_Geo139.csv>"
task new_musician_email: :environment do
User.deliver_new_musician_notifications(Time.now-12.months)
end
end