mattmatt-cap-ext-webistrano 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ your command line just using the cap command.
4
4
  Installation
5
5
  ============
6
6
 
7
- gem install mattmatt-cap-ext-webistrano
7
+ gem install mattmatt-cap-ext-webistrano
8
8
 
9
9
  Usage
10
10
  =====
@@ -14,25 +14,25 @@ Capistrano.
14
14
 
15
15
  In your Capfile, insert the following lines at the end.
16
16
 
17
- gem 'mattmatt-cap-ext-webistrano'
18
- require 'cap_ext_webistrano'
17
+ gem 'mattmatt-cap-ext-webistrano'
18
+ require 'cap_ext_webistrano'
19
19
 
20
20
  The Webistrano extensions require a couple of configuration options that you
21
21
  can specify in your deploy.rb. They're pretty much the standard options you'd
22
22
  configure for your application with Capistrano.
23
23
 
24
- set :application, "My project" # The project as named in Webistrano
25
- set :user, "admin"
26
- set :password, "admin"
27
- set :stage, "test" # specify the stage you want to deploy
28
- set :webistrano_home, "http://webistrano.mydomain.com/"
24
+ set :application, "My project" # The project as named in Webistrano
25
+ set :user, "admin"
26
+ set :password, "admin"
27
+ set :stage, "test" # specify the stage you want to deploy
28
+ set :webistrano_home, "http://webistrano.mydomain.com/"
29
29
 
30
30
  If you only have one stage in your project this should do, however with
31
31
  several stages it'd be better to ask for the stage to be deployed:
32
32
 
33
- set :stage do
34
- Capistrano::CLI.ui.ask "Specify the stage to deploy: "
35
- end
33
+ set :stage do
34
+ Capistrano::CLI.ui.ask "Specify the stage to deploy: "
35
+ end
36
36
 
37
37
  (c) 2009 Mathias Meyer
38
38
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 0
3
- :patch: 4
2
+ :minor: 1
3
+ :patch: 0
4
4
  :major: 0
@@ -4,11 +4,12 @@ require 'cap_ext_webistrano/deployment'
4
4
 
5
5
  module CapExtWebistrano
6
6
  class Task
7
- attr_accessor :task
7
+ attr_accessor :task, :log
8
8
 
9
9
  def initialize(task, config)
10
10
  @task = task
11
11
  @config = config
12
+ @log = ""
12
13
  end
13
14
 
14
15
  def set_access_data
@@ -17,11 +18,30 @@ module CapExtWebistrano
17
18
  end
18
19
  end
19
20
 
21
+ def loop_latest_deployment
22
+ still_running = true
23
+ while still_running
24
+ sleep 5
25
+ @deployment = Deployment.find(@deployment.id, :params => {:project_id => @project.id, :stage_id => @stage.id})
26
+ print_diff(@deployment)
27
+ still_running = false unless @deployment.completed_at.nil?
28
+ end
29
+ end
30
+
31
+ def print_diff(deployment)
32
+ if deployment.log
33
+ diff = deployment.log.sub(log, "")
34
+ print diff
35
+ log << diff
36
+ end
37
+ end
38
+
20
39
  def run
21
40
  set_access_data
22
- project = Project.find_by_name(@config[:application])
23
- stage = project.find_stage(@config[:stage])
24
- Deployment.create(:task => task, :stage_id => stage.id, :project_id => project.id)
41
+ @project = Project.find_by_name(@config[:application])
42
+ @stage = @project.find_stage(@config[:stage])
43
+ @deployment = Deployment.create(:task => task, :stage_id => @stage.id, :project_id => @project.id)
44
+ loop_latest_deployment
25
45
  end
26
46
  end
27
47
  end
data/test/task_shoulda.rb CHANGED
@@ -15,6 +15,7 @@ class TaskTest < Test::Unit::TestCase
15
15
  @config[:user] = "chunky"
16
16
  @task = CapExtWebistrano::Task.new("deploy", @config)
17
17
  @task.set_access_data
18
+ @task.stubs(:sleep)
18
19
  end
19
20
 
20
21
  context "when setting up the configuration data" do
@@ -44,7 +45,9 @@ class TaskTest < Test::Unit::TestCase
44
45
  Project.stubs(:find).returns([@project1, @project2])
45
46
  @stage1 = Stage.new(:name => "test", :id => 3)
46
47
  Stage.stubs(:find).returns([@stage1])
47
- Deployment.stubs(:create).returns nil
48
+ @deployment = Deployment.new(:completed_at => Time.now, :log => "Chunky bacon!")
49
+ Deployment.stubs(:create).returns @deployment
50
+ Deployment.stubs(:find).returns(@deployment)
48
51
  @config[:application] = "Bacon"
49
52
  @config[:stage] = "test"
50
53
  end
@@ -60,9 +63,30 @@ class TaskTest < Test::Unit::TestCase
60
63
  end
61
64
 
62
65
  should "create a deployment" do
63
- Deployment.expects(:create).with(:task => "deploy", :project_id => 2, :stage_id => 3)
66
+ Deployment.expects(:create).with(:task => "deploy", :project_id => 2, :stage_id => 3).returns(@deployment)
64
67
  @task.run
65
68
  end
69
+
70
+ should "find the latest deployment" do
71
+ Deployment.expects(:find).returns @deployment
72
+ @task.run
73
+ end
74
+
75
+ context "when requesting the deployment multiple times" do
76
+ setup do
77
+ @seq = sequence("latest")
78
+ @deployment1 = Deployment.new(:completed_at => nil, :log => "Chunky bacon", :id => 2)
79
+ @deployment2 = Deployment.new(:completed_at => Time.now, :log => "Chunky bacon is my bitch", :id => 2)
80
+ Deployment.stubs(:create).returns(@deployment1)
81
+ end
82
+
83
+ should "concat the deployment log" do
84
+ Deployment.expects(:find).returns(@deployment1).in_sequence(@seq)
85
+ Deployment.expects(:find).returns(@deployment2).in_sequence(@seq)
86
+ @task.run
87
+ assert_equal "Chunky bacon is my bitch", @task.log
88
+ end
89
+ end
66
90
  end
67
91
  end
68
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mattmatt-cap-ext-webistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Meyer
@@ -31,7 +31,7 @@ extra_rdoc_files: []
31
31
 
32
32
  files:
33
33
  - Rakefile
34
- - README
34
+ - README.markdown
35
35
  - VERSION.yml
36
36
  - lib/cap_ext_webistrano
37
37
  - lib/cap_ext_webistrano/deployment.rb