{"action":"created","comment":{"url":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/comments/174375568","pull_request_review_id":103717350,"id":174375568,"diff_hunk":"@@ -73,9 +79,9 @@\n     ba2 = create(:poll_booth_assignment, poll: poll2, booth: booth2)\n     ba3 = create(:poll_booth_assignment, poll: poll2, booth: booth2)\n \n-    create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: Date.today)\n-    create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.today)\n-    create(:poll_officer_assignment, officer: officer, booth_assignment: ba3, date: Date.today)\n+    create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: '2018-01-01')\n+    create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: '2018-01-01')\n+    create(:poll_officer_assignment, officer: officer, booth_assignment: ba3, date: '2018-01-01')","path":"spec/features/officing/booth_spec.rb","position":null,"original_position":51,"commit_id":"4863da8e18b43affbd20a26017bf6f04bb39a88d","original_commit_id":"216295a1ce303b408d3fa30c50d806ae42b9b034","user":{"login":"iagirre","id":31625251,"avatar_url":"https://avatars3.githubusercontent.com/u/31625251?v=4","gravatar_id":"","url":"https://api.github.com/users/iagirre","html_url":"https://github.com/iagirre","followers_url":"https://api.github.com/users/iagirre/followers","following_url":"https://api.github.com/users/iagirre/following{/other_user}","gists_url":"https://api.github.com/users/iagirre/gists{/gist_id}","starred_url":"https://api.github.com/users/iagirre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iagirre/subscriptions","organizations_url":"https://api.github.com/users/iagirre/orgs","repos_url":"https://api.github.com/users/iagirre/repos","events_url":"https://api.github.com/users/iagirre/events{/privacy}","received_events_url":"https://api.github.com/users/iagirre/received_events","type":"User","site_admin":false},"body":"Yes, I didn't realised before. I've changed it.","created_at":"2018-03-14T07:56:13Z","updated_at":"2018-03-14T07:56:14Z","html_url":"https://github.com/AyuntamientoMadrid/consul/pull/1343#discussion_r174375568","pull_request_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/1343","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/comments/174375568"},"html":{"href":"https://github.com/AyuntamientoMadrid/consul/pull/1343#discussion_r174375568"},"pull_request":{"href":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/1343"}},"in_reply_to_id":174190433},"pull_request":{"url":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/1343","id":173715341,"html_url":"https://github.com/AyuntamientoMadrid/consul/pull/1343","diff_url":"https://github.com/AyuntamientoMadrid/consul/pull/1343.diff","patch_url":"https://github.com/AyuntamientoMadrid/consul/pull/1343.patch","issue_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/issues/1343","number":1343,"state":"open","locked":false,"title":"Flaky spec: booth_spec.rb","user":{"login":"iagirre","id":31625251,"avatar_url":"https://avatars3.githubusercontent.com/u/31625251?v=4","gravatar_id":"","url":"https://api.github.com/users/iagirre","html_url":"https://github.com/iagirre","followers_url":"https://api.github.com/users/iagirre/followers","following_url":"https://api.github.com/users/iagirre/following{/other_user}","gists_url":"https://api.github.com/users/iagirre/gists{/gist_id}","starred_url":"https://api.github.com/users/iagirre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iagirre/subscriptions","organizations_url":"https://api.github.com/users/iagirre/orgs","repos_url":"https://api.github.com/users/iagirre/repos","events_url":"https://api.github.com/users/iagirre/events{/privacy}","received_events_url":"https://api.github.com/users/iagirre/received_events","type":"User","site_admin":false},"body":"References\r\n==========\r\n* **Related Issues:** #1202, #1203 and #1204\r\n\r\nObjectives\r\n==========\r\nFix the flaky that appeared in `spec/features/officing/booth_spec.rb:53`, `spec/features/officing/booth_spec.rb:82` and `spec/features/officing/booth_spec.rb:33`.\r\n\r\n### Explain why the test is flaky, or under which conditions/scenario it fails randomly\r\n\r\n**(This explanation is the same as in #1342 PR because the problem is exactly the same).**\r\n\r\nThe problems was that the tests were not reaching to the residence verification page, so they failed in their assertions. To figure out what was going on there, I studied the flow the test follows so that I could find the scenarios where it would crash, and, after doing it, step by step, I determined that the test will fail when:\r\n\r\n- There are more than 1 `officer_assignments` (booths) for this user, so the page will redirect to the select booth page.\r\n- There aren't any `officer_assignments`, so that the user can't even reach the target page (it redirects to the root).\r\n\r\nThe code that determines that is:\r\n```\r\n# app/controller/officing/base_controller.rb\r\n\t[...]\r\n\r\n\tdef load_officer_assignment\r\n      @officer_assignments ||= current_user.poll_officer.officer_assignments.where(date: Time.current.to_date)\r\n    end\r\n\r\n    def verify_officer_assignment\r\n      if @officer_assignments.blank?\r\n        redirect_to officing_root_path, notice: t(\"officing.residence.flash.not_allowed\")\r\n      end\r\n    end\r\n\r\n    def verify_booth\r\n      return unless current_booth.blank?\r\n      booths = todays_booths_for_officer(current_user.poll_officer)\r\n      case booths.count\r\n      when 0\r\n        redirect_to officing_root_path\r\n      when 1\r\n        session[:booth_id] = booths.first.id\r\n      else\r\n        redirect_to new_officing_booth_path\r\n      end\r\n    end\r\n\r\n    [...]\r\n\r\n    def todays_booths_for_officer(officer)\r\n      officer.officer_assignments.by_date(Date.today).map(&:booth).uniq\r\n    end\r\n```\r\n\r\nAfter trying to reproduce it (without success), I saw the new piece of information about the probable failing hours, and I realized that the problem could be in the moment of creating the objects. If the `officer_assignment` are created at 23:59:59 and the rest of the test is executed after 00:00:00, the dates for the objects and the `Date.current` (used to check if there are any shifts today) won't be the same, because the shift will be for, lets say, 07/03/2018 and Date.current will be 08/03/2018.\r\n\r\nTo prove that, I forced in the factory the dates of the `officer_assignments` to an earlier date, and it failed in the exact same way as the reported ones.\r\n\r\n\r\n### Explain why your PR fixes it\r\n\r\nI stubed the Date and Time clases to force them to give me a date I can controll. I set that date (01/01/2018) to the objects that depend on it (`poll_shift`, `officer_assignment` and `polls`). This way, it doesn't matter when the test is executed, for it will always be the same date.\r\n\r\nVisual Changes (if any)\r\n=======================\r\nThere aren't, is a flaky.\r\n\r\nNotes\r\n=====================\r\n- I added stubs for `Date.current`, `Date.today` and `Time.current` (this are all the functions used to check the shifts and officer assignments) so that they all return a predefined date: 01/01/2018.\r\n- I stubed them in a before block, so that it works for all the test.\r\n- I set that date to the objects that depend on it (`officer_assignment`).\r\n","created_at":"2018-03-08T11:46:57Z","updated_at":"2018-03-14T07:56:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a17ace1d9a96f1f8c48a9f7a156b76e4a6623927","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/1343/commits","review_comments_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/1343/comments","review_comment_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/comments{/number}","comments_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/issues/1343/comments","statuses_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/statuses/4863da8e18b43affbd20a26017bf6f04bb39a88d","head":{"label":"wairbut-m2c-aytomadrid:1202-flaky-booth-officer-with-multiple-booth-assignments-today","ref":"1202-flaky-booth-officer-with-multiple-booth-assignments-today","sha":"4863da8e18b43affbd20a26017bf6f04bb39a88d","user":{"login":"wairbut-m2c-aytomadrid","id":36006872,"avatar_url":"https://avatars3.githubusercontent.com/u/36006872?v=4","gravatar_id":"","url":"https://api.github.com/users/wairbut-m2c-aytomadrid","html_url":"https://github.com/wairbut-m2c-aytomadrid","followers_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/followers","following_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/following{/other_user}","gists_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/gists{/gist_id}","starred_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/subscriptions","organizations_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/orgs","repos_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/repos","events_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/events{/privacy}","received_events_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/received_events","type":"Organization","site_admin":false},"repo":{"id":119714863,"name":"consul","full_name":"wairbut-m2c-aytomadrid/consul","owner":{"login":"wairbut-m2c-aytomadrid","id":36006872,"avatar_url":"https://avatars3.githubusercontent.com/u/36006872?v=4","gravatar_id":"","url":"https://api.github.com/users/wairbut-m2c-aytomadrid","html_url":"https://github.com/wairbut-m2c-aytomadrid","followers_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/followers","following_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/following{/other_user}","gists_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/gists{/gist_id}","starred_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/subscriptions","organizations_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/orgs","repos_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/repos","events_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/events{/privacy}","received_events_url":"https://api.github.com/users/wairbut-m2c-aytomadrid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wairbut-m2c-aytomadrid/consul","description":"Consul - Gobierno abierto del Ayuntamiento de Madrid","fork":true,"url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul","forks_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/forks","keys_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/teams","hooks_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/hooks","issue_events_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/issues/events{/number}","events_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/events","assignees_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/assignees{/user}","branches_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/branches{/branch}","tags_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/tags","blobs_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/git/refs{/sha}","trees_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/statuses/{sha}","languages_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/languages","stargazers_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/stargazers","contributors_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/contributors","subscribers_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/subscribers","subscription_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/subscription","commits_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/commits{/sha}","git_commits_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/git/commits{/sha}","comments_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/comments{/number}","issue_comment_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/issues/comments{/number}","contents_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/contents/{+path}","compare_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/merges","archive_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/downloads","issues_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/issues{/number}","pulls_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/pulls{/number}","milestones_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/milestones{/number}","notifications_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/labels{/name}","releases_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/releases{/id}","deployments_url":"https://api.github.com/repos/wairbut-m2c-aytomadrid/consul/deployments","created_at":"2018-01-31T16:44:30Z","updated_at":"2018-03-13T20:19:32Z","pushed_at":"2018-03-14T07:54:14Z","git_url":"git://github.com/wairbut-m2c-aytomadrid/consul.git","ssh_url":"git@github.com:wairbut-m2c-aytomadrid/consul.git","clone_url":"https://github.com/wairbut-m2c-aytomadrid/consul.git","svn_url":"https://github.com/wairbut-m2c-aytomadrid/consul","homepage":"https://decide.madrid.es/","size":1905515,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"AyuntamientoMadrid:master","ref":"master","sha":"041addb9d02474b26b837eeac398e9b690eaf815","user":{"login":"AyuntamientoMadrid","id":13286342,"avatar_url":"https://avatars3.githubusercontent.com/u/13286342?v=4","gravatar_id":"","url":"https://api.github.com/users/AyuntamientoMadrid","html_url":"https://github.com/AyuntamientoMadrid","followers_url":"https://api.github.com/users/AyuntamientoMadrid/followers","following_url":"https://api.github.com/users/AyuntamientoMadrid/following{/other_user}","gists_url":"https://api.github.com/users/AyuntamientoMadrid/gists{/gist_id}","starred_url":"https://api.github.com/users/AyuntamientoMadrid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AyuntamientoMadrid/subscriptions","organizations_url":"https://api.github.com/users/AyuntamientoMadrid/orgs","repos_url":"https://api.github.com/users/AyuntamientoMadrid/repos","events_url":"https://api.github.com/users/AyuntamientoMadrid/events{/privacy}","received_events_url":"https://api.github.com/users/AyuntamientoMadrid/received_events","type":"Organization","site_admin":false},"repo":{"id":46575779,"name":"consul","full_name":"AyuntamientoMadrid/consul","owner":{"login":"AyuntamientoMadrid","id":13286342,"avatar_url":"https://avatars3.githubusercontent.com/u/13286342?v=4","gravatar_id":"","url":"https://api.github.com/users/AyuntamientoMadrid","html_url":"https://github.com/AyuntamientoMadrid","followers_url":"https://api.github.com/users/AyuntamientoMadrid/followers","following_url":"https://api.github.com/users/AyuntamientoMadrid/following{/other_user}","gists_url":"https://api.github.com/users/AyuntamientoMadrid/gists{/gist_id}","starred_url":"https://api.github.com/users/AyuntamientoMadrid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AyuntamientoMadrid/subscriptions","organizations_url":"https://api.github.com/users/AyuntamientoMadrid/orgs","repos_url":"https://api.github.com/users/AyuntamientoMadrid/repos","events_url":"https://api.github.com/users/AyuntamientoMadrid/events{/privacy}","received_events_url":"https://api.github.com/users/AyuntamientoMadrid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/AyuntamientoMadrid/consul","description":"Consul - Gobierno abierto del Ayuntamiento de Madrid","fork":true,"url":"https://api.github.com/repos/AyuntamientoMadrid/consul","forks_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/forks","keys_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/teams","hooks_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/hooks","issue_events_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/issues/events{/number}","events_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/events","assignees_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/assignees{/user}","branches_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/branches{/branch}","tags_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/tags","blobs_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/git/refs{/sha}","trees_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/statuses/{sha}","languages_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/languages","stargazers_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/stargazers","contributors_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/contributors","subscribers_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/subscribers","subscription_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/subscription","commits_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/commits{/sha}","git_commits_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/git/commits{/sha}","comments_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/comments{/number}","issue_comment_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/issues/comments{/number}","contents_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/contents/{+path}","compare_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/merges","archive_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/downloads","issues_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/issues{/number}","pulls_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls{/number}","milestones_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/milestones{/number}","notifications_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/labels{/name}","releases_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/releases{/id}","deployments_url":"https://api.github.com/repos/AyuntamientoMadrid/consul/deployments","created_at":"2015-11-20T17:10:12Z","updated_at":"2018-03-13T19:22:35Z","pushed_at":"2018-03-14T07:54:15Z","git_url":"git://github.com/AyuntamientoMadrid/consul.git","ssh_url":"git@github.com:AyuntamientoMadrid/consul.git","clone_url":"https://github.com/AyuntamientoMadrid/consul.git","svn_url":"https://github.com/AyuntamientoMadrid/consul","homepage":"https://decide.madrid.es/","size":1905471,"stargazers_count":43,"watchers_count":43,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"archived":false,"open_issues_count":92,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":15,"open_issues":92,"watchers":43,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/1343"},"html":{"href":"https://github.com/AyuntamientoMadrid/consul/pull/1343"},"issue":{"href":"https://api.github.com/repos/AyuntamientoMadrid/consul/issues/1343"},"comments":{"href":"https://api.github.com/repos/AyuntamientoMadrid/consul/issues/1343/comments"},"review_comments":{"href":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/1343/comments"},"review_comment":{"href":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/AyuntamientoMadrid/consul/pulls/1343/commits"},"statuses":{"href":"https://api.github.com/repos/AyuntamientoMadrid/consul/statuses/4863da8e18b43affbd20a26017bf6f04bb39a88d"}},"author_association":"NONE"}}
{"actor":{"display_login":"iagirre"}}