mongoid-rspec 1.4.4 → 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.2
1
+ rvm use --create 1.9.3@mongoid-rspec
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7 # (current default)
3
+ - 1.9.2
4
+ - rbx
5
+ - rbx-2.0
6
+ - ree
7
+ - jruby
8
+ - ruby-head
data/README.md CHANGED
@@ -6,13 +6,10 @@ RSpec matchers for Mongoid.
6
6
  Association Matchers
7
7
  -
8
8
  describe User do
9
- it { should reference_many(:articles).with_foreign_key(:author_id) }
10
9
  it { should have_many(:articles).with_foreign_key(:author_id) }
11
10
 
12
- it { should reference_one(:record) }
13
11
  it { should have_one(:record) }
14
12
 
15
- it { should reference_many :comments }
16
13
  it { should have_many :comments }
17
14
 
18
15
  #can also specify with_dependent to test if :dependent => :destroy/:destroy_all/:delete is set
@@ -21,9 +18,9 @@ Association Matchers
21
18
  it { should have_many(:comments).with_autosave }
22
19
 
23
20
  it { should embed_one :profile }
24
-
25
- it { should reference_and_be_referenced_in_many(:children).of_type(User) }
26
- it { should have_and_belong_to_many(:children) }
21
+
22
+ it { should have_and_belong_to_many(:children) }
23
+ it { should have_and_belong_to_many(:children).of_type(User) }
27
24
  end
28
25
 
29
26
  describe Profile do
@@ -31,18 +28,18 @@ Association Matchers
31
28
  end
32
29
 
33
30
  describe Article do
34
- it { should be_referenced_in(:author).of_type(User).as_inverse_of(:articles) }
35
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 }
36
33
  it { should embed_many(:comments) }
37
34
  end
38
35
 
39
36
  describe Comment do
40
37
  it { should be_embedded_in(:article).as_inverse_of(:comments) }
41
- it { should be_referenced_in(:user).as_inverse_of(:comments) }
38
+ it { should belong_to(:user).as_inverse_of(:comments) }
42
39
  end
43
40
 
44
41
  describe Record do
45
- it { should be_referenced_in(:user).as_inverse_of(:record) }
42
+ it { should belong_to(:user).as_inverse_of(:record) }
46
43
  end
47
44
 
48
45
  Validation Matchers
@@ -53,14 +50,20 @@ Validation Matchers
53
50
  end
54
51
 
55
52
  describe User do
56
- it { should validate_presence_of(:login) }
57
- it { should validate_uniqueness_of(:login).scoped_to(:site) }
58
- it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
59
- it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
60
- it { should validate_associated(:profile) }
61
- it { should validate_inclusion_of(:role).to_allow("admin", "member") }
62
- it { should validate_confirmation_of(:email) }
63
- end
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
64
67
 
65
68
  describe Article do
66
69
  it { should validate_length_of(:title).within(8..16) }
@@ -82,12 +85,16 @@ Others
82
85
  it { should have_field(:active).of_type(Boolean).with_default_value_of(false) }
83
86
  it { should have_fields(:birthdate, :registered_at).of_type(DateTime) }
84
87
 
88
+ it { should have_index_for(:last_name) }
89
+ it { should have_index_for(:email).with_options(:unique => true) }
90
+
85
91
  # useful if you use factory_girl and have Factory(:user) defined for User
86
92
  it { should save }
87
93
 
88
94
  it { should be_timestamped_document } # if you're declaring `include Mongoid::Timestamps`
89
95
  it { should be_versioned_document } # if you're declaring `include Mongoid::Versioning`
90
96
  it { should be_paranoid_document } # if you're declaring `include Mongoid::Paranoia`
97
+ it { should be_multiparameted_document } # if you're declaring `include Mongoid::MultiParameterAttributes`
91
98
  end
92
99
 
93
100
  describe Log do
@@ -110,4 +117,4 @@ Acknowledgement
110
117
  -
111
118
  Thanks to [Durran Jordan](https://github.com/durran) for providing the changes necessary to make
112
119
  this compatible with mongoid 2.0.0.rc, and for other [contributors](https://github.com/evansagge/mongoid-rspec/contributors)
113
- to this project.
120
+ to this project.
data/Rakefile CHANGED
@@ -4,16 +4,14 @@ require 'bundler'
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
6
  require 'rspec/core/rake_task'
7
- RSpec::Core::RakeTask.new(:spec)
8
7
 
9
8
  task :default => :spec
10
- task :test => :spec
11
9
 
12
- require 'rake/rdoctask'
13
- require "mongoid-rspec/version"
14
- Rake::RDocTask.new do |rdoc|
15
- rdoc.rdoc_dir = 'rdoc'
16
- rdoc.title = "mongoid-rspec #{Mongoid::Rspec::VERSION}"
17
- rdoc.rdoc_files.include('README*')
18
- rdoc.rdoc_files.include('lib/**/*.rb')
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ spec.pattern = "./spec/**/*_spec.rb"
12
+ end
13
+
14
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
15
+ spec.pattern = "./spec/**/*_spec.rb"
16
+ spec.rcov = true
19
17
  end
@@ -38,19 +38,25 @@ module Mongoid
38
38
  @expectation_message << " which is an inverse of #{@association[:inverse_of].inspect}"
39
39
  self
40
40
  end
41
-
41
+
42
42
  def with_dependent(method_name)
43
- @association[:dependent] = method_name
43
+ @association[:dependent] = method_name
44
44
  @expectation_message << " which specifies dependent as #{@association[:dependent].to_s}"
45
45
  self
46
46
  end
47
47
 
48
48
  def with_autosave
49
- @association[:autosave] = true
49
+ @association[:autosave] = true
50
50
  @expectation_message << " which specifies autosave as #{@association[:autosave].to_s}"
51
51
  self
52
52
  end
53
-
53
+
54
+ def with_index
55
+ @association[:index] = true
56
+ @expectation_message << " which specifies index as #{@association[:index].to_s}"
57
+ self
58
+ end
59
+
54
60
  def stored_as(store_as)
55
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"
56
62
  end
@@ -113,7 +119,16 @@ module Mongoid
113
119
  @positive_result_message = "#{@positive_result_message} which set autosave"
114
120
  end
115
121
  end
116
-
122
+
123
+ if @association[:index]
124
+ if metadata.index != true
125
+ @negative_result_message = "#{@positive_result_message} which did not set index"
126
+ return false
127
+ else
128
+ @positive_result_message = "#{@positive_result_message} which set index"
129
+ end
130
+ end
131
+
117
132
  if @association[:foreign_key]
118
133
  if metadata.foreign_key != @association[:foreign_key]
119
134
  @negative_result_message = "#{@positive_result_message} with foreign key #{metadata.foreign_key.inspect}"
@@ -176,24 +191,20 @@ module Mongoid
176
191
  def have_one_related(association_name)
177
192
  HaveAssociationMatcher.new(association_name, HAS_ONE)
178
193
  end
179
- alias :reference_one :have_one_related
180
194
  alias :have_one :have_one_related
181
195
 
182
196
  def have_many_related(association_name)
183
197
  HaveAssociationMatcher.new(association_name, HAS_MANY)
184
198
  end
185
- alias :reference_many :have_many_related
186
199
  alias :have_many :have_many_related
187
200
 
188
201
  def have_and_belong_to_many(association_name)
189
202
  HaveAssociationMatcher.new(association_name, HAS_AND_BELONGS_TO_MANY)
190
203
  end
191
- alias :reference_and_be_referenced_in_many :have_and_belong_to_many
192
204
 
193
205
  def belong_to_related(association_name)
194
206
  HaveAssociationMatcher.new(association_name, BELONGS_TO)
195
207
  end
196
- alias :be_referenced_in :belong_to_related
197
208
  alias :belong_to :belong_to_related
198
209
  end
199
210
  end
@@ -24,9 +24,9 @@ module Mongoid
24
24
  if @type and @klass.fields[attr].type != @type
25
25
  error << " of type #{@klass.fields[attr].type}"
26
26
  end
27
-
28
- if !@default.nil? and !@klass.fields[attr].default.nil? and @klass.fields[attr].default != @default
29
- error << " with default value of #{@klass.fields[attr].default}"
27
+
28
+ if !@default.nil? and !@klass.fields[attr].default_val.nil? and @klass.fields[attr].default_val != @default
29
+ error << " with default value of #{@klass.fields[attr].default_val}"
30
30
  end
31
31
 
32
32
  @errors.push("field #{attr.inspect}" << error) unless error.blank?
@@ -74,38 +74,48 @@ RSpec::Matchers.define :be_mongoid_document do
74
74
  match do |doc|
75
75
  doc.class.included_modules.include?(Mongoid::Document)
76
76
  end
77
-
77
+
78
78
  description do
79
79
  "be a Mongoid document"
80
- end
80
+ end
81
81
  end
82
82
 
83
83
  RSpec::Matchers.define :be_versioned_document do
84
84
  match do |doc|
85
85
  doc.class.included_modules.include?(Mongoid::Versioning)
86
86
  end
87
-
87
+
88
88
  description do
89
89
  "be a versioned Mongoid document"
90
- end
90
+ end
91
91
  end
92
92
 
93
93
  RSpec::Matchers.define :be_timestamped_document do
94
94
  match do |doc|
95
95
  doc.class.included_modules.include?(Mongoid::Timestamps)
96
96
  end
97
-
97
+
98
98
  description do
99
99
  "be a timestamped Mongoid document"
100
- end
100
+ end
101
101
  end
102
102
 
103
103
  RSpec::Matchers.define :be_paranoid_document do
104
104
  match do |doc|
105
105
  doc.class.included_modules.include?(Mongoid::Paranoia)
106
106
  end
107
-
107
+
108
108
  description do
109
109
  "be a paranoid Mongoid document"
110
- end
110
+ end
111
+ end
112
+
113
+ RSpec::Matchers.define :be_multiparameted_document do
114
+ match do |doc|
115
+ doc.class.included_modules.include?(Mongoid::MultiParameterAttributes)
116
+ end
117
+
118
+ description do
119
+ "be a multiparameted Mongoid document"
120
+ end
111
121
  end
@@ -0,0 +1,51 @@
1
+ module Mongoid
2
+ module Matchers
3
+ class HaveIndexForMatcher # :nodoc:
4
+ def initialize(index_fields)
5
+ @index_fields = index_fields
6
+ end
7
+
8
+ def with_options(options = {})
9
+ @options = options
10
+ self
11
+ end
12
+
13
+ def matches?(klass)
14
+ @klass = klass.is_a?(Class) ? klass : klass.class
15
+ @errors = []
16
+
17
+ unless @klass.index_options[@index_fields]
18
+ @errors.push "no index for #{@index_fields}"
19
+ else
20
+ if !@options.nil? && !@options.empty?
21
+ @options.each do |option, option_value|
22
+ if @klass.index_options[@index_fields].include?(option) && @klass.index_options[@index_fields][option] != option_value
23
+ @errors.push "index for #{@index_fields.inspect} with options of #{@klass.index_options[@index_fields].inspect}"
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ @errors.empty?
30
+ end
31
+
32
+ def failure_message_for_should
33
+ "Expected #{@klass.inspect} to #{description}, got #{@errors.to_sentence}"
34
+ end
35
+
36
+ def failure_message_for_should_not
37
+ "Expected #{@klass.inspect} to not #{description}, got #{@klass.inspect} to #{description}"
38
+ end
39
+
40
+ def description
41
+ desc = "have an index for #{@index_fields.inspect}"
42
+ desc << " with options of #{@options.inspect}" if @options
43
+ desc
44
+ end
45
+ end
46
+
47
+ def have_index_for(index_fields)
48
+ HaveIndexForMatcher.new(index_fields)
49
+ end
50
+ end
51
+ end
@@ -7,12 +7,13 @@ module Mongoid
7
7
  def initialize(field, validation_type)
8
8
  @field = field.to_s
9
9
  @type = validation_type.to_s
10
+ @options = {}
10
11
  end
11
12
 
12
13
  def matches?(actual)
13
14
  @klass = actual.is_a?(Class) ? actual : actual.class
14
15
 
15
- @validator = @klass.validators_on(@field).detect{|v| v.kind.to_s == @type }
16
+ @validator = @klass.validators_on(@field).detect{|v| v.kind.to_s == @type}
16
17
 
17
18
  if @validator
18
19
  @negative_result_message = "#{@type.inspect} validator on #{@field.inspect}"
@@ -21,8 +22,9 @@ module Mongoid
21
22
  @negative_result_message = "no #{@type.inspect} validator on #{@field.inspect}"
22
23
  return false
23
24
  end
24
-
25
- true
25
+ @result = true
26
+ check_on if @options[:on]
27
+ @result
26
28
  end
27
29
 
28
30
  def failure_message_for_should
@@ -36,6 +38,21 @@ module Mongoid
36
38
  def description
37
39
  "validate #{@type} of #{@field.inspect}"
38
40
  end
41
+
42
+ def on(*on_method)
43
+ @options[:on] = on_method.flatten
44
+ self
45
+ end
46
+
47
+ def check_on
48
+ message = " on methods: #{@validator.options[:on]}"
49
+ if [@validator.options[:on]].flatten == @options[:on]
50
+ @positive_result_message << message
51
+ else
52
+ @negative_result_message << message
53
+ @result = false
54
+ end
55
+ end
39
56
  end
40
57
  end
41
58
  end
@@ -0,0 +1,9 @@
1
+ module Mongoid
2
+ module Matchers
3
+ module Validations
4
+ def validate_acceptance_of(field)
5
+ HaveValidationMatcher.new(field, :acceptance)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,42 @@
1
+ module Mongoid
2
+ module Matchers
3
+ module Validations
4
+ class ValidateExclusionOfMatcher < HaveValidationMatcher
5
+ def initialize(name)
6
+ super(name, :exclusion)
7
+ end
8
+
9
+ def to_not_allow(*values)
10
+ @not_allowed_values = [values].flatten
11
+ self
12
+ end
13
+
14
+ def matches?(actual)
15
+ return false unless result = super(actual)
16
+
17
+ if @not_allowed_values
18
+ allowed_values = @not_allowed_values - @validator.options[:in]
19
+ if allowed_values.empty?
20
+ @positive_result_message = @positive_result_message << " not allowing all values mentioned"
21
+ else
22
+ @negative_result_message = @negative_result_message << " allowing the following the ff. values: #{allowed_values.inspect}"
23
+ result = false
24
+ end
25
+ end
26
+
27
+ result
28
+ end
29
+
30
+ def description
31
+ options_desc = []
32
+ options_desc << " not allowing the ff. values: #{@not_allowed_values}" if @not_allowed_values
33
+ super << options_desc.to_sentence
34
+ end
35
+ end
36
+
37
+ def validate_exclusion_of(field)
38
+ ValidateExclusionOfMatcher.new(field)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -7,7 +7,7 @@ module Mongoid
7
7
  end
8
8
 
9
9
  def to_allow(*values)
10
- @allowed_values = [values].flatten
10
+ @allowed_values = values.map(&:to_a).flatten
11
11
  self
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ module Mongoid
15
15
  return false unless result = super(actual)
16
16
 
17
17
  if @allowed_values
18
- not_allowed_values = @allowed_values - @validator.options[:in]
18
+ not_allowed_values = @allowed_values - @validator.options[:in].to_a
19
19
  if not_allowed_values.empty?
20
20
  @positive_result_message = @positive_result_message << " allowing all values mentioned"
21
21
  else
@@ -7,7 +7,7 @@ module Mongoid
7
7
  end
8
8
 
9
9
  def scoped_to(*scope)
10
- @scope = [scope].flatten
10
+ @scope = [scope].flatten.map(&:to_sym)
11
11
  self
12
12
  end
13
13
  alias_method :scoped_on, :scoped_to
@@ -59,8 +59,8 @@ module Mongoid
59
59
  end
60
60
 
61
61
  def check_scope
62
- message = "scope to #{@validator.options[:scope]}"
63
- if [@validator.options[:scope]].flatten == @scope
62
+ message = " scope to #{@validator.options[:scope]}"
63
+ if [@validator.options[:scope]].flatten.map(&:to_sym) == @scope
64
64
  @positive_result_message << message
65
65
  else
66
66
  @negative_result_message << message
@@ -5,15 +5,18 @@ require 'rspec'
5
5
  require 'matchers/document'
6
6
  require 'matchers/associations'
7
7
  require 'matchers/collections'
8
+ require 'matchers/indexes'
8
9
  require 'matchers/validations'
9
10
  require 'matchers/validations/associated'
10
11
  require 'matchers/validations/confirmation_of'
12
+ require 'matchers/validations/exclusion_of'
11
13
  require 'matchers/validations/format_of'
12
14
  require 'matchers/validations/inclusion_of'
13
15
  require 'matchers/validations/length_of'
14
16
  require 'matchers/validations/numericality_of'
15
17
  require 'matchers/validations/presence_of'
16
18
  require 'matchers/validations/uniqueness_of'
19
+ require 'matchers/validations/acceptance_of'
17
20
 
18
21
  module Mongoid
19
22
  module Matchers
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Rspec
3
- VERSION = "1.4.4"
3
+ VERSION = "1.4.5"
4
4
  end
5
5
  end
@@ -6,19 +6,20 @@ Gem::Specification.new do |s|
6
6
  s.name = "mongoid-rspec"
7
7
  s.version = Mongoid::Rspec::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Evan Sagge"]
10
- s.email = %q{evansagge@gmail.com}
11
- s.homepage = %q{http://github.com/evansagge/mongoid-rspec}
12
- s.summary = %q{RSpec matchers for Mongoid}
9
+ s.authors = ["Evan Sagge"]
10
+ s.email = %q{evansagge@gmail.com}
11
+ s.homepage = %q{http://github.com/evansagge/mongoid-rspec}
12
+ s.summary = %q{RSpec matchers for Mongoid}
13
13
  s.description = %q{RSpec matches for Mongoid models, including association and validation matchers}
14
-
14
+
15
15
  s.rubyforge_project = "mongoid-rspec"
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
-
22
- s.add_runtime_dependency(%q<mongoid>, ["~> 2.0"])
23
- s.add_runtime_dependency(%q<rspec>, ["~> 2"])
24
- end
21
+
22
+ s.add_dependency 'rake'
23
+ s.add_dependency 'mongoid', '>= 2.4.6'
24
+ s.add_dependency 'rspec', '>= 2.9'
25
+ end
@@ -3,18 +3,21 @@ class Article
3
3
  include Mongoid::Timestamps
4
4
  include Mongoid::Paranoia
5
5
  include Mongoid::Versioning
6
-
6
+ include Mongoid::MultiParameterAttributes
7
+
7
8
  field :title
8
9
  field :content
9
10
  field :published, :type => Boolean, :default => false
10
11
  field :allow_comments, :type => Boolean, :default => true
11
-
12
+
12
13
  embeds_many :comments
13
14
  embeds_one :permalink
14
- referenced_in :author, :class_name => 'User', :inverse_of => :articles
15
-
15
+ belongs_to :author, :class_name => 'User', :inverse_of => :articles, :index => true
16
+
16
17
  validates :title, :presence => true
17
-
18
+
18
19
  validates_length_of :title, :minimum => 8, :maximum => 16
19
- end
20
-
20
+
21
+ index :title, :unique => true, :background => true
22
+ index :published
23
+ end
@@ -2,5 +2,5 @@ class Comment
2
2
  include Mongoid::Document
3
3
 
4
4
  embedded_in :article, :inverse_of => :comments
5
- referenced_in :user, :inverse_of => :comments
5
+ belongs_to :user, :inverse_of => :comments
6
6
  end
@@ -1,5 +1,5 @@
1
1
  class MovieArticle < Article
2
- field :rating, :type => Numeric
2
+ field :rating, :type => Float
3
3
  field :classification, :type => Integer
4
4
 
5
5
  validates_numericality_of :rating, :greater_than => 0, :less_than_or_equal_to => 5
@@ -8,4 +8,12 @@ class Profile
8
8
  embedded_in :user, :inverse_of => :profile
9
9
 
10
10
  validates_numericality_of :age, :greater_than => 0
11
- end
11
+ validates_acceptance_of :terms_of_service
12
+
13
+ index(
14
+ [
15
+ [ :first_name, Mongo::ASCENDING ],
16
+ [ :last_name, Mongo::ASCENDING ]
17
+ ]
18
+ )
19
+ end
@@ -1,5 +1,5 @@
1
1
  class Record
2
2
  include Mongoid::Document
3
-
4
- referenced_in :user, :inverse_of => :record
5
- end
3
+
4
+ belongs_to :user, :inverse_of => :record
5
+ end
@@ -1,10 +1,10 @@
1
1
  class Site
2
2
  include Mongoid::Document
3
-
3
+
4
4
  field :name
5
-
6
- references_many :users, :inverse_of => :site
7
-
5
+
6
+ has_many :users, :inverse_of => :site
7
+
8
8
  validates :name, :presence => true, :uniqueness => true
9
-
9
+
10
10
  end
@@ -4,19 +4,23 @@ class User
4
4
  field :login
5
5
  field :email
6
6
  field :role
7
+ field :age, type: Integer
8
+ field :password, type: String
7
9
 
8
- referenced_in :site, :inverse_of => :users
9
- references_many :articles, :foreign_key => :author_id
10
- references_many :comments, :dependent => :destroy, :autosave => true
11
- references_and_referenced_in_many :children, :class_name => "User"
12
- references_one :record
10
+ belongs_to :site, :inverse_of => :users
11
+ has_many :articles, :foreign_key => :author_id
12
+ has_many :comments, :dependent => :destroy, :autosave => true
13
+ has_and_belongs_to_many :children, :class_name => "User"
14
+ has_one :record
13
15
 
14
16
  embeds_one :profile
15
17
 
16
- validates :login, :presence => true, :uniqueness => { :scope => :site }, :format => { :with => /^[\w\-]+$/ }
18
+ validates :login, :presence => true, :uniqueness => { :scope => :site }, :format => { :with => /^[\w\-]+$/ }, :exclusion => { :in => ["super", "index", "edit"]}
17
19
  validates :email, :uniqueness => { :case_sensitive => false, :scope => :site, :message => "is already taken" }, :confirmation => true
18
- validates :role, :presence => true, :inclusion => { :in => ["admin", "moderator", "member"]}
20
+ validates :role, :presence => true, :inclusion => { :in => ["admin", "moderator", "member"]}
19
21
  validates :profile, :presence => true, :associated => true
22
+ validates :age, :presence => true, :numericality => true, :inclusion => { :in => 23..42 }, :on => [:create, :update]
23
+ validates :password, :presence => true, :on => :create
20
24
 
21
25
  def admin?
22
26
  false
@@ -2,19 +2,15 @@ require 'spec_helper'
2
2
 
3
3
  describe "Associations" do
4
4
  describe User do
5
- it { should reference_many(:articles).with_foreign_key(:author_id) }
6
5
  it { should have_many(:articles).with_foreign_key(:author_id) }
7
-
8
- it { should reference_one(:record) }
9
- it { should have_one(:record) }
10
-
11
- it { should reference_many(:comments).with_dependent(:destroy).with_autosave }
6
+
7
+ it { should have_one(:record) }
8
+
12
9
  it { should have_many(:comments).with_dependent(:destroy).with_autosave }
13
-
10
+
14
11
  it { should embed_one :profile }
15
-
16
- it { should reference_and_be_referenced_in_many(:children).of_type(User) }
17
- it { should have_and_belong_to_many(:children) }
12
+
13
+ it { should have_and_belong_to_many(:children).of_type(User) }
18
14
  end
19
15
 
20
16
  describe Profile do
@@ -22,19 +18,18 @@ describe "Associations" do
22
18
  end
23
19
 
24
20
  describe Article do
25
- it { should be_referenced_in(:author).of_type(User).as_inverse_of(:articles) }
26
- it { should belong_to(:author).of_type(User).as_inverse_of(:articles) }
21
+ it { should belong_to(:author).of_type(User).as_inverse_of(:articles).with_index }
27
22
  it { should embed_many(:comments) }
28
- it { should embed_one(:permalink) }
23
+ it { should embed_one(:permalink) }
29
24
  end
30
25
 
31
26
  describe Comment do
32
27
  it { should be_embedded_in(:article).as_inverse_of(:comments) }
33
- it { should be_referenced_in(:user).as_inverse_of(:comments) }
28
+ it { should belong_to(:user).as_inverse_of(:comments) }
34
29
  end
35
-
30
+
36
31
  describe Record do
37
- it { should be_referenced_in(:user).as_inverse_of(:record) }
32
+ it { should belong_to(:user).as_inverse_of(:record) }
38
33
  end
39
34
 
40
35
  describe Permalink do
@@ -42,6 +37,6 @@ describe "Associations" do
42
37
  end
43
38
 
44
39
  describe Site do
45
- it { should reference_many(:users).as_inverse_of(:site) }
40
+ it { should have_many(:users).as_inverse_of(:site) }
46
41
  end
47
42
  end
@@ -16,5 +16,6 @@ describe "Document" do
16
16
  it { should be_versioned_document }
17
17
  it { should be_timestamped_document }
18
18
  it { should be_paranoid_document }
19
+ it { should be_multiparameted_document }
19
20
  end
20
- end
21
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Indexes" do
4
+ describe Article do
5
+ it { should have_index_for(:published) }
6
+ it { should have_index_for(:title).with_options(:unique => true, :background => true) }
7
+ end
8
+
9
+ describe Profile do
10
+ it { should have_index_for([ [ :first_name, Mongo::ASCENDING ], [ :last_name, Mongo::ASCENDING ] ]) }
11
+ end
12
+ end
@@ -12,12 +12,18 @@ describe "Validations" do
12
12
  it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
13
13
  it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
14
14
  it { should validate_associated(:profile) }
15
+ it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
15
16
  it { should validate_inclusion_of(:role).to_allow("admin", "member") }
16
17
  it { should validate_confirmation_of(:email) }
18
+ it { should validate_presence_of(:age).on(:create, :update) }
19
+ it { should validate_numericality_of(:age).on(:create, :update) }
20
+ it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
21
+ it { should validate_presence_of(:password).on(:create) }
17
22
  end
18
23
 
19
24
  describe Profile do
20
25
  it { should validate_numericality_of(:age).greater_than(0) }
26
+ it { should validate_acceptance_of(:terms_of_service) }
21
27
  end
22
28
 
23
29
  describe Article do
@@ -27,6 +33,6 @@ describe "Validations" do
27
33
  describe MovieArticle do
28
34
  it { should validate_numericality_of(:rating).greater_than(0) }
29
35
  it { should validate_numericality_of(:rating).to_allow(:greater_than => 0).less_than_or_equal_to(5) }
30
- it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
36
+ it { should validate_numericality_of(:classification).to_allow(:even => true, :only_integer => true, :nil => false) }
31
37
  end
32
38
  end
metadata CHANGED
@@ -1,63 +1,74 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mongoid-rspec
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.5
4
5
  prerelease:
5
- version: 1.4.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Evan Sagge
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-02 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: mongoid
12
+ date: 2012-05-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70235030173460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
17
23
  prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: *70235030173460
25
+ - !ruby/object:Gem::Dependency
26
+ name: mongoid
27
+ requirement: &70235030172800 !ruby/object:Gem::Requirement
19
28
  none: false
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: "2.0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.4.6
24
33
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
34
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: *70235030172800
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70235030172220 !ruby/object:Gem::Requirement
30
39
  none: false
31
- requirements:
32
- - - ~>
33
- - !ruby/object:Gem::Version
34
- version: "2"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '2.9'
35
44
  type: :runtime
36
- version_requirements: *id002
37
- description: RSpec matches for Mongoid models, including association and validation matchers
45
+ prerelease: false
46
+ version_requirements: *70235030172220
47
+ description: RSpec matches for Mongoid models, including association and validation
48
+ matchers
38
49
  email: evansagge@gmail.com
39
50
  executables: []
40
-
41
51
  extensions: []
42
-
43
52
  extra_rdoc_files: []
44
-
45
- files:
53
+ files:
46
54
  - .bundle/config
47
55
  - .document
48
56
  - .gitignore
49
57
  - .rvmrc
58
+ - .travis.yml
50
59
  - Gemfile
51
- - Gemfile.lock
52
60
  - LICENSE
53
61
  - README.md
54
62
  - Rakefile
55
63
  - lib/matchers/associations.rb
56
64
  - lib/matchers/collections.rb
57
65
  - lib/matchers/document.rb
66
+ - lib/matchers/indexes.rb
58
67
  - lib/matchers/validations.rb
68
+ - lib/matchers/validations/acceptance_of.rb
59
69
  - lib/matchers/validations/associated.rb
60
70
  - lib/matchers/validations/confirmation_of.rb
71
+ - lib/matchers/validations/exclusion_of.rb
61
72
  - lib/matchers/validations/format_of.rb
62
73
  - lib/matchers/validations/inclusion_of.rb
63
74
  - lib/matchers/validations/length_of.rb
@@ -80,35 +91,33 @@ files:
80
91
  - spec/unit/associations_spec.rb
81
92
  - spec/unit/collections_spec.rb
82
93
  - spec/unit/document_spec.rb
94
+ - spec/unit/indexes_spec.rb
83
95
  - spec/unit/validations_spec.rb
84
96
  homepage: http://github.com/evansagge/mongoid-rspec
85
97
  licenses: []
86
-
87
98
  post_install_message:
88
99
  rdoc_options: []
89
-
90
- require_paths:
100
+ require_paths:
91
101
  - lib
92
- required_ruby_version: !ruby/object:Gem::Requirement
102
+ required_ruby_version: !ruby/object:Gem::Requirement
93
103
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: "0"
98
- required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
109
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: "0"
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
104
114
  requirements: []
105
-
106
115
  rubyforge_project: mongoid-rspec
107
- rubygems_version: 1.8.5
116
+ rubygems_version: 1.8.10
108
117
  signing_key:
109
118
  specification_version: 3
110
119
  summary: RSpec matchers for Mongoid
111
- test_files:
120
+ test_files:
112
121
  - spec/models/article.rb
113
122
  - spec/models/comment.rb
114
123
  - spec/models/log.rb
@@ -122,4 +131,5 @@ test_files:
122
131
  - spec/unit/associations_spec.rb
123
132
  - spec/unit/collections_spec.rb
124
133
  - spec/unit/document_spec.rb
134
+ - spec/unit/indexes_spec.rb
125
135
  - spec/unit/validations_spec.rb