diff options
| -rw-r--r-- | app/controllers/referentials_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/referential.rb | 2 | ||||
| -rw-r--r-- | app/models/referential_metadata.rb | 11 | ||||
| -rw-r--r-- | spec/models/referential_spec.rb | 2 | 
4 files changed, 3 insertions, 14 deletions
| diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index ae3411dab..dbf753794 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -11,7 +11,7 @@ class ReferentialsController < BreadcrumbController      new! do        @referential.data_format = current_organisation.data_format -      @referential.workbench_id = params[:workbench_id] +      @referential.workbench_id ||= params[:workbench_id]        if @referential.in_workbench?          @referential.init_metadatas first_period_begin: Date.today, first_period_end: Date.today.advance(months: 1) diff --git a/app/models/referential.rb b/app/models/referential.rb index af39f4fc8..afff89892 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -133,6 +133,7 @@ class Referential < ActiveRecord::Base        stop_area_referential: from.stop_area_referential,        workbench: from.workbench,        created_from: from, +      metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m) }      })    end @@ -176,7 +177,6 @@ class Referential < ActiveRecord::Base    before_validation :clone_associations, :on => :create, if: :created_from    before_create :create_schema -  before_validation :clone_metadatas, on: :create, if: :created_from    after_create :clone_schema, if: :created_from    before_destroy :destroy_schema diff --git a/app/models/referential_metadata.rb b/app/models/referential_metadata.rb index 3f5ed4db8..d1300b690 100644 --- a/app/models/referential_metadata.rb +++ b/app/models/referential_metadata.rb @@ -63,17 +63,6 @@ class ReferentialMetadata < ActiveRecord::Base      end    end -  # def lines_with_ids_support=(values) -  #   if String === values.first -  #     self.line_values = values -  #   else -  #     self.lines_without_values_support = values -  #   end -  # end -  # alias_method_chain :lines, :ids_support - -  #delegate :begin, :begin=, :end, :end=, to: :first_period, prefix: :first_period -    def self.new_from from      from.dup.tap do |metadata|        metadata.referential_id = nil diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index c1205c9f0..4c9338aa6 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -12,7 +12,7 @@ describe Referential, :type => :model do    it { should belong_to(:workbench) }    context "Cloning referential" do -    let(:cloned) { create(:referential, created_from: ref) } +    let(:cloned) { Referential.new_from(ref).tap(&:save!) }      it 'should create a ReferentialCloning' do        expect { cloned }.to change{ReferentialCloning.count}.by(1) | 
