mongoid-rspec 1.5.0 → 1.11.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 (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +14 -2
  6. data/README.md +188 -108
  7. data/lib/matchers/accept_nested_attributes.rb +65 -0
  8. data/lib/matchers/associations.rb +124 -22
  9. data/lib/matchers/document.rb +43 -4
  10. data/lib/matchers/indexes.rb +22 -10
  11. data/lib/matchers/validations/acceptance_of.rb +2 -2
  12. data/lib/matchers/validations/associated.rb +5 -5
  13. data/lib/matchers/validations/confirmation_of.rb +2 -2
  14. data/lib/matchers/validations/custom_validation_of.rb +2 -19
  15. data/lib/matchers/validations/exclusion_of.rb +8 -1
  16. data/lib/matchers/validations/format_of.rb +21 -21
  17. data/lib/matchers/validations/inclusion_of.rb +20 -13
  18. data/lib/matchers/validations/length_of.rb +66 -19
  19. data/lib/matchers/validations/numericality_of.rb +10 -10
  20. data/lib/matchers/validations/presence_of.rb +2 -2
  21. data/lib/matchers/validations/uniqueness_of.rb +13 -30
  22. data/lib/matchers/validations/with_message.rb +27 -0
  23. data/lib/matchers/validations.rb +45 -26
  24. data/lib/mongoid-rspec/version.rb +1 -1
  25. data/lib/mongoid-rspec.rb +5 -1
  26. data/mongoid-rspec.gemspec +2 -2
  27. data/spec/models/article.rb +18 -9
  28. data/spec/models/comment.rb +2 -2
  29. data/spec/models/movie_article.rb +6 -5
  30. data/spec/models/permalink.rb +1 -1
  31. data/spec/models/person.rb +0 -3
  32. data/spec/models/profile.rb +9 -7
  33. data/spec/models/record.rb +1 -1
  34. data/spec/models/site.rb +2 -3
  35. data/spec/models/user.rb +20 -12
  36. data/spec/unit/accept_nested_attributes_spec.rb +12 -0
  37. data/spec/unit/allow_mass_assignment_spec.rb +1 -1
  38. data/spec/unit/associations_spec.rb +6 -6
  39. data/spec/unit/document_spec.rb +8 -5
  40. data/spec/unit/indexes_spec.rb +3 -2
  41. data/spec/unit/validations_spec.rb +8 -0
  42. data/spec/validators/ssn_validator.rb +3 -1
  43. metadata +40 -28
  44. data/.rvmrc +0 -1
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90683af43b99f047532aad535c6e43dd6967f95d
4
+ data.tar.gz: 6dc40541b28ba2944e2a28e1db7aac2a1d8f986f
5
+ SHA512:
6
+ metadata.gz: 4600c194356594e38e1ce975412e3a64ae740deaef458adc1f069936254bc2b85c59fffbee44ee6272197affab3a998e8bf76f4d2f62eab7715cdca68e58cb74
7
+ data.tar.gz: fbd39276f0ae7b8bf388c488df939ce343bbeaa25377b79094ff24b8593590e402549681e1290ba857d5a318d4675ca1e7ed3abe449c1cad20c4cd5b5d005350
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  *.gem
2
+ .rvmrc
2
3
  .bundle
3
4
  Gemfile.lock
4
5
  pkg/*
6
+
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ mongoid-rspec
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.0
data/.travis.yml CHANGED
@@ -1,5 +1,17 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
5
- - ruby-head
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - ruby-head
7
+ - jruby-18mode
8
+ - jruby-19mode
9
+ - jruby-head
10
+ - rbx-2.1.1
11
+ - rbx-head
12
+ - ree
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: ruby-head
16
+ - rvm: jruby-head
17
+ - rvm: rbx-head
data/README.md CHANGED
@@ -1,125 +1,205 @@
1
1
  mongoid-rspec
2
2
  =
3
3
 
4
- RSpec matchers for Mongoid.
4
+ [![Build Status](https://secure.travis-ci.org/evansagge/mongoid-rspec.png?branch=master)](https://travis-ci.org/evansagge/mongoid-rspec)
5
+
6
+ http://rubygems.org/gems/mongoid-rspec
7
+
8
+ RSpec matchers for Mongoid 3.x.
9
+
10
+ For Mongoid 2.x, use [mongoid-rspec 1.4.5](http://rubygems.org/gems/mongoid-rspec/versions/1.4.5)
11
+
12
+ Installation
13
+ -
14
+ Add to your Gemfile
15
+
16
+ gem 'mongoid-rspec'
17
+
18
+ Drop in existing or dedicated support file in spec/support (spec/support/mongoid.rb)
19
+
20
+ ```ruby
21
+ RSpec.configure do |config|
22
+ config.include Mongoid::Matchers, type: :model
23
+ end
24
+ ```
5
25
 
6
26
  Association Matchers
7
27
  -
8
- describe User do
9
- it { should have_many(:articles).with_foreign_key(:author_id) }
10
-
11
- it { should have_one(:record) }
12
-
13
- it { should have_many :comments }
14
-
15
- #can also specify with_dependent to test if :dependent => :destroy/:destroy_all/:delete is set
16
- it { should have_many(:comments).with_dependent(:destroy) }
17
- #can verify autosave is set to true
18
- it { should have_many(:comments).with_autosave }
19
-
20
- it { should embed_one :profile }
21
-
22
- it { should have_and_belong_to_many(:children) }
23
- it { should have_and_belong_to_many(:children).of_type(User) }
24
- end
25
-
26
- describe Profile do
27
- it { should be_embedded_in(:user).as_inverse_of(:profile) }
28
- end
29
-
30
- describe Article do
31
- it { should belong_to(:author).of_type(User).as_inverse_of(:articles) }
32
- it { should belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
33
- it { should embed_many(:comments) }
34
- end
35
-
36
- describe Comment do
37
- it { should be_embedded_in(:article).as_inverse_of(:comments) }
38
- it { should belong_to(:user).as_inverse_of(:comments) }
39
- end
40
-
41
- describe Record do
42
- it { should belong_to(:user).as_inverse_of(:record) }
43
- end
28
+
29
+ ```ruby
30
+ describe User do
31
+ it { should have_many(:articles).with_foreign_key(:author_id).ordered_by(:title) }
32
+
33
+ it { should have_one(:record) }
34
+ #can verify autobuild is set to true
35
+ it { should have_one(:record).with_autobuild }
36
+
37
+ it { should have_many :comments }
38
+
39
+ #can also specify with_dependent to test if :dependent => :destroy/:destroy_all/:delete is set
40
+ it { should have_many(:comments).with_dependent(:destroy) }
41
+ #can verify autosave is set to true
42
+ it { should have_many(:comments).with_autosave }
43
+
44
+ it { should embed_one :profile }
45
+
46
+ it { should have_and_belong_to_many(:children) }
47
+ it { should have_and_belong_to_many(:children).of_type(User) }
48
+ end
49
+
50
+ describe Profile do
51
+ it { should be_embedded_in(:user).as_inverse_of(:profile) }
52
+ end
53
+
54
+ describe Article do
55
+ it { should belong_to(:author).of_type(User).as_inverse_of(:articles) }
56
+ it { should belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
57
+ it { should embed_many(:comments) }
58
+ end
59
+
60
+ describe Comment do
61
+ it { should be_embedded_in(:article).as_inverse_of(:comments) }
62
+ it { should belong_to(:user).as_inverse_of(:comments) }
63
+ end
64
+
65
+ describe Record do
66
+ it { should belong_to(:user).as_inverse_of(:record) }
67
+ end
68
+
69
+ describe Site do
70
+ it { should have_many(:users).as_inverse_of(:site).ordered_by(:email.asc) }
71
+ end
72
+ ```
73
+
74
+ Mass Assignment Matcher
75
+ -
76
+
77
+ ```ruby
78
+ describe User do
79
+ it { should allow_mass_assignment_of(:login) }
80
+ it { should allow_mass_assignment_of(:email) }
81
+ it { should allow_mass_assignment_of(:age) }
82
+ it { should allow_mass_assignment_of(:password) }
83
+ it { should allow_mass_assignment_of(:password) }
84
+ it { should allow_mass_assignment_of(:role).as(:admin) }
85
+
86
+ it { should_not allow_mass_assignment_of(:role) }
87
+ end
88
+ ```
44
89
 
45
90
  Validation Matchers
46
91
  -
47
- describe Site do
48
- it { should validate_presence_of(:name) }
49
- it { should validate_uniqueness_of(:name) }
50
- end
51
-
52
- describe User do
53
- it { should validate_presence_of(:login) }
54
- it { should validate_uniqueness_of(:login).scoped_to(:site) }
55
- it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
56
- it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
57
- it { should validate_associated(:profile) }
58
- it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
59
- it { should validate_inclusion_of(:role).to_allow("admin", "member") }
60
- it { should validate_confirmation_of(:email) }
61
- it { should validate_presence_of(:age).on(:create, :update) }
62
- # The on matcher can take var args or an array. Validations do not fail if on is not specified.
63
- it { should validate_numericality_of(:age).on(:create, :update) }
64
- it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
65
- it { should validate_presence_of(:password).on(:create) }
66
- end
67
-
68
- describe Article do
69
- it { should validate_length_of(:title).within(8..16) }
70
- end
71
-
72
- describe Profile do
73
- it { should validate_numericality_of(:age).greater_than(0) }
74
- end
75
-
76
- describe MovieArticle do
77
- it { should validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
78
- it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
79
- end
80
-
81
- describe Person do
82
- # in order to be able to use the custom_validate matcher, the custom validator class (in this case SsnValidator)
83
- # should redefine the kind method to return :custom, i.e. "def self.kind() :custom end"
84
- it { should custom_validate(:ssn).with_validator(SsnValidator) }
85
- end
92
+
93
+ ```ruby
94
+ describe Site do
95
+ it { should validate_presence_of(:name) }
96
+ it { should validate_uniqueness_of(:name) }
97
+ end
98
+
99
+ describe User do
100
+ it { should validate_presence_of(:login) }
101
+ it { should validate_uniqueness_of(:login).scoped_to(:site) }
102
+ it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
103
+ it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
104
+ it { should validate_associated(:profile) }
105
+ it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
106
+ it { should validate_inclusion_of(:role).to_allow("admin", "member") }
107
+ it { should validate_confirmation_of(:email) }
108
+ it { should validate_presence_of(:age).on(:create, :update) }
109
+ it { should validate_numericality_of(:age).on(:create, :update) }
110
+ it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
111
+ it { should validate_presence_of(:password).on(:create) }
112
+ it { should validate_presence_of(:provider_uid).on(:create) }
113
+ it { should validate_inclusion_of(:locale).to_allow([:en, :ru]) }
114
+ end
115
+
116
+ describe Article do
117
+ it { should validate_length_of(:title).within(8..16) }
118
+ end
119
+
120
+ describe Profile do
121
+ it { should validate_numericality_of(:age).greater_than(0) }
122
+ end
123
+
124
+ describe MovieArticle do
125
+ it { should validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
126
+ it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
127
+ end
128
+
129
+ describe Person do
130
+ # in order to be able to use the custom_validate matcher, the custom validator class (in this case SsnValidator)
131
+ # should redefine the kind method to return :custom, i.e. "def self.kind() :custom end"
132
+ it { should custom_validate(:ssn).with_validator(SsnValidator) }
133
+ end
134
+ ```
135
+
136
+ Accepts Nested Attributes Matcher
137
+ -
138
+
139
+ ```ruby
140
+ describe User do
141
+ it { should accept_nested_attributes_for(:articles) }
142
+ it { should accept_nested_attributes_for(:comments) }
143
+ end
144
+
145
+ describe Article do
146
+ it { should accept_nested_attributes_for(:permalink) }
147
+ end
148
+ ```
149
+
150
+ Index Matcher
151
+ -
152
+
153
+ ```ruby
154
+ describe Article do
155
+ it { should have_index_for(published: 1) }
156
+ it { should have_index_for(title: 1).with_options(unique: true, background: true) }
157
+ end
158
+
159
+ describe Profile do
160
+ it { should have_index_for(first_name: 1, last_name: 1) }
161
+ end
162
+ ```
163
+
86
164
  Others
87
165
  -
88
- describe User do
89
- it { should have_fields(:email, :login) }
90
- it { should have_field(:active).of_type(Boolean).with_default_value_of(false) }
91
- it { should have_fields(:birthdate, :registered_at).of_type(DateTime) }
92
-
93
- it { should have_index_for(:last_name) }
94
- it { should have_index_for(:email).with_options(:unique => true) }
95
-
96
- # useful if you use factory_girl and have Factory(:user) defined for User
97
- it { should save }
98
-
99
- it { should be_timestamped_document } # if you're declaring `include Mongoid::Timestamps`
100
- it { should be_versioned_document } # if you're declaring `include Mongoid::Versioning`
101
- it { should be_paranoid_document } # if you're declaring `include Mongoid::Paranoia`
102
- it { should be_multiparameted_document } # if you're declaring `include Mongoid::MultiParameterAttributes`
103
- end
104
-
105
- describe Log do
106
- it { should be_stored_in :logs }
107
- end
108
-
109
- Use
166
+
167
+ ```ruby
168
+ describe User do
169
+ it { should have_fields(:email, :login) }
170
+ it { should have_field(:s).with_alias(:status) }
171
+ it { should have_fields(:birthdate, :registered_at).of_type(DateTime) }
172
+
173
+ # if you're declaring 'include Mongoid::Timestamps'
174
+ # or any of 'include Mongoid::Timestamps::Created' and 'Mongoid::Timestamps::Updated'
175
+ it { should be_timestamped_document }
176
+ it { should be_timestamped_document.with(:created) }
177
+ it { should_not be_timestamped_document.with(:updated) }
178
+
179
+ it { should be_versioned_document } # if you're declaring `include Mongoid::Versioning`
180
+ it { should be_paranoid_document } # if you're declaring `include Mongoid::Paranoia`
181
+ it { should be_multiparameted_document } # if you're declaring `include Mongoid::MultiParameterAttributes`
182
+ end
183
+
184
+ describe Log do
185
+ it { should be_stored_in :logs }
186
+ end
187
+
188
+ describe Article do
189
+ it { should have_field(:published).of_type(Boolean).with_default_value_of(false) }
190
+ it { should have_field(:allow_comments).of_type(Boolean).with_default_value_of(true) }
191
+ it { should_not have_field(:allow_comments).of_type(Boolean).with_default_value_of(false) }
192
+ it { should_not have_field(:number_of_comments).of_type(Integer).with_default_value_of(1) }
193
+ end
194
+ ```
195
+
196
+ Known issues
110
197
  -
111
- add in Gemfile
112
198
 
113
- gem 'mongoid-rspec'
114
-
115
- drop in existing or dedicated support file in spec/support (spec/support/mongoid.rb)
199
+ accept_nested_attributes_for matcher must test options [issue 91](https://github.com/evansagge/mongoid-rspec/issues/91).
116
200
 
117
- RSpec.configure do |configuration|
118
- configuration.include Mongoid::Matchers
119
- end
120
-
121
201
  Acknowledgement
122
202
  -
123
- Thanks to [Durran Jordan](https://github.com/durran) for providing the changes necessary to make
124
- this compatible with mongoid 2.0.0.rc, and for other [contributors](https://github.com/evansagge/mongoid-rspec/contributors)
203
+ Thanks to [Durran Jordan](https://github.com/durran) for providing the changes necessary to make
204
+ this compatible with mongoid 2.0.0.rc, and for other [contributors](https://github.com/evansagge/mongoid-rspec/contributors)
125
205
  to this project.
@@ -0,0 +1,65 @@
1
+ module Mongoid
2
+ module Matchers # :nodoc:
3
+
4
+ # Ensures that the model can accept nested attributes for the specified
5
+ # association.
6
+ #
7
+ # Example:
8
+ # it { should accept_nested_attributes_for(:articles) }
9
+ #
10
+ def accept_nested_attributes_for(attribute)
11
+ AcceptNestedAttributesForMatcher.new(attribute)
12
+ end
13
+
14
+ class AcceptNestedAttributesForMatcher
15
+
16
+ def initialize(attribute)
17
+ @attribute = attribute.to_s
18
+ @options = {}
19
+ end
20
+
21
+ def matches?(subject)
22
+ @subject = subject
23
+ match?
24
+ end
25
+
26
+ def failure_message
27
+ "Expected #{expectation} (#{@problem})"
28
+ end
29
+
30
+ def negative_failure_message
31
+ "Did not expect #{expectation}"
32
+ end
33
+
34
+ def description
35
+ description = "accepts_nested_attributes_for :#{@attribute}"
36
+ end
37
+
38
+ protected
39
+ def match?
40
+ exists?
41
+ end
42
+
43
+ def exists?
44
+ if config
45
+ true
46
+ else
47
+ @problem = 'is not declared'
48
+ false
49
+ end
50
+ end
51
+
52
+ def config
53
+ model_class.nested_attributes["#{@attribute}_attributes"]
54
+ end
55
+
56
+ def model_class
57
+ @subject.class
58
+ end
59
+
60
+ def expectation
61
+ "#{model_class.name} to accept nested attributes for #{@attribute}"
62
+ end
63
+ end
64
+ end
65
+ end
@@ -12,16 +12,11 @@ module Mongoid
12
12
  EMBEDS_ONE = Mongoid::Relations::Embedded::One
13
13
  EMBEDDED_IN = Mongoid::Relations::Embedded::In
14
14
 
15
-
16
15
  class HaveAssociationMatcher
17
16
  def initialize(name, association_type)
18
17
  @association = {}
19
18
  @association[:name] = name.to_s
20
19
  @association[:type] = association_type
21
- # begin
22
- # @association[:class] = name.to_s.classify.constantize
23
- # rescue
24
- # end
25
20
  @expectation_message = "#{type_description} #{@association[:name].inspect}"
26
21
  @expectation_message << " of type #{@association[:class].inspect}" unless @association[:class].nil?
27
22
  end
@@ -39,6 +34,19 @@ module Mongoid
39
34
  self
40
35
  end
41
36
 
37
+ def ordered_by(association_field_name)
38
+ raise "#{@association[:type].inspect} does not respond to :order" unless [HAS_MANY, HAS_AND_BELONGS_TO_MANY, EMBEDS_MANY].include?(@association[:type])
39
+ @association[:order] = association_field_name.to_s
40
+ @expectation_message << " ordered by #{@association[:order].inspect}"
41
+
42
+ if association_field_name.is_a? Origin::Key
43
+ @association[:order_operator] = association_field_name.operator
44
+ @expectation_message << " #{order_way(@association[:order_operator])}"
45
+ end
46
+
47
+ self
48
+ end
49
+
42
50
  def with_dependent(method_name)
43
51
  @association[:dependent] = method_name
44
52
  @expectation_message << " which specifies dependent as #{@association[:dependent].to_s}"
@@ -57,8 +65,34 @@ module Mongoid
57
65
  self
58
66
  end
59
67
 
68
+ def with_autobuild
69
+ @association[:autobuild] = true
70
+ @expectation_message << " which specifies autobuild as #{@association[:autobuild].to_s}"
71
+ self
72
+ end
73
+
74
+ def with_polymorphism
75
+ @association[:polymorphic] = true
76
+ @expectation_message << " which specifies polymorphic as #{@association[:polymorphic].to_s}"
77
+ self
78
+ end
79
+
80
+ def with_cascading_callbacks
81
+ @association[:cascade_callbacks] = true
82
+ @expectation_message << " which specifies cascade_callbacks as #{@association[:cascade_callbacks].to_s}"
83
+ self
84
+ end
85
+
86
+ def cyclic
87
+ @association[:cyclic] = true
88
+ @expectation_message << " which specifies cyclic as #{@association[:cyclic].to_s}"
89
+ self
90
+ end
91
+
60
92
  def stored_as(store_as)
61
- raise NotImplementedError, "`references_many #{@association[:name]} :stored_as => :array` has been removed in Mongoid 2.0.0.rc, use `references_and_referenced_in_many #{@association[:name]}` instead"
93
+ @association[:store_as] = store_as.to_s
94
+ @expectation_message << " which is stored as #{@association[:store_as].inspect}"
95
+ self
62
96
  end
63
97
 
64
98
  def with_foreign_key(foreign_key)
@@ -102,6 +136,24 @@ module Mongoid
102
136
  end
103
137
  end
104
138
 
139
+ if @association[:order]
140
+ if @association[:order].to_s != metadata.order.to_s
141
+ @negative_result_message = "#{@positive_result_message} ordered by #{metadata.order}"
142
+ return false
143
+ else
144
+ @positive_result_message = "#{@positive_result_message} ordered by #{metadata.order}"
145
+ end
146
+ end
147
+
148
+ if @association[:order_operator]
149
+ if @association[:order_operator] != metadata.order.operator
150
+ @negative_result_message = "#{@positive_result_message} #{order_way(@association[:order_operator] * -1)}"
151
+ return false
152
+ else
153
+ @positive_result_message = "#{@positive_result_message} #{order_way(@association[:order_operator])}"
154
+ end
155
+ end
156
+
105
157
  if @association[:dependent]
106
158
  if @association[:dependent].to_s != metadata.dependent.to_s
107
159
  @negative_result_message = "#{@positive_result_message} which specified dependent as #{metadata.dependent}"
@@ -120,6 +172,51 @@ module Mongoid
120
172
  end
121
173
  end
122
174
 
175
+ if @association[:autobuild]
176
+ if metadata.autobuilding? != true
177
+ @negative_result_message = "#{@positive_result_message} which did not set autobuild"
178
+ return false
179
+ else
180
+ @positive_result_message = "#{@positive_result_message} which set autobuild"
181
+ end
182
+ end
183
+
184
+ if @association[:polymorphic]
185
+ if metadata.polymorphic? != true
186
+ @negative_result_message = "#{@positive_result_message} which did not set polymorphic"
187
+ return false
188
+ else
189
+ @positive_result_message = "#{@positive_result_message} which set polymorphic"
190
+ end
191
+ end
192
+
193
+ if @association[:cascade_callbacks]
194
+ if metadata.cascading_callbacks? != true
195
+ @negative_result_message = "#{@positive_result_message} which did not set cascade_callbacks"
196
+ return false
197
+ else
198
+ @positive_result_message = "#{@positive_result_message} which set cascade_callbacks"
199
+ end
200
+ end
201
+
202
+ if @association[:cyclic]
203
+ if metadata.cyclic? != true
204
+ @negative_result_message = "#{@positive_result_message} which did not set cyclic"
205
+ return false
206
+ else
207
+ @positive_result_message = "#{@positive_result_message} which set cyclic"
208
+ end
209
+ end
210
+
211
+ if @association[:store_as]
212
+ if metadata.store_as != @association[:store_as]
213
+ @negative_result_message = "#{@positive_result_message} which is stored as #{metadata.store_as}"
214
+ return false
215
+ else
216
+ @positive_result_message = "#{@positive_result_message} which is stored as #{metadata.store_as}"
217
+ end
218
+ end
219
+
123
220
  if @association[:index]
124
221
  if metadata.index != true
125
222
  @negative_result_message = "#{@positive_result_message} which did not set index"
@@ -156,24 +253,29 @@ module Mongoid
156
253
  def type_description(type = nil, passive = true)
157
254
  type ||= @association[:type]
158
255
  case type.name
159
- when EMBEDS_ONE.name
160
- (passive ? 'embed' : 'embeds') << ' one'
161
- when EMBEDS_MANY.name
162
- (passive ? 'embed' : 'embeds') << ' many'
163
- when EMBEDDED_IN.name
164
- (passive ? 'be' : 'is') << ' embedded in'
165
- when HAS_ONE.name
166
- (passive ? 'reference' : 'references') << ' one'
167
- when HAS_MANY.name
168
- (passive ? 'reference' : 'references') << ' many'
169
- when HAS_AND_BELONGS_TO_MANY.name
170
- (passive ? 'reference' : 'references') << ' and referenced in many'
171
- when BELONGS_TO.name
172
- (passive ? 'be referenced in' : 'referenced in')
173
- else
174
- raise "Unknown association type '%s'" % type
256
+ when EMBEDS_ONE.name
257
+ (passive ? 'embed' : 'embeds') << ' one'
258
+ when EMBEDS_MANY.name
259
+ (passive ? 'embed' : 'embeds') << ' many'
260
+ when EMBEDDED_IN.name
261
+ (passive ? 'be' : 'is') << ' embedded in'
262
+ when HAS_ONE.name
263
+ (passive ? 'reference' : 'references') << ' one'
264
+ when HAS_MANY.name
265
+ (passive ? 'reference' : 'references') << ' many'
266
+ when HAS_AND_BELONGS_TO_MANY.name
267
+ (passive ? 'reference' : 'references') << ' and referenced in many'
268
+ when BELONGS_TO.name
269
+ (passive ? 'be referenced in' : 'referenced in')
270
+ else
271
+ raise "Unknown association type '%s'" % type
175
272
  end
176
273
  end
274
+
275
+ private
276
+ def order_way(operator)
277
+ [nil, "ascending", "descending"][operator]
278
+ end
177
279
  end
178
280
 
179
281
  def embed_one(association_name)