Commit 46023e568af47f54b6bd7345ba4b7b29fc322217

Authored by Rafael Manzo
Committed by Diego Camarinha
1 parent 494f50ba

Range overlapping does not consider the reange itself for the edition case

Fixed infinity buttons acceptance tests that were trying to create overlapping ranges
app/models/validators/range_overlapping_validator.rb
1 1 class RangeOverlappingValidator < ActiveModel::Validator
2 2 def validate(record)
3 3 record.class.ranges_of(record.metric_configuration_id).each do |mezuro_range|
4   - if overlaps?(mezuro_range,record)
  4 + if mezuro_range.id != record.id && overlaps?(mezuro_range,record)
5 5 record.errors[:beginning] << "There's already a #{record.class} within these boundaries! Please, choose another ones."
6 6 break
7 7 end
... ...
features/mezuro_range/create.feature
... ... @@ -150,7 +150,6 @@ Feature: Create range
150 150 And I own a sample reading group
151 151 And I have a sample metric configuration within the given mezuro configuration
152 152 And I have a sample reading within the sample reading group labeled "My Reading"
153   - And I have a sample range within the sample metric configuration with beginning "2"
154 153 And I am at the New Range page
155 154 And I click the -∞ link
156 155 And I click the ∞ link
... ...
spec/models/validators/range_overlapping_validator_spec.rb
... ... @@ -12,10 +12,10 @@ describe RangeOverlappingValidator, :type =&gt; :model do
12 12 end
13 13  
14 14 context 'not overlapping' do
15   - let!(:not_overlapping_range) { FactoryGirl.build(:mezuro_range, beginning: 0.0, end: 'INF', metric_configuration_id: metric_configuration.id) }
  15 + let!(:not_overlapping_range) { FactoryGirl.build(:mezuro_range, id: 31, beginning: 0.0, end: 'INF', metric_configuration_id: metric_configuration.id) }
16 16  
17 17 before :each do
18   - MezuroRange.expects(:ranges_of).with(metric_configuration.id).returns([not_overlapping_range])
  18 + MezuroRange.expects(:ranges_of).with(metric_configuration.id).returns([range, not_overlapping_range])
19 19 end
20 20  
21 21 it 'is expected to not return errors' do
... ... @@ -24,11 +24,12 @@ describe RangeOverlappingValidator, :type =&gt; :model do
24 24 end
25 25 end
26 26  
  27 +
27 28 context 'overlapping' do
28   - let!(:overlapping_range) { FactoryGirl.build(:mezuro_range, beginning: -2.0, end: -1.0, metric_configuration_id: metric_configuration.id) }
  29 + let!(:overlapping_range) { FactoryGirl.build(:mezuro_range, id: 31, beginning: '-INF', end: 'INF', metric_configuration_id: metric_configuration.id) }
29 30  
30 31 before :each do
31   - MezuroRange.expects(:ranges_of).with(metric_configuration.id).returns([overlapping_range])
  32 + MezuroRange.expects(:ranges_of).with(metric_configuration.id).returns([range, overlapping_range])
32 33 end
33 34  
34 35 it 'is expected to return errors' do
... ...