sluggi 0.3.0 → 0.3.1
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 +4 -4
- data/lib/sluggi/generators/sluggi_generator.rb +5 -6
- data/lib/sluggi/history.rb +4 -5
- data/lib/sluggi/migrations/create_slugs.rb +4 -4
- data/lib/sluggi/model.rb +1 -1
- data/lib/sluggi/version.rb +1 -1
- metadata +5 -27
- data/.gitignore +0 -5
- data/.travis.yml +0 -8
- data/Gemfile +0 -3
- data/Rakefile +0 -10
- data/sluggi.gemspec +0 -25
- data/test/generator_test.rb +0 -17
- data/test/history_test.rb +0 -123
- data/test/model_test.rb +0 -73
- data/test/slug_test.rb +0 -35
- data/test/slugged_test.rb +0 -31
- data/test/test_helper.rb +0 -48
- data/test/validate_presence_test.rb +0 -12
- data/test/validate_uniqueness_test.rb +0 -32
- data/test/validates_exclusion_of_test.rb +0 -25
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72a92d30f09969e63089958da3e197a5ffa57146
|
|
4
|
+
data.tar.gz: f95fc4c7371e7c2f6ae64524e01a0372fc584163
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe12fe4a76145b87e21e9a093524213fa8666dc8c7e2a06e53900431c58ee34508876e90f7205dd374f443d7097dbb117ae93bf12a36e067cc3d806eb0b877ae
|
|
7
|
+
data.tar.gz: 090fb62d93291fa03f7b41ee6b76c9da9ad7d23ce48d946095aa1cfed185bd00e83920aa9bd28220e002994967245c3ee4ad6e872d601e13a8c703cfd9eea043
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require "rails/generators"
|
|
2
|
+
require "rails/generators/active_record"
|
|
3
3
|
|
|
4
4
|
# Copy the migration to create the slugs table.
|
|
5
5
|
class SluggiGenerator < ActiveRecord::Generators::Base
|
|
6
|
-
argument :name, type: :string, default:
|
|
7
|
-
source_root File.expand_path(
|
|
6
|
+
argument :name, type: :string, default: "required_but_not_used"
|
|
7
|
+
source_root File.expand_path("../../migrations", __FILE__)
|
|
8
8
|
|
|
9
9
|
# Copy the migration template to db/migrate.
|
|
10
10
|
def copy_files
|
|
11
|
-
migration_template
|
|
11
|
+
migration_template "create_slugs.rb", "db/migrate/create_slugs.rb"
|
|
12
12
|
end
|
|
13
|
-
|
|
14
13
|
end
|
data/lib/sluggi/history.rb
CHANGED
|
@@ -4,8 +4,8 @@ module Sluggi
|
|
|
4
4
|
|
|
5
5
|
included do
|
|
6
6
|
has_many :slugs,
|
|
7
|
-
-> { order(
|
|
8
|
-
class_name:
|
|
7
|
+
-> { order("slugs.id DESC") },
|
|
8
|
+
class_name: "Sluggi::Slug",
|
|
9
9
|
as: :sluggable,
|
|
10
10
|
dependent: :destroy
|
|
11
11
|
|
|
@@ -16,7 +16,7 @@ module Sluggi
|
|
|
16
16
|
def find_slug!(slug)
|
|
17
17
|
object = where(slug: slug).first || find_slugs(slug).first.try(:sluggable)
|
|
18
18
|
unless object.is_a?(self)
|
|
19
|
-
raise ActiveRecord::RecordNotFound, "Couldn't find #{
|
|
19
|
+
raise ActiveRecord::RecordNotFound, "Couldn't find #{name} with 'slug'='#{slug}'"
|
|
20
20
|
end
|
|
21
21
|
object
|
|
22
22
|
end
|
|
@@ -30,7 +30,7 @@ module Sluggi
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
private
|
|
34
34
|
|
|
35
35
|
def create_slug
|
|
36
36
|
value = clean_slug(slug_value)
|
|
@@ -39,6 +39,5 @@ module Sluggi
|
|
|
39
39
|
self.class.find_slugs(value).delete_all # revert to previous slug & put first
|
|
40
40
|
slugs.create(slug: value)
|
|
41
41
|
end
|
|
42
|
-
|
|
43
42
|
end
|
|
44
43
|
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
class CreateSlugs < ActiveRecord::Migration
|
|
2
2
|
def change
|
|
3
3
|
create_table :slugs do |t|
|
|
4
|
-
t.string
|
|
5
|
-
t.integer
|
|
6
|
-
t.string
|
|
4
|
+
t.string :slug, null: false
|
|
5
|
+
t.integer :sluggable_id, null: false
|
|
6
|
+
t.string :sluggable_type, null: false
|
|
7
7
|
t.datetime :created_at
|
|
8
8
|
end
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
add_index :slugs, [:slug, :sluggable_type], unique: true
|
|
11
11
|
add_index :slugs, :sluggable_id
|
|
12
12
|
end
|
data/lib/sluggi/model.rb
CHANGED
data/lib/sluggi/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sluggi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tee Parham
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -87,12 +87,8 @@ executables: []
|
|
|
87
87
|
extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
|
89
89
|
files:
|
|
90
|
-
- ".gitignore"
|
|
91
|
-
- ".travis.yml"
|
|
92
|
-
- Gemfile
|
|
93
90
|
- LICENSE.txt
|
|
94
91
|
- README.md
|
|
95
|
-
- Rakefile
|
|
96
92
|
- lib/sluggi.rb
|
|
97
93
|
- lib/sluggi/generators/sluggi_generator.rb
|
|
98
94
|
- lib/sluggi/history.rb
|
|
@@ -104,16 +100,6 @@ files:
|
|
|
104
100
|
- lib/sluggi/validate_presence.rb
|
|
105
101
|
- lib/sluggi/validate_uniqueness.rb
|
|
106
102
|
- lib/sluggi/version.rb
|
|
107
|
-
- sluggi.gemspec
|
|
108
|
-
- test/generator_test.rb
|
|
109
|
-
- test/history_test.rb
|
|
110
|
-
- test/model_test.rb
|
|
111
|
-
- test/slug_test.rb
|
|
112
|
-
- test/slugged_test.rb
|
|
113
|
-
- test/test_helper.rb
|
|
114
|
-
- test/validate_presence_test.rb
|
|
115
|
-
- test/validate_uniqueness_test.rb
|
|
116
|
-
- test/validates_exclusion_of_test.rb
|
|
117
103
|
homepage: https://github.com/neighborland/sluggi
|
|
118
104
|
licenses:
|
|
119
105
|
- MIT
|
|
@@ -134,17 +120,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
134
120
|
version: '0'
|
|
135
121
|
requirements: []
|
|
136
122
|
rubyforge_project:
|
|
137
|
-
rubygems_version: 2.
|
|
123
|
+
rubygems_version: 2.5.1
|
|
138
124
|
signing_key:
|
|
139
125
|
specification_version: 4
|
|
140
126
|
summary: Rails Slug Generator
|
|
141
|
-
test_files:
|
|
142
|
-
|
|
143
|
-
- test/history_test.rb
|
|
144
|
-
- test/model_test.rb
|
|
145
|
-
- test/slug_test.rb
|
|
146
|
-
- test/slugged_test.rb
|
|
147
|
-
- test/test_helper.rb
|
|
148
|
-
- test/validate_presence_test.rb
|
|
149
|
-
- test/validate_uniqueness_test.rb
|
|
150
|
-
- test/validates_exclusion_of_test.rb
|
|
127
|
+
test_files: []
|
|
128
|
+
has_rdoc:
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/sluggi.gemspec
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require './lib/sluggi/version'
|
|
2
|
-
|
|
3
|
-
Gem::Specification.new do |spec|
|
|
4
|
-
spec.name = "sluggi"
|
|
5
|
-
spec.version = Sluggi::VERSION
|
|
6
|
-
spec.authors = ["Tee Parham"]
|
|
7
|
-
spec.email = ["tee@neighborland.com"]
|
|
8
|
-
spec.summary = %q{Rails Slug Generator}
|
|
9
|
-
spec.description = %q{A Rails slug generator inspired by friendly_id}
|
|
10
|
-
spec.homepage = "https://github.com/neighborland/sluggi"
|
|
11
|
-
spec.license = "MIT"
|
|
12
|
-
|
|
13
|
-
spec.files = `git ls-files`.split($/)
|
|
14
|
-
spec.test_files = spec.files.grep(%r{^(test)/})
|
|
15
|
-
spec.require_paths = ["lib"]
|
|
16
|
-
|
|
17
|
-
spec.required_ruby_version = ">= 1.9.3"
|
|
18
|
-
|
|
19
|
-
spec.add_dependency "activerecord", "~> 4.0"
|
|
20
|
-
spec.add_dependency "railties", "~> 4.0"
|
|
21
|
-
|
|
22
|
-
spec.add_development_dependency "rake", "~> 10.4"
|
|
23
|
-
spec.add_development_dependency "sqlite3", "~> 1.3"
|
|
24
|
-
spec.add_development_dependency "mocha", "~> 1.0"
|
|
25
|
-
end
|
data/test/generator_test.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
require 'rails/generators/test_case'
|
|
3
|
-
|
|
4
|
-
class GeneratorTest < Rails::Generators::TestCase
|
|
5
|
-
tests ::SluggiGenerator
|
|
6
|
-
destination File.expand_path("../../tmp", __FILE__)
|
|
7
|
-
setup :prepare_destination
|
|
8
|
-
|
|
9
|
-
test "generate a migration" do
|
|
10
|
-
begin
|
|
11
|
-
run_generator
|
|
12
|
-
assert_migration "db/migrate/create_slugs"
|
|
13
|
-
ensure
|
|
14
|
-
FileUtils.rm_rf self.destination_root
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
data/test/history_test.rb
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class HistoryTest < MiniTest::Spec
|
|
4
|
-
class ::Cat < ActiveRecord::Base
|
|
5
|
-
include Sluggi::Slugged
|
|
6
|
-
include Sluggi::History
|
|
7
|
-
|
|
8
|
-
def slug_value
|
|
9
|
-
name
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def slug_value_changed?
|
|
13
|
-
name_changed?
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
class ::Dog < ActiveRecord::Base
|
|
18
|
-
include Sluggi::Slugged
|
|
19
|
-
include Sluggi::History
|
|
20
|
-
|
|
21
|
-
def slug_value
|
|
22
|
-
name
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def slug_value_changed?
|
|
26
|
-
name_changed?
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class ::BigDog < ::Dog
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
class ::LittleDog < ::Dog
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
before do
|
|
37
|
-
Cat.delete_all
|
|
38
|
-
Sluggi::Slug.delete_all
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe ".find_slug!" do
|
|
42
|
-
it "finds current slug" do
|
|
43
|
-
cat = Cat.create(name: 'Tsim Tung Brother Cream')
|
|
44
|
-
assert_equal cat, Cat.find_slug!('tsim-tung-brother-cream')
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "finds both current and historical slug" do
|
|
48
|
-
cat = Cat.create(name: 'Tsim Tung Brother Cream')
|
|
49
|
-
cat.name = 'Cream Aberdeen'
|
|
50
|
-
cat.save!
|
|
51
|
-
assert_equal cat, Cat.find_slug!('tsim-tung-brother-cream')
|
|
52
|
-
assert_equal cat, Cat.find_slug!('cream-aberdeen')
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "raises when not found" do
|
|
56
|
-
assert_raises(ActiveRecord::RecordNotFound) do
|
|
57
|
-
Cat.find_slug! 'garfield'
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "finds STI classes" do
|
|
62
|
-
big_dog = BigDog.create(name: 'Snoop')
|
|
63
|
-
assert_equal big_dog, Dog.find_slug!('snoop')
|
|
64
|
-
assert_equal big_dog, BigDog.find_slug!('snoop')
|
|
65
|
-
error = assert_raises(ActiveRecord::RecordNotFound) do
|
|
66
|
-
LittleDog.find_slug!('snoop')
|
|
67
|
-
end
|
|
68
|
-
assert_equal "Couldn't find LittleDog with 'slug'='snoop'", error.message
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
describe ".slug_exists?" do
|
|
73
|
-
it "exists" do
|
|
74
|
-
Cat.create(name: 'Tsim Tung Brother Cream')
|
|
75
|
-
assert Cat.slug_exists?('tsim-tung-brother-cream')
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "does not exist" do
|
|
79
|
-
refute Cat.slug_exists?('tsim-tung-brother-cream')
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
describe ".find_slugs" do
|
|
84
|
-
it "is empty" do
|
|
85
|
-
assert_empty Cat.find_slugs('garfield')
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it "finds historical slug" do
|
|
89
|
-
cat = Cat.create(name: 'Tsim Tung Brother Cream')
|
|
90
|
-
slugs = Cat.find_slugs('tsim-tung-brother-cream')
|
|
91
|
-
assert_equal 1, slugs.size
|
|
92
|
-
slug = slugs.first
|
|
93
|
-
assert_equal 'tsim-tung-brother-cream', slug.slug
|
|
94
|
-
assert_equal 'Cat', slug.sluggable_type
|
|
95
|
-
assert_equal cat.id, slug.sluggable_id
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
describe ".after_save" do
|
|
100
|
-
it "creates a slug when model is created" do
|
|
101
|
-
cat = Cat.create(name: 'Tsim Tung Brother Cream')
|
|
102
|
-
assert_equal 1, cat.slugs.size
|
|
103
|
-
assert_equal 'tsim-tung-brother-cream', cat.slugs.first.slug
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "creates a slug when model slug changes" do
|
|
107
|
-
cat = Cat.create(name: 'Tsim Tung Brother Cream')
|
|
108
|
-
cat.name = 'Cream Aberdeen'
|
|
109
|
-
cat.save!
|
|
110
|
-
assert_equal 2, cat.slugs.size
|
|
111
|
-
assert_equal ['cream-aberdeen', 'tsim-tung-brother-cream'], cat.slugs.map(&:slug)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it "does not create a slug when model slug is unchanged" do
|
|
115
|
-
cat = Cat.create(name: 'Tsim Tung Brother Cream')
|
|
116
|
-
cat.factoid = 'aka Cream Aberdeen'
|
|
117
|
-
cat.save!
|
|
118
|
-
assert_equal 1, cat.slugs.size
|
|
119
|
-
assert_equal 'tsim-tung-brother-cream', cat.slugs.first.slug
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
end
|
data/test/model_test.rb
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class ModelTest < MiniTest::Spec
|
|
4
|
-
class IncompleteCat < ActiveRecord::Base
|
|
5
|
-
self.table_name = 'cats'
|
|
6
|
-
include Sluggi::Model
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class Cat < ActiveRecord::Base
|
|
10
|
-
include Sluggi::Model
|
|
11
|
-
|
|
12
|
-
def slug_value
|
|
13
|
-
name
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def slug_value_changed?
|
|
17
|
-
name_changed?
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class CandidateCat < ActiveRecord::Base
|
|
22
|
-
self.table_name = 'cats'
|
|
23
|
-
include Sluggi::Model
|
|
24
|
-
|
|
25
|
-
def slug_candidates
|
|
26
|
-
[nil, name]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def slug_value_changed?
|
|
30
|
-
name_changed?
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "raises when slug_value is not implemented" do
|
|
35
|
-
assert_raises(NotImplementedError) do
|
|
36
|
-
IncompleteCat.new.valid?
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
describe "#to_param" do
|
|
41
|
-
before do
|
|
42
|
-
Cat.delete_all
|
|
43
|
-
@cat = Cat.new(name: 'Tuxedo Stan')
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "is nil when new" do
|
|
47
|
-
assert_nil @cat.to_param
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "is the slug when persisted" do
|
|
51
|
-
@cat.save!
|
|
52
|
-
assert_equal 'tuxedo-stan', @cat.to_param
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "is the old slug when changed but not saved" do
|
|
56
|
-
@cat.save!
|
|
57
|
-
@cat.slug = 'ketzel'
|
|
58
|
-
assert_equal 'tuxedo-stan', @cat.to_param
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "sets slug from candidates on validation" do
|
|
63
|
-
cat = CandidateCat.new(name: 'Smokey')
|
|
64
|
-
assert cat.valid?
|
|
65
|
-
assert_equal 'smokey', cat.slug
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "sets slug on validation" do
|
|
69
|
-
cat = Cat.new(name: 'Prince Chunk')
|
|
70
|
-
assert cat.valid?
|
|
71
|
-
assert_equal 'prince-chunk', cat.slug
|
|
72
|
-
end
|
|
73
|
-
end
|
data/test/slug_test.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
module Sluggi
|
|
4
|
-
class SlugTest < MiniTest::Spec
|
|
5
|
-
describe "validation" do
|
|
6
|
-
it "is not valid" do
|
|
7
|
-
slug = Slug.new
|
|
8
|
-
refute slug.valid?
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "is valid" do
|
|
12
|
-
slug = Slug.new(sluggable_type: 'Cat', sluggable_id: 1, slug: 'garfield')
|
|
13
|
-
assert slug.valid?
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe ".find_type" do
|
|
18
|
-
it "finds" do
|
|
19
|
-
slug = Slug.create(sluggable_type: 'Cat', sluggable_id: 1, slug: 'garfield')
|
|
20
|
-
assert_equal slug, Slug.find_type('garfield', 'Cat').first
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe "#to_param" do
|
|
25
|
-
it "is nil" do
|
|
26
|
-
assert_nil Slug.new.to_param
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "is slug" do
|
|
30
|
-
assert_equal 'meow', Slug.new(slug: 'meow').to_param
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
end
|
data/test/slugged_test.rb
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class SluggedTest < MiniTest::Spec
|
|
4
|
-
class Cat < ActiveRecord::Base
|
|
5
|
-
include Sluggi::Slugged
|
|
6
|
-
|
|
7
|
-
def slug_value
|
|
8
|
-
name
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def slug_value_changed?
|
|
12
|
-
name_changed?
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "includes ValidatePresence" do
|
|
17
|
-
assert Cat.new.is_a? Sluggi::ValidatePresence
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "includes ValidateUniqueness" do
|
|
21
|
-
assert Cat.new.is_a? Sluggi::ValidateUniqueness
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "includes ValidateExclusionOf" do
|
|
25
|
-
assert Cat.new.is_a? Sluggi::ValidateExclusionOf
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "includes Model" do
|
|
29
|
-
assert Cat.new.is_a? Sluggi::Model
|
|
30
|
-
end
|
|
31
|
-
end
|
data/test/test_helper.rb
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
#require 'coveralls'
|
|
2
|
-
#Coveralls.wear!
|
|
3
|
-
|
|
4
|
-
require 'minitest/autorun'
|
|
5
|
-
require 'active_support'
|
|
6
|
-
require 'active_record'
|
|
7
|
-
require 'sqlite3'
|
|
8
|
-
require 'sluggi'
|
|
9
|
-
require 'mocha/setup'
|
|
10
|
-
|
|
11
|
-
ActiveRecord::Base.logger = Logger.new(STDERR) if ENV["VERBOSE"]
|
|
12
|
-
|
|
13
|
-
ActiveRecord::Base.establish_connection(
|
|
14
|
-
adapter: "sqlite3",
|
|
15
|
-
database: ":memory:"
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
unless ActiveRecord::Base.connection.tables.include?('cats')
|
|
19
|
-
ActiveRecord::Schema.define do
|
|
20
|
-
create_table :cats do |t|
|
|
21
|
-
t.datetime :created_at
|
|
22
|
-
t.string :factoid
|
|
23
|
-
t.string :name
|
|
24
|
-
t.string :slug
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
create_table :slugs do |t|
|
|
28
|
-
t.string :slug, null: false
|
|
29
|
-
t.integer :sluggable_id, null: false
|
|
30
|
-
t.string :sluggable_type
|
|
31
|
-
t.datetime :created_at
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
create_table :dogs do |t|
|
|
35
|
-
t.datetime :created_at
|
|
36
|
-
t.string :type
|
|
37
|
-
t.string :name
|
|
38
|
-
t.string :slug
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
I18n.enforce_available_locales = true
|
|
44
|
-
|
|
45
|
-
# suppress deprecation warning
|
|
46
|
-
ActiveSupport.test_order = :random
|
|
47
|
-
|
|
48
|
-
# Thanks to this List of Cats: http://en.wikipedia.org/wiki/List_of_cats
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class ValidatePresenceTest < MiniTest::Spec
|
|
4
|
-
class Cat < ActiveRecord::Base
|
|
5
|
-
include Sluggi::ValidatePresence
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "validates presence of slug" do
|
|
9
|
-
refute Cat.new(slug: '').valid?
|
|
10
|
-
assert Cat.new(slug: 'foo').valid?
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class ValidateUniquenessTest < MiniTest::Spec
|
|
4
|
-
class Cat < ActiveRecord::Base
|
|
5
|
-
include Sluggi::Model
|
|
6
|
-
include Sluggi::ValidateUniqueness
|
|
7
|
-
|
|
8
|
-
def slug_value
|
|
9
|
-
name
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def slug_value_changed?
|
|
13
|
-
name_changed?
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "validates slug is unique" do
|
|
18
|
-
Cat.create(slug: "mrs-chippy")
|
|
19
|
-
cat = Cat.new(name: "Mrs. Chippy")
|
|
20
|
-
refute cat.valid?
|
|
21
|
-
assert_equal "has already been taken", cat.errors[:slug].first
|
|
22
|
-
assert_nil cat.to_param
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "does not validate uniqueness when slug is unchanged" do
|
|
26
|
-
cat = Cat.create(slug: "garfield")
|
|
27
|
-
cat.factoid = "factoid"
|
|
28
|
-
refute cat.slug_value_changed?
|
|
29
|
-
ActiveRecord::Validations::UniquenessValidator.any_instance.expects(:validate_each).never
|
|
30
|
-
assert cat.valid?
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class ValidatesExclusionOfTest < MiniTest::Spec
|
|
4
|
-
class Cat < ActiveRecord::Base
|
|
5
|
-
include Sluggi::ValidateExclusionOf
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
describe ".reserved_slugs" do
|
|
9
|
-
%w(create login users).each do |word|
|
|
10
|
-
it "includes #{word}" do
|
|
11
|
-
assert_includes Cat.reserved_slugs, word
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "does not include valid slug" do
|
|
16
|
-
refute_includes Cat.reserved_slugs, 'something'
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "validation" do
|
|
21
|
-
it "ensures slug is not a reserved word" do
|
|
22
|
-
refute Cat.new(slug: 'edit').valid?
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|