Permalink
Browse files

Fixing issue #2

  • Loading branch information...
1 parent 3bfe571 commit 988f9b37acd3db13663559b3129ff577029784c9 @tapajos tapajos committed Aug 17, 2011
Showing with 34 additions and 6 deletions.
  1. +2 −0 features/kumade_executable.feature
  2. +10 −0 lib/kumade/deployer.rb
  3. +22 −6 spec/kumade/deployer_spec.rb
@@ -24,6 +24,7 @@ Feature: Kumade executable
==> Packaged assets with Jammit
run git push origin master
==> Pushed master -> origin
+ run git branch deploy
run git push -f pretend-staging deploy:master
==> Force pushed master -> pretend-staging
==> Migrated pretend-staging-app
@@ -54,6 +55,7 @@ Feature: Kumade executable
==> Packaged assets with Jammit
run git push origin new_branch
==> Pushed new_branch -> origin
+ run git branch deploy
run git push -f pretend-staging deploy:master
==> Force pushed new_branch -> pretend-staging
==> Migrated pretend-staging-app
@@ -32,6 +32,9 @@ def sync_github
end
def sync_heroku
+ unless branch_exist?(DEPLOY_BRANCH)
+ run_or_error("git branch deploy", "Failed to create #{DEPLOY_BRANCH}")
+ end
run_or_error("git push -f #{environment} #{DEPLOY_BRANCH}:master",
"Failed to force push #{DEPLOY_BRANCH} -> #{environment}/master")
success("Force pushed #{@branch} -> #{environment}")
@@ -161,6 +164,13 @@ def run(command, config = {})
say_status :run, command
config[:capture] ? `#{command}` : system("#{command}")
end
+
+ def branch_exist?(branch)
+ branches = `git branch`
+ regex = Regexp.new('[\\n\\s\\*]+' + Regexp.escape(branch.to_s) + '\\n')
+ result = ((branches =~ regex) ? true : false)
+ return result
+ end
def error(message)
say("==> ! #{message}", :red)
@@ -100,12 +100,28 @@
let(:environment) { 'my-env' }
subject { Kumade::Deployer.new(environment) }
before { subject.stub(:say) }
+
+ context "when deploy branch exists" do
+ it "should calls `git push -f`" do
+ subject.stub(:branch_exist?).with("deploy").and_return(true)
+ subject.should_receive(:run).
+ with("git push -f #{environment} deploy:master").
+ and_return(true)
+ subject.sync_heroku
+ end
+ end
- it "calls `git push -f`" do
- subject.should_receive(:run).
- with("git push -f #{environment} deploy:master").
- and_return(true)
- subject.sync_heroku
+ context "when deploy branch doesn't exists" do
+ it "should calls `git branch deploy` and `git push -f`" do
+ subject.stub(:branch_exist?).with("deploy").and_return(false)
+ subject.should_receive(:run).
+ with("git branch deploy").
+ and_return(true)
+ subject.should_receive(:run).
+ with("git push -f #{environment} deploy:master").
+ and_return(true)
+ subject.sync_heroku
+ end
end
context "when syncing to heroku fails" do
@@ -114,7 +130,7 @@
end
it "prints an error" do
- subject.should_receive(:error)
+ subject.should_receive(:error).twice
subject.sync_heroku
end
end

0 comments on commit 988f9b3

Please sign in to comment.