Last active
August 29, 2015 14:05
-
-
Save opsb/8d0aa20d82965d53cbec to your computer and use it in GitHub Desktop.
Post a json callback request using capybara / jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def post_json_callback(path, payload) | |
| script = "jQuery.ajax({url: '#{path}', type: 'POST', data: JSON.stringify(#{payload.to_json}), contentType: 'application/json; charset=utf-8'});" | |
| page.execute_script(script) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def wait_for_ajax | |
| Timeout.timeout(::Capybara.default_wait_time) do | |
| loop until finished_all_ajax_requests? | |
| end | |
| end | |
| def finished_all_ajax_requests? | |
| page.evaluate_script('jQuery.active').zero? | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| zencoder_payload = { | |
| job: { status: 'finished' }, | |
| output: { | |
| id: 123, | |
| state: 'finished', | |
| thumbnails: [ | |
| {label: "small", images: [{url: "s3://#{ENV["AWS_S3_BUCKET"]}/test/users/@user.id/videos/#{@video.id}/0000-550x413-video-1-sml-thumbnail.png"}]}, | |
| {label: "medium", images: [{url: "s3://#{ENV["AWS_S3_BUCKET"]}/test/users/@user.id/videos/#{@video.id}/0000-550x413-video-1-med-thumbnail.png"}]}, | |
| {label: "large", images: [{url: "s3://#{ENV["AWS_S3_BUCKET"]}/test/users/@user.id/videos/#{@video.id}/0000-550x413-video-1-lrg-thumbnail.png"}]} | |
| ] | |
| } | |
| } | |
| post_json_callback("/zencoder-callback", zencoder_payload) | |
| wait_for_ajax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment