Skip to content

Commit

Permalink
Add some validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Libranner committed Oct 1, 2013
1 parent c8e473d commit 42ab417
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spec/models/building_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
building.should have(1).error_on(:rooms)
end

it 'validate uniqueness of name field' do
create(:building, name: 'Edificio', abbreviation: 'ED')
classroom = build(:building,name:'Edificio', abbreviation: 'ED')
classroom.should have(1).error_on(:name)
end

end
31 changes: 30 additions & 1 deletion spec/models/classroom_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
require 'spec_helper'

describe Classroom do
pending "add some examples to (or delete) #{__FILE__}"
it 'validate sits field is greater than zero' do
classroom = build(:classroom, sits:0)
classroom.should have(1).error_on(:sits)
end

it 'validate field available_until is greater than field available_from' do
classroom = build(:classroom, sits:2, available_from: 1.hour.ago, available_until: 2.hour.ago)
classroom.should have(1).error_on(:available_from)
end

=begin
it 'validate presence of fields available_from and available_until' do
classroom = Classroom.new
classroom.should have(2).error_on(:available_from)
classroom.should have(1).error_on(:available_until)
end
=end

it 'validate uniqueness of name field' do
create(:classroom,name: 'Aula 1', sits:2, available_from: 3.hour.ago, available_until: 2.hour.ago)
classroom = build(:classroom,name: 'Aula 1', sits:2, available_from: 3.hour.ago, available_until: 2.hour.ago)
classroom.should have(1).error_on(:name)
end

it 'validate on floor must be greater than 0 and less than floor field of the building' do
building = create(:building, floors: 2)
classroom = build(:classroom, building: building, on_floor: 3)
classroom.should have(1).error_on(:on_floor)
end

end

0 comments on commit 42ab417

Please sign in to comment.