1require File.expand_path('../test_helper', __FILE__) 2require 'config_uninstaller' 3 4describe "ConfigUninstaller" do 5 before do 6 @tmp = File.expand_path('../tmp') 7 FileUtils.mkdir_p @tmp 8 @config_installer = File.expand_path('../../config_uninstaller.rb', __FILE__) 9 10 @host = "het-manfreds-blog.local" 11 @aliases = "manfred-s-blog.local my-blog.local" 12 @vhost_file = File.join(@tmp, 'test.vhost.conf') 13 14 File.open(@vhost_file, 'w') { |f| f << 'bla' } 15 16 @uninstaller = ConfigUninstaller.new([{ 'config_path' => @vhost_file, 'host' => @host, 'aliases' => @aliases }].to_yaml) 17 end 18 19 after do 20 FileUtils.rm_rf @tmp 21 end 22 23 it "should initialize" do 24 @uninstaller.data.should == [{ 'config_path' => @vhost_file, 'host' => @host, 'aliases' => @aliases }] 25 end 26 27 it "should remove the ServerName entry and the ServerAlias entries from the hosts db" do 28 @uninstaller.expects(:system).with("/usr/bin/dscl localhost -delete /Local/Default/Hosts/het-manfreds-blog.local") 29 @uninstaller.expects(:system).with("/usr/bin/dscl localhost -delete /Local/Default/Hosts/manfred-s-blog.local") 30 @uninstaller.expects(:system).with("/usr/bin/dscl localhost -delete /Local/Default/Hosts/my-blog.local") 31 @uninstaller.remove_from_hosts(0) 32 end 33 34 it "should return the path to the vhost config" do 35 @uninstaller.config_path(0).should == "#{PassengerPaneConfig::PASSENGER_APPS_DIR}/het-manfreds-blog.local.#{PassengerPaneConfig::PASSENGER_APPS_EXTENSION}" 36 end 37 38 it "should remove the vhost config file" do 39 @uninstaller.stubs(:config_path).returns(@vhost_file) 40 @uninstaller.remove_vhost_conf(0) 41 File.should.not.exist @vhost_file 42 end 43 44 it "should restart Apache" do 45 @uninstaller.expects(:system).with(PassengerPaneConfig::APACHE_RESTART_COMMAND) 46 @uninstaller.restart_apache! 47 end 48 49 it "should remove multiple applications in one go" do 50 uninstaller = ConfigUninstaller.any_instance 51 52 uninstaller.expects(:remove_from_hosts).with(0) 53 uninstaller.expects(:remove_from_hosts).with(1) 54 55 uninstaller.expects(:remove_vhost_conf).with(0) 56 uninstaller.expects(:remove_vhost_conf).with(1) 57 58 uninstaller.expects(:restart_apache!) 59 60 ConfigUninstaller.new([{}, {}].to_yaml).uninstall! 61 end 62end