From 5074667b2876e1edb57ba46800010f2db320b67f Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Fri, 2 Jul 2010 11:38:29 -0700 Subject: [PATCH] [#4180] Block total from getting set on HourlyDeliverables. --- app/models/hourly_deliverable.rb | 16 ++++++++++++++++ test/integration/deliverables_new_test.rb | 1 + test/unit/hourly_deliverable_test.rb | 23 +++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 test/unit/hourly_deliverable_test.rb diff --git a/app/models/hourly_deliverable.rb b/app/models/hourly_deliverable.rb index f74b9fe..42e7cdb 100644 --- a/app/models/hourly_deliverable.rb +++ b/app/models/hourly_deliverable.rb @@ -7,7 +7,23 @@ class HourlyDeliverable < Deliverable # Accessors + # Callbacks + before_save :clear_total + def short_type 'H' end + + # Block getting and setting the total on HourlyDeliverables + def total + nil + end + + def total=(v) + nil + end + + def clear_total + write_attribute(:total, nil) + end end diff --git a/test/integration/deliverables_new_test.rb b/test/integration/deliverables_new_test.rb index 3003f3f..72d422e 100644 --- a/test/integration/deliverables_new_test.rb +++ b/test/integration/deliverables_new_test.rb @@ -90,6 +90,7 @@ class DeliverablesNewTest < ActionController::IntegrationTest fill_in "Start", :with => '2010-01-01' fill_in "End Date", :with => '2010-12-31' fill_in "Notes", :with => 'Some notes on the deliverable' + fill_in "Total", :with => '1,000.00' # Hide and clear the total assert js("jQuery('#deliverable_total_input').is(':hidden')"), diff --git a/test/unit/hourly_deliverable_test.rb b/test/unit/hourly_deliverable_test.rb new file mode 100644 index 0000000..88005d4 --- /dev/null +++ b/test/unit/hourly_deliverable_test.rb @@ -0,0 +1,23 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class HourlyDeliverableTest < ActiveSupport::TestCase + context "#total=" do + should "not write any attributes" do + d = HourlyDeliverable.new + d.total = '$100.00' + + assert_equal nil, d.total + end + end + + context "clear_total" do + should "clear any total attributes" do + d = HourlyDeliverable.new + d.write_attribute(:total, 100.00) + d.clear_total + + assert_equal nil, d.total + + end + end +end