vrfs-774: added search tests, ui integration

This commit is contained in:
Jonathan Kolyer 2013-11-05 04:23:01 -06:00
parent 4379ab4283
commit 16cddf67d2
7 changed files with 123 additions and 80 deletions

View File

@ -74,27 +74,58 @@
}
else {
$noMusiciansFound.hide();
musicians = musicianList;
renderMusicians();
musicians = musicianList['musicians'];
if (!(typeof musicians === 'undefined')) {
renderMusicians();
}
}
}
/**
* Render a list of musicians
*/
* Render a list of musicians
*/
function renderMusicians() {
var ii, len;
var mTemplate = $('#template-find-musician-row').html();
var fTemplate = $('#template-musician-follow-info').html();
var mVals, mm, renderings='';
var instrument_html;
var instr_logos, instr;
var follows, followVals, aFollow;
for (ii=0, len=musicians.length; ii < len; ii++) {
mm = musicians[ii];
instr_logos = '';
for (var jj=0, ilen=mm['instruments'].length; jj<ilen; jj++) {
if (mm['instruments'][jj].instrument_id in instrument_logo_map) {
instr = instrument_logo_map[mm['instruments'][jj].instrument_id];
}
instr_logos += '<img src="' + instr + '" width="24" height="24" />&nbsp;';
}
follows = '';
followVals = {};
for (var jj=0, ilen=mm['followings'].length; jj<ilen; jj++) {
aFollow = mm['followings'][jj];
followVals = {
musician_name: aFollow.name,
profile_url: '/#/profile/' + aFollow.user_id,
avatar_url: context.JK.resolveAvatarUrl(aFollow.photo_url),
};
follows += context.JK.fillTemplate(fTemplate, followVals);
if (2 == jj) break;
}
mVals = {
avatar_url: context.JK.resolveAvatarUrl(mm.photo_url),
profile_url: "/#/profile/" + mm.id,
like_url: '#',
friend_url: '#',
follow_url: '#',
musician_name: mm.name,
musician_location: mm.city + ', ' + mm.state,
instruments: instrument_html
instruments: instr_logos,
biography: mm['biography'],
follow_count: mm['follow_count'],
friend_count: mm['friend_count'],
musician_follow_template: follows
};
renderings += context.JK.fillTemplate(mTemplate, mVals);
}
@ -129,8 +160,8 @@
}
/**
* Initialize,
*/
* Initialize,
*/
function initialize() {
var screenBindings = {
@ -151,4 +182,4 @@
return this;
};
})(window,jQuery);
})(window,jQuery);

View File

@ -17,6 +17,15 @@ unless @search.musicians.nil? || @search.musicians.size == 0
child :musician_instruments => :instruments do
attributes :instrument_id, :description, :proficiency_level, :priority
end
child :user_followings => :followings do |uf|
node :user_id do |uu| uu.following.id end
node :photo_url do |uu| uu.following.photo_url end
node :name do |uu| uu.following.name end
end
node :follow_count do |musician| musician.follow_count end
node :friend_count do |musician| musician.friend_count end
}
end

View File

