おそらく、POST
リクエストを処理するためにコントローラーを使用しています。それを呼び出しましょうWebhookController
必要なもののパラメーターを含む投稿が、必要なことを行っていることを簡単にテストできます。例:統合テスト (テスト単位ですが、rspec は同じことを行います)。
Rspec にはfixture_file_upload
、xml ファイルのアップロード/追加用のバージョンが異なる場合がありますが、このスタックの質問によると、それも使用できるようです。ファイルを say に貼り付けますspec/files
。
とにかく、Web と初心者の場合Delayed::Job
、別のテストで呼び出しが実際に機能することをテストすることになります。何かのようなもの:
class GetWebhookTest < ActionController::IntegrationTest
fixtures :all
def recieve_webhook
post '/webhook/338782', fixture_file_upload('webhook.xml', 'application/xml')
end
#Test you do what the outcome of your POST would be.
#this is refactored but you can shove the post line where receive_webhook is
test "recieve a webhook via xml" do
assert_difference('RawData.count') do
receive_webhook
end
end
test "make sure the status is 200" do
recieve_webhook
assert_response :success
end
#Test 1 will fail before this, but i was more/too thorough back in the day
test "Delayed Job increases" do
assert_difference "Delayed::Job.count", 1 do
recieve_webhook
end
end
end
繰り返しますが、Rspec にはresponse.should be_success
Object.count 差分メソッドのようなものもあります。状況に合わせて調整してください。鍵はfixture_file_upload