mongoid-rspec 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,6 +17,8 @@ Association Matchers
17
17
 
18
18
  #can also specify with_dependent to test if :dependent => :destroy/:destroy_all/:delete is set
19
19
  it { should have_many(:comments).with_dependent(:destroy) }
20
+ #can verify autosave is set to true
21
+ it { should have_many(:comments).with_autosave }
20
22
 
21
23
  it { should embed_one :profile }
22
24
 
@@ -33,7 +33,7 @@ module Mongoid
33
33
  end
34
34
 
35
35
  def as_inverse_of(association_inverse_name)
36
- raise "#{@association[:type].inspect} does not respond to :inverse_of" unless [BELONGS_TO, EMBEDDED_IN].include?(@association[:type])
36
+ raise "#{@association[:type].inspect} does not respond to :inverse_of" unless [HAS_MANY, HAS_AND_BELONGS_TO_MANY, BELONGS_TO, EMBEDDED_IN].include?(@association[:type])
37
37
  @association[:inverse_of] = association_inverse_name.to_s
38
38
  @expectation_message << " which is an inverse of #{@association[:inverse_of].inspect}"
39
39
  self
@@ -44,6 +44,12 @@ module Mongoid
44
44
  @expectation_message << " which specifies dependent as #{@association[:dependent].to_s}"
45
45
  self
46
46
  end
47
+
48
+ def with_autosave
49
+ @association[:autosave] = true
50
+ @expectation_message << " which specifies autosave as #{@association[:autosave].to_s}"
51
+ self
52
+ end
47
53
 
48
54
  def stored_as(store_as)
49
55
  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"
@@ -98,6 +104,15 @@ module Mongoid
98
104
  @positive_result_message = "#{@positive_result_message} which specified dependent as #{metadata.dependent}"
99
105
  end
100
106
  end
107
+
108
+ if @association[:autosave]
109
+ if metadata.autosave != true
110
+ @negative_result_message = "#{@positive_result_message} which did not set autosave"
111
+ return false
112
+ else
113
+ @positive_result_message = "#{@positive_result_message} which set autosave"
114
+ end
115
+ end
101
116
 
102
117
  if @association[:foreign_key]
103
118
  if metadata.foreign_key != @association[:foreign_key]
@@ -72,24 +72,40 @@ end
72
72
 
73
73
  RSpec::Matchers.define :be_mongoid_document do
74
74
  match do |doc|
75
- doc.class.included_modules.should include(Mongoid::Document)
75
+ doc.class.included_modules.include?(Mongoid::Document)
76
76
  end
77
+
78
+ description do
79
+ "be a Mongoid document"
80
+ end
77
81
  end
78
82
 
79
83
  RSpec::Matchers.define :be_versioned_document do
80
84
  match do |doc|
81
- doc.class.included_modules.should include(Mongoid::Versioning)
85
+ doc.class.included_modules.include?(Mongoid::Versioning)
82
86
  end
87
+
88
+ description do
89
+ "be a versioned Mongoid document"
90
+ end
83
91
  end
84
92
 
85
93
  RSpec::Matchers.define :be_timestamped_document do
86
94
  match do |doc|
87
- doc.class.included_modules.should include(Mongoid::Timestamps)
95
+ doc.class.included_modules.include?(Mongoid::Timestamps)
88
96
  end
97
+
98
+ description do
99
+ "be a timestamped Mongoid document"
100
+ end
89
101
  end
90
102
 
91
103
  RSpec::Matchers.define :be_paranoid_document do
92
104
  match do |doc|
93
- doc.class.included_modules.should include(Mongoid::Paranoia)
105
+ doc.class.included_modules.include?(Mongoid::Paranoia)
94
106
  end
107
+
108
+ description do
109
+ "be a paranoid Mongoid document"
110
+ end
95
111
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Rspec
3
- VERSION = "1.4.2"
3
+ VERSION = "1.4.3"
4
4
  end
5
5
  end
@@ -1,5 +1,8 @@
1
1
  class Article
2
2
  include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+ include Mongoid::Paranoia
5
+ include Mongoid::Versioning
3
6
 
4
7
  field :title
5
8
  field :content
data/spec/models/user.rb CHANGED
@@ -7,7 +7,7 @@ class User
7
7
 
8
8
  referenced_in :site, :inverse_of => :users
9
9
  references_many :articles, :foreign_key => :author_id
10
- references_many :comments, :dependent => :destroy
10
+ references_many :comments, :dependent => :destroy, :autosave => true
11
11
  references_and_referenced_in_many :children, :class_name => "User"
12
12
  references_one :record
13
13
 
@@ -8,8 +8,8 @@ describe "Associations" do
8
8
  it { should reference_one(:record) }
9
9
  it { should have_one(:record) }
10
10
 
11
- it { should reference_many(:comments).with_dependent(:destroy) }
12
- it { should have_many(:comments).with_dependent(:destroy) }
11
+ it { should reference_many(:comments).with_dependent(:destroy).with_autosave }
12
+ it { should have_many(:comments).with_dependent(:destroy).with_autosave }
13
13
 
14
14
  it { should embed_one :profile }
15
15
 
@@ -39,4 +39,8 @@ describe "Associations" do
39
39
  describe Permalink do
40
40
  it { should be_embedded_in(:linkable).as_inverse_of(:link) }
41
41
  end
42
+
43
+ describe Site do
44
+ it { should reference_many(:users).as_inverse_of(:site) }
45
+ end
42
46
  end
@@ -7,5 +7,12 @@ describe "Document" do
7
7
 
8
8
  describe Article do
9
9
  it { should have_field(:published).of_type(Boolean).with_default_value_of(false) }
10
- end
10
+ end
11
+
12
+ describe Article do
13
+ it { should be_mongoid_document }
14
+ it { should be_versioned_document }
15
+ it { should be_timestamped_document }
16
+ it { should be_paranoid_document }
17
+ end
11
18
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongoid-rspec
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.4.2
5
+ version: 1.4.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Evan Sagge
@@ -10,8 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-23 00:00:00 +08:00
14
- default_executable:
13
+ date: 2011-06-02 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: mongoid
@@ -82,7 +81,6 @@ files:
82
81
  - spec/unit/collections_spec.rb
83
82
  - spec/unit/document_spec.rb
84
83
  - spec/unit/validations_spec.rb
85
- has_rdoc: true
86
84
  homepage: http://github.com/evansagge/mongoid-rspec
87
85
  licenses: []
88
86
 
@@ -106,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
104
  requirements: []
107
105
 
108
106
  rubyforge_project: mongoid-rspec
109
- rubygems_version: 1.5.2
107
+ rubygems_version: 1.8.5
110
108
  signing_key:
111
109
  specification_version: 3
112
110
  summary: RSpec matchers for Mongoid