mongo_mapper-unstable 2009.11.6 → 2009.11.8

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
18
18
  gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
19
19
  gem.add_development_dependency('shoulda', '2.10.2')
20
20
  gem.add_development_dependency('timecop', '0.3.1')
21
- gem.add_development_dependency('mocha', '0.9.4')
21
+ gem.add_development_dependency('mocha', '0.9.8')
22
22
  end
23
23
 
24
24
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2009.11.06
1
+ 2009.11.08
@@ -6,7 +6,7 @@ module MongoMapper
6
6
  def initialize(owner, association)
7
7
  @owner = owner
8
8
  @association = association
9
- @association.options[:extend].each { |ext| proxy_extend(ext) }
9
+ @association.options[:extend].each { |ext| class << self; self; end.instance_eval { include ext } }
10
10
  reset
11
11
  end
12
12
 
@@ -25,7 +25,12 @@ module MongoMapper
25
25
  end
26
26
 
27
27
  def send(method, *args)
28
- return super if methods.include?(method.to_s)
28
+ metaclass_instance_methods = class << self; self; end.instance_methods
29
+
30
+ if metaclass_instance_methods.any? { |m| m.to_s == method.to_s }
31
+ return __send__(method, *args)
32
+ end
33
+
29
34
  load_target
30
35
  @target.send(method, *args)
31
36
  end
@@ -45,12 +50,12 @@ module MongoMapper
45
50
  end
46
51
 
47
52
  protected
48
- def method_missing(method, *args)
53
+ def method_missing(method, *args, &block)
49
54
  if load_target
50
- if block_given?
51
- @target.send(method, *args) { |*block_args| yield(*block_args) }
52
- else
55
+ if block.nil?
53
56
  @target.send(method, *args)
57
+ else
58
+ @target.send(method, *args) { |*block_args| block.call(*block_args) }
54
59
  end
55
60
  end
56
61
  end
@@ -432,12 +432,12 @@ module MongoMapper
432
432
  read_attribute('_id').blank? || using_custom_id?
433
433
  end
434
434
 
435
- def save
436
- valid? ? create_or_update : false
435
+ def save(perform_validations=true)
436
+ !perform_validations || valid? ? create_or_update : false
437
437
  end
438
438
 
439
439
  def save!
440
- valid? ? create_or_update : raise(DocumentNotValid.new(self))
440
+ save || raise(DocumentNotValid.new(self))
441
441
  end
442
442
 
443
443
  def destroy
@@ -89,7 +89,13 @@ module MongoMapper
89
89
 
90
90
  private
91
91
  def accessors_module
92
- if const_defined?('MongoMapperKeys')
92
+ module_defined = if method(:const_defined?).arity == 1 # Ruby 1.9 compat check
93
+ const_defined?('MongoMapperKeys')
94
+ else
95
+ const_defined?('MongoMapperKeys', false)
96
+ end
97
+
98
+ if module_defined
93
99
  const_get 'MongoMapperKeys'
94
100
  else
95
101
  const_set 'MongoMapperKeys', Module.new
@@ -24,8 +24,9 @@ module MongoMapper
24
24
 
25
25
  def initialize(model, options)
26
26
  raise ArgumentError, "Options must be a hash" unless options.is_a?(Hash)
27
+ options = options.clone
27
28
  options.symbolize_keys!
28
-
29
+
29
30
  @model = model
30
31
  @options = {}
31
32
  @conditions = options.delete(:conditions) || {}
@@ -1,10 +1,10 @@
1
1
  class BasicObject #:nodoc:
2
- alias_method :proxy_extend, :extend
3
- instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|^methods$|instance_eval|proxy_|^object_id$)/ }
2
+ instance_methods.each { |m| undef_method m unless m =~ /(^__|instance_eval)/ }
4
3
  end unless defined?(BasicObject)
5
4
 
6
5
  class Array
7
6
  def self.to_mongo(value)
7
+ value = value.respond_to?(:lines) ? value.lines : value
8
8
  value.to_a
9
9
  end
10
10
 
data/mongo_mapper.gemspec CHANGED
@@ -142,7 +142,7 @@ Gem::Specification.new do |s|
142
142
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
143
143
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3"])
144
144
  s.add_runtime_dependency(%q<mongo>, ["= 0.16"])
145
- s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.8.0"])
145
+ s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
146
146
  s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
147
147
  s.add_development_dependency(%q<shoulda>, ["= 2.10.2"])
148
148
  s.add_development_dependency(%q<timecop>, ["= 0.3.1"])
@@ -50,8 +50,16 @@ class PaginationTest < Test::Unit::TestCase
50
50
  })
51
51
  result.should == [@doc1, @doc3]
52
52
  result.first.age.should == 27
53
+
54
+ result = @document.paginate({
55
+ :conditions => {:last_name => 'Nunemaker'},
56
+ :order => "age DESC",
57
+ :per_page => 2,
58
+ :page => 1} )
59
+ result.should == [@doc1, @doc3]
60
+ result.first.age.should == 27
53
61
  end
54
-
62
+
55
63
  should "withstand rigor" do
56
64
  result = @document.paginate({
57
65
  :per_page => 1,
@@ -24,7 +24,24 @@ class ValidationsTest < Test::Unit::TestCase
24
24
  doc.errors.full_messages.should == ["Name can't be empty"]
25
25
  end
26
26
  end
27
-
27
+
28
+ context "Skipping validations when saving" do
29
+ setup do
30
+ @document = Class.new do
31
+ include MongoMapper::Document
32
+ set_collection_name 'test'
33
+ key :name, String, :required => true
34
+ end
35
+ @document.collection.remove
36
+ end
37
+
38
+ should "insert document" do
39
+ doc = @document.new
40
+ doc.save(false)
41
+ @document.count.should == 1
42
+ end
43
+ end
44
+
28
45
  context "Saving a document that is invalid (destructive)" do
29
46
  setup do
30
47
  @document = Class.new do
data/test/test_helper.rb CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../lib/mongo_mapper')
3
3
  gem 'jnunemaker-matchy', '0.4.0'
4
4
  gem 'shoulda', '2.10.2'
5
5
  gem 'timecop', '0.3.1'
6
- gem 'mocha', '0.9.4'
6
+ gem 'mocha', '0.9.8'
7
7
 
8
8
  require 'matchy'
9
9
  require 'shoulda'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper-unstable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2009.11.6
4
+ version: 2009.11.8
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: 2009-11-06 00:00:00 -05:00
12
+ date: 2009-11-08 00:00:00 -05:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -80,7 +80,7 @@ dependencies:
80
80
  requirements:
81
81
  - - "="
82
82
  - !ruby/object:Gem::Version
83
- version: 0.9.4
83
+ version: 0.9.8
84
84
  version:
85
85
  description:
86
86
  email: nunemaker@gmail.com