mongo_mapper 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ Jeweler::Tasks.new do |gem|
13
13
  gem.version = MongoMapper::Version
14
14
 
15
15
  gem.add_dependency('activesupport', '>= 2.3.4')
16
- gem.add_dependency('mongo', '0.20.1')
16
+ gem.add_dependency('mongo', '1.0')
17
17
  gem.add_dependency('jnunemaker-validatable', '1.8.4')
18
18
 
19
19
  gem.add_development_dependency('json', '>= 1.2.3')
data/lib/mongo_mapper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # Make sure you have the following libs in your load path or you could have issues:
2
2
  # gem 'activesupport', '>= 2.3.4'
3
- # gem 'mongo', '0.20.1'
3
+ # gem 'mongo', '1.0'
4
4
  # gem 'jnunemaker-validatable', '1.8.4'
5
5
  require 'set'
6
6
  require 'uri'
@@ -79,12 +79,12 @@ module MongoMapper
79
79
  find(id)
80
80
  end
81
81
 
82
- def first_or_create(arg)
83
- first(arg) || create(arg)
82
+ def first_or_create(args)
83
+ first(args) || create(args.reject { |key, value| !key?(key) })
84
84
  end
85
85
 
86
- def first_or_new(arg)
87
- first(arg) || new(arg)
86
+ def first_or_new(args)
87
+ first(args) || new(args.reject { |key, value| !key?(key) })
88
88
  end
89
89
 
90
90
  def first(options={})
@@ -28,6 +28,10 @@ module MongoMapper
28
28
  key
29
29
  end
30
30
 
31
+ def key?(key)
32
+ keys.keys.include?(key.to_s)
33
+ end
34
+
31
35
  def using_object_id?
32
36
  object_id_key?(:_id)
33
37
  end
@@ -147,7 +151,7 @@ module MongoMapper
147
151
  module InstanceMethods
148
152
  def initialize(attrs={}, from_database=false)
149
153
  default_id_value(attrs)
150
-
154
+
151
155
  if from_database
152
156
  @new = false
153
157
  self.attributes = attrs
@@ -155,7 +159,7 @@ module MongoMapper
155
159
  @new = true
156
160
  assign(attrs)
157
161
  end
158
-
162
+
159
163
  assign_type
160
164
  end
161
165
 
@@ -1,3 +1,3 @@
1
1
  module MongoMapper
2
- Version = '0.7.4'
2
+ Version = '0.7.5'
3
3
  end
data/mongo_mapper.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_mapper}
8
- s.version = "0.7.4"
8
+ s.version = "0.7.5"
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-04-18}
12
+ s.date = %q{2010-04-30}
13
13
  s.default_executable = %q{mmconsole}
14
14
  s.email = %q{nunemaker@gmail.com}
15
15
  s.executables = ["mmconsole"]
@@ -183,7 +183,7 @@ Gem::Specification.new do |s|
183
183
 
184
184
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
185
185
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
186
- s.add_runtime_dependency(%q<mongo>, ["= 0.20.1"])
186
+ s.add_runtime_dependency(%q<mongo>, ["= 1.0"])
187
187
  s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.8.4"])
188
188
  s.add_development_dependency(%q<json>, [">= 1.2.3"])
189
189
  s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
@@ -192,7 +192,7 @@ Gem::Specification.new do |s|
192
192
  s.add_development_dependency(%q<mocha>, ["= 0.9.8"])
193
193
  else
194
194
  s.add_dependency(%q<activesupport>, [">= 2.3.4"])
195
- s.add_dependency(%q<mongo>, ["= 0.20.1"])
195
+ s.add_dependency(%q<mongo>, ["= 1.0"])
196
196
  s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.4"])
197
197
  s.add_dependency(%q<json>, [">= 1.2.3"])
198
198
  s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
@@ -202,7 +202,7 @@ Gem::Specification.new do |s|
202
202
  end
203
203
  else
204
204
  s.add_dependency(%q<activesupport>, [">= 2.3.4"])
205
- s.add_dependency(%q<mongo>, ["= 0.20.1"])
205
+ s.add_dependency(%q<mongo>, ["= 1.0"])
206
206
  s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.4"])
207
207
  s.add_dependency(%q<json>, [">= 1.2.3"])
208
208
  s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
@@ -448,6 +448,15 @@ class DocumentTest < Test::Unit::TestCase
448
448
  created.last_name.should == 'Nunemaker'
449
449
  }.should change { @document.count }.by(1)
450
450
  end
451
+
452
+ should "disregard non-keys when creating, but use them in the query" do
453
+ assert_nothing_raised do
454
+ @document.create(:first_name => 'John', :age => 9)
455
+ lambda {
456
+ @document.first_or_create(:first_name => 'John', :age.gt => 10).first_name.should == 'John'
457
+ }.should change { @document.count }.by(1)
458
+ end
459
+ end
451
460
  end
452
461
 
453
462
  context "first_or_new" do
@@ -467,6 +476,13 @@ class DocumentTest < Test::Unit::TestCase
467
476
  created.should be_new
468
477
  }.should_not change { @document.count }
469
478
  end
479
+
480
+ should "disregard non-keys when initializing, but use them in the query" do
481
+ assert_nothing_raised do
482
+ @document.create(:first_name => 'John', :age => 9)
483
+ @document.first_or_new(:first_name => 'John', :age.gt => 10).first_name.should == 'John'
484
+ end
485
+ end
470
486
  end
471
487
 
472
488
  context "ClassMethods#delete (single document)" do
@@ -22,6 +22,18 @@ end
22
22
  class KeyTest < Test::Unit::TestCase
23
23
  include MongoMapper::Plugins::Keys
24
24
 
25
+ context ".key?" do
26
+ should "be true if document has key" do
27
+ Address.key?(:city).should be_true
28
+ Address.key?('city').should be_true
29
+ end
30
+
31
+ should "be false if document does not have key" do
32
+ Address.key?(:foo).should be_false
33
+ Address.key?('foo').should be_false
34
+ end
35
+ end
36
+
25
37
  context "Initializing a new key" do
26
38
  should "allow setting the name" do
27
39
  Key.new(:foo, String).name.should == 'foo'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 4
9
- version: 0.7.4
8
+ - 5
9
+ version: 0.7.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Nunemaker
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-18 00:00:00 -04:00
17
+ date: 2010-04-30 00:00:00 -07:00
18
18
  default_executable: mmconsole
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -39,10 +39,9 @@ dependencies:
39
39
  - - "="
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
- - 0
43
- - 20
44
42
  - 1
45
- version: 0.20.1
43
+ - 0
44
+ version: "1.0"
46
45
  type: :runtime
47
46
  version_requirements: *id002
48
47
  - !ruby/object:Gem::Dependency