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

Refactor income credits calculation #81

Closed
wants to merge 5 commits into from

Conversation

gsaint
Copy link
Contributor

@gsaint gsaint commented Nov 15, 2016

  • Moving Income credits calculation in the Income base model
  • Fixing single user creation

Related to issue 55: #55

We might need to add more tests on the controllers.

@incomes = @game.incomes.where(round: @current_round)
if @last_round > 0
@previous_income = @game.incomes.where(round: @last_round)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was not used

end

private
def get_income_to_credits_array
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An other possibility to get this array for the corresponding team could be to add they array to the team model.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right now, the user/team structure is sort of in flux. It's sort of a messed up design which needs to be rethought. So it's fine to leave this here until.

Copy link
Contributor

@FifthSurprise FifthSurprise left a comment

Choose a reason for hiding this comment

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

Left some comments. Don't feel obliged to get this in before Dec. 3rd. This was not a game-critical PR (although still really important).

Overall, looks nice, just some style things and some RSPEC related things.

end

private
def get_income_to_credits_array
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now, the user/team structure is sort of in flux. It's sort of a messed up design which needs to be rethought. So it's fine to leave this here until.

when 'Germany'
[2, 5, 6, 7, 8, 9, 10, 12, 14]
else
[2, 5, 6, 7, 8, 9, 10, 11, 12]
Copy link
Contributor

Choose a reason for hiding this comment

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

We should explicitly state India here and then have an overall default (which can be the same array as India's anyway).

Copy link
Contributor

Choose a reason for hiding this comment

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

On second thought, this should just be a hash where keys are the country names and values is the array. Store this at the top of the class as a constant like COUNTRY_CREDIT_LEVELS.

Then in this method, if self.team_name is in COUNTRY_CREDIT_LEVELS.keys then return COUNTRY_CREDIT_LEVELS[self.team_name]. Otherwise, you provide the default (which may as well also be stored as a constant).

RSpec.describe Income, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"

Game::COUNTRIES.each { |country| Team.find_or_create_by(team_name: country) }
Copy link
Contributor

Choose a reason for hiding this comment

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

You should just make the Team call in before(:each) be a find_or_create_by and delete this line. Otherwise, you may cause some unintended side effect since rails does not know how to clean up the created Teams after the rspec is run. In this case, you lucked out because we are doing a find_or_create but if another test eventually attempts to mess with Teams/Team creation we might have unexpected errors.

You could also do this in a before(:all) and then make an after(:all) hook that destroys all Teams. But really it's not worth it because we don't have that many examples that its slowing down the tests.

@FifthSurprise
Copy link
Contributor

Also, sorry I took so long on this, I got caught up in setting up for our Dec. 3rd game.

@FifthSurprise
Copy link
Contributor

Wow, I was not expecting to wake up and see PR updates for this repo haha. I'll review when I have a chance.

@gsaint
Copy link
Contributor Author

gsaint commented May 9, 2017

Sorry for the long delay... I have been travelling for the past 5 months! (and will be travelling until this Septembre).

@gsaint gsaint closed this May 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants