Permalink
Browse files

Rails 3.2 compatibility fixes

  • Loading branch information...
1 parent 356b28b commit 717b38ba63427e6ebdf5e06facc36c335447784a Brian Durand committed Jan 24, 2012
View
@@ -1,3 +1,10 @@
+1.2.2
+ - Remove deprecation warning in Rails 3.2
+
+1.2.1
+ - Add nicer syntax for copying attributes to revisions
+ - Bug fixes
+
1.2.0
- Removed label column from revision_records table
- Added support for customizing and subclassing RevisionRecord
View
@@ -1 +1 @@
-1.2.1
+1.2.2
@@ -7,7 +7,7 @@ class RevisionRecord < ActiveRecord::Base
before_create :set_revision_number
attr_reader :data_encoding
- set_table_name :revision_records
+ self.table_name = :revision_records
class << self
# Find a specific revision record.
@@ -204,7 +204,12 @@ def restore_association(record, association, association_attributes)
begin
if reflection.macro == :has_many
if association_attributes.kind_of?(Array)
- record.send("#{association}=", [])
+ # Pop all the associated records to remove all records. In Rails 3.2 setting the value of the list
+ # will immediately affect the database
+ records = record.send(association)
+ while records.pop do
+ # no-op
+ end
association_attributes.each do |attrs|
restore_association(record, association, attrs)
end
@@ -89,7 +89,7 @@ def secret=(val)
end
class RevisionRecord2 < ActsAsRevisionable::RevisionRecord
- set_table_name "revision_records_2"
+ self.table_name = "revision_records_2"
create_table
connection.add_column(table_name, :label, :string)
connection.add_column(table_name, :updated_by, :string)
@@ -113,7 +113,7 @@ class RevisionableNamespaceModel < ActiveRecord::Base
t.column :type_name, :string
end unless table_exists?
- set_inheritance_column :type_name
+ self.inheritance_column = :type_name
acts_as_revisionable :dependent => :keep, :on_destroy => true, :encoding => :xml
self.store_full_sti_class = false
end
@@ -491,7 +491,7 @@ class RevisionableSubclassModel < RevisionableNamespaceModel
restored.many_other_things.collect{|t| t.name}.sort.should == ['many_other_thing_3', 'new_many_other_thing_1']
restored.valid?.should == true
- # make the restore to memory didn't affect the database
+ # make sure the restore to memory didn't affect the database
model.reload
model.name.should == 'new_name'
model.many_things(true).collect{|t| t.name}.sort.should == ['many_thing_3', 'new_many_thing_1']
@@ -23,6 +23,8 @@ class TestRevisionableOneAssociationRecord < ActiveRecord::Base
t.column :value, :integer
t.column :test_revisionable_record_id, :integer
end unless table_exists?
+
+ self.primary_key = nil if ActiveRecord::VERSION::MAJOR >= 3 && ActiveRecord::VERSION::MINOR > 0
end
class TestRevisionableAssociationComposite < ActiveRecord::Base
@@ -304,8 +306,7 @@ def self.base_class
it "should be able to restore the has_one associations" do
revision = ActsAsRevisionable::RevisionRecord.new(TestRevisionableRecord.new)
record = TestRevisionableRecord.new
- revision.send(:restore_association, record, :one_association, {'id' => 1, 'name' => 'one', 'value' => 1})
- record.one_association.id.should == 1
+ revision.send(:restore_association, record, :one_association, {'name' => 'one', 'value' => 1})
record.one_association.name.should == 'one'
record.one_association.value.should == 1
end
View
@@ -18,8 +18,10 @@
if ActiveRecord::VERSION::MAJOR >= 3
if ActiveRecord::VERSION::MINOR == 0
composite_primary_key_version = "~>3.1.0"
+ elsif ActiveRecord::VERSION::MINOR == 1
+ composite_primary_key_version = "~>4"
else
- composite_primary_key_version = ">=4.0.0"
+ composite_primary_key_version = ">4"
end
else
composite_primary_key_version = "~>2.3.5"

0 comments on commit 717b38b

Please sign in to comment.