test for logged out maps GET api

This commit is contained in:
Devin Howard 2016-10-25 16:46:06 +08:00
parent 4875a8b0c4
commit eaa9a662c3
2 changed files with 11 additions and 1 deletions

View file

@ -87,7 +87,7 @@ class Map < ApplicationRecord
end
def starred_by_user?(user)
user&.stars&.where(map: self)&.exists?
user&.stars&.where(map: self)&.exists? || false # return false, not nil
end
def as_json(_options = {})

View file

@ -23,6 +23,16 @@ RSpec.describe 'maps API', type: :request do
expect(JSON.parse(response.body)['data']['id']).to eq map.id
end
describe 'logged out' do
it 'GET commons map' do
get "/api/v2/maps/#{map.id}"
expect(response).to have_http_status(:success)
expect(response).to match_json_schema(:map)
expect(JSON.parse(response.body)['data']['id']).to eq map.id
end
end
it 'POST /api/v2/maps' do
post '/api/v2/maps', params: { map: map.attributes, access_token: token }