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

Calculate total expenses for a user within a given date range #14

Merged
merged 15 commits into from Oct 31, 2015

Conversation

Projects
None yet
2 participants
@boddhisattva
Owner

boddhisattva commented Oct 31, 2015

No description provided.

boddhisattva added some commits Oct 29, 2015

Uses a tableless model to validate presence of dates
This refactoring removes the need to create a new Expense object to
throw validation errors if “from date” and “to date” are blank when a
user tries to go about calculating total expenses.
Adds a link in user dashboard to help calculate total expenses
Please note the link is styled with a bootstrap button CSS to make it
look more intuitive.
Ensures that form contains only relevant data based on a request
Earlier if a user didn’t submit the total expenses form with valid
data, appropriate validation messages are shown on the page. Now if a
user enters correct data and resubmits the form the earlier validation
messages weren’t getting erased. This change ensures that the earlier
messages wrt a form submit do not persist when one makes another form
submit.
Adds a validation to ensure that "from date" is lesser than "to date"
To calculate expenses within a given time period, the from date should
be less than to date.
Adds specs related to the date validator
Date validator is currently used when a user tries to calculate total
expenses. These specs help ensure that appropriate error messages are
raised when the user tries to calculate total expenses with
insufficient data.
Ensures the date is converted to appropriate format
As part of the total expenses form, the form params are passed as a
string. Inorder to do comparison between two dates to validate things
like the from_date should be less than the to_date in order to
calculate expenses within a period, the dates need to be in the
appropriate format before the comparison that validates this. Hence
this conversion is done .
Handles a scenario where a user tries to delete an already deleted ex…
…pense

Scenario: Assume a user is logged in to the expense app from two
different browsers and the user deletes one of their expenses from one
of the browsers. In case the user forgets about this action and is
surprised to see the same record from the other browser and goes about
trying to delete the same record an appropriate error message is
displayed as part of this user action.
it { should_not be_valid }
end
end

This comment has been minimized.

@houndci-bot

houndci-bot Oct 31, 2015

Final newline missing.

@houndci-bot

houndci-bot Oct 31, 2015

Final newline missing.

errors.add(:from_date, "cannot be greater than to date")
end
end
end

This comment has been minimized.

@houndci-bot

houndci-bot Oct 31, 2015

Final newline missing.

@houndci-bot

houndci-bot Oct 31, 2015

Final newline missing.

scope :made_between, -> (from_date, to_date) { where(date: from_date..to_date) }
def self.total_between(from_date, to_date)
made_between(from_date, to_date).collect(&:cost).sum

This comment has been minimized.

@houndci-bot

houndci-bot Oct 31, 2015

Prefer map over collect.

@houndci-bot

houndci-bot Oct 31, 2015

Prefer map over collect.

@@ -46,4 +58,11 @@ def expense_params
def get_user_expenses
@expenses = Expense.order_by_most_recent(current_user.id)
end
def dates_are_present?(from_date, to_date)

This comment has been minimized.

@houndci-bot

houndci-bot Oct 31, 2015

Inconsistent indentation detected.

@houndci-bot

houndci-bot Oct 31, 2015

Inconsistent indentation detected.

#expenses_page_heading {
margin-right: 336px;
margin-top: 40px;
#create_expense_link_text {

This comment has been minimized.

@houndci-bot

houndci-bot Oct 31, 2015

Avoid using id selectors
Selector create_expense_link_text should be written in lowercase with hyphens

@houndci-bot

houndci-bot Oct 31, 2015

Avoid using id selectors
Selector create_expense_link_text should be written in lowercase with hyphens

margin-top: 40px;
}
#calculate_total_expenses_link_text {

This comment has been minimized.

@houndci-bot

houndci-bot Oct 31, 2015

Avoid using id selectors
Selector calculate_total_expenses_link_text should be written in lowercase with hyphens

@houndci-bot

houndci-bot Oct 31, 2015

Avoid using id selectors
Selector calculate_total_expenses_link_text should be written in lowercase with hyphens

@@ -2,11 +2,16 @@
float: right;
}
#create_expense_link_text {
#expenses_page_heading {

This comment has been minimized.

@houndci-bot

houndci-bot Oct 31, 2015

Avoid using id selectors
Selector expenses_page_heading should be written in lowercase with hyphens

@houndci-bot

houndci-bot Oct 31, 2015

Avoid using id selectors
Selector expenses_page_heading should be written in lowercase with hyphens

boddhisattva added a commit that referenced this pull request Oct 31, 2015

Merge pull request #14 from boddhisattva/14-total-expenses
Calculate total expenses for a user within a given date range

@boddhisattva boddhisattva merged commit 4d21d03 into master Oct 31, 2015

2 checks passed

ci/circleci Your tests passed on CircleCI!
Details
hound 8 violations found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment