-
Notifications
You must be signed in to change notification settings - Fork 0
/
sl12_partial.rb
54 lines (44 loc) · 1.18 KB
/
sl12_partial.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
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: 'students.sqlite'
)
I18n.enforce_available_locales = false # get rid of the warning
class Student < ActiveRecord::Base
# we have name, surnames, birthday, website, number_of_dogs
# and first_programming_experience
AGE_MINIMUM = 16
validates_presence_of :name, :surnames
validates_format_of :website, with: /\Ahttp:/
validates_numericality_of :number_of_dogs, greater_than: 0
validate :proper_age
private
def proper_age
unless birthday < AGE_MINIMUM.years.ago
errors.add(:birthday, 'is too young')
end
end
end
describe Student do
before do
@student = Student.new
@student.name = 'Joe'
@student.surnames = 'Ironhack'
@student.birthday = Date.new(1987,12,5)
@student.number_of_dogs = 1
@student.website = 'http://ironhack.com'
end
it "should be valid with correct data" do
expect(@student.valid?).to be_truthy
end
describe :name do
it "should be invalid if it's missing" do
@student.name = nil
expect(@student.valid?).to be_falsy
end
end
describe :surnames do
# your turn!
end
end