mongoid-slug 4.0.0 → 5.0.0

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.
Files changed (43) hide show
  1. checksums.yaml +13 -5
  2. data/LICENSE +1 -1
  3. data/README.md +18 -18
  4. data/lib/mongoid/slug.rb +48 -44
  5. data/lib/mongoid/slug/criteria.rb +14 -11
  6. data/lib/mongoid/slug/index.rb +5 -8
  7. data/lib/mongoid/slug/paranoia.rb +0 -2
  8. data/lib/mongoid/slug/slug_id_strategy.rb +1 -1
  9. data/lib/mongoid/slug/unique_slug.rb +27 -29
  10. data/lib/mongoid/slug/version.rb +1 -1
  11. data/spec/models/alias.rb +2 -2
  12. data/spec/models/article.rb +1 -1
  13. data/spec/models/author.rb +3 -3
  14. data/spec/models/author_polymorphic.rb +3 -3
  15. data/spec/models/book.rb +1 -1
  16. data/spec/models/book_polymorphic.rb +1 -1
  17. data/spec/models/caption.rb +1 -1
  18. data/spec/models/entity.rb +2 -2
  19. data/spec/models/friend.rb +2 -2
  20. data/spec/models/incorrect_slug_persistence.rb +5 -5
  21. data/spec/models/integer_id.rb +1 -1
  22. data/spec/models/magazine.rb +1 -1
  23. data/spec/models/page.rb +3 -3
  24. data/spec/models/page_localize.rb +3 -3
  25. data/spec/models/page_slug_localized.rb +3 -3
  26. data/spec/models/page_slug_localized_custom.rb +0 -1
  27. data/spec/models/page_slug_localized_history.rb +3 -3
  28. data/spec/models/paranoid_document.rb +1 -1
  29. data/spec/models/paranoid_permanent.rb +1 -1
  30. data/spec/models/partner.rb +1 -1
  31. data/spec/models/person.rb +2 -2
  32. data/spec/models/relationship.rb +1 -1
  33. data/spec/models/string_id.rb +1 -1
  34. data/spec/models/subject.rb +1 -1
  35. data/spec/models/without_slug.rb +1 -1
  36. data/spec/mongoid/criteria_spec.rb +109 -109
  37. data/spec/mongoid/index_spec.rb +12 -14
  38. data/spec/mongoid/paranoia_spec.rb +78 -90
  39. data/spec/mongoid/slug_spec.rb +493 -492
  40. data/spec/shared/indexes.rb +13 -13
  41. data/spec/spec_helper.rb +18 -14
  42. metadata +51 -26
  43. data/spec/mongoid/slug_spec.rb.b00 +0 -1101
@@ -1,5 +1,5 @@
1
1
  module Mongoid #:nodoc:
2
2
  module Slug
3
- VERSION = '4.0.0'
3
+ VERSION = '5.0.0'
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  class Alias
2
2
  include Mongoid::Document
3
3
  include Mongoid::Slug
4
- field :name, :as => :author_name
5
- slug :author_name
4
+ field :name, as: :author_name
5
+ slug :author_name
6
6
  end
@@ -3,7 +3,7 @@ class Article
3
3
  include Mongoid::Slug
4
4
  field :brief
5
5
  field :title
6
- slug :title, :brief do |doc|
6
+ slug :title, :brief do |doc|
7
7
  [doc.title, doc.brief].reject(&:blank?).first
8
8
  end
9
9
  end
@@ -3,9 +3,9 @@ class Author
3
3
  include Mongoid::Slug
4
4
  field :first_name
5
5
  field :last_name
6
- slug :first_name, :last_name, :scope => :book
6
+ slug :first_name, :last_name, scope: :book
7
7
  belongs_to :book
8
8
  has_many :characters,
9
- :class_name => 'Person',
10
- :foreign_key => :author_id
9
+ class_name: 'Person',
10
+ foreign_key: :author_id
11
11
  end
@@ -3,9 +3,9 @@ class AuthorPolymorphic
3
3
  include Mongoid::Slug
4
4
  field :first_name
5
5
  field :last_name
6
- slug :first_name, :last_name, :scope => :book_polymorphic
6
+ slug :first_name, :last_name, scope: :book_polymorphic
7
7
  belongs_to :book_polymorphic
8
8
  has_many :characters,
9
- :class_name => 'Person',
10
- :foreign_key => :author_id
9
+ class_name: 'Person',
10
+ foreign_key: :author_id
11
11
  end
