2016-03-05 17:07:32 -05:00
|
|
|
require "rails_helper"
|
2013-10-29 11:57:41 -04:00
|
|
|
|
|
|
|
describe PaperTrail::VersionConcern do
|
2016-03-05 17:07:32 -05:00
|
|
|
before(:all) { require "support/alt_db_init" }
|
2013-10-29 11:57:41 -04:00
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
it "allows included class to have different connections" do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(Foo::Version.connection).not_to eq(Bar::Version.connection)
|
2013-10-29 11:57:41 -04:00
|
|
|
end
|
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
it "allows custom version class to share connection with superclass" do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(Foo::Version.connection).to eq(Foo::Document.connection)
|
|
|
|
expect(Bar::Version.connection).to eq(Bar::Document.connection)
|
2013-10-29 11:57:41 -04:00
|
|
|
end
|
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
it "can be used with class_name option" do
|
|
|
|
expect(Foo::Document.version_class_name).to eq("Foo::Version")
|
|
|
|
expect(Bar::Document.version_class_name).to eq("Bar::Version")
|
2013-12-03 15:55:45 -05:00
|
|
|
end
|
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
describe "persistence", versioning: true do
|
2013-12-03 15:55:45 -05:00
|
|
|
before do
|
2016-03-05 17:07:32 -05:00
|
|
|
@foo_doc = Foo::Document.create!(name: "foobar")
|
|
|
|
@bar_doc = Bar::Document.create!(name: "raboof")
|
2013-12-03 15:55:45 -05:00
|
|
|
end
|
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
it "should store versions in the correct corresponding db location" do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(@foo_doc.versions.first).to be_instance_of(Foo::Version)
|
|
|
|
expect(@bar_doc.versions.first).to be_instance_of(Bar::Version)
|
2013-12-03 15:55:45 -05:00
|
|
|
end
|
2013-10-29 11:57:41 -04:00
|
|
|
end
|
|
|
|
end
|