reading_group_spec.rb
2.07 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'rails_helper'
describe ReadingGroup, :type => :model do
describe 'methods' do
describe 'persisted?' do
before :each do
@subject = FactoryGirl.build(:reading_group)
ReadingGroup.expects(:exists?).with(@subject.id).returns(false)
end
it 'should return false' do
expect(@subject.persisted?).to eq(false)
end
end
describe 'update' do
before :each do
@qt = FactoryGirl.build(:reading_group)
@qt_params = Hash[FactoryGirl.attributes_for(:reading_group).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
end
context 'with valid attributes' do
before :each do
@qt.expects(:save).returns(true)
end
it 'should return true' do
expect(@qt.update(@qt_params)).to eq(true)
end
end
context 'with invalid attributes' do
before :each do
@qt.expects(:save).returns(false)
end
it 'should return false' do
expect(@qt.update(@qt_params)).to eq(false)
end
end
end
describe 'readings' do
subject { FactoryGirl.build(:reading_group) }
let(:reading) { FactoryGirl.build(:reading) }
it 'should call readings_of on the Reading model' do
Reading.expects(:readings_of).with(subject.id).returns([reading])
expect(subject.readings).to include(reading)
end
end
end
describe 'validations' do
subject {FactoryGirl.build(:reading_group)}
context 'active model validations' do
before :each do
ReadingGroup.expects(:all).at_least_once.returns([])
end
it { is_expected.to validate_presence_of(:name) }
end
context 'kalibro validations' do
before :each do
ReadingGroup.expects(:request).returns(42)
end
it 'should validate uniqueness' do
KalibroUniquenessValidator.any_instance.expects(:validate_each).with(subject, :name, subject.name)
subject.save
end
end
end
end