oop_rails_server 0.0.19 → 0.0.20

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f07bd13a4e1384b5c4aaead8af1b980892fa6de8
4
- data.tar.gz: 2d8a3a3a3af8fd99a6247bafcf9d4af731a1c583
3
+ metadata.gz: 140913824859d2e60dac03fd6dcf65dea5a08583
4
+ data.tar.gz: 5f2868f6c2eb0c022e58a8662482df1a977999dd
5
5
  SHA512:
6
- metadata.gz: 96d680a1199a5aa1eb124e1ea2bbc2efbec0c7ccd85a0e76f6e10d79ec4c1fb2a3f32f0e4a769eb96274700fe4a8040a0052c48d01b364bdb716e27737f0eb61
7
- data.tar.gz: f9302281fcb1216edaf939e2dab8c6341f468f0272130ab1c9817ec5c5e8c2ad7e32055a5fccb3083be0a92fe9e6c956f2e1ba273d1522c2ef79b5072a995a0d
6
+ metadata.gz: b7571e1382081033e21809caff1f082d7b72137c752063e99a008470b57c47c6e5b4f57f393dd422232561a20026cadca1ad0e8717ffd0fb45de4ec0014a255f
7
+ data.tar.gz: ae4e5afc2c61b4154833537c1c2e4c49993165343101bc67fea02d4d9a2954e015ddfe088df8023eaa662fd5e648410ef1ea8dc9beb3f017d33e7a157cde9c87
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # `oop_rails_server` Releases
2
2
 
3
+ ## 0.0.20, 27 September 2016
4
+
5
+ * If exceptions have a `cause`, nest that inside the JSON returned on error.
6
+ * Pass 'Accept: text/html' by default when fetching from a Rails server, unless specified otherwise.
7
+
3
8
  ## 0.0.19, 20 September 2016
4
9
 
5
10
  * Significant internal refactor to how Gemfiles get modified that's much more reliable; changes
@@ -58,6 +58,8 @@ module OopRailsServer
58
58
  expect(json['exception']).to be
59
59
  expect(json['exception']['class']).to eq(class_name.to_s)
60
60
  expect(json['exception']['message']).to match(message)
61
+
62
+ json
61
63
  end
62
64
 
63
65
  def rails_template_name
@@ -94,11 +94,16 @@ module OopRailsServer
94
94
  end
95
95
 
96
96
  def get_response(path_or_uri, options = { })
97
- options.assert_valid_keys(:ignore_status_code, :nil_on_not_found, :query, :no_layout)
97
+ options.assert_valid_keys(:ignore_status_code, :nil_on_not_found, :query, :no_layout, :accept_header)
98
98
 
99
99
  uri = uri_for(path_or_uri, options[:query])
100
- # say "[fetch '#{uri}']"
101
- data = Net::HTTP.get_response(uri)
100
+ data = nil
101
+ accept_header = options.fetch(:accept_header, 'text/html')
102
+ Net::HTTP.start(uri.host, uri.port) do |http|
103
+ request = Net::HTTP::Get.new(uri)
104
+ request['Accept'] = accept_header if accept_header
105
+ data = http.request(request)
106
+ end
102
107
 
103
108
  if (data.code.to_s != '200')
104
109
  if options[:ignore_status_code]
@@ -106,7 +111,7 @@ module OopRailsServer
106
111
  elsif options[:nil_on_not_found]
107
112
  data = nil
108
113
  else
109
- raise "'#{uri}' returned #{data.code.inspect}, not 200; body was: #{data.body.strip}"
114
+ raise "'#{uri}' returned #{data.code.inspect}, not 200; body was: #{data.body.inspect}"
110
115
  end
111
116
  end
112
117
  data
@@ -1,3 +1,3 @@
1
1
  module OopRailsServer
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.20"
3
3
  end
@@ -5,11 +5,22 @@ class ApplicationController < ActionController::Base
5
5
 
6
6
  rescue_from Exception do |exception|
7
7
  render :json => {
8
- :exception => {
9
- :class => exception.class.name,
10
- :message => exception.message,
11
- :backtrace => exception.backtrace
12
- }
8
+ :exception => exception_to_hash(exception)
13
9
  }
14
10
  end
11
+
12
+ private
13
+ def exception_to_hash(exception)
14
+ out = {
15
+ :class => exception.class.name,
16
+ :message => exception.message,
17
+ :backtrace => exception.backtrace
18
+ }
19
+
20
+ if exception.cause && (! exception.cause.equal?(exception))
21
+ out[:cause] = exception_to_hash(exception.cause)
22
+ end
23
+
24
+ out
25
+ end
15
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oop_rails_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Geweke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json