gettext 1.91.0 → 1.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +111 -1
- data/NEWS +35 -0
- data/README +26 -24
- data/bin/rgettext +2 -2
- data/bin/rmsgfmt +2 -2
- data/bin/rmsgmerge +2 -2
- data/doc/classes/ActionView/Helpers/FormBuilder.html +11 -11
- data/doc/classes/ActionView/TemplateFinder.html +152 -0
- data/doc/classes/ActiveRecord/Base.html +87 -87
- data/doc/classes/ActiveRecord/ConnectionAdapters/Column.html +6 -6
- data/doc/classes/GetText.html +617 -491
- data/doc/classes/GetText/ActiveRecordParser.html +13 -13
- data/doc/classes/GetText/ErbContainer.html +12 -12
- data/doc/classes/GetText/ErbParser.html +6 -6
- data/doc/classes/GetText/NoboundTextDomainError.html +1 -1
- data/doc/classes/GetText/PoParser.html +11 -11
- data/doc/classes/GetText/Rails.html +20 -20
- data/doc/classes/GetText/RubyParser.html +5 -0
- data/doc/classes/GetText/TextDomain.html +53 -53
- data/doc/classes/GetText/TextDomainManager.html +54 -54
- data/doc/classes/Iconv.html +20 -20
- data/doc/classes/Locale.html +151 -151
- data/doc/classes/Locale/Object.html +92 -92
- data/doc/classes/Locale/SystemBase.html +32 -32
- data/doc/classes/Locale/SystemCGI.html +31 -31
- data/doc/classes/Locale/SystemWin32.html +6 -6
- data/doc/classes/MOFile.html +311 -293
- data/doc/classes/MOFile/HeaderRev1.html +150 -0
- data/doc/classes/Module.html +6 -6
- data/doc/created.rid +1 -1
- data/doc/files/ChangeLog.html +143 -2
- data/doc/files/README.html +31 -25
- data/doc/files/lib/gettext/active_record_rb.html +1 -1
- data/doc/files/lib/gettext/mo_rb.html +1 -1
- data/doc/files/lib/gettext/parser/active_record_rb.html +1 -1
- data/doc/files/lib/gettext/parser/ruby_rb.html +1 -1
- data/doc/files/lib/gettext/poparser_rb.html +1 -1
- data/doc/files/lib/gettext/rails_rb.html +1 -1
- data/doc/files/lib/gettext/rgettext_rb.html +1 -1
- data/doc/files/lib/gettext/rmsgfmt_rb.html +2 -1
- data/doc/files/lib/gettext/utils_rb.html +1 -1
- data/doc/files/lib/gettext/version_rb.html +1 -1
- data/doc/files/lib/gettext_rb.html +1 -1
- data/doc/fr_class_index.html +2 -0
- data/doc/fr_method_index.html +133 -129
- data/lib/gettext.rb +49 -7
- data/lib/gettext/active_record.rb +49 -4
- data/lib/gettext/mo.rb +39 -12
- data/lib/gettext/parser/active_record.rb +6 -4
- data/lib/gettext/parser/ruby.rb +11 -4
- data/lib/gettext/poparser.rb +81 -52
- data/lib/gettext/rails.rb +28 -11
- data/lib/gettext/rgettext.rb +6 -1
- data/lib/gettext/rmsgfmt.rb +3 -11
- data/lib/gettext/utils.rb +7 -3
- data/lib/gettext/version.rb +1 -1
- data/po/bs/rails.po +55 -20
- data/po/bs/rgettext.po +3 -3
- data/po/ca/rails.po +58 -31
- data/po/ca/rgettext.po +16 -18
- data/po/cs/rails.po +55 -20
- data/po/cs/rgettext.po +3 -3
- data/po/de/rails.po +55 -27
- data/po/de/rgettext.po +21 -22
- data/po/el/rails.po +60 -36
- data/po/el/rgettext.po +15 -17
- data/po/eo/rails.po +51 -23
- data/po/eo/rgettext.po +21 -20
- data/po/es/rails.po +57 -31
- data/po/es/rgettext.po +17 -18
- data/po/et/rails.po +55 -20
- data/po/fr/rails.po +56 -21
- data/po/fr/rgettext.po +3 -3
- data/po/hr/rails.po +55 -20
- data/po/hr/rgettext.po +3 -3
- data/po/hu/rails.po +54 -26
- data/po/hu/rgettext.po +18 -17
- data/po/it/rails.po +55 -20
- data/po/it/rgettext.po +3 -3
- data/po/ja/rails.po +54 -26
- data/po/ja/rgettext.po +17 -18
- data/po/ko/rails.po +56 -21
- data/po/ko/rgettext.po +3 -3
- data/po/lv/rails.po +155 -0
- data/po/lv/rgettext.po +137 -0
- data/po/nb/rails.po +61 -34
- data/po/nb/rgettext.po +22 -19
- data/po/nl/rails.po +56 -21
- data/po/nl/rgettext.po +3 -3
- data/po/pt_BR/rails.po +53 -26
- data/po/pt_BR/rgettext.po +19 -19
- data/po/rails.pot +44 -16
- data/po/rgettext.pot +3 -3
- data/po/ru/rails.po +62 -36
- data/po/ru/rgettext.po +19 -19
- data/po/sr/rails.po +87 -58
- data/po/sr/rgettext.po +38 -33
- data/po/sv/rgettext.po +3 -3
- data/po/ua/rails.po +62 -32
- data/po/ua/rgettext.po +19 -17
- data/po/vi/rails.po +56 -28
- data/po/vi/rgettext.po +35 -34
- data/po/zh/rails.po +52 -24
- data/po/zh/rgettext.po +22 -24
- data/po/zh_TW/rails.po +51 -23
- data/po/zh_TW/rgettext.po +16 -18
- data/samples/cgi/cookie.cgi +0 -0
- data/samples/cgi/helloerb1.cgi +0 -0
- data/samples/cgi/helloerb2.cgi +0 -0
- data/samples/cgi/http.rb +0 -0
- data/samples/cgi/index.cgi +0 -0
- data/samples/cgi/po/lv/helloerb1.po +65 -0
- data/samples/cgi/po/lv/helloerb2.po +52 -0
- data/samples/cgi/po/lv/hellolib.po +24 -0
- data/samples/cgi/po/lv/main.po +77 -0
- data/samples/cgi/po/nb/helloerb1.po +16 -14
- data/samples/cgi/po/nb/helloerb2.po +14 -12
- data/samples/cgi/po/nb/hellolib.po +9 -7
- data/samples/cgi/po/nb/main.po +20 -18
- data/samples/cgi/po/sr/helloerb1.po +8 -8
- data/samples/cgi/po/sr/helloerb2.po +6 -6
- data/samples/cgi/po/sr/hellolib.po +2 -2
- data/samples/cgi/po/sr/main.po +15 -15
- data/samples/cgi/po/ua/helloerb1.po +2 -2
- data/samples/cgi/po/ua/main.po +3 -3
- data/samples/hello_plural.rb +0 -0
- data/samples/makemo.rb +0 -0
- data/samples/po/lv/hello.po +24 -0
- data/samples/po/lv/hello2.po +32 -0
- data/samples/po/lv/hello_noop.po +28 -0
- data/samples/po/lv/hello_plural.po +26 -0
- data/samples/po/lv/helloglade2.po +38 -0
- data/samples/po/lv/hellogtk.po +24 -0
- data/samples/po/lv/hellotk.po +24 -0
- data/samples/po/nb/hello.po +9 -8
- data/samples/po/nb/hello2.po +9 -9
- data/samples/po/nb/hello_noop.po +10 -9
- data/samples/po/nb/hello_plural.po +10 -8
- data/samples/po/nb/helloglade2.po +10 -8
- data/samples/po/nb/hellogtk.po +9 -8
- data/samples/po/nb/hellotk.po +9 -7
- data/samples/po/sr/hello.po +2 -2
- data/samples/po/sr/hello2.po +4 -4
- data/samples/po/sr/hello_noop.po +3 -3
- data/samples/po/sr/hello_plural.po +3 -3
- data/samples/po/sr/helloglade2.po +4 -4
- data/samples/po/sr/hellogtk.po +2 -2
- data/samples/po/sr/hellotk.po +2 -2
- data/samples/po/ua/hello2.po +2 -2
- data/samples/po/ua/hello_plural.po +2 -2
- data/samples/rails/config/boot.rb +3 -2
- data/samples/rails/config/environment.rb +2 -3
- data/samples/rails/db/schema.rb +0 -0
- data/samples/rails/po/lv/blog.po +110 -0
- data/samples/rails/po/nb/blog.po +19 -15
- data/samples/rails/po/sr/blog.po +23 -23
- data/samples/rails/po/ua/blog.po +3 -3
- data/samples/rails/public/dispatch.cgi +0 -0
- data/samples/rails/public/dispatch.fcgi +0 -0
- data/samples/rails/public/dispatch.rb +0 -0
- data/samples/rails/public/javascripts/controls.js +1 -1
- data/samples/rails/public/javascripts/dragdrop.js +1 -1
- data/samples/rails/public/javascripts/effects.js +1 -1
- data/samples/rails/script/about +0 -0
- data/samples/rails/script/breakpointer +0 -0
- data/samples/rails/script/console +0 -0
- data/samples/rails/script/destroy +0 -0
- data/samples/rails/script/generate +0 -0
- data/samples/rails/script/performance/benchmarker +0 -0
- data/samples/rails/script/performance/profiler +0 -0
- data/samples/rails/script/plugin +0 -0
- data/samples/rails/script/process/reaper +0 -0
- data/samples/rails/script/process/spawner +0 -0
- data/samples/rails/script/process/spinner +0 -0
- data/samples/rails/script/runner +0 -0
- data/samples/rails/script/server +0 -0
- data/samples/rails/vendor/plugins/gettext/po/lv/gettext_plugin.po +28 -0
- data/samples/rails/vendor/plugins/gettext/po/nb/gettext_plugin.po +11 -8
- data/samples/rails/vendor/plugins/gettext/po/sr/gettext_plugin.po +5 -5
- data/src/poparser.ry +27 -6
- data/test/benchmark.rb +1 -1
- data/test/db/mysql.drop.sql +1 -0
- data/test/db/mysql.sql +13 -0
- data/test/fixtures/inept_wizard.rb +3 -0
- data/test/fixtures/people.yml +6 -0
- data/test/fixtures/topic.rb +30 -0
- data/test/fixtures/wizard.rb +5 -0
- data/test/po/active_record.pot +151 -66
- data/test/po/ja/active_record.po +177 -92
- data/test/po/ja/test_pgettext.po +41 -0
- data/test/rails/app/controllers/users_controller.rb +1 -0
- data/test/rails/app/views/articles/_form_fr.html.erb +1 -0
- data/test/rails/config/boot.rb +96 -32
- data/test/rails/config/environment.rb +3 -2
- data/test/rails/db/schema.rb +4 -4
- data/test/rails/public/dispatch.cgi +0 -0
- data/test/rails/public/dispatch.fcgi +0 -0
- data/test/rails/public/dispatch.rb +0 -0
- data/test/rails/public/javascripts/controls.js +484 -354
- data/test/rails/public/javascripts/dragdrop.js +88 -58
- data/test/rails/public/javascripts/effects.js +396 -364
- data/test/rails/public/javascripts/prototype.js +2817 -1107
- data/test/rails/script/about +0 -0
- data/test/rails/script/breakpointer +0 -0
- data/test/rails/script/console +0 -0
- data/test/rails/script/destroy +0 -0
- data/test/rails/script/generate +0 -0
- data/test/rails/script/performance/benchmarker +0 -0
- data/test/rails/script/performance/profiler +0 -0
- data/test/rails/script/plugin +0 -0
- data/test/rails/script/process/inspector +0 -0
- data/test/rails/script/process/reaper +0 -0
- data/test/rails/script/process/spawner +0 -0
- data/test/rails/script/runner +0 -0
- data/test/rails/script/server +0 -0
- data/test/rails/test/functional/articles_controller_test.rb +5 -0
- data/test/rails/test/result/en/create_error.html +3 -3
- data/test/rails/test/result/en/custom_error_message.html +3 -3
- data/test/rails/test/result/en/custom_error_message_with_plural.html +60 -60
- data/test/rails/test/result/en/multi_error_messages_for.html +6 -6
- data/test/rails/test/result/en/new.html +3 -3
- data/test/rails/test/result/fr/custom_error_message.html +3 -3
- data/test/rails/test/result/fr/custom_error_message_with_plural.html +60 -60
- data/test/rails/test/result/fr/new.html +23 -0
- data/test/rails/test/result/ja/create_error.html +3 -3
- data/test/rails/test/result/ja/custom_error_message.html +3 -3
- data/test/rails/test/result/ja/custom_error_message_with_plural.html +60 -60
- data/test/rails/test/result/ja/multi_error_messages_for.html +6 -6
- data/test/rails/test/result/ja/new.html +3 -3
- data/test/test.sh +2 -2
- data/test/test_active_record.rb +824 -20
- data/test/test_gettext.rb +34 -4
- data/test/test_java.sh +0 -0
- data/test/test_locale.rb +2 -2
- data/test/test_parser.rb +13 -2
- data/test/test_rails_caching.rb +11 -4
- data/test/testlib/pgettext.rb +33 -0
- metadata +32 -4
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
|
4
|
+
<title>Ruby-GetText-Package Test Application</title>
|
|
5
|
+
<link href="/stylesheets/scaffold.css" media="screen" rel="Stylesheet" type="text/css" />
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
|
|
9
|
+
<p style="color: green"></p>
|
|
10
|
+
|
|
11
|
+
<h1>New article</h1>
|
|
12
|
+
|
|
13
|
+
<form action="/articles/create" method="post">
|
|
14
|
+
<h1>FRENCH</h1>
|
|
15
|
+
|
|
16
|
+
<input name="commit" type="submit" value="Create" />
|
|
17
|
+
</form>
|
|
18
|
+
|
|
19
|
+
<a href="/articles/list">Back</a>
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
<option value="2004">2004</option>
|
|
28
28
|
<option value="2005">2005</option>
|
|
29
29
|
<option value="2006">2006</option>
|
|
30
|
-
<option
|
|
30
|
+
<option selected="selected" value="2007">2007</option>
|
|
31
31
|
<option value="2008">2008</option>
|
|
32
32
|
<option value="2009">2009</option>
|
|
33
33
|
<option value="2010">2010</option>
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
<option value="1">January</option>
|
|
39
39
|
<option value="2">February</option>
|
|
40
40
|
<option value="3">March</option>
|
|
41
|
-
<option
|
|
41
|
+
<option selected="selected" value="4">April</option>
|
|
42
42
|
<option value="5">May</option>
|
|
43
43
|
<option value="6">June</option>
|
|
44
44
|
<option value="7">July</option>
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
<option value="12">December</option>
|
|
50
50
|
</select>
|
|
51
51
|
<select id="article_lastupdate_3i" name="article[lastupdate(3i)]">
|
|
52
|
-
<option
|
|
52
|
+
<option selected="selected" value="1">1</option>
|
|
53
53
|
<option value="2">2</option>
|
|
54
54
|
<option value="3">3</option>
|
|
55
55
|
<option value="4">4</option>
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
<option value="2004">2004</option>
|
|
21
21
|
<option value="2005">2005</option>
|
|
22
22
|
<option value="2006">2006</option>
|
|
23
|
-
<option
|
|
23
|
+
<option selected="selected" value="2007">2007</option>
|
|
24
24
|
<option value="2008">2008</option>
|
|
25
25
|
<option value="2009">2009</option>
|
|
26
26
|
<option value="2010">2010</option>
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
<option value="2012">2012</option>
|
|
29
29
|
</select>
|
|
30
30
|
<select id="user_lastupdate_2i" name="user[lastupdate(2i)]">
|
|
31
|
-
<option
|
|
31
|
+
<option selected="selected" value="1">January</option>
|
|
32
32
|
<option value="2">February</option>
|
|
33
33
|
<option value="3">March</option>
|
|
34
34
|
<option value="4">April</option>
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
<option value="12">December</option>
|
|
43
43
|
</select>
|
|
44
44
|
<select id="user_lastupdate_3i" name="user[lastupdate(3i)]">
|
|
45
|
-
<option
|
|
45
|
+
<option selected="selected" value="1">1</option>
|
|
46
46
|
<option value="2">2</option>
|
|
47
47
|
<option value="3">3</option>
|
|
48
48
|
<option value="4">4</option>
|
|
@@ -14,66 +14,66 @@
|
|
|
14
14
|
<div class="fieldWithErrors"><input id="user_name" name="user[name]" size="30" type="text" value="foo" /></div></p>
|
|
15
15
|
|
|
16
16
|
<p><label for="user_lastupdate">最終更新日</label><br/>
|
|
17
|
-
<div class="fieldWithErrors"><select id="user_lastupdate_1i" name="user[lastupdate(1i)]">
|
|
18
|
-
<option value="
|
|
19
|
-
<option value="
|
|
20
|
-
<option value="
|
|
21
|
-
<option value="
|
|
22
|
-
<option value="
|
|
23
|
-
<
|
|
24
|
-
<option value="
|
|
25
|
-
<option value="
|
|
26
|
-
<option value="
|
|
27
|
-
<option value="
|
|
28
|
-
<option value="
|
|
29
|
-
</select>
|
|
30
|
-
<select id="user_lastupdate_2i" name="user[lastupdate(2i)]">
|
|
31
|
-
<option value="1">January</option>
|
|
32
|
-
<option value="2">February</option>
|
|
33
|
-
<option value="3">March</option>
|
|
34
|
-
<option value="4">April</option>
|
|
35
|
-
<
|
|
36
|
-
<option value="6">June</option>
|
|
37
|
-
<option value="7">July</option>
|
|
38
|
-
<option value="8">August</option>
|
|
39
|
-
<option value="9">September</option>
|
|
40
|
-
<option value="10">October</option>
|
|
41
|
-
<option value="11">November</option>
|
|
42
|
-
<option value="12">December</option>
|
|
43
|
-
</select>
|
|
44
|
-
<select id="user_lastupdate_3i" name="user[lastupdate(3i)]">
|
|
45
|
-
<option value="1">1</option>
|
|
46
|
-
<option value="2">2</option>
|
|
47
|
-
<option value="3">3</option>
|
|
48
|
-
<option value="4">4</option>
|
|
49
|
-
<option value="5">5</option>
|
|
50
|
-
<
|
|
51
|
-
<option value="7">7</option>
|
|
52
|
-
<option value="8">8</option>
|
|
53
|
-
<option value="9">9</option>
|
|
54
|
-
<option value="10">10</option>
|
|
55
|
-
<option value="11">11</option>
|
|
56
|
-
<option value="12">12</option>
|
|
57
|
-
<option value="13">13</option>
|
|
58
|
-
<option value="14">14</option>
|
|
59
|
-
<option value="15">15</option>
|
|
60
|
-
<option value="16">16</option>
|
|
61
|
-
<option value="17">17</option>
|
|
62
|
-
<option value="18">18</option>
|
|
63
|
-
<option value="19">19</option>
|
|
64
|
-
<option value="20">20</option>
|
|
65
|
-
<option value="21">21</option>
|
|
66
|
-
<option value="22">22</option>
|
|
67
|
-
<option value="23">23</option>
|
|
68
|
-
<option value="24">24</option>
|
|
69
|
-
<option value="25">25</option>
|
|
70
|
-
<option value="26">26</option>
|
|
71
|
-
<option value="27">27</option>
|
|
72
|
-
<option value="28">28</option>
|
|
73
|
-
<option value="29">29</option>
|
|
74
|
-
<option value="30">30</option>
|
|
75
|
-
<option value="31">31</option>
|
|
76
|
-
</select>
|
|
17
|
+
<div class="fieldWithErrors"><div class="fieldWithErrors"><select id="user_lastupdate_1i" name="user[lastupdate(1i)]">
|
|
18
|
+
<div class="fieldWithErrors"><option value="2002">2002</option></div>
|
|
19
|
+
<div class="fieldWithErrors"><option value="2003">2003</option></div>
|
|
20
|
+
<div class="fieldWithErrors"><option value="2004">2004</option></div>
|
|
21
|
+
<div class="fieldWithErrors"><option value="2005">2005</option></div>
|
|
22
|
+
<div class="fieldWithErrors"><option value="2006">2006</option></div>
|
|
23
|
+
<div class="fieldWithErrors"><option selected="selected" value="2007">2007</option></div>
|
|
24
|
+
<div class="fieldWithErrors"><option value="2008">2008</option></div>
|
|
25
|
+
<div class="fieldWithErrors"><option value="2009">2009</option></div>
|
|
26
|
+
<div class="fieldWithErrors"><option value="2010">2010</option></div>
|
|
27
|
+
<div class="fieldWithErrors"><option value="2011">2011</option></div>
|
|
28
|
+
<div class="fieldWithErrors"><option value="2012">2012</option></div>
|
|
29
|
+
</select></div>
|
|
30
|
+
<div class="fieldWithErrors"><select id="user_lastupdate_2i" name="user[lastupdate(2i)]">
|
|
31
|
+
<div class="fieldWithErrors"><option selected="selected" value="1">January</option></div>
|
|
32
|
+
<div class="fieldWithErrors"><option value="2">February</option></div>
|
|
33
|
+
<div class="fieldWithErrors"><option value="3">March</option></div>
|
|
34
|
+
<div class="fieldWithErrors"><option value="4">April</option></div>
|
|
35
|
+
<div class="fieldWithErrors"><option value="5">May</option></div>
|
|
36
|
+
<div class="fieldWithErrors"><option value="6">June</option></div>
|
|
37
|
+
<div class="fieldWithErrors"><option value="7">July</option></div>
|
|
38
|
+
<div class="fieldWithErrors"><option value="8">August</option></div>
|
|
39
|
+
<div class="fieldWithErrors"><option value="9">September</option></div>
|
|
40
|
+
<div class="fieldWithErrors"><option value="10">October</option></div>
|
|
41
|
+
<div class="fieldWithErrors"><option value="11">November</option></div>
|
|
42
|
+
<div class="fieldWithErrors"><option value="12">December</option></div>
|
|
43
|
+
</select></div>
|
|
44
|
+
<div class="fieldWithErrors"><select id="user_lastupdate_3i" name="user[lastupdate(3i)]">
|
|
45
|
+
<div class="fieldWithErrors"><option selected="selected" value="1">1</option></div>
|
|
46
|
+
<div class="fieldWithErrors"><option value="2">2</option></div>
|
|
47
|
+
<div class="fieldWithErrors"><option value="3">3</option></div>
|
|
48
|
+
<div class="fieldWithErrors"><option value="4">4</option></div>
|
|
49
|
+
<div class="fieldWithErrors"><option value="5">5</option></div>
|
|
50
|
+
<div class="fieldWithErrors"><option value="6">6</option></div>
|
|
51
|
+
<div class="fieldWithErrors"><option value="7">7</option></div>
|
|
52
|
+
<div class="fieldWithErrors"><option value="8">8</option></div>
|
|
53
|
+
<div class="fieldWithErrors"><option value="9">9</option></div>
|
|
54
|
+
<div class="fieldWithErrors"><option value="10">10</option></div>
|
|
55
|
+
<div class="fieldWithErrors"><option value="11">11</option></div>
|
|
56
|
+
<div class="fieldWithErrors"><option value="12">12</option></div>
|
|
57
|
+
<div class="fieldWithErrors"><option value="13">13</option></div>
|
|
58
|
+
<div class="fieldWithErrors"><option value="14">14</option></div>
|
|
59
|
+
<div class="fieldWithErrors"><option value="15">15</option></div>
|
|
60
|
+
<div class="fieldWithErrors"><option value="16">16</option></div>
|
|
61
|
+
<div class="fieldWithErrors"><option value="17">17</option></div>
|
|
62
|
+
<div class="fieldWithErrors"><option value="18">18</option></div>
|
|
63
|
+
<div class="fieldWithErrors"><option value="19">19</option></div>
|
|
64
|
+
<div class="fieldWithErrors"><option value="20">20</option></div>
|
|
65
|
+
<div class="fieldWithErrors"><option value="21">21</option></div>
|
|
66
|
+
<div class="fieldWithErrors"><option value="22">22</option></div>
|
|
67
|
+
<div class="fieldWithErrors"><option value="23">23</option></div>
|
|
68
|
+
<div class="fieldWithErrors"><option value="24">24</option></div>
|
|
69
|
+
<div class="fieldWithErrors"><option value="25">25</option></div>
|
|
70
|
+
<div class="fieldWithErrors"><option value="26">26</option></div>
|
|
71
|
+
<div class="fieldWithErrors"><option value="27">27</option></div>
|
|
72
|
+
<div class="fieldWithErrors"><option value="28">28</option></div>
|
|
73
|
+
<div class="fieldWithErrors"><option value="29">29</option></div>
|
|
74
|
+
<div class="fieldWithErrors"><option value="30">30</option></div>
|
|
75
|
+
<div class="fieldWithErrors"><option value="31">31</option></div>
|
|
76
|
+
</select></div>
|
|
77
77
|
</div></p>
|
|
78
78
|
<!--[eoform:article]-->
|
|
79
79
|
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
<option value="2004">2004</option>
|
|
25
25
|
<option value="2005">2005</option>
|
|
26
26
|
<option value="2006">2006</option>
|
|
27
|
-
<option
|
|
27
|
+
<option selected="selected" value="2007">2007</option>
|
|
28
28
|
<option value="2008">2008</option>
|
|
29
29
|
<option value="2009">2009</option>
|
|
30
30
|
<option value="2010">2010</option>
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
<option value="1">January</option>
|
|
36
36
|
<option value="2">February</option>
|
|
37
37
|
<option value="3">March</option>
|
|
38
|
-
<option
|
|
38
|
+
<option selected="selected" value="4">April</option>
|
|
39
39
|
<option value="5">May</option>
|
|
40
40
|
<option value="6">June</option>
|
|
41
41
|
<option value="7">July</option>
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
<option value="12">December</option>
|
|
47
47
|
</select>
|
|
48
48
|
<select id="article_lastupdate_3i" name="article[lastupdate(3i)]">
|
|
49
|
-
<option
|
|
49
|
+
<option selected="selected" value="1">1</option>
|
|
50
50
|
<option value="2">2</option>
|
|
51
51
|
<option value="3">3</option>
|
|
52
52
|
<option value="4">4</option>
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
<option value="2004">2004</option>
|
|
91
91
|
<option value="2005">2005</option>
|
|
92
92
|
<option value="2006">2006</option>
|
|
93
|
-
<option
|
|
93
|
+
<option selected="selected" value="2007">2007</option>
|
|
94
94
|
<option value="2008">2008</option>
|
|
95
95
|
<option value="2009">2009</option>
|
|
96
96
|
<option value="2010">2010</option>
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
<option value="1">January</option>
|
|
102
102
|
<option value="2">February</option>
|
|
103
103
|
<option value="3">March</option>
|
|
104
|
-
<option
|
|
104
|
+
<option selected="selected" value="4">April</option>
|
|
105
105
|
<option value="5">May</option>
|
|
106
106
|
<option value="6">June</option>
|
|
107
107
|
<option value="7">July</option>
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
<option value="12">December</option>
|
|
113
113
|
</select>
|
|
114
114
|
<select id="user_lastupdate_3i" name="user[lastupdate(3i)]">
|
|
115
|
-
<option
|
|
115
|
+
<option selected="selected" value="1">1</option>
|
|
116
116
|
<option value="2">2</option>
|
|
117
117
|
<option value="3">3</option>
|
|
118
118
|
<option value="4">4</option>
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
<option value="2004">2004</option>
|
|
28
28
|
<option value="2005">2005</option>
|
|
29
29
|
<option value="2006">2006</option>
|
|
30
|
-
<option
|
|
30
|
+
<option selected="selected" value="2007">2007</option>
|
|
31
31
|
<option value="2008">2008</option>
|
|
32
32
|
<option value="2009">2009</option>
|
|
33
33
|
<option value="2010">2010</option>
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
<option value="1">January</option>
|
|
39
39
|
<option value="2">February</option>
|
|
40
40
|
<option value="3">March</option>
|
|
41
|
-
<option
|
|
41
|
+
<option selected="selected" value="4">April</option>
|
|
42
42
|
<option value="5">May</option>
|
|
43
43
|
<option value="6">June</option>
|
|
44
44
|
<option value="7">July</option>
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
<option value="12">December</option>
|
|
50
50
|
</select>
|
|
51
51
|
<select id="article_lastupdate_3i" name="article[lastupdate(3i)]">
|
|
52
|
-
<option
|
|
52
|
+
<option selected="selected" value="1">1</option>
|
|
53
53
|
<option value="2">2</option>
|
|
54
54
|
<option value="3">3</option>
|
|
55
55
|
<option value="4">4</option>
|
data/test/test.sh
CHANGED
data/test/test_active_record.rb
CHANGED
|
@@ -11,11 +11,13 @@ require 'active_record/fixtures'
|
|
|
11
11
|
require 'fixtures/topic'
|
|
12
12
|
require 'fixtures/reply'
|
|
13
13
|
require 'fixtures/developer'
|
|
14
|
+
require 'fixtures/wizard'
|
|
15
|
+
require 'fixtures/inept_wizard'
|
|
14
16
|
require 'logger'
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
AR_TEST_VERSION = /activerecord-([^\/]+)/.match($:.join)[1]
|
|
17
19
|
|
|
18
|
-
if
|
|
20
|
+
if AR_TEST_VERSION > "2.0.0"
|
|
19
21
|
#ticket 6657 on dev.rubyonrails.org require this but it becames removed(?)
|
|
20
22
|
AR_6657 = true
|
|
21
23
|
else
|
|
@@ -67,6 +69,12 @@ class Topic
|
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
71
|
|
|
72
|
+
class ProtectedPerson < ActiveRecord::Base
|
|
73
|
+
set_table_name 'people'
|
|
74
|
+
attr_accessor :addon
|
|
75
|
+
attr_protected :first_name
|
|
76
|
+
end
|
|
77
|
+
|
|
70
78
|
class MyModel
|
|
71
79
|
attr_accessor :title
|
|
72
80
|
def save; end
|
|
@@ -83,16 +91,30 @@ class MyModel
|
|
|
83
91
|
validates_presence_of :title
|
|
84
92
|
end
|
|
85
93
|
|
|
94
|
+
class Conjurer < IneptWizard
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
class Thaumaturgist < IneptWizard
|
|
98
|
+
end
|
|
99
|
+
|
|
86
100
|
class ValidationsTest < Test::Unit::TestCase
|
|
87
101
|
fixtures :topics, :developers
|
|
88
102
|
|
|
89
103
|
def setup
|
|
90
104
|
bindtextdomain_to(Topic, "active_record")
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
105
|
+
|
|
106
|
+
if AR_TEST_VERSION < "2.1.0"
|
|
107
|
+
Topic.write_inheritable_attribute(:validate, nil)
|
|
108
|
+
Topic.write_inheritable_attribute(:validate_on_create, nil)
|
|
109
|
+
Topic.write_inheritable_attribute(:validate_on_update, nil)
|
|
110
|
+
else
|
|
111
|
+
Topic.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
|
112
|
+
Topic.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
|
113
|
+
Topic.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
|
114
|
+
end
|
|
94
115
|
end
|
|
95
116
|
|
|
117
|
+
|
|
96
118
|
def test_single_attr_validation_and_error_msg
|
|
97
119
|
GetText.set_locale_all "ja_JP.UTF-8"
|
|
98
120
|
r = Reply.new
|
|
@@ -210,6 +232,77 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
210
232
|
end
|
|
211
233
|
end
|
|
212
234
|
|
|
235
|
+
def test_exception_on_create_bang_many
|
|
236
|
+
assert_raises(ActiveRecord::RecordInvalid) do
|
|
237
|
+
Reply.create!([ { "title" => "OK" }, { "title" => "Wrong Create" }])
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
241
|
+
begin
|
|
242
|
+
Reply.create!([ { "title" => "OK" }, { "title" => "Wrong Create" }])
|
|
243
|
+
rescue ActiveRecord::RecordInvalid => invalid
|
|
244
|
+
assert_equal "入力値が正しくありません。: Reply内容 空です。", invalid.message
|
|
245
|
+
end
|
|
246
|
+
GetText.set_locale_all "en"
|
|
247
|
+
begin
|
|
248
|
+
Reply.create!([ { "title" => "OK" }, { "title" => "Wrong Create" }])
|
|
249
|
+
rescue ActiveRecord::RecordInvalid => invalid
|
|
250
|
+
assert_equal "Validation failed: Content Empty", invalid.message
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def test_exception_on_create_bang_with_block
|
|
256
|
+
assert_raises(ActiveRecord::RecordInvalid) do
|
|
257
|
+
Reply.create!({ "title" => "OK" }) do |r|
|
|
258
|
+
r.content = nil
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
263
|
+
begin
|
|
264
|
+
Reply.create!({ "title" => "OK" }) do |r|
|
|
265
|
+
r.content = nil
|
|
266
|
+
end
|
|
267
|
+
rescue ActiveRecord::RecordInvalid => invalid
|
|
268
|
+
assert_equal "入力値が正しくありません。: Reply内容 空です。", invalid.message
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
GetText.set_locale_all "en"
|
|
272
|
+
begin
|
|
273
|
+
Reply.create!({ "title" => "OK" }) do |r|
|
|
274
|
+
r.content = nil
|
|
275
|
+
end
|
|
276
|
+
rescue ActiveRecord::RecordInvalid => invalid
|
|
277
|
+
assert_equal "Validation failed: Content Empty", invalid.message
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def test_exception_on_create_bang_many_with_block
|
|
282
|
+
assert_raises(ActiveRecord::RecordInvalid) do
|
|
283
|
+
Reply.create!([{ "title" => "OK" }, { "title" => "Wrong Create" }]) do |r|
|
|
284
|
+
r.content = nil
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
288
|
+
begin
|
|
289
|
+
Reply.create!([{ "title" => "OK" }, { "title" => "Wrong Create" }]) do |r|
|
|
290
|
+
r.content = nil
|
|
291
|
+
end
|
|
292
|
+
rescue ActiveRecord::RecordInvalid => invalid
|
|
293
|
+
assert_equal "入力値が正しくありません。: Reply内容 空です。", invalid.message
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
GetText.set_locale_all "en"
|
|
297
|
+
begin
|
|
298
|
+
Reply.create!([{ "title" => "OK" }, { "title" => "Wrong Create" }]) do |r|
|
|
299
|
+
r.content = nil
|
|
300
|
+
end
|
|
301
|
+
rescue ActiveRecord::RecordInvalid => invalid
|
|
302
|
+
assert_equal "Validation failed: Content Empty", invalid.message
|
|
303
|
+
end
|
|
304
|
+
end
|
|
305
|
+
|
|
213
306
|
def test_scoped_create_without_attributes
|
|
214
307
|
Reply.with_scope(:create => {}) do
|
|
215
308
|
assert_raises(ActiveRecord::RecordInvalid) { Reply.create! }
|
|
@@ -234,7 +327,6 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
234
327
|
end
|
|
235
328
|
end
|
|
236
329
|
|
|
237
|
-
|
|
238
330
|
def test_single_error_per_attr_iteration
|
|
239
331
|
GetText.set_locale_all "ja_JP.UTF-8"
|
|
240
332
|
r = Reply.new
|
|
@@ -350,6 +442,16 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
350
442
|
perform = false
|
|
351
443
|
end
|
|
352
444
|
|
|
445
|
+
=begin
|
|
446
|
+
#Don't need this
|
|
447
|
+
def test_no_title_confirmation
|
|
448
|
+
end
|
|
449
|
+
def test_title_confirmation
|
|
450
|
+
end
|
|
451
|
+
def test_terms_of_service_agreement_no_acceptance
|
|
452
|
+
end
|
|
453
|
+
=end
|
|
454
|
+
|
|
353
455
|
def test_errors_on_boundary_breaking
|
|
354
456
|
GetText.set_locale_all "ja_JP.UTF-8"
|
|
355
457
|
developer = Developer.new("name" => "xs")
|
|
@@ -467,6 +569,14 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
467
569
|
assert t.save
|
|
468
570
|
end
|
|
469
571
|
|
|
572
|
+
=begin
|
|
573
|
+
#Don't need this
|
|
574
|
+
def test_validates_acceptance_of_as_database_column
|
|
575
|
+
end
|
|
576
|
+
def test_validates_acceptance_of_with_non_existant_table
|
|
577
|
+
end
|
|
578
|
+
=end
|
|
579
|
+
|
|
470
580
|
def test_validate_presences
|
|
471
581
|
Topic.validates_presence_of(:title, :content)
|
|
472
582
|
|
|
@@ -539,7 +649,80 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
539
649
|
assert_equal "Title has already been taken", t2.errors.on(:title)
|
|
540
650
|
end
|
|
541
651
|
|
|
542
|
-
|
|
652
|
+
=begin
|
|
653
|
+
#Don't need this
|
|
654
|
+
def test_validate_uniqueness_with_scope
|
|
655
|
+
end
|
|
656
|
+
def test_validate_uniqueness_scoped_to_defining_class
|
|
657
|
+
end
|
|
658
|
+
def test_validate_uniqueness_with_scope_array
|
|
659
|
+
end
|
|
660
|
+
def test_validate_case_insensitive_uniqueness
|
|
661
|
+
end
|
|
662
|
+
def test_validate_case_sensitive_uniqueness
|
|
663
|
+
end
|
|
664
|
+
=end
|
|
665
|
+
|
|
666
|
+
def test_validate_straight_inheritance_uniqueness
|
|
667
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
668
|
+
w1 = IneptWizard.create(:name => "I18nRincewind", :city => "I18nAnkh-Morpork")
|
|
669
|
+
assert w1.valid?, "Saving w1"
|
|
670
|
+
|
|
671
|
+
# Should use validation from base class (which is abstract)
|
|
672
|
+
w2 = IneptWizard.new(:name => "I18nRincewind", :city => "I18nQuirm")
|
|
673
|
+
assert !w2.valid?, "w2 shouldn't be valid"
|
|
674
|
+
assert w2.errors.on(:name), "Should have errors for name"
|
|
675
|
+
assert_equal "不器用な魔術師名はすでに存在します。", w2.errors.on(:name), "Should have uniqueness message for name"
|
|
676
|
+
|
|
677
|
+
w3 = Conjurer.new(:name => "I18nRincewind", :city => "I18nQuirm")
|
|
678
|
+
assert !w3.valid?, "w3 shouldn't be valid"
|
|
679
|
+
assert w3.errors.on(:name), "Should have errors for name"
|
|
680
|
+
assert_equal "手品師名はすでに存在します。", w3.errors.on(:name), "Should have uniqueness message for name"
|
|
681
|
+
|
|
682
|
+
w4 = Conjurer.create(:name => "I18nThe Amazing Bonko", :city => "I18nQuirm")
|
|
683
|
+
assert w4.valid?, "Saving w4"
|
|
684
|
+
|
|
685
|
+
w5 = Thaumaturgist.new(:name => "I18nThe Amazing Bonko", :city => "I18nLancre")
|
|
686
|
+
assert !w5.valid?, "w5 shouldn't be valid"
|
|
687
|
+
assert w5.errors.on(:name), "Should have errors for name"
|
|
688
|
+
assert_equal "奇術師名はすでに存在します。", w5.errors.on(:name), "Should have uniqueness message for name"
|
|
689
|
+
|
|
690
|
+
w6 = Thaumaturgist.new(:name => "I18nMustrum Ridcully", :city => "I18nQuirm")
|
|
691
|
+
assert !w6.valid?, "w6 shouldn't be valid"
|
|
692
|
+
assert w6.errors.on(:city), "Should have errors for city"
|
|
693
|
+
assert_equal "奇術師町はすでに存在します。", w6.errors.on(:city), "Should have uniqueness message for city"
|
|
694
|
+
|
|
695
|
+
GetText.set_locale_all "en"
|
|
696
|
+
w1 = IneptWizard.create(:name => "Rincewind", :city => "Ankh-Morpork")
|
|
697
|
+
assert w1.valid?, "Saving w1"
|
|
698
|
+
|
|
699
|
+
# Should use validation from base class (which is abstract)
|
|
700
|
+
w2 = IneptWizard.new(:name => "Rincewind", :city => "Quirm")
|
|
701
|
+
assert !w2.valid?, "w2 shouldn't be valid"
|
|
702
|
+
assert w2.errors.on(:name), "Should have errors for name"
|
|
703
|
+
assert_equal "Name has already been taken", w2.errors.on(:name), "Should have uniqueness message for name"
|
|
704
|
+
|
|
705
|
+
w3 = Conjurer.new(:name => "Rincewind", :city => "Quirm")
|
|
706
|
+
assert !w3.valid?, "w3 shouldn't be valid"
|
|
707
|
+
assert w3.errors.on(:name), "Should have errors for name"
|
|
708
|
+
assert_equal "Name has already been taken", w3.errors.on(:name), "Should have uniqueness message for name"
|
|
709
|
+
|
|
710
|
+
w4 = Conjurer.create(:name => "The Amazing Bonko", :city => "Quirm")
|
|
711
|
+
assert w4.valid?, "Saving w4"
|
|
712
|
+
|
|
713
|
+
w5 = Thaumaturgist.new(:name => "The Amazing Bonko", :city => "Lancre")
|
|
714
|
+
assert !w5.valid?, "w5 shouldn't be valid"
|
|
715
|
+
assert w5.errors.on(:name), "Should have errors for name"
|
|
716
|
+
assert_equal "Name has already been taken", w5.errors.on(:name), "Should have uniqueness message for name"
|
|
717
|
+
|
|
718
|
+
w6 = Thaumaturgist.new(:name => "Mustrum Ridcully", :city => "Quirm")
|
|
719
|
+
assert !w6.valid?, "w6 shouldn't be valid"
|
|
720
|
+
assert w6.errors.on(:city), "Should have errors for city"
|
|
721
|
+
assert_equal "City has already been taken", w6.errors.on(:city), "Should have uniqueness message for city"
|
|
722
|
+
end
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
def test_validate_format_fn
|
|
543
726
|
Topic.validates_format_of(:title, :content, :with => /^Validation\smacros \w+!$/, :message => N_("%{fn} is bad data"))
|
|
544
727
|
|
|
545
728
|
GetText.set_locale_all "ja_JP.UTF-8"
|
|
@@ -588,6 +771,63 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
588
771
|
assert_raise(ArgumentError) { Topic.validates_format_of(:title, :content) }
|
|
589
772
|
end
|
|
590
773
|
|
|
774
|
+
=begin
|
|
775
|
+
# Don't need this
|
|
776
|
+
def test_validate_format_with_allow_blank
|
|
777
|
+
end
|
|
778
|
+
=end
|
|
779
|
+
def test_validate_format_numeric_fn
|
|
780
|
+
Topic.validates_format_of(:title, :content, :with => /^[1-9][0-9]*$/, :message => N_("%{fn} is bad data"))
|
|
781
|
+
|
|
782
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
783
|
+
t = Topic.create("title" => "72x", "content" => "6789")
|
|
784
|
+
assert !t.valid?, "Shouldn't be valid"
|
|
785
|
+
assert !t.save, "Shouldn't save because it's invalid"
|
|
786
|
+
assert_equal "タイトルは悪いデータです。", t.errors.on(:title)
|
|
787
|
+
assert_nil t.errors.on(:content)
|
|
788
|
+
|
|
789
|
+
t.title = "-11"
|
|
790
|
+
assert !t.valid?, "Shouldn't be valid"
|
|
791
|
+
|
|
792
|
+
t.title = "03"
|
|
793
|
+
assert !t.valid?, "Shouldn't be valid"
|
|
794
|
+
|
|
795
|
+
t.title = "z44"
|
|
796
|
+
assert !t.valid?, "Shouldn't be valid"
|
|
797
|
+
|
|
798
|
+
t.title = "5v7"
|
|
799
|
+
assert !t.valid?, "Shouldn't be valid"
|
|
800
|
+
|
|
801
|
+
t.title = "1"
|
|
802
|
+
|
|
803
|
+
assert t.save
|
|
804
|
+
assert_nil t.errors.on(:title)
|
|
805
|
+
|
|
806
|
+
GetText.set_locale_all "en"
|
|
807
|
+
t = Topic.create("title" => "72x", "content" => "6789")
|
|
808
|
+
assert !t.valid?, "Shouldn't be valid"
|
|
809
|
+
assert !t.save, "Shouldn't save because it's invalid"
|
|
810
|
+
assert_equal "Title is bad data", t.errors.on(:title)
|
|
811
|
+
assert_nil t.errors.on(:content)
|
|
812
|
+
|
|
813
|
+
t.title = "-11"
|
|
814
|
+
assert !t.valid?, "Shouldn't be valid"
|
|
815
|
+
|
|
816
|
+
t.title = "03"
|
|
817
|
+
assert !t.valid?, "Shouldn't be valid"
|
|
818
|
+
|
|
819
|
+
t.title = "z44"
|
|
820
|
+
assert !t.valid?, "Shouldn't be valid"
|
|
821
|
+
|
|
822
|
+
t.title = "5v7"
|
|
823
|
+
assert !t.valid?, "Shouldn't be valid"
|
|
824
|
+
|
|
825
|
+
t.title = "1"
|
|
826
|
+
|
|
827
|
+
assert t.save
|
|
828
|
+
assert_nil t.errors.on(:title)
|
|
829
|
+
end
|
|
830
|
+
|
|
591
831
|
def test_validate_format_numeric
|
|
592
832
|
Topic.validates_format_of(:title, :content, :with => /^[1-9][0-9]*$/, :message => N_("is bad data"))
|
|
593
833
|
|
|
@@ -639,7 +879,35 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
639
879
|
assert t.save
|
|
640
880
|
assert_nil t.errors.on(:title)
|
|
641
881
|
end
|
|
642
|
-
|
|
882
|
+
|
|
883
|
+
def test_validate_format_with_formatted_message_fn
|
|
884
|
+
Topic.validates_format_of(:title, :with => /^Valid Title$/, :message => N_("%{fn} can not be %{val}"))
|
|
885
|
+
|
|
886
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
887
|
+
t = Topic.create(:title => 'Invalid title')
|
|
888
|
+
assert_equal "Invalid titleはタイトルではありません。", t.errors.full_messages[0]
|
|
889
|
+
assert_equal "Invalid titleはタイトルではありません。", t.errors.on(:title)
|
|
890
|
+
|
|
891
|
+
GetText.set_locale_all "en"
|
|
892
|
+
t = Topic.create(:title => 'Invalid title')
|
|
893
|
+
assert_equal "Title can not be Invalid title", t.errors.full_messages[0]
|
|
894
|
+
assert_equal "Title can not be Invalid title", t.errors.on(:title)
|
|
895
|
+
end
|
|
896
|
+
|
|
897
|
+
def test_validate_format_with_formatted_message
|
|
898
|
+
Topic.validates_format_of(:title, :with => /^Valid Title$/, :message => N_("can not be %{val}"))
|
|
899
|
+
|
|
900
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
901
|
+
t = Topic.create(:title => 'Invalid title')
|
|
902
|
+
assert_equal "タイトル はInvalid titleではありません。", t.errors.full_messages[0]
|
|
903
|
+
assert_equal "はInvalid titleではありません。", t.errors.on(:title)
|
|
904
|
+
|
|
905
|
+
GetText.set_locale_all "en"
|
|
906
|
+
t = Topic.create(:title => 'Invalid title')
|
|
907
|
+
assert_equal "Title can not be Invalid title", t.errors.full_messages[0]
|
|
908
|
+
assert_equal "can not be Invalid title", t.errors.on(:title)
|
|
909
|
+
end
|
|
910
|
+
|
|
643
911
|
def test_validates_inclusion_of
|
|
644
912
|
Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ) )
|
|
645
913
|
|
|
@@ -662,6 +930,113 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
662
930
|
assert_equal "Title is not included in the list", t.errors.on(:title)
|
|
663
931
|
end
|
|
664
932
|
|
|
933
|
+
=begin
|
|
934
|
+
# Don't need this
|
|
935
|
+
def test_validates_inclusion_of_with_allow_nil
|
|
936
|
+
end
|
|
937
|
+
def test_numericality_with_getter_method
|
|
938
|
+
end
|
|
939
|
+
def test_validates_length_of_with_allow_nil
|
|
940
|
+
end
|
|
941
|
+
def test_validates_length_of_with_allow_blank
|
|
942
|
+
end
|
|
943
|
+
=end
|
|
944
|
+
|
|
945
|
+
def test_validates_inclusion_of_with_formatted_message_fn
|
|
946
|
+
Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ), :message => N_("%{fn} option %{val} is not in the list") )
|
|
947
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
948
|
+
|
|
949
|
+
assert Topic.create("title" => "a", "content" => "abc").valid?
|
|
950
|
+
|
|
951
|
+
t = Topic.create("title" => "uhoh", "content" => "abc")
|
|
952
|
+
assert !t.valid?
|
|
953
|
+
assert t.errors.on(:title)
|
|
954
|
+
assert_equal "オプションuhohはタイトル一覧にありません。", t.errors.full_messages[0]
|
|
955
|
+
assert_equal "オプションuhohはタイトル一覧にありません。", t.errors["title"]
|
|
956
|
+
|
|
957
|
+
GetText.set_locale_all "en"
|
|
958
|
+
assert Topic.create("title" => "a", "content" => "abc").valid?
|
|
959
|
+
|
|
960
|
+
t = Topic.create("title" => "uhoh", "content" => "abc")
|
|
961
|
+
assert !t.valid?
|
|
962
|
+
assert t.errors.on(:title)
|
|
963
|
+
assert_equal "Title option uhoh is not in the list", t.errors.full_messages[0]
|
|
964
|
+
assert_equal "Title option uhoh is not in the list", t.errors["title"]
|
|
965
|
+
end
|
|
966
|
+
|
|
967
|
+
def test_validates_inclusion_of_with_formatted_message
|
|
968
|
+
Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ), :message => N_("option %{val} is not in the list") )
|
|
969
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
970
|
+
|
|
971
|
+
assert Topic.create("title" => "a", "content" => "abc").valid?
|
|
972
|
+
|
|
973
|
+
t = Topic.create("title" => "uhoh", "content" => "abc")
|
|
974
|
+
assert !t.valid?
|
|
975
|
+
assert t.errors.on(:title)
|
|
976
|
+
assert_equal "タイトル オプションuhohは一覧にありません。", t.errors.full_messages[0]
|
|
977
|
+
assert_equal "オプションuhohは一覧にありません。", t.errors["title"]
|
|
978
|
+
|
|
979
|
+
GetText.set_locale_all "en"
|
|
980
|
+
assert Topic.create("title" => "a", "content" => "abc").valid?
|
|
981
|
+
|
|
982
|
+
t = Topic.create("title" => "uhoh", "content" => "abc")
|
|
983
|
+
assert !t.valid?
|
|
984
|
+
assert t.errors.on(:title)
|
|
985
|
+
assert_equal "Title option uhoh is not in the list", t.errors.full_messages[0]
|
|
986
|
+
assert_equal "option uhoh is not in the list", t.errors["title"]
|
|
987
|
+
end
|
|
988
|
+
|
|
989
|
+
=begin
|
|
990
|
+
Don't need this
|
|
991
|
+
def test_numericality_with_allow_nil_and_getter_method
|
|
992
|
+
end
|
|
993
|
+
def test_validates_exclusion_of
|
|
994
|
+
end
|
|
995
|
+
=end
|
|
996
|
+
def test_validates_exclusion_of_with_formatted_message_fn
|
|
997
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
998
|
+
Topic.validates_exclusion_of( :title, :in => %w( abe monkey ), :message => N_("%{fn} option %{val} is restricted") )
|
|
999
|
+
|
|
1000
|
+
assert Topic.create("title" => "something", "content" => "abc")
|
|
1001
|
+
|
|
1002
|
+
t = Topic.create("title" => "monkey")
|
|
1003
|
+
assert !t.valid?
|
|
1004
|
+
assert t.errors.on(:title)
|
|
1005
|
+
assert_equal "オプションタイトルmonkeyは制限されています。", t.errors.full_messages[0]
|
|
1006
|
+
assert_equal "オプションタイトルmonkeyは制限されています。", t.errors["title"]
|
|
1007
|
+
|
|
1008
|
+
GetText.set_locale_all "en"
|
|
1009
|
+
assert Topic.create("title" => "something", "content" => "abc")
|
|
1010
|
+
|
|
1011
|
+
t = Topic.create("title" => "monkey")
|
|
1012
|
+
assert !t.valid?
|
|
1013
|
+
assert t.errors.on(:title)
|
|
1014
|
+
assert_equal "Title option monkey is restricted", t.errors.full_messages[0]
|
|
1015
|
+
assert_equal "Title option monkey is restricted", t.errors["title"]
|
|
1016
|
+
end
|
|
1017
|
+
|
|
1018
|
+
def test_validates_exclusion_of_with_formatted_message
|
|
1019
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
1020
|
+
Topic.validates_exclusion_of( :title, :in => %w( abe monkey ), :message => N_("option %{val} is restricted") )
|
|
1021
|
+
|
|
1022
|
+
assert Topic.create("title" => "something", "content" => "abc")
|
|
1023
|
+
|
|
1024
|
+
t = Topic.create("title" => "monkey")
|
|
1025
|
+
assert !t.valid?
|
|
1026
|
+
assert t.errors.on(:title)
|
|
1027
|
+
assert_equal "タイトル オプションmonkeyは制限されています。", t.errors.full_messages[0]
|
|
1028
|
+
assert_equal "オプションmonkeyは制限されています。", t.errors["title"]
|
|
1029
|
+
|
|
1030
|
+
GetText.set_locale_all "en"
|
|
1031
|
+
assert Topic.create("title" => "something", "content" => "abc")
|
|
1032
|
+
|
|
1033
|
+
t = Topic.create("title" => "monkey")
|
|
1034
|
+
assert !t.valid?
|
|
1035
|
+
assert t.errors.on(:title)
|
|
1036
|
+
assert_equal "Title option monkey is restricted", t.errors.full_messages[0]
|
|
1037
|
+
assert_equal "option monkey is restricted", t.errors["title"]
|
|
1038
|
+
end
|
|
1039
|
+
|
|
665
1040
|
def test_validates_length_of_using_minimum
|
|
666
1041
|
Topic.validates_length_of :title, :minimum => 5
|
|
667
1042
|
|
|
@@ -709,6 +1084,12 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
709
1084
|
assert_equal "Title is too long (maximum is 5 characters)", t.errors.on("title")
|
|
710
1085
|
end
|
|
711
1086
|
|
|
1087
|
+
=begin
|
|
1088
|
+
# Don't need this
|
|
1089
|
+
def test_optionally_validates_length_of_using_minimum
|
|
1090
|
+
end
|
|
1091
|
+
=end
|
|
1092
|
+
|
|
712
1093
|
def test_validates_length_of_using_within
|
|
713
1094
|
Topic.validates_length_of(:title, :content, :within => 3..5)
|
|
714
1095
|
|
|
@@ -745,6 +1126,12 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
745
1126
|
assert_equal "Content is too short (minimum is 3 characters)", t.errors.on(:content)
|
|
746
1127
|
end
|
|
747
1128
|
|
|
1129
|
+
=begin
|
|
1130
|
+
# Don't need this
|
|
1131
|
+
def test_optionally_validates_length_of_using_within
|
|
1132
|
+
end
|
|
1133
|
+
=end
|
|
1134
|
+
|
|
748
1135
|
def test_optionally_validates_length_of_using_within_on_create_fn
|
|
749
1136
|
Topic.validates_length_of :title, :content, :within => 5..10, :on => :create, :too_short => N_("my string(%{fn}) is too short: %d"), :too_long => N_("my string(%{fn}) is too long: %d")
|
|
750
1137
|
|
|
@@ -858,6 +1245,14 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
858
1245
|
|
|
859
1246
|
end
|
|
860
1247
|
|
|
1248
|
+
=begin
|
|
1249
|
+
# Don't need this
|
|
1250
|
+
def test_optionally_validates_length_of_using_is
|
|
1251
|
+
end
|
|
1252
|
+
def test_validates_length_of_using_bignum
|
|
1253
|
+
end
|
|
1254
|
+
=end
|
|
1255
|
+
|
|
861
1256
|
def test_validates_length_with_globaly_modified_error_message_fn
|
|
862
1257
|
ActiveRecord::Errors.default_error_messages[:too_short] = N_('%{fn} %d dayo')
|
|
863
1258
|
Topic.validates_length_of :title, :minimum => 10
|
|
@@ -892,6 +1287,15 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
892
1287
|
assert_equal '10 dayo', t.errors.on('title')
|
|
893
1288
|
end
|
|
894
1289
|
|
|
1290
|
+
=begin
|
|
1291
|
+
def test_validates_size_of_association
|
|
1292
|
+
end
|
|
1293
|
+
def test_validates_size_of_association_using_within
|
|
1294
|
+
end
|
|
1295
|
+
def test_validates_length_of_nasty_params
|
|
1296
|
+
end
|
|
1297
|
+
=end
|
|
1298
|
+
|
|
895
1299
|
def test_validates_length_of_custom_errors_for_minimum_with_message_fn
|
|
896
1300
|
Topic.validates_length_of( :title, :minimum => 5, :message => N_("%{fn} hoo %d") )
|
|
897
1301
|
GetText.set_locale_all "ja_JP.UTF-8"
|
|
@@ -1101,6 +1505,29 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
1101
1505
|
assert_equal "hoo 5", t.errors.on("title")
|
|
1102
1506
|
end
|
|
1103
1507
|
|
|
1508
|
+
=begin
|
|
1509
|
+
def test_validates_length_of_using_minimum_utf8
|
|
1510
|
+
end
|
|
1511
|
+
def test_validates_length_of_using_maximum_utf8
|
|
1512
|
+
end
|
|
1513
|
+
def test_validates_length_of_using_within_utf8
|
|
1514
|
+
end
|
|
1515
|
+
def test_optionally_validates_length_of_using_within_utf8
|
|
1516
|
+
end
|
|
1517
|
+
def test_optionally_validates_length_of_using_within_on_create_utf8
|
|
1518
|
+
end
|
|
1519
|
+
def test_optionally_validates_length_of_using_within_on_update_utf8
|
|
1520
|
+
end
|
|
1521
|
+
def test_validates_length_of_using_is_utf8
|
|
1522
|
+
end
|
|
1523
|
+
def test_validates_size_of_association_utf8
|
|
1524
|
+
end
|
|
1525
|
+
def test_validates_associated_many
|
|
1526
|
+
end
|
|
1527
|
+
def test_validates_associated_one
|
|
1528
|
+
end
|
|
1529
|
+
=end
|
|
1530
|
+
|
|
1104
1531
|
def test_validate_block_fn
|
|
1105
1532
|
Topic.validate { |topic| topic.errors.add("title", N_("%{fn} will never be valid")) }
|
|
1106
1533
|
GetText.set_locale_all "ja_JP.UTF-8"
|
|
@@ -1135,6 +1562,13 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
1135
1562
|
assert_equal "will never be valid", t.errors.on("title")
|
|
1136
1563
|
end
|
|
1137
1564
|
|
|
1565
|
+
=begin
|
|
1566
|
+
def test_invalid_validator
|
|
1567
|
+
end
|
|
1568
|
+
def test_throw_away_typing
|
|
1569
|
+
end
|
|
1570
|
+
=end
|
|
1571
|
+
|
|
1138
1572
|
def test_validates_acceptance_of_with_custom_error_using_quotes_fn
|
|
1139
1573
|
Developer.validates_acceptance_of :salary, :message=> N_("%{fn} contains 'single' and \"double\" quotes")
|
|
1140
1574
|
|
|
@@ -1569,6 +2003,155 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
1569
2003
|
assert_equal "This string contains 'single' and \"double\" quotes", r.errors.on(:topic)
|
|
1570
2004
|
end
|
|
1571
2005
|
|
|
2006
|
+
=begin
|
|
2007
|
+
def test_if_validation_using_method_true
|
|
2008
|
+
end
|
|
2009
|
+
def test_unless_validation_using_method_true
|
|
2010
|
+
end
|
|
2011
|
+
def test_if_validation_using_method_false
|
|
2012
|
+
end
|
|
2013
|
+
=end
|
|
2014
|
+
def test_unless_validation_using_method_false_fn
|
|
2015
|
+
# When the method returns false
|
|
2016
|
+
Topic.validates_length_of( :title, :maximum=>5, :too_long=>N_("%{fn} hoo %d"), :unless => :condition_is_true_but_its_not )
|
|
2017
|
+
|
|
2018
|
+
GetText.set_locale_all "ja"
|
|
2019
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2020
|
+
assert !t.valid?
|
|
2021
|
+
assert t.errors.on(:title)
|
|
2022
|
+
assert_equal "タイトルふー5", t.errors.full_messages[0]
|
|
2023
|
+
assert_equal "タイトルふー5", t.errors["title"]
|
|
2024
|
+
|
|
2025
|
+
GetText.set_locale_all "en"
|
|
2026
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2027
|
+
assert !t.valid?
|
|
2028
|
+
assert t.errors.on(:title)
|
|
2029
|
+
assert_equal "Title hoo 5", t.errors.full_messages[0]
|
|
2030
|
+
assert_equal "Title hoo 5", t.errors["title"]
|
|
2031
|
+
end
|
|
2032
|
+
|
|
2033
|
+
def test_unless_validation_using_method_false
|
|
2034
|
+
# When the method returns false
|
|
2035
|
+
Topic.validates_length_of( :title, :maximum=>5, :too_long=>N_("hoo %d"), :unless => :condition_is_true_but_its_not )
|
|
2036
|
+
|
|
2037
|
+
GetText.set_locale_all "ja"
|
|
2038
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2039
|
+
assert !t.valid?
|
|
2040
|
+
assert t.errors.on(:title)
|
|
2041
|
+
assert_equal "タイトル ふー5", t.errors.full_messages[0]
|
|
2042
|
+
assert_equal "ふー5", t.errors["title"]
|
|
2043
|
+
|
|
2044
|
+
GetText.set_locale_all "en"
|
|
2045
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2046
|
+
assert !t.valid?
|
|
2047
|
+
assert t.errors.on(:title)
|
|
2048
|
+
assert_equal "Title hoo 5", t.errors.full_messages[0]
|
|
2049
|
+
assert_equal "hoo 5", t.errors["title"]
|
|
2050
|
+
end
|
|
2051
|
+
|
|
2052
|
+
def test_if_validation_using_string_true_fn
|
|
2053
|
+
# When the evaluated string returns true
|
|
2054
|
+
Topic.validates_length_of( :title, :maximum=>5, :too_long=>N_("%{fn} hoo %d"), :if => "a = 1; a == 1" )
|
|
2055
|
+
|
|
2056
|
+
GetText.set_locale_all "ja"
|
|
2057
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2058
|
+
assert !t.valid?
|
|
2059
|
+
assert t.errors.on(:title)
|
|
2060
|
+
assert_equal "タイトルふー5", t.errors.full_messages[0]
|
|
2061
|
+
assert_equal "タイトルふー5", t.errors["title"]
|
|
2062
|
+
|
|
2063
|
+
GetText.set_locale_all "en"
|
|
2064
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2065
|
+
assert !t.valid?
|
|
2066
|
+
assert t.errors.on(:title)
|
|
2067
|
+
assert_equal "Title hoo 5", t.errors.full_messages[0]
|
|
2068
|
+
assert_equal "Title hoo 5", t.errors["title"]
|
|
2069
|
+
end
|
|
2070
|
+
|
|
2071
|
+
def test_if_validation_using_string_true
|
|
2072
|
+
# When the evaluated string returns true
|
|
2073
|
+
Topic.validates_length_of( :title, :maximum=>5, :too_long=>N_("hoo %d"), :if => "a = 1; a == 1" )
|
|
2074
|
+
|
|
2075
|
+
GetText.set_locale_all "ja"
|
|
2076
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2077
|
+
assert !t.valid?
|
|
2078
|
+
assert t.errors.on(:title)
|
|
2079
|
+
assert_equal "タイトル ふー5", t.errors.full_messages[0]
|
|
2080
|
+
assert_equal "ふー5", t.errors["title"]
|
|
2081
|
+
|
|
2082
|
+
GetText.set_locale_all "en"
|
|
2083
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2084
|
+
assert !t.valid?
|
|
2085
|
+
assert t.errors.on(:title)
|
|
2086
|
+
assert_equal "Title hoo 5", t.errors.full_messages[0]
|
|
2087
|
+
assert_equal "hoo 5", t.errors["title"]
|
|
2088
|
+
end
|
|
2089
|
+
|
|
2090
|
+
=begin
|
|
2091
|
+
def test_unless_validation_using_string_true
|
|
2092
|
+
end
|
|
2093
|
+
def test_if_validation_using_string_false
|
|
2094
|
+
end
|
|
2095
|
+
=end
|
|
2096
|
+
def test_unless_validation_using_string_false
|
|
2097
|
+
# When the evaluated string returns false
|
|
2098
|
+
Topic.validates_length_of( :title, :maximum=>5, :too_long=>N_("hoo %d"), :unless => "false")
|
|
2099
|
+
|
|
2100
|
+
GetText.set_locale_all "ja"
|
|
2101
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2102
|
+
assert !t.valid?
|
|
2103
|
+
assert t.errors.on(:title)
|
|
2104
|
+
assert_equal "タイトル ふー5", t.errors.full_messages[0]
|
|
2105
|
+
assert_equal "ふー5", t.errors["title"]
|
|
2106
|
+
|
|
2107
|
+
GetText.set_locale_all "en"
|
|
2108
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2109
|
+
assert !t.valid?
|
|
2110
|
+
assert t.errors.on(:title)
|
|
2111
|
+
assert_equal "Title hoo 5", t.errors.full_messages[0]
|
|
2112
|
+
assert_equal "hoo 5", t.errors["title"]
|
|
2113
|
+
end
|
|
2114
|
+
|
|
2115
|
+
def test_if_validation_using_block_true_fn
|
|
2116
|
+
# When the block returns true
|
|
2117
|
+
Topic.validates_length_of( :title, :maximum=>5, :too_long=>N_("%{fn} hoo %d"),
|
|
2118
|
+
:if => Proc.new { |r| r.content.size > 4 } )
|
|
2119
|
+
|
|
2120
|
+
GetText.set_locale_all "ja"
|
|
2121
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2122
|
+
assert !t.valid?
|
|
2123
|
+
assert t.errors.on(:title)
|
|
2124
|
+
assert_equal "タイトルふー5", t.errors.full_messages[0]
|
|
2125
|
+
assert_equal "タイトルふー5", t.errors["title"]
|
|
2126
|
+
|
|
2127
|
+
GetText.set_locale_all "en"
|
|
2128
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2129
|
+
assert !t.valid?
|
|
2130
|
+
assert t.errors.on(:title)
|
|
2131
|
+
assert_equal "Title hoo 5", t.errors.full_messages[0]
|
|
2132
|
+
assert_equal "Title hoo 5", t.errors["title"]
|
|
2133
|
+
end
|
|
2134
|
+
|
|
2135
|
+
def test_if_validation_using_block_true
|
|
2136
|
+
# When the block returns true
|
|
2137
|
+
Topic.validates_length_of( :title, :maximum=>5, :too_long=>N_("hoo %d"),
|
|
2138
|
+
:if => Proc.new { |r| r.content.size > 4 } )
|
|
2139
|
+
|
|
2140
|
+
GetText.set_locale_all "ja"
|
|
2141
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2142
|
+
assert !t.valid?
|
|
2143
|
+
assert t.errors.on(:title)
|
|
2144
|
+
assert_equal "タイトル ふー5", t.errors.full_messages[0]
|
|
2145
|
+
assert_equal "ふー5", t.errors["title"]
|
|
2146
|
+
|
|
2147
|
+
GetText.set_locale_all "en"
|
|
2148
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2149
|
+
assert !t.valid?
|
|
2150
|
+
assert t.errors.on(:title)
|
|
2151
|
+
assert_equal "Title hoo 5", t.errors.full_messages[0]
|
|
2152
|
+
assert_equal "hoo 5", t.errors["title"]
|
|
2153
|
+
end
|
|
2154
|
+
|
|
1572
2155
|
def test_conditional_validation_using_method_true_fn
|
|
1573
2156
|
# When the method returns true
|
|
1574
2157
|
Topic.validates_length_of( :title, :maximum=>5, :too_long=> N_("%{fn} hoo %d"), :if => :condition_is_true )
|
|
@@ -1576,8 +2159,8 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
1576
2159
|
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
1577
2160
|
assert !t.valid?
|
|
1578
2161
|
assert t.errors.on(:title)
|
|
1579
|
-
assert_equal "タイトルふー5", t.errors.on("title")
|
|
1580
2162
|
assert_equal "タイトルふー5", t.errors.full_messages[0]
|
|
2163
|
+
assert_equal "タイトルふー5", t.errors.on("title")
|
|
1581
2164
|
|
|
1582
2165
|
GetText.set_locale_all "en"
|
|
1583
2166
|
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
@@ -1587,6 +2170,54 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
1587
2170
|
assert_equal "Title hoo 5", t.errors.on("title")
|
|
1588
2171
|
end
|
|
1589
2172
|
|
|
2173
|
+
=begin
|
|
2174
|
+
Don't need this
|
|
2175
|
+
def test_unless_validation_using_block_true
|
|
2176
|
+
end
|
|
2177
|
+
def test_if_validation_using_block_false
|
|
2178
|
+
end
|
|
2179
|
+
=end
|
|
2180
|
+
|
|
2181
|
+
def test_unless_validation_using_block_false_fn
|
|
2182
|
+
# When the block returns false
|
|
2183
|
+
Topic.validates_length_of( :title, :maximum=>5, :too_long=>N_("%{fn} hoo %d"),
|
|
2184
|
+
:unless => Proc.new { |r| r.title != "uhohuhoh"} )
|
|
2185
|
+
|
|
2186
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
2187
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2188
|
+
assert !t.valid?
|
|
2189
|
+
assert t.errors.on(:title)
|
|
2190
|
+
assert_equal "タイトルふー5", t.errors.full_messages[0]
|
|
2191
|
+
assert_equal "タイトルふー5", t.errors.on("title")
|
|
2192
|
+
|
|
2193
|
+
GetText.set_locale_all "en"
|
|
2194
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2195
|
+
assert !t.valid?
|
|
2196
|
+
assert t.errors.on(:title)
|
|
2197
|
+
assert_equal "Title hoo 5", t.errors.full_messages[0]
|
|
2198
|
+
assert_equal "Title hoo 5", t.errors["title"]
|
|
2199
|
+
end
|
|
2200
|
+
|
|
2201
|
+
def test_unless_validation_using_block_false
|
|
2202
|
+
# When the block returns false
|
|
2203
|
+
Topic.validates_length_of( :title, :maximum=>5, :too_long=>N_("hoo %d"),
|
|
2204
|
+
:unless => Proc.new { |r| r.title != "uhohuhoh"} )
|
|
2205
|
+
|
|
2206
|
+
GetText.set_locale_all "ja_JP.UTF-8"
|
|
2207
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2208
|
+
assert !t.valid?
|
|
2209
|
+
assert t.errors.on(:title)
|
|
2210
|
+
assert_equal "タイトル ふー5", t.errors.full_messages[0]
|
|
2211
|
+
assert_equal "ふー5", t.errors.on("title")
|
|
2212
|
+
|
|
2213
|
+
GetText.set_locale_all "en"
|
|
2214
|
+
t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
|
|
2215
|
+
assert !t.valid?
|
|
2216
|
+
assert t.errors.on(:title)
|
|
2217
|
+
assert_equal "Title hoo 5", t.errors.full_messages[0]
|
|
2218
|
+
assert_equal "hoo 5", t.errors["title"]
|
|
2219
|
+
end
|
|
2220
|
+
|
|
1590
2221
|
def test_conditional_validation_using_method_true
|
|
1591
2222
|
# When the method returns true
|
|
1592
2223
|
Topic.validates_length_of( :title, :maximum=>5, :too_long=> N_("hoo %d"), :if => :condition_is_true )
|
|
@@ -1732,6 +2363,12 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
1732
2363
|
end
|
|
1733
2364
|
end
|
|
1734
2365
|
|
|
2366
|
+
=begin
|
|
2367
|
+
#Don't need this
|
|
2368
|
+
def test_validation_with_if_as_string
|
|
2369
|
+
end
|
|
2370
|
+
=end
|
|
2371
|
+
|
|
1735
2372
|
def test_default_validates_numericality_of
|
|
1736
2373
|
GetText.set_locale_all "ja_JP.UTF-8"
|
|
1737
2374
|
Topic.validates_numericality_of :approved
|
|
@@ -1742,7 +2379,7 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
1742
2379
|
topic = Topic.create("title" => "numeric test", "content" => "whatever", "approved" => "aaa")
|
|
1743
2380
|
assert_equal "Approved is not a number", topic.errors.on(:approved)
|
|
1744
2381
|
assert_equal "Approved is not a number", topic.errors.full_messages[0]
|
|
1745
|
-
|
|
2382
|
+
end
|
|
1746
2383
|
|
|
1747
2384
|
def test_inherited_messages
|
|
1748
2385
|
GetText.set_locale_all "ja_JP.UTF-8"
|
|
@@ -1758,29 +2395,35 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
1758
2395
|
|
|
1759
2396
|
t = Reply.create
|
|
1760
2397
|
assert !t.save
|
|
1761
|
-
assert_equal "Reply
|
|
1762
|
-
assert_equal "Reply
|
|
1763
|
-
assert_equal "
|
|
1764
|
-
assert_equal "空です。", t.errors.
|
|
2398
|
+
assert_equal "Replyタイトルを入力してください。", t.errors.full_messages[0]
|
|
2399
|
+
assert_equal "Replyタイトル 空です。", t.errors.full_messages[1]
|
|
2400
|
+
assert_equal "Reply内容を入力してください。", t.errors.full_messages[2]
|
|
2401
|
+
assert_equal "Reply内容 空です。", t.errors.full_messages[3]
|
|
2402
|
+
assert_equal ["Replyタイトルを入力してください。","空です。"], t.errors.on(:title)
|
|
2403
|
+
assert_equal ["Reply内容を入力してください。", "空です。"], t.errors.on(:content)
|
|
1765
2404
|
|
|
1766
2405
|
t = Reply.create
|
|
1767
2406
|
t.title = "Wrong Create"
|
|
1768
2407
|
assert !t.save
|
|
1769
2408
|
assert_equal "Replyタイトル が不正に生成されました。", t.errors.full_messages[0]
|
|
1770
|
-
assert_equal "Reply
|
|
2409
|
+
assert_equal "Reply内容を入力してください。", t.errors.full_messages[1]
|
|
2410
|
+
assert_equal "Reply内容 空です。", t.errors.full_messages[2]
|
|
1771
2411
|
|
|
1772
2412
|
t = SillyReply.create
|
|
1773
2413
|
assert !t.save
|
|
1774
|
-
assert_equal "Silly
|
|
1775
|
-
assert_equal "Silly
|
|
1776
|
-
assert_equal "
|
|
1777
|
-
assert_equal "空です。", t.errors.
|
|
2414
|
+
assert_equal "Sillyタイトルを入力してください。", t.errors.full_messages[0]
|
|
2415
|
+
assert_equal "Sillyタイトル 空です。", t.errors.full_messages[1]
|
|
2416
|
+
assert_equal "Silly内容を入力してください。", t.errors.full_messages[2]
|
|
2417
|
+
assert_equal "Silly内容 空です。", t.errors.full_messages[3]
|
|
2418
|
+
assert_equal ["Sillyタイトルを入力してください。","空です。"], t.errors.on(:title)
|
|
2419
|
+
assert_equal ["Silly内容を入力してください。","空です。"], t.errors.on(:content)
|
|
1778
2420
|
|
|
1779
2421
|
t = SillyReply.create
|
|
1780
2422
|
t.title = "Wrong Create"
|
|
1781
2423
|
assert !t.save
|
|
1782
2424
|
assert_equal "Sillyタイトル が不正に生成されました。", t.errors.full_messages[0]
|
|
1783
|
-
assert_equal "Silly
|
|
2425
|
+
assert_equal "Silly内容を入力してください。", t.errors.full_messages[1]
|
|
2426
|
+
assert_equal "Silly内容 空です。", t.errors.full_messages[2]
|
|
1784
2427
|
end
|
|
1785
2428
|
|
|
1786
2429
|
def test_original_model_with_validation
|
|
@@ -1800,3 +2443,164 @@ class ValidationsTest < Test::Unit::TestCase
|
|
|
1800
2443
|
end
|
|
1801
2444
|
end
|
|
1802
2445
|
|
|
2446
|
+
class ValidatesNumericalityTest < Test::Unit::TestCase
|
|
2447
|
+
include GetText
|
|
2448
|
+
|
|
2449
|
+
NIL = [nil]
|
|
2450
|
+
BLANK = ["", " ", " \t \r \n"]
|
|
2451
|
+
BIGDECIMAL_STRINGS = %w(12345678901234567890.1234567890) # 30 significent digits
|
|
2452
|
+
FLOAT_STRINGS = %w(0.0 +0.0 -0.0 10.0 10.5 -10.5 -0.0001 -090.1 90.1e1 -90.1e5 -90.1e-5 90e-5)
|
|
2453
|
+
INTEGER_STRINGS = %w(0 +0 -0 10 +10 -10 0090 -090)
|
|
2454
|
+
FLOATS = [0.0, 10.0, 10.5, -10.5, -0.0001] + FLOAT_STRINGS
|
|
2455
|
+
INTEGERS = [0, 10, -10] + INTEGER_STRINGS
|
|
2456
|
+
BIGDECIMAL = BIGDECIMAL_STRINGS.collect! { |bd| BigDecimal.new(bd) }
|
|
2457
|
+
JUNK = ["not a number", "42 not a number", "0xdeadbeef", "00-1", "--3", "+-3", "+3-1", "-+019.0", "12.12.13.12", "123\nnot a number"]
|
|
2458
|
+
|
|
2459
|
+
def setup
|
|
2460
|
+
bindtextdomain_to(Topic, "active_record")
|
|
2461
|
+
|
|
2462
|
+
Topic.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
|
2463
|
+
Topic.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
|
2464
|
+
Topic.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
|
2465
|
+
end
|
|
2466
|
+
|
|
2467
|
+
def test_default_validates_numericality_of
|
|
2468
|
+
Topic.validates_numericality_of :approved
|
|
2469
|
+
|
|
2470
|
+
invalid!(NIL + BLANK + JUNK)
|
|
2471
|
+
# valid!(FLOATS + INTEGERS + BIGDECIMAL)
|
|
2472
|
+
end
|
|
2473
|
+
|
|
2474
|
+
def test_validates_numericality_of_with_nil_allowed
|
|
2475
|
+
Topic.validates_numericality_of :approved, :allow_nil => true
|
|
2476
|
+
|
|
2477
|
+
invalid!(BLANK + JUNK)
|
|
2478
|
+
# valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL)
|
|
2479
|
+
end
|
|
2480
|
+
|
|
2481
|
+
def test_validates_numericality_of_with_integer_only
|
|
2482
|
+
Topic.validates_numericality_of :approved, :only_integer => true
|
|
2483
|
+
|
|
2484
|
+
invalid!(NIL + BLANK + JUNK + FLOATS + BIGDECIMAL)
|
|
2485
|
+
# valid!(INTEGERS)
|
|
2486
|
+
end
|
|
2487
|
+
|
|
2488
|
+
def test_validates_numericality_of_with_integer_only_and_nil_allowed
|
|
2489
|
+
Topic.validates_numericality_of :approved, :only_integer => true, :allow_nil => true
|
|
2490
|
+
|
|
2491
|
+
invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL)
|
|
2492
|
+
# valid!(NIL + INTEGERS)
|
|
2493
|
+
end
|
|
2494
|
+
|
|
2495
|
+
def test_validates_numericality_with_greater_than
|
|
2496
|
+
Topic.validates_numericality_of :approved, :greater_than => 10
|
|
2497
|
+
|
|
2498
|
+
invalid!([-10, 10], 'Approved must be greater than 10',
|
|
2499
|
+
'承認は10より大きい値にしてください。')
|
|
2500
|
+
# valid!([11])
|
|
2501
|
+
end
|
|
2502
|
+
|
|
2503
|
+
def test_validates_numericality_with_greater_than_or_equal
|
|
2504
|
+
Topic.validates_numericality_of :approved, :greater_than_or_equal_to => 10
|
|
2505
|
+
|
|
2506
|
+
invalid!([-9, 9], 'Approved must be greater than or equal to 10',
|
|
2507
|
+
"承認は10以上の値にしてください。")
|
|
2508
|
+
# valid!([10])
|
|
2509
|
+
end
|
|
2510
|
+
|
|
2511
|
+
def test_validates_numericality_with_equal_to
|
|
2512
|
+
Topic.validates_numericality_of :approved, :equal_to => 10
|
|
2513
|
+
|
|
2514
|
+
invalid!([-10, 11], 'Approved must be equal to 10',
|
|
2515
|
+
"承認は10にしてください。")
|
|
2516
|
+
# valid!([10])
|
|
2517
|
+
end
|
|
2518
|
+
|
|
2519
|
+
def test_validates_numericality_with_less_than
|
|
2520
|
+
Topic.validates_numericality_of :approved, :less_than => 10
|
|
2521
|
+
|
|
2522
|
+
invalid!([10], 'Approved must be less than 10',
|
|
2523
|
+
"承認は10より小さい値にしてください。")
|
|
2524
|
+
# valid!([-9, 9])
|
|
2525
|
+
end
|
|
2526
|
+
|
|
2527
|
+
def test_validates_numericality_with_less_than_or_equal_to
|
|
2528
|
+
Topic.validates_numericality_of :approved, :less_than_or_equal_to => 10
|
|
2529
|
+
|
|
2530
|
+
invalid!([11], 'Approved must be less than or equal to 10')
|
|
2531
|
+
# valid!([-10, 10])
|
|
2532
|
+
end
|
|
2533
|
+
|
|
2534
|
+
def test_validates_numericality_with_odd
|
|
2535
|
+
Topic.validates_numericality_of :approved, :odd => true
|
|
2536
|
+
|
|
2537
|
+
invalid!([-2, 2], 'Approved must be odd',
|
|
2538
|
+
"承認は奇数にしてください。")
|
|
2539
|
+
# valid!([-1, 1])
|
|
2540
|
+
end
|
|
2541
|
+
|
|
2542
|
+
def test_validates_numericality_with_even
|
|
2543
|
+
Topic.validates_numericality_of :approved, :even => true
|
|
2544
|
+
|
|
2545
|
+
invalid!([-1, 1], 'Approved must be even',
|
|
2546
|
+
"承認は偶数にしてください。")
|
|
2547
|
+
# valid!([-2, 2])
|
|
2548
|
+
end
|
|
2549
|
+
|
|
2550
|
+
def test_validates_numericality_with_greater_than_less_than_and_even
|
|
2551
|
+
Topic.validates_numericality_of :approved, :greater_than => 1, :less_than => 4, :even => true
|
|
2552
|
+
|
|
2553
|
+
invalid!([1, 3, 4])
|
|
2554
|
+
# valid!([2])
|
|
2555
|
+
end
|
|
2556
|
+
|
|
2557
|
+
def test_validates_numericality_with_numeric_message
|
|
2558
|
+
Topic.validates_numericality_of :approved, :less_than => 4, :message => N_("smaller than %d")
|
|
2559
|
+
topic = Topic.new("title" => "numeric test", "approved" => 10)
|
|
2560
|
+
|
|
2561
|
+
assert !topic.valid?
|
|
2562
|
+
assert_equal "Approved smaller than 4", topic.errors.full_messages[0]
|
|
2563
|
+
assert_equal "smaller than 4", topic.errors.on(:approved)
|
|
2564
|
+
|
|
2565
|
+
Topic.validates_numericality_of :approved, :greater_than => 4, :message => N_("greater than %d")
|
|
2566
|
+
topic = Topic.new("title" => "numeric test", "approved" => 1)
|
|
2567
|
+
|
|
2568
|
+
assert !topic.valid?
|
|
2569
|
+
assert_equal "Approved greater than 4", topic.errors.full_messages[0]
|
|
2570
|
+
assert_equal "greater than 4", topic.errors.on(:approved)
|
|
2571
|
+
end
|
|
2572
|
+
|
|
2573
|
+
private
|
|
2574
|
+
def invalid!(values, error=nil, errorj=nil)
|
|
2575
|
+
with_each_topic_approved_value(values) do |topic, value|
|
|
2576
|
+
GetText.set_locale_all "ja"
|
|
2577
|
+
assert !topic.valid?, "#{value.inspect} not rejected as a number"
|
|
2578
|
+
assert topic.errors.on(:approved)
|
|
2579
|
+
assert_equal errorj, topic.errors.full_messages[0] if errorj
|
|
2580
|
+
assert_equal errorj, topic.errors.on(:approved) if errorj
|
|
2581
|
+
end
|
|
2582
|
+
|
|
2583
|
+
with_each_topic_approved_value(values) do |topic, value|
|
|
2584
|
+
GetText.set_locale_all "en"
|
|
2585
|
+
assert !topic.valid?, "#{value.inspect} not rejected as a number"
|
|
2586
|
+
assert topic.errors.on(:approved)
|
|
2587
|
+
assert_equal error, topic.errors.full_messages[0] if error
|
|
2588
|
+
assert_equal error, topic.errors.on(:approved) if error
|
|
2589
|
+
end
|
|
2590
|
+
end
|
|
2591
|
+
=begin
|
|
2592
|
+
# Don't need this
|
|
2593
|
+
def valid!(values)
|
|
2594
|
+
with_each_topic_approved_value(values) do |topic, value|
|
|
2595
|
+
assert topic.valid?, "#{value.inspect} not accepted as a number"
|
|
2596
|
+
end
|
|
2597
|
+
end
|
|
2598
|
+
=end
|
|
2599
|
+
def with_each_topic_approved_value(values)
|
|
2600
|
+
topic = Topic.new("title" => "numeric test", "content" => "whatever")
|
|
2601
|
+
values.each do |value|
|
|
2602
|
+
topic.approved = value
|
|
2603
|
+
yield topic, value
|
|
2604
|
+
end
|
|
2605
|
+
end
|
|
2606
|
+
end
|