djsun-mongomapper 0.3.5.5 → 0.4.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README.rdoc +38 -38
  2. data/Rakefile +87 -73
  3. data/VERSION +1 -1
  4. data/lib/mongomapper.rb +67 -71
  5. data/lib/mongomapper/associations.rb +86 -84
  6. data/lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb +34 -34
  7. data/lib/mongomapper/associations/many_embedded_proxy.rb +67 -17
  8. data/lib/mongomapper/associations/proxy.rb +74 -73
  9. data/lib/mongomapper/document.rb +342 -348
  10. data/lib/mongomapper/embedded_document.rb +354 -274
  11. data/lib/mongomapper/finder_options.rb +84 -84
  12. data/lib/mongomapper/key.rb +32 -76
  13. data/lib/mongomapper/rails_compatibility/document.rb +14 -14
  14. data/lib/mongomapper/rails_compatibility/embedded_document.rb +26 -24
  15. data/lib/mongomapper/support.rb +156 -29
  16. data/lib/mongomapper/validations.rb +69 -47
  17. data/test/custom_matchers.rb +48 -0
  18. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +53 -56
  19. data/test/functional/associations/test_belongs_to_proxy.rb +48 -49
  20. data/test/functional/associations/test_many_documents_as_proxy.rb +208 -253
  21. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +130 -130
  22. data/test/functional/associations/test_many_embedded_proxy.rb +168 -106
  23. data/test/functional/associations/test_many_polymorphic_proxy.rb +261 -262
  24. data/test/functional/test_binary.rb +21 -0
  25. data/test/functional/test_document.rb +946 -952
  26. data/test/functional/test_embedded_document.rb +98 -0
  27. data/test/functional/test_pagination.rb +87 -80
  28. data/test/functional/test_rails_compatibility.rb +29 -29
  29. data/test/functional/test_validations.rb +262 -172
  30. data/test/models.rb +169 -169
  31. data/test/test_helper.rb +28 -66
  32. data/test/unit/serializers/test_json_serializer.rb +193 -193
  33. data/test/unit/test_document.rb +161 -123
  34. data/test/unit/test_embedded_document.rb +643 -547
  35. data/test/unit/test_finder_options.rb +183 -183
  36. data/test/unit/test_key.rb +175 -247
  37. data/test/unit/test_rails_compatibility.rb +38 -33
  38. data/test/unit/test_serializations.rb +52 -52
  39. data/test/unit/test_support.rb +268 -0
  40. data/test/unit/test_time_zones.rb +40 -0
  41. data/test/unit/test_validations.rb +499 -258
  42. metadata +22 -12
  43. data/History +0 -76
  44. data/mongomapper.gemspec +0 -145
@@ -1,39 +1,39 @@
1
- = MongoMapper
2
-
3
- Awesome gem for modeling your domain and storing it in mongo.
4
-
5
- Releases are tagged on github and also released as gems on github and rubyforge. Master is pushed to whenever I add a patch or a new feature. To build from master, you can clone the code, generate the updated gemspec, build the gem and install.
6
-
7
- * rake gemspec
8
- * gem build mongomapper.gemspec
9
- * gem install the gem that was built
10
-
11
- == Note on Patches/Pull Requests
12
-
13
- * Fork the project.
14
- * Make your feature addition or bug fix.
15
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
16
- * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
17
- * Send me a pull request. Bonus points for topic branches.
18
-
19
- == Dependencies
20
-
21
- * ActiveSupport (activesupport)
22
- * Mongo Ruby Driver (mongodb-mongo)
23
- * My fork of the validatable gem (jnunemaker-validatable)
24
-
25
- == Documentation
26
-
27
- http://rdoc.info/projects/jnunemaker/mongomapper
28
-
29
- == More Info
30
-
31
- You can learn more about mongo here:
32
- http://www.mongodb.org/
33
-
34
- You can learn more about the mongo ruby driver here:
35
- http://github.com/mongodb/mongo-ruby-driver/tree/master
36
-
37
- == Copyright
38
-
1
+ = MongoMapper
2
+
3
+ Awesome gem for modeling your domain and storing it in mongo.
4
+
5
+ Releases are tagged on github and also released as gems on github and rubyforge. Master is pushed to whenever I add a patch or a new feature. To build from master, you can clone the code, generate the updated gemspec, build the gem and install.
6
+
7
+ * rake gemspec
8
+ * gem build mongomapper.gemspec
9
+ * gem install the gem that was built
10
+
11
+ == Note on Patches/Pull Requests
12
+
13
+ * Fork the project.
14
+ * Make your feature addition or bug fix.
15
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
16
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
17
+ * Send me a pull request. Bonus points for topic branches.
18
+
19
+ == Dependencies
20
+
21
+ * ActiveSupport (activesupport)
22
+ * Mongo Ruby Driver (mongo)
23
+ * My fork of the validatable gem (jnunemaker-validatable)
24
+
25
+ == Documentation
26
+
27
+ http://rdoc.info/projects/jnunemaker/mongomapper
28
+
29
+ == More Info
30
+
31
+ You can learn more about mongo here:
32
+ http://www.mongodb.org/
33
+
34
+ You can learn more about the mongo ruby driver here:
35
+ http://github.com/mongodb/mongo-ruby-driver/tree/master
36
+
37
+ == Copyright
38
+
39
39
  Copyright (c) 2009 John Nunemaker. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,73 +1,87 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "mongomapper"
