friendly_id 2.3.4 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Changelog.md +10 -0
  2. data/Contributors.md +1 -0
  3. data/Guide.md +48 -4
  4. data/README.md +6 -4
  5. data/Rakefile +1 -1
  6. data/extras/extras.rb +1 -1
  7. data/generators/friendly_id/friendly_id_generator.rb +1 -1
  8. data/lib/friendly_id.rb +4 -6
  9. data/lib/friendly_id/{active_record2 → acktive_record}/configuration.rb +2 -2
  10. data/lib/friendly_id/{active_record2 → acktive_record}/finders.rb +24 -10
  11. data/lib/friendly_id/{active_record2 → acktive_record}/simple_model.rb +12 -50
  12. data/lib/friendly_id/acktive_record/slug.rb +66 -0
  13. data/lib/friendly_id/{active_record2 → acktive_record}/slugged_model.rb +9 -85
  14. data/lib/friendly_id/{active_record2 → acktive_record}/tasks.rb +5 -2
  15. data/lib/friendly_id/{active_record2 → acktive_record}/tasks/friendly_id.rake +1 -1
  16. data/lib/friendly_id/{active_record2.rb → active_record.rb} +18 -13
  17. data/lib/friendly_id/configuration.rb +11 -26
  18. data/lib/friendly_id/finders.rb +5 -3
  19. data/lib/friendly_id/slug_string.rb +11 -10
  20. data/lib/friendly_id/slugged.rb +11 -4
  21. data/lib/friendly_id/test.rb +46 -5
  22. data/lib/friendly_id/version.rb +5 -4
  23. data/lib/generators/friendly_id_generator.rb +32 -0
  24. data/rails/init.rb +1 -1
  25. data/test/{active_record2 → acktive_record}/basic_slugged_model_test.rb +3 -3
  26. data/test/{active_record2 → acktive_record}/cached_slug_test.rb +3 -3
  27. data/test/{active_record2 → acktive_record}/core.rb +1 -1
  28. data/test/{active_record2 → acktive_record}/custom_normalizer_test.rb +3 -3
  29. data/test/{active_record2 → acktive_record}/custom_table_name_test.rb +3 -3
  30. data/test/{active_record2 → acktive_record}/scoped_model_test.rb +2 -2
  31. data/test/{active_record2 → acktive_record}/simple_test.rb +4 -1
  32. data/test/{active_record2 → acktive_record}/slug_test.rb +0 -0
  33. data/test/{active_record2 → acktive_record}/slugged.rb +1 -1
  34. data/test/{active_record2 → acktive_record}/slugged_status_test.rb +1 -1
  35. data/test/{active_record2 → acktive_record}/sti_test.rb +3 -3
  36. data/test/{active_record2 → acktive_record}/support/database.mysql.yml +0 -0
  37. data/test/{active_record2 → acktive_record}/support/database.postgres.yml +0 -0
  38. data/test/{active_record2 → acktive_record}/support/database.sqlite3.yml +0 -0
  39. data/test/{active_record2 → acktive_record}/support/models.rb +5 -6
  40. data/test/{active_record2 → acktive_record}/tasks_test.rb +1 -1
  41. data/test/acktive_record/temp_test.rb +32 -0
  42. data/test/{active_record2 → acktive_record}/test_helper.rb +4 -10
  43. data/test/slug_string_test.rb +5 -1
  44. data/test/test_helper.rb +9 -3
  45. metadata +48 -44
  46. data/lib/friendly_id/active_record2/slug.rb +0 -111
  47. data/test/active_record2/deprecated_test.rb +0 -23
@@ -1,8 +1,9 @@
1
1
  module FriendlyId
2
2
  module Version
3
- MAJOR = 2
4
- MINOR = 3
5
- TINY = 4
6
- STRING = [MAJOR, MINOR, TINY].join('.')
3
+ MAJOR = 3
4
+ MINOR = 0
5
+ TINY = 0
6
+ BUILD = "beta1"
7
+ STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
7
8
  end
8
9
  end
