sluggable_finder 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -26,6 +26,9 @@ Then run the following to load the test schema:
26
26
 
27
27
  rake db:create
28
28
 
29
+ Note: I'm using mysql for now due to an apparent bug in ActiveRecord's sqlite3 adapter.
30
+ Look for configuration in spec/sluggable_finder_spec.rb
31
+
29
32
  ## SYNOPSIS:
30
33
 
31
34
  ### Models
@@ -102,17 +105,19 @@ ActiveRecord, ActiveSupport
102
105
 
103
106
  ## INSTALL:
104
107
 
105
- If you haven't yet, add github.com to your gem sources (you only need to do that once):
108
+ You can install or clone the repo from Github, but the recommended way for normal usage is to install the latest stable version from Gemcutter.org:
109
+
110
+ If you haven't yet, add gemcutter.org to your gem sources (you only need to do that once):
106
111
 
107
- gem sources -a http://gems.github.com
112
+ gem sources -a http://gemcutter.org
108
113
 
109
114
  Now you can install the normal way:
110
115
 
111
- sudo gem install ismasan-sluggable_finder
116
+ sudo gem install sluggable_finder
112
117
 
113
118
  Then, in your Rails app's environment:
114
119
 
115
- config.gem "ismasan-sluggable_finder", :lib => 'sluggable_finder'
120
+ config.gem "sluggable_finder"
116
121
 
117
122
  If you wan to unpack the gem to you app's "vendor" directory:
118
123
 
@@ -120,7 +125,7 @@ If you wan to unpack the gem to you app's "vendor" directory:
120
125
 
121
126
  ## TODO:
122
127
 
123
- *Refactor. It works but I hate the code.
128
+ *Refactor. It works but I hate the code. Find a way to override ActiveRecord.find more cleanly. Maybe Rails 3?
124
129
 
125
130
  ## LICENSE:
126
131
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 2
3
3
  :minor: 2
4
- :patch: 0
4
+ :patch: 1
@@ -4,7 +4,7 @@ module SluggableFinder
4
4
  module Finder
5
5
  def find_sluggable(opts,*args)
6
6
  key = args.first
7
- if key.is_a?(Symbol) || (key.to_s =~ /\A\d+\Z/ && opts[:allow_integer_ids]) # normal INT find
7
+ if key.is_a?(Symbol) || key.kind_of?(Array) || (key.to_s =~ /\A\d+\Z/ && opts[:allow_integer_ids]) # normal INT find
8
8
  find_without_slug(*args)
9
9
  else # sluggable find
10
10
  options = {:conditions => ["#{ opts[:to]} = ?", key]}
@@ -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.0"
8
+ s.version = "2.2.1"
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{2009-11-09}
12
+ s.date = %q{2009-12-09}
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 = [
@@ -1,8 +1,13 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  ActiveRecord::Base.establish_connection(
4
- :adapter=>'sqlite3',
5
- :dbfile=> File.join(File.dirname(__FILE__),'db','test.db')
4
+ # :adapter =>'sqlite3',
5
+ # :database => File.join(File.dirname(__FILE__),'db','test.db')
6
+ :adapter => 'mysql',
7
+ :host => 'localhost',
8
+ :database => 'sluggable_finder_test',
9
+ :user => 'root',
10
+ :password => ''
6
11
  )
7
12
 
8
13
  LOGGER = Logger.new(STDOUT)
@@ -51,6 +56,7 @@ end
51
56
  class Category < ActiveRecord::Base
52
57
  has_many :scoped_items
53
58
  has_many :simple_items
59
+ has_many :string_only_items
54
60
  end
55
61
 
56
62
  class ScopedItem < Item
@@ -144,6 +150,30 @@ describe "SluggableFinder" do
144
150
  StringOnlyItem.find('1234567890').should == @item2
145
151
  StringOnlyItem.find(1234567890).should == @item2
146
152
  end
153
+
154
+ describe 'with nested models' do
155
+
156
+ before do
157
+ @category = Category.create(:name => 'foo')
158
+ @item1 = @category.string_only_items.create(:title => 'scoped string only')
159
+ @item2 = @category.string_only_items.create(:title => '987654321')
160
+ end
161
+
162
+ it 'should work by string permalink' do
163
+ @category.string_only_items.find('scoped-string-only').should == @item1
164
+ end
165
+
166
+ it 'should NOT allow integer ID' do
167
+ lambda {
168
+ @category.string_only_items.find(@item1.id)
169
+ }.should raise_error(ActiveRecord::RecordNotFound)
170
+ end
171
+
172
+ it 'should find by integer-like slugs' do
173
+ @category.string_only_items.find('987654321').should == @item2
174
+ @category.string_only_items.find(987654321).should == @item2
175
+ end
176
+ end
147
177
  end
148
178
 
149
179
  # Raising custom not found exceptions allows us to use this with merb's NotFound exception
@@ -287,4 +317,23 @@ describe "SluggableFinder" do
287
317
  NoFinder.find(@string_id).should == @item
288
318
  end
289
319
  end
320
+
321
+ describe 'collection setters' do
322
+ before do
323
+ @item1 = SimpleItem.create(:title => 'item1')
324
+ @item2 = SimpleItem.create(:title => 'item12')
325
+ @category = Category.create(:name => 'Cat1')
326
+ end
327
+
328
+ it 'should assign children ids' do
329
+ @category.simple_item_ids = [@item1.id, @item2.id]
330
+ @category.simple_items.should == [@item1, @item2]
331
+ end
332
+
333
+ it 'should not break when assigning empty array' do
334
+ lambda {
335
+ @category.simple_item_ids = []
336
+ }.should_not raise_error
337
+ end
338
+ end
290
339
  end
data/spec/spec_helper.rb CHANGED
@@ -7,4 +7,4 @@ rescue LoadError
7
7
  end
8
8
 
9
9
  $:.unshift(File.dirname(__FILE__) + '/../lib')
10
- require 'sluggable_finder'
10
+ require 'sluggable_finder'
data/tasks/db.rake CHANGED
@@ -1,7 +1,12 @@
1
1
  require 'active_record'
2
2
  db = {
3
- :adapter=>'sqlite3',
4
- :dbfile=> File.join(File.dirname(__FILE__),'..','spec','db','test.db')
3
+ # :adapter=>'sqlite3',
4
+ # :dbfile=> File.join(File.dirname(__FILE__),'..','spec','db','test.db')
5
+ :adapter => 'mysql',
6
+ :host => 'localhost',
7
+ :database => 'sluggable_finder_test',
8
+ :user => 'root',
9
+ :password => ''
5
10
  }
6
11
  ActiveRecord::Base.establish_connection( db )
7
12
  # define a migration
@@ -31,7 +36,7 @@ namespace :db do
31
36
  desc "Create test schema"
32
37
  task :create do
33
38
  # run the migration
34
- File.unlink(db[:dbfile]) if File.exists?(db[:dbfile])
39
+ File.unlink(db[:dbfile]) if db[:adapter] == 'sqlite3' && File.exists?(db[:dbfile])
35
40
  ActiveRecord::Base.connection
36
41
  TestSchema.migrate(:up)
37
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sluggable_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-09 00:00:00 +00:00
12
+ date: 2009-12-09 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency