{"action":"created","comment":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/56542568","id":56542568,"diff_hunk":"@@ -5,9 +5,58 @@ class Overlay < ActiveRecord::Base\n     # INFO: disable ActiveRecord inheritance column\n     self.inheritance_column = :_type\n \n-    after_initialize do |overlay|\n-      self.options = ::JSON.parse(self.options)\n+    serialize :options, JSON\n+\n+    validates :visualization_id, presence: true\n+    validates :type, presence: true\n+    validate :unique_overlay_not_duplicated\n+\n+    after_save :invalidate_cache\n+    after_destroy :invalidate_cache\n+\n+    # There can be at most one of this types per visualization\n+    UNIQUE_TYPES = [\n+      'header', 'search', 'layer_selector', 'share', 'zoom', 'logo', 'loader', 'fullscreen'\n+    ].freeze\n+\n+    def hide\n+      options['display'] = false\n+      self\n+    end\n+\n+    def show\n+      options['display'] = true\n+      self\n+    end\n+\n+    def hidden?\n+      !options['display']\n     end\n \n+    private\n+\n+    def visualization","path":"app/models/carto/overlay.rb","position":36,"original_position":36,"commit_id":"7d6f1033ea34f2a096be27f31031a47f761ae817","original_commit_id":"7d6f1033ea34f2a096be27f31031a47f761ae817","user":{"login":"juanignaciosl","id":932968,"avatar_url":"https://avatars.githubusercontent.com/u/932968?v=3","gravatar_id":"","url":"https://api.github.com/users/juanignaciosl","html_url":"https://github.com/juanignaciosl","followers_url":"https://api.github.com/users/juanignaciosl/followers","following_url":"https://api.github.com/users/juanignaciosl/following{/other_user}","gists_url":"https://api.github.com/users/juanignaciosl/gists{/gist_id}","starred_url":"https://api.github.com/users/juanignaciosl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanignaciosl/subscriptions","organizations_url":"https://api.github.com/users/juanignaciosl/orgs","repos_url":"https://api.github.com/users/juanignaciosl/repos","events_url":"https://api.github.com/users/juanignaciosl/events{/privacy}","received_events_url":"https://api.github.com/users/juanignaciosl/received_events","type":"User","site_admin":false},"body":"PS2: `visualization` is expected to be a `Carto::Visualization`. I guess this naming is intentional, but I'm not sure about it. Consider using a different naming so requesting the old model is explicit, and the new naming is coherent. Not sure, anyway. cc @gfiorav ","created_at":"2016-03-17T17:19:41Z","updated_at":"2016-03-17T17:19:41Z","html_url":"https://github.com/CartoDB/cartodb/pull/6868#discussion_r56542568","pull_request_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6868","_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/56542568"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/6868#discussion_r56542568"},"pull_request":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6868"}}},"pull_request":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6868","id":62781746,"html_url":"https://github.com/CartoDB/cartodb/pull/6868","diff_url":"https://github.com/CartoDB/cartodb/pull/6868.diff","patch_url":"https://github.com/CartoDB/cartodb/pull/6868.patch","issue_url":"https://api.github.com/repos/CartoDB/cartodb/issues/6868","number":6868,"state":"open","locked":false,"title":"Refactor Overlay model (move to ActiveRecord)","user":{"login":"javitonino","id":7569673,"avatar_url":"https://avatars.githubusercontent.com/u/7569673?v=3","gravatar_id":"","url":"https://api.github.com/users/javitonino","html_url":"https://github.com/javitonino","followers_url":"https://api.github.com/users/javitonino/followers","following_url":"https://api.github.com/users/javitonino/following{/other_user}","gists_url":"https://api.github.com/users/javitonino/gists{/gist_id}","starred_url":"https://api.github.com/users/javitonino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javitonino/subscriptions","organizations_url":"https://api.github.com/users/javitonino/orgs","repos_url":"https://api.github.com/users/javitonino/repos","events_url":"https://api.github.com/users/javitonino/events{/privacy}","received_events_url":"https://api.github.com/users/javitonino/received_events","type":"User","site_admin":false},"body":"This completely removes the old Overlay model using Virtus (member/collection) and moves to ActiveRecord. Some highlights:\r\n 1. Adds validation to ensure at least `type` and `visualization_id` are filled. The db table allows nulls.\r\n 2. Adds tests to overlay controller (very poorly covered before)\r\n 3. Removes the old model and uninstalls `aequitas` gem(only used in this model)\r\n 4. When creating a new visualization, the overlays are written to the database BEFORE the visualization itself. That makes it impossible (for now) to add FK's. Also, some additional code is added to avoid checking for overlay duplicates if the visualization doesn't exist yet.\r\n\r\nPlease CR, @gfiorav @juanignaciosl \r\n\r\nCloses #6861","created_at":"2016-03-14T17:01:31Z","updated_at":"2016-03-17T17:19:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1c24117578b24ee93a33b56b60850366d5de0f9e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6868/commits","review_comments_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6868/comments","review_comment_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/issues/6868/comments","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/7d6f1033ea34f2a096be27f31031a47f761ae817","head":{"label":"CartoDB:6861-overlay_refactor","ref":"6861-overlay_refactor","sha":"7d6f1033ea34f2a096be27f31031a47f761ae817","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":4909355,"name":"cartodb","full_name":"CartoDB/cartodb","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/cartodb","description":"Location Intelligence & Data Visualization tool","fork":false,"url":"https://api.github.com/repos/CartoDB/cartodb","forks_url":"https://api.github.com/repos/CartoDB/cartodb/forks","keys_url":"https://api.github.com/repos/CartoDB/cartodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/cartodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/cartodb/teams","hooks_url":"https://api.github.com/repos/CartoDB/cartodb/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/cartodb/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/cartodb/events","assignees_url":"https://api.github.com/repos/CartoDB/cartodb/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/cartodb/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/cartodb/tags","blobs_url":"https://api.github.com/repos/CartoDB/cartodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/cartodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/cartodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/cartodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/cartodb/languages","stargazers_url":"https://api.github.com/repos/CartoDB/cartodb/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/cartodb/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/cartodb/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/cartodb/subscription","commits_url":"https://api.github.com/repos/CartoDB/cartodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/cartodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/cartodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/cartodb/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/cartodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/cartodb/merges","archive_url":"https://api.github.com/repos/CartoDB/cartodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/cartodb/downloads","issues_url":"https://api.github.com/repos/CartoDB/cartodb/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/cartodb/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/cartodb/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/cartodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/cartodb/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/cartodb/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/cartodb/deployments","created_at":"2012-07-05T15:23:45Z","updated_at":"2016-03-17T08:45:48Z","pushed_at":"2016-03-17T17:03:56Z","git_url":"git://github.com/CartoDB/cartodb.git","ssh_url":"git@github.com:CartoDB/cartodb.git","clone_url":"https://github.com/CartoDB/cartodb.git","svn_url":"https://github.com/CartoDB/cartodb","homepage":"http://cartodb.com","size":379008,"stargazers_count":1080,"watchers_count":1080,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":270,"mirror_url":null,"open_issues_count":849,"forks":270,"open_issues":849,"watchers":1080,"default_branch":"master"}},"base":{"label":"CartoDB:master","ref":"master","sha":"511c38be3d6f80206a8c00ef38b7dc66f39feaa8","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":4909355,"name":"cartodb","full_name":"CartoDB/cartodb","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/cartodb","description":"Location Intelligence & Data Visualization tool","fork":false,"url":"https://api.github.com/repos/CartoDB/cartodb","forks_url":"https://api.github.com/repos/CartoDB/cartodb/forks","keys_url":"https://api.github.com/repos/CartoDB/cartodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/cartodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/cartodb/teams","hooks_url":"https://api.github.com/repos/CartoDB/cartodb/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/cartodb/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/cartodb/events","assignees_url":"https://api.github.com/repos/CartoDB/cartodb/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/cartodb/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/cartodb/tags","blobs_url":"https://api.github.com/repos/CartoDB/cartodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/cartodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/cartodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/cartodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/cartodb/languages","stargazers_url":"https://api.github.com/repos/CartoDB/cartodb/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/cartodb/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/cartodb/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/cartodb/subscription","commits_url":"https://api.github.com/repos/CartoDB/cartodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/cartodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/cartodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/cartodb/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/cartodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/cartodb/merges","archive_url":"https://api.github.com/repos/CartoDB/cartodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/cartodb/downloads","issues_url":"https://api.github.com/repos/CartoDB/cartodb/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/cartodb/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/cartodb/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/cartodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/cartodb/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/cartodb/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/cartodb/deployments","created_at":"2012-07-05T15:23:45Z","updated_at":"2016-03-17T08:45:48Z","pushed_at":"2016-03-17T17:03:56Z","git_url":"git://github.com/CartoDB/cartodb.git","ssh_url":"git@github.com:CartoDB/cartodb.git","clone_url":"https://github.com/CartoDB/cartodb.git","svn_url":"https://github.com/CartoDB/cartodb","homepage":"http://cartodb.com","size":379008,"stargazers_count":1080,"watchers_count":1080,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":270,"mirror_url":null,"open_issues_count":849,"forks":270,"open_issues":849,"watchers":1080,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6868"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/6868"},"issue":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/6868"},"comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/6868/comments"},"review_comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6868/comments"},"review_comment":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6868/commits"},"statuses":{"href":"https://api.github.com/repos/CartoDB/cartodb/statuses/7d6f1033ea34f2a096be27f31031a47f761ae817"}}}}