@@ -0,0 +1,32 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class FriendlyIdGenerator < Rails::Generators::Base
5
+
6
+ include Rails::Generators::Migration
7
+
8
+ RAKE_FILE = File.join(File.dirname(__FILE__), "..", "friendly_id", "acktive_record", "tasks", "friendly_id.rake")
9
+ MIGRATIONS_FILE = File.join(File.dirname(__FILE__), "..", "..", "generators", "friendly_id", "templates", "create_slugs.rb")
10
+
11
+ class_option :"skip-migration", :type => :boolean, :desc => "Don't generate a migration for the slugs table"
12
+ class_option :"skip-tasks", :type => :boolean, :desc => "Don't add friendly_id Rake tasks to lib/tasks"
13
+ class_option :"skip-initializer", :type => :boolean, :desc => "Don't add friendly_id initializer to config/initializers"
14
+
15
+ def copy_files(*args)
16
+ migration_template MIGRATIONS_FILE, "db/migrate/create_slugs.rb" unless options["skip-migration"]
17
+ rakefile "friendly_id.rake", File.read(RAKE_FILE) unless options["skip-tasks"]
18
+ initializer "friendly_id.rb" do
19
+ 'require "friendly_id/active_record"'
20
+ end unless options["skip-initializer"]
21
+ end
22
+
23
+ # Taken from ActiveRecord's migration generator
24
+ def self.next_migration_number(dirname) #:nodoc:
25
+ if ActiveRecord::Base.timestamped_migrations
26
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
27
+ else
28
+ "%.3d" % (current_migration_number(dirname) + 1)
29
+ end
30
+ end
31
+
32
+ end
data/rails/init.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require "friendly_id"
2
- require "friendly_id/active_record2"
2
+ require "friendly_id/active_record"
@@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  module FriendlyId
4
4
  module Test
5
- module ActiveRecord2
5
+ module AcktiveRecord
6
6
  class BasicSluggedModelTest < ::Test::Unit::TestCase
7
7
  include FriendlyId::Test::Generic
8
8
  include FriendlyId::Test::Slugged
9
- include FriendlyId::Test::ActiveRecord2::Slugged
10
- include FriendlyId::Test::ActiveRecord2::Core
9
+ include FriendlyId::Test::AcktiveRecord::Slugged
10
+ include FriendlyId::Test::AcktiveRecord::Core
11
11
  end
12
12
  end
13
13
  end
@@ -2,14 +2,14 @@ require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  module FriendlyId
4
4
  module Test
5
- module ActiveRecord2
5
+ module AcktiveRecord
6
6
 
7
7
  class CachedSlugTest < ::Test::Unit::TestCase
8
8
 
9
9
  include FriendlyId::Test::Generic
10
10
  include FriendlyId::Test::Slugged
11
- include FriendlyId::Test::ActiveRecord2::Slugged
12
- include FriendlyId::Test::ActiveRecord2::Core
11
+ include FriendlyId::Test::AcktiveRecord::Slugged
12
+ include FriendlyId::Test::AcktiveRecord::Core
13
13
 
14
14
  def klass
15
15
  District
@@ -4,7 +4,7 @@ module FriendlyId
4
4
 
5
5
  module Test
6
6
 
7
- module ActiveRecord2
7
+ module AcktiveRecord
8
8
 
9
9
  module Core
10
10
 
@@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  module FriendlyId
4
4
  module Test
5
- module ActiveRecord2
5
+ module AcktiveRecord
6
6
 
7
7
  class CustomNormalizerTest < ::Test::Unit::TestCase
8
8
 
9
- include FriendlyId::Test::ActiveRecord2::Core
10
- include FriendlyId::Test::ActiveRecord2::Slugged
9
+ include FriendlyId::Test::AcktiveRecord::Core
10
+ include FriendlyId::Test::AcktiveRecord::Slugged
11
11
  include FriendlyId::Test::CustomNormalizer
12
12
 
13
13
  def klass
@@ -2,14 +2,14 @@ require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  module FriendlyId
4
4
  module Test
5
- module ActiveRecord2
5
+ module AcktiveRecord
6
6
 
7
7
  class CustomTableNameTest < ::Test::Unit::TestCase
8
8
 
9
9
  include FriendlyId::Test::Generic
10
10
  include FriendlyId::Test::Slugged
11
- include FriendlyId::Test::ActiveRecord2::Slugged
12
- include FriendlyId::Test::ActiveRecord2::Core
11
+ include FriendlyId::Test::AcktiveRecord::Slugged
12
+ include FriendlyId::Test::AcktiveRecord::Core
13
13
 
14
14
  def klass
15
15
  Place
@@ -7,8 +7,8 @@ module FriendlyId
7
7
 
8
8
  include FriendlyId::Test::Generic
9
9
  include FriendlyId::Test::Slugged
10
- include FriendlyId::Test::ActiveRecord2::Slugged
11
- include FriendlyId::Test::ActiveRecord2::Core
10
+ include FriendlyId::Test::AcktiveRecord::Slugged
11
+ include FriendlyId::Test::AcktiveRecord::Core
12
12
 
13
13
  def setup
14
14
  @user = User.create!(:name => "john")
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  module FriendlyId
4
4
  module Test
5
- module ActiveRecord2
5
+ module AcktiveRecord
6
6
  module Simple
7
7
 
8
8
  module SimpleTest
@@ -21,6 +21,9 @@ module FriendlyId
21
21
 
22
22
  class StatusTest < ::Test::Unit::TestCase
23
23
 
24
+ include FriendlyId::Test::Generic
25
+ include FriendlyId::Test::Simple
26
+ include FriendlyId::Test::AcktiveRecord::Core
24
27
  include SimpleTest
25
28
 
26
29
  test "should default to not friendly" do
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  module FriendlyId
4
4
  module Test
5
- module ActiveRecord2
5
+ module AcktiveRecord
6
6
  module Slugged
7
7
 
8
8
  test "should allow eager loading of slugs" do
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/test_helper'
3
3
 
4
4
  module FriendlyId
5
5
  module Test
6
- module ActiveRecord2
6
+ module AcktiveRecord
7
7
 
8
8
  class StatusTest < ::Test::Unit::TestCase
9
9
 
@@ -2,14 +2,14 @@ require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  module FriendlyId
4
4
  module Test
5
- module ActiveRecord2
5
+ module AcktiveRecord
6
6
 
7
7
  class StiTest < ::Test::Unit::TestCase
8
8
 
9
9
  include FriendlyId::Test::Generic
10
10
  include FriendlyId::Test::Slugged
11
- include FriendlyId::Test::ActiveRecord2::Slugged
12
- include FriendlyId::Test::ActiveRecord2::Core
11
+ include FriendlyId::Test::AcktiveRecord::Slugged
12
+ include FriendlyId::Test::AcktiveRecord::Core
13
13
 
14
14
  def klass
15
15
  Novel
@@ -5,6 +5,11 @@ class CreateSupportModels < ActiveRecord::Migration
5
5
  t.string :name
6
6
  end
7
7
 
8
+ create_table :blocks do |t|
9
+ t.string :name
10
+ t.string :note
11
+ end
12
+
8
13
  create_table :books do |t|
9
14
  t.string :name
10
15
  t.string :type
@@ -65,14 +70,8 @@ class CreateSupportModels < ActiveRecord::Migration
65
70
  t.index :name, :unique => true
66
71
  end
67
72
 
68
- create_table :blocks do |t|
69
- t.string :name
70
- t.string :note
71
- end
72
-
73
73
  end
74
74
 
75
75
  def self.down
76
76
  end
77
77
  end
78
-
@@ -1,5 +1,5 @@
1
1
  require(File.dirname(__FILE__) + '/test_helper')
2
- require File.dirname(__FILE__) + '/../../lib/friendly_id/active_record2/tasks'
2
+ require File.dirname(__FILE__) + '/../../lib/friendly_id/acktive_record/tasks'
3
3
 
4
4
  class TasksTest < Test::Unit::TestCase
5
5
 
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+
4
+ # scope :hello, :conditions => {"books.name" => "hello world"}
5
+ # scope :friendly, lambda { |name| {:conditions => {"slugs.name" => name }, :include => :slugs}}
6
+ #
7
+ # def self.find(*args, &block)
8
+ # if FriendlyId::Finders::Base.friendly?(args.first)
9
+ # puts "doing friendly find with #{args.first}"
10
+ # self.friendly(args.shift).first(*args)
11
+ # else
12
+ # super
13
+ # end
14
+ # end
15
+ #
16
+ # end
17
+
18
+ module FriendlyId
19
+ module Test
20
+ module AcktiveRecord
21
+
22
+ class StiTest < ::Test::Unit::TestCase
23
+
24
+ # def test_temp
25
+ # instance = Post.create(:name => "hello world")
26
+ # p instance.class.find(instance.friendly_id)
27
+ # end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -2,7 +2,8 @@ require File.dirname(__FILE__) + "/../test_helper"
2
2
 
3
3
  require "active_record"
4
4
  require "active_support"
