/
dog_spec.rb
80 lines (67 loc) · 1.82 KB
/
dog_spec.rb
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
76
77
78
79
80
require 'spec_helper'
describe Dog do
attrs = {
'registered_name' => :string,
'call_name' => :string,
'female' => :boolean,
'neutered' => :boolean,
'registration' => :string,
'registry' => :string,
'registration2' => :string,
'registry2' => :string,
'dna_registration' => :string,
'stud_book_date' => :date,
'deceased_at' => :date,
'frozen_semen' => :boolean,
'data_source' => :string,
}
attrs.each do |attr, col_type|
it "has a #{attr}" do
subject.should have_attribute(attr => col_type)
end
end
it 'belongs to an owner' do
subject.should belong_to :owner
end
it 'belongs to a litter' do
subject.should belong_to :litter
end
it 'has many completed titles' do
subject.should have_many :completed_titles
end
it 'has many completed certifications' do
subject.should have_many :completed_certifications
end
it 'has many diagnoses' do
subject.should have_many :diagnoses
end
context 'when male' do
it 'has many litters as the sire' do
dog = Factory(:dog, :female => false)
litter = dog.litters.build
litter.sire.should == dog
end
end
context 'when female' do
it 'has many litters as the dam' do
bitch = Factory(:dog, :female => true)
litter = bitch.litters.build
litter.dam.should == bitch
end
end
describe 'delegations to litter' do
before(:all) do
@litter = Factory.build(:litter)
@dog = Factory.build(:dog, :litter => @litter)
end
it 'delegates breeder' do
@dog.breeder.should == @litter.breeder
end
it 'delegates whelp_date' do
@dog.whelp_date.should == @litter.whelp_date
end
end
it 'matches any' do
Dog.should respond_to :matching_any
end
end