diff --git a/app/models/map.rb b/app/models/map.rb index 285185cb..86a89a24 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -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 = {}) diff --git a/spec/api/v2/maps_api_spec.rb b/spec/api/v2/maps_api_spec.rb index abed255d..8c9e87f6 100644 --- a/spec/api/v2/maps_api_spec.rb +++ b/spec/api/v2/maps_api_spec.rb @@ -22,6 +22,16 @@ RSpec.describe 'maps API', type: :request do expect(response).to match_json_schema(:map) 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 }