Skip to content

Commit

Permalink
remove Link#== from test_helper as it fucks up representable as monke…
Browse files Browse the repository at this point in the history
…y-patching sucks.
  • Loading branch information
apotonick committed Apr 15, 2014
1 parent 59127d5 commit 049da2d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 23 deletions.
4 changes: 2 additions & 2 deletions test/collection_json_test.rb
Expand Up @@ -108,12 +108,12 @@ class CollectionJsonTest < MiniTest::Spec
song = subject.items.first
song.title.must_equal "scarifice"
song.length.must_equal 43
song.links.must_equal("download" => link({:rel=>:download, :href=>"//songs/scarifice.mp3"}), "stats" => link({:rel=>:stats, :href=>"//songs/scarifice/stats"}))
song.links.must_equal("download" => link({:rel=>"download", :href=>"//songs/scarifice.mp3"}), "stats" => link({:rel=>"stats", :href=>"//songs/scarifice/stats"}))
song.href.must_equal link(:href => "//songs/scarifice")
end

it "provides #links" do
subject.links.must_equal({"feed" => link(:rel => :feed, :href => "//songs/feed")})
subject.links.must_equal({"feed" => link(:rel => "feed", :href => "//songs/feed")})
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/decorator_test.rb
Expand Up @@ -78,7 +78,7 @@ class SongRepresentation < Roar::Decorator

it "sets links on decorator" do
decorator.from_xml(%{<song><link rel="self" href="http://next"/></song>})
decorator.links.must_equal("self"=>link(:rel=>:self, :href=>"http://next"))
decorator.links.must_equal("self"=>link(:rel=>"self", :href=>"http://next"))
end
end

Expand All @@ -100,7 +100,7 @@ class SongRepresentation < Roar::Decorator

it "sets links on decorator" do
decorator.from_hash({"_links"=>{"self"=>{:href=>"http://next"}}})
decorator.links.must_equal("self"=>link(:rel=>:self, :href=>"http://next"))
decorator.links.must_equal("self"=>link(:rel=>"self", :href=>"http://next"))
end

describe "Decorator::HypermediaClient" do
Expand All @@ -112,7 +112,7 @@ class SongRepresentation < Roar::Decorator

it "propagates links to represented" do
decorator.new(model_with_links).from_hash("_links"=>{"self"=>{:href=>"http://self"}})
model_with_links.links[:self].must_equal(link(:rel=>:self, :href=>"http://self"))
model_with_links.links[:self].must_equal(link(:rel=>"self", :href=>"http://self"))
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/hal_json_test.rb
Expand Up @@ -24,17 +24,17 @@ class HalJsonTest < MiniTest::Spec
describe "parsing" do
it "parses link array" do # TODO: remove me.
obj = subject.from_json("{\"_links\":{\"self\":[{\"lang\":\"en\",\"href\":\"http://en.hit\"},{\"lang\":\"de\",\"href\":\"http://de.hit\"}]}}")
obj.links.must_equal "self" => [link(:rel => :self, :href => "http://en.hit", :lang => :en), link(:rel => :self, :href => "http://de.hit", :lang => :de)]
obj.links.must_equal "self" => [link("rel" => "self", "href" => "http://en.hit", "lang" => "en"), link("rel" => "self", "href" => "http://de.hit", "lang" => "de")]
end

it "parses single links" do # TODO: remove me.
obj = subject.from_json("{\"_links\":{\"next\":{\"href\":\"http://next\"}}}")
obj.links.must_equal "next" => link(:rel => :next, :href => "http://next")
obj.links.must_equal "next" => link("rel" => "next", "href" => "http://next")
end

it "parses link and link array" do
obj = subject.from_json("{\"_links\":{\"next\":{\"href\":\"http://next\"}, \"self\":[{\"lang\":\"en\",\"href\":\"http://en.hit\"},{\"lang\":\"de\",\"href\":\"http://de.hit\"}]}}")
obj.links.must_equal "next" => link(:rel => :next, :href => "http://next"), "self" => [link(:rel => :self, :href => "http://en.hit", :lang => :en), link(:rel => :self, :href => "http://de.hit", :lang => :de)]
obj.links.must_equal "next" => link("rel" => "next", "href" => "http://next"), "self" => [link("rel" => "self", "href" => "http://en.hit", "lang" => "en"), link("rel" => "self", "href" => "http://de.hit", "lang" => "de")]
end

it "parses empty link array" do
Expand Down Expand Up @@ -73,7 +73,7 @@ class HalJsonTest < MiniTest::Spec
describe "#prepare_links!" do
it "should map link arrays correctly" do
subject.send :prepare_links!
subject.links.must_equal "self" => [link(:rel => :self, :href => "http://en.hit", :lang => "en"),link(:rel => :self, :href => "http://de.hit", :lang => "de")], "next" => link(:href => "http://next", :rel => :next)
subject.links.must_equal "self" => [link("rel" => :self, "href" => "http://en.hit", "lang" => "en"),link("rel" => :self, "href" => "http://de.hit", "lang" => "de")], "next" => link("href" => "http://next", "rel" => :next)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/hal_links_test.rb
Expand Up @@ -24,7 +24,7 @@ class HalLinkTest < MiniTest::Spec

describe "#from_json" do
it "uses 'links' key" do
subject.from_json("{\"links\":{\"self\":{\"href\":\"//lifer\"}}}").links.values.must_equal [link(:href => "//lifer", :rel => :self)]
subject.from_json("{\"links\":{\"self\":{\"href\":\"//lifer\"}}}").links.values.must_equal [link("href" => "//lifer", "rel" => "self")]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/hypermedia_test.rb
Expand Up @@ -56,7 +56,7 @@ module Foo
describe "#from_json" do
it "parses" do
subject.from_json "{\"links\":[{\"rel\":\"self\",\"href\":\"//self\"}]}"
subject.links.must_equal({"self" => link(:rel => :self, :href => "//self")})
subject.links.must_equal({"self" => link("rel" => "self", "href" => "//self")})
end
end

Expand Down
12 changes: 0 additions & 12 deletions test/test_helper.rb
Expand Up @@ -51,15 +51,3 @@ def self.verbs(&block)
%w(get post put delete).each(&block)
end
end

Roar::Representer::Feature::Hypermedia::Hyperlink.class_eval do
def ==(other)
stringify_hash(table) == stringify_hash(other.table)
end

def stringify_hash(hash)
hash.collect do |k,v|
[k.to_s, v.to_s]
end.sort
end
end

0 comments on commit 049da2d

Please sign in to comment.