samedi 6 décembre 2014

Unable to access content in JSON parsing


Vote count:

0




I am new in RoR and I follow some tutorials like Rails for Zombie and I have a problem in an integration test function :



test 'returns user by id' do
get "/users", {id: @user.id}, { :authorization => token_header(@user.authentication_token)}
assert_equal 200, response.status
user_response = JSON.parse(response.body, symbolize_names: true)
Rails.logger.debug "TEST: #{user_response}"
assert_equal @user.email, user_response[:email]
end


And I get this error :



ListingUsersTest#test_returns_user_by_id:
TypeError: no implicit conversion of Symbol into Integer
test/integration/listing_users_test.rb:23:in `[]'
test/integration/listing_users_test.rb:23:in `block in <class:ListingUsersTest>'


I thought user_response was empty or nil or something like that but in my log :



TEST: [{:id=>428186149, :email=>"name.surname@host.com",...}]


So I am just wondering if I hadn't miss something with hash structure or.. I don't know.



asked 1 min ago







Unable to access content in JSON parsing

Aucun commentaire:

Enregistrer un commentaire