friendly_id_globalize3 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/Changelog.md +354 -0
  2. data/Contributors.md +43 -0
  3. data/Guide.md +686 -0
  4. data/MIT-LICENSE +19 -0
  5. data/README.md +99 -0
  6. data/Rakefile +75 -0
  7. data/extras/README.txt +3 -0
  8. data/extras/bench.rb +40 -0
  9. data/extras/extras.rb +38 -0
  10. data/extras/prof.rb +19 -0
  11. data/extras/template-gem.rb +26 -0
  12. data/extras/template-plugin.rb +28 -0
  13. data/generators/friendly_id/friendly_id_generator.rb +30 -0
  14. data/generators/friendly_id/templates/create_slugs.rb +18 -0
  15. data/lib/friendly_id.rb +93 -0
  16. data/lib/friendly_id/active_record.rb +74 -0
  17. data/lib/friendly_id/active_record_adapter/configuration.rb +68 -0
  18. data/lib/friendly_id/active_record_adapter/finders.rb +148 -0
  19. data/lib/friendly_id/active_record_adapter/relation.rb +165 -0
  20. data/lib/friendly_id/active_record_adapter/simple_model.rb +63 -0
  21. data/lib/friendly_id/active_record_adapter/slug.rb +77 -0
  22. data/lib/friendly_id/active_record_adapter/slugged_model.rb +122 -0
  23. data/lib/friendly_id/active_record_adapter/tasks.rb +72 -0
  24. data/lib/friendly_id/configuration.rb +178 -0
  25. data/lib/friendly_id/datamapper.rb +5 -0
  26. data/lib/friendly_id/railtie.rb +22 -0
  27. data/lib/friendly_id/sequel.rb +5 -0
  28. data/lib/friendly_id/slug_string.rb +25 -0
  29. data/lib/friendly_id/slugged.rb +105 -0
  30. data/lib/friendly_id/status.rb +35 -0
  31. data/lib/friendly_id/test.rb +350 -0
  32. data/lib/friendly_id/version.rb +9 -0
  33. data/lib/generators/friendly_id_generator.rb +25 -0
  34. data/lib/tasks/friendly_id.rake +19 -0
  35. data/rails/init.rb +2 -0
  36. data/test/active_record_adapter/ar_test_helper.rb +150 -0
  37. data/test/active_record_adapter/basic_slugged_model_test.rb +14 -0
  38. data/test/active_record_adapter/cached_slug_test.rb +76 -0
  39. data/test/active_record_adapter/core.rb +138 -0
  40. data/test/active_record_adapter/custom_normalizer_test.rb +20 -0
  41. data/test/active_record_adapter/custom_table_name_test.rb +22 -0
  42. data/test/active_record_adapter/default_scope_test.rb +30 -0
  43. data/test/active_record_adapter/optimistic_locking_test.rb +18 -0
  44. data/test/active_record_adapter/scoped_model_test.rb +119 -0
  45. data/test/active_record_adapter/simple_test.rb +76 -0
  46. data/test/active_record_adapter/slug_test.rb +34 -0
  47. data/test/active_record_adapter/slugged.rb +33 -0
  48. data/test/active_record_adapter/slugged_status_test.rb +28 -0
  49. data/test/active_record_adapter/sti_test.rb +22 -0
  50. data/test/active_record_adapter/support/database.jdbcsqlite3.yml +2 -0
  51. data/test/active_record_adapter/support/database.mysql.yml +4 -0
  52. data/test/active_record_adapter/support/database.postgres.yml +6 -0
  53. data/test/active_record_adapter/support/database.sqlite3.yml +2 -0
  54. data/test/active_record_adapter/support/models.rb +104 -0
  55. data/test/active_record_adapter/tasks_test.rb +82 -0
  56. data/test/friendly_id_test.rb +96 -0
  57. data/test/test_helper.rb +13 -0
  58. metadata +193 -0
