offshore 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,8 +21,8 @@ module Offshore
21
21
  def base_uri
22
22
  with_http = host
23
23
  with_http = "http://#{host}" unless (host =~ /^https?:/) == 0
24
- need_port = port || 80
25
- "#{with_http}:#{need_port}"
24
+ with_http << ":#{port}" if port
25
+ "#{with_http}"
26
26
  end
27
27
 
28
28
  def connection
@@ -30,7 +30,10 @@ module Offshore
30
30
  connection_class = Faraday.respond_to?(:new) ? ::Faraday : ::Faraday::Connection
31
31
 
32
32
  timeout_seconds = 5*60 # 5 minutes
33
- @connection = connection_class.new(base_uri, :timeout => timeout_seconds) do |builder|
33
+ options = {:timeout => timeout_seconds}
34
+ options[:ssl] = {:verify => false}
35
+
36
+ @connection = connection_class.new(base_uri, options) do |builder|
34
37
  builder.use Faraday::Request::UrlEncoded if defined?(Faraday::Request::UrlEncoded)
35
38
  builder.adapter Faraday.default_adapter
36
39
  end
@@ -49,9 +52,9 @@ module Offshore
49
52
  else
50
53
  begin
51
54
  hash = MultiJson.decode(http_response.body)
52
- message = "Error in offshore connection (#{append_path}): #{hash}"
55
+ message = "Error in offshore connection (#{append_path}): #{http_response.status},\n#{hash}"
53
56
  rescue
54
- message = "Error in offshore connection (#{append_path}): #{http_response.status}"
57
+ message = "Error in offshore connection (#{append_path}): #{http_response.status}\n#{hash}"
55
58
  end
56
59
  raise message
57
60
  end
@@ -5,13 +5,13 @@ module Offshore
5
5
  end
6
6
 
7
7
  def init_server
8
- Offshore::Database.init # has it's own singleton code
8
+ Offshore::Database.init # has its own singleton code
9
9
  end
10
10
 
11
11
  def init_thread
12
12
  return if @init_thread
13
13
  @init_thread = true
14
-
14
+
15
15
  # TODO: move this to a config block
16
16
  if defined?(Rails)
17
17
  begin
@@ -29,20 +29,31 @@ module Offshore
29
29
 
30
30
 
31
31
  def call(env)
32
- if (env["PATH_INFO"] =~ /^\/offshore_tests\/(.*)/) == 0
33
- offshore_call($1, env)
32
+ if offshore_request?(env)
33
+ offshore_call(env)
34
34
  else
35
35
  @app.call(env)
36
36
  end
37
37
  end
38
+
39
+ def offshore_request?(env)
40
+ return false unless Offshore.enabled?
41
+ !!offshore_method(env)
42
+ end
43
+
44
+ def offshore_method(env)
45
+ env["PATH_INFO"] =~ /^\/offshore_tests\/(.*)/
46
+ $1
47
+ end
38
48
 
39
- def offshore_call(method, env)
49
+ def offshore_call(env)
40
50
  status = 500
41
51
  headers = {}
52
+ method = offshore_method(env)
42
53
  hash = {"error" => "Unknown method: #{method}"}
43
54
 
44
55
  Logger.info("Offshore Tests Action: #{method}")
45
-
56
+
46
57
  begin
47
58
  case method
48
59
  when "factory_create", "suite_start", "suite_stop", "test_start", "test_stop"
@@ -12,7 +12,7 @@ module Offshore
12
12
  raise "Only supported in Rails for now" unless defined?(Rails)
13
13
 
14
14
  yml = Rails.root.join("config", "database.yml")
15
- hash = YAML.load(ERB.new(File.read(yml)).result)["test"]
15
+ hash = YAML.load(ERB.new(File.read(yml)).result)['test']
16
16
 
17
17
  @config = {}
18
18
  ['username', 'password', 'host', 'port', 'database', 'collation', 'charset'].each do |key|
@@ -1,3 +1,3 @@
1
1
  module Offshore
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/offshore.rb CHANGED
@@ -12,6 +12,18 @@ module Offshore
12
12
  def test
13
13
  Offshore::Test
14
14
  end
15
+
16
+ def enable!
17
+ @enabled = true
18
+ end
19
+
20
+ def enabled?
21
+ !!@enabled
22
+ end
23
+
24
+ def disable!
25
+ @enabled = false
26
+ end
15
27
  end
16
28
 
17
29
  require "offshore/client"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: offshore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-08 00:00:00.000000000 Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json