Show Me The Money-8.1 - Finishing up validation

Iteration#1 : Day 8/10

Lets look at our iteration burndown. No points earned since we are still not complete.. we have Deleting Credit Entries and some UI polishing to do.
It shows that
  • Unless there is a time warp in the near future, we aren’t going to make it.
  • Do we have a problem. We aren’t going as fast as we hoped to. (The light trendline. Found Chart > Add Trendline… in Excel. Yay!). We could attribute some of that to the new tools and their learning curves.
On that challenging note, we begin our day.
We need to write the controller tests for validations. Test first as ever… rails doesn’t let us do much… it’s all taken care of! I’m coining a term for that -- ATCO

file: \ShowMeTheMoney\test\functional\inflow_controller_test.rb

  def test_createEntryWithNoDescription
[nil, " "].each{|value|
test_new
post :create, :credit => {:description => value, :amount => 120.23 }

assert_response :success
assert_template 'inflow/new'

assert_errors_on_page
assert_equal @numberOfFixtureRecords, Credit.count
}
end

def test_createEntryWithNilZeroOrNegativeAmount
[nil, 0, -4.5].each {|value|
test_new
post :create, :credit => {:description => "Salary", :amount => value }

assert_response :success
assert_template 'inflow/new'

assert_errors_on_page
assert_equal @numberOfFixtureRecords, Credit.count
}
end


assert_errors_on_page is a custom assertion added to test_helper.rb, that checks if there is an error div tag on the rendered view

file: \ShowMeTheMoney\test\test_helper.rb

class Test::Unit::TestCase
...

#custom assertions
def assert_errors_on_page
assert_tag :tag => 'div', :attributes => {:class => 'fieldWithErrors'}
end
end


All Green! So now we can move on to delete or destroy as Rails calls it. ATCO!!

file:\ShowMeTheMoney\test\unit\credit_test.rb

  def test_destroy
assert_nothing_raised { getFirstEntry }

getFirstEntry.destroy

assert_raise (ActiveRecord::RecordNotFound) { getFirstEntry }
end


file: \ShowMeTheMoney\test\functional\inflow_controller_test.rb

  def test_destroy
firstEntryID = credits(:salary_credit_entry).id
assert_nothing_raised { Credit.find(firstEntryID) }

post :destroy, :id => firstEntryID
assert_response :redirect
assert_redirected_to :action => 'list'

assert_raise(ActiveRecord::RecordNotFound) { Credit.find(firstEntryID) }
end

So there we have it. I think we have all we need for this story except the spiffy UI.

No comments:

Post a Comment