From eaa9a662c32170e3b587c85d15c13c809731b9c3 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 25 Oct 2016 16:46:06 +0800 Subject: [PATCH] test for logged out maps GET api --- app/models/map.rb | 2 +- spec/api/v2/maps_api_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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 }