mongomodel 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Appraisals +5 -5
- data/gemfiles/rails-3.1.gemfile +3 -3
- data/gemfiles/rails-3.2.gemfile +11 -0
- data/lib/mongomodel/concerns/attribute_methods.rb +8 -0
- data/lib/mongomodel/concerns/attribute_methods/read.rb +5 -2
- data/lib/mongomodel/support/types.rb +18 -31
- data/lib/mongomodel/support/types/array.rb +4 -4
- data/lib/mongomodel/support/types/boolean.rb +2 -0
- data/lib/mongomodel/support/types/date.rb +2 -0
- data/lib/mongomodel/support/types/date_time.rb +2 -0
- data/lib/mongomodel/support/types/float.rb +2 -0
- data/lib/mongomodel/support/types/hash.rb +3 -1
- data/lib/mongomodel/support/types/integer.rb +2 -0
- data/lib/mongomodel/support/types/object.rb +5 -0
- data/lib/mongomodel/support/types/openstruct.rb +26 -0
- data/lib/mongomodel/support/types/rational.rb +4 -0
- data/lib/mongomodel/support/types/set.rb +4 -0
- data/lib/mongomodel/support/types/string.rb +2 -0
- data/lib/mongomodel/support/types/symbol.rb +2 -0
- data/lib/mongomodel/support/types/time.rb +2 -0
- data/lib/mongomodel/version.rb +1 -1
- data/mongomodel.gemspec +1 -1
- data/spec/mongomodel/attributes/store_spec.rb +17 -2
- data/spec/mongomodel/concerns/activemodel_spec.rb +16 -97
- data/spec/mongomodel/concerns/attribute_methods_spec.rb +68 -0
- data/spec/mongomodel/support/map_spec.rb +9 -0
- metadata +25 -27
- data/gemfiles/rails-3.1.gemfile.lock +0 -62
- data/gemfiles/rails-edge.gemfile +0 -11
- data/gemfiles/rails-edge.gemfile.lock +0 -66
data/.gitignore
CHANGED
data/Appraisals
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
appraise "rails-3.1" do
|
2
|
-
gem "activesupport", "3.1.
|
3
|
-
gem "activemodel", "3.1.
|
2
|
+
gem "activesupport", "3.1.3"
|
3
|
+
gem "activemodel", "3.1.3"
|
4
4
|
end
|
5
5
|
|
6
|
-
appraise "rails-
|
7
|
-
gem "activesupport", :git => "https://github.com/rails/rails.git"
|
8
|
-
gem "activemodel", :git => "https://github.com/rails/rails.git"
|
6
|
+
appraise "rails-3.2" do
|
7
|
+
gem "activesupport", :git => "https://github.com/rails/rails.git", :branch => '3-2-stable'
|
8
|
+
gem "activemodel", :git => "https://github.com/rails/rails.git", :branch => '3-2-stable'
|
9
9
|
end
|
data/gemfiles/rails-3.1.gemfile
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
|
+
gem "appraisal", "~> 0.3.6"
|
5
6
|
gem "bson_ext", "~> 1.5"
|
6
7
|
gem "tzinfo"
|
7
|
-
gem "
|
8
|
-
gem "
|
9
|
-
gem "appraisal", "~> 0.3.6"
|
8
|
+
gem "activesupport", "3.1.3"
|
9
|
+
gem "activemodel", "3.1.3"
|
10
10
|
|
11
11
|
gemspec :path=>"../"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "appraisal", "~> 0.3.6"
|
6
|
+
gem "bson_ext", "~> 1.5"
|
7
|
+
gem "tzinfo"
|
8
|
+
gem "activesupport", :git=>"https://github.com/rails/rails.git", :branch=>"3-2-stable"
|
9
|
+
gem "activemodel", :git=>"https://github.com/rails/rails.git", :branch=>"3-2-stable"
|
10
|
+
|
11
|
+
gemspec :path=>"../"
|
@@ -9,6 +9,7 @@ module MongoModel
|
|
9
9
|
# accessors, mutators and query methods.
|
10
10
|
def define_attribute_methods
|
11
11
|
return if attribute_methods_generated?
|
12
|
+
superclass.define_attribute_methods unless abstract_class?
|
12
13
|
super(properties.keys)
|
13
14
|
@attribute_methods_generated = true
|
14
15
|
end
|
@@ -27,6 +28,13 @@ module MongoModel
|
|
27
28
|
undefine_attribute_methods
|
28
29
|
property
|
29
30
|
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
def instance_method_already_implemented?(method_name)
|
34
|
+
method_defined?(method_name) ||
|
35
|
+
private_method_defined?(method_name) ||
|
36
|
+
super
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
40
|
def method_missing(method, *args, &block)
|
@@ -3,8 +3,11 @@ module MongoModel
|
|
3
3
|
module Read
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
# ActiveModel 3.2 defines the non-prefixed attribute name automatically
|
7
|
+
if ActiveModel::VERSION::STRING <= "3.2"
|
8
|
+
included do
|
9
|
+
attribute_method_suffix ""
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
10
13
|
# Returns the value of the attribute identified by +name+ after it has been typecast (for example,
|
@@ -1,7 +1,21 @@
|
|
1
|
-
require 'rational' unless RUBY_VERSION >= '1.9.2'
|
2
|
-
require 'set'
|
3
|
-
|
4
1
|
require 'mongomodel/support/types/object'
|
2
|
+
require 'mongomodel/support/types/custom'
|
3
|
+
|
4
|
+
module MongoModel
|
5
|
+
module Types
|
6
|
+
CONVERTERS = Hash.new { |h, k| h[k] = Types::Custom.new(k) }
|
7
|
+
|
8
|
+
def self.register_converter(type, converter)
|
9
|
+
CONVERTERS[type] = converter
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.converter_for(type)
|
13
|
+
CONVERTERS[type]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Built-in types
|
5
19
|
require 'mongomodel/support/types/string'
|
6
20
|
require 'mongomodel/support/types/integer'
|
7
21
|
require 'mongomodel/support/types/float'
|
@@ -10,35 +24,8 @@ require 'mongomodel/support/types/symbol'
|
|
10
24
|
require 'mongomodel/support/types/date'
|
11
25
|
require 'mongomodel/support/types/time'
|
12
26
|
require 'mongomodel/support/types/date_time'
|
13
|
-
require 'mongomodel/support/types/custom'
|
14
27
|
require 'mongomodel/support/types/array'
|
15
28
|
require 'mongomodel/support/types/set'
|
16
29
|
require 'mongomodel/support/types/hash'
|
17
30
|
require 'mongomodel/support/types/rational'
|
18
|
-
|
19
|
-
module MongoModel
|
20
|
-
module Types
|
21
|
-
CONVERTERS = {
|
22
|
-
::String => Types::String.new,
|
23
|
-
::Integer => Types::Integer.new,
|
24
|
-
::Float => Types::Float.new,
|
25
|
-
::Boolean => Types::Boolean.new,
|
26
|
-
::Symbol => Types::Symbol.new,
|
27
|
-
::Date => Types::Date.new,
|
28
|
-
::Time => Types::Time.new,
|
29
|
-
::DateTime => Types::DateTime.new,
|
30
|
-
::Array => Types::Array.new,
|
31
|
-
::Set => Types::Set.new,
|
32
|
-
::Hash => Types::Hash.new,
|
33
|
-
::Rational => Types::Rational.new
|
34
|
-
}
|
35
|
-
|
36
|
-
def self.converter_for(type)
|
37
|
-
if CONVERTERS[type]
|
38
|
-
CONVERTERS[type]
|
39
|
-
else
|
40
|
-
CONVERTERS[type] = Types::Custom.new(type)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
31
|
+
require 'mongomodel/support/types/openstruct'
|
@@ -2,14 +2,14 @@ module MongoModel
|
|
2
2
|
module Types
|
3
3
|
class Array < Object
|
4
4
|
def to_mongo(array)
|
5
|
-
array.map { |i|
|
6
|
-
Types.converter_for(i.class).to_mongo(i)
|
7
|
-
} if array
|
5
|
+
array.map { |i| convert(i) } if array
|
8
6
|
end
|
9
7
|
|
10
8
|
def to_query(value)
|
11
|
-
|
9
|
+
convert(value)
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
14
|
+
|
15
|
+
MongoModel::Types.register_converter(Array, MongoModel::Types::Array.new)
|
@@ -5,7 +5,7 @@ module MongoModel
|
|
5
5
|
class Hash < Object
|
6
6
|
def to_mongo(hash)
|
7
7
|
hash.inject({}) { |result, (k, v)|
|
8
|
-
result[k] =
|
8
|
+
result[convert(k)] = convert(v)
|
9
9
|
result
|
10
10
|
} if hash
|
11
11
|
end
|
@@ -16,3 +16,5 @@ module MongoModel
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
MongoModel::Types.register_converter(Hash, MongoModel::Types::Hash.new)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module MongoModel
|
4
|
+
module Types
|
5
|
+
class OpenStruct < Object
|
6
|
+
def cast(value)
|
7
|
+
case value
|
8
|
+
when ::OpenStruct
|
9
|
+
value
|
10
|
+
else
|
11
|
+
::OpenStruct.new(value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_mongo(value)
|
16
|
+
value.marshal_dump if value
|
17
|
+
end
|
18
|
+
|
19
|
+
def from_mongo(value)
|
20
|
+
::OpenStruct.new(value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
MongoModel::Types.register_converter(OpenStruct, MongoModel::Types::OpenStruct.new)
|
data/lib/mongomodel/version.rb
CHANGED
data/mongomodel.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency "will_paginate", "~> 2.3.15"
|
21
21
|
|
22
22
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
23
|
-
s.add_development_dependency "rspec", "~> 2.
|
23
|
+
s.add_development_dependency "rspec", "~> 2.8"
|
24
24
|
s.add_development_dependency "guard-rspec", "~> 0.5.0"
|
25
25
|
|
26
26
|
s.files = `git ls-files`.split("\n")
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
3
2
|
require 'active_support/core_ext/hash/indifferent_access'
|
4
|
-
|
3
|
+
|
4
|
+
require 'set'
|
5
|
+
require "ostruct"
|
6
|
+
require 'rational' unless RUBY_VERSION >= '1.9.2'
|
5
7
|
|
6
8
|
module MongoModel
|
7
9
|
describe Attributes::Store do
|
@@ -18,6 +20,7 @@ module MongoModel
|
|
18
20
|
properties[:time] = MongoModel::Properties::Property.new(:time, Time)
|
19
21
|
properties[:datetime] = MongoModel::Properties::Property.new(:datetime, DateTime)
|
20
22
|
properties[:rational] = MongoModel::Properties::Property.new(:rational, Rational)
|
23
|
+
properties[:openstruct] = MongoModel::Properties::Property.new(:openstruct, OpenStruct)
|
21
24
|
properties[:custom] = MongoModel::Properties::Property.new(:custom, CustomClass)
|
22
25
|
properties[:custom_default] = MongoModel::Properties::Property.new(:custom_default, CustomClassWithDefault)
|
23
26
|
properties[:default] = MongoModel::Properties::Property.new(:default, String, :default => 'Default')
|
@@ -153,6 +156,11 @@ module MongoModel
|
|
153
156
|
{
|
154
157
|
Rational(1, 15) => Rational(1, 15),
|
155
158
|
"2/3" => Rational(2, 3)
|
159
|
+
},
|
160
|
+
:openstruct =>
|
161
|
+
{
|
162
|
+
OpenStruct.new(:abc => 123) => OpenStruct.new(:abc => 123),
|
163
|
+
{ :mykey => "Hello world" } => OpenStruct.new(:mykey => "Hello world")
|
156
164
|
}
|
157
165
|
}
|
158
166
|
|
@@ -201,6 +209,7 @@ module MongoModel
|
|
201
209
|
:hash => [ { :foo => 'bar' } ],
|
202
210
|
:array => [ [123, 'abc', :foo, true] ],
|
203
211
|
:rational => [ "2/3" ],
|
212
|
+
:openstruct => [ { :abc => 123 } ],
|
204
213
|
:date => [ Date.civil(2009, 11, 15), Time.local(2008, 12, 3, 0, 0, 0, 0), "2009/3/4", "Sat Jan 01 20:15:01 UTC 2000" ],
|
205
214
|
:time => [ Time.local(2008, 5, 14, 1, 2, 3, 4), Date.civil(2009, 11, 15), "Sat Jan 01 20:15:01 UTC 2000", "2009/3/4" ]
|
206
215
|
}
|
@@ -229,6 +238,7 @@ module MongoModel
|
|
229
238
|
:date => [ Date.civil(2009, 11, 15) ],
|
230
239
|
:time => [ Time.local(2008, 5, 14, 1, 2, 3, 4) ],
|
231
240
|
:rational => [ Rational(2, 3) ],
|
241
|
+
:openstruct => [ {} ],
|
232
242
|
:custom => [ CustomClass.new('foobar'), 'baz' ]
|
233
243
|
}
|
234
244
|
|
@@ -243,6 +253,7 @@ module MongoModel
|
|
243
253
|
:date => [ nil, '' ],
|
244
254
|
:time => [ nil, '' ],
|
245
255
|
:rational => [ nil ],
|
256
|
+
:openstruct => [ nil ],
|
246
257
|
:custom => [ nil ]
|
247
258
|
}
|
248
259
|
|
@@ -281,6 +292,7 @@ module MongoModel
|
|
281
292
|
subject[:date] = Date.civil(2009, 11, 15)
|
282
293
|
subject[:time] = Time.local(2008, 5, 14, 1, 2, 3, 4, 0.5)
|
283
294
|
subject[:rational] = Rational(2, 3)
|
295
|
+
subject[:openstruct] = OpenStruct.new(:abc => 123)
|
284
296
|
subject[:custom] = CustomClass.new('custom')
|
285
297
|
subject[:as] = "As property"
|
286
298
|
subject[:non_property] = "Hello World"
|
@@ -297,6 +309,7 @@ module MongoModel
|
|
297
309
|
'date' => "2009/11/15",
|
298
310
|
'time' => Time.local(2008, 5, 14, 1, 2, 3, 4, 0),
|
299
311
|
'rational' => "2/3",
|
312
|
+
'openstruct' => { :abc => 123 },
|
300
313
|
'custom' => { :name => 'custom' },
|
301
314
|
'_custom_as' => "As property",
|
302
315
|
'non_property' => "Hello World",
|
@@ -316,6 +329,7 @@ module MongoModel
|
|
316
329
|
'date' => Time.utc(2009, 11, 15),
|
317
330
|
'time' => Time.local(2008, 5, 14, 1, 2, 3, 4, 0.5),
|
318
331
|
'rational' => "2/3",
|
332
|
+
'openstruct' => { "foo" => "bar" },
|
319
333
|
'custom' => { :name => 'custom' },
|
320
334
|
'_custom_as' => "As property",
|
321
335
|
'custom_non_property' => { :name => 'custom non property' }
|
@@ -331,6 +345,7 @@ module MongoModel
|
|
331
345
|
subject[:date].should == Date.civil(2009, 11, 15)
|
332
346
|
subject[:time].should == Time.local(2008, 5, 14, 1, 2, 3, 4, 0)
|
333
347
|
subject[:rational].should == Rational(2, 3)
|
348
|
+
subject[:openstruct].should == OpenStruct.new(:foo => "bar")
|
334
349
|
subject[:custom].should == CustomClass.new('custom')
|
335
350
|
subject[:as].should == "As property"
|
336
351
|
subject[:custom_non_property].should == { :name => 'custom non property' }
|
@@ -1,106 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
# Specs ported from ActiveModel::Lint::Tests
|
4
|
-
#
|
5
|
-
# These tests do not attempt to determine the semantic correctness of the
|
6
|
-
# returned values. For instance, you could implement valid? to always
|
7
|
-
# return true, and the tests would pass. It is up to you to ensure that
|
8
|
-
# the values are semantically meaningful.
|
9
|
-
#
|
10
|
-
# Objects you pass in are expected to return a compliant object from a
|
11
|
-
# call to to_model. It is perfectly fine for to_model to return self.
|
12
3
|
module MongoModel
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
subject { TestModel.new.to_model }
|
17
|
-
|
18
|
-
# == Responds to <tt>to_key</tt>
|
19
|
-
#
|
20
|
-
# Returns an Enumerable of all (primary) key attributes
|
21
|
-
# or nil if model.persisted? is false
|
22
|
-
it { should respond_to(:to_key) }
|
23
|
-
|
24
|
-
specify "to_key should return nil if subject.persisted? is false" do
|
25
|
-
subject.stub!(:persisted?).and_return(false)
|
26
|
-
subject.to_key.should be_nil
|
27
|
-
end
|
28
|
-
|
29
|
-
# == Responds to <tt>to_param</tt>
|
30
|
-
#
|
31
|
-
# Returns a string representing the object's key suitable for use in URLs
|
32
|
-
# or nil if model.persisted? is false.
|
33
|
-
#
|
34
|
-
# Implementers can decide to either raise an exception or provide a default
|
35
|
-
# in case the record uses a composite primary key. There are no tests for this
|
36
|
-
# behavior in lint because it doesn't make sense to force any of the possible
|
37
|
-
# implementation strategies on the implementer. However, if the resource is
|
38
|
-
# not persisted?, then to_param should always return nil.
|
39
|
-
it { should respond_to(:to_param) }
|
40
|
-
|
41
|
-
specify "to_param should return nil if subject.persisted? is false" do
|
42
|
-
subject.stub!(:to_key).and_return([1])
|
43
|
-
subject.stub!(:persisted?).and_return(false)
|
44
|
-
subject.to_param.should be_nil
|
45
|
-
end
|
46
|
-
|
47
|
-
# == Responds to <tt>valid?</tt>
|
48
|
-
#
|
49
|
-
# Returns a boolean that specifies whether the object is in a valid or invalid
|
50
|
-
# state.
|
51
|
-
it { should respond_to_boolean(:valid?) }
|
4
|
+
shared_examples_for "ActiveModel" do
|
5
|
+
require 'test/unit/assertions'
|
6
|
+
include Test::Unit::Assertions
|
52
7
|
|
53
|
-
|
54
|
-
#
|
55
|
-
# Returns a boolean that specifies whether the object has been persisted yet.
|
56
|
-
# This is used when calculating the URL for an object. If the object is
|
57
|
-
# not persisted, a form for that object, for instance, will be POSTed to the
|
58
|
-
# collection. If it is persisted, a form for the object will put PUTed to the
|
59
|
-
# URL for the object.
|
60
|
-
it { should respond_to_boolean(:persisted?) }
|
8
|
+
include ActiveModel::Lint::Tests
|
61
9
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
# :human and :partial_path. Check ActiveModel::Naming for more information.
|
66
|
-
#
|
67
|
-
specify "the model class should respond to model_name" do
|
68
|
-
subject.class.should respond_to(:model_name)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should return strings for model_name" do
|
72
|
-
model_name = subject.class.model_name
|
73
|
-
model_name.should be_a_kind_of(String)
|
74
|
-
model_name.human.should be_a_kind_of(String)
|
75
|
-
model_name.partial_path.should be_a_kind_of(String)
|
76
|
-
model_name.singular.should be_a_kind_of(String)
|
77
|
-
model_name.plural.should be_a_kind_of(String)
|
78
|
-
end
|
79
|
-
|
80
|
-
# == Errors Testing
|
81
|
-
#
|
82
|
-
# Returns an object that has :[] and :full_messages defined on it. See below
|
83
|
-
# for more details.
|
84
|
-
describe "errors" do
|
85
|
-
it { should respond_to(:errors) }
|
86
|
-
|
87
|
-
# Returns an Array of Strings that are the errors for the attribute in
|
88
|
-
# question. If localization is used, the Strings should be localized
|
89
|
-
# for the current locale. If no error is present, this method should
|
90
|
-
# return an empty Array.
|
91
|
-
describe "#[]" do
|
92
|
-
it "should return an Array" do
|
93
|
-
subject.errors[:hello].should be_an(Array)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# Returns an Array of all error messages for the object. Each message
|
98
|
-
# should contain information about the field, if applicable.
|
99
|
-
describe "#full_messages" do
|
100
|
-
it "should return an Array" do
|
101
|
-
subject.errors.full_messages.should be_an(Array)
|
102
|
-
end
|
10
|
+
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
|
11
|
+
example m.gsub('_',' ') do
|
12
|
+
send m
|
103
13
|
end
|
104
14
|
end
|
15
|
+
|
16
|
+
let(:model) { subject }
|
17
|
+
end
|
18
|
+
|
19
|
+
specs_for(Document, EmbeddedDocument) do
|
20
|
+
define_class(:TestModel, described_class)
|
21
|
+
subject { TestModel.new }
|
22
|
+
|
23
|
+
it_should_behave_like "ActiveModel"
|
105
24
|
end
|
106
25
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module MongoModel
|
4
|
+
specs_for(Document, EmbeddedDocument) do
|
5
|
+
describe "generating attribute methods" do
|
6
|
+
define_class(:TestDocument, described_class) do
|
7
|
+
property :foo, String
|
8
|
+
|
9
|
+
def foo(a); "from method"; end
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { TestDocument.new }
|
13
|
+
|
14
|
+
it "should not overwrite an existing method" do
|
15
|
+
subject.foo(1).should == "from method"
|
16
|
+
end
|
17
|
+
|
18
|
+
context "on a subclass" do
|
19
|
+
define_class(:SubDocument, :TestDocument)
|
20
|
+
subject { SubDocument.new }
|
21
|
+
|
22
|
+
it "should not overwrite methods defined on the superclass" do
|
23
|
+
subject.foo(1).should == "from method"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "on a class with an included module" do
|
28
|
+
module TestModule
|
29
|
+
def foo(a); "from method"; end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not overwrite methods defined on the included module" do
|
33
|
+
TestDocument.send(:include, TestModule)
|
34
|
+
subject.foo(1).should == "from method"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "on a class with an included concern that defines the property" do
|
39
|
+
module TestConcern
|
40
|
+
extend ActiveSupport::Concern
|
41
|
+
|
42
|
+
included do
|
43
|
+
property :bar, String
|
44
|
+
end
|
45
|
+
|
46
|
+
def bar(a); "from concern"; end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "the base class" do
|
50
|
+
it "should not overwrite methods defined within the concern" do
|
51
|
+
TestDocument.send(:include, TestConcern)
|
52
|
+
subject.bar(1).should == "from concern"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "subclasses" do
|
57
|
+
define_class(:SubDocument, :TestDocument)
|
58
|
+
subject { SubDocument.new }
|
59
|
+
|
60
|
+
it "should not overwrite methods defined within the concern" do
|
61
|
+
SubDocument.send(:include, TestConcern)
|
62
|
+
subject.bar(1).should == "from concern"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -212,6 +212,15 @@ module MongoModel
|
|
212
212
|
subject.values_at(:another, :abc).should == [doc2, doc1]
|
213
213
|
end
|
214
214
|
end
|
215
|
+
|
216
|
+
describe "map from Date to String" do
|
217
|
+
let(:klass) { Map[Date => String] }
|
218
|
+
subject { klass.new(Date.civil(2009, 11, 15) => "Hello world") }
|
219
|
+
|
220
|
+
it "should cast key to String on #to_mongo" do
|
221
|
+
subject.to_mongo.should == { "2009/11/15" => "Hello world" }
|
222
|
+
end
|
223
|
+
end
|
215
224
|
end
|
216
225
|
|
217
226
|
specs_for(Document, EmbeddedDocument) do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongomodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 4
|
10
|
+
version: 0.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sam Pohlenz
|
@@ -15,10 +15,9 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-28 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name: activesupport
|
22
21
|
prerelease: false
|
23
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
23
|
none: false
|
@@ -30,10 +29,10 @@ dependencies:
|
|
30
29
|
- 3
|
31
30
|
- 1
|
32
31
|
version: "3.1"
|
33
|
-
type: :runtime
|
34
32
|
version_requirements: *id001
|
33
|
+
name: activesupport
|
34
|
+
type: :runtime
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name: activemodel
|
37
36
|
prerelease: false
|
38
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
38
|
none: false
|
@@ -45,10 +44,10 @@ dependencies:
|
|
45
44
|
- 3
|
46
45
|
- 1
|
47
46
|
version: "3.1"
|
48
|
-
type: :runtime
|
49
47
|
version_requirements: *id002
|
48
|
+
name: activemodel
|
49
|
+
type: :runtime
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
|
-
name: mongo
|
52
51
|
prerelease: false
|
53
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
53
|
none: false
|
@@ -60,10 +59,10 @@ dependencies:
|
|
60
59
|
- 1
|
61
60
|
- 5
|
62
61
|
version: "1.5"
|
63
|
-
type: :runtime
|
64
62
|
version_requirements: *id003
|
63
|
+
name: mongo
|
64
|
+
type: :runtime
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
|
-
name: will_paginate
|
67
66
|
prerelease: false
|
68
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
68
|
none: false
|
@@ -76,10 +75,10 @@ dependencies:
|
|
76
75
|
- 3
|
77
76
|
- 15
|
78
77
|
version: 2.3.15
|
79
|
-
type: :runtime
|
80
78
|
version_requirements: *id004
|
79
|
+
name: will_paginate
|
80
|
+
type: :runtime
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name: bundler
|
83
82
|
prerelease: false
|
84
83
|
requirement: &id005 !ruby/object:Gem::Requirement
|
85
84
|
none: false
|
@@ -92,26 +91,25 @@ dependencies:
|
|
92
91
|
- 0
|
93
92
|
- 0
|
94
93
|
version: 1.0.0
|
95
|
-
type: :development
|
96
94
|
version_requirements: *id005
|
95
|
+
name: bundler
|
96
|
+
type: :development
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec
|
99
98
|
prerelease: false
|
100
99
|
requirement: &id006 !ruby/object:Gem::Requirement
|
101
100
|
none: false
|
102
101
|
requirements:
|
103
102
|
- - ~>
|
104
103
|
- !ruby/object:Gem::Version
|
105
|
-
hash:
|
104
|
+
hash: 19
|
106
105
|
segments:
|
107
106
|
- 2
|
108
|
-
-
|
109
|
-
|
110
|
-
version: 2.6.0
|
111
|
-
type: :development
|
107
|
+
- 8
|
108
|
+
version: "2.8"
|
112
109
|
version_requirements: *id006
|
110
|
+
name: rspec
|
111
|
+
type: :development
|
113
112
|
- !ruby/object:Gem::Dependency
|
114
|
-
name: guard-rspec
|
115
113
|
prerelease: false
|
116
114
|
requirement: &id007 !ruby/object:Gem::Requirement
|
117
115
|
none: false
|
@@ -124,8 +122,9 @@ dependencies:
|
|
124
122
|
- 5
|
125
123
|
- 0
|
126
124
|
version: 0.5.0
|
127
|
-
type: :development
|
128
125
|
version_requirements: *id007
|
126
|
+
name: guard-rspec
|
127
|
+
type: :development
|
129
128
|
description: MongoModel is a MongoDB ORM for Ruby/Rails similar to ActiveRecord and DataMapper.
|
130
129
|
email:
|
131
130
|
- sam@sampohlenz.com
|
@@ -145,9 +144,7 @@ files:
|
|
145
144
|
- Rakefile
|
146
145
|
- bin/console
|
147
146
|
- gemfiles/rails-3.1.gemfile
|
148
|
-
- gemfiles/rails-3.
|
149
|
-
- gemfiles/rails-edge.gemfile
|
150
|
-
- gemfiles/rails-edge.gemfile.lock
|
147
|
+
- gemfiles/rails-3.2.gemfile
|
151
148
|
- lib/mongomodel.rb
|
152
149
|
- lib/mongomodel/attributes/mongo.rb
|
153
150
|
- lib/mongomodel/attributes/store.rb
|
@@ -226,6 +223,7 @@ files:
|
|
226
223
|
- lib/mongomodel/support/types/hash.rb
|
227
224
|
- lib/mongomodel/support/types/integer.rb
|
228
225
|
- lib/mongomodel/support/types/object.rb
|
226
|
+
- lib/mongomodel/support/types/openstruct.rb
|
229
227
|
- lib/mongomodel/support/types/rational.rb
|
230
228
|
- lib/mongomodel/support/types/set.rb
|
231
229
|
- lib/mongomodel/support/types/string.rb
|
@@ -251,6 +249,7 @@ files:
|
|
251
249
|
- spec/mongomodel/concerns/attribute_methods/query_spec.rb
|
252
250
|
- spec/mongomodel/concerns/attribute_methods/read_spec.rb
|
253
251
|
- spec/mongomodel/concerns/attribute_methods/write_spec.rb
|
252
|
+
- spec/mongomodel/concerns/attribute_methods_spec.rb
|
254
253
|
- spec/mongomodel/concerns/attributes_spec.rb
|
255
254
|
- spec/mongomodel/concerns/callbacks_spec.rb
|
256
255
|
- spec/mongomodel/concerns/logging_spec.rb
|
@@ -325,10 +324,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
325
324
|
requirements: []
|
326
325
|
|
327
326
|
rubyforge_project: mongomodel
|
328
|
-
rubygems_version: 1.8.
|
327
|
+
rubygems_version: 1.8.10
|
329
328
|
signing_key:
|
330
329
|
specification_version: 3
|
331
330
|
summary: MongoDB ORM for Ruby/Rails
|
332
331
|
test_files: []
|
333
332
|
|
334
|
-
has_rdoc:
|
@@ -1,62 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: /Users/sam/Work/mongomodel
|
3
|
-
specs:
|
4
|
-
mongomodel (0.4.3)
|
5
|
-
activemodel (~> 3.1)
|
6
|
-
activesupport (~> 3.1)
|
7
|
-
mongo (~> 1.5)
|
8
|
-
will_paginate (~> 2.3.15)
|
9
|
-
|
10
|
-
GEM
|
11
|
-
remote: http://rubygems.org/
|
12
|
-
specs:
|
13
|
-
activemodel (3.1.0)
|
14
|
-
activesupport (= 3.1.0)
|
15
|
-
bcrypt-ruby (~> 3.0.0)
|
16
|
-
builder (~> 3.0.0)
|
17
|
-
i18n (~> 0.6)
|
18
|
-
activesupport (3.1.0)
|
19
|
-
multi_json (~> 1.0)
|
20
|
-
appraisal (0.3.8)
|
21
|
-
bundler
|
22
|
-
rake
|
23
|
-
bcrypt-ruby (3.0.1)
|
24
|
-
bson (1.5.2)
|
25
|
-
bson_ext (1.5.2)
|
26
|
-
bson (= 1.5.2)
|
27
|
-
builder (3.0.0)
|
28
|
-
diff-lcs (1.1.3)
|
29
|
-
guard (0.8.8)
|
30
|
-
thor (~> 0.14.6)
|
31
|
-
guard-rspec (0.5.9)
|
32
|
-
guard (>= 0.8.4)
|
33
|
-
i18n (0.6.0)
|
34
|
-
mongo (1.5.2)
|
35
|
-
bson (= 1.5.2)
|
36
|
-
multi_json (1.0.4)
|
37
|
-
rake (0.9.2.2)
|
38
|
-
rspec (2.6.0)
|
39
|
-
rspec-core (~> 2.6.0)
|
40
|
-
rspec-expectations (~> 2.6.0)
|
41
|
-
rspec-mocks (~> 2.6.0)
|
42
|
-
rspec-core (2.6.4)
|
43
|
-
rspec-expectations (2.6.0)
|
44
|
-
diff-lcs (~> 1.1.2)
|
45
|
-
rspec-mocks (2.6.0)
|
46
|
-
thor (0.14.6)
|
47
|
-
tzinfo (0.3.31)
|
48
|
-
will_paginate (2.3.16)
|
49
|
-
|
50
|
-
PLATFORMS
|
51
|
-
ruby
|
52
|
-
|
53
|
-
DEPENDENCIES
|
54
|
-
activemodel (= 3.1.0)
|
55
|
-
activesupport (= 3.1.0)
|
56
|
-
appraisal (~> 0.3.6)
|
57
|
-
bson_ext (~> 1.5)
|
58
|
-
bundler (>= 1.0.0)
|
59
|
-
guard-rspec (~> 0.5.0)
|
60
|
-
mongomodel!
|
61
|
-
rspec (~> 2.6.0)
|
62
|
-
tzinfo
|
data/gemfiles/rails-edge.gemfile
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "http://rubygems.org"
|
4
|
-
|
5
|
-
gem "bson_ext", "~> 1.5"
|
6
|
-
gem "tzinfo"
|
7
|
-
gem "activemodel", :git=>"https://github.com/rails/rails.git"
|
8
|
-
gem "activesupport", :git=>"https://github.com/rails/rails.git"
|
9
|
-
gem "appraisal", "~> 0.3.6"
|
10
|
-
|
11
|
-
gemspec :path=>"../"
|
@@ -1,66 +0,0 @@
|
|
1
|
-
GIT
|
2
|
-
remote: https://github.com/rails/rails.git
|
3
|
-
revision: 38703ac8972c7e8f3f3f1ac95aa506cc4ae30ef0
|
4
|
-
specs:
|
5
|
-
activemodel (3.2.0.beta)
|
6
|
-
activesupport (= 3.2.0.beta)
|
7
|
-
builder (~> 3.0.0)
|
8
|
-
i18n (~> 0.6)
|
9
|
-
activesupport (3.2.0.beta)
|
10
|
-
i18n (~> 0.6)
|
11
|
-
multi_json (~> 1.0)
|
12
|
-
|
13
|
-
PATH
|
14
|
-
remote: /Users/sam/Work/mongomodel
|
15
|
-
specs:
|
16
|
-
mongomodel (0.4.3)
|
17
|
-
activemodel (~> 3.1)
|
18
|
-
activesupport (~> 3.1)
|
19
|
-
mongo (~> 1.5)
|
20
|
-
will_paginate (~> 2.3.15)
|
21
|
-
|
22
|
-
GEM
|
23
|
-
remote: http://rubygems.org/
|
24
|
-
specs:
|
25
|
-
appraisal (0.3.8)
|
26
|
-
bundler
|
27
|
-
rake
|
28
|
-
bson (1.5.2)
|
29
|
-
bson_ext (1.5.2)
|
30
|
-
bson (= 1.5.2)
|
31
|
-
builder (3.0.0)
|
32
|
-
diff-lcs (1.1.3)
|
33
|
-
guard (0.8.8)
|
34
|
-
thor (~> 0.14.6)
|
35
|
-
guard-rspec (0.5.9)
|
36
|
-
guard (>= 0.8.4)
|
37
|
-
i18n (0.6.0)
|
38
|
-
mongo (1.5.2)
|
39
|
-
bson (= 1.5.2)
|
40
|
-
multi_json (1.0.4)
|
41
|
-
rake (0.9.2.2)
|
42
|
-
rspec (2.6.0)
|
43
|
-
rspec-core (~> 2.6.0)
|
44
|
-
rspec-expectations (~> 2.6.0)
|
45
|
-
rspec-mocks (~> 2.6.0)
|
46
|
-
rspec-core (2.6.4)
|
47
|
-
rspec-expectations (2.6.0)
|
48
|
-
diff-lcs (~> 1.1.2)
|
49
|
-
rspec-mocks (2.6.0)
|
50
|
-
thor (0.14.6)
|
51
|
-
tzinfo (0.3.31)
|
52
|
-
will_paginate (2.3.16)
|
53
|
-
|
54
|
-
PLATFORMS
|
55
|
-
ruby
|
56
|
-
|
57
|
-
DEPENDENCIES
|
58
|
-
activemodel!
|
59
|
-
activesupport!
|
60
|
-
appraisal (~> 0.3.6)
|
61
|
-
bson_ext (~> 1.5)
|
62
|
-
bundler (>= 1.0.0)
|
63
|
-
guard-rspec (~> 0.5.0)
|
64
|
-
mongomodel!
|
65
|
-
rspec (~> 2.6.0)
|
66
|
-
tzinfo
|