dawarich/spec/serializers/api/point_serializer_spec.rb
2025-09-29 22:27:07 +02:00

31 lines
915 B
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::PointSerializer do
describe '#call' do
subject(:serializer) { described_class.new(point).call }
let(:point) { create(:point) }
let(:all_excluded) { Api::PointSerializer::EXCLUDED_ATTRIBUTES }
let(:expected_json) do
point.attributes.except(*all_excluded).tap do |attributes|
attributes['latitude'] = point.lat.to_s
attributes['longitude'] = point.lon.to_s
end
end
it 'returns JSON with correct attributes' do
expect(serializer.to_json).to eq(expected_json.to_json)
end
it 'does not include excluded attributes' do
expect(serializer).not_to include(*all_excluded)
end
it 'extracts coordinates from PostGIS geometry' do
expect(serializer['latitude']).to eq(point.lat.to_s)
expect(serializer['longitude']).to eq(point.lon.to_s)
end
end
end