-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse git remote name to determine Heroku app
Several reports have matched #72, which was affecting the `restore` command for some users. The cause turned out to be local folder names not matching the name of the Heroku app. Now that Heroku tracks Git remotes, we can take advantage of the Git remote to correctly identify the app name even the local folder name doesn't match. While this requirement has been present for the entirety of Parity's existence, it stopped being a problem for most commands once Heroku introduced remotes. I inadvertently reintroduced this requirement in ad2c21a when we started automatically bypassing confirmation arguments for restores to non-production environments. I've moved the `git` and `rake` dependencies to the gemspec, as they do not appear to be installed by default if they are listed in the Gemfile. Fix #72.
- Loading branch information
1 parent
95ac59c
commit 10574fe
Showing
6 changed files
with
50 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,4 @@ source 'https://rubygems.org' | |
|
||
gemspec | ||
|
||
gem 'rake' | ||
gem 'rspec' | ||
gem "rspec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,26 @@ | |
expect(Kernel).to have_received(:system).with(heroku_backup) | ||
end | ||
|
||
it "correctly connects to the Heroku app when the $PWD's name does not match the app's name" do | ||
backup = stub_parity_backup | ||
stub_git_remote(base_name: "parity-integration", environment: "staging") | ||
allow(Parity::Backup).to receive(:new).and_return(backup) | ||
|
||
Parity::Environment.new("staging", ["restore", "production"]).run | ||
|
||
expect(Parity::Backup). | ||
to have_received(:new). | ||
with( | ||
from: "production", | ||
to: "staging", | ||
additional_args: "--confirm parity-integration-staging", | ||
) | ||
expect(backup).to have_received(:restore) | ||
end | ||
|
||
it "restores backups from production to staging" do | ||
backup = double("backup", restore: nil) | ||
backup = stub_parity_backup | ||
stub_git_remote(environment: "staging") | ||
allow(Parity::Backup).to receive(:new).and_return(backup) | ||
|
||
Parity::Environment.new("staging", ["restore", "production"]).run | ||
|
@@ -48,7 +66,8 @@ | |
end | ||
|
||
it "restores using restore-from" do | ||
backup = double("backup", restore: nil) | ||
backup = stub_parity_backup | ||
stub_git_remote(environment: "staging") | ||
allow(Parity::Backup).to receive(:new).and_return(backup) | ||
|
||
Parity::Environment.new("staging", ["restore-from", "production"]).run | ||
|
@@ -64,7 +83,8 @@ | |
end | ||
|
||
it "passes the confirm argument when restoring to a non-prod environment" do | ||
backup = double("backup", restore: nil) | ||
backup = stub_parity_backup | ||
stub_git_remote(environment: "staging") | ||
allow(Parity::Backup).to receive(:new).and_return(backup) | ||
|
||
Parity::Environment.new("staging", ["restore", "production"]).run | ||
|
@@ -79,7 +99,7 @@ | |
end | ||
|
||
it "restores backups from production to development" do | ||
backup = double("backup", restore: nil) | ||
backup = stub_parity_backup | ||
allow(Parity::Backup).to receive(:new).and_return(backup) | ||
|
||
Parity::Environment.new("development", ["restore", "production"]).run | ||
|
@@ -90,7 +110,7 @@ | |
end | ||
|
||
it "restores backups from staging to development" do | ||
backup = double("backup", restore: nil) | ||
backup = stub_parity_backup | ||
allow(Parity::Backup).to receive(:new).and_return(backup) | ||
|
||
Parity::Environment.new("development", ["restore", "staging"]).run | ||
|
@@ -101,7 +121,8 @@ | |
end | ||
|
||
it "does not allow restoring backups into production" do | ||
backup = double("backup", restore: nil) | ||
backup = stub_parity_backup | ||
stub_git_remote | ||
allow(Parity::Backup).to receive(:new).and_return(backup) | ||
allow($stdout).to receive(:puts) | ||
|
||
|
@@ -323,4 +344,18 @@ def stub_migration_path_check(result) | |
|
||
path_stub | ||
end | ||
|
||
def stub_git_remote(base_name: "parity", environment: "staging") | ||
git_remote = instance_double( | ||
"Git::Remote", | ||
url: "[email protected]:#{base_name}-#{environment}.git", | ||
) | ||
git = instance_double("Git::Base") | ||
allow(git).to receive(:remote).with("staging").and_return(git_remote) | ||
allow(Git).to receive(:init).and_return(git) | ||
end | ||
|
||
def stub_parity_backup | ||
instance_double("Parity::Backup", restore: nil) | ||
end | ||
end |