Commit 5b419f8c0fc9a517df718f9cc99b927db822b266
Committed by
Rafael Manzo
1 parent
e4998ac7
Exists in
colab
and in
4 other branches
Finished Mezuro Range integration
Showing
5 changed files
with
3 additions
and
110 deletions
Show diff stats
app/models/mezuro_range.rb
| 1 | -require "validators/beginning_uniqueness_validator.rb" | |
| 2 | -require "validators/greater_than_beginning_validator.rb" | |
| 3 | -require "validators/range_overlapping_validator.rb" | |
| 4 | - | |
| 5 | 1 | class MezuroRange < KalibroGatekeeperClient::Entities::Range |
| 6 | - include KalibroRecord | |
| 7 | - | |
| 8 | - attr_accessor :beginning, :end, :reading_id, :mezuro_configuration_id, :comments | |
| 9 | - | |
| 10 | - validates :beginning, presence: true, beginning_uniqueness: true | |
| 11 | - validates :beginning, numericality: true, if: :non_infinite_beginning? | |
| 12 | - validates :end, presence: true | |
| 13 | - validates :end, numericality: true, if: :non_infinite_end? | |
| 14 | - validates :end, greater_than_beginning: true | |
| 15 | - validates :reading_id, presence: true | |
| 16 | - validates_with RangeOverlappingValidator | |
| 17 | - | |
| 18 | - private | |
| 19 | - | |
| 20 | - def non_infinite_end? | |
| 21 | - !(self.end == '-INF' || self.end == 'INF') | |
| 22 | - end | |
| 23 | - | |
| 24 | - def non_infinite_beginning? | |
| 25 | - val = !(self.beginning == '-INF' || self.beginning == 'INF') | |
| 26 | - end | |
| 27 | 2 | end | ... | ... |
spec/models/mezuro_range_spec.rb
| ... | ... | @@ -1,85 +0,0 @@ |
| 1 | -require 'rails_helper' | |
| 2 | - | |
| 3 | -describe MezuroRange, :type => :model do | |
| 4 | - pending 'waiting for kalibro configurations integration' do | |
| 5 | - subject { FactoryGirl.build(:mezuro_range, { metric_configuration_id: 42 }) } | |
| 6 | - describe 'validations' do | |
| 7 | - context 'active model validations' do | |
| 8 | - before :each do | |
| 9 | - BeginningUniquenessValidator.any_instance.stubs(:validate_each) | |
| 10 | - GreaterThanBeginningValidator.any_instance.stubs(:validate_each) | |
| 11 | - RangeOverlappingValidator.any_instance.stubs(:validate) | |
| 12 | - end | |
| 13 | - | |
| 14 | - it { is_expected.to validate_presence_of(:beginning) } | |
| 15 | - it { is_expected.to validate_presence_of(:end) } | |
| 16 | - it { is_expected.to validate_presence_of(:reading_id) } | |
| 17 | - | |
| 18 | - context 'beginning and end numericality' do | |
| 19 | - it { is_expected.to validate_numericality_of(:beginning) } | |
| 20 | - it { is_expected.to validate_numericality_of(:end) } | |
| 21 | - | |
| 22 | - it 'should allow -INF and INF to beginning' do | |
| 23 | - subject.beginning = '-INF' | |
| 24 | - subject.save | |
| 25 | - | |
| 26 | - expect(subject.errors.messages).to be_empty | |
| 27 | - | |
| 28 | - subject.beginning = 'INF' | |
| 29 | - subject.save | |
| 30 | - | |
| 31 | - expect(subject.errors.messages).to be_empty | |
| 32 | - end | |
| 33 | - | |
| 34 | - it 'should allow -INF and INF to end' do | |
| 35 | - subject.end = '-INF' | |
| 36 | - subject.save | |
| 37 | - | |
| 38 | - expect(subject.errors.messages).to be_empty | |
| 39 | - | |
| 40 | - subject.end = 'INF' | |
| 41 | - subject.save | |
| 42 | - | |
| 43 | - expect(subject.errors.messages).to be_empty | |
| 44 | - end | |
| 45 | - end | |
| 46 | - end | |
| 47 | - | |
| 48 | - context 'beginning validations' do | |
| 49 | - before :each do | |
| 50 | - GreaterThanBeginningValidator.any_instance.stubs(:validate_each) | |
| 51 | - RangeOverlappingValidator.any_instance.stubs(:validate) | |
| 52 | - end | |
| 53 | - | |
| 54 | - it 'should validate uniqueness' do | |
| 55 | - BeginningUniquenessValidator.any_instance.expects(:validate_each).with(subject, :beginning, subject.beginning) | |
| 56 | - subject.save | |
| 57 | - end | |
| 58 | - end | |
| 59 | - | |
| 60 | - context 'end validations' do | |
| 61 | - before :each do | |
| 62 | - BeginningUniquenessValidator.any_instance.stubs(:validate_each) | |
| 63 | - RangeOverlappingValidator.any_instance.stubs(:validate) | |
| 64 | - end | |
| 65 | - | |
| 66 | - it 'should validate that end is greater than beginning' do | |
| 67 | - GreaterThanBeginningValidator.any_instance.expects(:validate_each).with(subject, :end, subject.end) | |
| 68 | - subject.save | |
| 69 | - end | |
| 70 | - end | |
| 71 | - | |
| 72 | - context 'overlapping validations' do | |
| 73 | - before :each do | |
| 74 | - GreaterThanBeginningValidator.any_instance.stubs(:validate_each) | |
| 75 | - BeginningUniquenessValidator.any_instance.stubs(:validate_each) | |
| 76 | - end | |
| 77 | - | |
| 78 | - it 'is expected to validate if this range overlaps the existing ones' do | |
| 79 | - RangeOverlappingValidator.any_instance.expects(:validate).with(subject) | |
| 80 | - subject.save | |
| 81 | - end | |
| 82 | - end | |
| 83 | - end | |
| 84 | - end | |
| 85 | -end |
spec/models/validators/beginning_uniqueness_validator_spec.rb
spec/models/validators/greater_than_beginning_validator_spec.rb
spec/models/validators/kalibro_uniqueness_validator_spec.rb