VRFS-2694 user presence model tests
This commit is contained in:
parent
9ede0912a1
commit
e3f27eeebc
|
|
@ -16,7 +16,7 @@ module JamRuby
|
|||
|
||||
def self.create(current_user, options = {})
|
||||
auth_user(current_user, options)
|
||||
raise StateError, "Missing required information" if options[:service_type].nil? || options[:username].nil?
|
||||
raise StateError, "Missing required information" if options[:service_type].blank? || options[:username].blank?
|
||||
|
||||
up = UserPresence.new({:user_id => current_user.id, :service_type => options[:service_type], :username => options[:username]})
|
||||
up.save!
|
||||
|
|
@ -24,22 +24,24 @@ module JamRuby
|
|||
|
||||
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?
|
||||
|
||||
id = options[:id]
|
||||
if options[:username].nil?
|
||||
UserPresence.destroy(id)
|
||||
else
|
||||
up = UserPresence.find(options[:id])
|
||||
up.service_type = options[:service_type]
|
||||
up.username = options[:username]
|
||||
up.save!
|
||||
end
|
||||
up = UserPresence.find(options[:id])
|
||||
up.service_type = options[:service_type]
|
||||
up.username = options[:username]
|
||||
up.save!
|
||||
end
|
||||
|
||||
def self.destroy(current_user, options = {})
|
||||
user_presence = UserPresence.find(user_presence)
|
||||
def self.delete(current_user, options = {})
|
||||
id = options[:id]
|
||||
raise StateError, "Missing required information" if id.blank?
|
||||
user_presence = UserPresence.find(id)
|
||||
|
||||
if user_presence.user_id != current_user.id
|
||||
raise PermissionError, PERMISSION_MSG
|
||||
end
|
||||
|
||||
unless user_presence.nil?
|
||||
raise PermissionError, PERMISSION_MSG if user_presence.user_id != current_user.id
|
||||
UserPresence.destroy(id)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -90,27 +90,51 @@ describe UserPresence do
|
|||
|
||||
context "when request is not valid" do
|
||||
it "should raise PermissionError if requester id does not match id in request" do
|
||||
lambda{UserPresence.update(user1, {:user_id => user2.id, :id => @user_presence.id, :service_type => "soundcloud", :username => "soundclouduser2"})}.should raise_error(PermissionError)
|
||||
end
|
||||
|
||||
it "should raise error if type is missing" do
|
||||
lambda{UserPresence.update(user1, {:user_id => user1.id, :id => @user_presence.id, :username => "soundclouduser2"})}.should raise_error(StateError)
|
||||
end
|
||||
|
||||
it "should raise error if username is missing" do
|
||||
lambda{UserPresence.update(user1, {:user_id => user1.id, :id => @user_presence.id, :service_type => "soundcloud"})}.should raise_error(StateError)
|
||||
end
|
||||
|
||||
it "should raise error if user presence id is missing" do
|
||||
lambda{UserPresence.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_presence = UserPresence.new(:user_id => user1.id, :service_type => "soundcloud", :username => "soundclouduser1")
|
||||
@user_presence.save!
|
||||
end
|
||||
|
||||
context "when request is valid" do
|
||||
it "should destroy successfully" do
|
||||
up_list = UserPresence.index({:id => user1.id})
|
||||
up_list.count.should == 1
|
||||
up_list.first.service_type.should == "soundcloud"
|
||||
up_list.first.username.should == "soundclouduser1"
|
||||
|
||||
UserPresence.delete(user1, {:user_id => user1.id, :id => @user_presence.id})
|
||||
|
||||
up_list = UserPresence.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{UserPresence.delete(user2, {:user_id => user1.id, :id => @user_presence.id})}.should raise_error(PermissionError)
|
||||
end
|
||||
|
||||
it "should raise error if user presence id is missing" do
|
||||
lambda{UserPresence.delete(user1, {:user_id => user1.id})}.should raise_error(StateError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue