aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlban Peignier2016-11-20 16:15:19 +0100
committerAlban Peignier2016-11-20 16:40:57 +0100
commitba9ea54467215b01c369608179c1658e2ca42412 (patch)
tree47fded69de036b4afe5eef14c5369be2dcaa35e5
parent6fb74042430b89bbc3713e629b75ab5d70c5cd38 (diff)
downloadchouette-core-ba9ea54467215b01c369608179c1658e2ca42412.tar.bz2
Manage metadatas in Referential.new_from (to have expected metadatas in new form). Refs #1782
-rw-r--r--app/controllers/referentials_controller.rb2
-rw-r--r--app/models/referential.rb2
-rw-r--r--app/models/referential_metadata.rb11
-rw-r--r--spec/models/referential_spec.rb2
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)