Skip to content

Commit b6e0ab4

Browse files
API / naming: special rules for actor-like models
Switched from `<associat>ful` form to check for related records’ presence back to a passive one (`<associat>ed`). Thus, it’s `authored` and `edited` now instead of `authorful` and `editful`. References: 2a6165d.
1 parent 8de5589 commit b6e0ab4

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
### Changed
44

5+
- Special naming rules for “actor-like” models:
6+
switched from `<associat>ful` form to check for related records’ presence back to a passive one (`<associat>ed`).
7+
Thus, it’s `authored` and `edited` now instead of `authorful` and `editful`.
58
- `Relationship.to`/`.of` handle STI classes precisely instead of falling back to a base class.
69
- Customized inspections for `Relationship`.
710

lib/adjustable_schema/active_record/association/naming.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ module Actors # :nodoc:
4444
source: role.name,
4545
target: "#{role.name.passivize}_#{target_name}",
4646
}[direction]
47+
48+
def name_for_any(name = object_name) = name
49+
.passivize
50+
.to_sym
4751
end
4852

4953
def initialize(...)

test/lib/active_record/association_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ def defines_methods(&)
6868
.wont_respond_to :recursive
6969
end
7070

71+
describe 'with an actor-like model' do
72+
let(:direction) { :source }
73+
let(:target) { User }
74+
let(:role_name) { :author }
75+
76+
let(:association_name) { 'authors' }
77+
let(:name_for_any) { 'authored' }
78+
79+
defines_scopes
80+
defines_methods
81+
82+
describe 'without a role' do
83+
let(:role) {}
84+
85+
let(:association_name) { 'users' }
86+
let(:name_for_any) { 'used' }
87+
88+
defines_scopes
89+
defines_methods
90+
end
91+
end
92+
7193
describe 'when recursive' do
7294
let(:target) { owner }
7395

0 commit comments

Comments
 (0)