{"action":"created","comment":{"url":"https://api.github.com/repos/VirtusLab/beholder/pulls/comments/63325855","id":63325855,"diff_hunk":"@@ -31,39 +31,77 @@ trait ModelIncluded {\n \n   lazy val userMachineQuery = TableQuery[UserMachines]\n \n-  final def rollbackWithModel[A](func: Session => A): A = rollback {\n-    implicit session: Session =>\n-      usersRepository.create()\n-      machineRepository.create()\n-      Slick3Invoker.invokeAction(userMachineQuery.schema.create)\n-      func(session)\n+  object RollbackException extends Exception\n+\n+  /**\n+   * Runs action in rolled-back transaction.\n+   *\n+   * @param func function to run in rolled-back transaction\n+   * @tparam Result type returned by `f`\n+   * @return value returned from `f`\n+   */\n+  def rollbackActionWithModel[Result](func: => DBIO[Result]): Unit = withApp { implicit app =>\n+\n+    val createAndRunAction = for {\n+      _ <- usersRepository.createAction()\n+      _ <- machineRepository.createAction()\n+      _ <- userMachineQuery.schema.create\n+    } yield ()\n+\n+    val out = createAndRunAction\n+      .flatMap(_ => func)\n+      .flatMap(_ => DBIO.failed(RollbackException)).transactionally\n+\n+    val DB = DatabaseConfigProvider.get(app).db.asInstanceOf[driver.profile.backend.DatabaseDef]\n+\n+    Try(Await.result(DB.run(out), 10.seconds)) match {\n+      case Failure(RollbackException) =>\n+      case Failure(other) => throw other\n+    }\n   }\n \n-  class PopulatedDatabase(implicit session: Session) {\n-\n-    val users = Seq(\n-      User(None, \"a@a.pl\", \"Ala\", \"maKota\"),\n-      User(None, \"o@a.pl\", \"Ola\", \"maPsa\")\n-    ).map { user =>\n-        val userId = usersRepository.save(user)\n-        val userWithId = user.copy(id = Some(userId))\n-        userWithId\n-      }\n-\n-    val machines = Seq(\n-      Machine(None, \"a.a.pl\", \"Ubuntu\", 4, new Date(DateTime.now().minusHours(24).getMillis), Some(1), MachineStatus.Inactive),\n-      Machine(None, \"o.a.pl\", \"Fedora\", 1, new Date(DateTime.now().getMillis), Some(3), MachineStatus.Active)\n-    ).map(machine => machine.copy(id = Some(machineRepository.save(machine))))\n-\n-    val Seq(user1, user2) = users\n-    val Seq(machine1, machine2) = machines\n-\n-    Slick3Invoker.invokeAction(userMachineQuery ++= Seq(\n-      (user1.id.get, machine1.id.get),\n-      (user2.id.get, machine1.id.get),\n-      (user2.id.get, machine2.id.get)\n-    ))\n+  def populatedDatabase: DBIO[Unit] = {\n+\n+    val usersAction = DBIO.sequence(\n+      Seq(\n+        User(None, \"a@a.pl\", \"Ala\", \"maKota\"),\n+        User(None, \"o@a.pl\", \"Ola\", \"maPsa\")\n+      ).map { user =>\n+          val userIdAction = usersRepository.saveAction(user)\n+          userIdAction.map {\n+            userId =>\n+              user.copy(id = Some(userId))\n+          }\n+        }\n+    )\n+\n+    val machinesAction = DBIO.sequence(\n+      Seq(\n+        Machine(None, \"a.a.pl\", \"Ubuntu\", 4, new Date(DateTime.now().minusHours(24).getMillis), Some(1), MachineStatus.Inactive),\n+        Machine(None, \"o.a.pl\", \"Fedora\", 1, new Date(DateTime.now().getMillis), Some(3), MachineStatus.Active)\n+      ).map {\n+          machine =>\n+            val machineIdAction = machineRepository.saveAction(machine)\n+            machineIdAction.map {\n+              machineId =>\n+                machine.copy(id = Some(machineId))\n+            }\n+        }\n+    )\n+\n+    usersAction.zip(machinesAction).flatMap {\n+      case (users, machines) =>\n+        val Seq(user1, user2) = users\n+        val Seq(machine1, machine2) = machines\n+\n+        userMachineQuery ++= Seq(\n+          (user1.id.get, machine1.id.get),\n+          (user2.id.get, machine1.id.get),\n+          (user2.id.get, machine2.id.get)\n+        )\n+    }.map(_ => ())","path":"src/test/scala/org/virtuslab/beholder/BaseTest.scala","position":null,"original_position":122,"commit_id":"a5349c0908c68dc6406fcf14764863c4dadd5fe3","original_commit_id":"40c7b3db523251eaa7e025e1becef2f6fbb3cc32","user":{"login":"tgodzik","id":3807253,"avatar_url":"https://avatars.githubusercontent.com/u/3807253?v=3","gravatar_id":"","url":"https://api.github.com/users/tgodzik","html_url":"https://github.com/tgodzik","followers_url":"https://api.github.com/users/tgodzik/followers","following_url":"https://api.github.com/users/tgodzik/following{/other_user}","gists_url":"https://api.github.com/users/tgodzik/gists{/gist_id}","starred_url":"https://api.github.com/users/tgodzik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tgodzik/subscriptions","organizations_url":"https://api.github.com/users/tgodzik/orgs","repos_url":"https://api.github.com/users/tgodzik/repos","events_url":"https://api.github.com/users/tgodzik/events{/privacy}","received_events_url":"https://api.github.com/users/tgodzik/received_events","type":"User","site_admin":false},"body":"Fixed.","created_at":"2016-05-16T08:57:16Z","updated_at":"2016-05-16T08:57:16Z","html_url":"https://github.com/VirtusLab/beholder/pull/42#discussion_r63325855","pull_request_url":"https://api.github.com/repos/VirtusLab/beholder/pulls/42","_links":{"self":{"href":"https://api.github.com/repos/VirtusLab/beholder/pulls/comments/63325855"},"html":{"href":"https://github.com/VirtusLab/beholder/pull/42#discussion_r63325855"},"pull_request":{"href":"https://api.github.com/repos/VirtusLab/beholder/pulls/42"}}},"pull_request":{"url":"https://api.github.com/repos/VirtusLab/beholder/pulls/42","id":70164990,"html_url":"https://github.com/VirtusLab/beholder/pull/42","diff_url":"https://github.com/VirtusLab/beholder/pull/42.diff","patch_url":"https://github.com/VirtusLab/beholder/pull/42.patch","issue_url":"https://api.github.com/repos/VirtusLab/beholder/issues/42","number":42,"state":"open","locked":false,"title":"Migration to intermediate phase of using DBIOs. ","user":{"login":"tgodzik","id":3807253,"avatar_url":"https://avatars.githubusercontent.com/u/3807253?v=3","gravatar_id":"","url":"https://api.github.com/users/tgodzik","html_url":"https://github.com/tgodzik","followers_url":"https://api.github.com/users/tgodzik/followers","following_url":"https://api.github.com/users/tgodzik/following{/other_user}","gists_url":"https://api.github.com/users/tgodzik/gists{/gist_id}","starred_url":"https://api.github.com/users/tgodzik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tgodzik/subscriptions","organizations_url":"https://api.github.com/users/tgodzik/orgs","repos_url":"https://api.github.com/users/tgodzik/repos","events_url":"https://api.github.com/users/tgodzik/events{/privacy}","received_events_url":"https://api.github.com/users/tgodzik/received_events","type":"User","site_admin":false},"body":"- DBIOs are now used both in fitters and tests\r\n- uses new unicorn intermediate approach (0.7.2)","created_at":"2016-05-16T08:28:27Z","updated_at":"2016-05-16T08:57:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"99886a811a7cb23b982cc885f9e3b5af4f16808c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/VirtusLab/beholder/pulls/42/commits","review_comments_url":"https://api.github.com/repos/VirtusLab/beholder/pulls/42/comments","review_comment_url":"https://api.github.com/repos/VirtusLab/beholder/pulls/comments{/number}","comments_url":"https://api.github.com/repos/VirtusLab/beholder/issues/42/comments","statuses_url":"https://api.github.com/repos/VirtusLab/beholder/statuses/a5349c0908c68dc6406fcf14764863c4dadd5fe3","head":{"label":"tgodzik:v1.0.x-slick3.0.x-play2.4.x","ref":"v1.0.x-slick3.0.x-play2.4.x","sha":"a5349c0908c68dc6406fcf14764863c4dadd5fe3","user":{"login":"tgodzik","id":3807253,"avatar_url":"https://avatars.githubusercontent.com/u/3807253?v=3","gravatar_id":"","url":"https://api.github.com/users/tgodzik","html_url":"https://github.com/tgodzik","followers_url":"https://api.github.com/users/tgodzik/followers","following_url":"https://api.github.com/users/tgodzik/following{/other_user}","gists_url":"https://api.github.com/users/tgodzik/gists{/gist_id}","starred_url":"https://api.github.com/users/tgodzik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tgodzik/subscriptions","organizations_url":"https://api.github.com/users/tgodzik/orgs","repos_url":"https://api.github.com/users/tgodzik/repos","events_url":"https://api.github.com/users/tgodzik/events{/privacy}","received_events_url":"https://api.github.com/users/tgodzik/received_events","type":"User","site_admin":false},"repo":{"id":56590452,"name":"beholder","full_name":"tgodzik/beholder","owner":{"login":"tgodzik","id":3807253,"avatar_url":"https://avatars.githubusercontent.com/u/3807253?v=3","gravatar_id":"","url":"https://api.github.com/users/tgodzik","html_url":"https://github.com/tgodzik","followers_url":"https://api.github.com/users/tgodzik/followers","following_url":"https://api.github.com/users/tgodzik/following{/other_user}","gists_url":"https://api.github.com/users/tgodzik/gists{/gist_id}","starred_url":"https://api.github.com/users/tgodzik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tgodzik/subscriptions","organizations_url":"https://api.github.com/users/tgodzik/orgs","repos_url":"https://api.github.com/users/tgodzik/repos","events_url":"https://api.github.com/users/tgodzik/events{/privacy}","received_events_url":"https://api.github.com/users/tgodzik/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tgodzik/beholder","description":"Small slick lib for create views on on database","fork":true,"url":"https://api.github.com/repos/tgodzik/beholder","forks_url":"https://api.github.com/repos/tgodzik/beholder/forks","keys_url":"https://api.github.com/repos/tgodzik/beholder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tgodzik/beholder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tgodzik/beholder/teams","hooks_url":"https://api.github.com/repos/tgodzik/beholder/hooks","issue_events_url":"https://api.github.com/repos/tgodzik/beholder/issues/events{/number}","events_url":"https://api.github.com/repos/tgodzik/beholder/events","assignees_url":"https://api.github.com/repos/tgodzik/beholder/assignees{/user}","branches_url":"https://api.github.com/repos/tgodzik/beholder/branches{/branch}","tags_url":"https://api.github.com/repos/tgodzik/beholder/tags","blobs_url":"https://api.github.com/repos/tgodzik/beholder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tgodzik/beholder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tgodzik/beholder/git/refs{/sha}","trees_url":"https://api.github.com/repos/tgodzik/beholder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tgodzik/beholder/statuses/{sha}","languages_url":"https://api.github.com/repos/tgodzik/beholder/languages","stargazers_url":"https://api.github.com/repos/tgodzik/beholder/stargazers","contributors_url":"https://api.github.com/repos/tgodzik/beholder/contributors","subscribers_url":"https://api.github.com/repos/tgodzik/beholder/subscribers","subscription_url":"https://api.github.com/repos/tgodzik/beholder/subscription","commits_url":"https://api.github.com/repos/tgodzik/beholder/commits{/sha}","git_commits_url":"https://api.github.com/repos/tgodzik/beholder/git/commits{/sha}","comments_url":"https://api.github.com/repos/tgodzik/beholder/comments{/number}","issue_comment_url":"https://api.github.com/repos/tgodzik/beholder/issues/comments{/number}","contents_url":"https://api.github.com/repos/tgodzik/beholder/contents/{+path}","compare_url":"https://api.github.com/repos/tgodzik/beholder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tgodzik/beholder/merges","archive_url":"https://api.github.com/repos/tgodzik/beholder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tgodzik/beholder/downloads","issues_url":"https://api.github.com/repos/tgodzik/beholder/issues{/number}","pulls_url":"https://api.github.com/repos/tgodzik/beholder/pulls{/number}","milestones_url":"https://api.github.com/repos/tgodzik/beholder/milestones{/number}","notifications_url":"https://api.github.com/repos/tgodzik/beholder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tgodzik/beholder/labels{/name}","releases_url":"https://api.github.com/repos/tgodzik/beholder/releases{/id}","deployments_url":"https://api.github.com/repos/tgodzik/beholder/deployments","created_at":"2016-04-19T11:18:46Z","updated_at":"2016-04-19T11:18:47Z","pushed_at":"2016-05-16T08:56:49Z","git_url":"git://github.com/tgodzik/beholder.git","ssh_url":"git@github.com:tgodzik/beholder.git","clone_url":"https://github.com/tgodzik/beholder.git","svn_url":"https://github.com/tgodzik/beholder","homepage":"","size":1072,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"VirtusLab:v1.0.x-slick3.0.x-play2.4.x","ref":"v1.0.x-slick3.0.x-play2.4.x","sha":"8d5a87f87b69e222107606485db0edb74778bb69","user":{"login":"VirtusLab","id":5324131,"avatar_url":"https://avatars.githubusercontent.com/u/5324131?v=3","gravatar_id":"","url":"https://api.github.com/users/VirtusLab","html_url":"https://github.com/VirtusLab","followers_url":"https://api.github.com/users/VirtusLab/followers","following_url":"https://api.github.com/users/VirtusLab/following{/other_user}","gists_url":"https://api.github.com/users/VirtusLab/gists{/gist_id}","starred_url":"https://api.github.com/users/VirtusLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VirtusLab/subscriptions","organizations_url":"https://api.github.com/users/VirtusLab/orgs","repos_url":"https://api.github.com/users/VirtusLab/repos","events_url":"https://api.github.com/users/VirtusLab/events{/privacy}","received_events_url":"https://api.github.com/users/VirtusLab/received_events","type":"Organization","site_admin":false},"repo":{"id":17982765,"name":"beholder","full_name":"VirtusLab/beholder","owner":{"login":"VirtusLab","id":5324131,"avatar_url":"https://avatars.githubusercontent.com/u/5324131?v=3","gravatar_id":"","url":"https://api.github.com/users/VirtusLab","html_url":"https://github.com/VirtusLab","followers_url":"https://api.github.com/users/VirtusLab/followers","following_url":"https://api.github.com/users/VirtusLab/following{/other_user}","gists_url":"https://api.github.com/users/VirtusLab/gists{/gist_id}","starred_url":"https://api.github.com/users/VirtusLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VirtusLab/subscriptions","organizations_url":"https://api.github.com/users/VirtusLab/orgs","repos_url":"https://api.github.com/users/VirtusLab/repos","events_url":"https://api.github.com/users/VirtusLab/events{/privacy}","received_events_url":"https://api.github.com/users/VirtusLab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/VirtusLab/beholder","description":"Small slick lib for create views on on database","fork":false,"url":"https://api.github.com/repos/VirtusLab/beholder","forks_url":"https://api.github.com/repos/VirtusLab/beholder/forks","keys_url":"https://api.github.com/repos/VirtusLab/beholder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/VirtusLab/beholder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/VirtusLab/beholder/teams","hooks_url":"https://api.github.com/repos/VirtusLab/beholder/hooks","issue_events_url":"https://api.github.com/repos/VirtusLab/beholder/issues/events{/number}","events_url":"https://api.github.com/repos/VirtusLab/beholder/events","assignees_url":"https://api.github.com/repos/VirtusLab/beholder/assignees{/user}","branches_url":"https://api.github.com/repos/VirtusLab/beholder/branches{/branch}","tags_url":"https://api.github.com/repos/VirtusLab/beholder/tags","blobs_url":"https://api.github.com/repos/VirtusLab/beholder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/VirtusLab/beholder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/VirtusLab/beholder/git/refs{/sha}","trees_url":"https://api.github.com/repos/VirtusLab/beholder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/VirtusLab/beholder/statuses/{sha}","languages_url":"https://api.github.com/repos/VirtusLab/beholder/languages","stargazers_url":"https://api.github.com/repos/VirtusLab/beholder/stargazers","contributors_url":"https://api.github.com/repos/VirtusLab/beholder/contributors","subscribers_url":"https://api.github.com/repos/VirtusLab/beholder/subscribers","subscription_url":"https://api.github.com/repos/VirtusLab/beholder/subscription","commits_url":"https://api.github.com/repos/VirtusLab/beholder/commits{/sha}","git_commits_url":"https://api.github.com/repos/VirtusLab/beholder/git/commits{/sha}","comments_url":"https://api.github.com/repos/VirtusLab/beholder/comments{/number}","issue_comment_url":"https://api.github.com/repos/VirtusLab/beholder/issues/comments{/number}","contents_url":"https://api.github.com/repos/VirtusLab/beholder/contents/{+path}","compare_url":"https://api.github.com/repos/VirtusLab/beholder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/VirtusLab/beholder/merges","archive_url":"https://api.github.com/repos/VirtusLab/beholder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/VirtusLab/beholder/downloads","issues_url":"https://api.github.com/repos/VirtusLab/beholder/issues{/number}","pulls_url":"https://api.github.com/repos/VirtusLab/beholder/pulls{/number}","milestones_url":"https://api.github.com/repos/VirtusLab/beholder/milestones{/number}","notifications_url":"https://api.github.com/repos/VirtusLab/beholder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/VirtusLab/beholder/labels{/name}","releases_url":"https://api.github.com/repos/VirtusLab/beholder/releases{/id}","deployments_url":"https://api.github.com/repos/VirtusLab/beholder/deployments","created_at":"2014-03-21T14:44:19Z","updated_at":"2016-03-07T18:15:23Z","pushed_at":"2016-05-16T08:56:50Z","git_url":"git://github.com/VirtusLab/beholder.git","ssh_url":"git@github.com:VirtusLab/beholder.git","clone_url":"https://github.com/VirtusLab/beholder.git","svn_url":"https://github.com/VirtusLab/beholder","homepage":"","size":1080,"stargazers_count":14,"watchers_count":14,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":23,"forks":7,"open_issues":23,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/VirtusLab/beholder/pulls/42"},"html":{"href":"https://github.com/VirtusLab/beholder/pull/42"},"issue":{"href":"https://api.github.com/repos/VirtusLab/beholder/issues/42"},"comments":{"href":"https://api.github.com/repos/VirtusLab/beholder/issues/42/comments"},"review_comments":{"href":"https://api.github.com/repos/VirtusLab/beholder/pulls/42/comments"},"review_comment":{"href":"https://api.github.com/repos/VirtusLab/beholder/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/VirtusLab/beholder/pulls/42/commits"},"statuses":{"href":"https://api.github.com/repos/VirtusLab/beholder/statuses/a5349c0908c68dc6406fcf14764863c4dadd5fe3"}}}}