Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limita quantidade de andares e unidades por andar que podem ser criadas em uma torre #146

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading