Skip to content

Commit

Permalink
Reorganizing specs for new VersionConcern module merged from #289
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Atkins committed Oct 29, 2013
1 parent c0044a0 commit 975e1bb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 45 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 3.0.0 (Unreleased)

- [#289](/~https://github.com/airblade/paper_trail/pull/289) - Use `ActiveSupport::Concern` for implementation of base functionality on
`PaperTrail::Version` class. Increases flexibility and makes it easier to use custom version classes with multiple `ActiveRecord` connections.
- [#288](/~https://github.com/airblade/paper_trail/issues/288) - Change all scope declarations to class methods on the `PaperTrail::Version`
class. Fixes usability when `PaperTrail::Version.abstract_class? == true`.
- [#287](/~https://github.com/airblade/paper_trail/issues/287) - Support for
Expand Down
48 changes: 3 additions & 45 deletions spec/models/version_spec.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
require 'spec_helper'

module Foo
class Base < ActiveRecord::Base
self.abstract_class = true
end

class Document < Base
has_paper_trail :class_name => 'Foo::Version'
end

class Version < Base
include PaperTrail::VersionConcern
end
end
Foo::Base.establish_connection(:adapter => 'sqlite3', :database => File.expand_path('../../../test/dummy/db/test-foo.sqlite3', __FILE__))

module Bar
class Base < ActiveRecord::Base
self.abstract_class = true
end

class Document < Base
has_paper_trail :class_name => 'Bar::Version'
end

class Version < Base
include PaperTrail::VersionConcern
end
end
Bar::Base.establish_connection(:adapter => 'sqlite3', :database => File.expand_path('../../../test/dummy/db/test-bar.sqlite3', __FILE__))

describe PaperTrail::VersionConcern do
it 'allows included class to have different connections' do
Foo::Version.connection.should_not eq Bar::Version.connection
end

it 'allows custom version class to share connection with superclass' do
Foo::Version.connection.should eq Foo::Document.connection
Bar::Version.connection.should eq Bar::Document.connection
describe PaperTrail::Version do
it "should include the `VersionConcern` module to get base functionality" do
PaperTrail::Version.should include(PaperTrail::VersionConcern)
end

it 'can be used with class_name option' do
Foo::Document.version_class_name.should eq 'Foo::Version'
Bar::Document.version_class_name.should eq 'Bar::Version'
end
end

describe PaperTrail::Version do
describe "Attributes" do
it { should have_db_column(:item_type).of_type(:string) }
it { should have_db_column(:item_id).of_type(:integer) }
Expand Down
50 changes: 50 additions & 0 deletions spec/modules/version_concern_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'spec_helper'

describe PaperTrail::VersionConcern do

before(:all) do
module Foo
class Base < ActiveRecord::Base
self.abstract_class = true
end

class Document < Base
has_paper_trail :class_name => 'Foo::Version'
end

class Version < Base
include PaperTrail::VersionConcern
end
end
Foo::Base.establish_connection(:adapter => 'sqlite3', :database => File.expand_path('../../../test/dummy/db/test-foo.sqlite3', __FILE__))

module Bar
class Base < ActiveRecord::Base
self.abstract_class = true
end

class Document < Base
has_paper_trail :class_name => 'Bar::Version'
end

class Version < Base
include PaperTrail::VersionConcern
end
end
Bar::Base.establish_connection(:adapter => 'sqlite3', :database => File.expand_path('../../../test/dummy/db/test-bar.sqlite3', __FILE__))
end

it 'allows included class to have different connections' do
Foo::Version.connection.should_not eq Bar::Version.connection
end

it 'allows custom version class to share connection with superclass' do
Foo::Version.connection.should eq Foo::Document.connection
Bar::Version.connection.should eq Bar::Document.connection
end

it 'can be used with class_name option' do
Foo::Document.version_class_name.should eq 'Foo::Version'
Bar::Document.version_class_name.should eq 'Bar::Version'
end
end

0 comments on commit 975e1bb

Please sign in to comment.