friendly_id 5.5.1 → 5.7.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +4 -1
  3. data/README.md +3 -3
  4. data/lib/friendly_id/history.rb +2 -2
  5. data/lib/friendly_id/slug_generator.rb +15 -0
  6. data/lib/friendly_id/slugged.rb +19 -1
  7. data/lib/friendly_id/version.rb +1 -1
  8. metadata +5 -76
  9. checksums.yaml.gz.sig +0 -0
  10. data/.gemtest +0 -0
  11. data/.github/FUNDING.yml +0 -1
  12. data/.github/dependabot.yml +0 -6
  13. data/.github/stale.yml +0 -17
  14. data/.github/workflows/test.yml +0 -62
  15. data/.gitignore +0 -14
  16. data/.yardopts +0 -8
  17. data/CONTRIBUTING.md +0 -11
  18. data/Gemfile +0 -23
  19. data/Rakefile +0 -104
  20. data/UPGRADING.md +0 -115
  21. data/bench.rb +0 -84
  22. data/certs/parndt.pem +0 -27
  23. data/friendly_id.gemspec +0 -36
  24. data/gemfiles/Gemfile.rails-5.2.rb +0 -22
  25. data/gemfiles/Gemfile.rails-6.0.rb +0 -22
  26. data/gemfiles/Gemfile.rails-6.1.rb +0 -22
  27. data/gemfiles/Gemfile.rails-7.0.rb +0 -22
  28. data/guide.rb +0 -24
  29. data/test/base_test.rb +0 -69
  30. data/test/benchmarks/finders.rb +0 -90
  31. data/test/benchmarks/object_utils.rb +0 -56
  32. data/test/candidates_test.rb +0 -142
  33. data/test/configuration_test.rb +0 -60
  34. data/test/core_test.rb +0 -35
  35. data/test/databases.yml +0 -22
  36. data/test/finders_test.rb +0 -76
  37. data/test/generator_test.rb +0 -38
  38. data/test/helper.rb +0 -125
  39. data/test/history_test.rb +0 -434
  40. data/test/numeric_slug_test.rb +0 -31
  41. data/test/object_utils_test.rb +0 -27
  42. data/test/reserved_test.rb +0 -73
  43. data/test/schema.rb +0 -117
  44. data/test/scoped_test.rb +0 -95
  45. data/test/sequentially_slugged_test.rb +0 -214
  46. data/test/shared.rb +0 -181
  47. data/test/simple_i18n_test.rb +0 -144
  48. data/test/slugged_test.rb +0 -628
  49. data/test/sti_test.rb +0 -135
  50. data.tar.gz.sig +0 -0
  51. metadata.gz.sig +0 -0
