wire up get_work
This commit is contained in:
parent
c86433afd8
commit
fd42fc56fe
|
|
@ -1,14 +1,21 @@
|
|||
module JamRuby
|
||||
class GetWork < ActiveRecord::Base
|
||||
|
||||
self.table_name = "connections"
|
||||
|
||||
def self.get_work(mylocidispid)
|
||||
list = get_work_list(mylocidispid)
|
||||
list = self.get_work_list(mylocidispid)
|
||||
return nil if list.nil?
|
||||
return nil if list.length == 0
|
||||
return list[0]
|
||||
end
|
||||
|
||||
def self.get_work_list(mylocidispid)
|
||||
GetWork.find_by_sql("select get_work(#{mylocidispid}) as client_id")
|
||||
r = GetWork.select(:client_id).find_by_sql("select get_work(#{mylocidispid}) as client_id")
|
||||
#puts("r = #{r}")
|
||||
a = r.map {|i| i.client_id}
|
||||
#puts("a = #{a}")
|
||||
a
|
||||
#return ["blah1", "blah2", "blah3", "blah4", "blah5"]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe GetWork do
|
||||
before do
|
||||
|
||||
before(:each) do
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,9 @@ class ApiScoringController < ApiController
|
|||
if !c.user.id.eql?(current_user.id) then render :json => {message: 'user does not own client_id'}, :status => 403; return end
|
||||
|
||||
# todo this method is a stub
|
||||
#result_client_id = JamRuby::GetWork.get_work(c.locidispid)
|
||||
result_client_id = client_id+'peer'
|
||||
#puts "ApiScoringController#work(#{client_id}) => locidispid #{c.locidispid}"
|
||||
result_client_id = JamRuby::GetWork.get_work(c.locidispid)
|
||||
#result_client_id = client_id+'peer'
|
||||
|
||||
render :json => {:clientid => result_client_id}, :status => 200
|
||||
end
|
||||
|
|
@ -27,8 +28,8 @@ class ApiScoringController < ApiController
|
|||
if !c.user.id.eql?(current_user.id) then render :json => {message: 'user does not own client_id'}, :status => 403; return end
|
||||
|
||||
# todo this method is a stub
|
||||
# result_client_ids = JamRuby::GetWork.get_work_list(c.locidispid)
|
||||
result_client_ids = [client_id+'peer1', client_id+'peer2']
|
||||
result_client_ids = JamRuby::GetWork.get_work_list(c.locidispid)
|
||||
#result_client_ids = [client_id+'peer1', client_id+'peer2']
|
||||
|
||||
render :json => {:clientids => result_client_ids}, :status => 200
|
||||
end
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ describe ApiScoringController do
|
|||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 1
|
||||
json[:clientid].should_not be_nil
|
||||
json[:clientid].should eql(@mary_client_id+'peer')
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientid])
|
||||
end
|
||||
|
||||
it 'try work with mike and mike' do
|
||||
|
|
@ -84,7 +84,7 @@ describe ApiScoringController do
|
|||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 1
|
||||
json[:clientid].should_not be_nil
|
||||
json[:clientid].should eql(@mike_client_id+'peer')
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientid])
|
||||
end
|
||||
|
||||
it 'try work with mike and mary' do
|
||||
|
|
@ -136,8 +136,10 @@ describe ApiScoringController do
|
|||
json[:clientids].should_not be_nil
|
||||
json[:clientids].should_receive :length
|
||||
json[:clientids].length == 2
|
||||
json[:clientids][0].should eql(@mary_client_id+'peer1')
|
||||
json[:clientids][1].should eql(@mary_client_id+'peer2')
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientids][0])
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientids][1])
|
||||
json[:clientids][0].should_not eql(json[:clientids][1])
|
||||
|
||||
end
|
||||
|
||||
it 'try worklist with mike and mike' do
|
||||
|
|
@ -149,8 +151,9 @@ describe ApiScoringController do
|
|||
json[:clientids].should_not be_nil
|
||||
json[:clientids].should_receive :length
|
||||
json[:clientids].length == 2
|
||||
json[:clientids][0].should eql(@mike_client_id+'peer1')
|
||||
json[:clientids][1].should eql(@mike_client_id+'peer2')
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientids][0])
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientids][1])
|
||||
json[:clientids][0].should_not eql(json[:clientids][1])
|
||||
end
|
||||
|
||||
it 'try worklist with mary and mike' do
|
||||
|
|
|
|||
Loading…
Reference in New Issue