aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRobert2017-12-05 11:37:25 +0100
committerRobert2017-12-05 12:19:42 +0100
commit642d2bd3a46a4b459acf18748dbfebf0cb6ca7df (patch)
tree773a01b7a4dc86a5dabfab98f6f44bdc9f949a50 /spec
parent089c6935ca0e036de484834381e5beda7545d499 (diff)
downloadchouette-core-642d2bd3a46a4b459acf18748dbfebf0cb6ca7df.tar.bz2
Refs: #5179@1.25h; Referential Creation Enforces objectid_format from associated Workbench
- changed ObjectIdFormatterSupport as requested - respeced all defined cases - implemented respec Missing: What to do in `define_default_attributes` if ref has no workbench and no `objectid_format`?
Diffstat (limited to 'spec')
-rw-r--r--spec/models/referential/referential_oid_format_from_wkbch_spec.rb77
-rw-r--r--spec/support/random.rb9
2 files changed, 52 insertions, 34 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
index fe359ac6b..b0d78fcf2 100644
--- a/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
+++ b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
@@ -1,39 +1,48 @@
RSpec.describe Referential do
+ let( :legal_formats ){ ObjectidFormatterSupport.legal_formats }
+
+
describe 'default attributes' do
- let( :referential ){ described_class.new }
- let( :workbench ){ Workbench.new }
- it "of a referential with a workbench contain the workbench's objectid_format" do
- ObjectidFormatterSupport.legal_formats.each do |legal_format|
- workbench.objectid_format = legal_format
+ 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(legal_format)
+ expect( referential.objectid_format ).to eq(workbench.objectid_format)
+ end
+
+ xit 'and w/o a workbench will take the default objectid_format' do
+ referential.define_default_attributes
+ expect( referential.objectid_format ).to eq(some_value_to_be_defined)
end
end
- it 'of a referential w/o a workbench contain the default objectid_format' do
- referential.define_default_attributes
- expect( referential.objectid_format ).to eq(ObjectidFormatterSupport.default_format)
+
+ 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
-
- # Referential.new(
- # name:
- # slug: "#{from.slug}_clone",
- # prefix: from.prefix,
- # time_zone: from.time_zone,
- # bounds: from.bounds,
- # line_referential: from.line_referential,
- # stop_area_referential: from.stop_area_referential,
- # created_from: from,
- # metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m, functional_scope) }
- # )
- #
let( :source ){ build :referential }
let( :functional_scope ){ double('functional scope') }
@@ -41,17 +50,17 @@ RSpec.describe Referential do
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) })
-
+ .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
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