aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Smith <zach@driver.xyz>2018-03-20 14:59:01 -0700
committerZach Smith <zach@driver.xyz>2018-03-20 14:59:01 -0700
commit424e025f1c719006fe6a6669e43667e1d39ff076 (patch)
treed195616cca72ef37c98d85d6440e234cb19c6b4c
parentdd25ecb1e5cc93bd2da94f4e4bfddc9d3a5ebb5e (diff)
downloaddriver-core-424e025f1c719006fe6a6669e43667e1d39ff076.tar.gz
driver-core-424e025f1c719006fe6a6669e43667e1d39ff076.tar.bz2
driver-core-424e025f1c719006fe6a6669e43667e1d39ff076.zip
Curry the PatchRetrievable apply method
-rw-r--r--src/main/scala/xyz/driver/core/rest/PatchSupport.scala4
-rw-r--r--src/test/scala/xyz/driver/core/rest/PatchSupportTest.scala12
2 files changed, 8 insertions, 8 deletions
diff --git a/src/main/scala/xyz/driver/core/rest/PatchSupport.scala b/src/main/scala/xyz/driver/core/rest/PatchSupport.scala
index 5ded61f..d7c77c8 100644
--- a/src/main/scala/xyz/driver/core/rest/PatchSupport.scala
+++ b/src/main/scala/xyz/driver/core/rest/PatchSupport.scala
@@ -19,9 +19,9 @@ trait PatchSupport extends Directives with SprayJsonSupport {
}
object PatchRetrievable {
- def apply[T](retriever: ((Id[T], ServiceRequestContext) => Future[Option[T]])): PatchRetrievable[T] =
+ def apply[T](retriever: (Id[T] => (ServiceRequestContext => Future[Option[T]]))): PatchRetrievable[T] =
new PatchRetrievable[T] {
- override def apply(id: Id[T])(implicit ctx: ServiceRequestContext): Future[Option[T]] = retriever(id, ctx)
+ override def apply(id: Id[T])(implicit ctx: ServiceRequestContext): Future[Option[T]] = retriever(id)(ctx)
}
}
diff --git a/src/test/scala/xyz/driver/core/rest/PatchSupportTest.scala b/src/test/scala/xyz/driver/core/rest/PatchSupportTest.scala
index 20d667d..5c7faf8 100644
--- a/src/test/scala/xyz/driver/core/rest/PatchSupportTest.scala
+++ b/src/test/scala/xyz/driver/core/rest/PatchSupportTest.scala
@@ -34,7 +34,7 @@ class PatchSupportTest
val ContentTypeHeader = `Content-Type`(ContentType.parse("application/merge-patch+json").right.get)
"PatchSupport" should "allow partial updates to an existing object" in {
- implicit val fooPatchable = PatchRetrievable[Foo]((id, _) => Future.successful(Some(testFoo.copy(id = id))))
+ implicit val fooPatchable = PatchRetrievable[Foo](id => _ => Future.successful(Some(testFoo.copy(id = id))))
Patch("/api/v1/foos/1", jsonEntity("""{"rank": 4}""")).withHeaders(ContentTypeHeader) ~> route ~> check {
handled shouldBe true
@@ -43,7 +43,7 @@ class PatchSupportTest
}
it should "merge deeply nested objects" in {
- implicit val fooPatchable = PatchRetrievable[Foo]((id, _) => Future.successful(Some(testFoo.copy(id = id))))
+ implicit val fooPatchable = PatchRetrievable[Foo](id => _ => Future.successful(Some(testFoo.copy(id = id))))
Patch("/api/v1/foos/1", jsonEntity("""{"rank": 4, "bar": {"name": "My Bar"}}"""))
.withHeaders(ContentTypeHeader) ~> route ~> check {
@@ -53,7 +53,7 @@ class PatchSupportTest
}
it should "return a 404 if the object is not found" in {
- implicit val fooPatchable = PatchRetrievable[Foo]((id, _) => Future.successful(None))
+ implicit val fooPatchable = PatchRetrievable[Foo](_ => _ => Future.successful(None))
Patch("/api/v1/foos/1", jsonEntity("""{"rank": 4}""")).withHeaders(ContentTypeHeader) ~> route ~> check {
handled shouldBe true
@@ -62,7 +62,7 @@ class PatchSupportTest
}
it should "handle nulls on optional values correctly" in {
- implicit val fooPatchable = PatchRetrievable[Foo]((id, _) => Future.successful(Some(testFoo.copy(id = id))))
+ implicit val fooPatchable = PatchRetrievable[Foo](id => _ => Future.successful(Some(testFoo.copy(id = id))))
Patch("/api/v1/foos/1", jsonEntity("""{"bar": null}""")).withHeaders(ContentTypeHeader) ~> route ~> check {
handled shouldBe true
@@ -71,7 +71,7 @@ class PatchSupportTest
}
it should "return a 400 for nulls on non-optional values" in {
- implicit val fooPatchable = PatchRetrievable[Foo]((id, _) => Future.successful(Some(testFoo.copy(id = id))))
+ implicit val fooPatchable = PatchRetrievable[Foo](id => _ => Future.successful(Some(testFoo.copy(id = id))))
Patch("/api/v1/foos/1", jsonEntity("""{"rank": null}""")).withHeaders(ContentTypeHeader) ~> route ~> check {
handled shouldBe true
@@ -80,7 +80,7 @@ class PatchSupportTest
}
it should "return a 400 for incorrect Content-Type" in {
- implicit val fooPatchable = PatchRetrievable[Foo]((id, _) => Future.successful(Some(testFoo.copy(id = id))))
+ implicit val fooPatchable = PatchRetrievable[Foo](id => _ => Future.successful(Some(testFoo.copy(id = id))))
Patch("/api/v1/foos/1", jsonEntity("""{"rank": 4}""")) ~> route ~> check {
status shouldBe StatusCodes.BadRequest