ARTestHelper example


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #require 'test/unit' unless defined? $ZENTEST and $ZENTEST
  2.  
  3. require File.dirname(__FILE__) + '/../test_helper'
  4.  
  5. class AddressObserverTest < Test::Rails::TestCase
  6. def test_class_instance
  7. assert 1
  8. end
  9. end
  10.  
  11. class AddressTest < Test::Rails::TestCase
  12.  
  13. include ARTestHelper
  14.  
  15. check_associations %w(account addressable)
  16.  
  17. check_validations_for :street_address do
  18. invalid nil
  19. invalid 'st'
  20. invalid 'st'.ljust(200)
  21. valid 'This is some street address'
  22. end
  23.  
  24. check_validations_for :city do
  25. invalid nil
  26. invalid 'ci'
  27. invalid 'ci'.ljust(200)
  28. valid 'Funchal'
  29. end
  30.  
  31. check_validations_for :state do
  32. invalid nil
  33. invalid 's'
  34. invalid 's'.ljust(200)
  35. valid 'Madeira'
  36. valid 'CA'
  37. end
  38.  
  39. check_validations_for :postal_code do
  40. invalid nil
  41. invalid 'p'
  42. invalid 'p'.ljust(200)
  43. valid '9000-055'
  44. end
  45.  
  46. def setup
  47. super
  48. @address = @rentacar_account.addresses.find(1)
  49. @a = @address
  50. end
  51.  
  52. def test_account
  53. assert_a_account_instance
  54. end
  55.  
  56. def test_account_eh
  57. assert_raise( ArgumentError){ @address.account? }
  58. end
  59.  
  60. def test_account_equals
  61. assert_equal @address.account, @rentacar_account
  62. @address.account = @property_account
  63. assert_equal @address.account, @property_account
  64. end
  65.  
  66. def test_addressable
  67. assert_a_addressable_instance
  68. end
  69.  
  70. def test_addressable_equals
  71. assert_equal @address.addressable, @rentacar_account.branches.find(1)
  72. new_addressable = valid_branch( :parent => @rentacar_account )
  73. @address.addressable = new_addressable
  74. assert_equal @address.addressable, new_addressable
  75. end
  76.  
  77. def test_build_account
  78. assert_a_account_build
  79. end
  80.  
  81. def test_create_account
  82. assert_a_account_create
  83. end
  84.  
  85. def test_has_account_eh
  86. assert @address.has_account?
  87. end
  88.  
  89. def test_set_account_target
  90. assert_a_account_target
  91. end
  92.  
  93. def test_set_addressable_target
  94. assert_a_addressable_target
  95. end
  96.  
  97. def test_build_country
  98. assert_instance_of Globalize::Country, @address.build_country
  99. end
  100.  
  101. def test_country
  102. assert_a_country_instance
  103. end
  104.  
  105. def test_country_eh
  106. assert_raise( ArgumentError ){@address.country? }
  107. end
  108.  
  109. def test_country_equals
  110. @address.country = Globalize::Country.find(:first)
  111. assert_equal Globalize::Country.find(:first), @address.country
  112. end
  113.  
  114. def test_create_country
  115. assert_a_country_create
  116. end
  117.  
  118. def test_has_country_eh
  119. assert @address.has_country?
  120. end
  121.  
  122. def test_set_country_target
  123. assert_a_country_target
  124. end
  125.  
  126. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.