Skip to content
Extraits de code Groupes Projets
Valider 6cfa6577 rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Add first resque job

parent 0b5bf40a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -56,12 +56,7 @@ class PublicsController < ApplicationController ...@@ -56,12 +56,7 @@ class PublicsController < ApplicationController
end end
@user = person.owner @user = person.owner
Resque.enqueue(Jobs::ReceiveSalmon, @user.id, params[:xml])
begin
@user.receive_salmon(params[:xml])
rescue Exception => e
Rails.logger.info("bad salmon: #{e.message}")
end
render :nothing => true, :status => 200 render :nothing => true, :status => 200
end end
......
module Jobs
class ReceiveSalmon
@queue = :receive
def self.perform(user_id, xml)
user = User.find(user_id)
user.receive_salmon(xml)
end
end
end
Dir[File.join(Rails.root, 'app', 'jobs', '*.rb')].each { |file| require file }
#config = YAML::load(File.open("#{Rails.root}/config/redis.yml")) #config = YAML::load(File.open("#{Rails.root}/config/redis.yml"))
#Resque.redis = Redis.new(:host => config['host'], :port => config['port']) #Resque.redis = Redis.new(:host => config['host'], :port => config['port'])
require 'resque' require 'resque'
...@@ -7,42 +7,20 @@ require 'spec_helper' ...@@ -7,42 +7,20 @@ require 'spec_helper'
describe PublicsController do describe PublicsController do
render_views render_views
let!(:user) { make_user } 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(:person){Factory(:person)} let(:person){Factory(:person)}
before do
sign_in :user, user
end
describe '#receive' do describe '#receive' do
before do let(:xml) { "<walruses></walruses>" }
EventMachine::HttpRequest.stub!(:new).and_return(FakeHttpRequest.new(:success)) context 'success cases' do
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
it 'should 200 on successful receipt of a request' do it 'should 200 on successful receipt of a request' do
post :receive, :id =>user.person.id, :xml => xml post :receive, :id =>user.person.id, :xml => xml
response.code.should == '200' response.code.should == '200'
end end
it 'should have the xml processed as salmon on success' do it 'enqueues a receive job' do
@user_mock.should_receive(:receive_salmon).and_return(true) Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, xml).once
post :receive, :id => user.person.id, :xml => xml post :receive, :id =>user.person.id, :xml => xml
end end
end end
...@@ -55,8 +33,8 @@ describe PublicsController do ...@@ -55,8 +33,8 @@ describe PublicsController do
post :receive, :id => person.id, :xml => xml post :receive, :id => person.id, :xml => xml
response.code.should == '404' response.code.should == '404'
end end
end
end
describe '#hcard' do describe '#hcard' do
it 'queries by person id' do it 'queries by person id' do
...@@ -97,33 +75,4 @@ describe PublicsController do ...@@ -97,33 +75,4 @@ describe PublicsController do
response.should be_not_found response.should be_not_found
end end
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 end
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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter