Skip to content

Commit

Permalink
chore: remove scopes that are too trivial and aren't even needed yet
Browse files Browse the repository at this point in the history
  • Loading branch information
wwrk22 committed Jan 8, 2024
1 parent 6c34708 commit 1388b6d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
10 changes: 0 additions & 10 deletions app/models/rich_text_reaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,4 @@ class RichTextReaction < ApplicationRecord
in: Emoji.captions,
message: 'must be present in permissible set'
}

# +rich_text+ can be an ActionText::RichText object or its id.
scope :for_rich_text, ->(rich_text) do
RichTextReaction.includes(:user).where(rich_text:)
end

# +rich_texts+ can be an array of ActionText::RichText objects or their ids.
scope :for_rich_texts, ->(rich_texts) do
for_rich_text(rich_texts)
end
end
37 changes: 0 additions & 37 deletions spec/models/rich_text_reactions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,4 @@

expect(rich_text_reaction.errors[:emoji_caption]).to be_present
end

describe '.for_rich_text' do
context 'when given an ActionText::RichText record' do
it 'returns all associated RichTextReaction records' do
# Create a couple of reactions for the same rich text.
reaction = create(:rich_text_reaction)
create(:rich_text_reaction,
user: create(:user),
rich_text_id: reaction.rich_text_id)

reactions = described_class.for_rich_text(reaction.rich_text)

expect(described_class.all - reactions).to be_empty
end
end
end

describe '.for_rich_texts' do
context 'when given multiple ActionText::RichText ids' do
it 'returns all associated RichTextReaction records' do
# Create a couple of reactions for each rich text.
100.times do
reaction = create(:rich_text_reaction)
create(:rich_text_reaction,
user: create(:user),
rich_text_id: reaction.rich_text_id)
end

# The ids of the rich texts to find reactions for.
rich_text_ids = described_class.distinct.pluck(:rich_text_id)

reactions = described_class.for_rich_texts(rich_text_ids)

expect(described_class.all - reactions).to be_empty
end
end
end
end

0 comments on commit 1388b6d

Please sign in to comment.