mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-12 02:01:39 -05:00
Fix whole bunch of specs
This commit is contained in:
parent
4fa3c35fb8
commit
fc01cda5c6
13 changed files with 61 additions and 31 deletions
|
|
@ -50,11 +50,11 @@ class Point < ApplicationRecord
|
|||
end
|
||||
|
||||
def lon
|
||||
lonlat.x
|
||||
lonlat.x.to_s
|
||||
end
|
||||
|
||||
def lat
|
||||
lonlat.y
|
||||
lonlat.y.to_s
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ class Api::SlimPointSerializer
|
|||
def call
|
||||
{
|
||||
id: point.id,
|
||||
latitude: point.lat,
|
||||
longitude: point.lon,
|
||||
latitude: point.lat.to_s,
|
||||
longitude: point.lon.to_s,
|
||||
timestamp: point.timestamp
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class PointSerializer
|
||||
EXCLUDED_ATTRIBUTES = %w[created_at updated_at visit_id id import_id user_id raw_data lonlat].freeze
|
||||
EXCLUDED_ATTRIBUTES = %w[
|
||||
created_at updated_at visit_id id import_id user_id raw_data lonlat
|
||||
reverse_geocoded_at
|
||||
].freeze
|
||||
|
||||
def initialize(point)
|
||||
@point = point
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ class Points::GpxSerializer
|
|||
|
||||
points.each do |point|
|
||||
track_segment.points << GPX::TrackPoint.new(
|
||||
lat: point.latitude.to_f,
|
||||
lon: point.longitude.to_f,
|
||||
lat: point.lat.to_f,
|
||||
lon: point.lon.to_f,
|
||||
elevation: point.altitude.to_f,
|
||||
time: point.recorded_at
|
||||
)
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -9,8 +9,6 @@ RSpec.describe Point, type: :model do
|
|||
end
|
||||
|
||||
describe 'validations' do
|
||||
it { is_expected.to validate_presence_of(:latitude) }
|
||||
it { is_expected.to validate_presence_of(:longitude) }
|
||||
it { is_expected.to validate_presence_of(:timestamp) }
|
||||
it { is_expected.to validate_presence_of(:lonlat) }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ RSpec.describe Stat, type: :model do
|
|||
create(:point, user:, lonlat: 'POINT(2 2)', timestamp: DateTime.new(year, 1, 1, 2))
|
||||
end
|
||||
|
||||
before { expected_distance[0][1] = 157.23 }
|
||||
before { expected_distance[0][1] = 156.88 }
|
||||
|
||||
it 'returns distance by day' do
|
||||
expect(subject).to eq(expected_distance)
|
||||
|
|
|
|||
|
|
@ -6,8 +6,15 @@ RSpec.describe Api::SlimPointSerializer do
|
|||
describe '#call' do
|
||||
subject(:serializer) { described_class.new(point).call }
|
||||
|
||||
let(:point) { create(:point) }
|
||||
let(:expected_json) { point.attributes.slice('id', 'latitude', 'longitude', 'timestamp') }
|
||||
let!(:point) { create(:point, :with_known_location) }
|
||||
let(:expected_json) do
|
||||
{
|
||||
id: point.id,
|
||||
latitude: point.lat,
|
||||
longitude: point.lon,
|
||||
timestamp: point.timestamp
|
||||
}
|
||||
end
|
||||
|
||||
it 'returns JSON with correct attributes' do
|
||||
expect(serializer.to_json).to eq(expected_json.to_json)
|
||||
|
|
|
|||
|
|
@ -8,15 +8,37 @@ RSpec.describe PointSerializer do
|
|||
|
||||
let(:point) { create(:point) }
|
||||
let(:expected_json) do
|
||||
point.attributes.except(*PointSerializer::EXCLUDED_ATTRIBUTES)
|
||||
{
|
||||
'battery_status' => point.battery_status,
|
||||
'ping' => point.ping,
|
||||
'battery' => point.battery,
|
||||
'tracker_id' => point.tracker_id,
|
||||
'topic' => point.topic,
|
||||
'altitude' => point.altitude,
|
||||
'longitude' => point.lon,
|
||||
'velocity' => point.velocity,
|
||||
'trigger' => point.trigger,
|
||||
'bssid' => point.bssid,
|
||||
'ssid' => point.ssid,
|
||||
'connection' => point.connection,
|
||||
'vertical_accuracy' => point.vertical_accuracy,
|
||||
'accuracy' => point.accuracy,
|
||||
'timestamp' => point.timestamp,
|
||||
'latitude' => point.lat,
|
||||
'mode' => point.mode,
|
||||
'inrids' => point.inrids,
|
||||
'in_regions' => point.in_regions,
|
||||
'city' => point.city,
|
||||
'country' => point.country,
|
||||
'geodata' => point.geodata,
|
||||
'course' => point.course,
|
||||
'course_accuracy' => point.course_accuracy,
|
||||
'external_track_id' => point.external_track_id
|
||||
}
|
||||
end
|
||||
|
||||
it 'returns JSON' do
|
||||
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(*PointSerializer::EXCLUDED_ATTRIBUTES)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ RSpec.describe Points::GpxSerializer do
|
|||
serializer.tracks[0].points.each_with_index do |track_point, index|
|
||||
point = points[index]
|
||||
|
||||
expect(track_point.lat).to eq(point.lat)
|
||||
expect(track_point.lon).to eq(point.lon)
|
||||
expect(track_point.lat.to_s).to eq(point.lat)
|
||||
expect(track_point.lon.to_s).to eq(point.lon)
|
||||
expect(track_point.time).to eq(point.recorded_at)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,12 +35,12 @@ RSpec.describe GoogleMaps::PhoneTakeoutParser do
|
|||
it 'creates points with correct data' do
|
||||
parser
|
||||
|
||||
expect(Point.all[6].lat).to eq(27.696576)
|
||||
expect(Point.all[6].lon).to eq(-97.376949)
|
||||
expect(Point.all[6].lat).to eq('27.696576')
|
||||
expect(Point.all[6].lon).to eq('-97.376949')
|
||||
expect(Point.all[6].timestamp).to eq(1_693_180_140)
|
||||
|
||||
expect(Point.last.lat).to eq(27.709617)
|
||||
expect(Point.last.lon).to eq(-97.375988)
|
||||
expect(Point.last.lat).to eq('27.709617')
|
||||
expect(Point.last.lon).to eq('-97.375988')
|
||||
expect(Point.last.timestamp).to eq(1_693_180_320)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ RSpec.describe Gpx::TrackParser do
|
|||
it 'creates points with correct data' do
|
||||
parser
|
||||
|
||||
expect(Point.first.lat).to eq(37.1722103)
|
||||
expect(Point.first.lon).to eq(-3.55468)
|
||||
expect(Point.first.lat).to eq('37.1722103')
|
||||
expect(Point.first.lon).to eq('-3.55468')
|
||||
expect(Point.first.altitude).to eq(1066)
|
||||
expect(Point.first.timestamp).to eq(Time.zone.parse('2024-04-21T10:19:55Z').to_i)
|
||||
expect(Point.first.velocity).to eq('2.9')
|
||||
|
|
@ -67,8 +67,8 @@ RSpec.describe Gpx::TrackParser do
|
|||
it 'creates points with correct data' do
|
||||
parser
|
||||
|
||||
expect(Point.first.lat).to eq(10.758321212464024)
|
||||
expect(Point.first.lon).to eq(106.64234449272531)
|
||||
expect(Point.first.lat).to eq('10.758321212464024')
|
||||
expect(Point.first.lon).to eq('106.64234449272531')
|
||||
expect(Point.first.altitude).to eq(17)
|
||||
expect(Point.first.timestamp).to eq(1_730_626_211)
|
||||
expect(Point.first.velocity).to eq('2.8')
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ RSpec.describe Visits::Prepare do
|
|||
date: static_time.to_date.to_s,
|
||||
visits: [
|
||||
{
|
||||
latitude: 0.0,
|
||||
longitude: 0.0,
|
||||
latitude: '0.0',
|
||||
longitude: '0.0',
|
||||
radius: 10,
|
||||
points:,
|
||||
duration: 105,
|
||||
|
|
|
|||
Loading…
Reference in a new issue