diff options
| author | Robert | 2017-10-02 13:26:06 +0200 |
|---|---|---|
| committer | Robert | 2017-10-02 13:26:06 +0200 |
| commit | ed5f05acf1d604eab807f3455ea628179ab55408 (patch) | |
| tree | aa50571e8f43b1b2b2a471c45830512a1f76bfd8 | |
| parent | 30bdfe7c5557ba85f2c6cb18abe4b0308faa217d (diff) | |
| download | chouette-core-ed5f05acf1d604eab807f3455ea628179ab55408.tar.bz2 | |
Refs: #4627@1h;
- Rebase on udated master
- Removal of `default_criticity` from ComplianceControl Class Level Defaults
- Refactoring of specs to allow usage of the same shared examples (given that more models need to undergo the same refact)
6 files changed, 48 insertions, 154 deletions
diff --git a/db/schema.rb b/db/schema.rb index 443fe0579..91ffdd60c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -<<<<<<< HEAD -ActiveRecord::Schema.define(version: 20170928144740) do -======= ActiveRecord::Schema.define(version: 20171002080526) do ->>>>>>> eaf5b3fd868d68856ef94e18656dac39096d866b # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -168,10 +164,7 @@ ActiveRecord::Schema.define(version: 20171002080526) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "status" -<<<<<<< HEAD -======= t.integer "compliance_check_set_id" ->>>>>>> eaf5b3fd868d68856ef94e18656dac39096d866b end add_index "compliance_check_messages", ["compliance_check_id"], name: "index_compliance_check_messages_on_compliance_check_id", using: :btree @@ -409,9 +402,9 @@ ActiveRecord::Schema.define(version: 20171002080526) do t.string "type" t.integer "parent_id", limit: 8 t.string "parent_type" + t.datetime "notified_parent_at" t.integer "current_step", default: 0 t.integer "total_steps", default: 0 - t.datetime "notified_parent_at" t.string "creator" end diff --git a/spec/models/generic_attribute_control/min_max_spec.rb b/spec/models/generic_attribute_control/min_max_spec.rb index d7e1d9a53..0f020db89 100644 --- a/spec/models/generic_attribute_control/min_max_spec.rb +++ b/spec/models/generic_attribute_control/min_max_spec.rb @@ -1,53 +1,7 @@ -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 ){ 'info' } - - context 'class attributes' do - it 'are correctly set' do - 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 :min_max } - 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, 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 :min_max, construction_atts + let( :factory ){ :min_max } - expect( explicit.attributes.values_at(*default_att_names )) - .to eq(expected_values) - end - end - end + it_behaves_like 'ComplianceControl Class Level Defaults' end diff --git a/spec/models/generic_attribute_control/parent_class_spec.rb b/spec/models/generic_attribute_control/parent_class_spec.rb index be60f71be..f9c4373d5 100644 --- a/spec/models/generic_attribute_control/parent_class_spec.rb +++ b/spec/models/generic_attribute_control/parent_class_spec.rb @@ -1,8 +1,7 @@ RSpec.describe ComplianceControl do context 'class attributes' do it 'are correctly set' do - expect( described_class.default_criticity ).to eq( :warning ) - expect( described_class.default_code ).to eq( "" ) + expect( described_class ).to respond_to(:default_code) end end end diff --git a/spec/models/generic_attribute_control/pattern_spec.rb b/spec/models/generic_attribute_control/pattern_spec.rb index 294d33c4a..db2ded2a9 100644 --- a/spec/models/generic_attribute_control/pattern_spec.rb +++ b/spec/models/generic_attribute_control/pattern_spec.rb @@ -1,53 +1,7 @@ -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 ){ 'info' } - - context 'class attributes' do - it 'are correctly set' do - 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( :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, 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 :pattern, construction_atts + let( :factory ){ :pattern } - expect( explicit.attributes.values_at(*default_att_names )) - .to eq(expected_values) - end - end - end + it_behaves_like 'ComplianceControl Class Level Defaults' end diff --git a/spec/models/generic_attribute_control/uniqueness_spec.rb b/spec/models/generic_attribute_control/uniqueness_spec.rb index 179b7142d..e81ad26cd 100644 --- a/spec/models/generic_attribute_control/uniqueness_spec.rb +++ b/spec/models/generic_attribute_control/uniqueness_spec.rb @@ -1,52 +1,6 @@ -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 ){ 'info' } - - context 'class attributes' do - it 'are correctly set' do - 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 :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, 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 + let( :factory ){ :uniqueness } - expect( explicit.attributes.values_at(*default_att_names )) - .to eq(expected_values) - end - end - end + it_behaves_like 'ComplianceControl Class Level Defaults' end diff --git a/spec/support/shared_examples/compliance_control_class_level_defaults.rb b/spec/support/shared_examples/compliance_control_class_level_defaults.rb new file mode 100644 index 000000000..d433038fc --- /dev/null +++ b/spec/support/shared_examples/compliance_control_class_level_defaults.rb @@ -0,0 +1,40 @@ +H = Support::DataModifier::Hash +RSpec.shared_examples_for 'ComplianceControl Class Level Defaults' do + context 'class attributes' do + it 'are correctly set' do + expect( described_class.default_code).to eq(default_code) + end + end + context 'are used in instantiation' do + let( :record ){ create factory } + let( :default_att_names ){%w[ code origin_code ]} + + it 'all defaults' do + expect( record.attributes.values_at(*default_att_names )) + .to eq([ default_code, default_code]) + end + it 'but provided values are not overwritten by defaults' do + code = random_string + origin_code = random_string + # Remove each of the attributes from explicit initialisation to see + # its value provided by CCCWDA. + + # atts :: Map(String, (explicit_value, default_value)) + atts = { + 'code' => [code, default_code], + 'origin_code' => [origin_code, default_code], + } + 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 factory, construction_atts + + expect( explicit.attributes.values_at(*default_att_names )) + .to eq(expected_values) + end + end + end + end |
