Skip to content

Instantly share code, notes, and snippets.

@telagraphic
telagraphic / good or bad
Created November 18, 2012 01:24
association test
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)
@current_account = signed_in_user.accounts.find(params[:account_id])
@new_credit = @current_account.credits.build(params[:account_id])
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
after_save do |credit|
parent_account = credit.account_id
account_to_credit = Account.find(parent_account)
account_to_credit.balance + credit.amount
end
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])
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)
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?
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;
@telagraphic
telagraphic / columnFromTest doesn't iterate...?
Created February 27, 2013 19:22
Comparing a list of values from cucumber feature to table header columns from the code bids table. tableHeadersFromTest is a list but isn't iterating in my code below. tableHeadersFromApp does loop. Am I missing something ? If not, then I may be missing something from the cucumber side of things...
@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());
}
}
}
@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)