ismasan-sluggable_finder 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -103,6 +103,14 @@ If you wan to unpack the gem to you app's "vendor" directory:
103
103
 
104
104
  rake gems:unpack
105
105
 
106
+ ## TODO:
107
+
108
+ *Refactor. It works but I hate the code.
109
+
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
+
106
114
  ## LICENSE:
107
115
 
108
116
  (The MIT License)
@@ -4,7 +4,7 @@ module SluggableFinder
4
4
  module Finder
5
5
 
6
6
  def find_with_slug(*args)
7
- if (args.first.is_a?(String) and !(args.first =~ /\A\d+\Z/))#only contain digits
7
+ if (respond_to?(:sluggable_finder_options) && args.first.is_a?(String) and !(args.first =~ /\A\d+\Z/))#only contain digits
8
8
  options = {:conditions => ["#{ sluggable_finder_options[:to]} = ?", args.first]}
9
9
  first(options) or
10
10
  raise SluggableFinder.not_found_exception.new("There is no #{sluggable_finder_options[:sluggable_type]} with #{sluggable_finder_options[:to]} '#{args.first}'")
@@ -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.3'
5
+ VERSION = '2.0.4'
6
6
 
7
7
  @@not_found_exception = nil
8
8
 
@@ -28,7 +28,6 @@ module SluggableFinder
28
28
  end
29
29
  }.each do |klass|
30
30
  klass.send :include, SluggableFinder::Finder
31
- klass.class_eval { alias_method_chain :find, :slug }
32
31
  end
33
32
 
34
33
  end
@@ -14,6 +14,11 @@ class Item < ActiveRecord::Base
14
14
  named_scope :published, :conditions => {:published => true}
15
15
  end
16
16
 
17
+ # No sluggable finder, should be unnaffected
18
+ #
19
+ class NoFinder < Item
20
+
21
+ end
17
22
  # Simple slug
18
23
  #
19
24
  class SimpleItem < Item
@@ -208,4 +213,18 @@ describe SimpleItem, 'with AR named scopes' do
208
213
  SimpleItem.published.find('not-published')
209
214
  }.should raise_error(ActiveRecord::RecordNotFound)
210
215
  end
216
+ end
217
+
218
+ describe NoFinder, "with no finder" do
219
+ before(:each) do
220
+ NoFinder.delete_all
221
+ @item = NoFinder.create(:title => 'no finder here')
222
+ @string_id = "#{@item.id}-some-string"
223
+ end
224
+
225
+ it "should use find normally" do
226
+ NoFinder.find(:first).should == @item
227
+ NoFinder.find(@item.id).should == @item
228
+ NoFinder.find(@string_id).should == @item
229
+ end
211
230
  end
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.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis