Permalink
Browse files

XML::HyperlinkRepresenter now respects all link params.

  • Loading branch information...
1 parent f20aa08 commit 594e0fe2ef9753e176b7664a84077b7374b63efb @apotonick apotonick committed Mar 22, 2012
Showing with 33 additions and 13 deletions.
  1. +9 −0 CHANGES.markdown
  2. +3 −2 lib/roar/representer/xml.rb
  3. +11 −4 test/json_representer_test.rb
  4. +10 −7 test/xml_representer_test.rb
View
@@ -1,3 +1,12 @@
+## 0.10.0
+
+* Requiring representable-0.1.3.
+* Added JSON-HAL support.
+* Links are no longer rendered when `href` is `nil` or `false`.
+* `Representer.link` class method now accepts either the `rel` value, only, or a hash of link attributes (defined in `Hypermedia::Hyperlink.params`), like `link :rel => :self, :title => "You're good" do..`
+* API CHANGE: `Representer#links` no longer returns the `href` value but the link object. Use it like `object.links[:self].href` to retrieve the URL.
+* `#from_json` won't throw an exception anymore when passed an empty json document.
+
## 0.9.2
* Using representable-1.1.
@@ -52,8 +52,9 @@ module HyperlinkRepresenter
self.representation_wrap = :link
- property :rel, :from => "rel", :attribute => true
- property :href, :from => "href", :attribute => true
+ Feature::Hypermedia::Hyperlink.params.each do |attr|
+ property attr, :attribute => true
+ end
end
end
end
@@ -74,16 +74,23 @@ class Order
class JsonHyperlinkRepresenterTest
describe "API" do
before do
- # TODO: ehm... hello?
- @l = Roar::Representer::Feature::Hypermedia::Hyperlink.new.extend(Roar::Representer::JSON::HyperlinkRepresenter).from_json({:rel => :self, :href => "http://roar.apotomo.de"}.to_json)
+ @link = Roar::Representer::Feature::Hypermedia::Hyperlink.new.extend(Roar::Representer::JSON::HyperlinkRepresenter).from_json({:rel => :self, :href => "http://roar.apotomo.de", :media => "web"}.to_json)
end
it "responds to #rel" do
- assert_equal "self", @l.rel
+ assert_equal "self", @link.rel
end
it "responds to #href" do
- assert_equal "http://roar.apotomo.de", @l.href
+ assert_equal "http://roar.apotomo.de", @link.href
+ end
+
+ it "responds to #media" do
+ assert_equal "web", @link.media
+ end
+
+ it "responds to #to_json" do
+ assert_equal "{\"rel\":\"self\",\"href\":\"http://roar.apotomo.de\",\"media\":\"web\"}", @link.to_json
end
end
end
@@ -186,20 +186,23 @@ class Order
class XmlHyperlinkRepresenterTest < MiniTest::Spec
describe "API" do
before do
- @l = Roar::Representer::Feature::Hypermedia::Hyperlink.new.extend(Roar::Representer::XML::HyperlinkRepresenter).from_xml(%{<link rel="self" href="http://roar.apotomo.de"/>})
+ @link = Roar::Representer::Feature::Hypermedia::Hyperlink.new.extend(Roar::Representer::XML::HyperlinkRepresenter).from_xml(%{<link rel="self" href="http://roar.apotomo.de" media="web"/>})
end
- it "responds to #to_xml" do
- assert_xml_equal %{<link rel=\"self\" href=\"http://roar.apotomo.de\"/>}, @l.to_xml
+ it "responds to #rel" do
+ assert_equal "self", @link.rel
end
+ it "responds to #href" do
+ assert_equal "http://roar.apotomo.de", @link.href
+ end
- it "responds to #rel" do
- assert_equal "self", @l.rel
+ it "responds to #media" do
+ assert_equal "web", @link.media
end
- it "responds to #href" do
- assert_equal "http://roar.apotomo.de", @l.href
+ it "responds to #to_xml" do
+ assert_xml_equal %{<link rel=\"self\" href=\"http://roar.apotomo.de\" media="web"/>}, @link.to_xml
end
end
end

0 comments on commit 594e0fe

Please sign in to comment.