diff options
Diffstat (limited to 'spec/models')
3 files changed, 117 insertions, 20 deletions
diff --git a/spec/models/generic_attribute_control/min_max_spec.rb b/spec/models/generic_attribute_control/min_max_spec.rb index b3a5d4b6f..b38032965 100644 --- a/spec/models/generic_attribute_control/min_max_spec.rb +++ b/spec/models/generic_attribute_control/min_max_spec.rb @@ -1,21 +1,53 @@ + +H = Support::DataModifier::Hash + +# Describing Behavior of ComplianceControl Class Wide Default Attributes (CCCWDA) RSpec.describe GenericAttributeControl::MinMax, type: :model do let( :default_code ){ "3-Generic-2" } - let( :default_criticity ){ :warning } + let( :default_criticity ){ 'info' } - context 'class attributes' do + context 'class attributes' do it 'are correctly set' do - expect( described_class.default_criticity ).to eq(default_criticity) + expect( described_class.default_criticity ).to eq(:warning) expect( described_class.default_code).to eq(default_code) end - context 'are used in instantiation' do - let( :record ){ create :min_max } - let( :default_att_names ){%w[ code origin_code criticity ]} + end + context 'are used in instantiation' do + let( :record ){ create :uniqueness } + let( :default_att_names ){%w[ code origin_code criticity ]} - it 'all defaults' do - expect( record.attributes.values_at(*default_att_names )) - .to eq([ default_code, default_code, 'info' ]) + it 'all defaults' do + expect( record.attributes.values_at(*default_att_names )) + .to eq([ default_code, default_code, default_criticity]) + end + it 'but provided values are not overwritten by defaults' do + # atts = make_random_atts(code: :string, default_code: :string, criticity: %w[warning error]) + code = random_string + origin_code = random_string + criticity = random_element(%w[warning error]) + # Remove each of the attributes from explicit initialisation to see + # its value provided by CCCWDA. + # N.B. enum default (for criticity) takes precedence over the initializer + # unless nil is passed in explicitly (untested scenario for now, as + # we are suggestuing to remove `criticity` from CCCWDA. + + # atts :: Map(String, (explicit_value, default_value)) + atts = { + 'code' => [code, default_code], + 'origin_code' => [origin_code, default_code], + 'criticity' => [criticity, default_criticity] + } + atts.keys.each do |key| + # Replace key to be tested by default value + expected = H.first_values(atts).merge(key => atts[key].last) + expected_values = expected.values_at(*default_att_names) + # Remove key to be tested from atts passed to `#create` + construction_atts = H.first_values(atts).merge(key => nil).compact + explicit = create :uniqueness, construction_atts + + expect( explicit.attributes.values_at(*default_att_names )) + .to eq(expected_values) end end end - end diff --git a/spec/models/generic_attribute_control/pattern_spec.rb b/spec/models/generic_attribute_control/pattern_spec.rb index bd5d56dd7..646bb735e 100644 --- a/spec/models/generic_attribute_control/pattern_spec.rb +++ b/spec/models/generic_attribute_control/pattern_spec.rb @@ -1,20 +1,53 @@ + +H = Support::DataModifier::Hash + +# Describing Behavior of ComplianceControl Class Wide Default Attributes (CCCWDA) RSpec.describe GenericAttributeControl::Pattern, type: :model do let( :default_code ){ "3-Generic-3" } - let( :default_criticity ){ :warning } + let( :default_criticity ){ 'info' } - context 'class attributes' do + context 'class attributes' do it 'are correctly set' do - expect( described_class.default_criticity ).to eq(default_criticity) + expect( described_class.default_criticity ).to eq(:warning) expect( described_class.default_code).to eq(default_code) end end context 'are used in instantiation' do - let( :record ){ create :pattern } + let( :record ){ create :uniqueness } let( :default_att_names ){%w[ code origin_code criticity ]} it 'all defaults' do expect( record.attributes.values_at(*default_att_names )) - .to eq([ default_code, default_code, 'info' ]) + .to eq([ default_code, default_code, default_criticity]) + end + it 'but provided values are not overwritten by defaults' do + # atts = make_random_atts(code: :string, default_code: :string, criticity: %w[warning error]) + code = random_string + origin_code = random_string + criticity = random_element(%w[warning error]) + # Remove each of the attributes from explicit initialisation to see + # its value provided by CCCWDA. + # N.B. enum default (for criticity) takes precedence over the initializer + # unless nil is passed in explicitly (untested scenario for now, as + # we are suggestuing to remove `criticity` from CCCWDA. + + # atts :: Map(String, (explicit_value, default_value)) + atts = { + 'code' => [code, default_code], + 'origin_code' => [origin_code, default_code], + 'criticity' => [criticity, default_criticity] + } + atts.keys.each do |key| + # Replace key to be tested by default value + expected = H.first_values(atts).merge(key => atts[key].last) + expected_values = expected.values_at(*default_att_names) + # Remove key to be tested from atts passed to `#create` + construction_atts = H.first_values(atts).merge(key => nil).compact + explicit = create :uniqueness, construction_atts + + expect( explicit.attributes.values_at(*default_att_names )) + .to eq(expected_values) + end end end end diff --git a/spec/models/generic_attribute_control/uniqueness_spec.rb b/spec/models/generic_attribute_control/uniqueness_spec.rb index 6b94b76f5..179b7142d 100644 --- a/spec/models/generic_attribute_control/uniqueness_spec.rb +++ b/spec/models/generic_attribute_control/uniqueness_spec.rb @@ -1,10 +1,13 @@ -RSpec.describe GenericAttributeControl::Uniqueness do +H = Support::DataModifier::Hash + +# Describing Behavior of ComplianceControl Class Wide Default Attributes (CCCWDA) +RSpec.describe GenericAttributeControl::Uniqueness, type: :model do let( :default_code ){ "3-Generic-3" } - let( :default_criticity ){ :warning } + let( :default_criticity ){ 'info' } - context 'class attributes' do + context 'class attributes' do it 'are correctly set' do - expect( described_class.default_criticity ).to eq(default_criticity) + expect( described_class.default_criticity ).to eq(:warning) expect( described_class.default_code).to eq(default_code) end end @@ -14,7 +17,36 @@ RSpec.describe GenericAttributeControl::Uniqueness do it 'all defaults' do expect( record.attributes.values_at(*default_att_names )) - .to eq([ default_code, default_code, 'info' ]) + .to eq([ default_code, default_code, default_criticity]) + end + it 'but provided values are not overwritten by defaults' do + # atts = make_random_atts(code: :string, default_code: :string, criticity: %w[warning error]) + code = random_string + origin_code = random_string + criticity = random_element(%w[warning error]) + # Remove each of the attributes from explicit initialisation to see + # its value provided by CCCWDA. + # N.B. enum default (for criticity) takes precedence over the initializer + # unless nil is passed in explicitly (untested scenario for now, as + # we are suggestuing to remove `criticity` from CCCWDA. + + # atts :: Map(String, (explicit_value, default_value)) + atts = { + 'code' => [code, default_code], + 'origin_code' => [origin_code, default_code], + 'criticity' => [criticity, default_criticity] + } + atts.keys.each do |key| + # Replace key to be tested by default value + expected = H.first_values(atts).merge(key => atts[key].last) + expected_values = expected.values_at(*default_att_names) + # Remove key to be tested from atts passed to `#create` + construction_atts = H.first_values(atts).merge(key => nil).compact + explicit = create :uniqueness, construction_atts + + expect( explicit.attributes.values_at(*default_att_names )) + .to eq(expected_values) + end end end end |
