Skip to content

Commit

Permalink
[wip] Failing spec for #3354
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Jun 29, 2021
1 parent 555f778 commit c24d54b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def listing_for_model_or_object(model, object, query, sort, sort_reverse, all, p

current_page = page.presence || '1'

versions = object.nil? ? versions_for_model(model) : object.versions
versions = object.nil? ? versions_for_model(model) : object.public_send(object.versions_association_name)
versions = versions.where('event LIKE ?', "%#{query}%") if query.present?
versions = versions.order(sort_reverse == 'true' ? "#{sort} DESC" : sort)
versions = all ? versions : versions.send(Kaminari.config.page_method_name, current_page).per(per_page)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class PaperTrailTestWithCustomAssociation < ActiveRecord::Base
self.table_name = :paper_trail_tests
has_paper_trail versions: {name: :trails}
end
4 changes: 4 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@
factory :paper_trail_test_subclass_in_namespace,
parent: :paper_trail_test,
class: 'PaperTrailTest::SubclassInNamespace'

factory :paper_trail_test_with_custom_association,
parent: :paper_trail_test,
class: 'PaperTrailTestWithCustomAssociation'
end
end
15 changes: 11 additions & 4 deletions spec/integration/history/rails_admin_paper_trail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
end

it '#table returns item class name' do
expect(@version.table.to_s).to eq('PaperTrailTest')
expect(@version.table.to_s).to eq(@model.model.base_class.name)
end
end

Expand Down Expand Up @@ -143,7 +143,7 @@
end
end

context 'PaperTrailTest' do
context 'with a normal PaperTrail model' do
let(:paper_class_name) { 'PaperTrailTest' }
let(:paper_factory) { :paper_trail_test }

Expand All @@ -155,7 +155,7 @@
it_behaves_like :paper_history
end

context 'PaperTrailTestSubclass' do
context 'with a subclassed PaperTrail model' do
let(:paper_class_name) { 'PaperTrailTestSubclass' }
let(:paper_factory) { :paper_trail_test_subclass }

Expand All @@ -167,7 +167,7 @@
it_behaves_like :paper_history
end

context 'PaperTrailTest::SubclassInNamespace' do
context 'with a namespaced PaperTrail model' do
let(:paper_class_name) { 'PaperTrailTest::SubclassInNamespace' }
let(:paper_factory) { :paper_trail_test_subclass_in_namespace }

Expand All @@ -178,4 +178,11 @@

it_behaves_like :paper_history
end

context 'with a PaperTrail model with custom version association name' do
let(:paper_class_name) { 'PaperTrailTestWithCustomAssociation' }
let(:paper_factory) { :paper_trail_test_with_custom_association }

it_behaves_like :paper_history
end
end

0 comments on commit c24d54b

Please sign in to comment.