5
- require File.dirname(__FILE__) + "/../../lib/friendly_id/active_record2.rb"
5
+
6
+ require File.dirname(__FILE__) + "/../../lib/friendly_id/active_record.rb"
6
7
  require File.dirname(__FILE__) + "/../../generators/friendly_id/templates/create_slugs"
7
8
  require File.dirname(__FILE__) + "/support/models"
8
9
  require File.dirname(__FILE__) + '/core'
@@ -79,7 +80,7 @@ end
79
80
  # A model that uses default slug settings and has a named scope
80
81
  class Post < ActiveRecord::Base
81
82
  has_friendly_id :name, :use_slug => true
82
- named_scope :published, :conditions => { :published => true }
83
+ send FriendlyId::AcktiveRecord::Compat.scope_method, :published, :conditions => { :published => true }
83
84
  end
84
85
 
85
86
  # Model that uses a custom table name
@@ -104,11 +105,4 @@ end
104
105
  # A model with no table
105
106
  class Question < ActiveRecord::Base
106
107
  has_friendly_id :name, :use_slug => true
107
- end
108
-
109
- # A model using the deprecated block syntax
110
- class Block < ActiveRecord::Base
111
- has_friendly_id :name, :use_slug => true do |text|
112
- FriendlyId::SlugString.new(text).clean.with_dashes
113
- end
114
- end
108
+ end
@@ -73,6 +73,10 @@ module FriendlyId
73
73
  assert_equal "検-索", SlugString.new("検 索").with_dashes
74
74
  end
75
75
 
76
+ test "to_ascii should work with invalid UTF-8 strings" do
77
+ assert_equal "abc", SlugString.new("\x93abc").to_ascii.to_s
78
+ end
79
+
76
80
  end
77
81
  end
78
- end
82
+ end
data/test/test_helper.rb CHANGED
@@ -1,9 +1,15 @@
1
1
  $KCODE = "UTF8" if RUBY_VERSION < "1.9"
2
2
  $VERBOSE = false
3
-
4
- require "rubygems"
3
+ begin
4
+ require File.join(File.dirname(__FILE__), '../.bundle/environment')
5
+ rescue LoadError
6
+ # Fall back on doing an unlocked resolve at runtime.
7
+ require "rubygems"
8
+ require "bundler"
9
+ Bundler.setup
10
+ end
5
11
  require "test/unit"
6
12
  require "mocha"
7
13
  require "active_support"
8
14
  require File.dirname(__FILE__) + "/../lib/friendly_id"
9
- require File.dirname(__FILE__) + "/../lib/friendly_id/test"
15
+ require File.dirname(__FILE__) + "/../lib/friendly_id/test"
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_id
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
- - 2
7
6
  - 3
8
- - 4
9
- version: 2.3.4
7
+ - 0
8
+ - 0
9
+ - beta1
10
+ version: 3.0.0.beta1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Norman Clarke
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-03-22 00:00:00 -03:00
20
+ date: 2010-03-26 00:00:00 -03:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -57,13 +58,13 @@ extensions: []
57
58
  extra_rdoc_files: []
58
59
 
59
60
  files:
60
- - lib/friendly_id/active_record2/configuration.rb
61
- - lib/friendly_id/active_record2/finders.rb
62
- - lib/friendly_id/active_record2/simple_model.rb
63
- - lib/friendly_id/active_record2/slug.rb
64
- - lib/friendly_id/active_record2/slugged_model.rb
65
- - lib/friendly_id/active_record2/tasks.rb
66
- - lib/friendly_id/active_record2.rb
61
+ - lib/friendly_id/acktive_record/configuration.rb
62
+ - lib/friendly_id/acktive_record/finders.rb
63
+ - lib/friendly_id/acktive_record/simple_model.rb
64
+ - lib/friendly_id/acktive_record/slug.rb
65
+ - lib/friendly_id/acktive_record/slugged_model.rb
66
+ - lib/friendly_id/acktive_record/tasks.rb
67
+ - lib/friendly_id/active_record.rb
67
68
  - lib/friendly_id/configuration.rb
68
69
  - lib/friendly_id/finders.rb
69
70
  - lib/friendly_id/slug_string.rb
@@ -72,7 +73,8 @@ files:
72
73
  - lib/friendly_id/test.rb
73
74
  - lib/friendly_id/version.rb
74
75
  - lib/friendly_id.rb
