This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #652 from 18F/jy-confirm-bid
Add PlaceBidValidator class
- Loading branch information
Showing
10 changed files
with
196 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class PlaceBidValidator < ActiveModel::Validator | ||
def validate(bid) | ||
unless user_can_bid?(bid) | ||
add_error(bid, 'permissions') | ||
end | ||
|
||
if bid.amount <= 0 | ||
add_error(bid, 'amount.below_zero') | ||
end | ||
|
||
if bid.amount > max_allowed_bid(bid) | ||
add_error(bid, 'amount.greater_than_max') | ||
end | ||
end | ||
|
||
private | ||
|
||
def add_error(bid, message) | ||
bid.errors.add :base, I18n.t("activerecord.errors.models.bid.#{message}") | ||
end | ||
|
||
def user_can_bid?(bid) | ||
rules(bid).user_can_bid?(bid.bidder) | ||
end | ||
|
||
def max_allowed_bid(bid) | ||
rules(bid).max_allowed_bid | ||
end | ||
|
||
def rules(bid) | ||
RulesFactory.new(bid.auction).create | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,5 @@ | |
contracting_officer true | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.