aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/referential
diff options
context:
space:
mode:
authorTeddy Wing2017-12-05 18:26:57 +0100
committerTeddy Wing2017-12-05 18:26:57 +0100
commit47181fd81105396b2db394958c39a6e40bc6f0f0 (patch)
treee95e67d8479f348453e3e494b5991053b15ba3de /spec/models/referential
parent1098e24f15b235dce127f0398adac4bbf7cfe463 (diff)
parent9f1aa4d40d7d968963dae5799e15ad5da4cbcbc5 (diff)
downloadchouette-core-47181fd81105396b2db394958c39a6e40bc6f0f0.tar.bz2
Merge remote-tracking branch 'origin/master' into 5024-prevent-duplicate-referentials-from-being-created-during-parallel-db-transactions--rb201711271659
Conflicts: app/models/referential.rb A whitespace conflict in a place I don't even remember editing? Okaay.
Diffstat (limited to 'spec/models/referential')
-rw-r--r--spec/models/referential/referential_oid_format_from_wkbch_spec.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/models/referential/referential_oid_format_from_wkbch_spec.rb b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
new file mode 100644
index 000000000..b3ee68be3
--- /dev/null
+++ b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
@@ -0,0 +1,68 @@
+RSpec.describe Referential do
+
+ let( :legal_formats ){ described_class.objectid_format.values }
+
+
+ describe 'default attributes' do
+
+ context 'referential w/o an objectid_format' do
+ let( :referential ){ described_class.new }
+ let( :workbench ){ build_stubbed :workbench, objectid_format: random_element(legal_formats) }
+
+ it "but a workbench will take the format of the workbench" do
+ referential.workbench = workbench
+ referential.define_default_attributes
+ expect( referential.objectid_format ).to eq(workbench.objectid_format)
+ end
+
+ it 'and w/o a workbench will take the default objectid_format' do
+ referential.define_default_attributes
+ expect( referential.objectid_format ).to be_nil
+ end
+ end
+
+
+ context 'referential with an objectid_format' do
+ let( :distinct_formats ){ distinct_random_elements(legal_formats, count: 2) }
+
+ let( :referential ){ build_stubbed :referential, objectid_format: distinct_formats.first}
+ let( :workbench ){ build_stubbed :workbench, objectid_format: distinct_formats.second }
+
+ it "and a workbench will not take the format of the workbench" do
+ referential.workbench = workbench
+ expect{ referential.define_default_attributes }.not_to change{ referential.objectid_format }
+ end
+
+ it 'and w/o a workbench will not take the default objectid_format' do
+ expect{ referential.define_default_attributes }.not_to change{ referential.objectid_format }
+ end
+ end
+
+ end
+
+
+
+ describe 'self.new_from' do
+
+ let( :source ){ build :referential }
+ let( :functional_scope ){ double('functional scope') }
+
+ it 'copies objectid_format from source' do
+ expect( described_class )
+ .to receive(:new)
+ .with(name: I18n.t("activerecord.copy", name: source.name),
+ slug: "#{source.slug}_clone",
+ prefix: source.prefix,
+ time_zone: source.time_zone,
+ bounds: source.bounds,
+ line_referential: source.line_referential,
+ stop_area_referential: source.stop_area_referential,
+ created_from: source,
+ objectid_format: source.objectid_format,
+ metadatas: source.metadatas.map { |m| ReferentialMetadata.new_from(m, functional_scope) })
+
+ described_class.new_from( source, functional_scope )
+ end
+
+ end
+end