require 'spec_helper' describe CareerBuilder::Resume::LazyCollection do describe "#each" do before do stub_request(:post, "http://ws.careerbuilder.com/resumes/resumes.asmx/V2_AdvancedResumeSearch").with(:body => 'Packet=%3cPacket%3e%3cSessionToken%3e42%3c%2fSessionToken%3e%3cKeywords%3eRuby%3c%2fKeywords%3e%3cPageNumber%3e1%3c%2fPageNumber%3e%3c%2fPacket%3e').to_return(:body => "\r\n<Packet><Errors /><PageNumber>1</PageNumber><SearchTime>06/25/2010 12:03:14</SearchTime><FirstRec>1</FirstRec><LastRec>100</LastRec><Hits>4</Hits><MaxPage>2</MaxPage><Results><ResumeResultItem_V3><ContactEmail>Rhd4G067G4JVTLW99H7_A7C14Q67VKG000YBSCR~CBWS^U7A3LY6YY46V1MT0RJK@resume.cbdr.com</ContactEmail><ContactName>Rebecca Bernard</ContactName><HomeLocation>US-OH-Milford</HomeLocation><LastUpdate>2010/5/13</LastUpdate><ResumeTitle>BERNARD_SYSTEMS_ENGINEER</ResumeTitle><JobTitle>BERNARD_SYSTEMS_ENGINEER</JobTitle><RecentEmployer>TATA CONSULTANCY SERVICES</RecentEmployer><RecentJobTitle>CONSULTANCY SERVICES- Systems Engineer</RecentJobTitle><RecentPay>0</RecentPay><ResumeID>Rhd4G067G4JVTLW99H7</ResumeID><UserDID>U7X86R61VVKS4FWS03T</UserDID><ContactEmailMD5>139013c2fa2b945bdc340f8a698b009e</ContactEmailMD5></ResumeResultItem_V3><ResumeResultItem_V3><ContactEmail>Rhe7TZ764LHG1GQTPSM_A7C14Q67VKG000YBSCR~CBWS^U7A3LY6YY46V1MT0RJK@resume.cbdr.com</ContactEmail><ContactName>chris grader</ContactName><HomeLocation>US-OH-Milford</HomeLocation><LastUpdate>2010/6/4</LastUpdate><ResumeTitle>Chris Grader resume</ResumeTitle><JobTitle>Chris Grader resume</JobTitle><RecentEmployer>Millennial Medical, Inc</RecentEmployer><RecentJobTitle>Regional Sales Manager/Midwest Distributor</RecentJobTitle><RecentPay>0</RecentPay><ResumeID>Rhe7TZ764LHG1GQTPSM</ResumeID><UserDID>U346V1MKGCHPGCF9S8</UserDID><ContactEmailMD5>cfba57bf848b78211d99348cf0f90879</ContactEmailMD5></ResumeResultItem_V3><ResumeResultItem_V3><ContactEmail>RH52G867678F7GH02Q3_A7C14Q67VKG000YBSCR~CBWS^U7A3LY6YY46V1MT0RJK@resume.cbdr.com</ContactEmail><ContactName>Jeffrey Davis</ContactName><HomeLocation>US-OH-Goshen</HomeLocation><LastUpdate>2010/5/23</LastUpdate><ResumeTitle>Warehouse Distribution Specialist</ResumeTitle><JobTitle>Warehouse Distribution Specialist</JobTitle><RecentEmployer>OWENS &amp; MINOR</RecentEmployer><RecentJobTitle>Warehouse Lead Supervisor</RecentJobTitle><RecentPay>35776</RecentPay><ResumeID>RH52G867678F7GH02Q3</ResumeID><UserDID>U1C29V68M3YM95SP0XK</UserDID><ContactEmailMD5>e814ebaa93aae5c3719e27d26d5af917</ContactEmailMD5></ResumeResultItem_V3></Results></Packet>") stub_request(:post, "http://ws.careerbuilder.com/resumes/resumes.asmx/V2_AdvancedResumeSearch").with(:body => 'Packet=%3cPacket%3e%3cSessionToken%3e42%3c%2fSessionToken%3e%3cKeywords%3eRuby%3c%2fKeywords%3e%3cPageNumber%3e2%3c%2fPageNumber%3e%3c%2fPacket%3e').to_return(:body => "\r\n<Packet><Errors/><PageNumber>2</PageNumber><SearchTime>06/25/2010 12:03:14</SearchTime><FirstRec>1</FirstRec><LastRec>100</LastRec><Hits>4</Hits><MaxPage>2</MaxPage><Results><ResumeResultItem_V3><ContactEmail>Rhd4G067G4JVTLW99H7_A7C14Q67VKG000YBSCR~CBWS^U7A3LY6YY46V1MT0RJK@resume.cbdr.com</ContactEmail><ContactName>Michael Guterl</ContactName><HomeLocation>US-OH-Loveland</HomeLocation><LastUpdate>2010/5/13</LastUpdate><ResumeTitle>BERNARD_SYSTEMS_ENGINEER</ResumeTitle><JobTitle>BERNARD_SYSTEMS_ENGINEER</JobTitle><RecentEmployer>TATA CONSULTANCY SERVICES</RecentEmployer><RecentJobTitle>CONSULTANCY SERVICES- Systems Engineer</RecentJobTitle><RecentPay>0</RecentPay><ResumeID>RD52G867678F7GH0123</ResumeID><UserDID>U7X86R61VVKS4FWS03T</UserDID><ContactEmailMD5>139013c2fa2b945bdc340f8a698b009e</ContactEmailMD5></ResumeResultItem_V3></Results></Packet>") @client = CareerBuilder::Client.new("valid_email", "valid_password") @client.stub(:session_token).and_return(42) @client.stub(:authenticate).and_return(true) @collection = CareerBuilder::Resume::LazyCollection.new(@client, :keywords => "Ruby") end it 'should iterate through all pages of results' do resumes = [] @collection.each do |resume| resumes << resume end resumes.first.id.should == "Rhd4G067G4JVTLW99H7" resumes.last.id.should == "RD52G867678F7GH0123" end end end