goliath 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of goliath might be problematic. Click here for more details.

data/HISTORY.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # HISTORY
2
2
 
3
+ # v1.0.2 (April 25th 2013)
4
+ - Added a handle to disable server startup on exit
5
+ - Added support for JSON post bodies that are not a hash
6
+ - Added a setup hook for API's
7
+ - See full list @ https://github.com/postrank-labs/goliath/compare/v1.0.1...v1.0.2
8
+
3
9
  # v1.0.1 (November 8, 2012)
4
10
 
5
11
  - integrated console (CLI flag)
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency 'eventmachine', '>= 1.0.0.beta.4'
18
18
  s.add_dependency 'em-synchrony', '>= 1.0.0'
19
- s.add_dependency 'em-websocket'
19
+ s.add_dependency 'em-websocket', "0.3.8"
20
20
  s.add_dependency 'http_parser.rb', '0.5.3'
21
21
  s.add_dependency 'log4r'
22
22
 
@@ -125,7 +125,11 @@ module Goliath
125
125
  end
126
126
 
127
127
  at_exit do
128
- if $!.nil? && $0 == Goliath::Application.app_file
128
+ # Only run the application if ...
129
+ # - we want it to run
130
+ # - there has been no exception raised
131
+ # - the file that has been run, is the goliath application file
132
+ if Goliath.run_app_on_exit? && $!.nil? && $0 == Goliath::Application.app_file
129
133
  Application.run!
130
134
  end
131
135
  end
@@ -25,7 +25,13 @@ module Goliath
25
25
 
26
26
  alias :prod? :production?
27
27
  alias :dev? :development?
28
+
29
+ # Controls whether or not the application will be run using an at_exit block.
30
+ attr_accessor :run_app_on_exit
31
+ alias_method :run_app_on_exit?, :run_app_on_exit
28
32
  end
33
+ # By default, we do run the application using the at_exit block.
34
+ self.run_app_on_exit = true
29
35
 
30
36
  # Retrieves the current goliath environment
31
37
  #
@@ -31,7 +31,12 @@ module Goliath
31
31
  when URL_ENCODED then
32
32
  ::Rack::Utils.parse_nested_query(body)
33
33
  when JSON_ENCODED then
34
- MultiJson.load(body)
34
+ json = MultiJson.load(body)
35
+ if json.is_a?(Hash)
36
+ json
37
+ else
38
+ {'_json' => json}
39
+ end
35
40
  else
36
41
  {}
37
42
  end
@@ -293,6 +293,7 @@ module Goliath
293
293
  log.info("Starting server on #{@address}:#{@port} in #{Goliath.env} mode. Watch out for stones.")
294
294
 
295
295
  server = setup_server(log)
296
+ server.api.setup if server.api.respond_to?(:setup)
296
297
  server.start
297
298
  end
298
299
 
@@ -126,7 +126,7 @@ module Goliath
126
126
 
127
127
  # Retrieves the configuration directory for the server
128
128
  #
129
- # @return [String] THe full path to the config directory
129
+ # @return [String] The full path to the config directory
130
130
  def config_dir
131
131
  dir = options[:config] ? File.dirname(options[:config]) : './config'
132
132
  File.expand_path(dir)
@@ -6,6 +6,8 @@ require 'goliath/server'
6
6
  require 'goliath/rack'
7
7
  require 'rack'
8
8
 
9
+ Goliath.run_app_on_exit = false
10
+
9
11
  module Goliath
10
12
  # Methods to help with testing Goliath APIs
11
13
  #
@@ -178,9 +180,11 @@ module Goliath
178
180
  end
179
181
 
180
182
  def create_test_request(request_data)
183
+ domain = request_data.delete(:domain) || "localhost:#{@test_server_port}"
181
184
  path = request_data.delete(:path) || ''
182
185
  opts = request_data.delete(:connection_options) || {}
183
- EM::HttpRequest.new("http://localhost:#{@test_server_port}#{path}", opts)
186
+
187
+ EM::HttpRequest.new("http://#{domain}#{path}", opts)
184
188
  end
185
189
 
186
190
  private
@@ -1,4 +1,4 @@
1
1
  module Goliath
2
2
  # The current version of Goliath
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
@@ -59,6 +59,10 @@ module Goliath
59
59
  @parent.on_message(@env, msg)
60
60
  end
61
61
 
62
+ def close_connection
63
+ @env[STREAM_CLOSE].call
64
+ end
65
+
62
66
  def close_connection_after_writing
63
67
  @connection_close.call
64
68
  end
@@ -142,6 +142,16 @@ Berry\r
142
142
  ret['foo'].should == 'bar'
143
143
  end
144
144
 
145
+ it "parses json that does not evaluate to a hash" do
146
+ @env['CONTENT_TYPE'] = 'application/json'
147
+ @env['rack.input'] = StringIO.new
148
+ @env['rack.input'] << %|["foo","bar"]|
149
+ @env['rack.input'].rewind
150
+
151
+ ret = @params.retrieve_params(@env)
152
+ ret['_json'].should == ['foo', 'bar']
153
+ end
154
+
145
155
  it "handles empty input gracefully on JSON" do
146
156
  @env['CONTENT_TYPE'] = 'application/json'
147
157
  @env['rack.input'] = StringIO.new
@@ -108,6 +108,16 @@ describe Goliath::Runner do
108
108
  end
109
109
  end
110
110
 
111
+ it 'sets up the api if that implements the #setup method' do
112
+ server_mock = mock("Server").as_null_object
113
+ server_mock.api.should_receive(:setup)
114
+
115
+ Goliath::Server.stub!(:new).and_return(server_mock)
116
+
117
+ @r.stub!(:load_config).and_return({})
118
+ @r.send(:run_server)
119
+ end
120
+
111
121
  it 'runs the server' do
112
122
  server_mock = mock("Server").as_null_object
113
123
  server_mock.should_receive(:start)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goliath
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-09 00:00:00.000000000 Z
13
+ date: 2013-04-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: eventmachine
@@ -49,17 +49,17 @@ dependencies:
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
- - - ! '>='
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.3.8
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
60
- - - ! '>='
60
+ - - '='
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: 0.3.8
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: http_parser.rb
65
65
  requirement: !ruby/object:Gem::Requirement
@@ -666,9 +666,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
666
666
  - - ! '>='
667
667
  - !ruby/object:Gem::Version
668
668
  version: '0'
669
- segments:
670
- - 0
671
- hash: -356739448572304908
672
669
  requirements: []
673
670
  rubyforge_project:
674
671
  rubygems_version: 1.8.24