Permalink
Browse files

Creating rake task. Issue #6

  • Loading branch information...
1 parent 680fc82 commit 11366dbdf11df11dd2bd2167037eeb7f20361753 @tapajos tapajos committed Aug 18, 2011
Showing with 42 additions and 0 deletions.
  1. +4 −0 lib/kumade.rb
  2. +10 −0 lib/kumade/railtie.rb
  3. +8 −0 lib/tasks/deploy.rake
  4. +20 −0 spec/kumade_spec.rb
View
@@ -1,6 +1,7 @@
require 'thor'
require 'kumade/deployer'
require 'kumade/runner'
+require 'kumade/railtie'
module Kumade
def self.app_for(environment)
@@ -11,6 +12,9 @@ def self.app_for(environment)
nil
end
end
+ def self.environments
+ url_remotes = `git remote`.strip.split("\n").map{|remote| [remote, `git config --get remote.#{remote}.url`.strip] }.select{|remote| remote.last =~ /^git@heroku\.com:(.+)\.git$/}.map{|remote| remote.first}
+ end
def self.on_cedar!(app)
@cedar_apps ||= []
View
@@ -0,0 +1,10 @@
+# add rake tasks if we are inside Rails
+if defined?(Rails::Railtie)
+ class Module
+ class Railtie < ::Rails::Railtie
+ rake_tasks do
+ load File.expand_path("../../tasks/deploy.rake", __FILE__)
+ end
+ end
+ end
+end
View
@@ -0,0 +1,8 @@
+namespace :deploy do
+ Kumade.environments.each do |environment|
+ desc "Deploy to #{environment} environment"
+ task environment do
+ Kumade::Runner.run([environment])
+ end
+ end
+end
View
@@ -27,3 +27,23 @@
Kumade.app_for(not_a_heroku_env).should be_nil
end
end
+
+describe Kumade, ".environments" do
+ let(:environment){ 'staging' }
+ let(:app_name){ 'staging_test' }
+ let(:not_a_heroku_env){ 'fake_heroku' }
+ let(:not_a_heroku_url){ 'git@github.com:gabebw/kumade.git' }
+
+ before do
+ force_add_heroku_remote(environment, app_name)
+ `git remote add #{not_a_heroku_env} #{not_a_heroku_url}`
+ end
+ after do
+ remove_remote(environment)
+ remove_remote(not_a_heroku_env)
+ end
+
+ it "should return all environments" do
+ Kumade.environments.should == ["staging"]
+ end
+end

0 comments on commit 11366db

Please sign in to comment.