sluggable_finder 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -68,6 +68,14 @@ If you're using Integer-like strings in your slug column, you can ignore integer
68
68
  class Comment < ActiveRecord::Base
69
69
  sluggable_finder :title, :allow_integer_ids => false
70
70
  end
71
+
72
+ ### Single Table Inheritance (STI)
73
+
74
+ Slug uniqueness will be checked accross all classes in STI models. If you want to scope by sub-class, use :ignore_sti
75
+
76
+ class Comment < SomeParentClass
77
+ sluggable_finder :title, :ignore_sti => true
78
+ end
71
79
 
72
80
  ### Controllers
73
81
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :minor: 2
3
- :patch: 2
4
- :build:
5
2
  :major: 2
3
+ :minor: 3
4
+ :patch: 0
5
+ :build:
@@ -20,7 +20,8 @@ module SluggableFinder
20
20
  :to => :slug,
21
21
  :reserved_slugs => [],
22
22
  :allow_integer_ids => true,
23
- :upcase => false
23
+ :upcase => false,
24
+ :ignore_sti => false # if true, Uniqueness won't check sibling classes.
24
25
  }.merge( options ))
25
26
  class_inheritable_reader :sluggable_finder_options
26
27
 
@@ -95,9 +96,14 @@ module SluggableFinder
95
96
  else
96
97
  "id != #{id} AND "
97
98
  end
99
+ _type_column = slugable_class.inheritance_column
100
+ _class_name = self.class.name
101
+ puts 'AAAAAAAAAAAAAAAAAA' + _class_name
98
102
  slugable_class.transaction do
99
103
  #case insensitive
100
- existing = slugable_class.find(:first, :conditions => ["#{cond}#{destination_column} LIKE ? and #{scope_condition}", proposed_slug + suffix])
104
+ conds_sql = "#{cond}#{destination_column} LIKE ? and #{scope_condition}"
105
+ conds_sql << " and #{_type_column} = '#{_class_name}'" if sluggable_finder_options[:ignore_sti]
106
+ existing = slugable_class.find(:first, :conditions => [conds_sql, proposed_slug + suffix])
101
107
  while existing != nil or sluggable_finder_options[:reserved_slugs].include?(proposed_slug + suffix)
102
108
  if suffix.empty?
103
109
  suffix = "-2"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sluggable_finder}
8
- s.version = "2.2.2"
8
+ s.version = "2.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ismael Celis"]
12
- s.date = %q{2010-06-11}
12
+ s.date = %q{2011-03-01}
13
13
  s.description = %q{This plugin allows models to generate a unique "slug" (url-enabled name) from any regular attribute. Add friendly URLs to your models with one line.}
14
14
  s.email = %q{ismaelct@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
41
41
  s.homepage = %q{http://github.com/ismasan/sluggable-finder}
42
42
  s.rdoc_options = ["--charset=UTF-8"]
43
43
  s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.6}
44
+ s.rubygems_version = %q{1.3.7}
45
45
  s.summary = %q{Easy friendly URLs for your ActiveRecord models}
46
46
  s.test_files = [
47
47
  "spec/sluggable_finder_spec.rb",
@@ -52,7 +52,7 @@ Gem::Specification.new do |s|
52
52
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
53
  s.specification_version = 3
54
54
 
55
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
56
  s.add_runtime_dependency(%q<activerecord>, [">= 2.2.2"])
57
57
  else
58
58
  s.add_dependency(%q<activerecord>, [">= 2.2.2"])
@@ -19,6 +19,14 @@ class Item < ActiveRecord::Base
19
19
  named_scope :published, :conditions => {:published => true}
20
20
  end
21
21
 
22
+ class StiParent < Item
23
+ sluggable_finder :title, :ignore_sti => true
24
+ end
25
+
26
+ class StiChild < StiParent
27
+
28
+ end
29
+
22
30
  # No sluggable finder, should be unnaffected
23
31
  #
24
32
  class NoFinder < Item
@@ -348,4 +356,16 @@ describe "SluggableFinder" do
348
356
  }.should_not raise_error
349
357
  end
350
358
  end
359
+
360
+ describe 'STI scope' do
361
+ before do
362
+ @sti1 = StiParent.create(:title => 'Slug')
363
+ @sti2 = StiChild.create(:title => 'Slug')
364
+ end
365
+
366
+ it 'should not auto increment slugs' do
367
+ @sti1.slug.should == 'slug'
368
+ @sti2.slug.should == 'slug'
369
+ end
370
+ end
351
371
  end
data/tasks/db.rake CHANGED
@@ -19,6 +19,7 @@ class TestSchema < ActiveRecord::Migration
19
19
  create_table :items do |t|
20
20
  t.string :title
21
21
  t.string :slug
22
+ t.string :type
22
23
  t.string :permalink
23
24
  t.boolean :published
24
25
  t.integer :category_id
@@ -28,6 +29,7 @@ class TestSchema < ActiveRecord::Migration
28
29
 
29
30
  def self.down
30
31
  drop_table :items
32
+ drop_table :categories
31
33
  end
32
34
  end
33
35
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sluggable_finder
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 3
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
- - 2
8
- - 2
9
- version: 2.2.2
8
+ - 3
9
+ - 0
10
+ version: 2.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ismael Celis
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-11 00:00:00 +01:00
18
+ date: 2011-03-01 00:00:00 -03:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: activerecord
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 2
29
32
  - 2
@@ -71,23 +74,27 @@ rdoc_options:
71
74
  require_paths:
72
75
  - lib
73
76
  required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
74
78
  requirements:
75
79
  - - ">="
76
80
  - !ruby/object:Gem::Version
81
+ hash: 3
77
82
  segments:
78
83
  - 0
79
84
  version: "0"
80
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
81
87
  requirements:
82
88
  - - ">="
83
89
  - !ruby/object:Gem::Version
90
+ hash: 3
84
91
  segments:
85
92
  - 0
86
93
  version: "0"
87
94
  requirements: []
88
95
 
89
96
  rubyforge_project:
90
- rubygems_version: 1.3.6
97
+ rubygems_version: 1.3.7
91
98
  signing_key:
92
99
  specification_version: 3
93
100
  summary: Easy friendly URLs for your ActiveRecord models