has_slug 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/has_slug.rb +20 -20
- data/test/factories.rb +16 -0
- data/test/models.rb +24 -0
- data/test/test_helper.rb +7 -6
- data/test/unit/has_slug_test.rb +1 -1
- data/test/unit/slug_test.rb +1 -1
- metadata +14 -11
- data/test/factories/city_factory.rb +0 -3
- data/test/factories/kitchen_factory.rb +0 -3
- data/test/factories/restaurant_factory.rb +0 -5
- data/test/models/city.rb +0 -8
- data/test/models/kitchen.rb +0 -5
- data/test/models/restaurant.rb +0 -9
data/lib/has_slug.rb
CHANGED
@@ -42,27 +42,27 @@ module HasSlug
|
|
42
42
|
options = DEFAULT_HAS_SLUG_OPTIONS.merge(options).merge(:attribute => attribute)
|
43
43
|
|
44
44
|
if defined?(has_slug_options)
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
write_inheritable_attribute(:has_slug_options, options)
|
49
|
-
class_inheritable_reader(:has_slug_options)
|
50
|
-
|
51
|
-
if columns.any? { |column| column.name.to_s == options[:slug_column].to_s }
|
52
|
-
require 'has_slug/sluggable_class_methods'
|
53
|
-
require 'has_slug/sluggable_instance_methods'
|
54
|
-
|
55
|
-
extend SluggableClassMethods
|
56
|
-
include SluggableInstanceMethods
|
57
|
-
|
58
|
-
before_save :set_slug,
|
59
|
-
:if => :new_slug_needed?
|
45
|
+
Rails.logger.error "has_slug_options is already defined, you can only call has_slug once. This call has been ignored."
|
60
46
|
else
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
47
|
+
write_inheritable_attribute(:has_slug_options, options)
|
48
|
+
class_inheritable_reader(:has_slug_options)
|
49
|
+
|
50
|
+
if columns.any? { |column| column.name.to_s == options[:slug_column].to_s }
|
51
|
+
require 'has_slug/sluggable_class_methods'
|
52
|
+
require 'has_slug/sluggable_instance_methods'
|
53
|
+
|
54
|
+
extend SluggableClassMethods
|
55
|
+
include SluggableInstanceMethods
|
56
|
+
|
57
|
+
before_save :set_slug,
|
58
|
+
:if => :new_slug_needed?
|
59
|
+
else
|
60
|
+
require 'has_slug/not_sluggable_class_methods'
|
61
|
+
require 'has_slug/not_sluggable_instance_methods'
|
62
|
+
|
63
|
+
extend NotSluggableClassMethods
|
64
|
+
include NotSluggableInstanceMethods
|
65
|
+
end
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
data/test/factories.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
Factory.define :city do |f|
|
3
|
+
f.name 'New York'
|
4
|
+
end
|
5
|
+
|
6
|
+
Factory.define :kitchen do |f|
|
7
|
+
f.name 'Italian'
|
8
|
+
end
|
9
|
+
|
10
|
+
Factory.define :restaurant do |f|
|
11
|
+
f.name 'Da Marco'
|
12
|
+
f.city { |city| city.association(:city) }
|
13
|
+
f.kitchen { |kitchen| kitchen.association(:kitchen) }
|
14
|
+
end
|
15
|
+
rescue Factory::DuplicateDefinitionError
|
16
|
+
end
|
data/test/models.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class City < ActiveRecord::Base
|
2
|
+
has_slug :name
|
3
|
+
|
4
|
+
has_many :restaurants
|
5
|
+
|
6
|
+
has_many :kitchens,
|
7
|
+
:through => :restaurants
|
8
|
+
end
|
9
|
+
|
10
|
+
class Kitchen < ActiveRecord::Base
|
11
|
+
has_slug :name
|
12
|
+
|
13
|
+
belongs_to :restaurant
|
14
|
+
end
|
15
|
+
|
16
|
+
class Restaurant < ActiveRecord::Base
|
17
|
+
has_slug :name,
|
18
|
+
:scope => :city,
|
19
|
+
:preserve => '.'
|
20
|
+
|
21
|
+
belongs_to :city
|
22
|
+
|
23
|
+
belongs_to :kitchen
|
24
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -6,15 +6,16 @@ require 'shoulda'
|
|
6
6
|
require 'factory_girl'
|
7
7
|
|
8
8
|
HAS_SLUG_ROOT = File.dirname(__FILE__) + "/.."
|
9
|
-
$:.unshift("#{HAS_SLUG_ROOT}/lib")
|
10
9
|
|
11
|
-
ActiveRecord::Base.establish_connection(:adapter
|
12
|
-
:
|
10
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3",
|
11
|
+
:database => "#{HAS_SLUG_ROOT}/test/test.db")
|
12
|
+
|
13
|
+
$:.unshift("#{HAS_SLUG_ROOT}/lib")
|
13
14
|
require 'has_slug'
|
14
|
-
require "#{HAS_SLUG_ROOT}/test/schema.rb"
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
require "#{HAS_SLUG_ROOT}/test/schema"
|
17
|
+
require "#{HAS_SLUG_ROOT}/test/factories"
|
18
|
+
require "#{HAS_SLUG_ROOT}/test/models"
|
18
19
|
|
19
20
|
[City, Restaurant, Kitchen].each { |c| c.reset_column_information }
|
20
21
|
|
data/test/unit/has_slug_test.rb
CHANGED
data/test/unit/slug_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_slug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 7
|
9
|
+
version: 0.2.7
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Tom-Eric Gerritsen
|
@@ -9,7 +14,7 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-14 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
@@ -48,30 +53,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
53
|
requirements:
|
49
54
|
- - ">="
|
50
55
|
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
51
58
|
version: "0"
|
52
|
-
version:
|
53
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
60
|
requirements:
|
55
61
|
- - ">="
|
56
62
|
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
57
65
|
version: "0"
|
58
|
-
version:
|
59
66
|
requirements:
|
60
67
|
- unicode_utils or unicode gem install
|
61
68
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.3.
|
69
|
+
rubygems_version: 1.3.6
|
63
70
|
signing_key:
|
64
71
|
specification_version: 3
|
65
72
|
summary: A slugging plugin for Ruby on Rails
|
66
73
|
test_files:
|
67
74
|
- test/schema.rb
|
68
75
|
- test/test_helper.rb
|
69
|
-
- test/factories
|
70
|
-
- test/
|
71
|
-
- test/factories/restaurant_factory.rb
|
72
|
-
- test/models/city.rb
|
73
|
-
- test/models/kitchen.rb
|
74
|
-
- test/models/restaurant.rb
|
76
|
+
- test/factories.rb
|
77
|
+
- test/models.rb
|
75
78
|
- test/unit/has_slug_test.rb
|
76
79
|
- rails/init.rb
|
77
80
|
- test/unit/slug_test.rb
|
data/test/models/city.rb
DELETED
data/test/models/kitchen.rb
DELETED