mongo_mapper_ign 0.7.4 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. data/README.rdoc +1 -1
  2. data/lib/mongo_mapper.rb +5 -8
  3. data/lib/mongo_mapper/document.rb +24 -53
  4. data/lib/mongo_mapper/embedded_document.rb +1 -0
  5. data/lib/mongo_mapper/plugins.rb +1 -0
  6. data/lib/mongo_mapper/plugins/associations.rb +2 -1
  7. data/lib/mongo_mapper/plugins/associations/base.rb +5 -4
  8. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +2 -1
  9. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +2 -1
  10. data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
  11. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +1 -0
  12. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +1 -0
  13. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +1 -0
  14. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +2 -1
  15. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
  16. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +1 -0
  17. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
  18. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +1 -0
  19. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +2 -1
  20. data/lib/mongo_mapper/plugins/associations/proxy.rb +1 -0
  21. data/lib/mongo_mapper/plugins/callbacks.rb +1 -0
  22. data/lib/mongo_mapper/plugins/clone.rb +1 -0
  23. data/lib/mongo_mapper/plugins/descendants.rb +1 -0
  24. data/lib/mongo_mapper/plugins/dirty.rb +1 -0
  25. data/lib/mongo_mapper/plugins/equality.rb +4 -3
  26. data/lib/mongo_mapper/plugins/identity_map.rb +9 -7
  27. data/lib/mongo_mapper/plugins/inspect.rb +1 -0
  28. data/lib/mongo_mapper/plugins/keys.rb +50 -73
  29. data/lib/mongo_mapper/plugins/keys/key.rb +54 -0
  30. data/lib/mongo_mapper/plugins/logger.rb +1 -0
  31. data/lib/mongo_mapper/plugins/modifiers.rb +10 -5
  32. data/lib/mongo_mapper/plugins/pagination.rb +1 -0
  33. data/lib/mongo_mapper/plugins/pagination/proxy.rb +4 -3
  34. data/lib/mongo_mapper/plugins/persistence.rb +1 -0
  35. data/lib/mongo_mapper/plugins/protected.rb +1 -0
  36. data/lib/mongo_mapper/plugins/rails.rb +1 -0
  37. data/lib/mongo_mapper/plugins/serialization.rb +4 -3
  38. data/lib/mongo_mapper/plugins/timestamps.rb +2 -1
  39. data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
  40. data/lib/mongo_mapper/plugins/validations.rb +3 -2
  41. data/lib/mongo_mapper/query.rb +10 -129
  42. data/lib/mongo_mapper/support.rb +18 -39
  43. data/lib/mongo_mapper/support/descendant_appends.rb +1 -0
  44. data/lib/mongo_mapper/support/find.rb +1 -0
  45. data/lib/mongo_mapper/version.rb +2 -1
  46. metadata +32 -134
  47. data/.gitignore +0 -10
  48. data/Rakefile +0 -37
  49. data/mongo_mapper.gemspec +0 -214
  50. data/mongo_mapper_ign.gemspec +0 -217
  51. data/performance/read_write.rb +0 -52
  52. data/specs.watchr +0 -51
  53. data/test/NOTE_ON_TESTING +0 -1
  54. data/test/active_model_lint_test.rb +0 -13
  55. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +0 -63
  56. data/test/functional/associations/test_belongs_to_proxy.rb +0 -101
  57. data/test/functional/associations/test_in_array_proxy.rb +0 -325
  58. data/test/functional/associations/test_many_documents_as_proxy.rb +0 -229
  59. data/test/functional/associations/test_many_documents_proxy.rb +0 -536
  60. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +0 -176
  61. data/test/functional/associations/test_many_embedded_proxy.rb +0 -256
  62. data/test/functional/associations/test_many_polymorphic_proxy.rb +0 -302
  63. data/test/functional/associations/test_one_embedded_proxy.rb +0 -68
  64. data/test/functional/associations/test_one_proxy.rb +0 -196
  65. data/test/functional/test_associations.rb +0 -44
  66. data/test/functional/test_binary.rb +0 -27
  67. data/test/functional/test_callbacks.rb +0 -151
  68. data/test/functional/test_dirty.rb +0 -163
  69. data/test/functional/test_document.rb +0 -1219
  70. data/test/functional/test_embedded_document.rb +0 -210
  71. data/test/functional/test_identity_map.rb +0 -507
  72. data/test/functional/test_indexing.rb +0 -44
  73. data/test/functional/test_logger.rb +0 -20
  74. data/test/functional/test_modifiers.rb +0 -394
  75. data/test/functional/test_pagination.rb +0 -93
  76. data/test/functional/test_protected.rb +0 -163
  77. data/test/functional/test_string_id_compatibility.rb +0 -67
  78. data/test/functional/test_timestamps.rb +0 -64
  79. data/test/functional/test_userstamps.rb +0 -28
  80. data/test/functional/test_validations.rb +0 -342
  81. data/test/models.rb +0 -227
  82. data/test/support/custom_matchers.rb +0 -37
  83. data/test/support/timing.rb +0 -16
  84. data/test/test_helper.rb +0 -64
  85. data/test/unit/associations/test_base.rb +0 -212
  86. data/test/unit/associations/test_proxy.rb +0 -105
  87. data/test/unit/serializers/test_json_serializer.rb +0 -202
  88. data/test/unit/test_descendant_appends.rb +0 -71
  89. data/test/unit/test_document.rb +0 -225
  90. data/test/unit/test_dynamic_finder.rb +0 -123
  91. data/test/unit/test_embedded_document.rb +0 -657
  92. data/test/unit/test_keys.rb +0 -185
  93. data/test/unit/test_mongo_mapper.rb +0 -118
  94. data/test/unit/test_pagination.rb +0 -160
  95. data/test/unit/test_plugins.rb +0 -50
  96. data/test/unit/test_query.rb +0 -374
  97. data/test/unit/test_rails.rb +0 -181
  98. data/test/unit/test_rails_compatibility.rb +0 -52
  99. data/test/unit/test_serialization.rb +0 -51
  100. data/test/unit/test_support.rb +0 -382
  101. data/test/unit/test_time_zones.rb +0 -39
  102. data/test/unit/test_validations.rb +0 -544
@@ -1,185 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Address
4
- include MongoMapper::EmbeddedDocument
5
-
6
- key :address, String
7
- key :city, String
8
- key :state, String
9
- key :zip, Integer
10
- end
11
-
12
- class FooType < Struct.new(:bar)
13
- def self.to_mongo(value)
14
- 'to_mongo'
15
- end
16
-
17
- def self.from_mongo(value)
18
- 'from_mongo'
19
- end
20
- end
21
-
22
- class KeyTest < Test::Unit::TestCase
23
- include MongoMapper::Plugins::Keys
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
-
37
- context "Initializing a new key" do
38
- should "allow setting the name" do
39
- Key.new(:foo, String).name.should == 'foo'
40
- end
41
-
42
- should "allow setting the type" do
43
- Key.new(:foo, Integer).type.should be(Integer)
44
- end
45
-
46
- should "allow setting options" do
47
- Key.new(:foo, Integer, :required => true).options[:required].should be(true)
48
- end
49
-
50
- should "default options to {}" do
51
- Key.new(:foo, Integer, nil).options.should == {}
52
- end
53
-
54
- should "symbolize option keys" do
55
- Key.new(:foo, Integer, 'required' => true).options[:required].should be(true)
56
- end
57
-
58
- should "work with just name" do
59
- key = Key.new(:foo)
60
- key.name.should == 'foo'
61
- end
62
-
63
- should "work with name and type" do
64
- key = Key.new(:foo, String)
65
- key.name.should == 'foo'
66
- key.type.should == String
67
- end
68
-
69
- should "work with name, type, and options" do
70
- key = Key.new(:foo, String, :required => true)
71
- key.name.should == 'foo'
72
- key.type.should == String
73
- key.options[:required].should be_true
74
- end
75
-
76
- should "work with name and options" do
77
- key = Key.new(:foo, :required => true)
78
- key.name.should == 'foo'
79
- key.options[:required].should be_true
80
- end
81
- end
82
-
83
- context "A key" do
84
- should "be equal to another key with same name and type" do
85
- Key.new(:name, String).should == Key.new(:name, String)
86
- end
87
-
88
- should "not be equal to another key with different name" do
89
- Key.new(:name, String).should_not == Key.new(:foo, String)
90
- end
91
-
92
- should "not be equal to another key with different type" do
93
- Key.new(:name, String).should_not == Key.new(:name, Integer)
94
- end
95
-
96
- should "know if it is a embedded_document" do
97
- Key.new(:name, EDoc()).embeddable?.should be_true
98
- end
99
-
100
- should "know if it is not a embedded_document" do
101
- Key.new(:name, String).embeddable?.should be_false
102
- end
103
-
104
- should "know if it is a number" do
105
- Key.new(:age, Integer).number?.should be_true
106
- Key.new(:age, Float).number?.should be_true
107
- end
108
-
109
- should "know if it is not a number" do
110
- Key.new(:age, String).number?.should be_false
111
- end
112
- end
113
-
114
- context "setting a value with a custom type" do
115
- should "correctly typecast" do
116
- key = Key.new(:foo, FooType)
117
- key.set("something").should == 'to_mongo'
118
- end
119
-
120
- should "correctly typecast if object of that type is given" do
121
- key = Key.new(:foo, FooType)
122
- key.set(FooType.new('something')).should == 'to_mongo'
123
- end
124
- end
125
-
126
- context "getting a value with a custom type" do
127
- should "use #from_mongo to convert back to custom type" do
128
- key = Key.new(:foo, FooType)
129
- key.get('something').should == 'from_mongo'
130
- end
131
- end
132
-
133
- context "getting a value" do
134
- should "work with a type" do
135
- key = Key.new(:foo, String)
136
- key.get('bar').should == 'bar'
137
- end
138
-
139
- should "work without type" do
140
- key = Key.new(:foo)
141
- key.get([1, '2']).should == [1, '2']
142
- key.get(false).should == false
143
- key.get({}).should == {}
144
- end
145
-
146
- context "for a embedded_document" do
147
- should "default to nil" do
148
- key = Key.new(:foo, Address)
149
- key.get(nil).should be_nil
150
- end
151
-
152
- should "return instance if instance" do
153
- address = Address.new(:city => 'South Bend', :state => 'IN', :zip => 46544)
154
- key = Key.new(:foo, Address)
155
- key.get(address).should == address
156
- end
157
- end
158
- end
159
-
160
- context "getting a value with a default set" do
161
- setup do
162
- @key = Key.new(:foo, String, :default => 'baz')
163
- end
164
-
165
- should "return default value if value nil" do
166
- @key.get(nil).should == 'baz'
167
- end
168
-
169
- should "return value if not blank" do
170
- @key.get('foobar').should == 'foobar'
171
- end
172
-
173
- should "work with Boolean type and false value" do
174
- Key.new(:active, Boolean, :default => false).get(nil).should be_false
175
- end
176
-
177
- should "work with Boolean type and true value" do
178
- Key.new(:active, Boolean, :default => true).get(nil).should be_true
179
- end
180
-
181
- should "work with procs" do
182
- Key.new(:foo, String, :default => lambda { return 'hello world' }).get(nil).should == "hello world"
183
- end
184
- end
185
- end # KeyTest
@@ -1,118 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Address; end
4
-
5
- class MongoMapperTest < Test::Unit::TestCase
6
- should "be able to write and read connection" do
7
- conn = Mongo::Connection.new
8
- MongoMapper.connection = conn
9
- MongoMapper.connection.should == conn
10
- end
11
-
12
- should "default connection to new mongo ruby driver" do
13
- MongoMapper.connection = nil
14
- MongoMapper.connection.should be_instance_of(Mongo::Connection)
15
- end
16
-
17
- should "be able to write and read default database" do
18
- MongoMapper.database = 'test'
19
- MongoMapper.database.should be_instance_of(Mongo::DB)
20
- MongoMapper.database.name.should == 'test'
21
- end
22
-
23
- should "have document not found error" do
24
- lambda {
25
- MongoMapper::DocumentNotFound
26
- }.should_not raise_error
27
- end
28
-
29
- should "be able to read/write config" do
30
- config = {
31
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'},
32
- 'production' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test-prod'}
33
- }
34
- MongoMapper.config = config
35
- MongoMapper.config.should == config
36
- end
37
-
38
- context "connecting to environment from config" do
39
- should "work without authentication" do
40
- MongoMapper.config = {
41
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
42
- }
43
- Mongo::Connection.expects(:new).with('127.0.0.1', 27017, {})
44
- MongoMapper.expects(:database=).with('test')
45
- Mongo::DB.any_instance.expects(:authenticate).never
46
- MongoMapper.connect('development')
47
- end
48
-
49
- should "work without authentication using uri" do
50
- MongoMapper.config = {
51
- 'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
52
- }
53
- Mongo::Connection.expects(:new).with('127.0.0.1', 27017, {})
54
- MongoMapper.expects(:database=).with('test')
55
- Mongo::DB.any_instance.expects(:authenticate).never
56
- MongoMapper.connect('development')
57
- end
58
-
59
- should "work with options" do
60
- MongoMapper.config = {
61
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
62
- }
63
- connection, logger = mock('connection'), mock('logger')
64
- Mongo::Connection.expects(:new).with('127.0.0.1', 27017, :logger => logger)
65
- MongoMapper.connect('development', :logger => logger)
66
- end
67
-
68
- should "work with options using uri" do
69
- MongoMapper.config = {
70
- 'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
71
- }
72
- connection, logger = mock('connection'), mock('logger')
73
- Mongo::Connection.expects(:new).with('127.0.0.1', 27017, :logger => logger)
74
- MongoMapper.connect('development', :logger => logger)
75
- end
76
-
77
- should "work with authentication" do
78
- MongoMapper.config = {
79
- 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'username' => 'john', 'password' => 'secret'}
80
- }
81
- Mongo::DB.any_instance.expects(:authenticate).with('john', 'secret')
82
- MongoMapper.connect('development')
83
- end
84
-
85
- should "work with authentication using uri" do
86
- MongoMapper.config = {
87
- 'development' => {'uri' => 'mongodb://john:secret@127.0.0.1:27017/test'}
88
- }
89
- Mongo::DB.any_instance.expects(:authenticate).with('john', 'secret')
90
- MongoMapper.connect('development')
91
- end
92
-
93
- should "raise error for invalid scheme" do
94
- MongoMapper.config = {
95
- 'development' => {'uri' => 'mysql://127.0.0.1:5336/foo'}
96
- }
97
- assert_raises(MongoMapper::InvalidScheme) { MongoMapper.connect('development') }
98
- end
99
- end
100
-
101
- context "setup" do
102
- should "work as shortcut for setting config, environment and options" do
103
- config, logger = mock('config'), mock('logger')
104
- MongoMapper.expects(:config=).with(config)
105
- MongoMapper.expects(:connect).with('development', :logger => logger)
106
- MongoMapper.expects(:handle_passenger_forking).never
107
- MongoMapper.setup(config, 'development', :logger => logger)
108
- end
109
-
110
- should "handle passenger if option present" do
111
- config, logger = mock('config'), mock('logger')
112
- MongoMapper.expects(:config=).with(config)
113
- MongoMapper.expects(:connect).with('development', :logger => logger)
114
- MongoMapper.expects(:handle_passenger_forking)
115
- MongoMapper.setup(config, 'development', :logger => logger, :passenger => true)
116
- end
117
- end
118
- end
@@ -1,160 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PaginationTest < Test::Unit::TestCase
4
- should "default per_page to 25" do
5
- Doc().per_page.should == 25
6
- end
7
-
8
- should "allow overriding per_page" do
9
- Doc() { def self.per_page; 1 end }.per_page.should == 1
10
- end
11
-
12
- context "Pagination proxy" do
13
- include MongoMapper::Plugins::Pagination
14
-
15
- should "respond_to? correctly on proxy readers" do
16
- proxy = Proxy.new(25, 10, 4)
17
- proxy.respond_to?(:subject).should be_true
18
- proxy.respond_to?(:total_entries).should be_true
19
- proxy.respond_to?(:per_page).should be_true
20
- proxy.respond_to?(:current_page).should be_true
21
- proxy.respond_to?(:limit).should be_true
22
- proxy.respond_to?(:total_pages).should be_true
23
- proxy.respond_to?(:out_of_bounds?).should be_true
24
- proxy.respond_to?(:previous_page).should be_true
25
- proxy.respond_to?(:next_page).should be_true
26
- proxy.respond_to?(:skip).should be_true
27
- proxy.respond_to?(:offset).should be_true
28
-
29
- # make sure it doesnt respond true to everything
30
- proxy.respond_to?(:blahblahblah).should be_false
31
- end
32
-
33
- should "respond_to? correctly on proxy writers" do
34
- proxy = Proxy.new(25, 10, 4)
35
- proxy.respond_to?(:subject=).should be_true
36
- end
37
-
38
- should "should have accessors for subject" do
39
- subject = [1,2,3,4,5]
40
- collection = Proxy.new(25, 2)
41
- collection.subject = subject
42
- collection.subject.should == subject
43
- end
44
-
45
- should "delegate any methods not defined to the subject" do
46
- subject = [1,2,3,4,5]
47
- collection = Proxy.new(25, 2, 10)
48
- collection.subject = subject
49
- collection.size.should == 5
50
- collection.each_with_index do |value, i|
51
- value.should == subject[i]
52
- end
53
- collection[0..2].should == [1,2,3]
54
- collection.class.should == Array
55
- end
56
-
57
- should "should respond_to? correctly for methods defined on the subject" do
58
- subject = [1,2,3,4,5]
59
- def subject.blahblah
60
- "BLAHBLAH"
61
- end
62
- collection = Proxy.new(25, 2, 10)
63
- collection.subject = subject
64
- collection.respond_to?(:blahblah).should be_true
65
- end
66
-
67
- should "return correct value for total_entries" do
68
- Proxy.new(25, 2, 10).total_entries.should == 25
69
- Proxy.new('25', 2, 10).total_entries.should == 25
70
- end
71
-
72
- should "return correct value for per_page" do
73
- Proxy.new(25, 2, 10).per_page.should == 10
74
- Proxy.new(25, 2, '10').per_page.should == 10
75
- end
76
-
77
- should "alias limit to per_page" do
78
- Proxy.new(100, 1, 300).limit.should == 300
79
- end
80
-
81
- should "set per_page to 25 if nil or blank" do
82
- Proxy.new(25, 2).per_page.should == 25
83
- Proxy.new(25, 2, '').per_page.should == 25
84
- end
85
-
86
- should "return correct value for current_page" do
87
- Proxy.new(25, 2, 10).current_page.should == 2
88
- Proxy.new(25, '2', 10).current_page.should == 2
89
- end
90
-
91
- should "not allow value less than 1 for current page" do
92
- Proxy.new(25, -1).current_page.should == 1
93
- end
94
-
95
- should "automatically calculate total_pages from total_entries and per page" do
96
- Proxy.new(25, 2, 10).total_pages.should == 3
97
- end
98
-
99
- should "know how many records to skip" do
100
- Proxy.new(25, 2, 10).skip.should == 10
101
- end
102
-
103
- should "alias offset to skip" do
104
- Proxy.new(25, 2, 10).offset.should == 10
105
- end
106
-
107
- should "return true for === Array" do
108
- collection = Proxy.new(25, 2, 10)
109
- collection.subject = [1, 2]
110
- collection.should === Array
111
- end
112
-
113
- context "previous_page" do
114
- should "be nil if current page 1" do
115
- Proxy.new(25, 1, 10).previous_page.should be_nil
116
- end
117
-
118
- should "be one less than current page if current is > 1" do
119
- Proxy.new(25, 2, 10).previous_page.should == 1
120
- end
121
- end
122
-
123
- context "next_page" do
124
- should "be nil if current page is last page" do
125
- Proxy.new(25, 3, 10).next_page.should be_nil
126
- end
127
-
128
- should "work for any page that is not last" do
129
- Proxy.new(25, 1, 10).next_page.should == 2
130
- Proxy.new(25, 2, 10).next_page.should == 3
131
- end
132
- end
133
-
134
- context "previous_page" do
135
- should "be nil if current page is first page" do
136
- Proxy.new(25, 1, 10).previous_page.should be_nil
137
- end
138
-
139
- should "work for any page other than first" do
140
- Proxy.new(25, 2, 10).previous_page.should == 1
141
- Proxy.new(25, 3, 10).previous_page.should == 2
142
- end
143
- end
144
-
145
- context "out_of_bounds?" do
146
- should "be true if current_page is greater than total_pages" do
147
- Proxy.new(25, 10, 4).out_of_bounds?.should be_true
148
- end
149
-
150
- should "be false if current_page is less than total_pages" do
151
- Proxy.new(25, 10, 1).out_of_bounds?.should be_false
152
- Proxy.new(25, 2, 10).out_of_bounds?.should be_false
153
- end
154
-
155
- should "be false if current_page is equal to total_pages" do
156
- Proxy.new(25, 3, 10).out_of_bounds?.should be_false
157
- end
158
- end
159
- end
160
- end