Stub Jobs::ReceiveSalmon.perform in controller test

This commit is contained in:
Sarah Mei 2010-12-05 01:31:07 -08:00
parent 648614aea5
commit ecc537c737

View file

@ -4,45 +4,55 @@
require 'spec_helper' require 'spec_helper'
describe PublicsController do describe PublicsController do
render_views render_views
let(:user) { make_user } let(:user) { make_user }
let(:person){Factory(:person)} let(:person) { Factory(:person) }
describe '#receive' do describe '#receive' do
let(:xml) { "<walruses></walruses>" } let(:xml) { "<walruses></walruses>" }
context 'success cases' do
it 'should 200 on successful receipt of a request, and queues a job' do before do
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, xml).once Jobs::ReceiveSalmon.stub!(:perform)
post :receive, :id =>user.person.id, :xml => xml
response.code.should == '200'
end
end end
it 'should return a 422 if no xml is passed' do it 'succeeds' do
post :receive, :id => person.id post :receive, "id" => user.person.id.to_s, "xml" => xml
response.should be_success
end
it 'enqueues a receive job' do
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, xml).once
post :receive, "id" => user.person.id.to_s, "xml" => xml
end
it 'returns a 422 if no xml is passed' do
post :receive, "id" => person.id.to_s
response.code.should == '422' response.code.should == '422'
end end
it 'should return a 404 if no user is found' do it 'returns a 404 if no user is found' do
post :receive, :id => person.id, :xml => xml post :receive, "id" => person.id.to_s, "xml" => xml
response.code.should == '404' response.should be_not_found
end end
end end
describe '#hcard' do describe '#hcard' do
it 'queries by person id' do it "succeeds" do
post :hcard, :id => user.person.id post :hcard, "id" => user.person.id.to_s
response.should be_success
end
it 'sets the person' do
post :hcard, "id" => user.person.id.to_s
assigns[:person].should == user.person assigns[:person].should == user.person
response.code.should == '200'
end end
it 'does not query by user id' do it 'does not query by user id' do
post :hcard, :id => user.id post :hcard, "id" => user.id.to_s
assigns[:person].should be_nil assigns[:person].should be_nil
response.code.should == '404' response.should be_not_found
end end
end end