Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First stab at toystore integration. Still some work to do.

  • Loading branch information...
commit 694bf21530c9a495768a38bb2881f1f85c732a9f 1 parent 4a8b31d
@jwood authored
Showing with 418 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +2 −0  lib/tenacity.rb
  3. +113 −0 lib/tenacity/orm_ext/toystore.rb
  4. +4 −0 tenacity.gemspec
  5. +2 −0  test/fixtures/active_record_has_many_target.rb
  6. +2 −0  test/fixtures/active_record_has_one_target.rb
  7. +4 −0 test/fixtures/active_record_object.rb
  8. +2 −0  test/fixtures/couch_rest_has_many_target.rb
  9. +2 −0  test/fixtures/couch_rest_has_one_target.rb
  10. +4 −0 test/fixtures/couch_rest_object.rb
  11. +5 −0 test/fixtures/data_mapper_has_many_target.rb
  12. +5 −0 test/fixtures/data_mapper_has_one_target.rb
  13. +4 −0 test/fixtures/data_mapper_object.rb
  14. +2 −0  test/fixtures/mongo_mapper_has_many_target.rb
  15. +2 −0  test/fixtures/mongo_mapper_has_one_target.rb
  16. +4 −0 test/fixtures/mongo_mapper_object.rb
  17. +2 −0  test/fixtures/mongoid_has_many_target.rb
  18. +2 −0  test/fixtures/mongoid_has_one_target.rb
  19. +4 −0 test/fixtures/mongoid_object.rb
  20. +2 −0  test/fixtures/ripple_has_many_target.rb
  21. +2 −0  test/fixtures/ripple_has_one_target.rb
  22. +4 −0 test/fixtures/ripple_object.rb
  23. +2 −0  test/fixtures/sequel_has_many_target.rb
  24. +2 −0  test/fixtures/sequel_has_one_target.rb
  25. +4 −0 test/fixtures/sequel_object.rb
  26. +28 −0 test/fixtures/toystore_has_many_target.rb
  27. +28 −0 test/fixtures/toystore_has_one_target.rb
  28. +46 −0 test/fixtures/toystore_object.rb
  29. +6 −0 test/helpers/active_record_test_helper.rb
  30. +6 −0 test/helpers/sequel_test_helper.rb
  31. +17 −0 test/helpers/toystore_test_helper.rb
  32. +103 −0 test/orm_ext/toystore_test.rb
  33. +2 −0  test/test_helper.rb
View
1  .gitignore
@@ -8,3 +8,4 @@ doc/
coverage/
pkg/
Gemfile.lock
+log/
View
2  lib/tenacity.rb
@@ -17,6 +17,7 @@
require File.join(File.dirname(__FILE__), 'tenacity', 'orm_ext', 'mongoid')
require File.join(File.dirname(__FILE__), 'tenacity', 'orm_ext', 'ripple')
require File.join(File.dirname(__FILE__), 'tenacity', 'orm_ext', 'sequel')
+require File.join(File.dirname(__FILE__), 'tenacity', 'orm_ext', 'toystore')
module Tenacity #:nodoc:
include InstanceMethods
@@ -33,6 +34,7 @@ def self.included(model)
OrmExt::Mongoid.setup(model)
OrmExt::Ripple.setup(model)
OrmExt::Sequel.setup(model)
+ OrmExt::Toystore.setup(model)
raise "Tenacity does not support the database client used by #{model}" unless model.respond_to?(:_t_find)
model.extend(ClassMethods)
View
113 lib/tenacity/orm_ext/toystore.rb
@@ -0,0 +1,113 @@
+module Tenacity
+ module OrmExt
+ #
+ # Tenacity relationships on Toystore objects require no special attributes
+ # defined on the object. Tenacity will define the attributes that it needs
+ # to support the relationships. Take the following class for example:
+ #
+ # class Car
+ # include Toy::Store
+ # store :mongo, Mongo::Connection.new.db('tenacity')['toystore']
+ # include Tenacity
+ #
+ # t_has_many :wheels
+ # t_has_one :dashboard
+ # t_belongs_to :driver
+ # end
+ #
+ # *Please note that the data store must be established before including the Tenacity module.*
+ #
+ # == t_belongs_to
+ #
+ # The +t_belongs_to+ association will define an attribute named after the association.
+ # The example above will create an attribute named <tt>:driver_id</tt>
+ #
+ #
+ # == t_has_one
+ #
+ # The +t_has_one+ association will not define any new attributes on the object, since
+ # the associated object holds the foreign key.
+ #
+ #
+ # == t_has_many
+ #
+ # The +t_has_many+ association will define an attribute named after the association.
+ # The example above will create attribute named <tt>:wheels_ids</tt>
+ #
+ module Toystore
+
+ def self.setup(model) #:nodoc:
+ require 'toystore'
+ if model.included_modules.include?(::Toy::Store)
+ model.send :include, Toystore::InstanceMethods
+ model.extend Toystore::ClassMethods
+ end
+ rescue LoadError
+ # Toystore not available
+ end
+
+ module ClassMethods #:nodoc:
+ include Tenacity::OrmExt::Helpers
+
+ def _t_id_type
+ String
+ end
+
+ def _t_find(id)
+ (id.nil? || id.to_s.strip == "") ? nil : get(_t_serialize(id))
+ end
+
+ def _t_find_bulk(ids)
+ get_multi(_t_serialize_ids(ids)).compact
+ end
+
+ def _t_find_first_by_associate(property, id)
+ send("first_by_#{property}", id)
+ end
+
+ def _t_find_all_by_associate(property, id)
+ get_multi(_t_find_all_ids_by_associate(property, id))
+ end
+
+ def _t_find_all_ids_by_associate(property, id)
+ get_index(property.to_sym, id)
+ end
+
+ def _t_initialize_tenacity
+ before_save { |record| record._t_verify_associates_exist }
+ after_save { |record| record._t_save_autosave_associations }
+ end
+
+ def _t_initialize_has_one_association(association)
+ before_destroy { |record| record._t_cleanup_has_one_association(association) }
+ end
+
+ def _t_initialize_has_many_association(association)
+ after_save { |record| self.class._t_save_associates(record, association) }
+ before_destroy { |record| record._t_cleanup_has_many_association(association) }
+ end
+
+ def _t_initialize_belongs_to_association(association)
+ before_destroy { |record| record._t_cleanup_belongs_to_association(association) }
+ attribute association.foreign_key, id_class_for(association)
+ attribute association.polymorphic_type, String if association.polymorphic?
+ index(association.foreign_key.to_sym)
+ end
+
+ def _t_delete(ids, run_callbacks=true)
+ if run_callbacks
+ destroy(*ids)
+ else
+ delete(*ids)
+ end
+ end
+ end
+
+ module InstanceMethods #:nodoc:
+ def _t_reload
+ reload
+ end
+ end
+ end
+ end
+end
View
4 tenacity.gemspec
@@ -44,6 +44,10 @@ Gem::Specification.new do |s|
# Riak
s.add_development_dependency "ripple", "~> 0.9.2"
+ # Multiple
+ s.add_development_dependency "toystore", "~> 0.8.0"
+ s.add_development_dependency "adapter-mongo", "~> 0.5.2"
+
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
s.require_path = 'lib'
View
2  test/fixtures/active_record_has_many_target.rb
@@ -8,6 +8,7 @@ class ActiveRecordHasManyTarget < ActiveRecord::Base
require_mongoid { t_belongs_to :mongoid_object }
require_ripple { t_belongs_to :ripple_object }
t_belongs_to :sequel_object
+ require_toystore { t_belongs_to :toystore_object }
t_belongs_to :active_record_has_many_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_many_target_testable, :polymorphic => true
@@ -16,4 +17,5 @@ class ActiveRecordHasManyTarget < ActiveRecord::Base
require_mongoid { t_belongs_to :mongoid_has_many_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_many_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_many_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_many_target_testable, :polymorphic => true }
end
View
2  test/fixtures/active_record_has_one_target.rb
@@ -8,6 +8,7 @@ class ActiveRecordHasOneTarget < ActiveRecord::Base
require_mongoid { t_belongs_to :mongoid_object }
require_ripple { t_belongs_to :ripple_object }
t_belongs_to :sequel_object
+ require_toystore { t_belongs_to :toystore_object }
t_belongs_to :active_record_has_one_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_one_target_testable, :polymorphic => true
@@ -16,4 +17,5 @@ class ActiveRecordHasOneTarget < ActiveRecord::Base
require_mongoid { t_belongs_to :mongoid_has_one_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_one_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_one_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_one_target_testable, :polymorphic => true }
end
View
4 test/fixtures/active_record_object.rb
@@ -8,6 +8,7 @@ class ActiveRecordObject < ActiveRecord::Base
require_mongoid { t_has_one :mongoid_has_one_target }
require_ripple { t_has_one :ripple_has_one_target }
t_has_one :sequel_has_one_target
+ require_toystore { t_has_one :toystore_has_one_target }
t_has_one :active_record_has_one_target, :as => :active_record_has_one_target_testable
t_has_one :couch_rest_has_one_target, :as => :couch_rest_has_one_target_testable
@@ -16,6 +17,7 @@ class ActiveRecordObject < ActiveRecord::Base
require_mongoid { t_has_one :mongoid_has_one_target, :as => :mongoid_has_one_target_testable }
require_ripple { t_has_one :ripple_has_one_target, :as => :ripple_has_one_target_testable }
t_has_one :sequel_has_one_target, :as => :sequel_has_one_target_testable
+ require_toystore { t_has_one :toystore_has_one_target, :as => :toystore_has_one_target_testable }
t_has_many :active_record_has_many_targets
t_has_many :couch_rest_has_many_targets
@@ -24,6 +26,7 @@ class ActiveRecordObject < ActiveRecord::Base
require_mongoid { t_has_many :mongoid_has_many_targets }
require_ripple { t_has_many :ripple_has_many_targets }
t_has_many :sequel_has_many_targets
+ require_toystore { t_has_many :toystore_has_many_targets }
t_has_many :active_record_has_many_targets, :as => :active_record_has_many_target_testable
t_has_many :couch_rest_has_many_targets, :as => :couch_rest_has_many_target_testable
@@ -32,6 +35,7 @@ class ActiveRecordObject < ActiveRecord::Base
require_mongoid { t_has_many :mongoid_has_many_targets, :as => :mongoid_has_many_target_testable }
require_ripple { t_has_many :ripple_has_many_targets, :as => :ripple_has_many_target_testable }
t_has_many :sequel_has_many_targets, :as => :sequel_has_many_target_testable
+ require_toystore { t_has_many :toystore_has_many_targets, :as => :toystore_has_many_target_testable }
t_has_one :mongo_mapper_autosave_true_has_one_target, :autosave => true
t_has_one :mongo_mapper_autosave_false_has_one_target, :autosave => false
View
2  test/fixtures/couch_rest_has_many_target.rb
@@ -9,6 +9,7 @@ class CouchRestHasManyTarget < CouchRest::Model::Base
require_mongoid { t_belongs_to :mongoid_object }
require_ripple { t_belongs_to :ripple_object }
t_belongs_to :sequel_object
+ require_toystore { t_belongs_to :toystore_object }
t_belongs_to :active_record_has_many_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_many_target_testable, :polymorphic => true
@@ -17,5 +18,6 @@ class CouchRestHasManyTarget < CouchRest::Model::Base
require_mongoid { t_belongs_to :mongoid_has_many_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_many_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_many_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_many_target_testable, :polymorphic => true }
end
View
2  test/fixtures/couch_rest_has_one_target.rb
@@ -9,6 +9,7 @@ class CouchRestHasOneTarget < CouchRest::Model::Base
require_mongoid { t_belongs_to :mongoid_object }
require_ripple { t_belongs_to :ripple_object }
t_belongs_to :sequel_object
+ require_toystore { t_belongs_to :toystore_object }
t_belongs_to :active_record_has_one_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_one_target_testable, :polymorphic => true
@@ -17,5 +18,6 @@ class CouchRestHasOneTarget < CouchRest::Model::Base
require_mongoid { t_belongs_to :mongoid_has_one_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_one_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_one_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_one_target_testable, :polymorphic => true }
end
View
4 test/fixtures/couch_rest_object.rb
@@ -9,6 +9,7 @@ class CouchRestObject < CouchRest::Model::Base
require_mongoid { t_has_one :mongoid_has_one_target }
require_ripple { t_has_one :ripple_has_one_target }
t_has_one :sequel_has_one_target
+ require_toystore { t_has_one :toystore_has_one_target }
t_has_many :active_record_has_many_targets
t_has_many :couch_rest_has_many_targets
@@ -17,6 +18,7 @@ class CouchRestObject < CouchRest::Model::Base
require_mongoid { t_has_many :mongoid_has_many_targets }
require_ripple { t_has_many :ripple_has_many_targets }
t_has_many :sequel_has_many_targets
+ require_toystore { t_has_many :toystore_has_many_targets }
t_has_one :active_record_has_one_target, :as => :active_record_has_one_target_testable
t_has_one :couch_rest_has_one_target, :as => :couch_rest_has_one_target_testable
@@ -25,6 +27,7 @@ class CouchRestObject < CouchRest::Model::Base
require_mongoid { t_has_one :mongoid_has_one_target, :as => :mongoid_has_one_target_testable }
require_ripple { t_has_one :ripple_has_one_target, :as => :ripple_has_one_target_testable }
t_has_one :sequel_has_one_target, :as => :sequel_has_one_target_testable
+ require_toystore { t_has_one :toystore_has_one_target, :as => :toystore_has_one_target_testable }
t_has_many :active_record_has_many_targets, :as => :active_record_has_many_target_testable
t_has_many :couch_rest_has_many_targets, :as => :couch_rest_has_many_target_testable
@@ -33,5 +36,6 @@ class CouchRestObject < CouchRest::Model::Base
require_mongoid { t_has_many :mongoid_has_many_targets, :as => :mongoid_has_many_target_testable }
require_ripple { t_has_many :ripple_has_many_targets, :as => :ripple_has_many_target_testable }
t_has_many :sequel_has_many_targets, :as => :sequel_has_many_target_testable
+ require_toystore { t_has_many :toystore_has_many_targets, :as => :toystore_has_many_target_testable }
end
View
5 test/fixtures/data_mapper_has_many_target.rb
@@ -10,6 +10,7 @@ class DataMapperHasManyTarget
property :mongoid_object_id, String
property :ripple_object_id, String
property :sequel_object_id, Integer
+ property :toystore_object_id, String
property :active_record_has_many_target_testable_id, String
property :active_record_has_many_target_testable_type, String
@@ -25,6 +26,8 @@ class DataMapperHasManyTarget
property :ripple_has_many_target_testable_type, String
property :sequel_has_many_target_testable_id, String
property :sequel_has_many_target_testable_type, String
+ property :toystore_has_many_target_testable_id, String
+ property :toystore_has_many_target_testable_type, String
t_belongs_to :active_record_object
t_belongs_to :couch_rest_object
@@ -33,6 +36,7 @@ class DataMapperHasManyTarget
require_mongoid { t_belongs_to :mongoid_object }
require_ripple { t_belongs_to :ripple_object }
t_belongs_to :sequel_object
+ require_toystore { t_belongs_to :toystore_object }
t_belongs_to :active_record_has_many_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_many_target_testable, :polymorphic => true
@@ -41,4 +45,5 @@ class DataMapperHasManyTarget
require_mongoid { t_belongs_to :mongoid_has_many_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_many_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_many_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_many_target_testable, :polymorphic => true }
end
View
5 test/fixtures/data_mapper_has_one_target.rb
@@ -10,6 +10,7 @@ class DataMapperHasOneTarget
property :mongoid_object_id, String
property :ripple_object_id, String
property :sequel_object_id, Integer
+ property :toystore_object_id, String
property :active_record_has_one_target_testable_id, String
property :active_record_has_one_target_testable_type, String
@@ -25,6 +26,8 @@ class DataMapperHasOneTarget
property :ripple_has_one_target_testable_type, String
property :sequel_has_one_target_testable_id, String
property :sequel_has_one_target_testable_type, String
+ property :toystore_has_one_target_testable_id, String
+ property :toystore_has_one_target_testable_type, String
t_belongs_to :active_record_object
t_belongs_to :couch_rest_object
@@ -33,6 +36,7 @@ class DataMapperHasOneTarget
require_mongoid { t_belongs_to :mongoid_object }
require_ripple { t_belongs_to :ripple_object }
t_belongs_to :sequel_object
+ require_toystore { t_belongs_to :toystore_object }
t_belongs_to :active_record_has_one_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_one_target_testable, :polymorphic => true
@@ -41,4 +45,5 @@ class DataMapperHasOneTarget
require_mongoid { t_belongs_to :mongoid_has_one_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_one_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_one_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_one_target_testable, :polymorphic => true }
end
View
4 test/fixtures/data_mapper_object.rb
@@ -11,6 +11,7 @@ class DataMapperObject
require_mongoid { t_has_one :mongoid_has_one_target }
require_ripple { t_has_one :ripple_has_one_target }
t_has_one :sequel_has_one_target
+ require_toystore { t_has_one :toystore_has_one_target }
t_has_many :active_record_has_many_targets
t_has_many :couch_rest_has_many_targets
@@ -19,6 +20,7 @@ class DataMapperObject
require_mongoid { t_has_many :mongoid_has_many_targets }
require_ripple { t_has_many :ripple_has_many_targets }
t_has_many :sequel_has_many_targets
+ require_toystore { t_has_many :toystore_has_many_targets }
t_has_one :active_record_has_one_target, :as => :active_record_has_one_target_testable
t_has_one :couch_rest_has_one_target, :as => :couch_rest_has_one_target_testable
@@ -27,6 +29,7 @@ class DataMapperObject
require_mongoid { t_has_one :mongoid_has_one_target, :as => :mongoid_has_one_target_testable }
require_ripple { t_has_one :ripple_has_one_target, :as => :ripple_has_one_target_testable }
t_has_one :sequel_has_one_target, :as => :sequel_has_one_target_testable
+ require_toystore { t_has_one :toystore_has_one_target, :as => :toystore_has_one_target_testable }
t_has_many :active_record_has_many_targets, :as => :active_record_has_many_target_testable
t_has_many :couch_rest_has_many_targets, :as => :couch_rest_has_many_target_testable
@@ -35,4 +38,5 @@ class DataMapperObject
require_mongoid { t_has_many :mongoid_has_many_targets, :as => :mongoid_has_many_target_testable }
require_ripple { t_has_many :ripple_has_many_targets, :as => :ripple_has_many_target_testable }
t_has_many :sequel_has_many_targets, :as => :sequel_has_many_target_testable
+ require_toystore { t_has_many :toystore_has_many_targets, :as => :toystore_has_many_target_testable }
end
View
2  test/fixtures/mongo_mapper_has_many_target.rb
@@ -9,6 +9,7 @@ class MongoMapperHasManyTarget
require_mongoid { t_belongs_to :mongoid_object }
require_ripple { t_belongs_to :ripple_object }
t_belongs_to :sequel_object
+ require_toystore { t_belongs_to :toystore_object }
t_belongs_to :active_record_has_many_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_many_target_testable, :polymorphic => true
@@ -17,4 +18,5 @@ class MongoMapperHasManyTarget
require_mongoid { t_belongs_to :mongoid_has_many_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_many_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_many_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_many_target_testable, :polymorphic => true }
end
View
2  test/fixtures/mongo_mapper_has_one_target.rb
@@ -9,6 +9,7 @@ class MongoMapperHasOneTarget
require_mongoid { t_belongs_to :mongoid_object }
require_ripple { t_belongs_to :ripple_object }
t_belongs_to :sequel_object
+ require_toystore { t_belongs_to :toystore_object }
t_belongs_to :active_record_has_one_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_one_target_testable, :polymorphic => true
@@ -17,4 +18,5 @@ class MongoMapperHasOneTarget
require_mongoid { t_belongs_to :mongoid_has_one_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_one_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_one_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_one_target_testable, :polymorphic => true }
end
View
4 test/fixtures/mongo_mapper_object.rb
@@ -9,6 +9,7 @@ class MongoMapperObject
require_mongoid { t_has_one :mongoid_has_one_target }
require_ripple { t_has_one :ripple_has_one_target }
t_has_one :sequel_has_one_target
+ require_toystore { t_has_one :toystore_has_one_target }
t_has_many :active_record_has_many_targets
t_has_many :couch_rest_has_many_targets
@@ -17,6 +18,7 @@ class MongoMapperObject
require_mongoid { t_has_many :mongoid_has_many_targets }
require_ripple { t_has_many :ripple_has_many_targets }
t_has_many :sequel_has_many_targets
+ require_toystore { t_has_many :toystore_has_many_targets }
t_has_one :active_record_has_one_target, :as => :active_record_has_one_target_testable
t_has_one :couch_rest_has_one_target, :as => :couch_rest_has_one_target_testable
@@ -25,6 +27,7 @@ class MongoMapperObject
require_mongoid { t_has_one :mongoid_has_one_target, :as => :mongoid_has_one_target_testable }
require_ripple { t_has_one :ripple_has_one_target, :as => :ripple_has_one_target_testable }
t_has_one :sequel_has_one_target, :as => :sequel_has_one_target_testable
+ require_toystore { t_has_one :toystore_has_one_target, :as => :toystore_has_one_target_testable }
t_has_many :active_record_has_many_targets, :as => :active_record_has_many_target_testable
t_has_many :couch_rest_has_many_targets, :as => :couch_rest_has_many_target_testable
@@ -33,4 +36,5 @@ class MongoMapperObject
require_mongoid { t_has_many :mongoid_has_many_targets, :as => :mongoid_has_many_target_testable }
require_ripple { t_has_many :ripple_has_many_targets, :as => :ripple_has_many_target_testable }
t_has_many :sequel_has_many_targets, :as => :sequel_has_many_target_testable
+ require_toystore { t_has_many :toystore_has_many_targets, :as => :toystore_has_many_target_testable }
end
View
2  test/fixtures/mongoid_has_many_target.rb
@@ -10,6 +10,7 @@ class MongoidHasManyTarget
t_belongs_to :mongoid_object
t_belongs_to :ripple_object
t_belongs_to :sequel_object
+ t_belongs_to :toystore_object
t_belongs_to :active_record_has_many_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_many_target_testable, :polymorphic => true
@@ -18,5 +19,6 @@ class MongoidHasManyTarget
require_mongoid { t_belongs_to :mongoid_has_many_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_many_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_many_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_many_target_testable, :polymorphic => true }
end
end
View
2  test/fixtures/mongoid_has_one_target.rb
@@ -10,6 +10,7 @@ class MongoidHasOneTarget
t_belongs_to :mongoid_object
t_belongs_to :ripple_object
t_belongs_to :sequel_object
+ t_belongs_to :toystore_object
t_belongs_to :active_record_has_one_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_one_target_testable, :polymorphic => true
@@ -18,5 +19,6 @@ class MongoidHasOneTarget
require_mongoid { t_belongs_to :mongoid_has_one_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_one_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_one_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_one_target_testable, :polymorphic => true }
end
end
View
4 test/fixtures/mongoid_object.rb
@@ -10,6 +10,7 @@ class MongoidObject
t_has_one :mongoid_has_one_target
t_has_one :ripple_has_one_target
t_has_one :sequel_has_one_target
+ t_has_one :toystore_has_one_target
t_has_many :active_record_has_many_targets
t_has_many :couch_rest_has_many_targets
@@ -18,6 +19,7 @@ class MongoidObject
t_has_many :mongoid_has_many_targets
t_has_many :ripple_has_many_targets
t_has_many :sequel_has_many_targets
+ t_has_many :toystore_has_many_targets
t_has_one :active_record_has_one_target, :as => :active_record_has_one_target_testable
t_has_one :couch_rest_has_one_target, :as => :couch_rest_has_one_target_testable
@@ -26,6 +28,7 @@ class MongoidObject
require_mongoid { t_has_one :mongoid_has_one_target, :as => :mongoid_has_one_target_testable }
require_ripple { t_has_one :ripple_has_one_target, :as => :ripple_has_one_target_testable }
t_has_one :sequel_has_one_target, :as => :sequel_has_one_target_testable
+ require_toystore { t_has_one :toystore_has_one_target, :as => :toystore_has_one_target_testable }
t_has_many :active_record_has_many_targets, :as => :active_record_has_many_target_testable
t_has_many :couch_rest_has_many_targets, :as => :couch_rest_has_many_target_testable
@@ -34,5 +37,6 @@ class MongoidObject
require_mongoid { t_has_many :mongoid_has_many_targets, :as => :mongoid_has_many_target_testable }
require_ripple { t_has_many :ripple_has_many_targets, :as => :ripple_has_many_target_testable }
t_has_many :sequel_has_many_targets, :as => :sequel_has_many_target_testable
+ require_toystore { t_has_many :toystore_has_many_targets, :as => :toystore_has_many_target_testable }
end
end
View
2  test/fixtures/ripple_has_many_target.rb
@@ -10,6 +10,7 @@ class RippleHasManyTarget
t_belongs_to :mongoid_object
t_belongs_to :ripple_object
t_belongs_to :sequel_object
+ t_belongs_to :toystore_object
t_belongs_to :active_record_has_many_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_many_target_testable, :polymorphic => true
@@ -18,5 +19,6 @@ class RippleHasManyTarget
require_mongoid { t_belongs_to :mongoid_has_many_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_many_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_many_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_many_target_testable, :polymorphic => true }
end
end
View
2  test/fixtures/ripple_has_one_target.rb
@@ -10,6 +10,7 @@ class RippleHasOneTarget
t_belongs_to :mongoid_object
t_belongs_to :ripple_object
t_belongs_to :sequel_object
+ t_belongs_to :toystore_object
t_belongs_to :active_record_has_one_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_one_target_testable, :polymorphic => true
@@ -18,5 +19,6 @@ class RippleHasOneTarget
require_mongoid { t_belongs_to :mongoid_has_one_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_one_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_one_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_one_target_testable, :polymorphic => true }
end
end
View
4 test/fixtures/ripple_object.rb
@@ -10,6 +10,7 @@ class RippleObject
require_mongoid { t_has_one :mongoid_has_one_target }
require_ripple { t_has_one :ripple_has_one_target }
t_has_one :sequel_has_one_target
+ require_toystore { t_has_one :toystore_has_one_target }
t_has_many :active_record_has_many_targets
t_has_many :couch_rest_has_many_targets
@@ -18,6 +19,7 @@ class RippleObject
require_mongoid { t_has_many :mongoid_has_many_targets }
require_ripple { t_has_many :ripple_has_many_targets }
t_has_many :sequel_has_many_targets
+ require_toystore { t_has_many :toystore_has_many_targets }
t_has_one :active_record_has_one_target, :as => :active_record_has_one_target_testable
t_has_one :couch_rest_has_one_target, :as => :couch_rest_has_one_target_testable
@@ -26,6 +28,7 @@ class RippleObject
require_mongoid { t_has_one :mongoid_has_one_target, :as => :mongoid_has_one_target_testable }
require_ripple { t_has_one :ripple_has_one_target, :as => :ripple_has_one_target_testable }
t_has_one :sequel_has_one_target, :as => :sequel_has_one_target_testable
+ require_toystore { t_has_one :toystore_has_one_target, :as => :toystore_has_one_target_testable }
t_has_many :active_record_has_many_targets, :as => :active_record_has_many_target_testable
t_has_many :couch_rest_has_many_targets, :as => :couch_rest_has_many_target_testable
@@ -34,5 +37,6 @@ class RippleObject
require_mongoid { t_has_many :mongoid_has_many_targets, :as => :mongoid_has_many_target_testable }
require_ripple { t_has_many :ripple_has_many_targets, :as => :ripple_has_many_target_testable }
t_has_many :sequel_has_many_targets, :as => :sequel_has_many_target_testable
+ require_toystore { t_has_many :toystore_has_many_targets, :as => :toystore_has_many_target_testable }
end
end
View
2  test/fixtures/sequel_has_many_target.rb
@@ -8,6 +8,7 @@ class SequelHasManyTarget < Sequel::Model
require_mongoid { t_belongs_to :mongoid_object }
require_ripple { t_belongs_to :ripple_object }
t_belongs_to :sequel_object
+ require_toystore { t_belongs_to :toystore_object }
t_belongs_to :active_record_has_many_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_many_target_testable, :polymorphic => true
@@ -16,4 +17,5 @@ class SequelHasManyTarget < Sequel::Model
require_mongoid { t_belongs_to :mongoid_has_many_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_many_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_many_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_many_target_testable, :polymorphic => true }
end
View
2  test/fixtures/sequel_has_one_target.rb
@@ -8,6 +8,7 @@ class SequelHasOneTarget < Sequel::Model
require_mongoid { t_belongs_to :mongoid_object }
require_ripple { t_belongs_to :ripple_object }
t_belongs_to :sequel_object
+ require_toystore { t_belongs_to :toystore_object }
t_belongs_to :active_record_has_one_target_testable, :polymorphic => true
t_belongs_to :couch_rest_has_one_target_testable, :polymorphic => true
@@ -16,4 +17,5 @@ class SequelHasOneTarget < Sequel::Model
require_mongoid { t_belongs_to :mongoid_has_one_target_testable, :polymorphic => true }
require_ripple { t_belongs_to :ripple_has_one_target_testable, :polymorphic => true }
t_belongs_to :sequel_has_one_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_one_target_testable, :polymorphic => true }
end
View
4 test/fixtures/sequel_object.rb
@@ -8,6 +8,7 @@ class SequelObject < Sequel::Model
require_mongoid { t_has_one :mongoid_has_one_target }
require_ripple { t_has_one :ripple_has_one_target }
t_has_one :sequel_has_one_target
+ require_toystore { t_has_one :toystore_has_one_target }
t_has_many :active_record_has_many_targets
t_has_many :couch_rest_has_many_targets
@@ -16,6 +17,7 @@ class SequelObject < Sequel::Model
require_mongoid { t_has_many :mongoid_has_many_targets }
require_ripple { t_has_many :ripple_has_many_targets }
t_has_many :sequel_has_many_targets
+ require_toystore { t_has_many :toystore_has_many_targets }
t_has_one :active_record_has_one_target, :as => :active_record_has_one_target_testable
t_has_one :couch_rest_has_one_target, :as => :couch_rest_has_one_target_testable
@@ -24,6 +26,7 @@ class SequelObject < Sequel::Model
require_mongoid { t_has_one :mongoid_has_one_target, :as => :mongoid_has_one_target_testable }
require_ripple { t_has_one :ripple_has_one_target, :as => :ripple_has_one_target_testable }
t_has_one :sequel_has_one_target, :as => :sequel_has_one_target_testable
+ require_toystore { t_has_one :toystore_has_one_target, :as => :toystore_has_one_target_testable }
t_has_many :active_record_has_many_targets, :as => :active_record_has_many_target_testable
t_has_many :couch_rest_has_many_targets, :as => :couch_rest_has_many_target_testable
@@ -32,4 +35,5 @@ class SequelObject < Sequel::Model
require_mongoid { t_has_many :mongoid_has_many_targets, :as => :mongoid_has_many_target_testable }
require_ripple { t_has_many :ripple_has_many_targets, :as => :ripple_has_many_target_testable }
t_has_many :sequel_has_many_targets, :as => :sequel_has_many_target_testable
+ require_toystore { t_has_many :toystore_has_many_targets, :as => :toystore_has_many_target_testable }
end
View
28 test/fixtures/toystore_has_many_target.rb
@@ -0,0 +1,28 @@
+require_toystore do
+ require 'adapter/mongo'
+
+ class ToystoreHasManyTarget
+ include Toy::Store
+ store :mongo, Mongo::Connection.new.db('tenacity_test')['toystore']
+
+ include Tenacity
+
+ t_belongs_to :active_record_object
+ t_belongs_to :couch_rest_object
+ t_belongs_to :data_mapper_object
+ t_belongs_to :mongo_mapper_object
+ t_belongs_to :mongoid_object
+ t_belongs_to :ripple_object
+ t_belongs_to :sequel_object
+ t_belongs_to :toystore_object
+
+ t_belongs_to :active_record_has_many_target_testable, :polymorphic => true
+ t_belongs_to :couch_rest_has_many_target_testable, :polymorphic => true
+ t_belongs_to :data_mapper_has_many_target_testable, :polymorphic => true
+ t_belongs_to :mongo_mapper_has_many_target_testable, :polymorphic => true
+ require_mongoid { t_belongs_to :mongoid_has_many_target_testable, :polymorphic => true }
+ require_ripple { t_belongs_to :ripple_has_many_target_testable, :polymorphic => true }
+ t_belongs_to :sequel_has_many_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_many_target_testable, :polymorphic => true }
+ end
+end
View
28 test/fixtures/toystore_has_one_target.rb
@@ -0,0 +1,28 @@
+require_toystore do
+ require 'adapter/mongo'
+
+ class ToystoreHasOneTarget
+ include Toy::Store
+ store :mongo, Mongo::Connection.new.db('tenacity_test')['toystore']
+
+ include Tenacity
+
+ t_belongs_to :active_record_object
+ t_belongs_to :couch_rest_object
+ t_belongs_to :data_mapper_object
+ t_belongs_to :mongo_mapper_object
+ t_belongs_to :mongoid_object
+ t_belongs_to :ripple_object
+ t_belongs_to :sequel_object
+ t_belongs_to :toystore_object
+
+ t_belongs_to :active_record_has_one_target_testable, :polymorphic => true
+ t_belongs_to :couch_rest_has_one_target_testable, :polymorphic => true
+ t_belongs_to :data_mapper_has_one_target_testable, :polymorphic => true
+ t_belongs_to :mongo_mapper_has_one_target_testable, :polymorphic => true
+ require_mongoid { t_belongs_to :mongoid_has_one_target_testable, :polymorphic => true }
+ require_ripple { t_belongs_to :ripple_has_one_target_testable, :polymorphic => true }
+ t_belongs_to :sequel_has_one_target_testable, :polymorphic => true
+ require_toystore { t_belongs_to :toystore_has_one_target_testable, :polymorphic => true }
+ end
+end
View
46 test/fixtures/toystore_object.rb
@@ -0,0 +1,46 @@
+require_toystore do
+ require 'adapter/mongo'
+
+ class ToystoreObject
+ include Toy::Store
+ store :mongo, Mongo::Connection.new.db('tenacity_test')['toystore']
+
+ include Tenacity
+
+ t_has_one :active_record_has_one_target
+ t_has_one :couch_rest_has_one_target
+ t_has_one :data_mapper_has_one_target
+ t_has_one :mongo_mapper_has_one_target
+ t_has_one :mongoid_has_one_target
+ t_has_one :ripple_has_one_target
+ t_has_one :sequel_has_one_target
+ t_has_one :toystore_has_one_target
+
+ t_has_many :active_record_has_many_targets
+ t_has_many :couch_rest_has_many_targets
+ t_has_many :data_mapper_has_many_targets
+ t_has_many :mongo_mapper_has_many_targets
+ t_has_many :mongoid_has_many_targets
+ t_has_many :ripple_has_many_targets
+ t_has_many :sequel_has_many_targets
+ t_has_many :toystore_has_many_targets
+
+ t_has_one :active_record_has_one_target, :as => :active_record_has_one_target_testable
+ t_has_one :couch_rest_has_one_target, :as => :couch_rest_has_one_target_testable
+ t_has_one :data_mapper_has_one_target, :as => :data_mapper_has_one_target_testable
+ t_has_one :mongo_mapper_has_one_target, :as => :mongo_mapper_has_one_target_testable
+ require_mongoid { t_has_one :mongoid_has_one_target, :as => :mongoid_has_one_target_testable }
+ require_ripple { t_has_one :ripple_has_one_target, :as => :ripple_has_one_target_testable }
+ t_has_one :sequel_has_one_target, :as => :sequel_has_one_target_testable
+ require_toystore { t_has_one :toystore_has_one_target, :as => :toystore_has_one_target_testable }
+
+ t_has_many :active_record_has_many_targets, :as => :active_record_has_many_target_testable
+ t_has_many :couch_rest_has_many_targets, :as => :couch_rest_has_many_target_testable
+ t_has_many :data_mapper_has_many_targets, :as => :data_mapper_has_many_target_testable
+ t_has_many :mongo_mapper_has_many_targets, :as => :mongo_mapper_has_many_target_testable
+ require_mongoid { t_has_many :mongoid_has_many_targets, :as => :mongoid_has_many_target_testable }
+ require_ripple { t_has_many :ripple_has_many_targets, :as => :ripple_has_many_target_testable }
+ t_has_many :sequel_has_many_targets, :as => :sequel_has_many_target_testable
+ require_toystore { t_has_many :toystore_has_many_targets, :as => :toystore_has_many_target_testable }
+ end
+end
View
6 test/helpers/active_record_test_helper.rb
@@ -33,6 +33,7 @@
t.string :mongoid_object_id
t.string :ripple_object_id
t.integer :sequel_object_id
+ t.string :toystore_object_id
t.string :active_record_has_one_target_testable_id
t.string :active_record_has_one_target_testable_type
@@ -48,6 +49,8 @@
t.string :ripple_has_one_target_testable_type
t.string :sequel_has_one_target_testable_id
t.string :sequel_has_one_target_testable_type
+ t.string :toystore_has_one_target_testable_id
+ t.string :toystore_has_one_target_testable_type
end
create_table :active_record_has_many_targets, :force => true do |t|
@@ -58,6 +61,7 @@
t.string :mongoid_object_id
t.string :ripple_object_id
t.integer :sequel_object_id
+ t.string :toystore_object_id
t.string :active_record_has_many_target_testable_id
t.string :active_record_has_many_target_testable_type
@@ -73,6 +77,8 @@
t.string :ripple_has_many_target_testable_type
t.string :sequel_has_many_target_testable_id
t.string :sequel_has_many_target_testable_type
+ t.string :toystore_has_many_target_testable_id
+ t.string :toystore_has_many_target_testable_type
end
end
View
6 test/helpers/sequel_test_helper.rb
@@ -17,6 +17,7 @@
String :mongoid_object_id
String :ripple_object_id
Integer :sequel_object_id
+ String :toystore_object_id
String :active_record_has_one_target_testable_id
String :active_record_has_one_target_testable_type
@@ -32,6 +33,8 @@
String :ripple_has_one_target_testable_type
String :sequel_has_one_target_testable_id
String :sequel_has_one_target_testable_type
+ String :toystore_has_one_target_testable_id
+ String :toystore_has_one_target_testable_type
end
DB.create_table :sequel_has_many_targets do
@@ -44,6 +47,7 @@
String :mongoid_object_id
String :ripple_object_id
Integer :sequel_object_id
+ String :toystore_object_id
String :active_record_has_many_target_testable_id
String :active_record_has_many_target_testable_type
@@ -59,5 +63,7 @@
String :ripple_has_many_target_testable_type
String :sequel_has_many_target_testable_id
String :sequel_has_many_target_testable_type
+ String :toystore_has_many_target_testable_id
+ String :toystore_has_many_target_testable_type
end
View
17 test/helpers/toystore_test_helper.rb
@@ -0,0 +1,17 @@
+def require_toystore
+ begin
+ require 'toystore'
+ yield
+ rescue LoadError
+ end
+end
+
+begin
+ require 'toystore'
+
+ FileUtils.mkdir_p("log")
+ Toy.logger = ::Logger.new(File.join("log", "toystore.log"))
+rescue LoadError
+ puts "WARNING: Toystore could not be loaded. Skipping tests."
+end
+
View
103 test/orm_ext/toystore_test.rb
@@ -0,0 +1,103 @@
+require 'test_helper'
+
+require_toystore do
+ class ToystoreTest < Test::Unit::TestCase
+
+ context "The Toystore extension" do
+ setup do
+ setup_fixtures
+ end
+
+ should "be able to find the object in the database" do
+ object = ToystoreObject.create
+ assert_equal object, ToystoreObject._t_find(object.id)
+ end
+
+ should "return nil if the specified id could not be found in the database" do
+ assert_nil ToystoreObject._t_find('4d0e1224b28cdbfb72000042')
+ end
+
+ should "be able to find multiple objects in the database" do
+ object_1 = ToystoreObject.create
+ object_2 = ToystoreObject.create
+ assert_set_equal [object_1], ToystoreObject._t_find_bulk([object_1.id])
+ assert_set_equal [object_1, object_2], ToystoreObject._t_find_bulk([object_1.id, object_2.id, '4d0e1224b28cdbfb72000042'])
+ end
+
+ should "return an empty array if none of the specified object ids could be found in the database" do
+ assert_equal [], ToystoreObject._t_find_bulk(['4d0e1224b28cdbfb72000042', '4d0e1224b28cdbfb72000043', '4d0e1224b28cdbfb72000044'])
+ end
+
+ should "be able to find the first associate of an object" do
+ object = ToystoreObject.create
+ target = ToystoreHasOneTarget.create(:toystore_object_id => object.id)
+ assert_equal target, ToystoreHasOneTarget._t_find_first_by_associate(:toystore_object_id, object.id)
+ end
+
+ should "return nil if the first associate of an object could not be found" do
+ assert_nil ToystoreHasOneTarget._t_find_first_by_associate(:toystore_object_id, 12345)
+ end
+
+ should "be able to find the associates of an object" do
+ object_1 = ToystoreObject.create
+ object_2 = ToystoreObject.create
+ target_1 = ToystoreHasOneTarget.create(:toystore_object_id => object_1.id)
+ target_2 = ToystoreHasOneTarget.create(:toystore_object_id => object_1.id)
+ target_3 = ToystoreHasOneTarget.create(:toystore_object_id => object_2.id)
+ assert_set_equal [target_1, target_2], ToystoreHasOneTarget._t_find_all_by_associate(:toystore_object_id, object_1.id)
+ end
+
+ should "return an empty array if the object has no associates" do
+ assert_equal [], ToystoreHasOneTarget._t_find_all_by_associate(:toystore_object_id, '1234')
+ end
+
+ should "be able to get the ids of the objects associated with the given object" do
+ object = ToystoreObject.create
+ target_1 = ToystoreHasManyTarget.create
+ target_2 = ToystoreHasManyTarget.create
+ target_3 = ToystoreHasManyTarget.create
+ object.toystore_has_many_targets = [target_1, target_2, target_3]
+ object.save
+
+ assert_set_equal [target_1.id, target_2.id, target_3.id], ToystoreHasManyTarget._t_find_all_ids_by_associate(:toystore_object_id, object.id)
+ end
+
+ should "return an empty array when trying to fetch associate ids for an object with no associates" do
+ object = ToystoreObject.create
+ assert_set_equal [], ToystoreHasManyTarget._t_find_all_ids_by_associate(:toystore_object_id, object.id)
+ end
+
+ should "be able to reload an object from the database" do
+ target = ToystoreHasOneTarget.create
+ target.toystore_object_id = '101'
+ assert_equal '101', target.toystore_object_id
+ target._t_reload
+ assert_nil target.toystore_object_id
+ end
+
+ should "be able to delete a set of objects, issuing their callbacks" do
+ object_1 = ToystoreHasManyTarget.create
+ object_2 = ToystoreHasManyTarget.create
+ object_3 = ToystoreHasManyTarget.create
+
+ assert_equal 3, ToystoreHasManyTarget.get_multi(object_1.id, object_2.id, object_3.id).compact.size
+ ToystoreHasManyTarget._t_delete([object_1.id, object_2.id, object_3.id])
+ assert_equal 0, ToystoreHasManyTarget.get_multi(object_1.id, object_2.id, object_3.id).compact.size
+ end
+
+ should "be able to delete a setup of objects, without issuing their callbacks" do
+ object_1 = ToystoreHasManyTarget.create
+ object_2 = ToystoreHasManyTarget.create
+ object_3 = ToystoreHasManyTarget.create
+
+ assert_equal 3, ToystoreHasManyTarget.get_multi(object_1.id, object_2.id, object_3.id).compact.size
+ ToystoreHasManyTarget._t_delete([object_1.id, object_2.id, object_3.id], false)
+ assert_equal 0, ToystoreHasManyTarget.get_multi(object_1.id, object_2.id, object_3.id).compact.size
+ end
+ end
+
+ def association
+ Tenacity::Association.new(:t_has_many, :toystore_has_many_targets, ToystoreObject)
+ end
+ end
+end
View
2  test/test_helper.rb
@@ -23,6 +23,7 @@
require File.join(File.dirname(__FILE__), 'helpers', 'mongoid_test_helper')
require File.join(File.dirname(__FILE__), 'helpers', 'ripple_test_helper')
require File.join(File.dirname(__FILE__), 'helpers', 'sequel_test_helper')
+require File.join(File.dirname(__FILE__), 'helpers', 'toystore_test_helper')
Dir[File.join(File.dirname(__FILE__), 'fixtures', '*.rb')].each { |file| autoload(file[file.rindex('/') + 1..-4].camelcase, file) }
@@ -81,6 +82,7 @@ def orm_extensions
extensions = [:active_record, :couch_rest, :data_mapper, :mongo_mapper, :sequel]
require_mongoid { extensions << :mongoid }
require_ripple { extensions << :ripple } if ENV['LONG'] == 'true'
+ require_toystore { extensions << :toystore }
extensions
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.