-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from rubyforgood/add-student-funds_issue-142
Add student funds to admin
- Loading branch information
Showing
17 changed files
with
167 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
class Student < User | ||
belongs_to :classroom | ||
has_one :portfolio, foreign_key: 'user_id' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<%# | ||
# Form Partial | ||
This partial is rendered on a resource's `new` and `edit` pages, | ||
and renders all form fields for a resource's editable attributes. | ||
## Local variables: | ||
- `page`: | ||
An instance of [Administrate::Page::Form][1]. | ||
Contains helper methods to display a form, | ||
and knows which attributes should be displayed in the resource's form. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form | ||
%> | ||
|
||
<%= form_for([namespace, page.resource], html: { class: "form" }) do |f| %> | ||
<% if page.resource.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2> | ||
<%= t( | ||
"administrate.form.errors", | ||
pluralized_errors: pluralize(page.resource.errors.count, t("administrate.form.error")), | ||
resource_name: display_resource_name(page.resource_name, singular: true) | ||
) %> | ||
</h2> | ||
|
||
<ul> | ||
<% page.resource.errors.full_messages.each do |message| %> | ||
<li class="flash-error"><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<% page.attributes(controller.action_name).each do |title, attributes| -%> | ||
<fieldset class="<%= "field-unit--nested" if title.present? %>"> | ||
<% if title.present? %> | ||
<legend><%= t "helpers.label.#{f.object_name}.#{title}", default: title %></legend> | ||
<% end %> | ||
|
||
<% attributes.each do |attribute| %> | ||
<div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>"> | ||
<%= render_field attribute, f: f %> | ||
|
||
<% hint_key = "administrate.field_hints.#{page.resource_name}.#{attribute.name}" %> | ||
<% if I18n.exists?(hint_key) -%> | ||
<div class="field-unit__hint"> | ||
<%= I18n.t(hint_key) %> | ||
</div> | ||
<% end -%> | ||
</div> | ||
<% end %> | ||
</fieldset> | ||
<% if action_name == 'edit' %> | ||
<div class="field-unit"> | ||
<div class="field-unit__label"><label>Cash balance</label></div> | ||
<div class="field-unit__field"> | ||
<%= sprintf('%.2f', page.resource&.portfolio&.cash_balance || 0)%> | ||
</div> | ||
</div> | ||
<div class="field-unit"> | ||
<div class="field-unit__label"><label>Add funds</label></div> | ||
<div class="field-unit__field"> | ||
<input step="any" type="number" name="student[add_fund_amount]" id="student_add_fund_amount"> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end -%> | ||
|
||
<div class="form-actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20240531145714_add_amount_to_portfolio_transactions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddAmountToPortfolioTransactions < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :portfolio_transactions, :amount, :decimal, precision: 8, scale: 2, null: false | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20240531151002_remove_cash_balance_from_portfolios.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RemoveCashBalanceFromPortfolios < ActiveRecord::Migration[7.1] | ||
def change | ||
remove_column :portfolios, :cash_balance | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'test_helper' | ||
|
||
class Admin::StudentsControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@student = users(:one) | ||
end | ||
|
||
test 'should update student email' do | ||
@student.update_attribute(:email, '[email protected]') | ||
|
||
patch admin_student_url(@student), params: { student: { email: '[email protected]' } } | ||
@student.reload | ||
assert_equal '[email protected]', @student.email | ||
assert_redirected_to admin_student_url(@student) | ||
end | ||
|
||
test 'given a add_fund_amount, creates a transaction' do | ||
assert_difference('PortfolioTransaction.count', 1) do | ||
patch admin_student_url(@student), params: { student: { add_fund_amount: '10.50' } } | ||
end | ||
|
||
transaction = PortfolioTransaction.last | ||
|
||
assert_equal 10.50, transaction.amount | ||
assert_equal @student.reload.portfolio.portfolio_transactions.last, transaction | ||
|
||
assert_redirected_to admin_student_url(@student) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
year: 1 | ||
year: 2023 | ||
|
||
two: | ||
year: 2 | ||
year: 2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
require "test_helper" | ||
require 'test_helper' | ||
|
||
class PortfolioTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
#TODO: Add tests for the Portfolio model | ||
fixtures :portfolios | ||
test '#cash_balance' do | ||
portfolio = portfolios(:one) | ||
assert_equal BigDecimal('25.50'), portfolio.cash_balance | ||
end | ||
end |