spec/shelly/cli/backup_spec.rb in shelly-0.3.0 vs spec/shelly/cli/backup_spec.rb in shelly-0.3.1

- old
+ new

@@ -262,11 +262,11 @@ end describe "#import" do before do FileUtils.touch("dump.sql") - @app.stub(:upload => {"server" => "app1"}, :ssh => nil) + @app.stub(:upload_database => {"server" => "app1"}, :ssh => nil) @backup.stub(:system) $stdout.stub(:puts) $stdout.stub(:print) Time.stub_chain(:now, :to_i => 1370879705) end @@ -282,30 +282,30 @@ invoke(@backup, :import, "postgresql", "dump.sql") end end it "should upload compressed file" do - @app.should_receive(:upload).with("dump.sql-1370879705.tar.bz2") + @app.should_receive(:upload_database).with("dump.sql-1370879705.tar.bz2") $stdout.should_receive(:puts).with(green "Uploading dump.sql-1370879705.tar.bz2") fake_stdin(["yes"]) do invoke(@backup, :import, "postgresql", "dump.sql") end end it "should import given database from uploaded file" do @app.should_receive(:ssh).with(:command => "import_database postgresql dump.sql-1370879705.tar.bz2", - :server => "app1") + :server => "app1", :type => :db_server) $stdout.should_receive(:puts).with(green "Importing database") fake_stdin(["yes"]) do invoke(@backup, :import, "PostgreSQL", "dump.sql") end end context "on answering no" do it "should cancel database import" do - $stdout.should_receive(:puts).with("You are about import postgresql database for cloud foo-staging to state from file dump.sql") - $stdout.should_receive(:print).with("I want to import the database (yes/no): ") + $stdout.should_receive(:puts).with(yellow "You are about to import postgresql database for cloud foo-staging to state from file dump.sql") + $stdout.should_receive(:print).with("I want to import the database from dump (yes/no): ") $stdout.should_receive(:puts).with(red "Canceled") lambda { fake_stdin(["no"]) do invoke(@backup, :import, "postgresql", "dump.sql") end @@ -320,9 +320,22 @@ lambda { fake_stdin(["yes"]) do invoke(@backup, :import, "postgresql", "dump.sql") end }.should raise_error(SystemExit) + end + end + + context "with --reset option" do + it "should reset database first" do + @backup.options = {:cloud => "foo-staging", :reset => true} + @app.should_receive(:reset_database).with("postgresql") + @app.should_receive(:ssh).with(:command => "import_database postgresql dump.sql-1370879705.tar.bz2", + :server => "app1", :type => :db_server) + $stdout.should_receive(:puts).with(green "Importing database") + fake_stdin(["yes"]) do + invoke(@backup, :import, "postgresql", "dump.sql") + end end end end end