models: require belong_to associations on geo_area

This commit is contained in:
Pierre de La Morinerie 2020-07-20 16:50:12 +02:00
parent aff2713032
commit afb1c33154
3 changed files with 7 additions and 5 deletions

View file

@ -12,7 +12,7 @@
# geo_reference_id :string # geo_reference_id :string
# #
class GeoArea < ApplicationRecord class GeoArea < ApplicationRecord
belongs_to :champ belongs_to :champ, optional: false
store :properties, accessors: [ store :properties, accessors: [
:description, :description,

View file

@ -1,5 +1,7 @@
FactoryBot.define do FactoryBot.define do
factory :geo_area do factory :geo_area do
association :champ
trait :cadastre do trait :cadastre do
source { GeoArea.sources.fetch(:cadastre) } source { GeoArea.sources.fetch(:cadastre) }
numero { '42' } numero { '42' }

View file

@ -1,24 +1,24 @@
RSpec.describe GeoArea, type: :model do RSpec.describe GeoArea, type: :model do
describe '#area' do describe '#area' do
let(:geo_area) { create(:geo_area, :polygon) } let(:geo_area) { build(:geo_area, :polygon) }
it { expect(geo_area.area).to eq(219.0) } it { expect(geo_area.area).to eq(219.0) }
end end
describe '#length' do describe '#length' do
let(:geo_area) { create(:geo_area, :line_string) } let(:geo_area) { build(:geo_area, :line_string) }
it { expect(geo_area.length).to eq(30.8) } it { expect(geo_area.length).to eq(30.8) }
end end
describe '#location' do describe '#location' do
let(:geo_area) { create(:geo_area, :point) } let(:geo_area) { build(:geo_area, :point) }
it { expect(geo_area.location).to eq("2°25'42\"N 46°32'19\"E") } it { expect(geo_area.location).to eq("2°25'42\"N 46°32'19\"E") }
end end
describe '#rgeo_geometry' do describe '#rgeo_geometry' do
let(:geo_area) { create(:geo_area, geometry: geometry) } let(:geo_area) { build(:geo_area, geometry: geometry) }
context 'invalid' do context 'invalid' do
let(:geometry) do let(:geometry) do