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
class TestAccount < Test::Unit::TestCase | |
def setup | |
@associate = Account.create(:account_type => "checking", :name => "checkers", :balance => 600) | |
@credit = @associate.credits.create(:amount => 40, :description => "bar tab", :transaction_type => "credit") | |
end | |
def test_credits_association | |
assert_not_nil(@credit) | |
assert_equal(40, @credit.amount) |
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
@current_account = signed_in_user.accounts.find(params[:account_id]) | |
@new_credit = @current_account.credits.build(params[:account_id]) |
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
after_save do |credit| | |
parent_account = credit.account_id | |
account_to_credit = Account.find(account_id) | |
account_to_credit.balance.to_f + credit.amount.to_f | |
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
after_save do |credit| | |
parent_account = credit.account_id | |
account_to_credit = Account.find(parent_account) | |
account_to_credit.balance + credit.amount | |
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
class CreditsController < ApplicationController | |
def new | |
@current_account = signed_in_user.accounts.find(params[:account_id]) | |
@new_credit = Credit.new | |
@new_credit.account_id = @current_account.id | |
end | |
def create | |
@current_account = signed_in_user.accounts.find(params[:account_id]) | |
@new_credit = @current_account.credits.build(params[:credit]) |
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
module AccountBalances | |
def credit_to_balance(account, credit) | |
if account.update_attributes(balance: account.balance + credit.amount) | |
account | |
else | |
false | |
end | |
end | |
def debit_from_balance(account, debit) |
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
def new | |
@current_account = signed_in_user.accounts.find(params[:account_id]) | |
@new_credit = Credit.new | |
@new_credit.account_id = @current_account.id | |
end | |
:account_id is an attribute of the credits resource, so why use it to find an account record, why not just :id? |
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
package com.gfs.corp.bid.cucumber.codebidspage; | |
import static org.junit.Assert.assertEquals; | |
import java.text.DateFormat; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import org.openqa.selenium.internal.seleniumemulation.WaitForPageToLoad; |
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
@Then("^table has only these columns:$") | |
public void table_has_only_these_columns(List<String> tableHeadersFromTest) throws Throwable { | |
waitForPageToLoad(); | |
List<WebElement> tableHeadersFromApp = codeBidsPage.tableHeaders(); | |
for (String columnFromTest : tableHeadersFromTest) { | |
for (WebElement headerFromApp : tableHeadersFromApp) { | |
assertEquals(columnFromTest, headerFromApp.getText()); | |
} | |
} | |
} |
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
@wip | |
Scenario: Table has columns # codebidspage/CodeTable.feature:22 | |
Then table has only these columns: # CodeTableStepDefs.table_has_only_these_ Then table has only these columns: # CodeTableStepDefs.table_has_only_these_columns(String>) | |
java.lang.AssertionError | |
at org.junit.Assert.fail(Assert.java:92) | |
at org.junit.Assert.assertTrue(Assert.java:43) | |
at org.junit.Assert.assertTrue(Assert.java:54) | |
at com.gfs.corp.bid.cucumber.codebidspage.CodeTableStepDefs.table_has_only_these_columns(CodeTableStepDefs.java:51) | |
at ✽.Then table has only these columns:(codebidspage/CodeTable.feature:23) |