diff options
| author | Teddy Wing | 2017-12-19 16:35:09 +0100 | 
|---|---|---|
| committer | Luc Donnet | 2017-12-21 15:32:42 +0100 | 
| commit | 4918ffcd7492661f36a763cdf248757993f9bff4 (patch) | |
| tree | 11589d965fb2b4baf5c0e4db1ff5413946f87c4d /spec | |
| parent | d9f3af834a06a6d4e73c083440926983ac5e2cfa (diff) | |
| download | chouette-core-4918ffcd7492661f36a763cdf248757993f9bff4.tar.bz2 | |
Remove `hstore_accessor` usage
The places we were using `hstore_accessor` have now been converted to
Postgres JSON fields. Thus we no longer need `hstore_accessor` in order
to add accessors for the fields.
Instead we can use Rails' built-in support for Postgres JSON fields and
create accessors for our JSON hash keys with `store_accessor`. We get
rid of the data types because `store_accessor` doesn't work like that
and JSON already types our values with primitive data types.
Finally, add some extra validation tests now that the vaildation for our
JSON fields should work.
Refs #5316
Diffstat (limited to 'spec')
4 files changed, 15 insertions, 0 deletions
| diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb index 9610cc796..90bb660ee 100644 --- a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb +++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb @@ -4,4 +4,7 @@ RSpec.describe GenericAttributeControl::Pattern, type: :model do    let( :factory ){ :generic_attribute_control_pattern }    it_behaves_like 'ComplianceControl Class Level Defaults' +  it_behaves_like 'has target attribute' + +  it { should validate_presence_of(:pattern) }  end diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb index e4ab8d2cd..c4874b5a2 100644 --- a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb +++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb @@ -4,4 +4,5 @@ RSpec.describe GenericAttributeControl::Uniqueness, type: :model do    let( :factory ){ :generic_attribute_control_uniqueness }    it_behaves_like 'ComplianceControl Class Level Defaults'  +  it_behaves_like 'has target attribute'  end diff --git a/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb b/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb index 4d30d61e3..138f7aae1 100644 --- a/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb +++ b/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb @@ -4,5 +4,6 @@ RSpec.describe GenericAttributeControl::MinMax do    subject{ build factory }    it_behaves_like 'has min_max_values' +  it_behaves_like 'has target attribute'  end diff --git a/spec/support/shared_examples/compliance_control_validation.rb b/spec/support/shared_examples/compliance_control_validation.rb index d4ab9f41d..c76712c4c 100644 --- a/spec/support/shared_examples/compliance_control_validation.rb +++ b/spec/support/shared_examples/compliance_control_validation.rb @@ -1,6 +1,9 @@  RSpec.shared_examples_for 'has min_max_values' do    context "is valid" do +    it { should validate_numericality_of(:minimum) } +    it { should validate_numericality_of(:maximum) } +      it 'if no value is provided' do        expect_it.to be_valid      end @@ -41,3 +44,10 @@ RSpec.shared_examples_for 'has min_max_values' do      end    end  end + + +RSpec.shared_examples_for "has target attribute" do +  context "is valid" do +    it { should validate_presence_of(:target) } +  end +end | 
