roar 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.11.2
2
+
3
+ * The request body in POST, PUT and PATCH is now actually sent in HttpVerbs. Thanks to @nleguen for finding this embarrassing bug. That's what happens when you don't have proper tests, kids!
4
+
1
5
  ## 0.11.1
2
6
 
3
7
  * Since some users don't have access to my local hard-drive we now really require representable-1.2.2.
@@ -13,15 +13,15 @@ module Roar
13
13
  end
14
14
 
15
15
  def post_uri(uri, body, as)
16
- do_request(Net::HTTP::Post, uri, as)
16
+ do_request(Net::HTTP::Post, uri, as, body)
17
17
  end
18
18
 
19
19
  def put_uri(uri, body, as)
20
- do_request(Net::HTTP::Put, uri, as)
20
+ do_request(Net::HTTP::Put, uri, as, body)
21
21
  end
22
22
 
23
23
  def patch_uri(uri, body, as)
24
- do_request(Net::HTTP::Patch, uri, as)
24
+ do_request(Net::HTTP::Patch, uri, as, body)
25
25
  end
26
26
 
27
27
  def delete_uri(uri, as)
data/lib/roar/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Roar
2
- VERSION = "0.11.1"
2
+ VERSION = "0.11.2"
3
3
  end
data/test/fake_server.rb CHANGED
@@ -1,10 +1,34 @@
1
1
  require "bundler/setup"
2
- require 'sinatra/base'
2
+ require "sinatra/base"
3
+ require "roar/representer/json"
3
4
 
4
5
  class FakeServer < Sinatra::Base
5
-
6
6
  set :raise_errors, false
7
7
 
8
+ module BandRepresenter
9
+ include Roar::Representer::JSON
10
+
11
+ property :name
12
+ property :label
13
+ end
14
+
15
+ class Band
16
+ attr_reader :name, :label
17
+
18
+ def name=(value)
19
+ @name = value.upcase
20
+ end
21
+
22
+ def label=(value)
23
+ @label = value.upcase
24
+ end
25
+ end
26
+
27
+ def consume_band
28
+ Band.new.extend(BandRepresenter).from_json(request.body.string)
29
+ end
30
+
31
+
8
32
  get "/method" do
9
33
  "<method>get</method>"
10
34
  end
@@ -31,19 +55,20 @@ class FakeServer < Sinatra::Base
31
55
 
32
56
  post "/bands" do
33
57
  #if request.content_type =~ /xml/
34
- body '{"label": "n/a", "name": "Strung Out", "links": [{"href":"http://search", "rel": "search"}, {"href":"http://band/strungout", "rel": "self"}]}'
58
+ body consume_band.to_json
59
+
35
60
  status 201
36
61
  end
37
62
 
38
63
  put "/bands/strungout" do
39
64
  # DISCUSS: as long as we don't agree on what to return in PUT/PATCH, let's return an updated document.
40
- {:name => "Strung Out", :label => "Fat Wreck"}.to_json
65
+ body consume_band.to_json
41
66
  #status 204
42
67
  end
43
68
 
44
69
  patch '/bands/strungout' do
45
70
  # DISCUSS: as long as we don't agree on what to return in PUT/PATCH, let's return an updated document.
46
- {:name => 'Strung Out', :label => 'Fat Mike'}.to_json
71
+ body consume_band.to_json
47
72
  #status 204
48
73
  end
49
74
 
@@ -54,40 +79,4 @@ class FakeServer < Sinatra::Base
54
79
  delete '/banks/metallica' do
55
80
  status 204
56
81
  end
57
-
58
- require './test/order_representers'
59
- JSON::Order.class_eval do
60
- def items_url
61
- "http://roar.example.com/orders/1/items"
62
- end
63
- def order_url(order)
64
- "http://roar.example.com/orders/#{order}"
65
- end
66
- def represented
67
- 1
68
- end
69
-
70
- end
71
-
72
-
73
- post "/orders" do
74
- incoming = JSON::Order.deserialize(request.body.string)
75
- # create new record
76
-
77
- # render new record
78
-
79
- JSON::Order.from_attributes(incoming.to_attributes).serialize
80
- end
81
-
82
- post "/orders/1/items" do
83
- incoming = JSON::Item.deserialize(request.body.string)
84
-
85
- JSON::Item.from_attributes(incoming.to_attributes).serialize
86
- end
87
-
88
- get "/orders/1" do
89
- JSON::Order.new(:client_id => 1, :items => [JSON::Item.new(:article_id => "666-S", :amount => 1)]).serialize
90
- end
91
-
92
82
  end
93
-
@@ -3,12 +3,7 @@ require 'roar/representer/feature/http_verbs'
3
3
  require 'roar/representer/json'
4
4
 
5
5
  class HttpVerbsTest < MiniTest::Spec
6
- module BandRepresenter
7
- include Roar::Representer::JSON
8
-
9
- property :name
10
- property :label
11
- end
6
+ BandRepresenter = FakeServer::BandRepresenter
12
7
 
13
8
  # keep this class clear of Roar modules.
14
9
  class Band
@@ -80,8 +75,8 @@ class HttpVerbsTest < MiniTest::Spec
80
75
  assert_equal nil, @band.label
81
76
 
82
77
  @band.post("http://roar.example.com/bands", "application/xml")
83
- assert_equal "Strung Out", @band.name
84
- assert_equal "n/a", @band.label
78
+ assert_equal "STRUNG OUT", @band.name
79
+ assert_equal nil, @band.label
85
80
  end
86
81
  end
87
82
 
@@ -90,8 +85,8 @@ class HttpVerbsTest < MiniTest::Spec
90
85
  @band.name = "Strung Out"
91
86
  @band.label = "Fat Wreck"
92
87
  @band.put("http://roar.example.com/bands/strungout", "application/xml")
93
- assert_equal "Strung Out", @band.name
94
- assert_equal "Fat Wreck", @band.label
88
+ assert_equal "STRUNG OUT", @band.name
89
+ assert_equal "FAT WRECK", @band.label
95
90
  end
96
91
  end
97
92
 
@@ -99,7 +94,7 @@ class HttpVerbsTest < MiniTest::Spec
99
94
  it 'does something' do
100
95
  @band.label = 'Fat Mike'
101
96
  @band.patch("http://roar.example.com/bands/strungout", "application/xml")
102
- assert_equal 'Fat Mike', @band.label
97
+ assert_equal 'FAT MIKE', @band.label
103
98
  end
104
99
  end
105
100
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
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: 2012-06-05 00:00:00.000000000 Z
12
+ date: 2012-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: representable