diff options
| author | Xinhui | 2016-10-18 15:34:47 +0200 |
|---|---|---|
| committer | Xinhui | 2016-10-18 15:34:53 +0200 |
| commit | f9814e27bcaabbf69c66f43989236e40a334e0c1 (patch) | |
| tree | 7d16d0b33fb83d732b918fbd08d29c839ddb5478 | |
| parent | a9aa01e2271fda736e13d1a10bd62f45e1508330 (diff) | |
| download | chouette-core-f9814e27bcaabbf69c66f43989236e40a334e0c1.tar.bz2 | |
Relation Workbench - LineReferential & StopAreaReferential
Refs #1784
| -rw-r--r-- | app/models/line_referential.rb | 2 | ||||
| -rw-r--r-- | app/models/referential.rb | 15 | ||||
| -rw-r--r-- | app/models/stop_area_referential.rb | 1 | ||||
| -rw-r--r-- | app/models/user.rb | 1 | ||||
| -rw-r--r-- | app/models/workbench.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20161018121633_add_line_referential_to_workbenches.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20161018121647_add_stop_area_referential_to_workbenches.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 6 | ||||
| -rw-r--r-- | db/seeds.rb | 19 | ||||
| -rw-r--r-- | spec/factories/chouette_2_factories.rb | 4 | ||||
| -rw-r--r-- | spec/factories/workbenches.rb | 2 | ||||
| -rw-r--r-- | spec/models/line_referential_spec.rb | 1 | ||||
| -rw-r--r-- | spec/models/stop_area_referential_spec.rb | 1 | ||||
| -rw-r--r-- | spec/models/workbench_spec.rb | 3 | ||||
| -rw-r--r-- | spec/support/referential.rb | 6 |
15 files changed, 58 insertions, 15 deletions
diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index e4801a61e..7d3b638cb 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -6,8 +6,8 @@ class LineReferential < ActiveRecord::Base has_many :group_of_lines, class_name: 'Chouette::GroupOfLine' has_many :companies, class_name: 'Chouette::Company' has_many :networks, class_name: 'Chouette::Network' - has_many :line_referential_syncs, -> { order created_at: :desc} + has_many :workbenches def add_member(organisation, options = {}) attributes = options.merge organisation: organisation diff --git a/app/models/referential.rb b/app/models/referential.rb index dedf2aabd..98c60f549 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -8,6 +8,8 @@ class Referential < ActiveRecord::Base validates_presence_of :time_zone validates_presence_of :upper_corner validates_presence_of :lower_corner + validates_presence_of :workbench + validates_uniqueness_of :slug validates_uniqueness_of :name validates_format_of :slug, :with => %r{\A[a-z][0-9a-z_]+\Z} @@ -26,16 +28,15 @@ class Referential < ActiveRecord::Base validates_presence_of :organisation belongs_to :line_referential - # validates_presence_of :line_referential + validates_presence_of :line_referential has_many :lines, through: :line_referential has_many :companies, through: :line_referential has_many :group_of_lines, through: :line_referential has_many :networks, through: :line_referential belongs_to :stop_area_referential - # validates_presence_of :stop_area_referential + validates_presence_of :stop_area_referential has_many :stop_areas, through: :stop_area_referential - belongs_to :workbench def slug_excluded_values @@ -149,6 +150,14 @@ class Referential < ActiveRecord::Base Apartment::Tenant.create slug end + before_validation :assign_line_and_stop_area_referential, :on => :create + def assign_line_and_stop_area_referential + if workbench + self.line_referential = workbench.line_referential + self.stop_area_referential = workbench.stop_area_referential + end + end + before_destroy :destroy_schema def destroy_schema Apartment::Tenant.drop slug diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb index 5b84e6178..dd206f9e9 100644 --- a/app/models/stop_area_referential.rb +++ b/app/models/stop_area_referential.rb @@ -4,6 +4,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 def add_member(organisation, options = {}) attributes = options.merge organisation: organisation diff --git a/app/models/user.rb b/app/models/user.rb index 27adb3b34..8f0c32c54 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -32,7 +32,6 @@ class User < ActiveRecord::Base extra = extra_attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} self.name = extra[:full_name] self.email = extra[:email] - self.username = extra[:username] self.organisation = Organisation.find_or_create_by(code: extra[:organisation_code]).tap do |org| org.name = extra[:organisation_name] diff --git a/app/models/workbench.rb b/app/models/workbench.rb index e4efb6bd9..3525fe55e 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -1,5 +1,7 @@ class Workbench < ActiveRecord::Base belongs_to :organisation + belongs_to :line_referential + belongs_to :stop_area_referential validates :name, presence: true validates :organisation, presence: true diff --git a/db/migrate/20161018121633_add_line_referential_to_workbenches.rb b/db/migrate/20161018121633_add_line_referential_to_workbenches.rb new file mode 100644 index 000000000..2cffc4c1a --- /dev/null +++ b/db/migrate/20161018121633_add_line_referential_to_workbenches.rb @@ -0,0 +1,5 @@ +class AddLineReferentialToWorkbenches < ActiveRecord::Migration + def change + add_reference :workbenches, :line_referential, index: true + end +end diff --git a/db/migrate/20161018121647_add_stop_area_referential_to_workbenches.rb b/db/migrate/20161018121647_add_stop_area_referential_to_workbenches.rb new file mode 100644 index 000000000..5c368dd57 --- /dev/null +++ b/db/migrate/20161018121647_add_stop_area_referential_to_workbenches.rb @@ -0,0 +1,5 @@ +class AddStopAreaReferentialToWorkbenches < ActiveRecord::Migration + def change + add_reference :workbenches, :stop_area_referential, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 9b2c3f1b2..63614f440 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161017091304) do +ActiveRecord::Schema.define(version: 20161018121647) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -683,9 +683,13 @@ ActiveRecord::Schema.define(version: 20161017091304) do t.integer "organisation_id" t.datetime "created_at" t.datetime "updated_at" + t.integer "line_referential_id" + t.integer "stop_area_referential_id" end + add_index "workbenches", ["line_referential_id"], :name => "index_workbenches_on_line_referential_id" add_index "workbenches", ["organisation_id"], :name => "index_workbenches_on_organisation_id" + add_index "workbenches", ["stop_area_referential_id"], :name => "index_workbenches_on_stop_area_referential_id" Foreigner.load add_foreign_key "access_links", "access_points", name: "aclk_acpt_fkey", dependent: :delete diff --git a/db/seeds.rb b/db/seeds.rb index dae717966..0d7748f9c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -17,7 +17,6 @@ stif.users.find_or_create_by!(username: "admin") do |user| user.name = "STIF Administrateur" end -Workbench.find_or_create_by(name: "Gestion de l'offre", organisation: stif) operator = Organisation.find_or_create_by!(code: 'transporteur-a') do |organisation| organisation.name = "Transporteur A" @@ -43,6 +42,12 @@ line_referential = LineReferential.find_or_create_by(name: "CodifLigne") do |ref referential.add_member operator end +Workbench.find_or_create_by(name: "Gestion de l'offre", organisation: stif) do |workbench| + workbench.line_referential = line_referential + workbench.stop_area_referential = stop_area_referential +end + + LineReferentialSync.find_or_create_by(line_referential: line_referential) StopAreaReferentialSync.find_or_create_by(stop_area_referential: stop_area_referential) @@ -52,16 +57,16 @@ StopAreaReferentialSync.find_or_create_by(stop_area_referential: stop_area_refer end end - -workbench = Workbench.find_or_create_by(name: "Gestion de l'offre", organisation: operator) +workbench = Workbench.find_or_create_by(name: "Gestion de l'offre", organisation: operator) do |workbench| + workbench.line_referential = line_referential + workbench.stop_area_referential = stop_area_referential +end [["parissudest201604", "Paris Sud-Est Avril 2016"], ["parissudest201605", "Paris Sud-Est Mai 2016"]].each do |slug, name| operator.referentials.find_or_create_by!(slug: slug) do |referential| - referential.name = name - referential.prefix = slug + referential.name = name + referential.prefix = slug referential.workbench = workbench - referential.line_referential = line_referential - referential.stop_area_referential = stop_area_referential end end diff --git a/spec/factories/chouette_2_factories.rb b/spec/factories/chouette_2_factories.rb index b88b0d773..e8eba13e6 100644 --- a/spec/factories/chouette_2_factories.rb +++ b/spec/factories/chouette_2_factories.rb @@ -10,7 +10,9 @@ FactoryGirl.define do sequence(:slug) { |n| "test_#{n}" } sequence(:prefix) { |n| "test_#{n}" } association :organisation - + association :workbench + association :line_referential + association :stop_area_referential time_zone "Europe/Paris" end diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb index 16c673655..f51e7d94c 100644 --- a/spec/factories/workbenches.rb +++ b/spec/factories/workbenches.rb @@ -3,5 +3,7 @@ FactoryGirl.define do sequence(:name) { |n| "Workbench #{n}" } association :organisation, :factory => :organisation + association :line_referential + association :stop_area_referential end end diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb index 8b06f07ad..02838a4a7 100644 --- a/spec/models/line_referential_spec.rb +++ b/spec/models/line_referential_spec.rb @@ -7,5 +7,6 @@ RSpec.describe LineReferential, :type => :model do it { should validate_presence_of(:name) } it { is_expected.to have_many(:line_referential_syncs) } + it { is_expected.to have_many(:workbenches) } it { should validate_presence_of(:sync_interval) } end diff --git a/spec/models/stop_area_referential_spec.rb b/spec/models/stop_area_referential_spec.rb index 87b99b18b..271badff8 100644 --- a/spec/models/stop_area_referential_spec.rb +++ b/spec/models/stop_area_referential_spec.rb @@ -6,4 +6,5 @@ RSpec.describe StopAreaReferential, :type => :model do end it { is_expected.to have_many(:stop_area_referential_syncs) } + it { is_expected.to have_many(:workbenches) } end diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb index bafe95e75..023a65ea2 100644 --- a/spec/models/workbench_spec.rb +++ b/spec/models/workbench_spec.rb @@ -9,4 +9,7 @@ RSpec.describe Workbench, :type => :model do it { should validate_presence_of(:name) } it { should validate_presence_of(:organisation) } + it { should belong_to(:organisation) } + it { should belong_to(:line_referential) } + it { should belong_to(:stop_area_referential) } end diff --git a/spec/support/referential.rb b/spec/support/referential.rb index ddad29963..03f5a0977 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -43,8 +43,12 @@ RSpec.configure do |config| line_referential = LineReferential.find_or_create_by(name: "first") do |referential| referential.add_member organisation, owner: true end + stop_area_referential = StopAreaReferential.find_or_create_by(name: "first") do |referential| + referential.add_member organisation, owner: true + end - Referential.create! prefix: "first", name: "first", slug: "first", organisation: organisation, line_referential: line_referential + workbench = Workbench.create!(:name => "first", organisation: organisation, line_referential: line_referential, stop_area_referential: stop_area_referential) + Referential.create! prefix: "first", name: "first", slug: "first", organisation: organisation, workbench: workbench end config.before(:each) do |
