rails/activeresource

How to write specs to test if your schema and custom format work well together?

tolgap opened this issue · 1 comments

I'm trying to write specs to make sure that my custom (rather complex) format plays well with the schema definition I have in my models.

So here's how I wanted to ensure this in my model spec:

  1. Have a json fixture of my model that corresponds to an API call for that model
  2. Have a unit test for that model that parses the json fixture
  3. Ensure that the schema attributes are actually there in my expectations

I am having trouble with step 2. How do I tell ActiveResource to parse my model from the json fixture file, thus ensuring it uses the formatter internally?

I would like this to work:

RSpec.describe Offer do
  subject(:offer) { described_class.from_json(file_fixture('offer/single.json').read) }

  it 'has an external API id' do
    expect(offer.id).to be(45)
  end
end

So .from_json is not an actual method on an ActiveResource model. But what can I use that will transform a piece of JSON into my Resource?

Please use StackOverflow for questions/help, where a wider community will be able to help you. We reserve the issues tracker for issues only.