@@ -0,0 +1,82 @@
1
+ require "friendly_id/active_record_adapter/tasks"
2
+ require File.expand_path('../ar_test_helper', __FILE__)
3
+
4
+ class TasksTest < Test::Unit::TestCase
5
+
6
+ def teardown
7
+ ENV["MODEL"] = nil
8
+ [City, District, Post, Slug].map(&:delete_all)
9
+ end
10
+
11
+ test "should make slugs" do
12
+ City.create! :name => "Nairobi"
13
+ City.create! :name => "Buenos Aires"
14
+ Slug.delete_all
15
+ ENV["MODEL"] = "City"
16
+ FriendlyId::TaskRunner.new.make_slugs
17
+ assert_equal 2, Slug.count
18
+ end
19
+
20
+ test "should admit lower case, plural model names" do
21
+ ENV["MODEL"] = "cities"
22
+ assert_equal City, FriendlyId::TaskRunner.new.klass
23
+ end
24
+
25
+ test "make_slugs should raise error if no model given" do
26
+ assert_raise(RuntimeError) { FriendlyId::TaskRunner.new.make_slugs }
27
+ end
28
+
29
+ test "make_slugs should raise error if class doesn't use FriendlyId" do
30
+ ENV["MODEL"] = "String"
31
+ assert_raise(RuntimeError) { FriendlyId::TaskRunner.new.make_slugs }
32
+ end
33
+
34
+ test"delete_slugs delete only slugs for the specified model" do
35
+ Post.create! :name => "Slugs Considered Harmful"
36
+ City.create! :name => "Buenos Aires"
37
+ ENV["MODEL"] = "city"
38
+ FriendlyId::TaskRunner.new.delete_slugs
39
+ assert_equal 1, Slug.count
40
+ end
41
+
42
+ test "delete_slugs should set the cached_slug column to NULL" do
43
+ ENV["MODEL"] = "district"
44
+ District.create! :name => "Garment"
45
+ FriendlyId::TaskRunner.new.delete_slugs
46
+ assert_nil District.first.cached_slug
47
+ end
48
+
49
+
50
+ test "delete_old_slugs should delete slugs older than 45 days by default" do
51
+ set_up_old_slugs
52
+ FriendlyId::TaskRunner.new.delete_old_slugs
53
+ assert_equal 2, Slug.count
54
+ end
55
+
56
+ test "delete_old_slugs should respect the days argument" do
57
+ set_up_old_slugs
58
+ ENV["DAYS"] = "100"
59
+ FriendlyId::TaskRunner.new.delete_old_slugs
60
+ assert_equal 3, Slug.count
61
+ end
62
+
63
+ test "delete_old_slugs should respect the class argument" do
64
+ set_up_old_slugs
65
+ ENV["MODEL"] = "post"
66
+ FriendlyId::TaskRunner.new.delete_old_slugs
67
+ assert_equal 3, Slug.count
68
+ end
69
+
70
+ private
71
+
72
+ def set_up_old_slugs
73
+ Post.create! :name => "Slugs Considered Harmful"
74
+ city = City.create! :name => "Buenos Aires"
75
+ City.connection.execute "UPDATE slugs SET created_at = '%s' WHERE id = %d" % [
76
+ 45.days.ago.strftime("%Y-%m-%d"), city.slug.id
77
+ ]
78
+ city.update_attributes :name => "Ciudad de Buenos Aires"
79
+ assert_equal 3, Slug.count
80
+ end
81
+
82
+ end
@@ -0,0 +1,96 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../test_helper', __FILE__)
3
+
4
+ module FriendlyId
5
+ module Test
6
+
7
+ class ConfigurationTest < ::Test::Unit::TestCase
8
+ test "should validate sequence separator name" do
9
+ ["-", " ", "\n", "\t"].each do |string|
10
+ assert_raise ArgumentError do
11
+ Configuration.new(NilClass, :hello, :sequence_separator => string)
12
+ end
13
+ end
14
+ end
15
+
16
+ test "should validate cached slug name" do
17
+ ["slug", "slugs", " "].each do |string|
18
+ assert_raise ArgumentError do
19
+ Configuration.new(NilClass, :hello, :cache_column => string)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ class SlugStringTest < ::Test::Unit::TestCase
26
+ test "should not transliterate by default" do
27
+ s = SlugString.new("über")
28
+ assert_equal "über", s.normalize_for!(Configuration.new(nil, :name))
29
+ end
30
+
31
+ test "should transliterate if specified" do
32
+ s = SlugString.new("über")
33
+ options = {:approximate_ascii => true}
34
+ assert_equal "uber", s.normalize_for!(Configuration.new(nil, :name, options))
35
+ end
36
+
37
+ test "should strip non-ascii if specified" do
38
+ s = SlugString.new("über")
39
+ options = {:strip_non_ascii => true}
40
+ assert_equal "ber", s.normalize_for!(Configuration.new(nil, :name, options))
41
+ end
42
+
43
+ test "should use transliterations if given" do
44
+ s = SlugString.new("über")
45
+ options = {:approximate_ascii => true, :ascii_approximation_options => :german}
46
+ assert_equal "ueber", s.normalize_for!(Configuration.new(nil, :name, options))
47
+ end
48
+ end
49
+
50
+ class FriendlyIdTest < ::Test::Unit::TestCase
51
+ test "should parse a friendly_id name and sequence" do
52
+ assert_equal ["test", 2], "test--2".parse_friendly_id
53
+ end
54
+
55
+ test "should parse a friendly_id name and a double digit sequence" do
56
+ assert_equal ["test", 12], "test--12".parse_friendly_id
57
+ end
58
+
59
+ test "should parse with a default sequence of 1" do
60
+ assert_equal ["test", 1], "test".parse_friendly_id
61
+ end
62
+
63
+ test "should be parseable with a custom separator" do
64
+ assert_equal ["test", 2], "test:2".parse_friendly_id(":")
65
+ end
66
+
67
+ test "should be parseable with a custom separator and a double digit sequence" do
68
+ assert_equal ["test", 12], "test:12".parse_friendly_id(":")
69
+ end
70
+
71
+ test "should parse when default sequence separator occurs in friendly_id name" do
72
+ assert_equal ["test--test", 2], "test--test--2".parse_friendly_id
73
+ end
74
+
75
+ test "should parse when custom sequence separator occurs in friendly_id name" do
76
+ assert_equal ["test:test", 2], "test:test:2".parse_friendly_id(":")
77
+ end
78
+
79
+ test "should parse when sequence separator and number occur in friendly_id name" do
80
+ assert_equal ["test--2--test", 1], "test--2--test".parse_friendly_id
81
+ end
82
+
83
+ test "should parse when sequence separator, number and sequence occur in friendly_id name" do
84
+ assert_equal ["test--2--test", 2], "test--2--test--2".parse_friendly_id
85
+ end
86
+
87
+ test "should parse when double digit sequence separator, number and sequence occur in friendly_id name" do
88
+ assert_equal ["test--2--test", 12], "test--2--test--12".parse_friendly_id
89
+ end
90
+
91
+ test "should parse with a separator and no sequence" do
92
+ assert_equal ["test", 1], "test--".parse_friendly_id
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,13 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ $:.unshift File.expand_path(File.dirname(__FILE__))
3
+ $:.uniq!
4
+
5
+ $KCODE = "UTF8" if RUBY_VERSION < "1.9"
6
+ $VERBOSE = false
7
+ require "rubygems"
8
+ require "bundler/setup"
9
+ require "test/unit"
10
+ require "mocha"
11
+ require "active_support"
12
+ require "friendly_id"
13
+ require "friendly_id/test"
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: friendly_id_globalize3
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 3
7
+ - 2
8
+ - 0
9
+ version: 3.2.0
10
+ platform: ruby
11
+ authors:
12
+ - Norman Clarke
13
+ - Adrian Mugnolo
14
+ - Emilio Tagua
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-01-26 00:00:00 +13:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: babosa
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ segments:
31
+ - 0
32
+ - 2
33
+ - 1
34
+ version: 0.2.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activerecord
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 3
47
+ - 0
48
+ - 0
49
+ version: 3.0.0
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: mocha
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ - 9
63
+ version: "0.9"
64
+ type: :development
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: sqlite3-ruby
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 1
76
+ version: "1"
77
+ type: :development
78
+ version_requirements: *id004
79
+ description: " FriendlyId is the \"Swiss Army bulldozer\" of slugging and permalink plugins\n for Ruby on Rails. It allows you to create pretty URL's and work with\n human-friendly strings as if they were numeric ids for ActiveRecord models.\n"
80
+ email:
81
+ - norman@njclarke.com
82
+ - adrian@mugnolo.com
83
+ - miloops@gmail.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - lib/friendly_id/active_record.rb
92
+ - lib/friendly_id/active_record_adapter/configuration.rb
93
+ - lib/friendly_id/active_record_adapter/finders.rb
94
+ - lib/friendly_id/active_record_adapter/relation.rb
95
+ - lib/friendly_id/active_record_adapter/simple_model.rb
96
+ - lib/friendly_id/active_record_adapter/slug.rb
97
+ - lib/friendly_id/active_record_adapter/slugged_model.rb
98
+ - lib/friendly_id/active_record_adapter/tasks.rb
99
+ - lib/friendly_id/configuration.rb
100
+ - lib/friendly_id/datamapper.rb
101
+ - lib/friendly_id/railtie.rb
102
+ - lib/friendly_id/sequel.rb
103
+ - lib/friendly_id/slug_string.rb
104
+ - lib/friendly_id/slugged.rb
105
+ - lib/friendly_id/status.rb
106
+ - lib/friendly_id/test.rb
107
+ - lib/friendly_id/version.rb
108
+ - lib/friendly_id.rb
109
+ - lib/generators/friendly_id_generator.rb
110
+ - lib/tasks/friendly_id.rake
111
+ - Changelog.md
112
+ - Contributors.md
113
+ - Guide.md
114
+ - README.md
115
+ - MIT-LICENSE
116
+ - Rakefile
117
+ - rails/init.rb
118
+ - generators/friendly_id/friendly_id_generator.rb
119
+ - generators/friendly_id/templates/create_slugs.rb
120
+ - test/active_record_adapter/ar_test_helper.rb
121
+ - test/active_record_adapter/basic_slugged_model_test.rb
122
+ - test/active_record_adapter/cached_slug_test.rb
123
+ - test/active_record_adapter/core.rb
124
+ - test/active_record_adapter/custom_normalizer_test.rb
125
+ - test/active_record_adapter/custom_table_name_test.rb
126
+ - test/active_record_adapter/default_scope_test.rb
127
+ - test/active_record_adapter/optimistic_locking_test.rb
128
+ - test/active_record_adapter/scoped_model_test.rb
129
+ - test/active_record_adapter/simple_test.rb
130
+ - test/active_record_adapter/slug_test.rb
131
+ - test/active_record_adapter/slugged.rb
132
+ - test/active_record_adapter/slugged_status_test.rb
133
+ - test/active_record_adapter/sti_test.rb
134
+ - test/active_record_adapter/support/database.jdbcsqlite3.yml
135
+ - test/active_record_adapter/support/database.mysql.yml
136
+ - test/active_record_adapter/support/database.postgres.yml
137
+ - test/active_record_adapter/support/database.sqlite3.yml
138
+ - test/active_record_adapter/support/models.rb
139
+ - test/active_record_adapter/tasks_test.rb
140
+ - test/friendly_id_test.rb
141
+ - test/test_helper.rb
142
+ - extras/bench.rb
143
+ - extras/extras.rb
144
+ - extras/prof.rb
145
+ - extras/README.txt
146
+ - extras/template-gem.rb
147
+ - extras/template-plugin.rb
148
+ has_rdoc: true
149
+ homepage: http://norman.github.com/friendly_id
150
+ licenses: []
151
+
152
+ post_install_message:
153
+ rdoc_options: []
154
+
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ segments:
171
+ - 0
172
+ version: "0"
173
+ requirements: []
174
+
175
+ rubyforge_project: friendly-id
176
+ rubygems_version: 1.3.7
177
+ signing_key:
178
+ specification_version: 3
179
+ summary: A comprehensive slugging and pretty-URL plugin. Fork for globalize3 support.
180
+ test_files:
181
+ - test/active_record_adapter/basic_slugged_model_test.rb
182
+ - test/active_record_adapter/cached_slug_test.rb
183
+ - test/active_record_adapter/custom_normalizer_test.rb
184
+ - test/active_record_adapter/custom_table_name_test.rb
185
+ - test/active_record_adapter/default_scope_test.rb
186
+ - test/active_record_adapter/optimistic_locking_test.rb
187
+ - test/active_record_adapter/scoped_model_test.rb
188
+ - test/active_record_adapter/simple_test.rb
189
+ - test/active_record_adapter/slug_test.rb
190
+ - test/active_record_adapter/slugged_status_test.rb
191
+ - test/active_record_adapter/sti_test.rb
192
+ - test/active_record_adapter/tasks_test.rb
193
+ - test/friendly_id_test.rb