test/controllers/controller_test.rb in jsonapi-resources-0.6.0 vs test/controllers/controller_test.rb in jsonapi-resources-0.6.1

- old
+ new

@@ -3067,19 +3067,19 @@ assert_hash_equals json_response, { data: [ {id:"A4D3", type:"craters", - links:{self: "http://test.host/craters/A4D3"}, + links:{self: "http://test.host/api/v1/craters/A4D3"}, attributes:{code: "A4D3", description: "Small crater"}, - relationships:{moon: {links: {self: "http://test.host/craters/A4D3/relationships/moon", related: "http://test.host/craters/A4D3/moon"}}} + relationships:{moon: {links: {self: "http://test.host/api/v1/craters/A4D3/relationships/moon", related: "http://test.host/api/v1/craters/A4D3/moon"}}} }, {id: "S56D", type: "craters", - links:{self: "http://test.host/craters/S56D"}, + links:{self: "http://test.host/api/v1/craters/S56D"}, attributes:{code: "S56D", description: "Very large crater"}, - relationships:{moon: {links: {self: "http://test.host/craters/S56D/relationships/moon", related: "http://test.host/craters/S56D/moon"}}} + relationships:{moon: {links: {self: "http://test.host/api/v1/craters/S56D/relationships/moon", related: "http://test.host/api/v1/craters/S56D/moon"}}} } ] } end @@ -3089,5 +3089,73 @@ assert_response :success assert_equal "moons", json_response['data']['type'] assert_equal "1", json_response['data']['id'] end end + +class CarsControllerTest < ActionController::TestCase + def setup + JSONAPI.configuration.json_key_format = :camelized_key + end + + def test_create_sti + set_content_type_header! + post :create, + { + data: { + type: 'cars', + attributes: { + make: 'Toyota', + model: 'Tercel', + serialNumber: 'asasdsdadsa13544235', + driveLayout: 'FWD' + } + } + } + + assert_response :created + assert json_response['data'].is_a?(Hash) + assert_equal 'cars', json_response['data']['type'] + assert_equal 'Toyota', json_response['data']['attributes']['make'] + assert_equal 'FWD', json_response['data']['attributes']['driveLayout'] + end +end + +class VehiclesControllerTest < ActionController::TestCase + def setup + JSONAPI.configuration.json_key_format = :camelized_key + end + + def test_immutable_create_not_supported + set_content_type_header! + + assert_raises ActionController::UrlGenerationError do + post :create, + { + data: { + type: 'cars', + attributes: { + make: 'Toyota', + model: 'Corrola', + serialNumber: 'dsvffsfv', + driveLayout: 'FWD' + } + } + } + end + end + + def test_immutable_update_not_supported + set_content_type_header! + + assert_raises ActionController::UrlGenerationError do + patch :update, + data: { + id: '1', + type: 'cars', + attributes: { + make: 'Toyota', + } + } + end + end +end \ No newline at end of file