aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/models/referential/referential_oid_format_from_wkbch_spec.rb68
-rw-r--r--spec/support/random.rb9
2 files changed, 77 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
diff --git a/spec/support/random.rb b/spec/support/random.rb
index 0ebc2ee5e..16d8b4df3 100644
--- a/spec/support/random.rb
+++ b/spec/support/random.rb
@@ -10,6 +10,15 @@ module Support
def random_element from
from[random_int(from.size)]
end
+
+ def random_elements( from, count: )
+ (1..count).map{ |_| random_element from }
+ end
+
+ def distinct_random_elements( from, count: )
+ f = from.dup
+ (1..count).map { |_| f.delete_at( random_int(f.size) ) }
+ end
def random_int max_plus_one=PRETTY_LARGE_INT
(random_number * max_plus_one).to_i