Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't send an empty limit query parameter for Channel#get_reactions #39

Merged
merged 12 commits into from
Apr 29, 2021
2 changes: 1 addition & 1 deletion lib/discordrb/api/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def delete_user_reaction(token, channel_id, message_id, emoji, user_id)
# https://discord.com/developers/docs/resources/channel#get-reactions
def get_reactions(token, channel_id, message_id, emoji, before_id, after_id, limit = 100)
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
query_string = "limit=#{limit}#{"&before=#{before_id}" if before_id}#{"&after=#{after_id}" if after_id}"
query_string = "limit=#{limit || 100}#{"&before=#{before_id}" if before_id}#{"&after=#{after_id}" if after_id}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to see this as

query_string = URI.encode_www_form({ limit: limit, before: before_id, after: after_id }.compact)

Discordrb::API.request(
:channels_cid_messages_mid_reactions_emoji,
channel_id,
Expand Down
29 changes: 29 additions & 0 deletions spec/data/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,35 @@
end
end

describe '#reacted_with' do
let(:message) { described_class.new(message_data, bot) }
let(:emoji) { double('emoji') }

it 'calls the API method' do
expect(Discordrb::API::Channel).to receive(:get_reactions)
.with(token, channel_id, any_args, 27)
.and_return('[]')
message.reacted_with('👍', limit: 27)
end

it 'defaults to a limit of 100' do
expect(Discordrb::API::Channel).to receive(:get_reactions)
.with(token, channel_id, any_args, 100)
.and_return('[]')
message.reacted_with('👍')
end

it 'converts Emoji to strings' do
allow(emoji).to receive(:to_reaction).and_return('123')

expect(Discordrb::API::Channel).to receive(:get_reactions)
.with(token, channel_id, anything, '123', any_args)
.and_return('[]')

message.reacted_with(emoji)
end
end

describe '#reply!' do
let(:message) { described_class.new(message_data, bot) }
let(:content) { instance_double('String', 'content') }
Expand Down