Commit 14626e7e authored by hellekin's avatar hellekin

Serialize maps and geographic information

parent b0ef03e5
......@@ -43,7 +43,7 @@ end
# zoom :integer default(13)
# created_at :datetime not null
# updated_at :datetime not null
# agent_id :integer
# agent_id :bigint(8)
# collection_id :bigint(8)
# position_id :bigint(8)
# taxonomy_id :bigint(8)
......
......@@ -119,7 +119,7 @@ end
# geometry :geometry({:srid= geometry, 0
# latitude :decimal(9, 7)
# longitude :decimal(10, 7)
# radius :bigint(8)
# radius :integer
# created_at :datetime not null
# updated_at :datetime not null
#
......
# frozen_string_literal: true
class SerializableLocation < JSONAPI::Serializable::Resource
type 'locations'
attribute :locatable_type
attribute :locatable_id
attribute :position_id
attribute :created_at
attribute :updated_at
belongs_to :locatable
belongs_to :position
meta do
meta_current
end
end
Fabricator(:location) do
position nil
locatable nil
position
locatable { Fabricate(:resource) }
end
# == Schema Information
......
Fabricator(:map) do
agent_id 1
taxonomy nil
position nil
collection nil
zoom 1
uuid ""
agent
taxonomy
position
collection
zoom 10
uuid { SecureRandom.uuid }
end
# == Schema Information
......@@ -16,7 +16,7 @@ end
# zoom :integer default(13)
# created_at :datetime not null
# updated_at :datetime not null
# agent_id :integer
# agent_id :bigint(8)
# collection_id :bigint(8)
# position_id :bigint(8)
# taxonomy_id :bigint(8)
......
......@@ -19,7 +19,7 @@ end
# geometry :geometry({:srid= geometry, 0
# latitude :decimal(9, 7)
# longitude :decimal(10, 7)
# radius :bigint(8)
# radius :integer
# created_at :datetime not null
# updated_at :datetime not null
#
......
require 'rails_helper'
RSpec.describe Location, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
let(:location) { Fabricate(:location) }
describe 'factory' do
it 'exists and is valid' do
expect(location).to be_valid
end
end
describe 'associations' do
it 'belongs to a position' do
expect(location).to belong_to(:position)
end
it 'belongs to a polymorphic locatable' do
expect(location).to belong_to(:locatable)
end
end
describe 'validations' do
it 'requires a locatable' do
location.locatable_type = nil
location.locatable_id = nil
expect(location).not_to be_valid
end
it 'requires a position' do
location.position_id = nil
expect(location).not_to be_valid
end
end
end
# == Schema Information
......
require 'rails_helper'
RSpec.describe Map, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
let(:map) { Fabricate(:map) }
describe 'factory' do
it 'exists and is valid' do
expect(map).to be_valid
end
end
describe 'associations' do
it 'belongs to an Agent' do
expect(map).to belong_to(:agent)
end
it 'belongs to a Collection' do
expect(map).to belong_to(:collection)
end
it 'belongs to a Position' do
expect(map).to belong_to(:position)
end
it 'belongs to a Taxonomy' do
expect(map).to belong_to(:taxonomy)
end
it 'has many ResourceCollections' do
expect(map).to have_many(:resource_collections)
end
it 'has many Resources' do
expect(map).to have_many(:resources)
end
end
describe 'validations' do
describe '#uuid' do
# This is taken care of by UUIDParameter
it 'is present' do
expect(map).to respond_to(:uuid)
end
end
describe '#zoom' do
it 'must be present' do
map.zoom = nil
expect(map).not_to be_valid
end
it 'must be between 1 and 18' do
map.zoom = 0
expect(map).not_to be_valid
map.zoom = 1
expect(map).to be_valid
map.zoom = 18
expect(map).to be_valid
map.zoom = 19
expect(map).not_to be_valid
end
end
end
describe '#center' do
it 'is the center of associated Position' do
expect(map.center).to eql([map.position.longitude.to_f, map.position.latitude.to_f])
end
end
end
# == Schema Information
......@@ -13,7 +70,7 @@ end
# zoom :integer default(13)
# created_at :datetime not null
# updated_at :datetime not null
# agent_id :integer
# agent_id :bigint(8)
# collection_id :bigint(8)
# position_id :bigint(8)
# taxonomy_id :bigint(8)
......
......@@ -143,7 +143,7 @@ end
# geometry :geometry({:srid= geometry, 0
# latitude :decimal(9, 7)
# longitude :decimal(10, 7)
# radius :bigint(8)
# radius :integer
# created_at :datetime not null
# updated_at :datetime not null
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment