Skip to content

Commit 2e3d733

Browse files
authored
Fix TwitterAds::Creative::PromotedTweet#save (#239) (#240)
* Fix invalid converting params
1 parent ce4d2e8 commit 2e3d733

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

lib/twitter-ads/creative/promoted_tweet.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def save
4848

4949
# convert to `tweet_ids` param
5050
params = to_params
51-
params[:tweet_ids] = *params.delete(:tweet_id) if params.key?(:tweet_id)
51+
params[:tweet_ids] = params.delete(:tweet_id) if params.key?(:tweet_id)
5252

5353
if @id
5454
raise TwitterAds::NotFound.new(nil, 'Method PUT not allowed.', 404)

spec/twitter-ads/creative/promoted_tweet_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@
4141
expect { subject.save }.to raise_error(TwitterAds::ClientError)
4242
end
4343

44+
it 'sets params[:tweet_ids] from params[:tweet_id]' do
45+
request = double('request')
46+
response = double('response')
47+
allow(response).to receive(:body).and_return({ data: [{}] })
48+
allow(request).to receive(:perform).and_return(response)
49+
expected_params = { params: { line_item_id: '12345', tweet_ids: 99999999999999999999 } }
50+
51+
expect(Request).to receive(:new).with(
52+
client,
53+
:post,
54+
"/#{TwitterAds::API_VERSION}/accounts/#{account.id}/promoted_tweets",
55+
expected_params
56+
).and_return(request)
57+
58+
subject.line_item_id = '12345'
59+
subject.tweet_id = 99999999999999999999
60+
subject.save
61+
end
4462
end
4563

4664
end

0 commit comments

Comments
 (0)