require 'test_helper' module RubyPsigate class RecurringChargeTest < Test::Unit::TestCase def setup @recurring_charge = RecurringCharge.new end %w( rbcid rbname interval rbtrigger status starttime endtime processtype ).each do |attribute| should "have getter/setter for #{attribute}" do getter = "#{attribute}".to_sym setter = "#{attribute}=".to_sym assert @recurring_charge.respond_to?(getter) assert @recurring_charge.respond_to?(setter) end end should "respond to items" do assert @recurring_charge.respond_to?(:items) end should "add options via << method" do assert_equal 0, @recurring_charge.items.count @recurring_charge << valid_recurring_item assert_equal [valid_recurring_item_hash], @recurring_charge.items end should "raise an error unless added option is a ItemOption class" do assert_raises(InvalidRecurringItem) do @recurring_charge << "Something Here" end end should "return a hash" do @expectation = { :RBCID => "9999999999", :RBName => "Charge123", :Interval => "M", :RBTrigger => "25", :ProcessType => "A", :Status => "Active", :StartTime => "2010.08.01", :EndTime => "2015.12.31" } @recurring_charge = valid_recurring_charge assert_equal @expectation, @recurring_charge.to_hash end should "trim the hash of nil value attributes" do @expectation = { :RBCID => "9999999999", :RBName => "Charge123", :Interval => "M", :RBTrigger => "25", :StartTime => "2010.08.01", :EndTime => "2015.12.31" } @recurring_charge = valid_recurring_charge @recurring_charge.processtype = nil @recurring_charge.status = nil assert_equal @expectation, @recurring_charge.to_hash end should "return a hash with items" do @expectation = { :RBCID => "9999999999", :RBName => "Charge123", :Interval => "M", :RBTrigger => "25", :ProcessType => "A", :StartTime => "2010.08.01", :EndTime => "2015.12.31" } @expectation[:ItemInfo] = Array.new @expectation[:ItemInfo] << valid_recurring_item_hash @expectation[:ItemInfo] << valid_recurring_item_hash @recurring_charge = valid_recurring_charge @recurring_charge.status = nil @recurring_charge << valid_recurring_item @recurring_charge << valid_recurring_item assert_equal @expectation, @recurring_charge.to_hash end end end