VRFS-2693 performance model/tests
This commit is contained in:
parent
675dc70f23
commit
8bd311647a
|
|
@ -56,22 +56,10 @@ module JamRuby
|
|||
ps.save!
|
||||
end
|
||||
|
||||
def self.update(current_user, options = {})
|
||||
auth_user(current_user, options)
|
||||
raise StateError, "Missing required information" if options[:service_type].blank? || options[:username].blank? || options[:id].blank?
|
||||
|
||||
ps = PerformanceSample.find(options[:id])
|
||||
ps.service_type = options[:service_type]
|
||||
ps.claimed_recording_id = options[:claimed_recording_id]
|
||||
ps.service_id = options[:service_id]
|
||||
ps.url = options[:url]
|
||||
ps.save!
|
||||
end
|
||||
|
||||
def self.destroy(current_user, options = {})
|
||||
def self.delete(current_user, options = {})
|
||||
raise PermissionError, "You do not have permission to perform this operation" if current_user.nil? || options[:user_id] != current_user.id
|
||||
raise JamArgumentError, "The performance sample ID is missing." if options[:id].blank?
|
||||
PerformanceSample.destroy_all("id = ?", options[:id])
|
||||
raise StateError, "The performance sample ID is missing." if options[:id].blank?
|
||||
PerformanceSample.destroy(options[:id])
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ module JamRuby
|
|||
end
|
||||
|
||||
def self.index(options = {})
|
||||
raise JamArgumentError, "The user is not specified." if options[:id].blank?
|
||||
raise StateError, "The user is not specified." if options[:id].blank?
|
||||
UserPresence.where("user_id = ?", options[:id])
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ describe PerformanceSample do
|
|||
describe "index" do
|
||||
|
||||
before(:all) do
|
||||
PerformanceSample.delete_all
|
||||
|
||||
@user1_sample1 = PerformanceSample.new(:user_id => user1.id, :service_type => "jamkazam", :claimed_recording_id => claimed_recording.id)
|
||||
@user1_sample1.save!
|
||||
|
|
@ -42,6 +43,11 @@ describe PerformanceSample do
|
|||
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"})
|
||||
|
|
@ -53,89 +59,64 @@ describe PerformanceSample do
|
|||
|
||||
context "when request is not valid" do
|
||||
it "should raise PermissionError if requester id does not match id in request" do
|
||||
lambda{PerformanceSample.create(user1, {:user_id => user2.id, :service_type => "soundcloud", :username => "soundclouduser2"})}.should raise_error(PermissionError)
|
||||
lambda{PerformanceSample.create(user1, {:user_id => user2.id, :service_type => "soundcloud", :service_id => "12345"})}.should raise_error(PermissionError)
|
||||
end
|
||||
|
||||
it "should raise error if service type is missing" do
|
||||
lambda{PerformanceSample.create(user1, {:user_id => user1.id, :username => "soundclouduser2"})}.should raise_error(StateError)
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
# describe "update" do
|
||||
|
||||
# before(:all) do
|
||||
# @user_sample = PerformanceSample.new(:user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser1")
|
||||
# @user_sample.save!
|
||||
# end
|
||||
describe "destroy" do
|
||||
|
||||
# context "when request is valid" do
|
||||
# it "should save successfully" 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
|
||||
|
||||
# up_list = PerformanceSample.index({:id => user1.id})
|
||||
# up_list.count.should == 1
|
||||
# up_list.first.service_type.should == "soundcloud"
|
||||
# up_list.first.username.should == "soundclouduser1"
|
||||
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.update(user1, {:id => @user_sample.id, :user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser2"})
|
||||
PerformanceSample.delete(user1, {:user_id => user1.id, :id => @user_sample.id})
|
||||
|
||||
# up_list = PerformanceSample.index({:id => user1.id})
|
||||
# up_list.count.should == 1
|
||||
# up_list.first.service_type.should == "soundcloud"
|
||||
# up_list.first.username.should == "soundclouduser2"
|
||||
# end
|
||||
# end
|
||||
ps_list = PerformanceSample.index({:id => user1.id})
|
||||
ps_list.count.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
# context "when request is not valid" do
|
||||
# it "should raise PermissionError if requester id does not match id in request" do
|
||||
# lambda{PerformanceSample.update(user1, {:user_id => user2.id, :id => @user_sample.id, :service_type => "soundcloud", :username => "soundclouduser2"})}.should raise_error(PermissionError)
|
||||
# end
|
||||
context "when request is not valid" do
|
||||
it "should raise PermissionError 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(PermissionError)
|
||||
end
|
||||
|
||||
# it "should raise error if type is missing" do
|
||||
# lambda{PerformanceSample.update(user1, {:user_id => user1.id, :id => @user_sample.id, :username => "soundclouduser2"})}.should raise_error(StateError)
|
||||
# end
|
||||
|
||||
# it "should raise error if username is missing" do
|
||||
# lambda{PerformanceSample.update(user1, {:user_id => user1.id, :id => @user_sample.id, :service_type => "soundcloud"})}.should raise_error(StateError)
|
||||
# end
|
||||
|
||||
# it "should raise error if user sample id is missing" do
|
||||
# lambda{PerformanceSample.update(user1, {:user_id => user1.id, :username => "soundclouduser2", :service_type => "soundcloud"})}.should raise_error(StateError)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# describe "destroy" do
|
||||
|
||||
# before(:all) do
|
||||
# @user_sample = PerformanceSample.new(:user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser1")
|
||||
# @user_sample.save!
|
||||
# end
|
||||
|
||||
# context "when request is valid" do
|
||||
# it "should destroy successfully" do
|
||||
# up_list = PerformanceSample.index({:id => user1.id})
|
||||
# up_list.count.should == 1
|
||||
# up_list.first.service_type.should == "soundcloud"
|
||||
# up_list.first.username.should == "soundclouduser1"
|
||||
|
||||
# PerformanceSample.delete(user1, {:user_id => user1.id, :id => @user_sample.id})
|
||||
|
||||
# up_list = PerformanceSample.index({:id => user1.id})
|
||||
# up_list.count.should == 0
|
||||
# end
|
||||
# end
|
||||
|
||||
# context "when request is not valid" do
|
||||
# it "should raise PermissionError 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(PermissionError)
|
||||
# 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
|
||||
# end
|
||||
# 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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -32,11 +32,11 @@ describe UserPresence do
|
|||
|
||||
context "when request is invalid" do
|
||||
it "should raise error when options are missing" do
|
||||
lambda{UserPresence.index}.should raise_error(JamArgumentError)
|
||||
lambda{UserPresence.index}.should raise_error(StateError)
|
||||
end
|
||||
|
||||
it "should raise error when user id is missing" do
|
||||
lambda{UserPresence.index({:id => ""})}.should raise_error(JamArgumentError)
|
||||
lambda{UserPresence.index({:id => ""})}.should raise_error(StateError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue