mongo_mapper 0.6.9 → 0.6.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.9
1
+ 0.6.10
@@ -40,6 +40,12 @@ module MongoMapper
40
40
  value
41
41
  end
42
42
 
43
+ if association.one? || association.belongs_to?
44
+ define_method("#{association.name}?") do
45
+ get_proxy(association).present?
46
+ end
47
+ end
48
+
43
49
  if association.options[:dependent] && association.many? && !association.embeddable?
44
50
  after_destroy do |doc|
45
51
  case association.options[:dependent]
@@ -16,25 +16,28 @@ module MongoMapper
16
16
  def replace(doc)
17
17
  load_target
18
18
 
19
- if !@target.nil? && @target != doc
20
- if options[:dependent] && !@target.new?
19
+ if !target.nil? && target != doc
20
+ if options[:dependent] && !target.new?
21
21
  case options[:dependent]
22
22
  when :delete
23
- @target.delete
23
+ target.delete
24
24
  when :destroy
25
- @target.destroy
25
+ target.destroy
26
26
  when :nullify
27
- @target[foreign_key] = nil
28
- @target.save
27
+ target[foreign_key] = nil
28
+ target.save
29
29
  end
30
30
  end
31
31
  end
32
32
 
33
- if doc
33
+ reset
34
+
35
+ unless doc.nil?
34
36
  owner.save if owner.new?
35
37
  doc[foreign_key] = owner.id
36
38
  doc.save if doc.new?
37
- reset
39
+ loaded
40
+ @target = doc
38
41
  end
39
42
  end
40
43
 
@@ -17,7 +17,7 @@ module MongoMapper
17
17
  delegate :collection, :to => :klass
18
18
 
19
19
  def initialize(owner, reflection)
20
- @owner, @reflection = owner, reflection
20
+ @owner, @reflection, @loaded = owner, reflection, false
21
21
  Array(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
22
22
  reset
23
23
  end
@@ -45,6 +45,11 @@ module MongoMapper
45
45
  target.blank?
46
46
  end
47
47
 
48
+ def present?
49
+ load_target
50
+ target.present?
51
+ end
52
+
48
53
  def reload
49
54
  reset
50
55
  load_target
@@ -57,7 +62,7 @@ module MongoMapper
57
62
 
58
63
  def reset
59
64
  @loaded = false
60
- target = nil
65
+ @target = nil
61
66
  end
62
67
 
63
68
  def respond_to?(*args)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_mapper}
8
- s.version = "0.6.9"
8
+ s.version = "0.6.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Nunemaker"]
12
- s.date = %q{2010-01-01}
12
+ s.date = %q{2010-01-02}
13
13
  s.default_executable = %q{mmconsole}
14
14
  s.email = %q{nunemaker@gmail.com}
15
15
  s.executables = ["mmconsole"]
@@ -12,6 +12,14 @@ class BelongsToPolymorphicProxyTest < Test::Unit::TestCase
12
12
  status.target.nil?.should be_true
13
13
  status.target.inspect.should == "nil"
14
14
  end
15
+
16
+ should "have boolean presence method" do
17
+ status = Status.new
18
+ status.target?.should be_false
19
+
20
+ status.target = Project.new(:name => 'mongomapper')
21
+ status.target?.should be_true
22
+ end
15
23
 
16
24
  should "be able to replace the association" do
17
25
  status = Status.new(:name => 'Foo!')
@@ -21,6 +21,14 @@ class BelongsToProxyTest < Test::Unit::TestCase
21
21
  @comment_class.new.post.nil?.should be_true
22
22
  end
23
23
 
24
+ should "have boolean presence method" do
25
+ comment = @comment_class.new(:name => 'Foo!')
26
+ comment.post?.should be_false
27
+
28
+ comment.post = @post_class.new(:name => 'mongomapper')
29
+ comment.post?.should be_true
30
+ end
31
+
24
32
  should "be able to replace the association" do
25
33
  post = @post_class.new(:name => 'mongomapper')
26
34
  comment = @comment_class.new(:name => 'Foo!', :post => post)
@@ -23,13 +23,28 @@ class OneProxyTest < Test::Unit::TestCase
23
23
 
24
24
  should "be able to replace the association" do
25
25
  @post_class.one :author, :class => @author_class
26
+
26
27
  post = @post_class.new
27
- author = @author_class.new
28
+ author = @author_class.new(:name => 'Frank')
28
29
  post.author = author
29
30
  post.reload
30
31
 
31
32
  post.author.should == author
32
33
  post.author.nil?.should be_false
34
+
35
+ new_author = @author_class.new(:name => 'Emily')
36
+ post.author = new_author
37
+ post.author.should == new_author
38
+ end
39
+
40
+ should "have boolean method for testing presence" do
41
+ @post_class.one :author, :class => @author_class
42
+
43
+ post = @post_class.new
44
+ post.author?.should be_false
45
+
46
+ post.author = @author_class.new(:name => 'Frank')
47
+ post.author?.should be_true
33
48
  end
34
49
 
35
50
  should "unset the association" do
@@ -53,6 +53,7 @@ class ProxyTest < Test::Unit::TestCase
53
53
  context "blank?" do
54
54
  should "be true if blank" do
55
55
  @blank_proxy.blank?.should be_true
56
+ @nil_proxy.blank?.should be_true
56
57
  end
57
58
 
58
59
  should "be false if not blank" do
@@ -60,6 +61,17 @@ class ProxyTest < Test::Unit::TestCase
60
61
  end
61
62
  end
62
63
 
64
+ context "present?" do
65
+ should "be true if present" do
66
+ @proxy.present?.should be_true
67
+ end
68
+
69
+ should "be false if not present" do
70
+ @blank_proxy.present?.should be_false
71
+ @nil_proxy.present?.should be_false
72
+ end
73
+ end
74
+
63
75
  should "delegate respond_to? to target" do
64
76
  @proxy.respond_to?(:each).should be_true
65
77
  @proxy.respond_to?(:size).should be_true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.6.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-01 00:00:00 -05:00
12
+ date: 2010-01-02 00:00:00 -05:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency