ismasan-sluggable_finder 2.0.5 → 2.0.6

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.
data/README.markdown CHANGED
@@ -4,6 +4,8 @@ Ismael Celis
4
4
 
5
5
  http://github.com/ismasan/sluggable_finder
6
6
 
7
+ This gem is originally based on http://github.com/smtlaissezfaire/acts_as_sluggable/tree/master/lib%2Facts_as_slugable.rb
8
+
7
9
  ## DESCRIPTION:
8
10
 
9
11
  This is a variation of acts_as_sluggable, permalink_fu and acts_as_permalink.
@@ -107,10 +109,6 @@ If you wan to unpack the gem to you app's "vendor" directory:
107
109
 
108
110
  *Refactor. It works but I hate the code.
109
111
 
110
- *Avoid including in ALL models. At the moment we need to extend associations for all models. Not sure how to only extend associations for models that use the plugin.
111
-
112
- *Better testing for scoped collections. @user.posts.find 'blah' should only look in posts for @user without needing to add :scope
113
-
114
112
  ## LICENSE:
115
113
 
116
114
  (The MIT License)
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module SluggableFinder
5
- VERSION = '2.0.5'
5
+ VERSION = '2.0.6'
6
6
 
7
7
  @@not_found_exception = nil
8
8
 
@@ -44,10 +44,15 @@ module SluggableFinder
44
44
  end
45
45
  end
46
46
 
47
+ def self.random_slug_for(klass)
48
+ Digest::SHA1.hexdigest( klass.name.to_s + Time.now.to_s )
49
+ end
50
+
47
51
  end
48
52
 
49
53
  require 'rubygems'
50
54
  require 'active_record'
55
+ require 'digest/sha1'
51
56
 
52
57
  Dir.glob(File.dirname(__FILE__)+'/sluggable_finder/*.rb').each do |file|
53
58
  require file
@@ -70,14 +70,19 @@ module SluggableFinder
70
70
  s = self.create_sluggable_slug
71
71
  write_attribute(destination_column, s)
72
72
  end
73
-
73
+
74
+ def get_value_or_generate_random(column_name)
75
+ v = self.send(column_name)
76
+ v || SluggableFinder.random_slug_for(self.class)
77
+ end
78
+
74
79
  def create_sluggable_slug
75
80
  suffix = ''
76
81
  begin
77
- proposed_slug = if self.send(destination_column.to_sym).blank?
78
- SluggableFinder.encode self.send(source_column.to_sym)
82
+ proposed_slug = if self.send(destination_column.to_sym).blank? # self.slug
83
+ SluggableFinder.encode get_value_or_generate_random(source_column.to_sym) # self.title
79
84
  else
80
- SluggableFinder.encode self.send(destination_column.to_sym)
85
+ SluggableFinder.encode get_value_or_generate_random(destination_column.to_sym) # self.slug
81
86
  end
82
87
  rescue Exception => e
83
88
  raise e
@@ -54,6 +54,12 @@ class ScopedItem < Item
54
54
  sluggable_finder :title, :scope => :category_id
55
55
  end
56
56
 
57
+ describe "random slugs" do
58
+ it "should generate random slugs" do
59
+ SluggableFinder.random_slug_for(String).should_not be_nil
60
+ end
61
+ end
62
+
57
63
  describe SimpleItem, 'encoding permalinks' do
58
64
  before(:each) do
59
65
  Item.delete_all
@@ -86,7 +92,7 @@ describe SimpleItem, 'encoding permalinks' do
86
92
  SimpleItem.find(@item.id).should == @item
87
93
  end
88
94
 
89
- it "should by ID even if ID is string" do
95
+ it "should find by ID even if ID is string" do
90
96
  SimpleItem.find(@item.id.to_s).should == @item
91
97
  end
92
98
 
@@ -102,6 +108,11 @@ describe SimpleItem, 'encoding permalinks' do
102
108
  @item.save
103
109
  @item.to_param.should == 'hello-world'
104
110
  end
111
+
112
+ it "should store random slug if field is nil" do
113
+ item = SimpleItem.create!(:title => nil)
114
+ item.to_param.should_not be_blank
115
+ end
105
116
  end
106
117
 
107
118
  # Raising custom not found exceptions allows us to use this with merb's NotFound exception
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ismasan-sluggable_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis
@@ -9,20 +9,22 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-16 00:00:00 -08:00
12
+ date: 2009-02-25 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: newgem
17
+ type: :development
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 1.0.5
23
+ version: 1.2.3
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: hoe
27
+ type: :development
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -84,6 +86,6 @@ rubyforge_project: sluggable_finder
84
86
  rubygems_version: 1.2.0
85
87
  signing_key:
86
88
  specification_version: 2
87
- summary: SEO friendly permalinks for your Active Record models
89
+ summary: ""
88
90
  test_files: []
89
91