@ -1,7 +1,7 @@
<div style="min-width:770px;">
<div class="left ml35" style="padding-top:3px;">Filter Musician List:</div>
<!-- order by filter -->
<%= select_tag(:musician_order_by, options_for_select(Search::ORDERINGS), {:class => 'musician-order-by'} ) %>
<%= select_tag(:musician_order_by, options_for_select(Search::M_ORDERINGS), {:class => 'musician-order-by'} ) %>
<!-- instrument filter -->
<div id="find-musician-instrument" class="right ml10">
<%= select_tag(:instrument,

View File

@ -1,50 +0,0 @@
<div class="list-result">
<!-- avatar -->
<div class="avatar-small"><img src="images/shared/avatar_david.jpg" /></div>
<!-- name & location -->
<div class="result-name">David Wilson<br />
<span class="result-location">San Francisco, CA
<br /><br />
<div class="left mr10 mb"><img src="images/content/icon_instrument_guitar24.png" width="24" height="24" /></div>
<div class="left mr10"><img src="images/content/icon_instrument_vocal24.png" width="24" height="24" /></div>
<div class="left mr10"><img src="images/content/icon_instrument_keyboard24.png" width="24" height="24" /></div>
<br clear="all" /><br />
122 <img src="images/content/icon_friend.png" width="14" height="12" align="absmiddle" />&nbsp;&nbsp;&nbsp;4 <img src="images/content/icon_followers.png" width="22" height="12" align="absmiddle" />&nbsp;&nbsp;&nbsp;17 <img src="images/content/icon_recordings.png" width="12" height="13" align="absmiddle" />&nbsp;&nbsp;&nbsp;64 <img src="images/content/icon_session_tiny.png" width="12" height="12" align="absmiddle" /></span><br /><br />
</div>
<div class="left ml35 f11 whitespace w40"><br />
Nulla facilisi. In vel sem. Morbi id urna in diam dignissim feugiat. Proin molestie tortor eu velit. Aliquam erat volutpat. Nullam ultrices, diam tempus vulputate egestas, eros pede varius leo, sed imperdiet lectus est ornare odio.<br />
<br />
<a href="#" class="button-orange smallbutton m0">PROFILE</a><a href="#" class="button-orange smallbutton">LIKE</a><a href="#" class="button-orange smallbutton m0">FRIEND</a><a href="#" class="button-orange smallbutton">FOLLOW</a></div>
<div class="left ml10 w20">
<br />
<small><strong>FOLLOWING:</strong></small>
<table class="musicians" cellpadding="0" cellspacing="5">
<tr>
<td width="24"><a href="#" class="avatar-tiny"><img src="images/content/avatar_band3.jpg" /></a></td>
<td><a href="#"><strong>Fox Force Five</strong></a></td>
</tr>
<tr>
<td width="24"><a href="#" class="avatar-tiny"><img src="images/content/avatar_band1.jpg" /></a></td>
<td><a href="#"><strong>Tammany Hall</strong></a></td>
</tr>
<tr>
<td width="24"><a href="#" class="avatar-tiny"><img src="images/content/avatar_band2.jpg" /></a></td>
<td><a href="#"><strong>Bethany Grey</strong></a></td>
<td></td>
<td></td>
</tr>
</table>
</div>
<br clear="all" />
</div>
<!-- end list result -->

View File

@ -42,34 +42,32 @@
{instruments}
</div>
<br clear="all" /><br />
122 <img src="images/content/icon_friend.png" width="14" height="12" align="absmiddle" />&nbsp;&nbsp;&nbsp;4 <img src="images/content/icon_followers.png" width="22" height="12" align="absmiddle" />&nbsp;&nbsp;&nbsp;17 <img src="images/content/icon_recordings.png" width="12" height="13" align="absmiddle" />&nbsp;&nbsp;&nbsp;64 <img src="images/content/icon_session_tiny.png" width="12" height="12" align="absmiddle" /></span><br /><br />
{follow_count} <img src="../assets/content/icon_friend.png" width="14" height="12" align="absmiddle" />&nbsp;&nbsp;&nbsp;4 <img src="../assets/content/icon_followers.png" width="22" height="12" align="absmiddle" />&nbsp;&nbsp;&nbsp;17 <img src="../assets/content/icon_recordings.png" width="12" height="13" align="absmiddle" />&nbsp;&nbsp;&nbsp;64 <img src="../assets/content/icon_session_tiny.png" width="12" height="12" align="absmiddle" /></span><br /><br />
</div>
<div class="left ml35 f11 whitespace w40"><br />
Nulla facilisi. In vel sem. Morbi id urna in diam dignissim feugiat. Proin molestie tortor eu velit. Aliquam erat volutpat. Nullam ultrices, diam tempus vulputate egestas, eros pede varius leo, sed imperdiet lectus est ornare odio.<br />
{biography}<br />
<br />
<a href="#" class="button-orange smallbutton m0">PROFILE</a><a href="#" class="button-orange smallbutton">LIKE</a><a href="#" class="button-orange smallbutton m0">FRIEND</a><a href="#" class="button-orange smallbutton">FOLLOW</a></div>
<a href="{profile_url}" class="button-orange smallbutton m0">PROFILE</a><a href="{like_url}" class="button-orange smallbutton">LIKE</a><a href="{friend_url}" class="button-orange smallbutton m0">FRIEND</a><a href="{follow_url}" class="button-orange smallbutton">FOLLOW</a></div>
<div class="left ml10 w20">
<br />
<small><strong>FOLLOWING:</strong></small>
<table class="musicians" cellpadding="0" cellspacing="5">
<tr>
<td width="24"><a href="#" class="avatar-tiny"><img src="images/content/avatar_band3.jpg" /></a></td>
<td><a href="#"><strong>Fox Force Five</strong></a></td>
</tr>
<tr>
<td width="24"><a href="#" class="avatar-tiny"><img src="images/content/avatar_band1.jpg" /></a></td>
<td><a href="#"><strong>Tammany Hall</strong></a></td>
</tr>
<tr>
<td width="24"><a href="#" class="avatar-tiny"><img src="images/content/avatar_band2.jpg" /></a></td>
<td><a href="#"><strong>Bethany Grey</strong></a></td>
<td></td>
<td></td>
</tr>
{musician_follow_template}
</table>
</div>
<br clear="all" />
</div>
</script>
<script type="text/template" id="template-musician-follow-info">
<tr>
<td width="24">
<a href="{profile_url}" class="avatar-tiny"><img src="{avatar_url}" /></a>
</td>
<td>
<a href="{profile_url}"><strong>{musician_name}</strong></a>
</td>
</tr>
</script>

View File

@ -2,10 +2,14 @@ namespace :db do
desc "Fill database with sample data"
task populate: :environment do
make_users
make_microposts
# make_microposts
make_relationships
end
task populate_followings: :environment do
make_followings
end
desc "Fill database with music session sample data"
task populate_music_sessions: :environment do
make_users(10) if 14 > User.count
@ -102,6 +106,16 @@ def make_relationships
user = users.first
followed_users = users[2..50]
followers = users[3..40]
followed_users.each { |followed| user.follow!(followed) }
followed_users.each { |followed| user.followings << followed }
followers.each { |follower| follower.follow!(user) }
end
def make_followings
users = User.all
users[6..-1].each do |uu|
users[0..5].shuffle.each do |uuu|
uu.followings << uuu
uuu.followings << uu
end
end
end

View File

@ -45,5 +45,46 @@ describe "Musician Search API", :type => :api do
instruments.detect { |ii| ii['instrument_id'] == 'tuba' }.should_not == nil
instruments.detect { |ii| ii['instrument_id'] == 'electric guitar' }.should_not == nil
end
it "following search" do
params = {
first_name: "Example",
last_name: "User",
email: "user1@example.com",
password: "foobar",
password_confirmation: "foobar",
musician: true,
email_confirmed: true,
city: "Apex",
state: "NC",
country: "US"
}
@users = []
@users << @user1 = FactoryGirl.create(:user, params)
params[:email] = "user2@example.com"
@users << @user2 = FactoryGirl.create(:user, params)
params[:email] = "user3@example.com"
@users << @user3 = FactoryGirl.create(:user, params)
params[:email] = "user4@example.com"
@users << @user4 = FactoryGirl.create(:user, params)
@user4.followers.concat([@user2, @user3, @user4])
@user3.followers.concat([@user3, @user4])
@user2.followers.concat([@user4])
@user4.followers.count.should == 3
Friendship.save(@user1.id, @user2.id)
get_query
last_response.status.should == 200
response = JSON.parse(last_response.body)
musician = response["musicians"][0]
musician["id"].should == @user4.id
followings= musician['followings']
followings.length.should == 3
friend = response['musicians'].detect { |mm| mm['id'] == @user1.id }
friend['friend_count'].should == 1
end
end
end