Add first resque job
This commit is contained in:
parent
0b5bf40a8d
commit
6cfa6577a5
5 changed files with 37 additions and 65 deletions
|
|
@ -56,12 +56,7 @@ class PublicsController < ApplicationController
|
|||
end
|
||||
|
||||
@user = person.owner
|
||||
|
||||
begin
|
||||
@user.receive_salmon(params[:xml])
|
||||
rescue Exception => e
|
||||
Rails.logger.info("bad salmon: #{e.message}")
|
||||
end
|
||||
Resque.enqueue(Jobs::ReceiveSalmon, @user.id, params[:xml])
|
||||
|
||||
render :nothing => true, :status => 200
|
||||
end
|
||||
|
|
|
|||
10
app/models/jobs/receive_salmon.rb
Normal file
10
app/models/jobs/receive_salmon.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
module Jobs
|
||||
class ReceiveSalmon
|
||||
@queue = :receive
|
||||
def self.perform(user_id, xml)
|
||||
user = User.find(user_id)
|
||||
user.receive_salmon(xml)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
Dir[File.join(Rails.root, 'app', 'jobs', '*.rb')].each { |file| require file }
|
||||
#config = YAML::load(File.open("#{Rails.root}/config/redis.yml"))
|
||||
#Resque.redis = Redis.new(:host => config['host'], :port => config['port'])
|
||||
require 'resque'
|
||||
|
|
|
|||
|
|
@ -7,42 +7,20 @@ require 'spec_helper'
|
|||
|
||||
describe PublicsController do
|
||||
render_views
|
||||
let!(:user) { make_user }
|
||||
let!(:user2) { make_user }
|
||||
let!(:aspect1) { user.aspects.create(:name => "foo") }
|
||||
let!(:aspect2) { user2.aspects.create(:name => "far") }
|
||||
let!(:aspect2) { user2.aspects.create(:name => 'disciples') }
|
||||
let!(:req) { user2.send_contact_request_to(user.person, aspect2) }
|
||||
let!(:xml) { user2.salmon(req).xml_for(user.person) }
|
||||
let(:user) { make_user }
|
||||
let(:person){Factory(:person)}
|
||||
|
||||
before do
|
||||
sign_in :user, user
|
||||
|
||||
end
|
||||
|
||||
describe '#receive' do
|
||||
before do
|
||||
EventMachine::HttpRequest.stub!(:new).and_return(FakeHttpRequest.new(:success))
|
||||
end
|
||||
|
||||
context 'success cases' do
|
||||
before do
|
||||
@person_mock = mock()
|
||||
@user_mock = mock()
|
||||
@user_mock.stub!(:receive_salmon).and_return(true)
|
||||
@person_mock.stub!(:owner_id).and_return(true)
|
||||
@person_mock.stub!(:owner).and_return(@user_mock)
|
||||
Person.stub!(:first).and_return(@person_mock)
|
||||
end
|
||||
let(:xml) { "<walruses></walruses>" }
|
||||
context 'success cases' do
|
||||
it 'should 200 on successful receipt of a request' do
|
||||
post :receive, :id =>user.person.id, :xml => xml
|
||||
response.code.should == '200'
|
||||
end
|
||||
|
||||
it 'should have the xml processed as salmon on success' do
|
||||
@user_mock.should_receive(:receive_salmon).and_return(true)
|
||||
post :receive, :id => user.person.id, :xml => xml
|
||||
it 'enqueues a receive job' do
|
||||
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, xml).once
|
||||
post :receive, :id =>user.person.id, :xml => xml
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -55,8 +33,8 @@ describe PublicsController do
|
|||
post :receive, :id => person.id, :xml => xml
|
||||
response.code.should == '404'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#hcard' do
|
||||
it 'queries by person id' do
|
||||
|
|
@ -97,33 +75,4 @@ describe PublicsController do
|
|||
response.should be_not_found
|
||||
end
|
||||
end
|
||||
|
||||
context 'intergration tests that should not be in this file' do
|
||||
describe 'contact requests' do
|
||||
before do
|
||||
req.delete
|
||||
user2.reload
|
||||
user2.pending_requests.count.should be 1
|
||||
end
|
||||
|
||||
it 'should accept a post from another node and save the information' do
|
||||
pending
|
||||
message = user2.build_post(:status_message, :message => "hi")
|
||||
|
||||
connect_users(user, aspect1, user2, aspect2)
|
||||
|
||||
user.reload
|
||||
user.visible_post_ids.include?(message.id).should be false
|
||||
|
||||
xml1 = user2.salmon(message).xml_for(user.person)
|
||||
|
||||
EM::run{
|
||||
post :receive, :id => user.person.id, :xml => xml1
|
||||
EM.stop
|
||||
}
|
||||
user.reload
|
||||
user.visible_post_ids.include?(message.id).should be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
19
spec/models/jobs/receive_salmon_spec.rb
Normal file
19
spec/models/jobs/receive_salmon_spec.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
require 'spec/spec_helper'
|
||||
|
||||
describe Jobs::ReceiveSalmon do
|
||||
before do
|
||||
@user = make_user
|
||||
@xml = '<xml></xml>'
|
||||
User.stub(:find){ |id|
|
||||
if id == @user.id
|
||||
@user
|
||||
else
|
||||
nil
|
||||
end
|
||||
}
|
||||
end
|
||||
it 'calls receive_salmon' do
|
||||
@user.should_receive(:receive_salmon).with(@xml).once
|
||||
Jobs::ReceiveSalmon.perform(@user.id, @xml)
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue