test/consume_test.rb in roar-rails-1.0.2 vs test/consume_test.rb in roar-rails-1.1.0
- old
+ new
@@ -128,17 +128,22 @@
end
class ConsumeJsonApiTest < ActionController::TestCase
include Roar::Rails::TestCase
- module MusicianRepresenter
- include Roar::JSON::JSONAPI
- type :singer
- property :name
- end
+ Band = Struct.new(:name, :id)
+ Singer = Struct.new(:name, :id)
+ Musician = Struct.new(:name, :id)
+ class MusicianRepresenter < Roar::Decorator
+ include Roar::JSON::JSONAPI.resource :singer
+ attributes do
+ property :name
+ end
+ end
+
class SingersController < ActionController::Base
include Roar::Rails::ControllerAdditions
represents :json_api, :entity => MusicianRepresenter
def consume_json_api
@@ -149,12 +154,12 @@
tests SingersController
test "#consume parses JSON-API document and updates the model" do
@request.env['CONTENT_TYPE'] = 'application/vnd.api+json'
- post :consume_json_api, "{\"singer\": {\"name\": \"Bumi\"}}"
+ post :consume_json_api, %({"data":{"attributes":{"name":"Bumi"},"type":"song"}})
- assert_equal %{#<struct Singer name="Bumi">}, @response.body
+ assert_equal %{#<struct ConsumeJsonApiTest::Singer name="Bumi", id=nil>}, @response.body
end
end
class ConsumeWithOptionsOverridingConfigurationTest < ActionController::TestCase
include Roar::Rails::TestCase