vrfs-774: refactoring tests, using expect syntax over should
This commit is contained in:
parent
5b1ea983fa
commit
68f6225461
|
|
@ -1,75 +1,65 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe User do
|
||||
describe 'Ad hoc musician search' do
|
||||
|
||||
before(:each) do
|
||||
@geocode1 = FactoryGirl.create(:geocoder)
|
||||
@geocode2 = FactoryGirl.create(:geocoder)
|
||||
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)
|
||||
@users << @user1 = FactoryGirl.create(:user)
|
||||
@users << @user2 = FactoryGirl.create(:user)
|
||||
@users << @user3 = FactoryGirl.create(:user)
|
||||
@users << @user4 = FactoryGirl.create(:user)
|
||||
end
|
||||
|
||||
it "should find all musicians sorted by followers with pagination" do
|
||||
# establish sorting order
|
||||
@user4.followers.concat([@user2, @user3, @user4])
|
||||
@user3.followers.concat([@user3, @user4])
|
||||
@user2.followers.concat([@user1])
|
||||
@user4.followers.count.should == 3
|
||||
context 'default filter settings' do
|
||||
|
||||
UserFollower.count.should == 6
|
||||
it "finds all musicians" do
|
||||
pending
|
||||
# expects all the users
|
||||
num = User.where({:musician => true}).count
|
||||
results = Search.musician_search({ :per_page => num })
|
||||
expect(results.musicians.count).to eq(num)
|
||||
|
||||
# get all the users in correct order
|
||||
params = { :per_page => @users.size }
|
||||
results = Search.musician_search(params)
|
||||
results.musicians.count.should == @users.size
|
||||
|
||||
results.musicians.each_with_index do |uu, idx|
|
||||
uu.id.should == @users.reverse[idx].id
|
||||
# the ordering should be create_at since no followers exist
|
||||
expect(UserFollower.count).to eq(0)
|
||||
results.musicians.each_with_index do |uu, idx|
|
||||
expect(uu.id).to eq(@users.reverse[idx].id)
|
||||
end
|
||||
end
|
||||
|
||||
# refresh the order to ensure it works right
|
||||
@user2.followers.concat([@user3, @user4, @user2])
|
||||
results = Search.musician_search(params, @user3)
|
||||
results.musicians[0].id.should == @user2.id
|
||||
it "sorts musicians by followers" do
|
||||
pending
|
||||
# establish sorting order
|
||||
@user4.followers.concat([@user2, @user3, @user4])
|
||||
@user3.followers.concat([@user3, @user4])
|
||||
@user2.followers.concat([@user1])
|
||||
expect(@user4.followers.count).to be 3
|
||||
|
||||
# check the follower count for given entry
|
||||
results.musicians[0].search_follow_count.to_i.should_not == 0
|
||||
# check the follow relationship between current_user and result
|
||||
results.is_follower?(@user2).should == true
|
||||
expect(UserFollower.count).to be 6
|
||||
|
||||
# make sure pagination works right
|
||||
params = { :per_page => 2, :page => 1 }
|
||||
results = Search.musician_search(params)
|
||||
results.musicians.count.should == 2
|
||||
end
|
||||
# refresh the order to ensure it works right
|
||||
@user2.followers.concat([@user3, @user4, @user2])
|
||||
results = Search.musician_search({ :per_page => @users.size }, @user3)
|
||||
expect(results.musicians[0].id).to eq(@user2.id)
|
||||
|
||||
# check the follower count for given entry
|
||||
expect(results.musicians[0].search_follow_count.to_i).not_to eq(0)
|
||||
# check the follow relationship between current_user and result
|
||||
expect(results.is_follower?(@user2)).to be true
|
||||
|
||||
expect(@user4.top_followings.count).to be 3
|
||||
expect(@user4.top_followings.map(&:id)).to match_array((@users - [@user1]).map(&:id))
|
||||
end
|
||||
|
||||
it 'paginates properly' do
|
||||
pending
|
||||
# make sure pagination works right
|
||||
params = { :per_page => 2, :page => 1 }
|
||||
results = Search.musician_search(params)
|
||||
expect(results.musicians.count).to be 2
|
||||
end
|
||||
|
||||
it "should have friends counter " do
|
||||
Friendship.save(@user1.id, @user2.id)
|
||||
results = Search.musician_search({}, @user2)
|
||||
friend = results.musicians.detect { |mm| mm.id == @user1.id }
|
||||
friend.should_not == nil
|
||||
results.friend_count(friend).should == 1
|
||||
@user1.reload
|
||||
friend.friends?(@user2).should == true
|
||||
results.is_friend?(@user1).should == true
|
||||
end
|
||||
|
||||
def make_recording(uu)
|
||||
|
|
@ -88,89 +78,125 @@ describe User do
|
|||
recording
|
||||
end
|
||||
|
||||
it "should have recording counter " do
|
||||
recording = make_recording(@user1)
|
||||
recording.users.length.should == 1
|
||||
recording.users.first.should == @user1
|
||||
@user1.reload
|
||||
@user1.recordings.length.should == 1
|
||||
@user1.recordings.first.should == recording
|
||||
recording.claimed_recordings.length.should == 1
|
||||
@user1.recordings.detect { |rr| rr == recording }.should_not be nil
|
||||
context 'musician stat counters' do
|
||||
|
||||
results = Search.musician_search({},@user1)
|
||||
uu = results.musicians.detect { |mm| mm.id == @user1.id }
|
||||
uu.should_not == nil
|
||||
|
||||
results.record_count(uu).should == 1
|
||||
results.session_count(uu).should == 1
|
||||
end
|
||||
|
||||
it "should find musicians sorted by plays" do
|
||||
make_recording(@user1)
|
||||
results = Search.musician_search({ :orderby => 'plays' }, @user2)
|
||||
results.musicians[0].id.should == @user1.id
|
||||
make_recording(@user2)
|
||||
make_recording(@user2)
|
||||
results = Search.musician_search({ :orderby => 'plays' }, @user2)
|
||||
results.musicians[0].id.should == @user2.id
|
||||
end
|
||||
|
||||
it "should find all musicians sorted by now playing" do
|
||||
connection = FactoryGirl.create(:connection, :user => @user3)
|
||||
music_session = FactoryGirl.create(:music_session, :creator => @user3, :musician_access => true)
|
||||
music_session.connections << connection
|
||||
music_session.save
|
||||
results = Search.musician_search({ :orderby => 'playing' }, @user2)
|
||||
results.musicians.count.should == 1
|
||||
connection = FactoryGirl.create(:connection, :user => @user4)
|
||||
music_session = FactoryGirl.create(:music_session, :creator => @user4, :musician_access => true)
|
||||
music_session.connections << connection
|
||||
music_session.save
|
||||
results = Search.musician_search({ :orderby => 'playing' }, @user2)
|
||||
results.musicians.count.should == 2
|
||||
connection = FactoryGirl.create(:connection, :user => @user1)
|
||||
music_session = FactoryGirl.create(:music_session, :creator => @user1, :musician_access => true)
|
||||
music_session.connections << connection
|
||||
music_session.save
|
||||
results = Search.musician_search({ :orderby => 'playing' }, @user2)
|
||||
results.musicians.count.should == 3
|
||||
end
|
||||
|
||||
it "should find musicians with an instrument" do
|
||||
minst = FactoryGirl.create(:musician_instrument, {
|
||||
:user => @user1,
|
||||
:instrument => Instrument.find('tuba') })
|
||||
@user1.musician_instruments << minst
|
||||
@user1.reload
|
||||
ii = @user1.instruments.detect { |inst| inst.id == 'tuba' }
|
||||
ii.should_not be_nil
|
||||
params = { :instrument => ii.id }
|
||||
results = Search.musician_search(params)
|
||||
results.musicians.each do |rr|
|
||||
rr.instruments.detect { |inst| inst.id=='tuba' }.id.should == ii.id
|
||||
it "friends stat shows friend count" do
|
||||
pending
|
||||
# create friendship record
|
||||
Friendship.save(@user1.id, @user2.id)
|
||||
# search on user2
|
||||
results = Search.musician_search({}, @user2)
|
||||
friend = results.musicians.detect { |mm| mm.id == @user1.id }
|
||||
expect(friend).to_not be_nil
|
||||
expect(results.friend_count(friend)).to be 1
|
||||
@user1.reload
|
||||
expect(friend.friends?(@user2)).to be true
|
||||
expect(results.is_friend?(@user1)).to be true
|
||||
end
|
||||
|
||||
it "recording stat shows recording count" do
|
||||
pending
|
||||
recording = make_recording(@user1)
|
||||
expect(recording.users.length).to be 1
|
||||
expect(recording.users.first).to eq(@user1)
|
||||
@user1.reload
|
||||
expect(@user1.recordings.length).to be 1
|
||||
expect(@user1.recordings.first).to eq(recording)
|
||||
expect(recording.claimed_recordings.length).to be 1
|
||||
expect(@user1.recordings.detect { |rr| rr == recording }).to_not be_nil
|
||||
|
||||
results = Search.musician_search({},@user1)
|
||||
uu = results.musicians.detect { |mm| mm.id == @user1.id }
|
||||
expect(uu).to_not be_nil
|
||||
|
||||
expect(results.record_count(uu)).to be 1
|
||||
expect(results.session_count(uu)).to be 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'musician sorting' do
|
||||
|
||||
it "by plays" do
|
||||
pending
|
||||
make_recording(@user1)
|
||||
# order results by num recordings
|
||||
results = Search.musician_search({ :orderby => 'plays' }, @user2)
|
||||
expect(results.musicians[0].id).to eq(@user1.id)
|
||||
|
||||
# add more data and make sure order still correct
|
||||
make_recording(@user2); make_recording(@user2)
|
||||
results = Search.musician_search({ :orderby => 'plays' }, @user2)
|
||||
expect(results.musicians[0].id).to eq(@user2.id)
|
||||
end
|
||||
|
||||
it "by now playing" do
|
||||
connection = FactoryGirl.create(:connection, :user => @user3)
|
||||
music_session = FactoryGirl.create(:music_session, :creator => @user3, :musician_access => true)
|
||||
music_session.connections << connection
|
||||
music_session.save
|
||||
results = Search.musician_search({ :orderby => 'playing' }, @user2)
|
||||
results.musicians.count.should be 1
|
||||
connection = FactoryGirl.create(:connection, :user => @user4)
|
||||
music_session = FactoryGirl.create(:music_session, :creator => @user4, :musician_access => true)
|
||||
music_session.connections << connection
|
||||
music_session.save
|
||||
results = Search.musician_search({ :orderby => 'playing' }, @user2)
|
||||
results.musicians.count.should be 2
|
||||
connection = FactoryGirl.create(:connection, :user => @user1)
|
||||
music_session = FactoryGirl.create(:music_session, :creator => @user1, :musician_access => true)
|
||||
music_session.connections << connection
|
||||
music_session.save
|
||||
results = Search.musician_search({ :orderby => 'playing' }, @user2)
|
||||
results.musicians.count.should be 3
|
||||
end
|
||||
|
||||
it "should find musicians with an instrument" do
|
||||
pending
|
||||
minst = FactoryGirl.create(:musician_instrument, {
|
||||
:user => @user1,
|
||||
:instrument => Instrument.find('tuba') })
|
||||
@user1.musician_instruments << minst
|
||||
@user1.reload
|
||||
ii = @user1.instruments.detect { |inst| inst.id == 'tuba' }
|
||||
ii.should_not be_nil
|
||||
params = { :instrument => ii.id }
|
||||
results = Search.musician_search(params)
|
||||
results.musicians.each do |rr|
|
||||
rr.instruments.detect { |inst| inst.id=='tuba' }.id.should == ii.id
|
||||
end
|
||||
results.musicians.count.should be 1
|
||||
end
|
||||
results.musicians.count.should == 1
|
||||
end
|
||||
|
||||
it "should find musicians within a given distance of location" do
|
||||
pending
|
||||
@user1.lat.should_not == nil
|
||||
params = { :distance => 10, :city => 'San Francisco' }
|
||||
results = Search.musician_search(params)
|
||||
results.musicians.count.should == 0
|
||||
results.musicians.count.should be 0
|
||||
|
||||
params = { :distance => 10, :city => 'Apex' }
|
||||
results = Search.musician_search(params)
|
||||
results.musicians.count.should == User.count
|
||||
results.musicians.count.should be User.count
|
||||
|
||||
params = { :distance => 10 }
|
||||
results = Search.musician_search(params)
|
||||
results.musicians.count.should == User.count
|
||||
results.musicians.count.should be User.count
|
||||
end
|
||||
|
||||
it "should find new musicians nearby" do
|
||||
pending
|
||||
params = {
|
||||
first_name: "Example", last_name: "User",
|
||||
email: "#{User.count+1}@example.com", email_confirmed: true,
|
||||
password: "foobar", password_confirmation: "foobar",
|
||||
musician: true,
|
||||
city: "Austin", state: "TX", country: "US"
|
||||
}
|
||||
FactoryGirl.create(:user, params)
|
||||
Search.new_musicians do |usrs|
|
||||
usrs.count.should.not == 0
|
||||
usrs.count.should eq(User.count - 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue