stringex 1.5.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +16 -0
  3. data/Gemfile.lock +74 -0
  4. data/README.rdoc +22 -1
  5. data/Rakefile +46 -223
  6. data/VERSION +1 -0
  7. data/init.rb +1 -0
  8. data/lib/stringex.rb +11 -3
  9. data/lib/stringex/acts_as_url.rb +49 -97
  10. data/lib/stringex/acts_as_url/adapter.rb +26 -0
  11. data/lib/stringex/acts_as_url/adapter/active_record.rb +23 -0
  12. data/lib/stringex/acts_as_url/adapter/base.rb +188 -0
  13. data/lib/stringex/acts_as_url/adapter/data_mapper.rb +67 -0
  14. data/lib/stringex/acts_as_url/adapter/mongoid.rb +36 -0
  15. data/lib/stringex/configuration.rb +4 -0
  16. data/lib/stringex/configuration/acts_as_url.rb +44 -0
  17. data/lib/stringex/configuration/base.rb +58 -0
  18. data/lib/stringex/configuration/configurator.rb +25 -0
  19. data/lib/stringex/configuration/string_extensions.rb +19 -0
  20. data/lib/stringex/localization.rb +98 -0
  21. data/lib/stringex/localization/backend/i18n.rb +53 -0
  22. data/lib/stringex/localization/backend/internal.rb +51 -0
  23. data/lib/stringex/localization/conversion_expressions.rb +148 -0
  24. data/lib/stringex/localization/converter.rb +121 -0
  25. data/lib/stringex/localization/default_conversions.rb +88 -0
  26. data/lib/stringex/rails/railtie.rb +10 -0
  27. data/lib/stringex/string_extensions.rb +153 -208
  28. data/lib/stringex/unidecoder.rb +6 -101
  29. data/lib/stringex/unidecoder_data/x00.yml +1 -1
  30. data/lib/stringex/unidecoder_data/x02.yml +5 -5
  31. data/lib/stringex/unidecoder_data/x05.yml +1 -1
  32. data/lib/stringex/unidecoder_data/x06.yml +1 -1
  33. data/lib/stringex/unidecoder_data/x07.yml +3 -3
  34. data/lib/stringex/unidecoder_data/x09.yml +1 -1
  35. data/lib/stringex/unidecoder_data/x0e.yml +2 -2
  36. data/lib/stringex/unidecoder_data/x1f.yml +2 -2
  37. data/lib/stringex/unidecoder_data/x20.yml +1 -1
  38. data/lib/stringex/unidecoder_data/xfb.yml +1 -1
  39. data/lib/stringex/unidecoder_data/xff.yml +1 -1
  40. data/lib/stringex/version.rb +8 -0
  41. data/locales/da.yml +73 -0
  42. data/locales/en.yml +66 -0
  43. data/stringex.gemspec +77 -18
  44. data/test/acts_as_url/adapter/active_record.rb +72 -0
  45. data/test/acts_as_url/adapter/data_mapper.rb +82 -0
  46. data/test/acts_as_url/adapter/mongoid.rb +73 -0
  47. data/test/acts_as_url_configuration_test.rb +51 -0
  48. data/test/acts_as_url_integration_test.rb +271 -0
  49. data/test/localization/da_test.rb +117 -0
  50. data/test/localization/default_test.rb +113 -0
  51. data/test/localization/en_test.rb +117 -0
  52. data/test/localization_test.rb +123 -0
  53. data/test/redcloth_to_html_test.rb +37 -0
  54. data/test/string_extensions_test.rb +59 -91
  55. data/test/test_helper.rb +2 -0
  56. data/test/unicode_point_suite/basic_greek_test.rb +113 -0
  57. data/test/unicode_point_suite/basic_latin_test.rb +142 -0
  58. data/test/unicode_point_suite/codepoint_test_helper.rb +32 -0
  59. data/test/unidecoder/bad_localization.yml +1 -0
  60. data/test/unidecoder/localization.yml +4 -0
  61. data/test/unidecoder_test.rb +3 -5
  62. metadata +145 -37
  63. data/test/acts_as_url_test.rb +0 -272
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+
3
+ # 100% shorthand
4
+ module CodepointTestHelper
5
+ def assert_equal_encoded(expected, encode_mes)
6
+ # Killing a duck because Ruby 1.9 doesn't mix Enumerable into String
7
+ encode_mes = [encode_mes] if encode_mes.is_a?(String)
8
+ encode_mes.each do |encode_me|
9
+ encoded = encode(encode_me)
10
+ actual = encoded.to_ascii
11
+ if expected == actual
12
+ # Let's not retest it
13
+ assert true
14
+ else
15
+ message = "<#{expected.inspect}> expected but was\n<#{actual.inspect}>\n"
16
+ message << " defined in #{Stringex::Unidecoder.in_yaml_file(encoded)}"
17
+ reporting_class = defined?(Test::Unit::AssertionFailedError) ?
18
+ Test::Unit::AssertionFailedError : ActiveSupport::TestCase::Assertion
19
+ raise reporting_class.new(message)
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+ def encode(codepoint)
26
+ Stringex::Unidecoder.encode(codepoint)
27
+ end
28
+
29
+ def which_yaml(codepoint)
30
+ Stringex::Unidecoder.in_yaml_file(encode(codepoint))
31
+ end
32
+ end
@@ -0,0 +1 @@
1
+ Anything not correct
@@ -0,0 +1,4 @@
1
+ en:
2
+ é: ee
3
+ xx:
4
+ é: xx
@@ -1,9 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "test/unit"
4
-
5
- $: << File.join(File.expand_path(File.dirname(__FILE__)), '../lib')
6
- require File.join(File.expand_path(File.dirname(__FILE__)), "../init.rb")
3
+ require "test_helper"
4
+ require "stringex"
7
5
 
8
6
  class UnidecoderTest < Test::Unit::TestCase
9
7
  # Silly phrases courtesy of Frank da Cruz
@@ -40,7 +38,7 @@ class UnidecoderTest < Test::Unit::TestCase
40
38
  "من می توانم بدونِ احساس درد شيشه بخورم" => # Persian
41
39
  "mn my twnm bdwni Hss drd shyshh bkhwrm",
42
40
  "أنا قادر على أكل الزجاج و هذا لا يؤلمن" => # Arabic
43
- "'n qdr `l~ 'kl lzjj w hdh l yw'lmn",
41
+ "'n qdr 'l~ 'kl lzjj w hdh l yw'lmn",
44
42
  "אני יכול לאכול זכוכית וזה לא מזיק לי" => # Hebrew
45
43
  "ny ykvl lkvl zkvkyt vzh l mzyq ly",
46
44
  "ฉันกินกระจกได้ แต่มันไม่ทำให้ฉันเจ็บ" => # Thai
metadata CHANGED
@@ -1,36 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Russell Norris
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-30 00:00:00.000000000 Z
11
+ date: 2013-06-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.13
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.13
27
+ - !ruby/object:Gem::Dependency
28
+ name: dm-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: dm-migrations
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: dm-sqlite-adapter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: dm-validations
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
20
74
  - !ruby/object:Gem::Version
21
- version: '0'
75
+ version: 1.2.0
22
76
  type: :development
23
77
  prerelease: false
24
78
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
79
  requirements:
27
- - - ! '>='
80
+ - - '='
28
81
  - !ruby/object:Gem::Version
29
- version: '0'
82
+ version: 1.2.0
30
83
  - !ruby/object:Gem::Dependency
31
84
  name: jeweler
32
85
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
86
  requirements:
35
87
  - - '='
36
88
  - !ruby/object:Gem::Version
@@ -38,59 +90,80 @@ dependencies:
38
90
  type: :development
39
91
  prerelease: false
40
92
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
93
  requirements:
43
94
  - - '='
44
95
  - !ruby/object:Gem::Version
45
96
  version: 1.8.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: mongoid
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.1.4
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.1.4
46
111
  - !ruby/object:Gem::Dependency
47
112
  name: RedCloth
48
113
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
114
  requirements:
51
- - - ! '>='
115
+ - - '='
52
116
  - !ruby/object:Gem::Version
53
- version: '0'
117
+ version: 4.2.9
54
118
  type: :development
55
119
  prerelease: false
56
120
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
121
  requirements:
59
- - - ! '>='
122
+ - - '='
60
123
  - !ruby/object:Gem::Version
61
- version: '0'
124
+ version: 4.2.9
62
125
  - !ruby/object:Gem::Dependency
63
126
  name: sqlite3
64
127
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
128
  requirements:
67
- - - ! '>='
129
+ - - '='
68
130
  - !ruby/object:Gem::Version
69
- version: '0'
131
+ version: 1.3.7
70
132
  type: :development
71
133
  prerelease: false
72
134
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
135
  requirements:
75
- - - ! '>='
136
+ - - '='
76
137
  - !ruby/object:Gem::Version
77
- version: '0'
138
+ version: 1.3.7
78
139
  - !ruby/object:Gem::Dependency
79
140
  name: travis-lint
80
141
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
142
  requirements:
83
143
  - - '='
84
144
  - !ruby/object:Gem::Version
85
- version: 1.4.0
145
+ version: 1.7.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.7.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: i18n
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 0.6.1
86
160
  type: :development
87
161
  prerelease: false
88
162
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
163
  requirements:
91
164
  - - '='
92
165
  - !ruby/object:Gem::Version
93
- version: 1.4.0
166
+ version: 0.6.1
94
167
  description: ! 'Some [hopefully] useful extensions to Ruby''s String class. Stringex
95
168
  is made up of three libraries: ActsAsUrl [permalink solution with better character
96
169
  translation], Unidecoder [Unicode to ASCII transliteration], and StringExtensions
@@ -102,12 +175,32 @@ extra_rdoc_files:
102
175
  - MIT-LICENSE
103
176
  - README.rdoc
104
177
  files:
178
+ - Gemfile
179
+ - Gemfile.lock
105
180
  - MIT-LICENSE
106
181
  - README.rdoc
107
182
  - Rakefile
183
+ - VERSION
108
184
  - init.rb
109
185
  - lib/stringex.rb
110
186
  - lib/stringex/acts_as_url.rb
187
+ - lib/stringex/acts_as_url/adapter.rb
188
+ - lib/stringex/acts_as_url/adapter/active_record.rb
189
+ - lib/stringex/acts_as_url/adapter/base.rb
190
+ - lib/stringex/acts_as_url/adapter/data_mapper.rb
191
+ - lib/stringex/acts_as_url/adapter/mongoid.rb
192
+ - lib/stringex/configuration.rb
193
+ - lib/stringex/configuration/acts_as_url.rb
194
+ - lib/stringex/configuration/base.rb
195
+ - lib/stringex/configuration/configurator.rb
196
+ - lib/stringex/configuration/string_extensions.rb
197
+ - lib/stringex/localization.rb
198
+ - lib/stringex/localization/backend/i18n.rb
199
+ - lib/stringex/localization/backend/internal.rb
200
+ - lib/stringex/localization/conversion_expressions.rb
201
+ - lib/stringex/localization/converter.rb
202
+ - lib/stringex/localization/default_conversions.rb
203
+ - lib/stringex/rails/railtie.rb
111
204
  - lib/stringex/string_extensions.rb
112
205
  - lib/stringex/unidecoder.rb
113
206
  - lib/stringex/unidecoder_data/x00.yml
@@ -290,12 +383,32 @@ files:
290
383
  - lib/stringex/unidecoder_data/xfd.yml
291
384
  - lib/stringex/unidecoder_data/xfe.yml
292
385
  - lib/stringex/unidecoder_data/xff.yml
386
+ - lib/stringex/version.rb
387
+ - locales/da.yml
388
+ - locales/en.yml
293
389
  - stringex.gemspec
294
- - test/acts_as_url_test.rb
390
+ - test/acts_as_url/adapter/active_record.rb
391
+ - test/acts_as_url/adapter/data_mapper.rb
392
+ - test/acts_as_url/adapter/mongoid.rb
393
+ - test/acts_as_url_configuration_test.rb
394
+ - test/acts_as_url_integration_test.rb
395
+ - test/localization/da_test.rb
396
+ - test/localization/default_test.rb
397
+ - test/localization/en_test.rb
398
+ - test/localization_test.rb
399
+ - test/redcloth_to_html_test.rb
295
400
  - test/string_extensions_test.rb
401
+ - test/test_helper.rb
402
+ - test/unicode_point_suite/basic_greek_test.rb
403
+ - test/unicode_point_suite/basic_latin_test.rb
404
+ - test/unicode_point_suite/codepoint_test_helper.rb
405
+ - test/unidecoder/bad_localization.yml
406
+ - test/unidecoder/localization.yml
296
407
  - test/unidecoder_test.rb
297
408
  homepage: http://github.com/rsl/stringex
298
- licenses: []
409
+ licenses:
410
+ - MIT
411
+ metadata: {}
299
412
  post_install_message:
300
413
  rdoc_options:
301
414
  - --main
@@ -306,24 +419,19 @@ rdoc_options:
306
419
  require_paths:
307
420
  - lib
308
421
  required_ruby_version: !ruby/object:Gem::Requirement
309
- none: false
310
422
  requirements:
311
423
  - - ! '>='
312
424
  - !ruby/object:Gem::Version
313
425
  version: '0'
314
426
  required_rubygems_version: !ruby/object:Gem::Requirement
315
- none: false
316
427
  requirements:
317
428
  - - ! '>='
318
429
  - !ruby/object:Gem::Version
319
430
  version: '0'
320
431
  requirements: []
321
432
  rubyforge_project:
322
- rubygems_version: 1.8.24
433
+ rubygems_version: 2.0.3
323
434
  signing_key:
324
- specification_version: 3
435
+ specification_version: 4
325
436
  summary: Some [hopefully] useful extensions to Ruby's String class
326
- test_files:
327
- - test/acts_as_url_test.rb
328
- - test/string_extensions_test.rb
329
- - test/unidecoder_test.rb
437
+ test_files: []
@@ -1,272 +0,0 @@
1
- # encoding: UTF-8
2
- require 'test/unit'
3
-
4
- begin
5
- require File.expand_path(File.dirname(__FILE__)) + '/../../../config/environment'
6
- rescue LoadError
7
- require 'rubygems'
8
- gem 'activerecord'
9
- require 'active_record'
10
-
11
- RAILS_ROOT = File.expand_path(File.dirname(__FILE__))
12
- $: << File.join(File.expand_path(File.dirname(__FILE__)), '../lib')
13
- end
14
-
15
- require File.join(File.expand_path(File.dirname(__FILE__)), '../init.rb')
16
-
17
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "acts_as_url.sqlite3")
18
-
19
- ActiveRecord::Migration.verbose = false
20
- ActiveRecord::Schema.define(:version => 1) do
21
- create_table :documents, :force => true do |t|
22
- t.string :title, :url, :other
23
- end
24
-
25
- create_table :updateuments, :force => true do |t|
26
- t.string :title, :url, :other
27
- end
28
-
29
- create_table :mocuments, :force => true do |t|
30
- t.string :title, :url, :other
31
- end
32
-
33
- create_table :permuments, :force => true do |t|
34
- t.string :title, :permalink, :other
35
- end
36
-
37
- create_table :procuments, :force => true do |t|
38
- t.string :title, :url, :other
39
- end
40
-
41
- create_table :blankuments, :force => true do |t|
42
- t.string :title, :url, :other
43
- end
44
-
45
- create_table :duplicateuments, :force => true do |t|
46
- t.string :title, :url, :other
47
- end
48
-
49
- create_table :validatuments, :force => true do |t|
50
- t.string :title, :url, :other
51
- end
52
-
53
- create_table :ununiquments, :force => true do |t|
54
- t.string :title, :url, :other
55
- end
56
-
57
- create_table :limituments, :force => true do |t|
58
- t.string :title, :url, :other
59
- end
60
-
61
- create_table :skipuments, :force => true do |t|
62
- t.string :title, :url, :other
63
- end
64
- end
65
- ActiveRecord::Migration.verbose = true
66
-
67
- class Document < ActiveRecord::Base
68
- acts_as_url :title
69
- end
70
-
71
- class Updateument < ActiveRecord::Base
72
- acts_as_url :title, :sync_url => true
73
- end
74
-
75
- class Mocument < ActiveRecord::Base
76
- acts_as_url :title, :scope => :other, :sync_url => true
77
- end
78
-
79
- class Permument < ActiveRecord::Base
80
- acts_as_url :title, :url_attribute => :permalink
81
- end
82
-
83
- class Procument < ActiveRecord::Base
84
- acts_as_url :non_attribute_method
85
-
86
- def non_attribute_method
87
- "#{title} got massaged"
88
- end
89
- end
90
-
91
- class Blankument < ActiveRecord::Base
92
- acts_as_url :title, :only_when_blank => true
93
- end
94
-
95
- class Duplicateument < ActiveRecord::Base
96
- acts_as_url :title, :duplicate_count_separator => "---"
97
- end
98
-
99
- class Validatument < ActiveRecord::Base
100
- acts_as_url :title, :sync_url => true
101
- validates_presence_of :title
102
- end
103
-
104
- class Ununiqument < ActiveRecord::Base
105
- acts_as_url :title, :allow_duplicates => true
106
- end
107
-
108
- class Limitument < ActiveRecord::Base
109
- acts_as_url :title, :limit => 13
110
- end
111
-
112
- class Skipument < ActiveRecord::Base
113
- acts_as_url :title, :exclude => ["_So_Fucking_Special"]
114
- end
115
-
116
- class ActsAsUrlTest < Test::Unit::TestCase
117
- def test_should_create_url
118
- @doc = Document.create(:title => "Let's Make a Test Title, <em>Okay</em>?")
119
- assert_equal "lets-make-a-test-title-okay", @doc.url
120
- end
121
-
122
- def test_should_create_unique_url
123
- @doc = Document.create!(:title => "Unique")
124
- @other_doc = Document.create!(:title => "Unique")
125
- assert_equal "unique-1", @other_doc.url
126
- end
127
-
128
- def test_should_not_create_unique_url
129
- @doc = Ununiqument.create!(:title => "I am not a clone")
130
- @other_doc = Ununiqument.create!(:title => "I am not a clone")
131
- assert_equal "i-am-not-a-clone", @other_doc.url
132
- end
133
-
134
- def test_should_not_succ_on_repeated_saves
135
- @doc = Document.new(:title => "Continuous or Constant")
136
- 5.times do
137
- @doc.save!
138
- assert_equal "continuous-or-constant", @doc.url
139
- end
140
- end
141
-
142
- def test_should_create_unique_url_and_not_clobber_if_another_exists
143
- @doc = Updateument.create!(:title => "Unique")
144
- @other_doc = Updateument.create!(:title => "Unique")
145
- @doc.update_attributes :other => "foo"
146
-
147
- @doc2 = Document.create!(:title => "twonique")
148
- @other_doc2 = Document.create!(:title => "twonique")
149
- @doc2.update_attributes(:other => "foo")
150
-
151
- assert_equal "unique", @doc.url
152
- assert_equal "foo", @doc.other
153
- assert_equal "unique-1", @other_doc.url
154
-
155
- assert_equal "twonique", @doc2.url
156
- assert_equal "foo", @doc2.other
157
- assert_equal "twonique-1", @other_doc2.url
158
- end
159
-
160
- def test_should_create_unique_url_when_partial_url_already_exists
161
- @doc = Document.create!(:title => "House Farms")
162
- @other_doc = Document.create!(:title => "House Farm")
163
-
164
- assert_equal "house-farms", @doc.url
165
- assert_equal "house-farm", @other_doc.url
166
- end
167
-
168
- def test_should_scope_uniqueness
169
- @moc = Mocument.create!(:title => "Mocumentary", :other => "I dunno why but I don't care if I'm unique")
170
- @other_moc = Mocument.create!(:title => "Mocumentary")
171
- assert_equal @moc.url, @other_moc.url
172
- end
173
-
174
- def test_should_still_create_unique_if_in_same_scope
175
- @moc = Mocument.create!(:title => "Mocumentary", :other => "Suddenly, I care if I'm unique")
176
- @other_moc = Mocument.create!(:title => "Mocumentary", :other => "Suddenly, I care if I'm unique")
177
- assert_not_equal @moc.url, @other_moc.url
178
- end
179
-
180
- def test_should_use_alternate_field_name
181
- @perm = Permument.create!(:title => "Anything at This Point")
182
- assert_equal "anything-at-this-point", @perm.permalink
183
- end
184
-
185
- def test_should_not_update_url_by_default
186
- @doc = Document.create!(:title => "Stable as Stone")
187
- @original_url = @doc.url
188
- @doc.update_attributes :title => "New Unstable Madness"
189
- assert_equal @original_url, @doc.url
190
- end
191
-
192
- def test_should_update_url_if_asked
193
- @moc = Mocument.create!(:title => "Original")
194
- @original_url = @moc.url
195
- @moc.update_attributes :title => "New and Improved"
196
- assert_not_equal @original_url, @moc.url
197
- end
198
-
199
- def test_should_update_url_only_when_blank_if_asked
200
- @original_url = 'the-url-of-concrete'
201
- @blank = Blankument.create!(:title => "Stable as Stone", :url => @original_url)
202
- assert_equal @original_url, @blank.url
203
- @blank = Blankument.create!(:title => "Stable as Stone")
204
- assert_equal 'stable-as-stone', @blank.url
205
- end
206
-
207
- def test_should_mass_initialize_urls
208
- @doc_1 = Document.create!(:title => "Initial")
209
- @doc_2 = Document.create!(:title => "Subsequent")
210
- @doc_1.update_attribute :url, nil
211
- @doc_2.update_attribute :url, nil
212
- assert_nil @doc_1.url
213
- assert_nil @doc_2.url
214
- Document.initialize_urls
215
- @doc_1.reload
216
- @doc_2.reload
217
- assert_equal "initial", @doc_1.url
218
- assert_equal "subsequent", @doc_2.url
219
- end
220
-
221
- def test_should_mass_initialize_urls_with_custom_url_attribute
222
- @doc_1 = Permument.create!(:title => "Initial")
223
- @doc_2 = Permument.create!(:title => "Subsequent")
224
- @doc_1.update_attribute :permalink, nil
225
- @doc_2.update_attribute :permalink, nil
226
- assert_nil @doc_1.permalink
227
- assert_nil @doc_2.permalink
228
- Permument.initialize_urls
229
- @doc_1.reload
230
- @doc_2.reload
231
- assert_equal "initial", @doc_1.permalink
232
- assert_equal "subsequent", @doc_2.permalink
233
- end
234
-
235
- def test_should_utilize_block_if_given
236
- @doc = Procument.create!(:title => "Title String")
237
- assert_equal "title-string-got-massaged", @doc.url
238
- end
239
-
240
- def test_should_create_unique_with_custom_duplicate_count_separator
241
- @doc = Duplicateument.create!(:title => "Unique")
242
- @other_doc = Duplicateument.create!(:title => "Unique")
243
- assert_equal "unique", @doc.url
244
- assert_equal "unique---1", @other_doc.url
245
- end
246
-
247
- def test_should_only_update_url_if_model_is_valid
248
- @doc = Validatument.create!(:title => "Initial")
249
- @doc.title = nil
250
- assert !@doc.valid?
251
- assert_equal "initial", @doc.url
252
- end
253
-
254
- def test_should_allow_url_limit
255
- @doc = Limitument.create!(:title => "I am much too long")
256
- assert_equal "i-am-much-too", @doc.url
257
- end
258
-
259
- def test_should_handle_duplicate_urls_with_limits
260
- @doc = Limitument.create!(:title => "I am long but not unique")
261
- assert_equal "i-am-long-but", @doc.url
262
- @doc_2 = Limitument.create!(:title => "I am long but not unique")
263
- assert_equal "i-am-long-but-1", @doc_2.url
264
- end
265
-
266
- def test_should_allow_exclusions
267
- @doc = Skipument.create!(:title => "_So_Fucking_Special")
268
- assert_equal "_So_Fucking_Special", @doc.url
269
- @doc_2 = Skipument.create!(:title => "But I'm a creep")
270
- assert_equal "but-im-a-creep", @doc_2.url
271
- end
272
- end