-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding some tests * fix: readme * Serialize using yaml so we can support lower versions of rails * Fixing rails 6 tests
- Loading branch information
Showing
8 changed files
with
89 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
deferred_request (0.0.1) | ||
deferred_request (1.0.0) | ||
rails (>= 6.0.0) | ||
|
||
GEM | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module DeferredRequest | ||
class TestController < ApplicationController | ||
def status_callback | ||
head :ok | ||
DeferredRequest.perform_later_from_request!(request) | ||
end | ||
|
||
def status_callback_deferred(deferred_request) | ||
# Do something with the deferred request | ||
deferred_request.params.dig("answer") | ||
end | ||
|
||
def status_error | ||
# don't add the "_deferred" method (used for testing) | ||
head :ok | ||
DeferredRequest.perform_later_from_request!(request) | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module DeferredRequest | ||
module TestHelper | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
DeferredRequest::Engine.routes.draw do | ||
post "status_callback" => "test#status_callback" | ||
post "status_error" => "test#status_error" | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require "test_helper" | ||
|
||
module DeferredRequest | ||
class TestControllerTest < ActionDispatch::IntegrationTest | ||
include Engine.routes.url_helpers | ||
|
||
test "can_defer json request successfully" do | ||
answer = 1 | ||
|
||
assert_no_performed_jobs | ||
|
||
assert_difference("DeferredRequest.count") do | ||
post status_callback_url, params: {answer: answer}, as: :json | ||
end | ||
|
||
assert_response :success | ||
|
||
assert_enqueued_jobs 1 | ||
|
||
perform_enqueued_jobs | ||
|
||
last_request = DeferredRequest.last | ||
|
||
assert_equal answer, last_request.result | ||
|
||
assert_performed_jobs 1 | ||
end | ||
|
||
test "can_defer json request successfully but handle no deferred method" do | ||
answer = 2 | ||
|
||
assert_no_performed_jobs | ||
|
||
assert_difference("DeferredRequest.count") do | ||
post status_error_url, params: {answer: answer}, as: :json | ||
end | ||
|
||
assert_response :success | ||
|
||
assert_enqueued_jobs 1 | ||
|
||
perform_enqueued_jobs | ||
|
||
last_request = DeferredRequest.last | ||
|
||
assert_not_equal answer, last_request.result | ||
assert_equal "error", last_request.status | ||
|
||
assert_performed_jobs 1 | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
request: MyText | ||
routing: MyText | ||
status: 1 | ||
|
||
two: | ||
request: MyText | ||
routing: MyText | ||
status: 1 | ||
# one: | ||
# request: '{"url":"http://localhost:3000/status_callback?yo=some_text","method":"POST","headers":{"HTTP_VERSION":"HTTP/1.1","HTTP_USER_AGENT":"PostmanRuntime/7.29.0","HTTP_ACCEPT":"*/*","HTTP_POSTMAN_TOKEN":"ab8d6da5-575e-49a1-85bd-2a1f7be0c06e","HTTP_HOST":"localhost:3000","HTTP_ACCEPT_ENCODING":"gzip, | ||
# deflate, br","HTTP_CONNECTION":"keep-alive"},"params":{"some":"more","yo":"some_text","test":{"some":"more"}},"remote_ip":"::1"}' | ||
# routing: '{"controller":"TestController","action":"status_callback"}' | ||
# status: "queued" |