spec/lib/fourchette/heroku_spec.rb in fourchette-0.0.8 vs spec/lib/fourchette/heroku_spec.rb in fourchette-0.1.0
- old
+ new
@@ -91,11 +91,11 @@
describe '#copy_add_ons' do
let(:addon_list) { [ { 'plan' => { 'name' => 'redistogo' } } ] }
before do
- heroku.client.stub(:addon).and_return( double('addon') )
+ heroku.client.stub(:addon).and_return(double('addon'))
heroku.client.addon.stub(:create)
heroku.client.addon.stub(:list).and_return(addon_list)
end
it 'gets the addon list' do
@@ -108,12 +108,37 @@
heroku.copy_add_ons(from_app_name, to_app_name)
end
end
describe '#copy_pg' do
- it 'calls Fourchette::Pgbackups#copy' do
- Fourchette::Pgbackups.any_instance.should_receive(:copy).with(from_app_name, to_app_name)
- heroku.copy_pg(from_app_name, to_app_name)
+
+ before do
+ heroku.client.stub(:addon).and_return(double('addon'))
+ heroku.client.addon.stub(:list).and_return(addon_list)
+ end
+
+ context 'when a heroku-postgresql addon is enabled' do
+ let(:addon_list) { [{ 'addon_service' => { 'name' => 'heroku-postgresql' } }] }
+
+ it 'calls Fourchette::Pgbackups#copy' do
+ Fourchette::Pgbackups.any_instance.should_receive(:copy).with(from_app_name, to_app_name)
+ heroku.copy_pg(from_app_name, to_app_name)
+ end
+ end
+
+ context 'when a heroku-postgresql addon is not enabled' do
+ let(:addon_list) { [{ 'addon_service' => { 'name' => 'redistogo' } }] }
+
+ it 'does not call Fourchette::Pgbackups#copy' do
+ # Had to work around lack of support for any_instance and should_not_receive
+ # see https://github.com/rspec/rspec-mocks/issues/164 for more details
+ count = 0
+ Fourchette::Pgbackups.any_instance.stub(:copy) do |from_app_name, to_app_name|
+ count += 1
+ end
+ heroku.copy_pg(from_app_name, to_app_name)
+ count.should eq(0)
+ end
end
end
describe '#copy_RACK_AND_RAILS_ENV_again' do
context 'with RACK_ENV or RAILS_ENV setup' do