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

[Core] Check for existence of can_finance? method #11513

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ollybh
Copy link
Collaborator

@ollybh ollybh commented Feb 4, 2025

Implementation Notes

Explanation of Change

The can_finance? method was added for 1837 in commit d08cc84. It's used to check whether the bank will step in to pay the cost of a train.

This has broken 1877 Venezuela. There is a default implementation of can_finance? added to the Step::BuyTrain class, but 1877 Venezuela allows trains to be bought in the BuySellParShares step, which did not have this method.

This commit tests for the existence of this method before calling it.

Fixes #11508.

Before clicking "Create"

  • Branch is derived from the latest master
  • Add the pins or archive_alpha_games label if this change will break existing games
  • Code passes linter with docker compose exec rack rubocop -a
  • Tests pass cleanly with docker compose exec rack rake

The `can_finance?` method was added for 1837 in commit d08cc84. It's
used to check whether the bank will step in to pay the cost of a train.

This has broken 1877 Venezuela. There is a default implementation of
`can_finance?` added to the Step::BuyTrain class, but 1877 Venezuela
allows trains to be bought in the BuySellParShares step, which did not
have this method.

This commit tests for the existence of this method before calling it.

Fixes tobymao#11508.
@ollybh ollybh added 1877 Core touches shared code not limited to one game or game family labels Feb 4, 2025
@ollybh ollybh requested a review from crericha February 4, 2025 22:56
@@ -300,7 +300,7 @@ def render
children << h(:div, issue_str)
end

if @step.can_finance?(@corporation)
if @step.respond_to?(:can_finance?) && @step.can_finance?(@corporation)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I purposely avoided doing needing to do this by adding the method to the buy_train step. Looking at 1877's buy_sell_par_shares step, it copies over all the methods from the buy_train step. I think it should copy over this new method too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work too. I'd done the respond_to? check as we've already got a zillion tests like this in the UI code.

I've had a quick grep and can't see any other games that have a BuyTrain action in a step that's not inheriting from Step::BuyTrain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1877 Core touches shared code not limited to one game or game family
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1877: Venezuela game does not load
2 participants