diff options
| author | Xinhui | 2017-07-25 14:57:26 +0200 |
|---|---|---|
| committer | Xinhui | 2017-07-25 14:57:26 +0200 |
| commit | 5187a629316b207e8db8fd917ff7111b6712d8dd (patch) | |
| tree | cf869a811b6de0cba7dcf3b34086b21e3655b7db | |
| parent | 8f54a0e504f70e14e94dad810effdca5e85ee00c (diff) | |
| parent | 32a9d94028f9a21d3b7678a67d2b57b4b9ce057d (diff) | |
| download | chouette-core-5187a629316b207e8db8fd917ff7111b6712d8dd.tar.bz2 | |
Merge branch 'reflex_objectid'
| -rw-r--r-- | app/models/chouette/stif_reflex_objectid.rb | 18 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 13 | ||||
| -rw-r--r-- | app/models/concerns/stif_reflex_attributes_support.rb | 12 | ||||
| -rw-r--r-- | spec/models/chouette/stop_area_spec.rb | 19 |
4 files changed, 42 insertions, 20 deletions
diff --git a/app/models/chouette/stif_reflex_objectid.rb b/app/models/chouette/stif_reflex_objectid.rb new file mode 100644 index 000000000..c41a9325a --- /dev/null +++ b/app/models/chouette/stif_reflex_objectid.rb @@ -0,0 +1,18 @@ +class Chouette::StifReflexObjectid < String + + @@format = /^([A-Za-z_]+):([0-9A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ + cattr_reader :format + + def parts + match(format).try(:captures) + end + + def object_type + parts.try(:third) + end + + def local_id + parts.try(:fourth) + end + +end diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 4d98027d6..ac654206d 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -4,9 +4,12 @@ require 'geo_ruby' class Chouette::StopArea < Chouette::ActiveRecord # FIXME http://jira.codehaus.org/browse/JRUBY-6358 self.primary_key = "id" + include Geokit::Mappable + include StifReflexAttributesSupport include ProjectionFields include StopAreaRestrictions + include StopAreaReferentialSupport extend Enumerize enumerize :area_type, in: %i(zdep zder zdlp zdlr lda) @@ -14,9 +17,6 @@ class Chouette::StopArea < Chouette::ActiveRecord def self.model_name ActiveModel::Name.new self, Chouette, self.name.demodulize end - # Refs #1627 - # include DefaultAttributesSupport - include StopAreaReferentialSupport with_options dependent: :destroy do |assoc| assoc.has_many :stop_points @@ -57,13 +57,6 @@ class Chouette::StopArea < Chouette::ActiveRecord after_update :clean_invalid_access_links before_save :coordinates_to_lat_lng - # Refs #1627 - before_validation :prepare_auto_columns - def prepare_auto_columns - self.object_version = 1 - self.creator_id = 'chouette' - end - def combine_lat_lng if self.latitude.nil? || self.longitude.nil? "" diff --git a/app/models/concerns/stif_reflex_attributes_support.rb b/app/models/concerns/stif_reflex_attributes_support.rb new file mode 100644 index 000000000..074546ab1 --- /dev/null +++ b/app/models/concerns/stif_reflex_attributes_support.rb @@ -0,0 +1,12 @@ +module StifReflexAttributesSupport + extend ActiveSupport::Concern + + included do + validates_presence_of :objectid + end + + def objectid + Chouette::StifReflexObjectid.new read_attribute(:objectid).to_s + end + +end diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb index 1a2ff8ede..293ae5202 100644 --- a/spec/models/chouette/stop_area_spec.rb +++ b/spec/models/chouette/stop_area_spec.rb @@ -7,16 +7,15 @@ describe Chouette::StopArea, :type => :model do let!(:commercial_stop_point) { create :stop_area, :area_type => "lda" } let!(:stop_place) { create :stop_area, :area_type => "zdlp" } - # Refs #1627 - # describe '#objectid' do - # subject { super().objectid } - # it { is_expected.to be_kind_of(Chouette::ObjectId) } - # end - - it { is_expected.to belong_to(:stop_area_referential) } - it { is_expected.to validate_presence_of :name } - it { is_expected.to validate_numericality_of :latitude } - it { is_expected.to validate_numericality_of :longitude } + describe '#objectid' do + subject { super().objectid } + it { should be_kind_of(Chouette::StifReflexObjectid) } + end + + it { should belong_to(:stop_area_referential) } + it { should validate_presence_of :name } + it { should validate_numericality_of :latitude } + it { should validate_numericality_of :longitude } # describe ".latitude" do # it "should accept -90 value" do |
