VRFS-3242 : Schema and model changes required for band profile functionality.

* Additional attributes for band_type, band_status, concert_count,
add_new_members, play_commitment, touring_option, paid_gigs,
hourly_rate, gig_minimum
* For joined table musician_instruments, remove the hard requirement
that they be joined to a user, rather a “player” that is polymorphic.
* For joined table performance_stamples, remove the hard requirement
that they be joined to a user, rather a “player” that is polymorphic.
* For joined table online_presences, remove the hard requirement that
they be joined to a user, rather a “player” that is polymorphic.
* Change models as appropriate with new attributes and modify
belongs_to / has_many directives as necessary.
* Fix existing usages of user_id to work with polymorphic player_id.
* Fix tests that use user_id
* Add new tests that exercise online_presence, performance_samples, and
instruments that target a band, rather than a user.
This commit is contained in:
Steven Miers 2015-05-13 21:06:14 -05:00
parent 193888f960
commit 11f60b71e4
24 changed files with 370 additions and 292 deletions

View File

@ -19,7 +19,7 @@ FactoryGirl.define do
end
before(:create) do |user|
user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user)
user.musician_instruments << FactoryGirl.build(:musician_instrument, player: user)
end
factory :single_user_session do

View File

@ -289,3 +289,4 @@ payment_history.sql
jam_track_right_private_key.sql
first_downloaded_jamtrack_at.sql
signing.sql
enhance_band_profile.sql

View File

@ -0,0 +1,25 @@
ALTER TABLE bands ADD COLUMN band_type VARCHAR(16) DEFAULT 'not specified';
ALTER TABLE bands ADD COLUMN band_status VARCHAR(16) DEFAULT 'not specified';
ALTER TABLE bands ADD COLUMN concert_count SMALLINT DEFAULT 0;
ALTER TABLE bands ADD COLUMN add_new_members BOOLEAN DEFAULT FALSE;
ALTER TABLE bands ADD COLUMN play_commitment SMALLINT DEFAULT 0;
ALTER TABLE bands ADD COLUMN touring_option BOOLEAN DEFAULT FALSE;
ALTER TABLE bands ADD COLUMN paid_gigs BOOLEAN DEFAULT FALSE;
ALTER TABLE bands ADD COLUMN free_gigs BOOLEAN DEFAULT FALSE;
ALTER TABLE bands ADD COLUMN hourly_rate INT DEFAULT 0;
ALTER TABLE bands ADD COLUMN gig_minimum INT DEFAULT 0;
ALTER TABLE musicians_instruments ALTER COLUMN user_id DROP NOT NULL;
ALTER TABLE musicians_instruments RENAME COLUMN user_id TO player_id;
ALTER TABLE musicians_instruments ADD COLUMN player_type VARCHAR(32) DEFAULT 'user';
ALTER TABLE musicians_instruments DROP CONSTRAINT musicians_instruments_user_id_fkey;
ALTER TABLE performance_samples ALTER COLUMN user_id DROP NOT NULL;
ALTER TABLE performance_samples RENAME COLUMN user_id TO player_id;
ALTER TABLE performance_samples ADD COLUMN player_type VARCHAR(32) DEFAULT 'user';
ALTER TABLE performance_samples DROP CONSTRAINT performance_samples_user_id_fkey;
ALTER TABLE online_presences ALTER COLUMN user_id DROP NOT NULL;
ALTER TABLE online_presences RENAME COLUMN user_id TO player_id;
ALTER TABLE online_presences ADD COLUMN player_type VARCHAR(32) DEFAULT 'user';
ALTER TABLE online_presences DROP CONSTRAINT online_presences_user_id_fkey;

View File

@ -5,7 +5,9 @@ module JamRuby
attr_accessible :name, :website, :biography, :city, :state,
:country, :original_fpfile_photo, :cropped_fpfile_photo, :cropped_large_fpfile_photo,
:cropped_s3_path_photo, :cropped_large_s3_path_photo, :crop_selection_photo, :photo_url, :large_photo_url
:cropped_s3_path_photo, :cropped_large_s3_path_photo, :crop_selection_photo, :photo_url, :large_photo_url,
:band_type, :band_status, :concert_count, :add_new_members, :play_commitment, :touring_option, :paid_gigs,
:free_gigs, :hourly_rate, :gig_minimum
attr_accessor :updating_photo, :skip_location_validation
@ -25,6 +27,14 @@ module JamRuby
before_save :check_lat_lng
before_save :check_website_url
# instruments
has_many :musician_instruments, :class_name => "JamRuby::MusicianInstrument", :foreign_key=> 'player_id'
has_many :instruments, :through => :musician_instruments, :class_name => "JamRuby::Instrument", :foreign_key=> 'player_id'
has_many :online_presences, :class_name => "JamRuby::OnlinePresence"
has_many :performance_samples, :class_name => "JamRuby::PerformanceSample"
# musicians
has_many :band_musicians, :class_name => "JamRuby::BandMusician", dependent: :destroy
has_many :users, :through => :band_musicians, :class_name => "JamRuby::User"

View File

@ -36,7 +36,7 @@ module JamRuby
# users
has_many :musician_instruments, :class_name => "JamRuby::MusicianInstrument"
has_many :users, :through => :musician_instruments, :class_name => "JamRuby::User"
has_many :players, :through => :musician_instruments
has_many :tracks, :class_name => "JamRuby::Track", :inverse_of => :instrument
has_many :recorded_tracks, :class_name => "JamRuby::RecordedTrack", :inverse_of => :instrument

View File

@ -10,7 +10,7 @@ module JamRuby
# proficiency is 1 = Beginner, 2 = Intermediate, 3 = Expert
belongs_to :user, :class_name => "JamRuby::User"
belongs_to :player, polymorphic: true
belongs_to :instrument, :class_name => "JamRuby::Instrument"
def description

View File

@ -137,7 +137,7 @@ module JamRuby
def _instruments(rel)
unless (instruments = json['instruments']).blank?
instsql = "SELECT user_id FROM musicians_instruments WHERE (("
instsql = "SELECT player_id FROM musicians_instruments WHERE (("
instsql += instruments.collect do |inst|
"instrument_id = '#{inst['instrument_id']}' AND proficiency_level = #{inst['proficiency_level']}"
end.join(") OR (")

View File

@ -3,8 +3,8 @@ module JamRuby
PERMISSION_MSG = "You do not have permission to perform this operation."
attr_accessible :user_id, :service_type, :username
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id"
attr_accessible :player_id, :service_type, :username
belongs_to :player, polymorphic: true
validates :service_type, presence:true, length: {maximum: 100}
validates :username, presence:true, length: {maximum: 100}
@ -18,15 +18,15 @@ module JamRuby
def self.index(options = {})
raise StateError, "The user is not specified." if options[:id].blank?
OnlinePresence.where("user_id = ?", options[:id])
OnlinePresence.where("player_id = ?", options[:id])
end
def self.create(current_user, options = {}, save = true)
auth_user(current_user, options)
def self.create(player, options = {}, save = true)
auth_player(player, options)
raise StateError, "Missing required information" if options[:service_type].blank? || options[:username].blank?
up = OnlinePresence.new({
:user_id => current_user.id,
:player_id => player.id,
:service_type => options[:service_type],
:username => options[:username]
})
@ -35,8 +35,8 @@ module JamRuby
up
end
def self.update(current_user, options = {})
auth_user(current_user, options)
def self.update(player, options = {})
auth_player(player, options)
raise StateError, "Missing required information" if options[:service_type].blank? || options[:username].blank? || options[:id].blank?
up = OnlinePresence.find(options[:id])
@ -45,12 +45,12 @@ module JamRuby
up.save!
end
def self.delete(current_user, options = {})
def self.delete(player, options = {})
id = options[:id]
raise StateError, "Missing required information" if id.blank?
online_presence = OnlinePresence.find(id)
if online_presence.user_id != current_user.id
if online_presence.player_id != player.id
raise JamPermissionError, PERMISSION_MSG
end
@ -60,8 +60,8 @@ module JamRuby
end
private
def self.auth_user(current_user, options={})
raise JamPermissionError, PERMISSION_MSG if current_user.nil? || options[:user_id] != current_user.id
def self.auth_player(player, options={})
raise JamPermissionError, PERMISSION_MSG if player.nil? || options[:player_id] != player.id
end
end
end

View File

@ -3,9 +3,9 @@ module JamRuby
PERMISSION_MSG = "You do not have permission to perform this operation."
attr_accessible :user_id, :service_type, :claimed_recording_id, :service_id, :url, :description
attr_accessible :player_id, :service_type, :claimed_recording_id, :service_id, :url, :description
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id"
belongs_to :player, polymorphic: true
belongs_to :claimed_recording, :class_name => "JamRuby::ClaimedRecording", :foreign_key => "claimed_recording_id"
validates :service_type, presence:true, length: {maximum: 100}
@ -23,7 +23,7 @@ module JamRuby
end
def user_type_recording_unique
match = PerformanceSample.exists?(:user_id => self.user_id, :claimed_recording_id => self.claimed_recording_id, :service_type => self.service_type)
match = PerformanceSample.exists?(:player_id => self.player_id, :claimed_recording_id => self.claimed_recording_id, :service_type => self.service_type)
raise ConflictError, "You already have this JamKazam recording listed as a sample" if match
end
@ -32,13 +32,13 @@ module JamRuby
end
def user_type_service_unique
match = PerformanceSample.exists?(:user_id => self.user_id, :service_id => self.service_id, :service_type => self.service_type)
match = PerformanceSample.exists?(:player_id => self.player_id, :service_id => self.service_id, :service_type => self.service_type)
raise ConflictError, "You already have this #{self.service_type} sample listed (#{self.service_id})." if match
end
def self.index(options = {})
raise JamArgumentError, "The user is not specified." if options[:id].blank?
PerformanceSample.where("user_id = ?", options[:id])
PerformanceSample.where("player_id = ?", options[:id])
end
def self.create(current_user, options = {}, save = true)
@ -46,7 +46,7 @@ module JamRuby
raise StateError, "Missing required information" if options[:service_type].blank?
ps = PerformanceSample.new({
:user_id => current_user.id,
:player_id => current_user.id,
:service_type => options[:service_type],
:claimed_recording_id => options[:claimed_recording_id],
:service_id => options[:service_id],
@ -59,14 +59,14 @@ module JamRuby
end
def self.delete(current_user, options = {})
raise JamPermissionError, "You do not have permission to perform this operation" if current_user.nil? || options[:user_id] != current_user.id
raise JamPermissionError, "You do not have permission to perform this operation" if current_user.nil? || options[:player_id] != current_user.id
raise StateError, "The performance sample ID is missing." if options[:id].blank?
PerformanceSample.destroy(options[:id])
end
private
def self.auth_user(current_user, options={})
raise JamPermissionError, PERMISSION_MSG if current_user.nil? || options[:user_id] != current_user.id
raise JamPermissionError, PERMISSION_MSG if current_user.nil? || options[:player_id] != current_user.id
end
end
end

View File

@ -164,7 +164,7 @@ module JamRuby
rel = rel.group('users.id')
unless (instrument = params[:instrument]).blank?
rel = rel.joins("inner JOIN musicians_instruments AS minst ON minst.user_id = users.id")
rel = rel.joins("inner JOIN musicians_instruments AS minst ON minst.player_id = users.id")
.where(['minst.instrument_id = ?', instrument])
end

View File

@ -53,7 +53,7 @@ module JamRuby
has_many :received_friend_requests, :class_name => "JamRuby::FriendRequest", :foreign_key => 'friend_id'
# instruments
has_many :musician_instruments, :class_name => "JamRuby::MusicianInstrument"
has_many :musician_instruments, :class_name => "JamRuby::MusicianInstrument", :foreign_key=> 'player_id'
has_many :instruments, :through => :musician_instruments, :class_name => "JamRuby::Instrument"
# bands
@ -165,8 +165,8 @@ module JamRuby
# This causes the authenticate method to be generated (among other stuff)
#has_secure_password
has_many :online_presences, :class_name => "JamRuby::OnlinePresence"
has_many :performance_samples, :class_name => "JamRuby::PerformanceSample"
has_many :online_presences, :class_name => "JamRuby::OnlinePresence", :foreign_key=> 'player_id'
has_many :performance_samples, :class_name => "JamRuby::PerformanceSample", :foreign_key=> 'player_id'
has_one :musician_search, :class_name => 'JamRuby::MusicianSearch'
@ -702,14 +702,14 @@ module JamRuby
def update_instruments(instruments)
# delete all instruments for this user first
unless self.new_record?
MusicianInstrument.delete_all(["user_id = ?", self.id])
MusicianInstrument.delete_all(["player_id = ?", self.id])
end
# loop through each instrument in the array and save to the db
instruments.each do |musician_instrument_param|
instrument = Instrument.find(musician_instrument_param[:instrument_id])
musician_instrument = MusicianInstrument.new
musician_instrument.user = self
musician_instrument.player = self
musician_instrument.instrument = instrument
musician_instrument.proficiency_level = musician_instrument_param[:proficiency_level]
musician_instrument.priority = musician_instrument_param[:priority]
@ -1034,7 +1034,7 @@ module JamRuby
instruments.each do |musician_instrument_param|
instrument = Instrument.find(musician_instrument_param[:instrument_id])
musician_instrument = MusicianInstrument.new
musician_instrument.user = user
musician_instrument.player = user
musician_instrument.instrument = instrument
musician_instrument.proficiency_level = musician_instrument_param[:proficiency_level]
musician_instrument.priority = musician_instrument_param[:priority]
@ -1167,13 +1167,13 @@ module JamRuby
end
unless user.new_record?
MusicianInstrument.delete_all(["user_id = ?", user.id])
MusicianInstrument.delete_all(["player_id = ?", user.id])
end
instruments.each do |musician_instrument_param|
instrument = Instrument.find(musician_instrument_param[:instrument_id])
musician_instrument = MusicianInstrument.new
musician_instrument.user = user
musician_instrument.player = user
musician_instrument.instrument = instrument
musician_instrument.proficiency_level = musician_instrument_param[:proficiency_level]
musician_instrument.priority = musician_instrument_param[:priority]

View File

@ -25,10 +25,10 @@ FactoryGirl.define do
before(:create) do |user, evaluator|
if evaluator.specific_instruments
evaluator.specific_instruments.each do |instrument|
user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user, instrument: instrument)
user.musician_instruments << FactoryGirl.build(:musician_instrument, player: user, instrument: instrument)
end
else
user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user)
user.musician_instruments << FactoryGirl.build(:musician_instrument, player: user)
end
end

View File

@ -46,7 +46,7 @@ describe ConnectionManager, no_transaction: true do
client_id = "client_id1"
user_id = create_user("test", "user1", "user1@jamkazam.com")
user = User.find(user_id)
user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user)
user.musician_instruments << FactoryGirl.build(:musician_instrument, player: user)
user.save!
user = nil

View File

@ -19,6 +19,21 @@ describe Band do
}
}
describe 'with instruments' do
it 'builds with instruments' do
band.musician_instruments << FactoryGirl.build(:musician_instrument, player: band)
band.musician_instruments.should have(1).items
band.instruments.should have(1).items
end
it 'creates with instruments' do
FactoryGirl.create(:musician_instrument, player: band)
band.reload
band.musician_instruments.should have(1).items
band.instruments.should have(1).items
end
end
describe 'website update' do
it 'should have http prefix on website url' do
band.website = 'example.com'

View File