@@ -3,7 +3,7 @@ class Book
3
3
  include Mongoid::Slug
4
4
  field :title
5
5
 
6
- slug :title, :history => true
6
+ slug :title, history: true
7
7
  embeds_many :subjects
8
8
  has_many :authors
9
9
  end
@@ -3,7 +3,7 @@ class BookPolymorphic
3
3
  include Mongoid::Slug
4
4
  field :title
5
5
 
6
- slug :title, :history => true, :by_model_type => true
6
+ slug :title, history: true, by_model_type: true
7
7
  embeds_many :subjects
8
8
  has_many :author_polymorphics
9
9
  end
@@ -1,7 +1,7 @@
1
1
  class Caption
2
2
  include Mongoid::Document
3
3
  include Mongoid::Slug
4
- field :my_identity, :type => String
4
+ field :my_identity, type: String
5
5
  field :title
6
6
  field :medium
7
7
 
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
  class Entity
3
3
  include Mongoid::Document
4
4
  include Mongoid::Slug
@@ -8,5 +8,5 @@ class Entity
8
8
  field :name
9
9
  field :user_edited_variation
10
10
 
11
- slug :user_edited_variation, :history => true
11
+ slug :user_edited_variation, history: true
12
12
  end
@@ -2,6 +2,6 @@ class Friend
2
2
  include Mongoid::Document
3
3
  include Mongoid::Slug
4
4
  field :name
5
- field :slug_history, :type => Array
6
- slug :name, :reserve => ['foo', 'bar', /^[a-z]{2}$/i], :history => true
5
+ field :slug_history, type: Array
6
+ slug :name, reserve: ['foo', 'bar', /^[a-z]{2}$/i], history: true
7
7
  end
@@ -1,9 +1,9 @@
1
1
  class IncorrectSlugPersistence
2
- include Mongoid::Document
3
- include Mongoid::Slug
2
+ include Mongoid::Document
3
+ include Mongoid::Slug
4
4
 
5
- field :name
6
- slug :name, history: true
5
+ field :name
6
+ slug :name, history: true
7
7
 
8
- validates_length_of :name, :minimum => 4, :maximum => 5, :allow_blank => true
8
+ validates_length_of :name, minimum: 4, maximum: 5, allow_blank: true
9
9
  end
@@ -6,4 +6,4 @@ class IntegerId
6
6
  field :name, type: String
7
7
 
8
8
  slug :name, history: true
9
- end
9
+ end
@@ -3,5 +3,5 @@ class Magazine
3
3
  include Mongoid::Slug
4
4
  field :title
5
5
  field :publisher_id
6
- slug :title, :scope => :publisher_id
6
+ slug :title, scope: :publisher_id
7
7
  end
@@ -3,7 +3,7 @@ class Page
3
3
  include Mongoid::Slug
4
4
  field :title
5
5
  field :content
6
- field :order, :type => Integer
7
- slug :title
8
- default_scope ->{ asc(:order) }
6
+ field :order, type: Integer
7
+ slug :title
8
+ default_scope -> { asc(:order) }
9
9
  end
@@ -3,7 +3,7 @@ class PageLocalize
3
3
  include Mongoid::Slug
4
4
  field :title, localize: true
5
5
  field :content
6
- field :order, :type => Integer
7
- slug :title
8
- default_scope ->{ asc(:order) }
6
+ field :order, type: Integer
7
+ slug :title
8
+ default_scope -> { asc(:order) }
9
9
  end
@@ -3,7 +3,7 @@ class PageSlugLocalized
3
3
  include Mongoid::Slug
4
4
  field :title, localize: true
5
5
  field :content
6
- field :order, :type => Integer
7
- slug :title, localize: true
8
- default_scope ->{ asc(:order) }
6
+ field :order, type: Integer
7
+ slug :title, localize: true
8
+ default_scope -> { asc(:order) }
9
9
  end
@@ -7,5 +7,4 @@ class PageSlugLocalizedCustom
7
7
  slug :title, localize: true do |obj|
8
8
  obj.title.to_url
9
9
  end
10
-
11
10
  end
@@ -3,7 +3,7 @@ class PageSlugLocalizedHistory
3
3
  include Mongoid::Slug
4
4
  field :title, localize: true
5
5
  field :content
6
- field :order, :type => Integer
7
- slug :title, localize: true, history: true
8
- default_scope ->{ asc(:order) }
6
+ field :order, type: Integer
7
+ slug :title, localize: true, history: true
8
+ default_scope -> { asc(:order) }
9
9
  end
@@ -4,5 +4,5 @@ class ParanoidDocument
4
4
  include Mongoid::Slug
5
5
 
6
6
  field :title
7
- slug :title
7
+ slug :title
8
8
  end
@@ -4,5 +4,5 @@ class ParanoidPermanent
4
4
  include Mongoid::Slug
5
5
 
6
6
  field :title
7
- slug :title, permanent: true
7
+ slug :title, permanent: true
8
8
  end
@@ -2,6 +2,6 @@ class Partner
2
2
  include Mongoid::Document
3
3
  include Mongoid::Slug
4
4
  field :name
5
- slug :name
5
+ slug :name
6
6
  embedded_in :relationship
7
7
  end
@@ -2,7 +2,7 @@ class Person
2
2
  include Mongoid::Document
3
3
  include Mongoid::Slug
4
4
  field :name
5
- slug :name, :permanent => true, :scope => :author
5
+ slug :name, permanent: true, scope: :author
6
6
  embeds_many :relationships
7
- belongs_to :author, :inverse_of => :characters
7
+ belongs_to :author, inverse_of: :characters
8
8
  end
@@ -2,7 +2,7 @@ class Relationship
2
2
  include Mongoid::Document
3
3
  include Mongoid::Slug
4
4
  field :name
5
- slug :name
5
+ slug :name
6
6
  embeds_many :partners
7
7
  embedded_in :person
8
8
  end
@@ -6,4 +6,4 @@ class StringId
6
6
  field :name, type: String
7
7
 
8
8
  slug :name, history: true
9
- end
9
+ end
@@ -2,6 +2,6 @@ class Subject
2
2
  include Mongoid::Document
3
3
  include Mongoid::Slug
4
4
  field :name
5
- slug :name, :scope => :book, :history => true
5
+ slug :name, scope: :book, history: true
6
6
  embedded_in :book
7
7
  end
@@ -2,4 +2,4 @@ class WithoutSlug
2
2
  include Mongoid::Document
3
3
 
4
4
  field :_id, type: Integer
5
- end
5
+ end
@@ -1,188 +1,188 @@
1
- #encoding: utf-8
2
- require "spec_helper"
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
3
 
4
4
  describe Mongoid::Slug::Criteria do
5
- describe ".find" do
6
- let!(:book) { Book.create(:title => "A Working Title").tap { |d| d.update_attribute(:title, "A Thousand Plateaus") } }
7
- let!(:book2) { Book.create(:title => "Difference and Repetition") }
8
- let!(:friend) { Friend.create(:name => "Jim Bob") }
9
- let!(:friend2) { Friend.create(:name => friend.id.to_s) }
10
- let!(:integer_id) { IntegerId.new(:name => "I have integer ids").tap { |d| d.id = 123; d.save } }
11
- let!(:integer_id2) { IntegerId.new(:name => integer_id.id.to_s).tap { |d| d.id = 456; d.save } }
12
- let!(:string_id) { StringId.new(:name => "I have string ids").tap { |d| d.id = 'abc'; d.save } }
13
- let!(:string_id2) { StringId.new(:name => string_id.id.to_s).tap { |d| d.id = 'def'; d.save } }
14
- let!(:subject) { Subject.create(:name => "A Subject", :book => book) }
15
- let!(:subject2) { Subject.create(:name => "A Subject", :book => book2) }
16
- let!(:without_slug) { WithoutSlug.new().tap { |d| d.id = 456; d.save } }
17
-
18
- context "when the model does not use mongoid slugs" do
5
+ describe '.find' do
6
+ let!(:book) { Book.create(title: 'A Working Title').tap { |d| d.update_attribute(:title, 'A Thousand Plateaus') } }
7
+ let!(:book2) { Book.create(title: 'Difference and Repetition') }
8
+ let!(:friend) { Friend.create(name: 'Jim Bob') }
9
+ let!(:friend2) { Friend.create(name: friend.id.to_s) }
10
+ let!(:integer_id) { IntegerId.new(name: 'I have integer ids').tap { |d| d.id = 123; d.save! } }
11
+ let!(:integer_id2) { IntegerId.new(name: integer_id.id.to_s).tap { |d| d.id = 456; d.save! } }
12
+ let!(:string_id) { StringId.new(name: 'I have string ids').tap { |d| d.id = 'abc'; d.save! } }
13
+ let!(:string_id2) { StringId.new(name: string_id.id.to_s).tap { |d| d.id = 'def'; d.save! } }
14
+ let!(:subject) { Subject.create(name: 'A Subject', book: book) }
15
+ let!(:subject2) { Subject.create(name: 'A Subject', book: book2) }
16
+ let!(:without_slug) { WithoutSlug.new.tap { |d| d.id = 456; d.save! } }
17
+
18
+ context 'when the model does not use mongoid slugs' do
19
19
  it "should not use mongoid slug's custom find methods" do
20
- Mongoid::Slug::Criteria.any_instance.should_not_receive(:find)
21
- WithoutSlug.find(without_slug.id.to_s).should == without_slug
20
+ expect_any_instance_of(Mongoid::Slug::Criteria).not_to receive(:find)
21
+ expect(WithoutSlug.find(without_slug.id.to_s)).to eq(without_slug)
22
22
  end
23
23
  end
24
24
 
25
- context "using slugs" do
26
- context "(single)" do
27
- context "and a document is found" do
28
- it "returns the document as an object" do
29
- Book.find(book.slugs.first).should == book
25
+ context 'using slugs' do
26
+ context '(single)' do
27
+ context 'and a document is found' do
28
+ it 'returns the document as an object' do
29
+ expect(Book.find(book.slugs.first)).to eq(book)
30
30
  end
31
31
  end
32
32
 
33
- context "but no document is found" do
34
- it "raises a Mongoid::Errors::DocumentNotFound error" do
35
- lambda {
36
- Book.find("Anti Oedipus")
37
- }.should raise_error(Mongoid::Errors::DocumentNotFound)
33
+ context 'but no document is found' do
34
+ it 'raises a Mongoid::Errors::DocumentNotFound error' do
35
+ expect do
36
+ Book.find('Anti Oedipus')
37
+ end.to raise_error(Mongoid::Errors::DocumentNotFound)
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
- context "(multiple)" do
43
- context "and all documents are found" do
44
- it "returns the documents as an array without duplication" do
45
- Book.find(book.slugs + book2.slugs).should =~ [book, book2]
42
+ context '(multiple)' do
43
+ context 'and all documents are found' do
44
+ it 'returns the documents as an array without duplication' do
45
+ expect(Book.find(book.slugs + book2.slugs)).to match_array([book, book2])
46
46
  end
47
47
  end
48
48
 
49
- context "but not all documents are found" do
50
- it "raises a Mongoid::Errors::DocumentNotFound error" do
51
- lambda {
49
+ context 'but not all documents are found' do
50
+ it 'raises a Mongoid::Errors::DocumentNotFound error' do
51
+ expect do
52
52
  Book.find(book.slugs + ['something-nonexistent'])
53
- }.should raise_error(Mongoid::Errors::DocumentNotFound)
53
+ end.to raise_error(Mongoid::Errors::DocumentNotFound)
54
54
  end
55
55
  end
56
56
  end
57
57
 
58
- context "when no documents match" do
59
- it "raises a Mongoid::Errors::DocumentNotFound error" do
60
- lambda {
61
- Book.find("Anti Oedipus")
62
- }.should raise_error(Mongoid::Errors::DocumentNotFound)
58
+ context 'when no documents match' do
59
+ it 'raises a Mongoid::Errors::DocumentNotFound error' do
60
+ expect do
61
+ Book.find('Anti Oedipus')
62
+ end.to raise_error(Mongoid::Errors::DocumentNotFound)
63
63
  end
64
64
  end
65
65
 
66
- context "when ids are BSON::ObjectIds and the supplied argument looks like a BSON::ObjectId" do
67
- it "it should find based on ids not slugs" do # i.e. it should type cast the argument
68
- Friend.find(friend.id.to_s).should == friend
66
+ context 'when ids are BSON::ObjectIds and the supplied argument looks like a BSON::ObjectId' do
67
+ it 'it should find based on ids not slugs' do # i.e. it should type cast the argument
68
+ expect(Friend.find(friend.id.to_s)).to eq(friend)
69
69
  end
70
70
  end
71
71
 
72
- context "when ids are Strings" do
73
- it "it should find based on ids not slugs" do # i.e. string ids should take precedence over string slugs
74
- StringId.find(string_id.id.to_s).should == string_id
72
+ context 'when ids are Strings' do
73
+ it 'it should find based on ids not slugs' do # i.e. string ids should take precedence over string slugs
74
+ expect(StringId.find(string_id.id.to_s)).to eq(string_id)
75
75
  end
76
76
  end
77
77
 
78
- context "when ids are Integers and the supplied arguments looks like an Integer" do
79
- it "it should find based on slugs not ids" do # i.e. it should not type cast the argument
80
- IntegerId.find(integer_id.id.to_s).should == integer_id2
78
+ context 'when ids are Integers and the supplied arguments looks like an Integer' do
79
+ it 'it should find based on slugs not ids' do # i.e. it should not type cast the argument
80
+ expect(IntegerId.find(integer_id.id.to_s)).to eq(integer_id2)
81
81
  end
82
82
  end
83
83
 
84
- context "models that does not use slugs, should find using the original find" do
85
- it "it should find based on ids" do # i.e. it should not type cast the argument
86
- WithoutSlug.find(without_slug.id.to_s).should == without_slug
84
+ context 'models that does not use slugs, should find using the original find' do
85
+ it 'it should find based on ids' do # i.e. it should not type cast the argument
86
+ expect(WithoutSlug.find(without_slug.id.to_s)).to eq(without_slug)
87
87
  end
88
88
  end
89
89
 
90
- context "when scoped" do
91
- context "and a document is found" do
92
- it "returns the document as an object" do
93
- book.subjects.find(subject.slugs.first).should == subject
94
- book2.subjects.find(subject.slugs.first).should == subject2
90
+ context 'when scoped' do
91
+ context 'and a document is found' do
92
+ it 'returns the document as an object' do
93
+ expect(book.subjects.find(subject.slugs.first)).to eq(subject)
94
+ expect(book2.subjects.find(subject.slugs.first)).to eq(subject2)
95
95
  end
96
96
  end
97
97
 
98
- context "but no document is found" do
99
- it "raises a Mongoid::Errors::DocumentNotFound error" do
100
- lambda {
98
+ context 'but no document is found' do
99
+ it 'raises a Mongoid::Errors::DocumentNotFound error' do
100
+ expect do
101
101
  book.subjects.find('Another Subject')
102
- }.should raise_error(Mongoid::Errors::DocumentNotFound)
102
+ end.to raise_error(Mongoid::Errors::DocumentNotFound)
103
103
  end
104
104
  end
105
105
  end
106
106
  end
107
107
 
108
- context "using ids" do
109
- it "raises a Mongoid::Errors::DocumentNotFound error if no document is found" do
110
- lambda {
108
+ context 'using ids' do
109
+ it 'raises a Mongoid::Errors::DocumentNotFound error if no document is found' do
110
+ expect do
111
111
  Book.find(friend.id)
112
- }.should raise_error(Mongoid::Errors::DocumentNotFound)
112
+ end.to raise_error(Mongoid::Errors::DocumentNotFound)
113
113
  end
114
114
 
115
- context "given a single document" do
116
- it "returns the document" do
117
- Friend.find(friend.id).should == friend
115
+ context 'given a single document' do
116
+ it 'returns the document' do
117
+ expect(Friend.find(friend.id)).to eq(friend)
118
118
  end
119
119
  end
120
120
 
121
- context "given multiple documents" do
122
- it "returns the documents" do
123
- Book.find([book.id, book2.id]).should =~ [book, book2]
121
+ context 'given multiple documents' do
122
+ it 'returns the documents' do
123
+ expect(Book.find([book.id, book2.id])).to match_array([book, book2])
124
124
  end
125
125
  end
126
126
  end
127
127
  end
128
128
 
129
- describe ".find_by_slug!" do
130
- let!(:book) { Book.create(:title => "A Working Title").tap { |d| d.update_attribute(:title, "A Thousand Plateaus") } }
131
- let!(:book2) { Book.create(:title => "Difference and Repetition") }
132
- let!(:friend) { Friend.create(:name => "Jim Bob") }
133
- let!(:friend2) { Friend.create(:name => friend.id.to_s) }
134
- let!(:integer_id) { IntegerId.new(:name => "I have integer ids").tap { |d| d.id = 123; d.save } }
135
- let!(:integer_id2) { IntegerId.new(:name => integer_id.id.to_s).tap { |d| d.id = 456; d.save } }
136
- let!(:string_id) { StringId.new(:name => "I have string ids").tap { |d| d.id = 'abc'; d.save } }
137
- let!(:string_id2) { StringId.new(:name => string_id.id.to_s).tap { |d| d.id = 'def'; d.save } }
138
- let!(:subject) { Subject.create(:name => "A Subject", :book => book) }
139
- let!(:subject2) { Subject.create(:name => "A Subject", :book => book2) }
129
+ describe '.find_by_slug!' do
130
+ let!(:book) { Book.create(title: 'A Working Title').tap { |d| d.update_attribute(:title, 'A Thousand Plateaus') } }
131
+ let!(:book2) { Book.create(title: 'Difference and Repetition') }
132
+ let!(:friend) { Friend.create(name: 'Jim Bob') }
133
+ let!(:friend2) { Friend.create(name: friend.id.to_s) }
134
+ let!(:integer_id) { IntegerId.new(name: 'I have integer ids').tap { |d| d.id = 123; d.save! } }
135
+ let!(:integer_id2) { IntegerId.new(name: integer_id.id.to_s).tap { |d| d.id = 456; d.save! } }
136
+ let!(:string_id) { StringId.new(name: 'I have string ids').tap { |d| d.id = 'abc'; d.save! } }
137
+ let!(:string_id2) { StringId.new(name: string_id.id.to_s).tap { |d| d.id = 'def'; d.save! } }
138
+ let!(:subject) { Subject.create(name: 'A Subject', book: book) }
139
+ let!(:subject2) { Subject.create(name: 'A Subject', book: book2) }
140
140
 
141
- context "(single)" do
142
- context "and a document is found" do
143
- it "returns the document as an object" do
144
- Book.find_by_slug!(book.slugs.first).should == book
141
+ context '(single)' do
142
+ context 'and a document is found' do
143
+ it 'returns the document as an object' do
144
+ expect(Book.find_by_slug!(book.slugs.first)).to eq(book)
145
145
  end
146
146
  end
147
147
 
148
- context "but no document is found" do
149
- it "raises a Mongoid::Errors::DocumentNotFound error" do
150
- lambda {
151
- Book.find_by_slug!("Anti Oedipus")
152
- }.should raise_error(Mongoid::Errors::DocumentNotFound)
148
+ context 'but no document is found' do
149
+ it 'raises a Mongoid::Errors::DocumentNotFound error' do
150
+ expect do
151
+ Book.find_by_slug!('Anti Oedipus')
152
+ end.to raise_error(Mongoid::Errors::DocumentNotFound)
153
153
  end
154
154
  end
155
155
  end
156
156
 
157
- context "(multiple)" do
158
- context "and all documents are found" do
159
- it "returns the documents as an array without duplication" do
160
- Book.find_by_slug!(book.slugs + book2.slugs).should =~ [book, book2]
157
+ context '(multiple)' do
158
+ context 'and all documents are found' do
159
+ it 'returns the documents as an array without duplication' do
160
+ expect(Book.find_by_slug!(book.slugs + book2.slugs)).to match_array([book, book2])
161
161
  end
162
162
  end
163
163
 
164
- context "but not all documents are found" do
165
- it "raises a Mongoid::Errors::DocumentNotFound error" do
166
- lambda {
164
+ context 'but not all documents are found' do
165
+ it 'raises a Mongoid::Errors::DocumentNotFound error' do
166
+ expect do
167
167
  Book.find_by_slug!(book.slugs + ['something-nonexistent'])
168
- }.should raise_error(Mongoid::Errors::DocumentNotFound)
168
+ end.to raise_error(Mongoid::Errors::DocumentNotFound)
169
169
  end
170
170
  end
171
171
  end
172
172
 
173
- context "when scoped" do
174
- context "and a document is found" do
175
- it "returns the document as an object" do
176
- book.subjects.find_by_slug!(subject.slugs.first).should == subject
177
- book2.subjects.find_by_slug!(subject.slugs.first).should == subject2
173
+ context 'when scoped' do
174
+ context 'and a document is found' do
175
+ it 'returns the document as an object' do
176
+ expect(book.subjects.find_by_slug!(subject.slugs.first)).to eq(subject)
177
+ expect(book2.subjects.find_by_slug!(subject.slugs.first)).to eq(subject2)
178
178
  end
179
179
  end
180
180
 
181
- context "but no document is found" do
182
- it "raises a Mongoid::Errors::DocumentNotFound error" do
183
- lambda {
181
+ context 'but no document is found' do
182
+ it 'raises a Mongoid::Errors::DocumentNotFound error' do
183
+ expect do
184
184
  book.subjects.find_by_slug!('Another Subject')
185
- }.should raise_error(Mongoid::Errors::DocumentNotFound)
185
+ end.to raise_error(Mongoid::Errors::DocumentNotFound)
186
186
  end
187
187
  end
188
188
  end