cryx-g5k 0.2.2 → 0.2.3

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/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 2
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
@@ -13,13 +13,14 @@ module G5K
13
13
  end
14
14
 
15
15
  def formatted_error(http_status, options = {})
16
+ parser = options.delete(:parser)
17
+ format = options.delete(:format) || params[:format] || "txt"
16
18
  body = {:code => (options[:code] || http_status), :message => options[:message], :title => options[:title]}
17
- format = options[:format] || params[:format] || "txt"
18
19
  content_type format.to_sym, :charset => 'utf-8'
19
- if (parser = Parser.select(format.to_sym))
20
+ if (parser)
20
21
  body = parser.dump(body)
21
22
  else
22
- body.map!{|(k,v)| [k,v].join("=")}.join(";")
23
+ body = body.map{|(k,v)| [k,v].join("=")}.sort.join(";")
23
24
  end
24
25
  error(http_status, body)
25
26
  end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/../lib/g5k/sinatra/helpers'
3
+
4
+ describe G5K::Sinatra::Helpers do
5
+ class Request
6
+ include G5K::Sinatra::Helpers
7
+ def initialize(options = {})
8
+ @format = options[:format]
9
+ end
10
+ def params; {:format => @format}; end
11
+ end
12
+
13
+ it "should throw a 406 error if it does not provide the requested format" do
14
+ req = Request.new(:format => 'json')
15
+ req.should_receive(:throw).with(:halt, [406, "The accepted types are: xml, js"])
16
+ req.provides(:xml, :js)
17
+ end
18
+
19
+ it "should not throw a 406 error if it can provide the requested format" do
20
+ req = Request.new(:format => 'json')
21
+ req.should_not_receive(:throw)
22
+ req.provides(:xml, :json)
23
+ end
24
+
25
+ it "should format the error with the given parser" do
26
+ require 'json'
27
+ options = {:code => 500, :message => "message", :title => "title"}
28
+ req = Request.new
29
+ req.should_receive(:content_type).with(:json, :charset => 'utf-8')
30
+ req.should_receive(:error).with(404, options.to_json)
31
+ req.formatted_error(404, options.merge({:parser => JSON, :format => 'json'}))
32
+ end
33
+
34
+ it "should format the error even when no parser is given" do
35
+ options = {:code => 500, :message => "message", :title => "title"}
36
+ req = Request.new
37
+ req.should_receive(:content_type).with(:txt, :charset => 'utf-8')
38
+ req.should_receive(:error).with(404, "code=500;message=message;title=title")
39
+ req.formatted_error(404, options)
40
+ end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryx-g5k
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Rohr
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-02 00:00:00 -08:00
12
+ date: 2009-03-03 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -32,11 +32,13 @@ files:
32
32
  - lib/g5k/rack/accept_format.rb
33
33
  - lib/g5k/rack/jsonp.rb
34
34
  - lib/g5k/schema
35
+ - lib/g5k/schema/schema.rb
35
36
  - lib/g5k/sinatra
36
37
  - lib/g5k/sinatra/helpers.rb
37
38
  - lib/g5k.rb
38
39
  - spec/g5k_spec.rb
39
40
  - spec/parsing_spec.rb
41
+ - spec/sinatra_helpers_spec.rb
40
42
  - spec/spec_helper.rb
41
43
  has_rdoc: true
42
44
  homepage: http://github.com/cryx/g5k