Skip to content

Commit

Permalink
Merge pull request #146 from TreinaDev/validar-torre
Browse files Browse the repository at this point in the history
Limita quantidade de andares e unidades por andar que podem ser criadas em uma torre
  • Loading branch information
ruliancruz authored Jul 22, 2024
2 parents 5f6388e + 2479a24 commit ea37ac8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/tower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Tower < ApplicationRecord
validates :name, :floor_quantity, :units_per_floor, presence: true

validates :floor_quantity, :units_per_floor, numericality: {
greater_than: 0, only_integer: true
greater_than: 0, only_integer: true, less_than: 200
}

after_create :generate_floors
Expand Down
16 changes: 16 additions & 0 deletions spec/models/tower_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@
.to include 'Apartamentos por Andar não é um número'
end

it 'Floor Quantity and Units per Floor must be lesser than 200' do
over_floor_tower = build :tower, floor_quantity: 200, units_per_floor: 199
over_unit_tower = build :tower, floor_quantity: 199, units_per_floor: 200
valid_tower = build :tower, floor_quantity: 199, units_per_floor: 199

expect(over_floor_tower).not_to be_valid
expect(over_unit_tower).not_to be_valid
expect(valid_tower).to be_valid

expect(over_floor_tower.errors.include?(:floor_quantity)).to be true
expect(over_unit_tower.errors.include?(:units_per_floor)).to be true

expect(over_floor_tower.errors.full_messages).to include 'Quantidade de Andares deve ser menor que 200'
expect(over_unit_tower.errors.full_messages).to include 'Apartamentos por Andar deve ser menor que 200'
end

it 'Floor quantity must be greater than 0' do
no_floor_tower = build :tower, floor_quantity: 0, units_per_floor: 0
one_floor_tower = build :tower, floor_quantity: 1, units_per_floor: 1
Expand Down

0 comments on commit ea37ac8

Please sign in to comment.