Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 95 lines (76 sloc) 2.944 kB
4f9a8b0 @augustl Adding a very basic livevalidation.com adapter. It supports presence …
augustl authored
1 require File.join(File.dirname(__FILE__), "test_helper")
2
3 class LiveValidationsDotComTest < ActiveSupport::TestCase
4 def setup
f039f1f @augustl Improving the test suite by not using a vendored rails app in test/, …
augustl authored
5 reset_database
4f9a8b0 @augustl Adding a very basic livevalidation.com adapter. It supports presence …
augustl authored
6 reset_callbacks Post
b0fcede @augustl It's livevalidation.com, not livevalidations.com.
augustl authored
7 LiveValidations.use(LiveValidations::Adapters::LivevalidationDotCom)
4f9a8b0 @augustl Adding a very basic livevalidation.com adapter. It supports presence …
augustl authored
8 end
9
10 def teardown
11 restore_callbacks Post
12 end
13
14 def test_presence
15 Post.validates_presence_of :title
05744fa @augustl Refactoring the livevalidations.com adapter, now that we got this new…
augustl authored
16 assert_validators :title, "Presence"
4f9a8b0 @augustl Adding a very basic livevalidation.com adapter. It supports presence …
augustl authored
17 end
18
19 def test_format
20 Post.validates_format_of :title, :with => /ohai/
dcc1cf7 @augustl Forgot to update the tests when I changed the regexp mechanics. There.
augustl authored
21 assert_validators :title, "Format", :pattern => /ohai/
4f9a8b0 @augustl Adding a very basic livevalidation.com adapter. It supports presence …
augustl authored
22 end
23
c24d145 @augustl Adding some more validations to the livevalidation.com adapter.
augustl authored
24 def test_numericality
25 Post.validates_numericality_of :age
05744fa @augustl Refactoring the livevalidations.com adapter, now that we got this new…
augustl authored
26 assert_validators :age, "Numericality"
c24d145 @augustl Adding some more validations to the livevalidation.com adapter.
augustl authored
27 end
05744fa @augustl Refactoring the livevalidations.com adapter, now that we got this new…
augustl authored
28
c24d145 @augustl Adding some more validations to the livevalidation.com adapter.
augustl authored
29 def test_length_with_minimum
30 Post.validates_length_of :title, :minimum => 10
05744fa @augustl Refactoring the livevalidations.com adapter, now that we got this new…
augustl authored
31 assert_validators :title, "Length", :minimum => 10
c24d145 @augustl Adding some more validations to the livevalidation.com adapter.
augustl authored
32 end
33
34 def test_length_with_maximum
35 Post.validates_length_of :title, :maximum => 10
05744fa @augustl Refactoring the livevalidations.com adapter, now that we got this new…
augustl authored
36 assert_validators :title, "Length", :maximum => 10
c24d145 @augustl Adding some more validations to the livevalidation.com adapter.
augustl authored
37 end
38
39 def test_length_with_range
40 Post.validates_length_of :title, :within => 10..20
05744fa @augustl Refactoring the livevalidations.com adapter, now that we got this new…
augustl authored
41 assert_validators :title, "Length", :minimum => 10, :maximum => 20
c24d145 @augustl Adding some more validations to the livevalidation.com adapter.
augustl authored
42 end
43
44 def test_length_with_is
45 Post.validates_length_of :title, :is => 20
05744fa @augustl Refactoring the livevalidations.com adapter, now that we got this new…
augustl authored
46 assert_validators :title, "Length", :is => 20
c24d145 @augustl Adding some more validations to the livevalidation.com adapter.
augustl authored
47 end
48
8e4b34b @augustl Adding a shitload of validators to the livevalidation.com plugin. Onl…
augustl authored
49 def test_inclusion_with_numeric_range
50 Post.validates_inclusion_of :age, :in => 10..20
51 assert_validators :age, "Numericality", :minimum => 10, :maximum => 20
52 end
53
54 def test_inclusion_with_string_range
55 Post.validates_inclusion_of :title, :in => "a".."f"
56 assert_validators :title, "Inclusion", :within => %w(a b c d e f)
57 end
58
59 def test_inclusion_with_array
60 Post.validates_inclusion_of :title, :in => ["Darn", "that", "cencorship"]
61 assert_validators :title, "Inclusion", :within => ["Darn", "that", "cencorship"]
62 end
63
64 def test_exclusion_of_with_range
65 Post.validates_exclusion_of :age, :in => 0..4
66 assert_validators :age, "Exclusion", :within => [0, 1, 2, 3, 4]
67 end
68
69 def test_exclusion_of_with_array
70 Post.validates_exclusion_of :title, :in => ["Admin", "Only"]
71 assert_validators :title, "Exclusion", :within => ["Admin", "Only"]
72 end
73
74 def test_acceptance
75 Post.validates_acceptance_of :check_me
76 assert_validators :check_me, "Acceptance"
77 end
78
79 def test_confirmation
80 Post.validates_confirmation_of :password
81 assert_validators :password_confirmation, "Confirmation", :match => "post_password"
82 end
83
05744fa @augustl Refactoring the livevalidations.com adapter, now that we got this new…
augustl authored
84 def assert_validators(attribute, expected_validator, json = {})
4f9a8b0 @augustl Adding a very basic livevalidation.com adapter. It supports presence …
augustl authored
85 validator = LiveValidations.current_adapter.new(Post.new)
fa6e8f9 @augustl Now only adding validations for visible form fields.
augustl authored
86 validator.expects(:callback_has_visible_attributes?).returns(true)
87 validator.perform_validations
88
05744fa @augustl Refactoring the livevalidations.com adapter, now that we got this new…
augustl authored
89 assert validator[:validators][attribute].has_key?(expected_validator), "The validator did not include `#{expected_validator}'."
90
91 json.each do |key, value|
92 assert_equal value, validator[:validators][attribute][expected_validator][key]
93 end
4f9a8b0 @augustl Adding a very basic livevalidation.com adapter. It supports presence …
augustl authored
94 end
95 end
Something went wrong with that request. Please try again.