Skip to content

Instantly share code, notes, and snippets.

@kylewelsby
Created April 11, 2012 17:08
Show Gist options
  • Save kylewelsby/2360598 to your computer and use it in GitHub Desktop.
Save kylewelsby/2360598 to your computer and use it in GitHub Desktop.
View Specs Real Example
if @grouped
object @days
node do |date|
node(:changed) { date[:changed].format }
node(:balance) { date[:balance].format }
child date[:transactions] => :transactions do
extends 'transactions/show'
end
node(:date) { date[:date] }
end
else
collection @transactions
extends 'transactions/show'
end
require 'spec_helper'
describe "transactions/index" do
let(:user) {mock_model(User, accounts: [account])}
let(:account) { mock_model(Account, name: 'Test', balance: 0) }
let(:transaction) {
mock_model(Transaction, name: "test", amount: Money.new(1000))
}
let(:day) {
{
date: "2012-01-01",
balance: Money.new(100),
changed: Money.new(0),
transactions: [
transaction
]
}
}
it "renders an array of transactions" do
assign(:days, [day])
assign(:transactions, [transaction])
render
JSON.parse(rendered).should be_an_instance_of Array
end
it "renders an array of days with transactions" do
assign(:days, [day])
assign(:transactions, [transaction])
assign(:grouped, true)
render
JSON.parse(rendered).should be_an_instance_of Array
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment