-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Change concept of current budget to account for multiple budgets #2322
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 👏 for that helper_method at the app controller 👌 🙇
When there was only one budget this implementation worked fine Nowadays there can be multiple budgets, and therefore the definition of the current_budget has changed. It is no longer a budget that has not finished, but rather, the last budget created that is not in the initial drafting phase. Budgets in the drafting phase are not considered the current_budget, but rather a budget that is still being prepared and that soon will become the current_budget
6b754c1
to
c9d531d
Compare
Before Budget.current could return multiple budgets, now there can only be a single current_budget. Adding the concept of open, which better reflects what the admin sees in this page: A tab for open budgets and a tab for finished budgets
In the specs, some investment were missing a heading_id, thus creating another unexpected budget By explicitly setting the heading_id we can control better which budgets are created in each test
Before we could have multiple current budgets, as we now only have one current_budget, some specs broke. As there is no need to display multiple budgets to Valuators, only the current budget is necessary, we can remove arrays and assume that only a single budget, the current budget, is displayed to Valuators
This spec used to pass, because even though there were no budgets, as Budget.current returned an array, it gracefully handled situations without budgets Now we assume that there can only be a single current budget, and so calling any method of budget will raise an exception unless there is a current budget present Valuators should not access this page when there is no budget present, however it might be wise to create an issue to cover this case, just in case
c9d531d
to
34e0c23
Compare
@@ -30,8 +30,11 @@ class Budget < ActiveRecord::Base | |||
scope :balloting, -> { where(phase: "balloting") } | |||
scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") } | |||
scope :finished, -> { where(phase: "finished") } | |||
scope :open, -> { where.not(phase: "finished") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should exclude as well 'drafting' budgets, as those should be totally hidden to the public.
I know 'drafting' phase wasn't included in this PR (but in one that I created) but just realized/discovered about this filter and that we may not be doing it right, and maybe would be a better idea to address this on a separate issue & PR if my assumptions are correct. Is that so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, it makes sense at a code level, however at the interface level, it's not yet aplicable. As this scope is only used in the admin interface. Where there are only 2 tabs: open and close, which I think fits better with the current definition of open.
Maybe we can review this when we have a need to extend the budget's admin interface or the user facing interface due to having more budgets in different phases?
<tr id="<%= dom_id(budget) %>"> | ||
<td><%= budget.name %></td> | ||
<td><%= budget.translated_phase %></td> | ||
<tr id="<%= dom_id(@budget) %>"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that we may not be covering the scenario where @budget
may not be present (may be nil). I'm thinking about new clean installations without a proper database seed, or that have cleaned up "dummy data" from seeds.
Same could happen at the file app/views/valuation/budgets/index.html.erb changed in this PR
I realize that we weren't covering that scenario neither before, and that we may just should open a new issue to address it instead of extending this one... what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes :) +1 to an issue for this 👌
These are the tests that where failing due to not having a budget, it would be a great starting point to implementa that issue 👍
34e0c23
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great refactor! Although I've the following two questions, that may or not be valid, and we could be fixing in a second/third PR as it would be fixing stuff a bit out of the scope of this one's objective
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 so great to finally have this :) great work
💃 |
Change concept of current budget to account for multiple budgets
Where
What
currrent_budget
helper for controllers and viewscurrent_budget
helper takes into account that the current budget is the last budget createdcurrent_budget
is really the previous budget if it exists or nil otherwisecurrent_budget
Budget.open
to represent, budgets that are not finished. This substitutes the oldBudget.current
implementation and it's used only in the admin budget's index view, which has two tabs open budgets and finished_budgets (see screenshot)How
current_budget
to the ApplicationController and making it accessible to viewsScreenshots
Test
current_budget
andBudget.open
Deployment
Warnings