Skip to content

Instantly share code, notes, and snippets.

@Arkham
Created March 12, 2013 08:45
Show Gist options
  • Save Arkham/5141232 to your computer and use it in GitHub Desktop.
Save Arkham/5141232 to your computer and use it in GitHub Desktop.
mover specs
describe Wordmove::SqlMover do
context ".serialized_replace!" do
let(:content) { 'a:3:{i:0;s:20:"http://dump.com/spam";i:1;s:6:"foobar";i:2;s:22:"http://dump.com/foobar";}' }
let(:sql) { Tempfile.new('sql').tap do |d| d.write(content); d.close end }
let(:sql_path) { sql.path }
it "should replace source vhost with dest vhost" do
sql_mover.serialized_replace!('http://dump.com', 'http://shrubbery.com')
sql_mover.sql_content.should == 'a:3:{i:0;s:25:"http://shrubbery.com/spam";i:1;s:6:"foobar";i:2;s:27:"http://shrubbery.com/foobar";}'
end
context "given multiple types of string quoting" do
let(:content) { "a:3:{s:20:\\\"http://dump.com/spam\\\";s:6:'foobar';s:22:'http://dump.com/foobar';s:8:'sausages';}" }
it "should handle replacing just as well" do
sql_mover.serialized_replace!('http://dump.com', 'http://shrubbery.com')
sql_mover.sql_content.should == "a:3:{s:25:\\\"http://shrubbery.com/spam\\\";s:6:'foobar';s:27:'http://shrubbery.com/foobar';s:8:'sausages';}"
end
end
context "given multiple occurences in the same string" do
let(:content) { 'a:1:{i:0;s:52:"ni http://dump.com/spam ni http://dump.com/foobar ni";}' }
it "should replace all occurences" do
sql_mover.serialized_replace!('http://dump.com', 'http://shrubbery.com')
sql_mover.sql_content.should == 'a:1:{i:0;s:62:"ni http://shrubbery.com/spam ni http://shrubbery.com/foobar ni";}'
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment