mongoid-rspec 1.7.0 → 1.8.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.
- data/README.md +1 -1
- data/lib/matchers/associations.rb +16 -0
- data/lib/mongoid-rspec/version.rb +1 -1
- data/spec/models/user.rb +1 -1
- data/spec/unit/associations_spec.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Drop in existing or dedicated support file in spec/support (spec/support/mongoid
|
|
24
24
|
Association Matchers
|
25
25
|
-
|
26
26
|
describe User do
|
27
|
-
it { should have_many(:articles).with_foreign_key(:author_id) }
|
27
|
+
it { should have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
|
28
28
|
|
29
29
|
it { should have_one(:record) }
|
30
30
|
#can verify autobuild is set to true
|
@@ -39,6 +39,13 @@ module Mongoid
|
|
39
39
|
self
|
40
40
|
end
|
41
41
|
|
42
|
+
def ordered_by(association_field_name)
|
43
|
+
raise "#{@association[:type].inspect} does not respond to :order" unless [HAS_MANY, HAS_AND_BELONGS_TO_MANY, EMBEDS_MANY].include?(@association[:type])
|
44
|
+
@association[:order] = association_field_name.to_s
|
45
|
+
@expectation_message << " ordered by #{@association[:order].inspect}"
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
42
49
|
def with_dependent(method_name)
|
43
50
|
@association[:dependent] = method_name
|
44
51
|
@expectation_message << " which specifies dependent as #{@association[:dependent].to_s}"
|
@@ -108,6 +115,15 @@ module Mongoid
|
|
108
115
|
end
|
109
116
|
end
|
110
117
|
|
118
|
+
if @association[:order]
|
119
|
+
if @association[:order].to_s != metadata.order.to_s
|
120
|
+
@negative_result_message = "#{@positive_result_message} ordered by #{metadata.order}"
|
121
|
+
return false
|
122
|
+
else
|
123
|
+
@positive_result_message = "#{@positive_result_message} ordered by #{metadata.order}"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
111
127
|
if @association[:dependent]
|
112
128
|
if @association[:dependent].to_s != metadata.dependent.to_s
|
113
129
|
@negative_result_message = "#{@positive_result_message} which specified dependent as #{metadata.dependent}"
|
data/spec/models/user.rb
CHANGED
@@ -11,7 +11,7 @@ class User
|
|
11
11
|
field :locale
|
12
12
|
|
13
13
|
belongs_to :site, :inverse_of => :users
|
14
|
-
has_many :articles, :foreign_key => :author_id
|
14
|
+
has_many :articles, :foreign_key => :author_id, :order => :title
|
15
15
|
has_many :comments, :dependent => :destroy, :autosave => true
|
16
16
|
has_and_belongs_to_many :children, :class_name => "User"
|
17
17
|
has_one :record, :autobuild => true
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Associations" do
|
4
4
|
describe User do
|
5
|
-
it { should have_many(:articles).with_foreign_key(:author_id) }
|
5
|
+
it { should have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
|
6
6
|
|
7
7
|
it { should have_one(:record).with_autobuild }
|
8
8
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -129,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
segments:
|
131
131
|
- 0
|
132
|
-
hash:
|
132
|
+
hash: 4081406614009892373
|
133
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
134
|
none: false
|
135
135
|
requirements:
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
segments:
|
140
140
|
- 0
|
141
|
-
hash:
|
141
|
+
hash: 4081406614009892373
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project: mongoid-rspec
|
144
144
|
rubygems_version: 1.8.25
|