diff options
| author | Zog | 2018-04-17 10:13:07 +0200 |
|---|---|---|
| committer | Zog | 2018-04-17 10:13:07 +0200 |
| commit | 75dce9d57374c3c052ebde0c811edf3ebc6fec62 (patch) | |
| tree | 82f3092e58c88063d51fab1f12401a63f9320593 | |
| parent | 965dda9a017b103d35e1aacb42a7a7e9120453b6 (diff) | |
| download | chouette-core-6377-centralize-lines-scope-in-workbenches.tar.bz2 | |
Refs #6377; Use the workbench to retrieve the lines,6377-centralize-lines-scope-in-workbenches
Instead of the organisation
| -rw-r--r-- | app/controllers/referentials_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/merge.rb | 2 | ||||
| -rw-r--r-- | app/models/referential.rb | 4 | ||||
| -rw-r--r-- | app/models/referential_metadata.rb | 4 | ||||
| -rw-r--r-- | app/views/referentials/_form.html.slim | 2 | ||||
| -rw-r--r-- | spec/models/referential/referential_oid_format_from_wkbch_spec.rb | 5 | ||||
| -rw-r--r-- | spec/models/referential_metadata_spec.rb | 17 | ||||
| -rw-r--r-- | spec/models/referential_spec.rb | 2 |
8 files changed, 22 insertions, 16 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index fe661651e..3db38b0f6 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -143,7 +143,7 @@ class ReferentialsController < ChouetteController def build_referential if params[:from] source_referential = Referential.find(params[:from]) - @referential = Referential.new_from(source_referential, current_organisation) + @referential = Referential.new_from(source_referential, current_workbench) end @referential.data_format = current_organisation.data_format diff --git a/app/models/merge.rb b/app/models/merge.rb index 8d661f209..5ccf76d53 100644 --- a/app/models/merge.rb +++ b/app/models/merge.rb @@ -50,7 +50,7 @@ class Merge < ApplicationModel new = if workbench.output.current Rails.logger.debug "Clone current output" - Referential.new_from(workbench.output.current, workbench.organisation).tap do |clone| + Referential.new_from(workbench.output.current, workbench).tap do |clone| clone.inline_clone = true end else diff --git a/app/models/referential.rb b/app/models/referential.rb index 1794126a2..e570f42c6 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -241,7 +241,7 @@ class Referential < ApplicationModel end end - def self.new_from(from, organisation) + def self.new_from(from, workbench) Referential.new( name: I18n.t("activerecord.copy", name: from.name), slug: "#{from.slug}_clone", @@ -252,7 +252,7 @@ class Referential < ApplicationModel stop_area_referential: from.stop_area_referential, created_from: from, objectid_format: from.objectid_format, - metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m, organisation) } + metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m, workbench) } ) end diff --git a/app/models/referential_metadata.rb b/app/models/referential_metadata.rb index 7a8a01774..e13bb17ee 100644 --- a/app/models/referential_metadata.rb +++ b/app/models/referential_metadata.rb @@ -155,10 +155,10 @@ class ReferentialMetadata < ApplicationModel end private :clear_periods - def self.new_from(from, organisation) + def self.new_from(from, workbench) from.dup.tap do |metadata| metadata.referential_source_id = from.referential_id - metadata.line_ids = from.referential.lines.where(id: metadata.line_ids).for_organisation(organisation).pluck(:id) + metadata.line_ids = workbench.lines.where(id: metadata.line_ids).pluck(:id) metadata.referential_id = nil end end diff --git a/app/views/referentials/_form.html.slim b/app/views/referentials/_form.html.slim index c378f871e..94c7f3617 100644 --- a/app/views/referentials/_form.html.slim +++ b/app/views/referentials/_form.html.slim @@ -49,7 +49,7 @@ .separator .row .col-lg-11 - = subform.input :lines, as: :select, collection: Chouette::Line.includes(:company).order(:name).for_organisation(current_organisation), selected: subform.object.line_ids, label_method: :display_name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': t('simple_form.labels.referential.placeholders.select_lines'), 'multiple': 'multiple', style: 'width: 100%' } + = subform.input :lines, as: :select, collection: @workbench.lines, selected: subform.object.line_ids, label_method: :display_name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': t('simple_form.labels.referential.placeholders.select_lines'), 'multiple': 'multiple', style: 'width: 100%' } .col-lg-1 a.clear-lines.btn.btn-default href='#' .fa.fa-trash diff --git a/spec/models/referential/referential_oid_format_from_wkbch_spec.rb b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb index b3ee68be3..7b8a236df 100644 --- a/spec/models/referential/referential_oid_format_from_wkbch_spec.rb +++ b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb @@ -44,8 +44,7 @@ RSpec.describe Referential do describe 'self.new_from' do - let( :source ){ build :referential } - let( :functional_scope ){ double('functional scope') } + let( :source ){ build :workbench_referential } it 'copies objectid_format from source' do expect( described_class ) @@ -61,7 +60,7 @@ RSpec.describe Referential do objectid_format: source.objectid_format, metadatas: source.metadatas.map { |m| ReferentialMetadata.new_from(m, functional_scope) }) - described_class.new_from( source, functional_scope ) + described_class.new_from( source, source.workbench ) end end diff --git a/spec/models/referential_metadata_spec.rb b/spec/models/referential_metadata_spec.rb index 88a12b2bb..097285a38 100644 --- a/spec/models/referential_metadata_spec.rb +++ b/spec/models/referential_metadata_spec.rb @@ -10,12 +10,15 @@ RSpec.describe ReferentialMetadata, :type => :model do it { is_expected.to validate_presence_of(:periodes) } describe ".new_from" do - - let(:referential_metadata) { create :referential_metadata, referential_source: create(:referential) } - let(:new_referential_metadata) { ReferentialMetadata.new_from(referential_metadata, nil) } + let(:line_referential){ create :line_referential } + let(:workbench){ create :workbench, line_referential: line_referential} + let(:referential){ create :workbench_referential, workbench: workbench, line_referential: line_referential } + let(:referential_metadata) { create :referential_metadata, referential: referential } + let(:new_referential_metadata) { ReferentialMetadata.new_from(referential_metadata, referential.workbench) } before do + Workgroup.workbench_scopes_class = WorkbenchScopes::All referential_metadata.line_ids.each do |id| - Chouette::Line.find(id).update_attribute :line_referential_id, referential_metadata.referential.line_referential_id + Chouette::Line.find(id).update_attribute :line_referential_id, line_referential.id end end @@ -41,7 +44,11 @@ RSpec.describe ReferentialMetadata, :type => :model do context "with a functional scope" do let(:organisation){ create :organisation, sso_attributes: {"functional_scope" => [referential_metadata.referential.lines.first.objectid]} } - let(:new_referential_metadata) { ReferentialMetadata.new_from(referential_metadata, organisation) } + let(:new_referential_metadata) { ReferentialMetadata.new_from(referential_metadata, referential.workbench) } + before do + referential.workbench.update organisation: organisation + Workgroup.workbench_scopes_class = Stif::WorkbenchScopes + end it "should scope the lines" do expect(new_referential_metadata.line_ids).to eq [referential_metadata.referential.lines.first.id] diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index ca2caf57f..7fc3ff62d 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -55,7 +55,7 @@ describe Referential, :type => :model do context "Cloning referential" do let(:clone) do - Referential.new_from(ref, nil) + Referential.new_from(ref, ref.workbench) end let!(:workbench){ create :workbench } |