data/test/core_test.rb DELETED
@@ -1,35 +0,0 @@
1
- require "helper"
2
-
3
- class Book < ActiveRecord::Base
4
- extend FriendlyId
5
- friendly_id :name
6
- end
7
-
8
- class Author < ActiveRecord::Base
9
- extend FriendlyId
10
- friendly_id :name
11
- has_many :books
12
- end
13
-
14
- class CoreTest < TestCaseClass
15
- include FriendlyId::Test
16
- include FriendlyId::Test::Shared::Core
17
-
18
- def model_class
19
- Author
20
- end
21
-
22
- test "models don't use friendly_id by default" do
23
- assert !Class.new(ActiveRecord::Base) {
24
- self.abstract_class = true
25
- }.respond_to?(:friendly_id)
26
- end
27
-
28
- test "model classes should have a friendly id config" do
29
- assert model_class.friendly_id(:name).friendly_id_config
30
- end
31
-
32
- test "instances should have a friendly id" do
33
- with_instance_of(model_class) { |record| assert record.friendly_id }
34
- end
35
- end
data/test/databases.yml DELETED
@@ -1,22 +0,0 @@
1
- mysql:
2
- adapter: mysql2
3
- database: friendly_id_test
4
- username: root
5
- password: <%= ENV['MYSQL_PASSWORD'] %>
6
- host: 127.0.0.1
7
- port: 3306
8
- encoding: utf8
9
-
10
- postgres:
11
- adapter: postgresql
12
- host: <%= ENV.fetch('PGHOST', 'localhost') %>
13
- port: <%= ENV.fetch('PGPORT', '5432') %>
14
- username: <%= ENV.fetch('PGUSER', 'postgres') %>
15
- password: <%= ENV.fetch('PGPASSWORD', 'postgres') %>
16
- database: friendly_id_test
17
- encoding: utf8
18
-
19
- sqlite3:
20
- adapter: sqlite3
21
- database: ":memory:"
22
- encoding: utf8
data/test/finders_test.rb DELETED
@@ -1,76 +0,0 @@
1
- require "helper"
2
-
3
- class JournalistWithFriendlyFinders < ActiveRecord::Base
4
- self.table_name = "journalists"
5
- extend FriendlyId
6
- scope :existing, -> { where("1 = 1") }
7
- friendly_id :name, use: [:slugged, :finders]
8
- end
9
-
10
- class Finders < TestCaseClass
11
- include FriendlyId::Test
12
-
13
- def model_class
14
- JournalistWithFriendlyFinders
15
- end
16
-
17
- test "should find records with finders as class methods" do
18
- with_instance_of(model_class) do |record|
19
- assert model_class.find(record.friendly_id)
20
- end
21
- end
22
-
23
- test "should find records with finders on relations" do
24
- with_instance_of(model_class) do |record|
25
- assert model_class.existing.find(record.friendly_id)
26
- end
27
- end
28
-
29
- test "allows nil with allow_nil: true" do
30
- with_instance_of(model_class) do |record|
31
- assert_nil model_class.find("foo", allow_nil: true)
32
- end
33
- end
34
-
35
- test "allows nil on relations with allow_nil: true" do
36
- with_instance_of(model_class) do |record|
37
- assert_nil model_class.existing.find("foo", allow_nil: true)
38
- end
39
- end
40
-
41
- test "allows nil with a bad primary key ID and allow_nil: true" do
42
- with_instance_of(model_class) do |record|
43
- assert_nil model_class.find(0, allow_nil: true)
44
- end
45
- end
46
-
47
- test "allows nil on relations with a bad primary key ID and allow_nil: true" do
48
- with_instance_of(model_class) do |record|
49
- assert_nil model_class.existing.find(0, allow_nil: true)
50
- end
51
- end
52
-
53
- test "allows nil with a bad potential primary key ID and allow_nil: true" do
54
- with_instance_of(model_class) do |record|
55
- assert_nil model_class.find("0", allow_nil: true)
56
- end
57
- end
58
-
59
- test "allows nil on relations with a bad potential primary key ID and allow_nil: true" do
60
- with_instance_of(model_class) do |record|
61
- assert_nil model_class.existing.find("0", allow_nil: true)
62
- end
63
- end
64
-
65
- test "allows nil with nil ID and allow_nil: true" do
66
- with_instance_of(model_class) do |record|
67
- assert_nil model_class.find(nil, allow_nil: true)
68
- end
69
- end
70
-
71
- test "allows nil on relations with nil ID and allow_nil: true" do
72
- with_instance_of(model_class) do |record|
73
- assert_nil model_class.existing.find(nil, allow_nil: true)
74
- end
75
- end
76
- end
@@ -1,38 +0,0 @@
1
- require "helper"
2
- require "rails/generators"
3
- require "generators/friendly_id_generator"
4
-
5
- class FriendlyIdGeneratorTest < Rails::Generators::TestCase
6
- tests FriendlyIdGenerator
7
- destination File.expand_path("../../tmp", __FILE__)
8
-
9
- setup :prepare_destination
10
-
11
- test "should generate a migration" do
12
- run_generator
13
- assert_migration "db/migrate/create_friendly_id_slugs"
14
- ensure
15
- FileUtils.rm_rf destination_root
16
- end
17
-
18
- test "should skip the migration when told to do so" do
19
- run_generator ["--skip-migration"]
20
- assert_no_migration "db/migrate/create_friendly_id_slugs"
21
- ensure
22
- FileUtils.rm_rf destination_root
23
- end
24
-
25
- test "should generate an initializer" do
26
- run_generator
27
- assert_file "config/initializers/friendly_id.rb"
28
- ensure
29
- FileUtils.rm_rf destination_root
30
- end
31
-
32
- test "should skip the initializer when told to do so" do
33
- run_generator ["--skip-initializer"]
34
- assert_no_file "config/initializers/friendly_id.rb"
35
- ensure
36
- FileUtils.rm_rf destination_root
37
- end
38
- end
data/test/helper.rb DELETED
@@ -1,125 +0,0 @@
1
- require "bundler/setup"
2
-
3
- if ENV["COVERALLS"] || ENV["COVERAGE"]
4
- require "simplecov"
5
- if ENV["COVERALLS"]
6
- require "coveralls"
7
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
8
- end
9
- SimpleCov.start do
10
- add_filter "test"
11
- add_filter "friendly_id/migration"
12
- end
13
- end
14
-
15
- begin
16
- require "minitest"
17
- rescue LoadError
18
- require "minitest/unit"
19
- end
20
-
21
- begin
22
- TestCaseClass = Minitest::Test
23
- rescue NameError
24
- TestCaseClass = Minitest::Unit::TestCase
25
- end
26
-
27
- require "mocha/minitest"
28
- require "active_record"
29
- require "active_support/core_ext/time/conversions"
30
- require "erb"
31
-
32
- I18n.enforce_available_locales = false
33
-
34
- require "friendly_id"
35
-
36
- # If you want to see the ActiveRecord log, invoke the tests using `rake test LOG=true`
37
- if ENV["LOG"]
38
- require "logger"
39
- ActiveRecord::Base.logger = Logger.new($stdout)
40
- end
41
-
42
- if ActiveSupport::VERSION::STRING >= "4.2"
43
- ActiveSupport.test_order = :random
44
- end
45
-
46
- module FriendlyId
47
- module Test
48
- def self.included(base)
49
- if Minitest.respond_to?(:autorun)
50
- Minitest.autorun
51
- else
52
- require "minitest/autorun"
53
- end
54
- rescue LoadError
55
- end
56
-
57
- def transaction
58
- ActiveRecord::Base.transaction do
59
- yield
60
-
61
- raise ActiveRecord::Rollback
62
- end
63
- end
64
-
65
- def with_instance_of(*args)
66
- model_class = args.shift
67
- args[0] ||= {name: "a b c"}
68
- transaction { yield model_class.create!(*args) }
69
- end
70
-
71
- module Database
72
- extend self
73
-
74
- def connect
75
- version = ActiveRecord::VERSION::STRING
76
- engine = begin
77
- RUBY_ENGINE
78
- rescue
79
- "ruby"
80
- end
81
-
82
- ActiveRecord::Base.establish_connection config[driver]
83
- message = "Using #{engine} #{RUBY_VERSION} AR #{version} with #{driver}"
84
-
85
- puts "-" * 72
86
- if in_memory?
87
- ActiveRecord::Migration.verbose = false
88
- Schema.migrate :up
89
- puts "#{message} (in-memory)"
90
- else
91
- puts message
92
- end
93
- end
94
-
95
- def config
96
- @config ||= YAML.safe_load(
97
- ERB.new(
98
- File.read(File.expand_path("../databases.yml", __FILE__))
99
- ).result
100
- )
101
- end
102
-
103
- def driver
104
- db_driver = ENV.fetch("DB", "sqlite3").downcase
105
- db_driver = "postgres" if %w[postgresql pg].include?(db_driver)
106
- db_driver
107
- end
108
-
109
- def in_memory?
110
- config[driver]["database"] == ":memory:"
111
- end
112
- end
113
- end
114
- end
115
-
116
- class Module
117
- def test(name, &block)
118
- define_method("test_#{name.gsub(/[^a-z0-9']/i, "_")}".to_sym, &block)
119
- end
120
- end
121
-
122
- require "schema"
123
- require "shared"
124
- FriendlyId::Test::Database.connect
125
- at_exit { ActiveRecord::Base.connection.disconnect! }