Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created October 9, 2010 22:01
Show Gist options
  • Save ashaw/618642 to your computer and use it in GitHub Desktop.
Save ashaw/618642 to your computer and use it in GitHub Desktop.
# def to_db
# @payload.each do |item|
# u = Update.find_by_native_item_id(item[:native_item_id])
# u.nil? ? r = Update.new : r = u
# item.each {|k,v| r[k.to_sym] = v }
# r.save
# end
# end
it "should edit existing posts in the db, if original atom entries change" do
# first, check for the first update via atom:
u = Update.find(:first, :order => "item_create_time DESC", :conditions => {:via => "atom"})
u.native_item_id.should eql("tag:www.talkingpointsmemo.com,2010:/live//14117.354093")
u.title.should eql("Paul Ryan Pushing Medicare-Slashing 'Roadmap' On Incoming GOP Freshmen")
#now backup the existing fixture, and edit the fixture to "update" the post
%x[cp #{SPEC_PATH}/fixtures/midterms_wire.xml #{SPEC_PATH}/fixtures/midterms_wire.bak.xml]
@edited_xml_fixture = File.open("#{SPEC_PATH}/fixtures/midterms_wire.xml").readlines
@edited_xml_fixture[10] = "<title>Edited Title of Paul Ryan Hed</title>"
#delete the original midterms wire atom fixture
%x[rm -rf #{SPEC_PATH}/fixtures/midterms_wire.xml]
File.open("#{SPEC_PATH}/fixtures/midterms_wire.xml","w") {|f|
f.write(@edited_xml_fixture.to_s)
}
#check to see that we've edited the fixture
edited_xml = Crack::XML.parse(open("#{SPEC_PATH}/fixtures/midterms_wire.xml"))
edited_xml['feed']['entry'][0]['title'].should eql("Edited Title of Paul Ryan Hed")
#reregister the fixture
FakeWeb.register_uri(:get, 'http://www.talkingpointsmemo.com/live/tpm-midterms-wire/index.xml', :body => fixture_file('midterms_wire.xml'))
#rerun Consumer
MultiWire::Consumer.start
#put the original fixture back
%x[rm -rf #{SPEC_PATH}/fixtures/midterms_wire.xml]
%x[mv #{SPEC_PATH}/fixtures/midterms_wire.bak.xml #{SPEC_PATH}/fixtures/midterms_wire.xml]
#and reregister the fixture
FakeWeb.register_uri(:get, 'http://www.talkingpointsmemo.com/live/tpm-midterms-wire/index.xml', :body => fixture_file('midterms_wire.xml'))
#test it out
u = Update.find(:first, :order => "item_create_time DESC", :conditions => {:via => "atom"})
u.native_item_id.should eql("tag:www.talkingpointsmemo.com,2010:/live//14117.354093")
u.title.should eql("Edited Title of Paul Ryan Hed")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment