plexus / yaks

Ruby library for building hypermedia APIs
http://rubygems.org/gems/yaks
MIT License
236 stars 26 forks source link

More JSON-API updates #86

Closed janko closed 9 years ago

janko commented 9 years ago

What the heck, I really want to stay updated with JSON-API, and hopefully 1.0 will be released soon. The new change with the "attributes" key was totally justified, even though it wouldn't be necessary if there wasn't for "data" key in the first place.

I couldn't figure out how to get acceptance tests passing, regarding the links. I tried in the console, and the links are generated fine. But in acceptance tests the links are just eaten up, and there is always this "href", even though JSON-API doesn't set it anywhere (I removed it because JSON-API removed it). After a lot of debugging I found out that the JSON-API acceptance test doesn't even use Yaks::Mapper#call. What is going on there? :P

plexus commented 9 years ago

The "JSON round trip" test skips the mapper. It only tests JSON-API -> Yaks::Resource -> JSON-API

RSpec.shared_examples_for 'JSON round trip' do |yaks, format, name|
  let(:json) { load_json_fixture("#{name}.#{format}") }

  subject {
    resource = yaks.read(json, hooks: [[:skip, :parse]])
    yaks.call(resource, hooks: [[:skip, :map]], mapper: Struct.new(:context))
  }

  it { should deep_eql json }
end
plexus commented 9 years ago

Seems the JSON reader wasn't kept up to date with the writer's capabilities, and because our acceptance tests weren't functioning properly nobody noticed. I have some work in progress stuff in #88 to improve/fix the tests, after that's in I'll see if I can get your changes in and bring the Reader up to date with the Writer.

janko commented 9 years ago

Great that you're updating it. I can also just rebase to master after you merge it, and try to fix it in this branch, I know what I should write in the *.json fixtures.

TODO (for myself): I need to still add the test for case when there is no id, to test that Yaks doesn't add the id containing an empty string (Mutant will probably remind me about this missing test).

janko commented 9 years ago

Updated!

There are still a lot of issues in the 1.0 milestone for JSON-API, so I think I will completely finish the spec in Yaks when JSON-API reaches 1.0. But I think now it's really close enough :)

janko commented 9 years ago

Ok, fixed the mentioned things, now just to wait for the build to finish.

plexus commented 9 years ago

dancing