diff --git a/spec/marten-turbo/handlers/record_delete_spec.cr b/spec/marten-turbo/handlers/record_delete_spec.cr
index 1a64ef1..6dec4a2 100644
--- a/spec/marten-turbo/handlers/record_delete_spec.cr
+++ b/spec/marten-turbo/handlers/record_delete_spec.cr
@@ -12,8 +12,8 @@ describe MartenTurbo::Handlers::RecordCreate do
method: "GET",
resource: "",
headers: HTTP::Headers{
- "Accept" => "text/html",
- "Host" => "example.com",
+ "Accept" => "text/html",
+ "Host" => "example.com",
}
)
)
@@ -36,8 +36,8 @@ describe MartenTurbo::Handlers::RecordCreate do
method: "GET",
resource: "",
headers: HTTP::Headers{
- "Accept" => "text/html",
- "Host" => "example.com",
+ "Accept" => "text/html",
+ "Host" => "example.com",
}
)
)
@@ -49,6 +49,53 @@ describe MartenTurbo::Handlers::RecordCreate do
Tag.get(pk: tag_1.pk).should be_nil
Tag.get(pk: tag_2.pk).should eq tag_2
end
+
+ it "deletes the record and returns the expected redirect when a turbo request was made and no template is given" do
+ tag_1 = Tag.create!(name: "Tag 1")
+ tag_2 = Tag.create!(name: "Tag 2")
+
+ params = Marten::Routing::MatchParameters{"pk" => tag_1.pk!}
+ request = Marten::HTTP::Request.new(
+ ::HTTP::Request.new(
+ method: "GET",
+ resource: "",
+ headers: HTTP::Headers{
+ "Accept" => "text/html",
+ "Host" => "example.com",
+ }
+ )
+ )
+ handler = MartenTurbo::Handlers::RecordDeleteSpec::TestWithoutTemplateHandler.new(request, params)
+
+ response = handler.post
+
+ response.should be_a Marten::HTTP::Response::Found
+ Tag.get(pk: tag_1.pk).should be_nil
+ Tag.get(pk: tag_2.pk).should eq tag_2
+ end
+
+ it "deletes the record and returns a delete turbo stream when a turbo request was made and a template is given" do
+ tag_1 = Tag.create!(name: "Tag 1")
+ tag_2 = Tag.create!(name: "Tag 2")
+
+ params = Marten::Routing::MatchParameters{"pk" => tag_1.pk!}
+ request = Marten::HTTP::Request.new(
+ ::HTTP::Request.new(
+ method: "GET",
+ resource: "",
+ headers: HTTP::Headers{
+ "Accept" => "text/vnd.turbo-stream.html",
+ "Host" => "example.com",
+ }
+ )
+ )
+ handler = MartenTurbo::Handlers::RecordDeleteSpec::TestHandler.new(request, params)
+
+ response = handler.post
+
+ response.should_not be_a Marten::HTTP::Response::Found
+ response.content.strip.should contain ""
+ end
end
end
diff --git a/spec/test_project/templates/tags/delete.turbo_stream.html b/spec/test_project/templates/tags/delete.turbo_stream.html
index 5f9f44f..d3f8bf6 100644
--- a/spec/test_project/templates/tags/delete.turbo_stream.html
+++ b/spec/test_project/templates/tags/delete.turbo_stream.html
@@ -1 +1 @@
-
+