New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes broken test #1

Merged
merged 2 commits into from Feb 6, 2017

Conversation

Projects
None yet
1 participant
@leonelgalan
Owner

leonelgalan commented Jan 31, 2017

Without this code, response.body is {"name":"Name 1","description":"Description 1”}.
With it, it becomes what was expected: {“name":1,"description":"Description 1”}

The test won’t pass until name is not a string like the schema says.

Controller Action:

  def name_as_a_integer
    @profile = Profile.new(name: 'Name 1', description: 'Description 1') # From before_filter
    @profile.name = 1
    # index
    render json: @profile # index's method body 
  end

Test:

  it 'test_simple_json_pointers_that_doesnt_match' do
    get :name_as_a_integer

    expect do
      expect(response).to have_valid_schema.at_path 'simple_json_pointers.json'
    end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
  end

Profile is an ActiveModelSerializers::Model (0.10.4):

class Profile < ActiveModelSerializers::Model
  attr_accessor :name, :description
end
Fixes broken test
Without this code, `response.body` is `{"name":"Name
1","description":"Description 1”}`.
With it, it becomes what was expected:
`{“name":1,"description":"Description 1”}`

The test won’t pass until name is not a string like the schema says.
@leonelgalan

This comment has been minimized.

Owner

leonelgalan commented Feb 6, 2017

This should fix it, the error was my misunderstanding of how ActiveModelSerializers::Model works. Ultimately is its attributes what gets passed into the serializer and I was changing the instance variable @name, see inspect:

@profile.name = 1
puts @profile.inspect
#<Profile:0x007fb99f326738 @attributes={:name=>"Name 1", :description=>"Description 1"}, @errors=#<ActiveModel::Errors:0x007fb99f3266e8 @base=#<Profile:0x007fb99f326738 ...>, @messages={}, @details={}>, @name=1, @description="Description 1">

@leonelgalan leonelgalan merged commit 8f6ac02 into master Feb 6, 2017

3 checks passed

codeclimate/coverage 100%
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@leonelgalan leonelgalan deleted the fix/broken_test branch Feb 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment