forked from paper-trail-gem/paper_trail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing joins, as recommended by Sean
- Loading branch information
Showing
6 changed files
with
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
# Note that there is no `type` column for this subclassed model, so changes to | ||
# Management objects should result in Versions which have an item_type of | ||
# Customer. | ||
class Management < Customer | ||
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
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
::RSpec.describe(::Management, type: :model, versioning: true) do | ||
it "utilises the base_class for STI classes having no type column" do | ||
expect(Management.inheritance_column).to eq("type") | ||
expect(Management.columns.map(&:name)).not_to include("type") | ||
|
||
# Create, update, and destroy a Management and a Customer | ||
customer1 = Customer.create(name: "Cust 1") | ||
customer2 = Management.create(name: "Cust 2") | ||
customer1.update(name: "Cust 1a") | ||
customer2.update(name: "Cust 2a") | ||
customer1.destroy | ||
customer2.destroy | ||
|
||
# All versions end up with an `item_type` of Customer | ||
expect( | ||
PaperTrail::Version.where(item_type: "Customer").count | ||
).to eq(6) | ||
expect( | ||
PaperTrail::Version.where(item_type: "Management").count | ||
).to eq(0) | ||
|
||
# The item_subtype, on the other hand, is 3 and 3 | ||
expect( | ||
PaperTrail::Version.where(item_subtype: "Customer").count | ||
).to eq(3) | ||
expect( | ||
PaperTrail::Version.where(item_subtype: "Management").count | ||
).to eq(3) | ||
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
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
::RSpec.describe(::Song, type: :model, versioning: true) do | ||
describe "#joins" do | ||
it "works" do | ||
described_class.create! | ||
result = described_class. | ||
joins(:versions). | ||
select("songs.id, max(versions.event) as event"). | ||
group("songs.id"). | ||
first | ||
expect(result.event).to eq("create") | ||
end | ||
end | ||
end |