avatar

22

Add tests for the Active Record extensions in the plugin (all in templated_attribute.rb)

by chrisk, 28 Jul, 2007 10:05 PM
3 22  
11 require 'test/unit'
2 require 'test_helper'
23 
4 require File.dirname(__FILE__) + '/fixtures/user'
5 
36 class TemplatedAttributeTest < Test::Unit::TestCase
4   # Replace this with your real tests.
5   def test_this_plugin
6     flunk
7 
8   def setup
9     User.templated_attribute :website, :starting_value => 'http://'
10     @user = User.new
711   end
12   
13   def test_raise_argument_error_on_invalid_keys_in_options_hash
14     assert_raise ArgumentError do
15       User.templated_attribute :name, :invalid_option => 'foo'
16     end
17   end
18   
19   def test_raise_argument_error_on_no_options_hash
20     assert_raise ArgumentError do
21       User.templated_attribute :name
22     end
23   end
24   
25   def test_raise_argument_Error_on_mutually_exclusive_options_both_used
26     assert_raise ArgumentError do
27       User.templated_attribute :email, :label => 'user@server.com', :starting_value => 'user@server.com'
28     end    
29   end
30   
31   def test_protected_instance_methods_get_defined_on_model
32     assert @user.protected_methods.include?('remove_unchanged_template_values')
33   end
34   
35   def test_class_accessor_is_created_for_options_storage
36     assert_nothing_raised do
37       @user.instance_variable_get(:@templated_attributes_options)
38     end
39   end
40     
41   def test_remove_unchanged_template_values_removes_template_value
42     @user.website = 'http://'
43     @user.valid?
44     assert_equal nil, @user.website
45   end
46   
47   def test_remove_unchanged_template_values_removes_whitespaced_template_value
48     @user.website = 'http://  '
49     @user.valid?
50     assert_equal nil, @user.website
51   end
52   
53   def test_remove_unchanged_template_values_maintains_nils
54     @user.website = nil
55     @user.valid?
56     assert_equal nil, @user.website
57   end
58   
859 end