aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlban Peignier2018-03-15 11:49:56 +0100
committerGitHub2018-03-15 11:49:56 +0100
commitc427ad507e6ba9083e96e330814d8095a6c817b7 (patch)
tree5de57f07f6fc1c4abfa1b037ef6db3a049733d7e
parent478ec46371279b304effae0a9934d1fac38918a3 (diff)
parent34e463ce7ae08a08c8106e68544ddf43cc378c8d (diff)
downloadchouette-core-c427ad507e6ba9083e96e330814d8095a6c817b7.tar.bz2
Merge pull request #377 from af83/6107-bind-stop_area_referential-and-workgroups
Refs 6106 & 6107. Binds LineReferentials and StopAreaReferentials to Workgroups
-rw-r--r--app/models/line_referential.rb1
-rw-r--r--app/models/stop_area_referential.rb1
-rw-r--r--app/models/workgroup.rb2
-rw-r--r--spec/models/workgroup_spec.rb2
4 files changed, 6 insertions, 0 deletions
diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb
index 15b2f6276..0d2ed39b1 100644
--- a/app/models/line_referential.rb
+++ b/app/models/line_referential.rb
@@ -10,6 +10,7 @@ class LineReferential < ActiveRecord::Base
has_many :networks, class_name: 'Chouette::Network'
has_many :line_referential_syncs, -> { order created_at: :desc }
has_many :workbenches
+ has_one :workgroup
def add_member(organisation, options = {})
attributes = options.merge organisation: organisation
diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb
index 9e9e02d80..a9d3cc9b1 100644
--- a/app/models/stop_area_referential.rb
+++ b/app/models/stop_area_referential.rb
@@ -8,6 +8,7 @@ class StopAreaReferential < ActiveRecord::Base
has_many :stop_areas, class_name: 'Chouette::StopArea'
has_many :stop_area_referential_syncs, -> {order created_at: :desc}
has_many :workbenches
+ has_one :workgroup
def add_member(organisation, options = {})
attributes = options.merge organisation: organisation
diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb
index 3af20ae23..708225a2a 100644
--- a/app/models/workgroup.rb
+++ b/app/models/workgroup.rb
@@ -11,6 +11,8 @@ class Workgroup < ActiveRecord::Base
validates_presence_of :line_referential_id
validates_presence_of :stop_area_referential_id
+ validates_uniqueness_of :stop_area_referential_id
+ validates_uniqueness_of :line_referential_id
has_many :custom_fields
diff --git a/spec/models/workgroup_spec.rb b/spec/models/workgroup_spec.rb
index ac8d3fc98..97fff3d86 100644
--- a/spec/models/workgroup_spec.rb
+++ b/spec/models/workgroup_spec.rb
@@ -6,6 +6,8 @@ RSpec.describe Workgroup, type: :model do
it{ should have_many(:workbenches) }
it{ should validate_uniqueness_of(:name) }
+ it{ should validate_uniqueness_of(:stop_area_referential_id) }
+ it{ should validate_uniqueness_of(:line_referential_id) }
it 'is not valid without a stop_area_referential' do
workgroup.stop_area_referential_id = nil