stringex 2.0.11 → 2.8.6
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.
- checksums.yaml +6 -14
- data/Gemfile +45 -14
- data/MIT-LICENSE +1 -1
- data/README.md +162 -0
- data/Rakefile +5 -31
- data/VERSION +1 -1
- data/lib/stringex/acts_as_url/adapter/active_record.rb +1 -1
- data/lib/stringex/acts_as_url/adapter/base.rb +37 -5
- data/lib/stringex/acts_as_url/adapter/data_mapper.rb +3 -7
- data/lib/stringex/acts_as_url/adapter/mongoid.rb +2 -2
- data/lib/stringex/acts_as_url.rb +11 -4
- data/lib/stringex/configuration/acts_as_url.rb +15 -10
- data/lib/stringex/configuration/string_extensions.rb +7 -6
- data/lib/stringex/core_ext.rb +10 -0
- data/lib/stringex/localization/backend/i18n.rb +16 -3
- data/lib/stringex/localization/conversion_expressions.rb +64 -60
- data/lib/stringex/localization/converter.rb +8 -4
- data/lib/stringex/localization/default_conversions.rb +56 -55
- data/lib/stringex/localization.rb +2 -2
- data/lib/stringex/string_extensions.rb +34 -6
- data/lib/stringex/unidecoder.rb +26 -22
- data/lib/stringex/unidecoder_data/x00.yml +1 -1
- data/lib/stringex/unidecoder_data/x03.yml +2 -2
- data/lib/stringex/unidecoder_data/x05.yml +1 -1
- data/lib/stringex/unidecoder_data/x07.yml +1 -1
- data/lib/stringex/unidecoder_data/x09.yml +2 -2
- data/lib/stringex/unidecoder_data/x0a.yml +2 -2
- data/lib/stringex/unidecoder_data/x0f.yml +1 -1
- data/lib/stringex/unidecoder_data/x12.yml +1 -1
- data/lib/stringex/unidecoder_data/x13.yml +1 -1
- data/lib/stringex/unidecoder_data/x14.yml +2 -2
- data/lib/stringex/unidecoder_data/x15.yml +1 -1
- data/lib/stringex/unidecoder_data/x16.yml +2 -2
- data/lib/stringex/unidecoder_data/x18.yml +2 -2
- data/lib/stringex/unidecoder_data/x20.yml +4 -4
- data/lib/stringex/unidecoder_data/x21.yml +28 -28
- data/lib/stringex/unidecoder_data/x25.yml +16 -16
- data/lib/stringex/unidecoder_data/x28.yml +1 -1
- data/lib/stringex/unidecoder_data/x30.yml +2 -2
- data/lib/stringex/unidecoder_data/x32.yml +1 -1
- data/lib/stringex/unidecoder_data/xa1.yml +1 -1
- data/lib/stringex/unidecoder_data/xb1.yml +1 -1
- data/lib/stringex/unidecoder_data/xc6.yml +2 -2
- data/lib/stringex/unidecoder_data/xfe.yml +3 -3
- data/lib/stringex/unidecoder_data/xff.yml +5 -5
- data/lib/stringex.rb +1 -2
- data/locales/da.yml +2 -1
- data/locales/de.yml +1 -0
- data/locales/en.yml +1 -0
- data/locales/fr.yml +72 -0
- data/locales/nb.yml +76 -0
- data/locales/nl.yml +69 -0
- data/locales/no.yml +76 -0
- data/locales/pl.yml +88 -0
- data/locales/pt-BR.yml +1 -0
- data/locales/ru.yml +1 -0
- data/locales/sv.yml +76 -0
- data/stringex.gemspec +38 -59
- data/test/unit/acts_as_url/adapter/{active_record.rb → activerecord.rb} +4 -5
- data/test/unit/acts_as_url/adapter/{data_mapper.rb → datamapper.rb} +2 -3
- data/test/unit/acts_as_url/adapter/mongoid.rb +18 -11
- data/test/unit/acts_as_url_configuration_test.rb +2 -2
- data/test/unit/acts_as_url_integration_test.rb +169 -73
- data/test/unit/localization/da_test.rb +3 -2
- data/test/unit/localization/de_test.rb +1 -0
- data/test/unit/localization/default_test.rb +2 -0
- data/test/unit/localization/en_test.rb +1 -0
- data/test/unit/localization/fr_test.rb +118 -0
- data/test/unit/localization/nl_test.rb +118 -0
- data/test/unit/localization/pl_test.rb +118 -0
- data/test/unit/localization/pt_br_test.rb +118 -0
- data/test/unit/localization/ru_test.rb +2 -1
- data/test/unit/localization/sv_test.rb +118 -0
- data/test/unit/localization_test.rb +39 -19
- data/test/unit/string_extensions_test.rb +60 -6
- data/test/unit/unicode_point_suite/basic_greek_test.rb +1 -1
- data/test/unit/unicode_point_suite/basic_latin_test.rb +3 -1
- data/test/unit/unidecoder_test.rb +2 -1
- metadata +47 -94
- data/README.rdoc +0 -131
- data/test/unit/redcloth_to_html_test.rb +0 -37
@@ -2,56 +2,121 @@
|
|
2
2
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
adapter = ENV['ADAPTER'] || '
|
5
|
+
adapter = ENV['ADAPTER'] || 'activerecord'
|
6
6
|
require File.join(File.expand_path(File.dirname(__FILE__)), "acts_as_url/adapter/#{adapter}.rb")
|
7
7
|
|
8
8
|
class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
9
9
|
include AdapterSpecificTestBehaviors
|
10
10
|
|
11
11
|
def test_should_create_url
|
12
|
-
@doc = Document.create(:
|
12
|
+
@doc = Document.create(title: "Let's Make a Test Title, <em>Okay</em>?")
|
13
13
|
assert_equal "lets-make-a-test-title-okay", @doc.url
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_should_create_unique_url
|
17
|
-
@doc = Document.create(:
|
18
|
-
@other_doc = Document.create(:
|
17
|
+
@doc = Document.create(title: "Unique")
|
18
|
+
@other_doc = Document.create(title: "Unique")
|
19
19
|
assert_equal "unique", @doc.url
|
20
20
|
assert_equal "unique-1", @other_doc.url
|
21
21
|
end
|
22
22
|
|
23
|
+
def test_should_allow_custom_duplicates
|
24
|
+
sequence = Enumerator.new { |enum| loop { enum.yield 12345 } }
|
25
|
+
Document.class_eval do
|
26
|
+
acts_as_url :title, duplicate_sequence: sequence
|
27
|
+
end
|
28
|
+
|
29
|
+
@doc = Document.create(title: "New")
|
30
|
+
@other_doc = Document.create(title: "New")
|
31
|
+
assert_equal "new-document", @doc.url
|
32
|
+
assert_equal "new-document-12345", @other_doc.url
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_restart_duplicate_sequence_each_time
|
36
|
+
sequence = Enumerator.new do |enum|
|
37
|
+
n = 1
|
38
|
+
loop do
|
39
|
+
enum.yield n
|
40
|
+
n += 1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
Document.class_eval do
|
44
|
+
acts_as_url :title, duplicate_sequence: sequence
|
45
|
+
end
|
46
|
+
@doc = Document.create(title: "Unique")
|
47
|
+
@other_doc = Document.create(title: "Unique")
|
48
|
+
@third_doc = Document.create(title: "Another")
|
49
|
+
@fourth_doc = Document.create(title: "Another")
|
50
|
+
assert_equal "unique", @doc.url
|
51
|
+
assert_equal "unique-1", @other_doc.url
|
52
|
+
assert_equal "another", @third_doc.url
|
53
|
+
assert_equal "another-1", @fourth_doc.url
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_avoid_blacklist
|
57
|
+
@doc = Document.create(title: "New")
|
58
|
+
@other_doc = Document.create(title: "new")
|
59
|
+
assert_equal "new-document", @doc.url
|
60
|
+
assert_equal "new-document-1", @other_doc.url
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_allow_customizing_blacklist
|
64
|
+
Document.class_eval do
|
65
|
+
# Un-blacklisting 'new' isn't advisable
|
66
|
+
acts_as_url :title, blacklist: %w{special}
|
67
|
+
end
|
68
|
+
|
69
|
+
@doc = Document.create(title: "New")
|
70
|
+
@other_doc = Document.create(title: "Special")
|
71
|
+
assert_equal 'new', @doc.url
|
72
|
+
assert_equal 'special-document', @other_doc.url
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_should_allow_customizing_blacklist_policy
|
76
|
+
Document.class_eval do
|
77
|
+
acts_as_url :title, blacklist_policy: Proc.new(){|instance, url|
|
78
|
+
"#{url}-customized"
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
@doc = Document.create(title: "New")
|
83
|
+
@other_doc = Document.create(title: "New")
|
84
|
+
assert_equal 'new-customized', @doc.url
|
85
|
+
assert_equal 'new-customized-1', @other_doc.url
|
86
|
+
end
|
87
|
+
|
23
88
|
def test_should_create_unique_url_when_partial_url_already_exists
|
24
|
-
@doc = Document.create(:
|
25
|
-
@other_doc = Document.create(:
|
89
|
+
@doc = Document.create(title: "House Farms")
|
90
|
+
@other_doc = Document.create(title: "House Farm")
|
26
91
|
|
27
92
|
assert_equal "house-farms", @doc.url
|
28
93
|
assert_equal "house-farm", @other_doc.url
|
29
94
|
end
|
30
95
|
|
31
96
|
def test_should_not_sync_url_by_default
|
32
|
-
@doc = Document.create(:
|
97
|
+
@doc = Document.create(title: "Stable as Stone")
|
33
98
|
@original_url = @doc.url
|
34
|
-
adapter_specific_update @doc, :
|
99
|
+
adapter_specific_update @doc, title: "New Unstable Madness"
|
35
100
|
assert_equal @original_url, @doc.url
|
36
101
|
end
|
37
102
|
|
38
103
|
def test_should_allow_syncing_url
|
39
104
|
Document.class_eval do
|
40
|
-
acts_as_url :title, :
|
105
|
+
acts_as_url :title, sync_url: true
|
41
106
|
end
|
42
107
|
|
43
|
-
@doc = Document.create(:
|
108
|
+
@doc = Document.create(title: "Original")
|
44
109
|
@original_url = @doc.url
|
45
|
-
adapter_specific_update @doc, :
|
110
|
+
adapter_specific_update @doc, title: "New and Improved"
|
46
111
|
assert_not_equal @original_url, @doc.url
|
47
112
|
end
|
48
113
|
|
49
114
|
def test_should_not_increment_count_on_repeated_saves
|
50
115
|
Document.class_eval do
|
51
|
-
acts_as_url :title, :
|
116
|
+
acts_as_url :title, sync_url: true
|
52
117
|
end
|
53
118
|
|
54
|
-
@doc = Document.create(:
|
119
|
+
@doc = Document.create(title: "Continuous or Constant")
|
55
120
|
assert_equal "continuous-or-constant", @doc.url
|
56
121
|
5.times do |n|
|
57
122
|
@doc.save!
|
@@ -61,54 +126,54 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
61
126
|
|
62
127
|
def test_should_allow_allowing_duplicate_url
|
63
128
|
Document.class_eval do
|
64
|
-
acts_as_url :title, :
|
129
|
+
acts_as_url :title, allow_duplicates: true
|
65
130
|
end
|
66
131
|
|
67
|
-
@doc = Document.create(:
|
68
|
-
@other_doc = Document.create(:
|
132
|
+
@doc = Document.create(title: "I am not a clone")
|
133
|
+
@other_doc = Document.create(title: "I am not a clone")
|
69
134
|
assert_equal @doc.url, @other_doc.url
|
70
135
|
end
|
71
136
|
|
72
137
|
def test_should_allow_scoping_url_uniqueness
|
73
138
|
Document.class_eval do
|
74
|
-
acts_as_url :title, :
|
139
|
+
acts_as_url :title, scope: :other
|
75
140
|
end
|
76
141
|
|
77
|
-
@doc = Document.create(:
|
78
|
-
@other_doc = Document.create(:
|
142
|
+
@doc = Document.create(title: "Mocumentary", other: "I don't care if I'm unique for some reason")
|
143
|
+
@other_doc = Document.create(title: "Mocumentary", other: "Me either")
|
79
144
|
assert_equal @doc.url, @other_doc.url
|
80
145
|
end
|
81
146
|
|
82
147
|
def test_should_still_create_unique_urls_if_scoped_attribute_is_the_same
|
83
148
|
Document.class_eval do
|
84
|
-
acts_as_url :title, :
|
149
|
+
acts_as_url :title, scope: :other
|
85
150
|
end
|
86
151
|
|
87
|
-
@doc = Document.create(:
|
88
|
-
@other_doc = Document.create(:
|
152
|
+
@doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique")
|
153
|
+
@other_doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique")
|
89
154
|
assert_not_equal @doc.url, @other_doc.url
|
90
155
|
end
|
91
156
|
|
92
157
|
def test_should_allow_multiple_scopes
|
93
158
|
Document.class_eval do
|
94
|
-
acts_as_url :title, :
|
159
|
+
acts_as_url :title, scope: [:other, :another]
|
95
160
|
end
|
96
161
|
|
97
|
-
@doc = Document.create(:
|
98
|
-
:
|
99
|
-
@other_doc = Document.create(:
|
162
|
+
@doc = Document.create(title: "Mocumentary", other: "I don't care if I'm unique for some reason",
|
163
|
+
another: "Whatever")
|
164
|
+
@other_doc = Document.create(title: "Mocumentary", other: "Me either", another: "Whatever")
|
100
165
|
assert_equal @doc.url, @other_doc.url
|
101
166
|
end
|
102
167
|
|
103
168
|
def test_should_only_create_unique_urls_for_multiple_scopes_if_both_attributes_are_same
|
104
169
|
Document.class_eval do
|
105
|
-
acts_as_url :title, :
|
170
|
+
acts_as_url :title, scope: [:other, :another]
|
106
171
|
end
|
107
172
|
|
108
|
-
@doc = Document.create(:
|
109
|
-
:
|
110
|
-
@other_doc = Document.create(:
|
111
|
-
:
|
173
|
+
@doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique",
|
174
|
+
another: "Whatever")
|
175
|
+
@other_doc = Document.create(title: "Mocumentary", other: "Suddenly, I care if I'm unique",
|
176
|
+
another: "Whatever")
|
112
177
|
assert_not_equal @doc.url, @other_doc.url
|
113
178
|
end
|
114
179
|
|
@@ -117,10 +182,10 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
117
182
|
# Manually undefining the url method on Document which, in a real class not reused for tests,
|
118
183
|
# would never have been defined to begin with.
|
119
184
|
remove_method :url
|
120
|
-
acts_as_url :title, :
|
185
|
+
acts_as_url :title, url_attribute: :other
|
121
186
|
end
|
122
187
|
|
123
|
-
@doc = Document.create(:
|
188
|
+
@doc = Document.create(title: "Anything at This Point")
|
124
189
|
assert_equal "anything-at-this-point", @doc.other
|
125
190
|
assert_nil @doc.url
|
126
191
|
ensure
|
@@ -132,21 +197,21 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
132
197
|
|
133
198
|
def test_should_allow_updating_url_only_when_blank
|
134
199
|
Document.class_eval do
|
135
|
-
acts_as_url :title, :
|
200
|
+
acts_as_url :title, only_when_blank: true
|
136
201
|
end
|
137
202
|
|
138
203
|
@string = 'the-url-of-concrete'
|
139
|
-
@doc = Document.create(:
|
204
|
+
@doc = Document.create(title: "Stable as Stone", url: @string)
|
140
205
|
assert_equal @string, @doc.url
|
141
|
-
@other_doc = Document.create(:
|
206
|
+
@other_doc = Document.create(title: "Stable as Stone")
|
142
207
|
assert_equal 'stable-as-stone', @other_doc.url
|
143
208
|
end
|
144
209
|
|
145
210
|
def test_should_mass_initialize_urls
|
146
|
-
@doc = Document.create(:
|
147
|
-
@other_doc = Document.create(:
|
148
|
-
adapter_specific_update @doc, :
|
149
|
-
adapter_specific_update @other_doc, :
|
211
|
+
@doc = Document.create(title: "Initial")
|
212
|
+
@other_doc = Document.create(title: "Subsequent")
|
213
|
+
adapter_specific_update @doc, url: nil
|
214
|
+
adapter_specific_update @other_doc, url: nil
|
150
215
|
# Just making sure this got unset before the real test
|
151
216
|
assert_nil @doc.url
|
152
217
|
assert_nil @other_doc.url
|
@@ -164,13 +229,13 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
164
229
|
# Manually undefining the url method on Document which, in a real class not reused for tests,
|
165
230
|
# would never have been defined to begin with.
|
166
231
|
remove_method :url
|
167
|
-
acts_as_url :title, :
|
232
|
+
acts_as_url :title, url_attribute: :other
|
168
233
|
end
|
169
234
|
|
170
|
-
@doc = Document.create(:
|
171
|
-
@other_doc = Document.create(:
|
172
|
-
adapter_specific_update @doc, :
|
173
|
-
adapter_specific_update @other_doc, :
|
235
|
+
@doc = Document.create(title: "Initial")
|
236
|
+
@other_doc = Document.create(title: "Subsequent")
|
237
|
+
adapter_specific_update @doc, other: nil
|
238
|
+
adapter_specific_update @other_doc, other: nil
|
174
239
|
# Just making sure this got unset before the real test
|
175
240
|
assert_nil @doc.other
|
176
241
|
assert_nil @other_doc.other
|
@@ -189,10 +254,10 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
189
254
|
end
|
190
255
|
|
191
256
|
def test_should_mass_initialize_empty_string_urls
|
192
|
-
@doc = Document.create(:
|
193
|
-
@other_doc = Document.create(:
|
194
|
-
adapter_specific_update @doc, :
|
195
|
-
adapter_specific_update @other_doc, :
|
257
|
+
@doc = Document.create(title: "Initial")
|
258
|
+
@other_doc = Document.create(title: "Subsequent")
|
259
|
+
adapter_specific_update @doc, url: ''
|
260
|
+
adapter_specific_update @other_doc, url: ''
|
196
261
|
# Just making sure this got unset before the real test
|
197
262
|
assert_equal '', @doc.url
|
198
263
|
assert_equal '', @other_doc.url
|
@@ -214,7 +279,7 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
214
279
|
end
|
215
280
|
end
|
216
281
|
|
217
|
-
@doc = Document.create(:
|
282
|
+
@doc = Document.create(title: "Title String")
|
218
283
|
assert_equal "title-string-got-massaged", @doc.url
|
219
284
|
ensure
|
220
285
|
Document.class_eval do
|
@@ -225,22 +290,22 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
225
290
|
|
226
291
|
def test_should_allow_customizing_duplicate_count_separator
|
227
292
|
Document.class_eval do
|
228
|
-
acts_as_url :title, :
|
293
|
+
acts_as_url :title, duplicate_count_separator: "---"
|
229
294
|
end
|
230
295
|
|
231
|
-
@doc = Document.create(:
|
232
|
-
@other_doc = Document.create(:
|
296
|
+
@doc = Document.create(title: "Unique")
|
297
|
+
@other_doc = Document.create(title: "Unique")
|
233
298
|
assert_equal "unique", @doc.url
|
234
299
|
assert_equal "unique---1", @other_doc.url
|
235
300
|
end
|
236
301
|
|
237
302
|
def test_should_only_update_url_if_url_attribute_is_valid
|
238
303
|
Document.class_eval do
|
239
|
-
acts_as_url :title, :
|
304
|
+
acts_as_url :title, sync_url: true
|
240
305
|
end
|
241
306
|
add_validation_on_document_title
|
242
307
|
|
243
|
-
@doc = Document.create(:
|
308
|
+
@doc = Document.create(title: "Valid Record", other: "Present")
|
244
309
|
assert_equal "valid-record", @doc.url
|
245
310
|
@doc.title = nil
|
246
311
|
assert_equal false, @doc.valid?
|
@@ -251,61 +316,61 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
251
316
|
|
252
317
|
def test_should_allow_customizing_url_limit
|
253
318
|
Document.class_eval do
|
254
|
-
acts_as_url :title, :
|
319
|
+
acts_as_url :title, limit: 13
|
255
320
|
end
|
256
321
|
|
257
|
-
@doc = Document.create(:
|
322
|
+
@doc = Document.create(title: "I am much too long")
|
258
323
|
assert_equal "i-am-much-too", @doc.url
|
259
324
|
end
|
260
325
|
|
261
326
|
def test_handling_duplicate_urls_with_limits
|
262
327
|
Document.class_eval do
|
263
|
-
acts_as_url :title, :
|
328
|
+
acts_as_url :title, limit: 13
|
264
329
|
end
|
265
330
|
|
266
|
-
@doc = Document.create(:
|
331
|
+
@doc = Document.create(title: "I am much too long and also duplicated")
|
267
332
|
assert_equal "i-am-much-too", @doc.url
|
268
|
-
@other_doc = Document.create(:
|
333
|
+
@other_doc = Document.create(title: "I am much too long and also duplicated")
|
269
334
|
assert_equal "i-am-much-too-1", @other_doc.url
|
270
335
|
end
|
271
336
|
|
272
337
|
def test_should_allow_excluding_specific_values_from_being_run_through_to_url
|
273
338
|
Document.class_eval do
|
274
|
-
acts_as_url :title, :
|
339
|
+
acts_as_url :title, exclude: ["_So_Fucking_Special"]
|
275
340
|
end
|
276
341
|
|
277
|
-
@doc = Document.create(:
|
342
|
+
@doc = Document.create(title: "_So_Fucking_Special")
|
278
343
|
assert_equal "_So_Fucking_Special", @doc.url
|
279
|
-
@doc_2 = Document.create(:
|
344
|
+
@doc_2 = Document.create(title: "But I'm a creep")
|
280
345
|
assert_equal "but-im-a-creep", @doc_2.url
|
281
346
|
end
|
282
347
|
|
283
348
|
def test_should_allow_not_forcing_downcasing
|
284
349
|
Document.class_eval do
|
285
|
-
acts_as_url :title, :
|
350
|
+
acts_as_url :title, force_downcase: false
|
286
351
|
end
|
287
352
|
|
288
|
-
@doc = Document.create(:
|
353
|
+
@doc = Document.create(title: "I have CAPS!")
|
289
354
|
assert_equal "I-have-CAPS", @doc.url
|
290
355
|
end
|
291
356
|
|
292
357
|
def test_should_allow_alternate_whitespace_replacements
|
293
358
|
Document.class_eval do
|
294
|
-
acts_as_url :title, :
|
359
|
+
acts_as_url :title, replace_whitespace_with: "~"
|
295
360
|
end
|
296
361
|
|
297
|
-
@doc = Document.create(:
|
362
|
+
@doc = Document.create(title: "now with tildes")
|
298
363
|
assert_equal "now~with~tildes", @doc.url
|
299
364
|
end
|
300
365
|
|
301
366
|
def test_should_allow_enforcing_uniqueness_on_sti_base_class
|
302
367
|
STIBaseDocument.class_eval do
|
303
|
-
acts_as_url :title, :
|
368
|
+
acts_as_url :title, enforce_uniqueness_on_sti_base_class: true
|
304
369
|
end
|
305
370
|
|
306
|
-
@doc = STIChildDocument.create(:
|
371
|
+
@doc = STIChildDocument.create(title: "Unique")
|
307
372
|
assert_equal "unique", @doc.url
|
308
|
-
@doc_2 = AnotherSTIChildDocument.create(:
|
373
|
+
@doc_2 = AnotherSTIChildDocument.create(title: "Unique")
|
309
374
|
assert_equal "unique-1", @doc_2.url
|
310
375
|
end
|
311
376
|
|
@@ -314,16 +379,47 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
314
379
|
acts_as_url :title
|
315
380
|
end
|
316
381
|
|
317
|
-
@doc = Document.create(:
|
382
|
+
@doc = Document.create(title: "a b/c d")
|
318
383
|
assert_equal "a-b-slash-c-d", @doc.url
|
319
384
|
end
|
320
385
|
|
321
386
|
def test_should_allow_slashes_to_be_allowed
|
322
387
|
Document.class_eval do
|
323
|
-
acts_as_url :title, :
|
388
|
+
acts_as_url :title, allow_slash: true
|
324
389
|
end
|
325
390
|
|
326
|
-
@doc = Document.create(:
|
391
|
+
@doc = Document.create(title: "a b/c d")
|
327
392
|
assert_equal "a-b/c-d", @doc.url
|
328
393
|
end
|
394
|
+
|
395
|
+
def test_should_truncate_words_by_default
|
396
|
+
Document.class_eval do
|
397
|
+
acts_as_url :title, limit: 20
|
398
|
+
end
|
399
|
+
|
400
|
+
@doc = Document.create(title: "title with many whole words")
|
401
|
+
assert_equal 'title-with-many-whol', @doc.url
|
402
|
+
end
|
403
|
+
|
404
|
+
def test_should_not_truncate_words
|
405
|
+
Document.class_eval do
|
406
|
+
acts_as_url :title, limit: 20, truncate_words: false
|
407
|
+
end
|
408
|
+
|
409
|
+
@doc = Document.create(title: "title with many whole words")
|
410
|
+
assert_equal 'title-with-many', @doc.url
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_should_allow_overriding_url_taken_method
|
414
|
+
Document.class_eval do
|
415
|
+
acts_as_url :title, url_taken_method: :url_taken?
|
416
|
+
|
417
|
+
def url_taken?(url)
|
418
|
+
["unique", "unique-1", "unique-2"].include?(url)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
@doc = Document.create(title: "unique")
|
423
|
+
assert_equal "unique-3", @doc.url
|
424
|
+
end
|
329
425
|
end
|
@@ -25,7 +25,7 @@ class DanishYAMLLocalizationTest < Test::Unit::TestCase
|
|
25
25
|
"cost+tax" => "cost plus tax",
|
26
26
|
"batman/robin fan fiction" => "batman skråstreg robin fan fiction",
|
27
27
|
"dial *69" => "dial stjerne 69",
|
28
|
-
|
28
|
+
" i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
|
29
29
|
}.each do |original, converted|
|
30
30
|
define_method "test_character_conversion: '#{original}'" do
|
31
31
|
assert_equal converted, original.convert_miscellaneous_characters
|
@@ -33,6 +33,7 @@ class DanishYAMLLocalizationTest < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
{
|
36
|
+
"¤20" => "20 kroner",
|
36
37
|
"$100" => "100 dollars",
|
37
38
|
"$19.99" => "19 dollars 99 cents",
|
38
39
|
"£100" => "100 pund",
|
@@ -47,7 +48,7 @@ class DanishYAMLLocalizationTest < Test::Unit::TestCase
|
|
47
48
|
end
|
48
49
|
|
49
50
|
{
|
50
|
-
"Tea & Sympathy" => "Tea
|
51
|
+
"Tea & Sympathy" => "Tea og Sympathy",
|
51
52
|
"10¢" => "10 cents",
|
52
53
|
"©2000" => "(c)2000",
|
53
54
|
"98° is fine" => "98 grader is fine",
|
@@ -8,6 +8,7 @@ class DefaultLocalizationTest < Test::Unit::TestCase
|
|
8
8
|
Stringex::Localization.reset!
|
9
9
|
Stringex::Localization.backend = :internal
|
10
10
|
end
|
11
|
+
|
11
12
|
{
|
12
13
|
"foo & bar" => "foo and bar",
|
13
14
|
"AT&T" => "AT and T",
|
@@ -29,6 +30,7 @@ class DefaultLocalizationTest < Test::Unit::TestCase
|
|
29
30
|
end
|
30
31
|
|
31
32
|
{
|
33
|
+
"¤20" => "20 dollars",
|
32
34
|
"$100" => "100 dollars",
|
33
35
|
"$19.99" => "19 dollars 99 cents",
|
34
36
|
"£100" => "100 pounds",
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'i18n'
|
5
|
+
require 'stringex'
|
6
|
+
|
7
|
+
class FrenchYAMLLocalizationTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
Stringex::Localization.reset!
|
10
|
+
Stringex::Localization.backend = :i18n
|
11
|
+
Stringex::Localization.backend.load_translations :fr
|
12
|
+
Stringex::Localization.locale = :fr
|
13
|
+
end
|
14
|
+
|
15
|
+
{
|
16
|
+
"foo & bar" => "foo et bar",
|
17
|
+
"AT&T" => "AT et T",
|
18
|
+
"99° est normal" => "99 degrés est normal",
|
19
|
+
"4 ÷ 2 is 2" => "4 divisé par 2 is 2",
|
20
|
+
"webcrawler.com" => "webcrawler point com",
|
21
|
+
"Well..." => "Well point point point",
|
22
|
+
"x=1" => "x égal 1",
|
23
|
+
"a #2 pencil" => "a numéro 2 pencil",
|
24
|
+
"100%" => "100 pourcent",
|
25
|
+
"cost+tax" => "cost plus tax",
|
26
|
+
"batman/robin fan fiction" => "batman slash robin fan fiction",
|
27
|
+
"dial *69" => "dial étoile 69",
|
28
|
+
" i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
|
29
|
+
}.each do |original, converted|
|
30
|
+
define_method "test_character_conversion: '#{original}'" do
|
31
|
+
assert_equal converted, original.convert_miscellaneous_characters
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
{
|
36
|
+
"¤20" => "20 livres",
|
37
|
+
"$100" => "100 dollars",
|
38
|
+
"$19.99" => "19 dollars 99 cents",
|
39
|
+
"£100" => "100 livres",
|
40
|
+
"£19.99" => "19 livres 99 pennies",
|
41
|
+
"€100" => "100 euros",
|
42
|
+
"€19.99" => "19 euros 99 cents",
|
43
|
+
"¥1000" => "1000 yen"
|
44
|
+
}.each do |original, converted|
|
45
|
+
define_method "test_currency_conversion: '#{original}'" do
|
46
|
+
assert_equal converted, original.convert_miscellaneous_characters
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
{
|
51
|
+
"Tea & Sympathy" => "Tea et Sympathy",
|
52
|
+
"10¢" => "10 cents",
|
53
|
+
"©2000" => "(c)2000",
|
54
|
+
"98° is fine" => "98 degrés is fine",
|
55
|
+
"10÷5" => "10 divisé par 5",
|
56
|
+
""quoted"" => '"quoted"',
|
57
|
+
"to be continued…" => "to be continued...",
|
58
|
+
"2000–2004" => "2000-2004",
|
59
|
+
"I wish—oh, never mind" => "I wish--oh, never mind",
|
60
|
+
"½ ounce of gold" => "un demi ounce of gold",
|
61
|
+
"1 et ¼ d'once de platinium" => "1 et un quart d'once de platinium",
|
62
|
+
"9 et ¾ d'once de platinium" => "9 et trois quarts d'once de platinium",
|
63
|
+
"3>2" => "3>2",
|
64
|
+
"2<3" => "2<3",
|
65
|
+
"two words" => "two words",
|
66
|
+
"£100" => "livres 100",
|
67
|
+
"Walmart®" => "Walmart(r)",
|
68
|
+
"'single quoted'" => "'single quoted'",
|
69
|
+
"2×4" => "2x4",
|
70
|
+
"Programming™" => "Programming(tm)",
|
71
|
+
"¥20000" => "yen 20000",
|
72
|
+
" i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
|
73
|
+
}.each do |original, converted|
|
74
|
+
define_method "test_html_entity_conversion: '#{original}'" do
|
75
|
+
assert_equal converted, original.convert_miscellaneous_html_entities
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
{
|
80
|
+
"½" => "un demi",
|
81
|
+
"½" => "un demi",
|
82
|
+
"½" => "un demi",
|
83
|
+
"⅓" => "un tiers",
|
84
|
+
"⅓" => "un tiers",
|
85
|
+
"⅔" => "deux tiers",
|
86
|
+
"⅔" => "deux tiers",
|
87
|
+
"¼" => "un quart",
|
88
|
+
"¼" => "un quart",
|
89
|
+
"¼" => "un quart",
|
90
|
+
"¾" => "trois quarts",
|
91
|
+
"¾" => "trois quarts",
|
92
|
+
"¾" => "trois quarts",
|
93
|
+
"⅕" => "un cinquième",
|
94
|
+
"⅕" => "un cinquième",
|
95
|
+
"⅖" => "deux cinquièmes",
|
96
|
+
"⅖" => "deux cinquièmes",
|
97
|
+
"⅗" => "trois cinquièmes",
|
98
|
+
"⅗" => "trois cinquièmes",
|
99
|
+
"⅘" => "quatre cinquièmes",
|
100
|
+
"⅘" => "quatre cinquièmes",
|
101
|
+
"⅙" => "un sixième",
|
102
|
+
"⅙" => "un sixième",
|
103
|
+
"⅚" => "cinq sixièmes",
|
104
|
+
"⅚" => "cinq sixièmes",
|
105
|
+
"⅛" => "un huitième",
|
106
|
+
"⅛" => "un huitième",
|
107
|
+
"⅜" => "trois huitièmes",
|
108
|
+
"⅜" => "trois huitièmes",
|
109
|
+
"⅝" => "cinq huitièmes",
|
110
|
+
"⅝" => "cinq huitièmes",
|
111
|
+
"⅞" => "sept huitièmes",
|
112
|
+
"⅞" => "sept huitièmes"
|
113
|
+
}.each do |original, converted|
|
114
|
+
define_method "test_vulgar_fractions_conversion: #{original}" do
|
115
|
+
assert_equal converted, original.convert_vulgar_fractions
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|