mongoid_slug 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,7 +4,7 @@ Mongoid Slug
4
4
  Mongoid Slug generates a URL slug or permalink based on one or more
5
5
  fields in a Mongoid model. It sits idly on top of [stringex](https://github.com/rsl/stringex) and works with non-Latin characters.
6
6
 
7
- ![lacan](http://upload.wikimedia.org/wikipedia/commons/thumb/5/5d/Nus_borromeu_1.jpg/360px-Nus_borromeu_1.jpg)
7
+ [![travis](https://secure.travis-ci.org/papercavalier/mongoid-slug.png)](http://travis-ci.org/papercavalier/mongoid-slug)
8
8
 
9
9
  Quick Start
10
10
  -----------
data/lib/mongoid/slug.rb CHANGED
@@ -106,7 +106,11 @@ module Mongoid #:nodoc:
106
106
 
107
107
  # Returns the slug.
108
108
  def to_param
109
- read_attribute(slug_name)
109
+ read_attribute(slug_name) || begin
110
+ generate_slug!
111
+ save
112
+ read_attribute(slug_name)
113
+ end
110
114
  end
111
115
 
112
116
  private
@@ -1,5 +1,5 @@
1
1
  module Mongoid #:nodoc:
2
2
  module Slug
3
- VERSION = '0.8.1'
3
+ VERSION = '0.8.2'
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
 
4
4
  module Mongoid
5
5
  describe Slug do
6
- let!(:book) do
6
+ let(:book) do
7
7
  Book.create(:title => "A Thousand Plateaus")
8
8
  end
9
9
 
@@ -41,12 +41,6 @@ module Mongoid
41
41
  end
42
42
  end
43
43
 
44
- context "when using default_scope on a model" do
45
- it "find_unique_slug should work correctly" do
46
- Page.create!(:title => "Title", :content => "Content", :order => 1)
47
- end
48
- end
49
-
50
44
  context "when the object is embedded" do
51
45
  let(:subject) do
52
46
  book.subjects.create(:name => "Psychoanalysis")
@@ -363,5 +357,17 @@ module Mongoid
363
357
  Book.find_by_slug!(book.slug).should == book
364
358
  end
365
359
  end
360
+
361
+ context "when #to_param is called on an existing record with no slug" do
362
+ before do
363
+ Book.collection.insert(:title => "Proust and Signs")
364
+ end
365
+
366
+ it "generates the missing slug" do
367
+ book = Book.first
368
+ book.to_param
369
+ book.reload.slug.should eql "proust-and-signs"
370
+ end
371
+ end
366
372
  end
367
373
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 1
9
- version: 0.8.1
8
+ - 2
9
+ version: 0.8.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paper Cavalier
@@ -14,12 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-06-23 00:00:00 +01:00
17
+ date: 2011-07-20 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: mongoid
22
- prerelease: false
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
24
23
  none: false
25
24
  requirements:
@@ -30,10 +29,10 @@ dependencies:
30
29
  - 0
31
30
  version: "2.0"
32
31
  type: :runtime
32
+ prerelease: false
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: stringex
36
- prerelease: false
37
36
  requirement: &id002 !ruby/object:Gem::Requirement
38
37
  none: false
39
38
  requirements:
@@ -44,10 +43,10 @@ dependencies:
44
43
  - 2
45
44
  version: "1.2"
46
45
  type: :runtime
46
+ prerelease: false
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: database_cleaner
50
- prerelease: false
51
50
  requirement: &id003 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
@@ -58,11 +57,25 @@ dependencies:
58
57
  - 6
59
58
  version: "0.6"
60
59
  type: :development
60
+ prerelease: false
61
61
  version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
63
- name: rspec
64
- prerelease: false
63
+ name: rake
65
64
  requirement: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ - 9
72
+ version: "0.9"
73
+ type: :development
74
+ prerelease: false
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: rspec
78
+ requirement: &id005 !ruby/object:Gem::Requirement
66
79
  none: false
67
80
  requirements:
68
81
  - - ~>
@@ -72,7 +85,8 @@ dependencies:
72
85
  - 6
73
86
  version: "2.6"
74
87
  type: :development
75
- version_requirements: *id004
88
+ prerelease: false
89
+ version_requirements: *id005
76
90
  description: Mongoid Slug generates a URL slug or permalink based on one or more fields in a Mongoid model.
77
91
  email:
78
92
  - code@papercavalier.com
@@ -114,6 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="
116
130
  - !ruby/object:Gem::Version
131
+ hash: -1577337874357746648
117
132
  segments:
118
133
  - 0
119
134
  version: "0"
@@ -122,6 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
137
  requirements:
123
138
  - - ">="
124
139
  - !ruby/object:Gem::Version
140
+ hash: -1577337874357746648
125
141
  segments:
126
142
  - 0
127
143
  version: "0"