roar 0.11.16 → 0.11.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ # 0.11.17
2
+
3
+ * Fixing HAL + Decorator.
4
+ * Requiring representable-1.5.0.
5
+
1
6
  # 0.11.16
2
7
 
3
8
  * Added `Roar::Decorator::HypermediaConsumer` which propagates incoming hypermedia links to the represented object (it has to have accessors for `:links`).
@@ -6,5 +6,11 @@ class Roar::Decorator < Representable::Decorator
6
6
  super # TODO: this currently sets #links which is not obvious.
7
7
  represented.links = links
8
8
  end
9
+
10
+ # TODO: what is the deal with #links_array and #links?
11
+ def links=(*args)
12
+ super
13
+ represented.links = links
14
+ end
9
15
  end
10
16
  end
@@ -109,8 +109,8 @@ module Roar::Representer
109
109
  module LinkCollectionRepresenter
110
110
  include Representable::JSON::Hash
111
111
 
112
- values :extend => lambda { |item| item.is_a?(Array) ? LinkArrayRepresenter : Roar::Representer::JSON::HyperlinkRepresenter },
113
- :class => lambda { |hsh| hsh.is_a?(LinkArray) ? nil : Roar::Representer::Feature::Hypermedia::Hyperlink }
112
+ values :extend => lambda { |item, *| item.is_a?(Array) ? LinkArrayRepresenter : Roar::Representer::JSON::HyperlinkRepresenter },
113
+ :class => lambda { |hsh, *| hsh.is_a?(LinkArray) ? nil : Roar::Representer::Feature::Hypermedia::Hyperlink }
114
114
 
115
115
  def to_hash(options)
116
116
  super.tap do |hsh| # TODO: cool: super(:exclude => [:rel]).
@@ -157,11 +157,11 @@ module Roar::Representer
157
157
  def links_definition_options
158
158
  [:links,
159
159
  {
160
- :as => :links,
161
160
  :extend => HAL::Links::LinkCollectionRepresenter,
162
- :instance => lambda { |hsh| LinkCollection.new(link_array_rels) }, # defined in InstanceMethods as this is executed in represented context.
161
+ :instance => lambda { |*| LinkCollection.new(link_array_rels) }, # defined in InstanceMethods as this is executed in represented context.
163
162
  :representer_exec => true,
164
- :getter => lambda { |*| links }
163
+ :getter => lambda { |*| links },
164
+ :setter => lambda { |val,*| self.links=(val) }
165
165
  }
166
166
  ]
167
167
  end
@@ -1,3 +1,3 @@
1
1
  module Roar
2
- VERSION = "0.11.16"
2
+ VERSION = "0.11.17"
3
3
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_runtime_dependency "representable", ">= 1.4.2"
22
+ s.add_runtime_dependency "representable", ">= 1.5.0"
23
23
 
24
24
  s.add_development_dependency "rake"
25
25
  s.add_development_dependency "test_xml", ">= 0.1.4"
@@ -20,6 +20,7 @@ class DecoratorTest < MiniTest::Spec
20
20
  end
21
21
 
22
22
  let (:model) { Object.new }
23
+ let (:model_with_links) { model.singleton_class.instance_eval { attr_accessor :links }; model }
23
24
 
24
25
  describe "JSON" do
25
26
  let (:decorator) { rpr_mod = rpr
@@ -32,10 +33,9 @@ class DecoratorTest < MiniTest::Spec
32
33
  end
33
34
 
34
35
  it "sets links on decorator" do
35
- decorator.new(model).from_hash("links"=>[{:rel=>:self, :href=>"http://self"}]).links.must_equal("self"=>link(:rel=>:self, :href=>"http://self"))
36
+ decorator.new(model).from_hash("links"=>[{:rel=>:self, :href=>"http://next"}]).links.must_equal("self"=>link(:rel=>:self, :href=>"http://next"))
36
37
  end
37
38
 
38
- let (:model_with_links) { model.singleton_class.instance_eval { attr_accessor :links }; model }
39
39
  it "does not set links on represented" do
40
40
  decorator.new(model_with_links).from_hash("links"=>[{:rel=>:self, :href=>"http://self"}])
41
41
  model_with_links.links.must_equal nil
@@ -49,8 +49,8 @@ class DecoratorTest < MiniTest::Spec
49
49
  end }
50
50
 
51
51
  it "propagates links to represented" do
52
- decorator.new(model_with_links).from_hash("links"=>[{:rel=>:self, :href=>"http://self"}])
53
- model_with_links.links[:self].must_equal(link(:rel=>:self, :href=>"http://self"))
52
+ decorator.new(model_with_links).from_hash("links"=>[{:rel=>:self, :href=>"http://next"}])
53
+ model_with_links.links[:self].must_equal(link(:rel=>:self, :href=>"http://next"))
54
54
  end
55
55
  end
56
56
  end
@@ -71,7 +71,7 @@ class DecoratorTest < MiniTest::Spec
71
71
  end
72
72
 
73
73
  it "sets links on decorator" do
74
- decorator.new(model).from_xml(%{<song><link rel="self" href="http://self"/></song>}).links.must_equal("self"=>link(:rel=>:self, :href=>"http://self"))
74
+ decorator.new(model).from_xml(%{<song><link rel="self" href="http://next"/></song>}).links.must_equal("self"=>link(:rel=>:self, :href=>"http://next"))
75
75
  end
76
76
  end
77
77
 
@@ -88,6 +88,23 @@ class DecoratorTest < MiniTest::Spec
88
88
  it "rendering links works" do
89
89
  decorator.new(model).to_hash.must_equal({"_links"=>{"self"=>{:href=>"http://self"}}})
90
90
  end
91
+
92
+ it "sets links on decorator" do
93
+ decorator.new(model).from_hash({"_links"=>{"self"=>{:href=>"http://next"}}}).links.must_equal("self"=>link(:rel=>:self, :href=>"http://next"))
94
+ end
95
+
96
+ describe "Decorator::HypermediaClient" do
97
+ let (:decorator) { rpr_mod = rpr
98
+ Class.new(Roar::Decorator) do
99
+ include rpr_mod
100
+ include Roar::Decorator::HypermediaConsumer
101
+ end }
102
+
103
+ it "propagates links to represented" do
104
+ decorator.new(model_with_links).from_hash("_links"=>{"self"=>{:href=>"http://self"}})
105
+ model_with_links.links[:self].must_equal(link(:rel=>:self, :href=>"http://self"))
106
+ end
107
+ end
91
108
  end
92
109
  end
93
110
  end
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.16
4
+ version: 0.11.17
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-05-03 00:00:00.000000000 Z
12
+ date: 2013-05-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: representable
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.4.2
21
+ version: 1.5.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.4.2
29
+ version: 1.5.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rake
32
32
  requirement: !ruby/object:Gem::Requirement