@ -299,7 +299,7 @@ describe EmailBatchScheduledSessions do
4.downto(1) do |nn|
uu = FactoryGirl.create(:user, :last_jam_locidispid => 6, :last_jam_addr => 6)
uu.musician_instruments << FactoryGirl.build(:musician_instrument,
user: uu,
player: uu,
instrument: instruments.sample,
proficiency_level: 2)
end

View File

@ -2,159 +2,172 @@ require 'spec_helper'
describe OnlinePresence do
let(:user1) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
shared_examples_for :online_presence_specs do
describe "index" do
describe "index" do
before(:all) do
OnlinePresence.delete_all
before(:all) do
OnlinePresence.delete_all
player1_presence1 = OnlinePresence.new({:player_id => player1.id, :username => "myonlineusername", :service_type => "facebook"})
player1_presence1.save!
user1_presence1 = OnlinePresence.new({:user_id => user1.id, :username => "myonlineusername", :service_type => "facebook"})
user1_presence1.save!
player1_presence2 = OnlinePresence.new({:player_id => player1.id, :username => "myonlineusername", :service_type => "twitter"})
player1_presence2.save!
user1_presence2 = OnlinePresence.new({:user_id => user1.id, :username => "myonlineusername", :service_type => "twitter"})
user1_presence2.save!
player2_presence1 = OnlinePresence.new({:player_id => player2.id, :username => "myonlineusername", :service_type => "soundcloud"})
player2_presence1.save!
end
user2_presence1 = OnlinePresence.new({:user_id => user2.id, :username => "myonlineusername", :service_type => "soundcloud"})
user2_presence1.save!
end
context "when request is valid" do
it "should return all records for user" do
presence = OnlinePresence.index({:id => player1.id})
presence.count.should == 2
context "when request is valid" do
it "should return all records for user" do
presence = OnlinePresence.index({:id => user1.id})
presence.count.should == 2
presence = OnlinePresence.index({:id => player2.id})
presence.count.should == 1
end
end
presence = OnlinePresence.index({:id => user2.id})
presence.count.should == 1
context "when request is invalid" do
it "should raise error when options are missing" do
lambda{OnlinePresence.index}.should raise_error(StateError)
end
it "should raise error when user id is missing" do
lambda{OnlinePresence.index({:id => ""})}.should raise_error(StateError)
end
end
end
context "when request is invalid" do
it "should raise error when options are missing" do
lambda{OnlinePresence.index}.should raise_error(StateError)
describe "create" do
before(:all) do
OnlinePresence.delete_all
end
it "should raise error when user id is missing" do
lambda{OnlinePresence.index({:id => ""})}.should raise_error(StateError)
context "when request is valid" do
it "should save successfully" do
OnlinePresence.create(player1, {:player_id => player1.id, :service_type => "soundcloud", :username => "soundcloudplayer1"})
# make sure we can save a second OnlinePresence for same user and type
OnlinePresence.create(player1, {:player_id => player1.id, :service_type => "soundcloud", :username => "soundcloudplayer2"})
OnlinePresence.index({:id => player1.id}).count.should == 2
end
end
context "when request is not valid" do
it "should raise JamPermissionError if requester id does not match id in request" do
lambda{OnlinePresence.create(player1, {:player_id => player2.id, :service_type => "soundcloud", :username => "soundcloudplayer2"})}.should raise_error(JamPermissionError)
end
it "should raise error if service type is missing" do
lambda{OnlinePresence.create(player1, {:player_id => player1.id, :username => "soundcloudplayer2"})}.should raise_error(StateError)
end
it "should raise error if username is missing" do
lambda{OnlinePresence.create(player1, {:player_id => player1.id, :service_type => "soundcloud"})}.should raise_error(StateError)
end
it "should not allow duplicates of the same username / service type combination" do
OnlinePresence.create(player1, {:player_id => player1.id, :service_type => "soundcloud", :username => "soundcloudplayer1"})
OnlinePresence.index({:id => player1.id}).count.should == 1
lambda{OnlinePresence.create(player1, {:player_id => player1.id, :service_type => "soundcloud", :username => "soundcloudplayer1"})}.should raise_error(ConflictError)
OnlinePresence.index({:id => player1.id}).count.should == 1
end
end
end
describe "update" do
before(:all) do
OnlinePresence.delete_all
@online_presence = OnlinePresence.new(:player_id => player1.id, :service_type => "soundcloud", :username => "soundcloudplayer1")
@online_presence.save!
end
context "when request is valid" do
it "should save successfully" do
up_list = OnlinePresence.index({:id => player1.id})
up_list.count.should == 1
up_list.first.service_type.should == "soundcloud"
up_list.first.username.should == "soundcloudplayer1"
OnlinePresence.update(player1, {:id => @online_presence.id, :player_id => player1.id, :service_type => "soundcloud", :username => "soundcloudplayer2"})
up_list = OnlinePresence.index({:id => player1.id})
up_list.count.should == 1
up_list.first.service_type.should == "soundcloud"
up_list.first.username.should == "soundcloudplayer2"
end
end
context "when request is not valid" do
it "should raise JamPermissionError if requester id does not match id in request" do
lambda{OnlinePresence.update(player1, {:player_id => player2.id, :id => @online_presence.id, :service_type => "soundcloud", :username => "soundcloudplayer2"})}.should raise_error(JamPermissionError)
end
it "should raise error if type is missing" do
lambda{OnlinePresence.update(player1, {:player_id => player1.id, :id => @online_presence.id, :username => "soundcloudplayer2"})}.should raise_error(StateError)
end
it "should raise error if username is missing" do
lambda{OnlinePresence.update(player1, {:player_id => player1.id, :id => @online_presence.id, :service_type => "soundcloud"})}.should raise_error(StateError)
end
it "should raise error if player presence id is missing" do
lambda{OnlinePresence.update(player1, {:player_id => player1.id, :username => "soundcloudplayer2", :service_type => "soundcloud"})}.should raise_error(StateError)
end
end
end
describe "destroy" do
before(:all) do
OnlinePresence.delete_all
@online_presence = OnlinePresence.new(:player_id => player1.id, :service_type => "soundcloud", :username => "soundcloudplayer1")
@online_presence.save!
end
context "when request is valid" do
it "should destroy successfully" do
up_list = OnlinePresence.index({:id => player1.id})
up_list.count.should == 1
up_list.first.service_type.should == "soundcloud"
up_list.first.username.should == "soundcloudplayer1"
OnlinePresence.delete(player1, {:player_id => player1.id, :id => @online_presence.id})
up_list = OnlinePresence.index({:id => player1.id})
up_list.count.should == 0
end
end
context "when request is not valid" do
it "should raise JamPermissionError if requester id does not match id in request" do
lambda{OnlinePresence.delete(player2, {:player_id => player1.id, :id => @online_presence.id})}.should raise_error(JamPermissionError)
end
it "should raise error if player presence id is missing" do
lambda{OnlinePresence.delete(player1, {:player_id => player1.id})}.should raise_error(StateError)
end
end
end
end # shared
describe "with a user" do
it_should_behave_like :online_presence_specs do
let(:player1) { FactoryGirl.create(:user) }
let(:player2) { FactoryGirl.create(:user) }
end
end
describe "create" do
before(:all) do
OnlinePresence.delete_all
end
context "when request is valid" do
it "should save successfully" do
OnlinePresence.create(user1, {:user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser1"})
# make sure we can save a second OnlinePresence for same user and type
OnlinePresence.create(user1, {:user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser2"})
OnlinePresence.index({:id => user1.id}).count.should == 2
end
end
context "when request is not valid" do
it "should raise JamPermissionError if requester id does not match id in request" do
lambda{OnlinePresence.create(user1, {:user_id => user2.id, :service_type => "soundcloud", :username => "soundclouduser2"})}.should raise_error(JamPermissionError)
end
it "should raise error if service type is missing" do
lambda{OnlinePresence.create(user1, {:user_id => user1.id, :username => "soundclouduser2"})}.should raise_error(StateError)
end
it "should raise error if username is missing" do
lambda{OnlinePresence.create(user1, {:user_id => user1.id, :service_type => "soundcloud"})}.should raise_error(StateError)
end
it "should not allow duplicates of the same username / service type combination" do
OnlinePresence.create(user1, {:user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser1"})
OnlinePresence.index({:id => user1.id}).count.should == 1
lambda{OnlinePresence.create(user1, {:user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser1"})}.should raise_error(ConflictError)
OnlinePresence.index({:id => user1.id}).count.should == 1
end
end
end
describe "update" do
before(:all) do
OnlinePresence.delete_all
@online_presence = OnlinePresence.new(:user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser1")
@online_presence.save!
end
context "when request is valid" do
it "should save successfully" do
up_list = OnlinePresence.index({:id => user1.id})
up_list.count.should == 1
up_list.first.service_type.should == "soundcloud"
up_list.first.username.should == "soundclouduser1"
OnlinePresence.update(user1, {:id => @online_presence.id, :user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser2"})
up_list = OnlinePresence.index({:id => user1.id})
up_list.count.should == 1
up_list.first.service_type.should == "soundcloud"
up_list.first.username.should == "soundclouduser2"
end
end
context "when request is not valid" do
it "should raise JamPermissionError if requester id does not match id in request" do
lambda{OnlinePresence.update(user1, {:user_id => user2.id, :id => @online_presence.id, :service_type => "soundcloud", :username => "soundclouduser2"})}.should raise_error(JamPermissionError)
end
it "should raise error if type is missing" do
lambda{OnlinePresence.update(user1, {:user_id => user1.id, :id => @online_presence.id, :username => "soundclouduser2"})}.should raise_error(StateError)
end
it "should raise error if username is missing" do
lambda{OnlinePresence.update(user1, {:user_id => user1.id, :id => @online_presence.id, :service_type => "soundcloud"})}.should raise_error(StateError)
end
it "should raise error if user presence id is missing" do
lambda{OnlinePresence.update(user1, {:user_id => user1.id, :username => "soundclouduser2", :service_type => "soundcloud"})}.should raise_error(StateError)
end
end
end
describe "destroy" do
before(:all) do
OnlinePresence.delete_all
@online_presence = OnlinePresence.new(:user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser1")
@online_presence.save!
end
context "when request is valid" do
it "should destroy successfully" do
up_list = OnlinePresence.index({:id => user1.id})
up_list.count.should == 1
up_list.first.service_type.should == "soundcloud"
up_list.first.username.should == "soundclouduser1"
OnlinePresence.delete(user1, {:user_id => user1.id, :id => @online_presence.id})
up_list = OnlinePresence.index({:id => user1.id})
up_list.count.should == 0
end
end
context "when request is not valid" do
it "should raise JamPermissionError if requester id does not match id in request" do
lambda{OnlinePresence.delete(user2, {:user_id => user1.id, :id => @online_presence.id})}.should raise_error(JamPermissionError)
end
it "should raise error if user presence id is missing" do
lambda{OnlinePresence.delete(user1, {:user_id => user1.id})}.should raise_error(StateError)
end
describe "with a band" do
it_should_behave_like :online_presence_specs do
let(:player1) { FactoryGirl.create(:band) }
let(:player2) { FactoryGirl.create(:band) }
end
end
end

View File

@ -1,122 +1,136 @@
require 'spec_helper'
describe PerformanceSample do
let(:user1) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:claimed_recording) { FactoryGirl.create(:claimed_recording) }
describe "index" do
shared_examples_for :performance_sample_specs do
let(:claimed_recording) { FactoryGirl.create(:claimed_recording) }
before(:all) do
PerformanceSample.delete_all
describe "index" do
@user1_sample1 = PerformanceSample.new(:user_id => user1.id, :service_type => "jamkazam", :claimed_recording_id => claimed_recording.id)
@user1_sample1.save!
before(:all) do
PerformanceSample.delete_all
@user1_sample2 = PerformanceSample.new(:user_id => user1.id, :service_type => "youtube", :service_id => "12345")
@user1_sample2.save!
@player1_sample1 = PerformanceSample.new(:player_id => player1.id, :service_type => "jamkazam", :claimed_recording_id => claimed_recording.id)
@player1_sample1.save!
@user2_sample1 = PerformanceSample.new(:user_id => user2.id, :service_type => "soundcloud", :service_id => "67890")
@user2_sample1.save!
end
@player1_sample2 = PerformanceSample.new(:player_id => player1.id, :service_type => "youtube", :service_id => "12345")
@player1_sample2.save!
context "when request is valid" do
it "should return all records for user" do
sample = PerformanceSample.index({:id => user1.id})
sample.count.should == 2
@player2_sample1 = PerformanceSample.new(:player_id => player2.id, :service_type => "soundcloud", :service_id => "67890")
@player2_sample1.save!
end
sample = PerformanceSample.index({:id => user2.id})
sample.count.should == 1
context "when request is valid" do
it "should return all records for user" do
sample = PerformanceSample.index({:id => player1.id})
sample.count.should == 2
sample = PerformanceSample.index({:id => player2.id})
sample.count.should == 1
end
end
context "when request is invalid" do
it "should raise error when options are missing" do
lambda{PerformanceSample.index}.should raise_error(JamArgumentError)
end
it "should raise error when user id is missing" do
lambda{PerformanceSample.index({:id => ""})}.should raise_error(JamArgumentError)
end
end
end
context "when request is invalid" do
it "should raise error when options are missing" do
lambda{PerformanceSample.index}.should raise_error(JamArgumentError)
describe "create" do
before(:all) do
PerformanceSample.delete_all
end
it "should raise error when user id is missing" do
lambda{PerformanceSample.index({:id => ""})}.should raise_error(JamArgumentError)
context "when request is valid" do
it "should save successfully" do
PerformanceSample.create(player1, {:player_id => player1.id, :service_type => "youtube", :service_id => "12345"})
# make sure we can save a second PerformanceSample for same user and type
PerformanceSample.create(player1, {:player_id => player1.id, :service_type => "youtube", :service_id => "67890"})
end
end
context "when request is not valid" do
it "should raise JamPermissionError if requester id does not match id in request" do
lambda{PerformanceSample.create(player1, {:player_id => player2.id, :service_type => "soundcloud", :service_id => "12345"})}.should raise_error(JamPermissionError)
end
it "should raise error if service type is missing" do
lambda{PerformanceSample.create(player1, {:player_id => player1.id, :service_id => "12345"})}.should raise_error(StateError)
end
it "should raise error if service id is missing for non-JamKazam sample" do
lambda{PerformanceSample.create(player1, {:player_id => player1.id, :service_type => "youtube"})}.should raise_error(StateError)
end
it "should raise error if recording id is missing for JamKazam sample" do
lambda{PerformanceSample.create(player1, {:player_id => player1.id, :service_type => "jamkazam"})}.should raise_error(StateError)
end
it "should not allow duplicate type/service id combination for non-JamKazam sample" do
PerformanceSample.create(player1, {:player_id => player1.id, :service_type => "youtube", :service_id => "12345"})
lambda{PerformanceSample.create(player1, {:player_id => player1.id, :service_type => "youtube", :service_id => "12345"})}.should raise_error(ConflictError)
end
it "should not allow duplicate type/recording id combination for JamKazam sample" do
PerformanceSample.create(player1, {:player_id => player1.id, :service_type => "jamkazam", :claimed_recording_id => claimed_recording.id})
lambda{PerformanceSample.create(player1, {:player_id => player1.id, :service_type => "jamkazam", :claimed_recording_id => claimed_recording.id})}.should raise_error(ConflictError)
end
end
end
describe "destroy" do
before(:all) do
PerformanceSample.delete_all
@user_sample = PerformanceSample.new(:player_id => player1.id, :service_type => "soundcloud", :service_id => "12345")
@user_sample.save!
end
context "when request is valid" do
it "should destroy successfully" do
ps_list = PerformanceSample.index({:id => player1.id})
ps_list.count.should == 1
ps_list.first.service_type.should == "soundcloud"
ps_list.first.service_id.should == "12345"
PerformanceSample.delete(player1, {:player_id => player1.id, :id => @user_sample.id})
ps_list = PerformanceSample.index({:id => player1.id})
ps_list.count.should == 0
end
end
context "when request is not valid" do
it "should raise JamPermissionError if requester id does not match id in request" do
lambda{PerformanceSample.delete(player2, {:player_id => player1.id, :id => @user_sample.id})}.should raise_error(JamPermissionError)
end
it "should raise error if user sample id is missing" do
lambda{PerformanceSample.delete(player1, {:player_id => player1.id})}.should raise_error(StateError)
end
end
end
end
describe "create" do
before(:all) do
PerformanceSample.delete_all
end
context "when request is valid" do
it "should save successfully" do
PerformanceSample.create(user1, {:user_id => user1.id, :service_type => "youtube", :service_id => "12345"})
# make sure we can save a second PerformanceSample for same user and type
PerformanceSample.create(user1, {:user_id => user1.id, :service_type => "youtube", :service_id => "67890"})
end
end
context "when request is not valid" do
it "should raise JamPermissionError if requester id does not match id in request" do
lambda{PerformanceSample.create(user1, {:user_id => user2.id, :service_type => "soundcloud", :service_id => "12345"})}.should raise_error(JamPermissionError)
end
it "should raise error if service type is missing" do
lambda{PerformanceSample.create(user1, {:user_id => user1.id, :service_id => "12345"})}.should raise_error(StateError)
end
it "should raise error if service id is missing for non-JamKazam sample" do
lambda{PerformanceSample.create(user1, {:user_id => user1.id, :service_type => "youtube"})}.should raise_error(StateError)
end
it "should raise error if recording id is missing for JamKazam sample" do
lambda{PerformanceSample.create(user1, {:user_id => user1.id, :service_type => "jamkazam"})}.should raise_error(StateError)
end
it "should not allow duplicate type/service id combination for non-JamKazam sample" do
PerformanceSample.create(user1, {:user_id => user1.id, :service_type => "youtube", :service_id => "12345"})
lambda{PerformanceSample.create(user1, {:user_id => user1.id, :service_type => "youtube", :service_id => "12345"})}.should raise_error(ConflictError)
end
it "should not allow duplicate type/recording id combination for JamKazam sample" do
PerformanceSample.create(user1, {:user_id => user1.id, :service_type => "jamkazam", :claimed_recording_id => claimed_recording.id})
lambda{PerformanceSample.create(user1, {:user_id => user1.id, :service_type => "jamkazam", :claimed_recording_id => claimed_recording.id})}.should raise_error(ConflictError)
end
describe "with a user" do
it_should_behave_like :performance_sample_specs do
let(:player1) { FactoryGirl.create(:user) }
let(:player2) { FactoryGirl.create(:user) }
end
end
describe "destroy" do
before(:all) do
PerformanceSample.delete_all
@user_sample = PerformanceSample.new(:user_id => user1.id, :service_type => "soundcloud", :service_id => "12345")
@user_sample.save!
end
context "when request is valid" do
it "should destroy successfully" do
ps_list = PerformanceSample.index({:id => user1.id})
ps_list.count.should == 1
ps_list.first.service_type.should == "soundcloud"
ps_list.first.service_id.should == "12345"
PerformanceSample.delete(user1, {:user_id => user1.id, :id => @user_sample.id})
ps_list = PerformanceSample.index({:id => user1.id})
ps_list.count.should == 0
end
end
context "when request is not valid" do
it "should raise JamPermissionError if requester id does not match id in request" do
lambda{PerformanceSample.delete(user2, {:user_id => user1.id, :id => @user_sample.id})}.should raise_error(JamPermissionError)
end
it "should raise error if user sample id is missing" do
lambda{PerformanceSample.delete(user1, {:user_id => user1.id})}.should raise_error(StateError)
end
describe "with a band" do
it_should_behave_like :performance_sample_specs do
let(:player1) { FactoryGirl.create(:band) }
let(:player2) { FactoryGirl.create(:band) }
end
end
end

View File

@ -9,7 +9,7 @@ describe User do
User.delete_all
@user = User.new(first_name: "Example", last_name: "User", email: "user@example.com",
password: "foobar", password_confirmation: "foobar", city: "Apex", state: "NC", country: "US", terms_of_service: true, musician: true)
@user.musician_instruments << FactoryGirl.build(:musician_instrument, user: @user)
@user.musician_instruments << FactoryGirl.build(:musician_instrument, player: @user)
@recurly = RecurlyClient.new
end

View File

@ -98,13 +98,13 @@ describe "RenderMailers", :slow => true do
BatchMailer.deliveries.clear
scheduled_batch.reset!
drummer.musician_instruments << FactoryGirl.build(:musician_instrument, user: drummer, instrument: drums, proficiency_level: 2)
drummer.musician_instruments << FactoryGirl.build(:musician_instrument, user: drummer, instrument: guitar, proficiency_level: 2)
drummer.musician_instruments << FactoryGirl.build(:musician_instrument, player: drummer, instrument: drums, proficiency_level: 2)
drummer.musician_instruments << FactoryGirl.build(:musician_instrument, player: drummer, instrument: guitar, proficiency_level: 2)
guitarist.musician_instruments << FactoryGirl.build(:musician_instrument, user: guitarist, instrument: guitar, proficiency_level: 2)
guitarist.musician_instruments << FactoryGirl.build(:musician_instrument, user: guitarist, instrument: bass, proficiency_level: 2)
guitarist.musician_instruments << FactoryGirl.build(:musician_instrument, player: guitarist, instrument: guitar, proficiency_level: 2)
guitarist.musician_instruments << FactoryGirl.build(:musician_instrument, player: guitarist, instrument: bass, proficiency_level: 2)
vocalist.musician_instruments << FactoryGirl.build(:musician_instrument, user: vocalist, instrument: vocals, proficiency_level: 2)
vocalist.musician_instruments << FactoryGirl.build(:musician_instrument, player: vocalist, instrument: vocals, proficiency_level: 2)
FactoryGirl.create(:rsvp_slot, :instrument => drums, :music_session => session1)
FactoryGirl.create(:rsvp_slot, :instrument => guitar, :music_session => session1)

View File

@ -231,7 +231,7 @@
function addOnlinePresence(presenceArray, username, type) {
if ($.trim(username).length > 0) {
presenceArray.push({
'user_id': context.JK.currentUserId,
'player_id': context.JK.currentUserId,
'service_type': type,
'username': username
});
@ -247,7 +247,7 @@
if (type === 'jamkazam') {
sampleArray.push({
'user_id': context.JK.currentUserId,
'player_id': context.JK.currentUserId,
'service_type': type,
'claimed_recording_id': id,
});
@ -258,7 +258,7 @@
var title = $(this).attr('data-recording-title');
sampleArray.push({
'user_id': context.JK.currentUserId,
'player_id': context.JK.currentUserId,
'service_type': type,
'service_id': id,
'url': url,

View File

@ -201,7 +201,7 @@ def make_users(num=99)
user_instruments = instruments.sample(num_instrument)
num_instrument.times do |mm|
musician_instrument = MusicianInstrument.new
musician_instrument.user = uu
musician_instrument.player = uu
musician_instrument.instrument = user_instruments[mm]
musician_instrument.proficiency_level = rand(3) + 1
musician_instrument.priority = rand(num_instrument)

View File

@ -87,10 +87,10 @@ FactoryGirl.define do
before(:create) do |user, evaluator|
if evaluator.specific_instruments
evaluator.specific_instruments.each do |instrument|
user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user, instrument: instrument)
user.musician_instruments << FactoryGirl.build(:musician_instrument, player: user, instrument: instrument)
end
else
user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user)
user.musician_instruments << FactoryGirl.build(:musician_instrument, player: user)
end
end

View File

@ -24,16 +24,16 @@ describe "Musicians", :js => true, :type => :feature, :capybara_feature => true
it "Basic Test" do
navigate_musician_setup
save_screenshot("setup.png")
#save_screenshot("setup.png")
expect(page).to have_selector('#user-profile', visible: true)
expect(page).to have_selector('#no-samples', visible: true)
end
it "shows Online Presence" do
PerformanceSample.create!(:user_id => user.id, :service_type => "jamkazam", :claimed_recording_id => claimed_recording.id)
PerformanceSample.create!(:user_id => user.id, :service_type => "soundcloud", :service_id => "67890")
PerformanceSample.create!(:user_id => user.id, :service_type => "soundcloud", :service_id => "67891")
PerformanceSample.create!(:player_id => user.id, :service_type => "jamkazam", :claimed_recording_id => claimed_recording.id)
PerformanceSample.create!(:player_id => user.id, :service_type => "soundcloud", :service_id => "67890")
PerformanceSample.create!(:player_id => user.id, :service_type => "soundcloud", :service_id => "67891")
navigate_musician_setup
expect(page).to have_selector('#no-samples', visible: true)
@ -44,9 +44,9 @@ describe "Musicians", :js => true, :type => :feature, :capybara_feature => true
end
it "shows Performance Samples" do
OnlinePresence.create!({:user_id => user.id, :username => "myonlineusername", :service_type => "facebook"})
OnlinePresence.create!({:user_id => user.id, :username => "myonlineusername", :service_type => "twitter"})
OnlinePresence.create!({:user_id => user.id, :username => "myonlineusername", :service_type => "soundcloud"})
OnlinePresence.create!({:player_id => user.id, :username => "myonlineusername", :service_type => "facebook"})
OnlinePresence.create!({:player_id => user.id, :username => "myonlineusername", :service_type => "twitter"})
OnlinePresence.create!({:player_id => user.id, :username => "myonlineusername", :service_type => "soundcloud"})
navigate_musician_setup
expect(page).to have_selector('#facebook-presence', visible: true)

View File

@ -19,7 +19,7 @@ FactoryGirl.define do
end
before(:create) do |user|
user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user)
user.musician_instruments << FactoryGirl.build(:musician_instrument, player: user)
end
end