-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #451; Fix VersionConcern#reify in the context of models with a …
…default scope
- Loading branch information
Showing
5 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'rails_helper' | ||
require Rails.root.join('..', 'custom_json_serializer') | ||
|
||
describe Boolit, :type => :model do | ||
it { is_expected.to be_versioned } | ||
|
||
it "has a default scope" do | ||
expect(subject.default_scopes).to_not be_empty | ||
end | ||
|
||
describe "Versioning", :versioning => true do | ||
subject { Boolit.create! } | ||
before { subject.update_attributes!(:name => Faker::Name.name) } | ||
|
||
it "should have versions" do | ||
expect(subject.versions.size).to eq(2) | ||
end | ||
|
||
it "should be able to be reified and persisted" do | ||
expect { subject.versions.last.reify.save! }.to_not raise_error | ||
end | ||
|
||
context "Instance falls out of default scope" do | ||
before { subject.update_attributes!(:scoped => false) } | ||
|
||
it "is NOT scoped" do | ||
expect(Boolit.first).to be_nil | ||
end | ||
|
||
it "should still be able to be reified and persisted" do | ||
expect { subject.previous_version.save! }.to_not raise_error | ||
end | ||
|
||
context "with `nil` attributes on the live instance" do | ||
before do | ||
PaperTrail.serializer = CustomJsonSerializer | ||
subject.update_attributes!(:name => nil) | ||
subject.update_attributes!(:name => Faker::Name.name) | ||
end | ||
after { PaperTrail.serializer = PaperTrail::Serializers::YAML } | ||
|
||
it "should not overwrite that attribute during the reification process" do | ||
expect(subject.previous_version.name).to be_nil | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Boolit < ActiveRecord::Base | ||
default_scope { where(:scoped => true) } | ||
has_paper_trail | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters