Skip to content

Commit

Permalink
Use ApplicationRecord for Redmine 6 or later (#130)
Browse files Browse the repository at this point in the history
Related:
#126

## Issue
CI failed because of the following error.
```console
Error:
FullTextSearch::SearchControllerTest::AttachmentTest#test_api:
NoMethodError: undefined method `acts_as_event' for FullTextSearch::Target:Class
```
ref:
https://github.com/clear-code/redmine_full_text_search/actions/runs/8164642884/job/22320305058

## Cause
`Redmine::Acts::Event` isn't included in `ActiveRecord::Base` anymore.
That's the reason we cannot use `Redmine::Acts::Event#acts_as_event`.

Before Redmine v5.1, `ActiveRecord::Base` included
`Redmine::Acts::Event`. And `ActiveRecord::Base` was a base class.


https://github.com/redmine/redmine/blob/ed7873a4c49d9209c597378dab9a982391093c32/lib/plugins/acts_as_event/init.rb#L4

After Redmine master, `ApplicationRecord` included
`Redmine::Acts::Event`. And `ApplicationRecord` was a base class.


https://github.com/redmine/redmine/blob/fb449c77bc76b3bae9b3f0bfe18560b11f00902c/lib/plugins/acts_as_event/init.rb#L22

## Solution
Change the base class from ActiveRecord::Base to ApplicationRecord.

---------

Co-authored-by: Sutou Kouhei <[email protected]>
  • Loading branch information
otegami and kou authored Mar 6, 2024
1 parent aead520 commit eaddeb1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# For backward compatibility with Redmine < 6.
# ApplicationRecord is inherited from ActiveRecord Models instead of ActiveRecord::Base in Redmine >= 6.
# ref: https://www.redmine.org/issues/38975
unless defined?(ApplicationRecord)
ApplicationRecord = ActiveRecord::Base
end
2 changes: 1 addition & 1 deletion app/models/fts_query_expansion.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class FtsQueryExpansion < ActiveRecord::Base
class FtsQueryExpansion < ApplicationRecord
if respond_to?(:connection_db_config)
adapter = connection_db_config.adapter
else
Expand Down
2 changes: 1 addition & 1 deletion app/models/full_text_search/issue_content.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module FullTextSearch
class IssueContent < ActiveRecord::Base
class IssueContent < ApplicationRecord
end
end
2 changes: 1 addition & 1 deletion app/models/full_text_search/tag.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module FullTextSearch
class Tag < ActiveRecord::Base
class Tag < ApplicationRecord
self.table_name = :fts_tags
belongs_to :type, class_name: "FullTextSearch::TagType"

Expand Down
2 changes: 1 addition & 1 deletion app/models/full_text_search/tag_type.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module FullTextSearch
class TagType < ActiveRecord::Base
class TagType < ApplicationRecord
self.table_name = :fts_tag_types
has_many :tags, foreign_key: "type_id"

Expand Down
2 changes: 1 addition & 1 deletion app/models/full_text_search/target.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module FullTextSearch
class Target < ActiveRecord::Base
class Target < ApplicationRecord
self.table_name = :fts_targets

if respond_to?(:connection_db_config)
Expand Down
2 changes: 1 addition & 1 deletion app/models/full_text_search/type.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module FullTextSearch
class Type < ActiveRecord::Base
class Type < ApplicationRecord
self.table_name = :fts_types

class << self
Expand Down

0 comments on commit eaddeb1

Please sign in to comment.