75
- - lib/friendly_id/active_record2/tasks/friendly_id.rake
76
+ - lib/generators/friendly_id_generator.rb
77
+ - lib/friendly_id/acktive_record/tasks/friendly_id.rake
76
78
  - Changelog.md
77
79
  - Contributors.md
78
80
  - Guide.md
@@ -82,24 +84,24 @@ files:
82
84
  - rails/init.rb
83
85
  - generators/friendly_id/friendly_id_generator.rb
84
86
  - generators/friendly_id/templates/create_slugs.rb
85
- - test/active_record2/basic_slugged_model_test.rb
86
- - test/active_record2/cached_slug_test.rb
87
- - test/active_record2/core.rb
88
- - test/active_record2/custom_normalizer_test.rb
89
- - test/active_record2/custom_table_name_test.rb
90
- - test/active_record2/deprecated_test.rb
91
- - test/active_record2/scoped_model_test.rb
92
- - test/active_record2/simple_test.rb
93
- - test/active_record2/slug_test.rb
94
- - test/active_record2/slugged.rb
95
- - test/active_record2/slugged_status_test.rb
96
- - test/active_record2/sti_test.rb
97
- - test/active_record2/support/database.mysql.yml
98
- - test/active_record2/support/database.postgres.yml
99
- - test/active_record2/support/database.sqlite3.yml
100
- - test/active_record2/support/models.rb
101
- - test/active_record2/tasks_test.rb
102
- - test/active_record2/test_helper.rb
87
+ - test/acktive_record/basic_slugged_model_test.rb
88
+ - test/acktive_record/cached_slug_test.rb
89
+ - test/acktive_record/core.rb
90
+ - test/acktive_record/custom_normalizer_test.rb
91
+ - test/acktive_record/custom_table_name_test.rb
92
+ - test/acktive_record/scoped_model_test.rb
93
+ - test/acktive_record/simple_test.rb
94
+ - test/acktive_record/slug_test.rb
95
+ - test/acktive_record/slugged.rb
96
+ - test/acktive_record/slugged_status_test.rb
97
+ - test/acktive_record/sti_test.rb
98
+ - test/acktive_record/support/database.mysql.yml
99
+ - test/acktive_record/support/database.postgres.yml
100
+ - test/acktive_record/support/database.sqlite3.yml
101
+ - test/acktive_record/support/models.rb
102
+ - test/acktive_record/tasks_test.rb
103
+ - test/acktive_record/temp_test.rb
104
+ - test/acktive_record/test_helper.rb
103
105
  - test/friendly_id_test.rb
104
106
  - test/slug_string_test.rb
105
107
  - test/test_helper.rb
@@ -142,8 +144,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
144
  - - ">="
143
145
  - !ruby/object:Gem::Version
144
146
  segments:
145
- - 0
146
- version: "0"
147
+ - 1
148
+ - 3
149
+ - 6
150
+ version: 1.3.6
147
151
  requirements: []
148
152
 
149
153
  rubyforge_project: friendly-id
@@ -152,16 +156,16 @@ signing_key:
152
156
  specification_version: 3
153
157
  summary: A comprehensive slugging and pretty-URL plugin.
154
158
  test_files:
155
- - test/active_record2/basic_slugged_model_test.rb
156
- - test/active_record2/cached_slug_test.rb
157
- - test/active_record2/custom_normalizer_test.rb
158
- - test/active_record2/custom_table_name_test.rb
159
- - test/active_record2/deprecated_test.rb
160
- - test/active_record2/scoped_model_test.rb
161
- - test/active_record2/simple_test.rb
162
- - test/active_record2/slug_test.rb
163
- - test/active_record2/slugged_status_test.rb
164
- - test/active_record2/sti_test.rb
165
- - test/active_record2/tasks_test.rb
159
+ - test/acktive_record/basic_slugged_model_test.rb
160
+ - test/acktive_record/cached_slug_test.rb
161
+ - test/acktive_record/custom_normalizer_test.rb
162
+ - test/acktive_record/custom_table_name_test.rb
163
+ - test/acktive_record/scoped_model_test.rb
164
+ - test/acktive_record/simple_test.rb
165
+ - test/acktive_record/slug_test.rb
166
+ - test/acktive_record/slugged_status_test.rb
167
+ - test/acktive_record/sti_test.rb
168
+ - test/acktive_record/tasks_test.rb
169
+ - test/acktive_record/temp_test.rb
166
170
  - test/friendly_id_test.rb
167
171
  - test/slug_string_test.rb