Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #37 from raphaelcm/save_bug_fix

Save bug fix
  • Loading branch information...
commit 56e5a6b57d22b087967ae57bd9aff0bd37c886bf 2 parents cd517f3 + e00723b
@jwood authored
View
4 lib/tenacity/associate_proxy.rb
@@ -23,11 +23,11 @@ def inspect
@target.inspect
end
- def save
+ def save(*args)
if @association.readonly?
raise ReadOnlyError
else
- @target._t_save_if_dirty
+ @target._t_save_if_dirty(*args)
end
end
View
4 lib/tenacity/orm_ext/activerecord.rb
@@ -112,8 +112,8 @@ def _t_reload
self
end
- def _t_save_if_dirty
- changed? ? save : false
+ def _t_save_if_dirty(*args)
+ changed? ? save(*args) : true
end
end
View
4 lib/tenacity/orm_ext/couchrest.rb
@@ -145,8 +145,8 @@ def _t_reload
self
end
- def _t_save_if_dirty
- save
+ def _t_save_if_dirty(*args)
+ save(*args)
end
end
View
4 lib/tenacity/orm_ext/datamapper.rb
@@ -138,8 +138,8 @@ def _t_reload
self.class._t_find(self.id)
end
- def _t_save_if_dirty
- dirty? ? save : false
+ def _t_save_if_dirty(*args)
+ dirty? ? save(*args) : true
end
private
View
4 lib/tenacity/orm_ext/mongo_mapper.rb
@@ -111,8 +111,8 @@ def _t_reload
self
end
- def _t_save_if_dirty
- changed? ? save : false
+ def _t_save_if_dirty(*args)
+ changed? ? save(*args) : true
end
end
View
4 lib/tenacity/orm_ext/mongoid.rb
@@ -113,8 +113,8 @@ def _t_reload
self
end
- def _t_save_if_dirty
- changed? ? save : false
+ def _t_save_if_dirty(*args)
+ changed? ? save(*args) : true
end
end
View
4 lib/tenacity/orm_ext/ripple.rb
@@ -139,8 +139,8 @@ def _t_reload
self
end
- def _t_save_if_dirty
- changed? ? save : false
+ def _t_save_if_dirty(*args)
+ changed? ? save(*args) : true
end
def save
View
4 lib/tenacity/orm_ext/sequel.rb
@@ -147,8 +147,8 @@ def _t_reload
self
end
- def _t_save_if_dirty
- !changed_columns.empty? ? save : false
+ def _t_save_if_dirty(*args)
+ !changed_columns.empty? ? save(*args) : true
end
end
View
4 lib/tenacity/orm_ext/toystore.rb
@@ -109,8 +109,8 @@ def _t_reload
self
end
- def _t_save_if_dirty
- changed? ? save : false
+ def _t_save_if_dirty(*args)
+ changed? ? save(*args) : true
end
end
end
View
4 tenacity.gemspec
@@ -27,14 +27,14 @@ Gem::Specification.new do |s|
# Relational DBs
s.add_development_dependency "sqlite3-ruby", "1.3.1"
- s.add_development_dependency "activerecord", "~> 3.0.0"
+ s.add_development_dependency "activerecord", "= 3.0.7"
s.add_development_dependency "datamapper", "1.0.2"
s.add_development_dependency "dm-sqlite-adapter", "1.0.2"
s.add_development_dependency "sequel", "3.19.0"
# MongoDB
s.add_development_dependency "mongo_mapper", "0.9.0"
- s.add_development_dependency "bson_ext", "1.3.1"
+ s.add_development_dependency "bson_ext", "1.6.2"
s.add_development_dependency "mongoid", "2.0.0"
# CouchDB
View
5 test/fixtures/active_record_organization.rb
@@ -0,0 +1,5 @@
+class ActiveRecordOrganization < ActiveRecord::Base
+ include Tenacity
+
+ has_many :active_record_users
+end
View
5 test/fixtures/active_record_user.rb
@@ -0,0 +1,5 @@
+class ActiveRecordUser < ActiveRecord::Base
+ include Tenacity
+
+ belongs_to :active_record_organization, :autosave => true
+end
View
8 test/fixtures/mongoid_campus_hub.rb
@@ -0,0 +1,8 @@
+class MongoidCampusHub
+ include Mongoid::Document
+ include Mongoid::Timestamps
+ include Tenacity
+
+ t_belongs_to :active_record_organization
+
+end
View
8 test/helpers/active_record_test_helper.rb
@@ -29,6 +29,14 @@
create_table :active_record_object_with_string_ids, :force => true, :id => false do |t|
t.string :id, :limit => 36, :primary => true
end
+
+ create_table :active_record_users, :force => true do |t|
+ t.integer :active_record_organization_id
+ end
+
+ create_table :active_record_organizations, :force => true do |t|
+
+ end
create_table :active_record_has_one_targets, :force => true do |t|
t.integer :active_record_object_id
View
19 test/orm_ext/activerecord_test.rb
@@ -98,9 +98,15 @@ class ActiveRecordTest < Test::Unit::TestCase
assert object._t_save_if_dirty
end
+ should "return true for save if valid object is not dirty" do
+ object = ActiveRecordObject.create
+ assert object.save
+ end
+
should "not save the object if it is not dirty" do
object = ActiveRecordObject.create
- assert !object._t_save_if_dirty
+ ActiveRecordObject.any_instance.stubs(:save).returns(false)
+ assert object._t_save_if_dirty
end
should "be able to successfully determine the id type" do
@@ -110,6 +116,17 @@ class ActiveRecordTest < Test::Unit::TestCase
class ActiveRecordObjectWithNoTable < ActiveRecord::Base; include Tenacity; end
assert_equal Integer, ActiveRecordObjectWithNoTable._t_id_type
end
+
+ should "successfully save if belongs_to another AR object which is assigned from a mongoid object" do
+ org = ActiveRecordOrganization.create
+ campus_hub = MongoidCampusHub.create
+ campus_hub.active_record_organization = org
+ campus_hub.save!
+ user = ActiveRecordUser.new
+ user.active_record_organization = campus_hub.active_record_organization
+ assert user.save
+ assert user.active_record_organization.save(:validate => false)
+ end
end
private
View
8 test/orm_ext/datamapper_test.rb
@@ -89,9 +89,15 @@ class DataMapperTest < Test::Unit::TestCase
assert object._t_save_if_dirty
end
+ should "return true for save if valid object is not dirty" do
+ object = DataMapperObject.create
+ assert object.save
+ end
+
should "not save the object if it is not dirty" do
object = DataMapperObject.create
- assert !object._t_save_if_dirty
+ DataMapperObject.any_instance.stubs(:save).returns(false)
+ assert object._t_save_if_dirty
end
should "be able to successfully determine the id type" do
View
8 test/orm_ext/mongo_mapper_test.rb
@@ -99,9 +99,15 @@ class MongoMapperTest < Test::Unit::TestCase
assert object._t_save_if_dirty
end
+ should "return true for save if valid object is not dirty" do
+ object = MongoMapperObject.create
+ assert object.save
+ end
+
should "not save the object if it is not dirty" do
object = MongoMapperObject.create
- assert !object._t_save_if_dirty
+ MongoMapperObject.any_instance.stubs(:save).returns(false)
+ assert object._t_save_if_dirty
end
end
View
8 test/orm_ext/mongoid_test.rb
@@ -100,9 +100,15 @@ class MongoidTest < Test::Unit::TestCase
assert object._t_save_if_dirty
end
+ should "return true for save if valid object is not dirty" do
+ object = MongoidObject.create
+ assert object.save
+ end
+
should "not save the object if it is not dirty" do
object = MongoidObject.create
- assert !object._t_save_if_dirty
+ MongoidObject.any_instance.stubs(:save).returns(false)
+ assert object._t_save_if_dirty
end
end
View
8 test/orm_ext/ripple_test.rb
@@ -139,9 +139,15 @@ class RippleTest < Test::Unit::TestCase
assert object._t_save_if_dirty
end
+ should "return true for save if valid object is not dirty" do
+ object = RippleObject.create
+ assert object.save
+ end
+
should "not save the object if it is not dirty" do
object = RippleObject.create
- assert !object._t_save_if_dirty
+ RippleObject.any_instance.stubs(:save).returns(false)
+ assert object._t_save_if_dirty
end
end
View
8 test/orm_ext/sequel_test.rb
@@ -99,9 +99,15 @@ class SequelTest < Test::Unit::TestCase
assert object._t_save_if_dirty
end
+ should "return true for save if valid object is not dirty" do
+ object = SequelObject.create
+ assert object.save
+ end
+
should "not save the object if it is not dirty" do
object = SequelObject.create
- assert !object._t_save_if_dirty
+ SequelObject.any_instance.stubs(:save).returns(false)
+ assert object._t_save_if_dirty
end
should "be able to successfully determine the id type" do
View
8 test/orm_ext/toystore_test.rb
@@ -101,9 +101,15 @@ class ToystoreTest < Test::Unit::TestCase
assert object._t_save_if_dirty
end
+ should "return true for save if valid object is not dirty" do
+ object = ToystoreObject.create
+ assert object.save
+ end
+
should "not save the object if it is not dirty" do
object = ToystoreObject.create
- assert !object._t_save_if_dirty
+ ToystoreObject.any_instance.stubs(:save).returns(false)
+ assert object._t_save_if_dirty
end
end
View
2  test/test_helper.rb
@@ -35,7 +35,7 @@ def setup_fixtures
filename =~ /.*\/(.*)\.rb/
clazz = Kernel.const_get($1.camelcase)
if clazz.respond_to?(:delete_all)
- clazz.delete_all
+ clazz.delete_all rescue true
elsif clazz.respond_to?(:db)
clazz.db["delete from #{clazz.table_name}"].delete
elsif clazz.respond_to?(:destroy!)
Please sign in to comment.
Something went wrong with that request. Please try again.