Skip to content

Add maximum wager capability #18

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions app/models/table_rule_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@ def _restrict_doubling_to_hard_totals_includes_integers_between_2_and_21
errors.add :restrict_doubling_to_hard_totals, "must not contain any values less than 2 or greater than 21"
end
end

def maximum_wager_amount
self.minimum_wager_amount * 10
end

end
16 changes: 16 additions & 0 deletions app/models/wager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ class Wager < ActiveRecord::Base

validates :player, presence: true

validate :_wager_is_less_than_maximum_wager_amount

def maximum_wager_amount
return Float::INFINITY unless hand && hand.round && hand.round.table && hand.round.table.table_rule_set
hand.round.table.table_rule_set.maximum_wager_amount
end

def _wager_is_less_than_maximum_wager_amount
if self.amount > maximum_wager_amount
errors.add ("amount must be less than or equal to the maxium_wager_amount #{maximum_wager_amount}")
end
end



before_validation :build_matching_financial_transaction

def minimum_amount
Expand Down Expand Up @@ -41,4 +56,5 @@ def build_matching_financial_transaction

build_financial_transaction(amount: (-1 * amount), player: player, kind: :wager, action: self)
end

end
1 change: 1 addition & 0 deletions app/resources/v1/table_rule_set_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TableRuleSetResource < BaseResource
:dealer_wins_ties,
:round_initial_betting_window_seconds,
:minimum_wager_amount,
:maximum_wager_amount,
:minimum_players_per_round,
)

Expand Down
1 change: 1 addition & 0 deletions spec/acceptance/table_rule_sets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
expect(parsed["data"]["attributes"]["may-hit-split-aces"]).to eq table_rule_set.may_hit_split_aces
expect(parsed["data"]["attributes"]["player-must-stand-on-soft-21"]).to eq table_rule_set.player_must_stand_on_soft_21
expect(parsed["data"]["attributes"]["restrict-doubling-to-hard-totals"]).to eq table_rule_set.restrict_doubling_to_hard_totals
expect(parsed["data"]["attributes"]["maximum-wager-amount"]).to eq table_rule_set.maximum_wager_amount
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/models/table_rule_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,10 @@
subject.minimum_players_per_round = 1
expect(subject.minimum_players_per_round).to eq 1
end

it "has a maximum_wager_amount attribute" do
subject.minimum_wager_amount = 10
expect(subject.maximum_wager_amount).to eq (10 * subject.minimum_wager_amount)
end

end
7 changes: 7 additions & 0 deletions spec/models/wager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,11 @@
expect(subject.minimum_amount).to eq Float::INFINITY
end

it "validates that its amount is less than or equal to the maximum_wager_amount for the table" do
expect(subject).to receive(:minimum_amount).and_return(100)
subject.amount = 1001
subject.valid?
expect(subject.errors[:amount]).to include "must be less than or equal to 1001"
end

end