8
- gem.summary = %Q{Awesome gem for modeling your domain and storing it in mongo}
9
- gem.email = "nunemaker@gmail.com"
10
- gem.homepage = "http://github.com/jnunemaker/mongomapper"
11
- gem.authors = ["John Nunemaker"]
12
- gem.rubyforge_project = "mongomapper"
13
-
14
- gem.add_dependency('activesupport')
15
- gem.add_dependency('mongodb-mongo', '0.14.1')
16
- gem.add_dependency('jnunemaker-validatable', '1.7.2')
17
-
18
- gem.add_development_dependency('mocha', '0.9.4')
19
- gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
20
- end
21
-
22
- Jeweler::RubyforgeTasks.new do |rubyforge|
23
- rubyforge.doc_task = "rdoc"
24
- end
25
- rescue LoadError
26
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
27
- end
28
-
29
- require 'rake/testtask'
30
- Rake::TestTask.new(:test) do |test|
31
- test.libs << 'lib' << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
-
36
- begin
37
- require 'rcov/rcovtask'
38
- Rcov::RcovTask.new do |test|
39
- test.libs << 'test'
40
- test.pattern = 'test/**/test_*.rb'
41
- test.verbose = true
42
- end
43
- rescue LoadError
44
- task :rcov do
45
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
46
- end
47
- end
48
-
49
- begin
50
- require 'cucumber/rake/task'
51
- Cucumber::Rake::Task.new(:features)
52
- rescue LoadError
53
- task :features do
54
- abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
55
- end
56
- end
57
-
58
- task :default => :test
59
-
60
- require 'rake/rdoctask'
61
- Rake::RDocTask.new do |rdoc|
62
- if File.exist?('VERSION.yml')
63
- config = YAML.load(File.read('VERSION.yml'))
64
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
65
- else
66
- version = ""
67
- end
68
-
69
- rdoc.rdoc_dir = 'rdoc'
70
- rdoc.title = "MongoMapper #{version}"
71
- rdoc.rdoc_files.include('README*')
72
- rdoc.rdoc_files.include('lib/**/*.rb')
73
- end
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "djsun-mongomapper"
8
+ gem.summary = %Q{Map your domain to MongoDB}
9
+ gem.email = "djames@sunlightfoundation.com"
10
+ gem.homepage = "http://github.com/djsun/mongomapper"
11
+ gem.authors = ["John Nunemaker", "David James"]
12
+ # gem.rubyforge_project = "djsun-mongomapper"
13
+
14
+ gem.add_dependency('activesupport')
15
+ gem.add_dependency('mongo', '0.15')
16
+ gem.add_dependency('jnunemaker-validatable', '1.7.2')
17
+
18
+ gem.add_development_dependency('mocha', '0.9.4')
19
+ gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
20
+ end
21
+
22
+ Jeweler::RubyforgeTasks.new do |rubyforge|
23
+ rubyforge.doc_task = "rdoc"
24
+ end
25
+ rescue LoadError
26
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
27
+ end
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ namespace :test do
37
+ Rake::TestTask.new(:units) do |test|
38
+ test.libs << 'lib' << 'test'
39
+ test.pattern = 'test/unit/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ Rake::TestTask.new(:functionals) do |test|
44
+ test.libs << 'lib' << 'test'
45
+ test.pattern = 'test/functional/**/test_*.rb'
46
+ test.verbose = true
47
+ end
48
+ end
49
+
50
+ begin
51
+ require 'rcov/rcovtask'
52
+ Rcov::RcovTask.new do |test|
53
+ test.libs << 'test'
54
+ test.pattern = 'test/**/test_*.rb'
55
+ test.verbose = true
56
+ end
57
+ rescue LoadError
58
+ task :rcov do
59
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
60
+ end
61
+ end
62
+
63
+ begin
64
+ require 'cucumber/rake/task'
65
+ Cucumber::Rake::Task.new(:features)
66
+ rescue LoadError
67
+ task :features do
68
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
69
+ end
70
+ end
71
+
72
+ task :default => :test
73
+
74
+ require 'rake/rdoctask'
75
+ Rake::RDocTask.new do |rdoc|
76
+ if File.exist?('VERSION.yml')
77
+ config = YAML.load(File.read('VERSION.yml'))
78
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
79
+ else
80
+ version = ""
81
+ end
82
+
83
+ rdoc.rdoc_dir = 'rdoc'
84
+ rdoc.title = "MongoMapper #{version}"
85
+ rdoc.rdoc_files.include('README*')
86
+ rdoc.rdoc_files.include('lib/**/*.rb')
87
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5.5
1
+ 0.4.1.2
@@ -1,71 +1,67 @@
1
- require 'pathname'
2
- require 'rubygems'
3
-
4
- gem 'activesupport'
5
- gem 'mongodb-mongo', '0.14.1'
6
- gem 'jnunemaker-validatable', '1.7.2'
7
-
8
- # require 'activesupport'
9
- require 'mongo'
10
- require 'validatable'
11
-
12
- dir = Pathname(__FILE__).dirname.expand_path + 'mongomapper'
13
-
14
- require dir + 'support'
15
-
16
- require dir + 'associations'
17
- require dir + 'associations/base'
18
-
19
- require dir + 'associations/proxy'
20
- require dir + 'associations/many_documents_proxy'
21
-
22
- require dir + 'associations/belongs_to_proxy'
23
- require dir + 'associations/belongs_to_polymorphic_proxy'
24
- require dir + 'associations/many_proxy'
25
- require dir + 'associations/many_polymorphic_proxy'
26
- require dir + 'associations/many_embedded_proxy'
27
- require dir + 'associations/many_embedded_polymorphic_proxy'
28
- require dir + 'associations/many_documents_as_proxy'
29
-
30
- require dir + 'callbacks'
31
- require dir + 'finder_options'
32
- require dir + 'dynamic_finder'
33
- require dir + 'key'
34
- require dir + 'observing'
35
- require dir + 'pagination'
36
- require dir + 'save_with_validation'
37
- require dir + 'serialization'
38
- require dir + 'validations'
39
-
40
- require dir + 'rails_compatibility/document'
41
- require dir + 'rails_compatibility/embedded_document'
42
-
43
- require dir + 'embedded_document'
44
- require dir + 'document'
45
-
46
- module MongoMapper
47
- DocumentNotFound = Class.new(StandardError)
48
-
49
- DocumentNotValid = Class.new(StandardError) do
50
- def initialize(document)
51
- @document = document
52
- super("Validation failed: #{@document.errors.full_messages.join(", ")}")
53
- end
54
- end
55
-
56
- def self.connection
57
- @@connection ||= Mongo::Connection.new
58
- end
59
-
60
- def self.connection=(new_connection)
61
- @@connection = new_connection
62
- end
63
-
64
- def self.database=(name)
65
- @@database = MongoMapper.connection.db(name)
66
- end
67
-
68
- def self.database
69
- @@database
70
- end
71
- end
1
+ require 'rubygems'
2
+
3
+ gem 'activesupport'
4
+ gem 'mongo', '0.15'
5
+ gem 'jnunemaker-validatable', '1.7.2'
6
+
7
+ require 'activesupport'
8
+ require 'mongo'
9
+ require 'validatable'
10
+
11
+ require 'mongomapper/support'
12
+ require 'mongomapper/associations'
13
+ require 'mongomapper/associations/base'
14
+ require 'mongomapper/associations/proxy'
15
+ require 'mongomapper/associations/many_documents_proxy'
16
+ require 'mongomapper/associations/belongs_to_proxy'
17
+ require 'mongomapper/associations/belongs_to_polymorphic_proxy'
18
+ require 'mongomapper/associations/many_proxy'
19
+ require 'mongomapper/associations/many_polymorphic_proxy'
20
+ require 'mongomapper/associations/many_embedded_proxy'
21
+ require 'mongomapper/associations/many_embedded_polymorphic_proxy'
22
+ require 'mongomapper/associations/many_documents_as_proxy'
23
+ require 'mongomapper/callbacks'
24
+ require 'mongomapper/finder_options'
25
+ require 'mongomapper/dynamic_finder'
26
+ require 'mongomapper/key'
27
+ require 'mongomapper/observing'
28
+ require 'mongomapper/pagination'
29
+ require 'mongomapper/save_with_validation'
30
+ require 'mongomapper/serialization'
31
+ require 'mongomapper/validations'
32
+ require 'mongomapper/rails_compatibility/document'
33
+ require 'mongomapper/rails_compatibility/embedded_document'
34
+ require 'mongomapper/embedded_document'
35
+ require 'mongomapper/document'
36
+
37
+ module MongoMapper
38
+ DocumentNotFound = Class.new(StandardError)
39
+
40
+ DocumentNotValid = Class.new(StandardError) do
41
+ def initialize(document)
42
+ @document = document
43
+ super("Validation failed: #{@document.errors.full_messages.join(", ")}")
44
+ end
45
+ end
46
+
47
+ def self.connection
48
+ @@connection ||= Mongo::Connection.new
49
+ end
50
+
51
+ def self.connection=(new_connection)
52
+ @@connection = new_connection
53
+ end
54
+
55
+ def self.database=(name)
56
+ @@database = nil
57
+ @@database_name = name
58
+ end
59
+
60
+ def self.database
61
+ if @@database_name.blank?
62
+ raise 'You forgot to set the default database name: MongoMapper.database = "foobar"'
63
+ end
64
+
65
+ @@database ||= MongoMapper.connection.db(@@database_name)
66
+ end
67
+ end
@@ -1,84 +1,86 @@
1
- module MongoMapper
2
- module Associations
3
- module ClassMethods
4
- def belongs_to(association_id, options = {})
5
- create_association(:belongs_to, association_id, options)
6
- self
7
- end
8
-
9
- def many(association_id, options = {})
10
- create_association(:many, association_id, options)
11
- self
12
- end
13
-
14
- def associations
15
- @associations ||= HashWithIndifferentAccess.new
16
- end
17
-
18
- private
19
- def create_association(type, name, options)
20
- association = Associations::Base.new(type, name, options)
21
- associations[association.name] = association
22
- define_association_methods(association)
23
- define_dependent_callback(association)
24
- association
25
- end
26
-
27
- def define_association_methods(association)
28
- define_method(association.name) do
29
- get_proxy(association)
30
- end
31
-
32
- define_method("#{association.name}=") do |value|
33
- get_proxy(association).replace(value)
34
- value
35
- end
36
- end
37
-
38
- def define_dependent_callback(association)
39
- if association.options[:dependent]
40
- if association.many?
41
- define_dependent_callback_for_many(association)
42
- elsif association.belongs_to?
43
- define_dependent_callback_for_belongs_to(association)
44
- end
45
- end
46
- end
47
-
48
- def define_dependent_callback_for_many(association)
49
- return if association.embeddable?
50
-
51
- after_destroy do |doc|
52
- case association.options[:dependent]
53
- when :destroy
54
- doc.get_proxy(association).destroy_all
55
- when :delete_all
56
- doc.get_proxy(association).delete_all
57
- when :nullify
58
- doc.get_proxy(association).nullify
59
- end
60
- end
61
- end
62
-
63
- def define_dependent_callback_for_belongs_to(association)
64
- after_destroy do |doc|
65
- case association.options[:dependent]
66
- when :destroy
67
- doc.get_proxy(association).destroy
68
- end
69
- end
70
- end
71
- end
72
-
73
- module InstanceMethods
74
- def get_proxy(association)
75
- unless proxy = self.instance_variable_get(association.ivar)
76
- proxy = association.proxy_class.new(self, association)
77
- self.instance_variable_set(association.ivar, proxy) if !frozen?
78
- end
79
-
80
- proxy
81
- end
82
- end
83
- end
84
- end
1
+ module MongoMapper
2
+ module Associations
3
+ module ClassMethods
4
+ def belongs_to(association_id, options = {})
5
+ create_association(:belongs_to, association_id, options)
6
+ self
7
+ end
8
+
9
+ def many(association_id, options = {})
10
+ create_association(:many, association_id, options)
11
+ self
12
+ end
13
+
14
+ def associations
15
+ @associations ||= self.superclass.respond_to?(:associations) ?
16
+ self.superclass.associations :
17
+ HashWithIndifferentAccess.new
18
+ end
19
+
20
+ private
21
+ def create_association(type, name, options)
22
+ association = Associations::Base.new(type, name, options)
23
+ associations[association.name] = association
24
+ define_association_methods(association)
25
+ define_dependent_callback(association)
26
+ association
27
+ end
28
+
29
+ def define_association_methods(association)
30
+ define_method(association.name) do
31
+ get_proxy(association)
32
+ end
33
+
34
+ define_method("#{association.name}=") do |value|
35
+ get_proxy(association).replace(value)
36
+ value
37
+ end
38
+ end
39
+
40
+ def define_dependent_callback(association)
41
+ if association.options[:dependent]
42
+ if association.many?
43
+ define_dependent_callback_for_many(association)
44
+ elsif association.belongs_to?
45
+ define_dependent_callback_for_belongs_to(association)
46
+ end
47
+ end
48
+ end
49
+
50
+ def define_dependent_callback_for_many(association)
51
+ return if association.embeddable?
52
+
53
+ after_destroy do |doc|
54
+ case association.options[:dependent]
55
+ when :destroy
56
+ doc.get_proxy(association).destroy_all
57
+ when :delete_all
58
+ doc.get_proxy(association).delete_all
59
+ when :nullify
60
+ doc.get_proxy(association).nullify
61
+ end
62
+ end
63
+ end
64
+
65
+ def define_dependent_callback_for_belongs_to(association)
66
+ after_destroy do |doc|
67
+ case association.options[:dependent]
68
+ when :destroy
69
+ doc.get_proxy(association).destroy
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ module InstanceMethods
76
+ def get_proxy(association)
77
+ unless proxy = self.instance_variable_get(association.ivar)
78
+ proxy = association.proxy_class.new(self, association)
79
+ self.instance_variable_set(association.ivar, proxy) if !frozen?
80
+ end
81
+
82
+ proxy
83
+ end
84
+ end
85
+ end
86
+ end