test/responder_test.rb in roar-rails-0.0.15 vs test/responder_test.rb in roar-rails-0.1.0

- old
+ new

@@ -1,9 +1,7 @@ require 'test_helper' -Singer = Struct.new(:name) - module SingersRepresenter include Roar::Representer::JSON collection :singers, :extend => SingerRepresenter def singers @@ -47,10 +45,12 @@ end end class UnconfiguredControllerTest < ResponderTest SingersRepresenter = ::SingersRepresenter + SingerRepresenter = ::SingerRepresenter + class SingersController < BaseController end tests SingersController @@ -67,11 +67,11 @@ get do singers = [Singer.new("Bumi"), Singer.new("Bjork"), Singer.new("Sinead")] respond_with singers end - assert_equal({:singers => singers.collect {|s| s.extend(SingerRepresenter).to_hash }}.to_json, @response.body) + @response.body.must_equal({:singers => singers.collect {|s| s.extend(SingerRepresenter).to_hash }}.to_json) end test "responder allows empty response bodies to pass through" do put do singer = Singer.new("Bumi") @@ -144,12 +144,15 @@ end class ControllerWithDecoratorTest < ResponderTest class SingerRepresentation < Representable::Decorator include Roar::Representer::JSON + include Roar::Representer::JSON::HAL property :name + + link(:self) { "http://singers/#{represented.name}" } end class MusicianController < BaseController represents :json, :entity => SingerRepresentation end @@ -160,10 +163,10 @@ get do singer = Singer.new("Bumi") respond_with singer end - assert_equal "{\"name\":\"Bumi\"}", @response.body + assert_equal %{{"name":"Bumi","_links":{"self":{"href":"http://singers/Bumi"}}}}, @response.body end test "parsing uses decorating representer" do # FIXME: move to controller_test. created_singer = nil