Skip to content

Commit

Permalink
Memoize AdminUser#active_tags
Browse files Browse the repository at this point in the history
fixes: #348
  • Loading branch information
werner committed May 5, 2021
1 parent f1a8242 commit ba26db3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/admin_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def renew_otp_secret_key!
end

def active_tags
admin_user_taggings.pluck(:tag_id)
@active_tags ||= admin_user_taggings.pluck(:tag_id).presence
end

def can_manage_tag?(tag)
Expand Down
12 changes: 12 additions & 0 deletions spec/models/person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@
expect(persons[3].id).to eq(person4.id)
end

it 'memoize active tags' do
_, _, person3, = setup_for_admin_tags_spec
expect(Person.default_scope).to include(person3)
create(:admin_user_tagging,
admin_user: AdminUser.current_admin_user,
tag: PersonTagging.first.tag)
expect(AdminUser.current_admin_user.reload.active_tags).not_to be_empty
AdminUserTagging.delete_all
expect(AdminUser.current_admin_user.active_tags).not_to be_empty
expect(Person.default_scope).not_to include(person3)
end

it 'add country tag and create a new tag' do
person = create(:empty_person)

Expand Down

0 comments on commit ba26db3

Please sign in to comment.