Changeset 4918
- Timestamp:
- 09/03/06 17:54:48 (2 years ago)
- Files:
-
- trunk/activerecord/test/validations_test.rb (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/test/validations_test.rb
r4596 r4918 27 27 r = Reply.new 28 28 r.title = "There's no content!" 29 assert !r. save, "A reply without content shouldn't be saveable"29 assert !r.valid?, "A reply without content shouldn't be saveable" 30 30 31 31 r.content = "Messa content!" 32 assert r. save, "A reply with content should be saveable"32 assert r.valid?, "A reply with content should be saveable" 33 33 end 34 34 … … 36 36 r = Reply.new 37 37 r.title = "There's no content!" 38 r.save38 assert !r.valid? 39 39 assert r.errors.invalid?("content"), "A reply without content should mark that attribute as invalid" 40 40 assert_equal "Empty", r.errors.on("content"), "A reply without content should contain an error" … … 44 44 def test_double_attr_validation_and_error_msg 45 45 r = Reply.new 46 assert !r. save46 assert !r.valid? 47 47 48 48 assert r.errors.invalid?("title"), "A reply without title should mark that attribute as invalid" … … 58 58 r = Reply.new 59 59 r.title = "Wrong Create" 60 assert !r. save60 assert !r.valid? 61 61 assert r.errors.invalid?("title"), "A reply with a bad title should mark that attribute as invalid" 62 62 assert_equal "is Wrong Create", r.errors.on("title"), "A reply with a bad content should contain an error" … … 173 173 end 174 174 175 def test_ title_confirmation_no_confirm175 def test_no_title_confirmation 176 176 Topic.validates_confirmation_of(:title) 177 177 178 t = Topic.create("title" => "We should not be confirmed") 179 assert t.save 178 t = Topic.new(:author_name => "Plutarch") 179 assert t.valid? 180 181 t.title_confirmation = "Parallel Lives" 182 assert t.valid? 183 184 t.title_confirmation = nil 185 t.title = "Parallel Lives" 186 assert !t.valid? 187 188 t.title_confirmation = "Parallel Lives" 189 assert t.valid? 180 190 end 181 191 … … 710 720 t = Topic.create("title" => "äžäºäžåäº", "content" => "whatever") 711 721 assert t.valid? 712 722 713 723 t.title = "äžäº34äºå 714 724 " … … 756 766 assert t.errors.on(:title) 757 767 assert_equal "é·ãããŸã: 10", t.errors[:title] 758 768 759 769 t.title = "äžäºäžåäºå 760 770 äžå 761 771 «ä¹" 762 772 assert t.save 763 773 764 774 t.title = "äžäº3" 765 775 assert t.save 766 776 767 777 t.content = "äžäºäžåäºå 768 778 äžå 769 779 «ä¹å" 770 780 assert t.save 771 781 772 782 t.content = t.title = "äžäºäžåäºå 773 783 " … … 783 793 assert !t.save 784 794 assert t.errors.on(:title) 785 795 786 796 t.title = "1äºäž4" 787 797 assert !t.save 788 798 assert t.errors.on(:title) 789 799 assert_equal "çãããŸã: 5", t.errors[:title] 790 800 791 801 t.title = "valid" 792 802 t.content = "äžäºäžåäºå … … 795 805 assert !t.save 796 806 assert t.errors.on(:content) 797 807 798 808 t.content = "äžäº345" 799 809 assert t.save … … 864 874 865 875 def test_throw_away_typing 866 d = Developer. create "name" => "David", "salary" => "100,000"876 d = Developer.new("name" => "David", "salary" => "100,000") 867 877 assert !d.valid? 868 878 assert_equal 100, d.salary … … 879 889 880 890 def test_validates_confirmation_of_with_custom_error_using_quotes 881 Developer.validates_confirmation_of :name, :message=> " This string contains'single' and \"double\" quotes"891 Developer.validates_confirmation_of :name, :message=> "confirm 'single' and \"double\" quotes" 882 892 d = Developer.new 883 893 d.name = "John" 884 894 d.name_confirmation = "Johnny" 885 895 assert !d.valid? 886 assert_equal d.errors.on(:name), "This string contains 'single' and \"double\" quotes"896 assert_equal "confirm 'single' and \"double\" quotes", d.errors.on(:name) 887 897 end 888 898 889 899 def test_validates_format_of_with_custom_error_using_quotes 890 Developer.validates_format_of :name, :with => /^(A-Z*)$/, :message=> " This string contains'single' and \"double\" quotes"900 Developer.validates_format_of :name, :with => /^(A-Z*)$/, :message=> "format 'single' and \"double\" quotes" 891 901 d = Developer.new 892 d.name = "John 32"902 d.name = d.name_confirmation = "John 32" 893 903 assert !d.valid? 894 assert_equal d.errors.on(:name), "This string contains 'single' and \"double\" quotes"904 assert_equal "format 'single' and \"double\" quotes", d.errors.on(:name) 895 905 end 896 906 … … 900 910 d.salary = "90,000" 901 911 assert !d.valid? 902 assert_equal d.errors.on(:salary).first, "This string contains 'single' and \"double\" quotes"912 assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:salary).first 903 913 end 904 914 … … 908 918 d.name = "Jeffrey" 909 919 assert !d.valid? 910 assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes"920 assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first 911 921 end 912 922 … … 916 926 d.name = "Joe" 917 927 assert !d.valid? 918 assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes"928 assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first 919 929 end 920 930 … … 924 934 d.name = "Joe" 925 935 assert !d.valid? 926 assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes"936 assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first 927 937 end 928 938 … … 932 942 d.name = "Joe" 933 943 assert !d.valid? 934 assert_equal d.errors.on(:non_existent), "This string contains 'single' and \"double\" quotes"944 assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:non_existent) 935 945 end 936 946 … … 940 950 d.name = "David" 941 951 assert !d.valid? 942 assert_equal d.errors.on(:name).first, "This string contains 'single' and \"double\" quotes"952 assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first 943 953 end 944 954 … … 949 959 r.topic = Topic.create("title" => "uhohuhoh") 950 960 assert !r.valid? 951 assert_equal r.errors.on(:topic).first, "This string contains 'single' and \"double\" quotes"961 assert_equal "This string contains 'single' and \"double\" quotes", r.errors.on(:topic).first 952 962 end 953 963 … … 966 976 t = Topic.create("title" => "uhohuhoh", "content" => "whatever") 967 977 assert t.valid? 968 assert !t.errors.on(:title) 978 assert !t.errors.on(:title) 969 979 end 970 980