mezuro_range_spec.rb
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'spec_helper'
describe MezuroRange do
subject { FactoryGirl.build(:mezuro_range, { metric_configuration_id: 42 }) }
describe 'validations' do
context 'active model validations' do
before :each do
MezuroRange.expects(:ranges_of).with(subject.metric_configuration_id).at_least_once.returns([])
end
it { should validate_presence_of(:beginning) }
it { should validate_presence_of(:end) }
it { should validate_presence_of(:reading_id) }
context 'beginning and end numericality' do
it { should validate_presence_of(:beginning) }
it { should validate_presence_of(:end) }
it 'should allow -INF and INF to beginning' do
subject.beginning = '-INF'
subject.save
subject.errors.messages.should be_empty
subject.beginning = 'INF'
subject.save
subject.errors.messages.should be_empty
end
it 'should allow -INF and INF to end' do
subject.end = '-INF'
subject.save
subject.errors.messages.should be_empty
subject.end = 'INF'
subject.save
subject.errors.messages.should be_empty
end
end
end
end
context 'beginning validations' do
before :each do
MezuroRange.expects(:request).returns(2)
end
it 'should validate uniqueness' do
BeginningUniquenessValidator.any_instance.expects(:validate_each).with(subject, :beginning, subject.beginning)
subject.save
end
end
end