mongoid_slug 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,37 +11,43 @@ Quick Start
11
11
 
12
12
  Add mongoid_slug to your Gemfile:
13
13
 
14
- gem 'mongoid_slug', :require => 'mongoid/slug'
14
+ ```ruby
15
+ gem 'mongoid_slug'
16
+ ```
15
17
 
16
18
  Set up some slugs:
17
19
 
18
- class Book
19
- include Mongoid::Document
20
- include Mongoid::Slug
20
+ ```ruby
21
+ class Book
22
+ include Mongoid::Document
23
+ include Mongoid::Slug
21
24
 
22
- field :title
23
- embeds_many :authors
25
+ field :title
26
+ embeds_many :authors
24
27
 
25
- slug :title
26
- end
28
+ slug :title
29
+ end
27
30
 
28
- class Author
29
- include Mongoid::Document
30
- include Mongoid::Slug
31
+ class Author
32
+ include Mongoid::Document
33
+ include Mongoid::Slug
31
34
 
32
- field :first
33
- field :last
34
- embedded_in :book, :inverse_of => :authors
35
+ field :first
36
+ field :last
37
+ embedded_in :book, :inverse_of => :authors
35
38
 
36
- slug :first, :last, :as => :name
37
- end
39
+ slug :first, :last, :as => :name
40
+ end
41
+ ```
38
42
 
39
43
  In your controller, use available finders:
40
44
 
41
- # GET /books/a-thousand-plateaus/authors/gilles-deleuze
42
- author = Book.find_by_slug(params[:book_id]).
43
- authors.
44
- find_by_name(params[:id])
45
+ ```ruby
46
+ # GET /books/a-thousand-plateaus/authors/gilles-deleuze
47
+ author = Book.find_by_slug(params[:book_id]).
48
+ authors.
49
+ find_by_name(params[:id])
50
+ ```
45
51
 
46
52
  [Read here](https://github.com/papercavalier/mongoid-slug/blob/master/lib/mongoid/slug.rb)
47
53
  for all available options.
@@ -51,18 +57,20 @@ Scoping
51
57
 
52
58
  To scope a slug by a reference association, pass `:scope`:
53
59
 
54
- class Company
55
- include Mongoid::Document
56
- references_many :employees
57
- end
58
-
59
- class Employee
60
- include Mongoid::Document
61
- include Mongoid::Slug
62
- field :name
63
- slug :name, :scope => :company
64
- referenced_in :company
65
- end
60
+ ```ruby
61
+ class Company
62
+ include Mongoid::Document
63
+ references_many :employees
64
+ end
65
+
66
+ class Employee
67
+ include Mongoid::Document
68
+ include Mongoid::Slug
69
+ field :name
70
+ slug :name, :scope => :company
71
+ referenced_in :company
72
+ end
73
+ ```
66
74
 
67
75
  In this example, if you create an employee without associating it with
68
76
  any company, the scope will fall back to the root employees collection.
data/lib/mongoid/slug.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'mongoid'
1
2
  require 'stringex'
2
3
 
3
4
  module Mongoid #:nodoc:
@@ -1,5 +1,5 @@
1
1
  module Mongoid #:nodoc:
2
2
  module Slug
3
- VERSION = '0.8.0'
3
+ VERSION = '0.8.1'
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ require 'mongoid/slug'
@@ -271,22 +271,30 @@ module Mongoid
271
271
  end
272
272
  end
273
273
 
274
- it "works with non-Latin characters" do
275
- book.title = "Капитал"
276
- book.save
277
- book.to_param.should eql "kapital"
278
-
279
- book.title = "Ελλάδα"
280
- book.save
281
- book.to_param.should eql "ellada"
282
-
283
- book.title = "中文"
284
- book.save
285
- book.to_param.should eql 'zhong-wen'
286
-
287
- book.title = 'Paul Cézanne'
288
- book.save
289
- book.to_param.should eql 'paul-cezanne'
274
+ context "when slugged field contains non-ASCII characters" do
275
+ it "slugs Cyrillic characters" do
276
+ book.title = "Капитал"
277
+ book.save
278
+ book.to_param.should eql "kapital"
279
+ end
280
+
281
+ it "slugs Greek characters" do
282
+ book.title = "Ελλάδα"
283
+ book.save
284
+ book.to_param.should eql "ellada"
285
+ end
286
+
287
+ it "slugs Chinese characters" do
288
+ book.title = "中文"
289
+ book.save
290
+ book.to_param.should eql 'zhong-wen'
291
+ end
292
+
293
+ it "slugs non-ASCII Latin characters" do
294
+ book.title = 'Paul Cézanne'
295
+ book.save
296
+ book.to_param.should eql 'paul-cezanne'
297
+ end
290
298
  end
291
299
 
292
300
  context "when :index is passed as an argument" do
@@ -326,7 +334,7 @@ module Mongoid
326
334
  it "scopes by the superclass" do
327
335
  book = Book.create(:title => "Anti Oedipus")
328
336
  comic_book = ComicBook.create(:title => "Anti Oedipus")
329
- comic_book.slug.should_not eql(book.title)
337
+ comic_book.slug.should_not eql(book.slug)
330
338
  end
331
339
  end
332
340
 
data/spec/spec_helper.rb CHANGED
@@ -2,17 +2,15 @@ require "rubygems"
2
2
  require "bundler/setup"
3
3
 
4
4
  require "database_cleaner"
5
- require "mongoid"
6
- require "stringex"
7
5
  require "rspec"
8
6
 
7
+ require File.expand_path("../../lib/mongoid/slug", __FILE__)
8
+
9
9
  Mongoid.configure do |config|
10
10
  name = "mongoid_slug_test"
11
11
  config.master = Mongo::Connection.new.db(name)
12
12
  end
13
13
 
14
- require File.expand_path("../../lib/mongoid/slug", __FILE__)
15
-
16
14
  Dir["#{File.dirname(__FILE__)}/models/*.rb"].each { |f| require f }
17
15
 
18
16
  RSpec.configure do |c|
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 0
9
- version: 0.8.0
8
+ - 1
9
+ version: 0.8.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paper Cavalier
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-06-10 00:00:00 +01:00
17
+ date: 2011-06-23 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -85,6 +85,7 @@ extra_rdoc_files: []
85
85
  files:
86
86
  - lib/mongoid/slug/version.rb
87
87
  - lib/mongoid/slug.rb
88
+ - lib/mongoid_slug.rb
88
89
  - LICENSE
89
90
  - README.md
90
91
  - spec/models/article.rb