hoptoad_notifier 2.2.6 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,14 @@
1
+ Version 2.3.0 - 2010-06-24
2
+ ===============================================================================
3
+
4
+ Jason Morrison (5):
5
+ Add integration test for rails 3.0.0.beta4
6
+ Added feature: Support the Heroku addon in the generator
7
+ Add --heroku flag to generator to support ENV['HOPTOAD_API_KEY']
8
+ Reflect a copy change in rails.feature for --heroku generator flag
9
+ Support the proxy configuration options when notifying Hoptoad of a deploy (hat tip @gudleik)
10
+
11
+
1
12
  Version 2.2.6 - 2010-06-02
2
13
  ===============================================================================
3
14
 
@@ -147,3 +158,4 @@ Nick Quaranto (3):
147
158
 
148
159
 
149
160
 
161
+
@@ -6,4 +6,4 @@
6
6
  2.3.2
7
7
  2.3.4
8
8
  2.3.5
9
- 3.0.0.beta3
9
+ 3.0.0.beta4
@@ -3,12 +3,13 @@ require File.expand_path(File.dirname(__FILE__) + "/lib/rake_commands.rb")
3
3
 
4
4
  class HoptoadGenerator < Rails::Generator::Base
5
5
  def add_options!(opt)
6
- opt.on('-k', '--api-key=key', String, "Your Hoptoad API key") {|v| options[:api_key] = v}
6
+ opt.on('-k', '--api-key=key', String, "Your Hoptoad API key") {|v| options[:api_key] = v}
7
+ opt.on('-h', '--heroku', "Use the Heroku addon to provide your Hoptoad API key") {|v| options[:heroku] = v}
7
8
  end
8
9
 
9
10
  def manifest
10
- if !api_key_configured? && !options[:api_key]
11
- puts "Must pass --api-key or create config/initializers/hoptoad.rb"
11
+ if !api_key_configured? && !options[:api_key] && !options[:heroku]
12
+ puts "Must pass --api-key or --heroku or create config/initializers/hoptoad.rb"
12
13
  exit
13
14
  end
14
15
  if plugin_is_present?
@@ -21,13 +22,13 @@ class HoptoadGenerator < Rails::Generator::Base
21
22
  if ['config/deploy.rb', 'Capfile'].all? { |file| File.exists?(file) }
22
23
  m.append_to 'config/deploy.rb', capistrano_hook
23
24
  end
24
- if options[:api_key]
25
+ if api_key_expression
25
26
  if use_initializer?
26
27
  m.template 'initializer.rb', 'config/initializers/hoptoad.rb',
27
- :assigns => {:api_key => options[:api_key]}
28
+ :assigns => {:api_key => api_key_expression}
28
29
  else
29
30
  m.template 'initializer.rb', 'config/hoptoad.rb',
30
- :assigns => {:api_key => options[:api_key]}
31
+ :assigns => {:api_key => api_key_expression}
31
32
  m.append_to 'config/environment.rb', "require 'config/hoptoad'"
32
33
  end
33
34
  end
@@ -35,6 +36,14 @@ class HoptoadGenerator < Rails::Generator::Base
35
36
  end
36
37
  end
37
38
 
39
+ def api_key_expression
40
+ s = if options[:api_key]
41
+ "'#{options[:api_key]}'"
42
+ elsif options[:heroku]
43
+ "ENV['HOPTOAD_API_KEY']"
44
+ end
45
+ end
46
+
38
47
  def use_initializer?
39
48
  Rails::VERSION::MAJOR > 1
40
49
  end
@@ -2,5 +2,5 @@
2
2
  require 'hoptoad_notifier/rails'
3
3
  <% end -%>
4
4
  HoptoadNotifier.configure do |config|
5
- config.api_key = '<%= api_key %>'
5
+ config.api_key = <%= api_key_expression %>
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module HoptoadNotifier
2
- VERSION = "2.2.6".freeze
2
+ VERSION = "2.3.0".freeze
3
3
  end
data/lib/hoptoad_tasks.rb CHANGED
@@ -29,7 +29,14 @@ module HoptoadTasks
29
29
  opts.each {|k,v| params["deploy[#{k}]"] = v }
30
30
 
31
31
  url = URI.parse("http://#{HoptoadNotifier.configuration.host || 'hoptoadapp.com'}/deploys.txt")
32
- response = Net::HTTP.post_form(url, params)
32
+
33
+ proxy = Net::HTTP.Proxy(HoptoadNotifier.configuration.proxy_host,
34
+ HoptoadNotifier.configuration.proxy_port,
35
+ HoptoadNotifier.configuration.proxy_user,
36
+ HoptoadNotifier.configuration.proxy_pass)
37
+
38
+ response = proxy.post_form(url, params)
39
+
33
40
  puts response.body
34
41
  return Net::HTTPSuccess === response
35
42
  end
@@ -3,6 +3,7 @@ require 'rails/generators'
3
3
  class HoptoadGenerator < Rails::Generators::Base
4
4
 
5
5
  class_option :api_key, :aliases => "-k", :type => :string, :desc => "Your Hoptoad API key"
6
+ class_option :heroku, :type => :boolean, :desc => "Use the Heroku addon to provide your Hoptoad API key"
6
7
 
7
8
  def self.source_root
8
9
  @_hoptoad_source_root ||= File.expand_path("../../../../../generators/hoptoad/templates", __FILE__)
@@ -19,8 +20,8 @@ class HoptoadGenerator < Rails::Generators::Base
19
20
  private
20
21
 
21
22
  def ensure_api_key_was_configured
22
- if !options[:api_key] && !api_key_configured?
23
- puts "Must pass --api-key or create config/initializers/hoptoad.rb"
23
+ if !options[:api_key] && !options[:heroku] && !api_key_configured?
24
+ puts "Must pass --api-key or --heroku or create config/initializers/hoptoad.rb"
24
25
  exit
25
26
  end
26
27
  end
@@ -42,8 +43,12 @@ class HoptoadGenerator < Rails::Generators::Base
42
43
  end
43
44
  end
44
45
 
45
- def api_key
46
- options[:api_key]
46
+ def api_key_expression
47
+ s = if options[:api_key]
48
+ "'#{options[:api_key]}'"
49
+ elsif options[:heroku]
50
+ "ENV['HOPTOAD_API_KEY']"
51
+ end
47
52
  end
48
53
 
49
54
  def generate_initializer
@@ -37,25 +37,39 @@ class HoptoadTasksTest < Test::Unit::TestCase
37
37
  end
38
38
  end
39
39
 
40
- context "given valid options" do
41
- setup { @options = {:rails_env => "staging"} }
40
+ context "given an optional HTTP proxy and valid options" do
41
+ setup do
42
+ @response = stub("response", :body => "stub body")
43
+ @http_proxy = stub("proxy", :post_form => @response)
44
+
45
+ Net::HTTP.expects(:Proxy).
46
+ with(HoptoadNotifier.configuration.proxy_host,
47
+ HoptoadNotifier.configuration.proxy_port,
48
+ HoptoadNotifier.configuration.proxy_user,
49
+ HoptoadNotifier.configuration.proxy_pass).
50
+ returns(@http_proxy)
51
+
52
+ @options = { :rails_env => "staging" }
53
+ end
42
54
 
43
55
  context "on deploy(options)" do
44
- setup { @output = HoptoadTasks.deploy(@options) }
56
+ setup do
57
+ @output = HoptoadTasks.deploy(@options)
58
+ end
45
59
 
46
60
  before_should "post to http://hoptoadapp.com/deploys.txt" do
47
61
  URI.stubs(:parse).with('http://hoptoadapp.com/deploys.txt').returns(:uri)
48
- Net::HTTP.expects(:post_form).with(:uri, kind_of(Hash)).returns(successful_response)
62
+ @http_proxy.expects(:post_form).with(:uri, kind_of(Hash)).returns(successful_response)
49
63
  end
50
64
 
51
65
  before_should "use the project api key" do
52
- Net::HTTP.expects(:post_form).
66
+ @http_proxy.expects(:post_form).
53
67
  with(kind_of(URI), has_entries('api_key' => "1234123412341234")).
54
68
  returns(successful_response)
55
69
  end
56
70
 
57
71
  before_should "use send the rails_env param" do
58
- Net::HTTP.expects(:post_form).
72
+ @http_proxy.expects(:post_form).
59
73
  with(kind_of(URI), has_entries("deploy[rails_env]" => "staging")).
60
74
  returns(successful_response)
61
75
  end
@@ -63,7 +77,7 @@ class HoptoadTasksTest < Test::Unit::TestCase
63
77
  [:local_username, :scm_repository, :scm_revision].each do |key|
64
78
  before_should "use send the #{key} param if it's passed in." do
65
79
  @options[key] = "value"
66
- Net::HTTP.expects(:post_form).
80
+ @http_proxy.expects(:post_form).
67
81
  with(kind_of(URI), has_entries("deploy[#{key}]" => "value")).
68
82
  returns(successful_response)
69
83
  end
@@ -71,29 +85,29 @@ class HoptoadTasksTest < Test::Unit::TestCase
71
85
 
72
86
  before_should "use the :api_key param if it's passed in." do
73
87
  @options[:api_key] = "value"
74
- Net::HTTP.expects(:post_form).
88
+ @http_proxy.expects(:post_form).
75
89
  with(kind_of(URI), has_entries("api_key" => "value")).
76
90
  returns(successful_response)
77
91
  end
78
92
 
79
93
  before_should "puts the response body on success" do
80
94
  HoptoadTasks.expects(:puts).with("body")
81
- Net::HTTP.expects(:post_form).with(any_parameters).returns(successful_response('body'))
95
+ @http_proxy.expects(:post_form).with(any_parameters).returns(successful_response('body'))
82
96
  end
83
97
 
84
98
  before_should "puts the response body on failure" do
85
99
  HoptoadTasks.expects(:puts).with("body")
86
- Net::HTTP.expects(:post_form).with(any_parameters).returns(unsuccessful_response('body'))
100
+ @http_proxy.expects(:post_form).with(any_parameters).returns(unsuccessful_response('body'))
87
101
  end
88
102
 
89
103
  should "return false on failure", :before => lambda {
90
- Net::HTTP.expects(:post_form).with(any_parameters).returns(unsuccessful_response('body'))
104
+ @http_proxy.expects(:post_form).with(any_parameters).returns(unsuccessful_response('body'))
91
105
  } do
92
106
  assert !@output
93
107
  end
94
108
 
95
109
  should "return true on success", :before => lambda {
96
- Net::HTTP.expects(:post_form).with(any_parameters).returns(successful_response('body'))
110
+ @http_proxy.expects(:post_form).with(any_parameters).returns(successful_response('body'))
97
111
  } do
98
112
  assert @output
99
113
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 2
7
- - 2
8
- - 6
9
- version: 2.2.6
7
+ - 3
8
+ - 0
9
+ version: 2.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - thoughtbot, inc
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-02 00:00:00 -04:00
17
+ date: 2010-06-24 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency