2017-12-10 23:05:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-30 00:58:26 -04:00
|
|
|
require "spec_helper"
|
2017-11-30 21:39:22 -05:00
|
|
|
require "support/alt_db_init"
|
2013-10-29 11:57:41 -04:00
|
|
|
|
2017-05-21 01:41:20 -04:00
|
|
|
RSpec.describe PaperTrail::VersionConcern do
|
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
|
2017-04-01 01:50:13 -04:00
|
|
|
it "stores versions in the correct corresponding db location" do
|
2017-03-31 22:11:08 -04:00
|
|
|
foo_doc = Foo::Document.create!(name: "foobar")
|
|
|
|
bar_doc = Bar::Document.create!(name: "raboof")
|
|
|
|
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
|