Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 5.2 compatibility #5

Open
wants to merge 2 commits into
base: rails_5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/acts_as_revisionable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def store_revision(*args)
# Build a revision record based on this record
def build_revision
revision_options = self.class.acts_as_revisionable_options
revision = revision_record_class.new(self, revision_options[:encoding])
revision = revision_record_class.new(self)
set_revision_meta_attributes(revision_options[:meta], revision)

revision
Expand Down
5 changes: 3 additions & 2 deletions lib/acts_as_revisionable/revision_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def create_table

# Create a revision record based on a record passed in. The attributes of the original record will
# be serialized. If it uses the acts_as_revisionable behavior, associations will be revisioned as well.
def initialize(record, encoding = :ruby)
def initialize(record)
super({})
@data_encoding = encoding
options = record.class.try(:acts_as_revisionable_options) || {}
@data_encoding = options[:encoding] || :ruby
self.revisionable_type = record.class.base_class.name
self.revisionable_id = record.id
associations = record.class.revisionable_associations if record.class.respond_to?(:revisionable_associations)
Expand Down
9 changes: 6 additions & 3 deletions spec/revision_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ def self.base_class

it "should be able to restore the original model using Ruby serialization" do
attributes = {'id' => 1, 'name' => 'revision', 'value' => 5, 'test_revisionable_one_association_record_id' => nil}
revision = ActsAsRevisionable::RevisionRecord.new(TestRevisionableRecord.new(attributes), :ruby)
TestRevisionableRecord.acts_as_revisionable_options[:encoding] = :ruby
revision = ActsAsRevisionable::RevisionRecord.new(TestRevisionableRecord.new(attributes))
revision.data = Zlib::Deflate.deflate(Marshal.dump(attributes))
restored = revision.restore
restored.class.should == TestRevisionableRecord
Expand All @@ -229,7 +230,8 @@ def self.base_class

it "should be able to restore the original model using YAML serialization" do
attributes = {'id' => 1, 'name' => 'revision', 'value' => 5, 'test_revisionable_one_association_record_id' => nil}
revision = ActsAsRevisionable::RevisionRecord.new(TestRevisionableRecord.new(attributes), :yaml)
TestRevisionableRecord.acts_as_revisionable_options[:encoding] = :yaml
revision = ActsAsRevisionable::RevisionRecord.new(TestRevisionableRecord.new(attributes))
revision.data = Zlib::Deflate.deflate(YAML.dump(attributes))
restored = revision.restore
restored.class.should == TestRevisionableRecord
Expand All @@ -239,7 +241,8 @@ def self.base_class

it "should be able to restore the original model using XML serialization" do
attributes = {'id' => 1, 'name' => 'revision', 'value' => 5, 'test_revisionable_one_association_record_id' => nil}
revision = ActsAsRevisionable::RevisionRecord.new(TestRevisionableRecord.new(attributes), :xml)
TestRevisionableRecord.acts_as_revisionable_options[:encoding] = :xml
revision = ActsAsRevisionable::RevisionRecord.new(TestRevisionableRecord.new(attributes))
revision.data = Zlib::Deflate.deflate(YAML.dump(attributes))
restored = revision.restore
restored.class.should == TestRevisionableRecord
Expand Down