{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/policy-publisher/pulls/comments/28405499","id":28405499,"diff_hunk":"@@ -0,0 +1,108 @@\n+class Policy < ActiveRecord::Base\n+  validates :content_id, presence: true, uniqueness: true\n+  validates :name, :slug, presence: true, uniqueness: true\n+  validates :description, presence: true\n+\n+  validate :applicable_to_at_least_one_nation\n+  validate :alternative_urls_are_valid\n+\n+  has_many :policy_relations\n+  has_many :related_policies, class_name: 'Policy', through: :policy_relations, source: :related_policy\n+\n+  has_many :inverse_policy_relations, class_name: 'PolicyRelation', foreign_key: 'related_policy_id'\n+  has_many :parent_policies,  through: :inverse_policy_relations, source: :policy\n+\n+  before_validation on: :create do |object|\n+    object.slug = object.name.to_s.parameterize\n+    object.content_id = SecureRandom.uuid\n+  end\n+\n+  scope :areas, -> { joins(\"LEFT OUTER JOIN policy_relations\n+                            ON policies.id = policy_relations.related_policy_id\n+                            WHERE policy_relations.related_policy_id IS NULL\") }\n+\n+  after_save :publish!\n+  after_save :republish_parents!\n+\n+  # Virtual attribute used to identify a new record as a programme\n+  attr_writer :programme\n+\n+  def publish!\n+    publish_content_item!\n+    add_to_search_index!\n+  end\n+\n+  def republish!\n+    publish_content_item!('minor')","path":"app/models/policy.rb","position":36,"original_position":36,"commit_id":"eeed6f1b009e0446ca8e7364eb0678e38927e682","original_commit_id":"1890eef0e4f4fc2eac69b0e8ab0c94fdbca9c108","user":{"login":"elliotcm","id":109225,"avatar_url":"https://avatars.githubusercontent.com/u/109225?v=3","gravatar_id":"","url":"https://api.github.com/users/elliotcm","html_url":"https://github.com/elliotcm","followers_url":"https://api.github.com/users/elliotcm/followers","following_url":"https://api.github.com/users/elliotcm/following{/other_user}","gists_url":"https://api.github.com/users/elliotcm/gists{/gist_id}","starred_url":"https://api.github.com/users/elliotcm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elliotcm/subscriptions","organizations_url":"https://api.github.com/users/elliotcm/orgs","repos_url":"https://api.github.com/users/elliotcm/repos","events_url":"https://api.github.com/users/elliotcm/events{/privacy}","received_events_url":"https://api.github.com/users/elliotcm/received_events","type":"User","site_admin":false},"body":"Fair.  Let's do it separately.","created_at":"2015-04-15T09:33:50Z","updated_at":"2015-04-15T09:33:50Z","html_url":"https://github.com/alphagov/policy-publisher/pull/40#discussion_r28405499","pull_request_url":"https://api.github.com/repos/alphagov/policy-publisher/pulls/40","_links":{"self":{"href":"https://api.github.com/repos/alphagov/policy-publisher/pulls/comments/28405499"},"html":{"href":"https://github.com/alphagov/policy-publisher/pull/40#discussion_r28405499"},"pull_request":{"href":"https://api.github.com/repos/alphagov/policy-publisher/pulls/40"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/policy-publisher/pulls/40","id":33277618,"html_url":"https://github.com/alphagov/policy-publisher/pull/40","diff_url":"https://github.com/alphagov/policy-publisher/pull/40.diff","patch_url":"https://github.com/alphagov/policy-publisher/pull/40.patch","issue_url":"https://api.github.com/repos/alphagov/policy-publisher/issues/40","number":40,"state":"open","locked":false,"title":"Simplify policy modelling","user":{"login":"tekin","id":3687,"avatar_url":"https://avatars.githubusercontent.com/u/3687?v=3","gravatar_id":"","url":"https://api.github.com/users/tekin","html_url":"https://github.com/tekin","followers_url":"https://api.github.com/users/tekin/followers","following_url":"https://api.github.com/users/tekin/following{/other_user}","gists_url":"https://api.github.com/users/tekin/gists{/gist_id}","starred_url":"https://api.github.com/users/tekin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tekin/subscriptions","organizations_url":"https://api.github.com/users/tekin/orgs","repos_url":"https://api.github.com/users/tekin/repos","events_url":"https://api.github.com/users/tekin/events{/privacy}","received_events_url":"https://api.github.com/users/tekin/received_events","type":"User","site_admin":false},"body":"This merges the two separate `PolicyArea` and `Programme` models into a single `Policy` model. \r\n\r\nThe main rational for this was that the two models essentially had identical behaviour, save for the distinction that programmes can be identified as being \"part of\" a policy area. This resulted in a lot of duplication and forced us to use `ActiveSupport::Concerns` to mix in the shared behaviour for the two models. It also introduced issues around verifying uniqueness (the validations were per-model, which meant that it was technically possible to create both a `PolicyArea` and a `Programme` with the same name and slug.\r\n\r\nThe UI has been simplified a bit - there is now only a single index that lists all the policies. This makes it easier to find the policy of interest using the filter, rather than having to click through to the appropriate list first.\r\n\r\n![screen shot 2015-04-15 at 10 12 23](https://cloud.githubusercontent.com/assets/3687/7155614/0358f62c-e358-11e4-95d3-65d9e435fd69.png)\r\n\r\n![screen shot 2015-04-15 at 10 12 32](https://cloud.githubusercontent.com/assets/3687/7155624/15f7d0a0-e358-11e4-8a60-b4b4bfc2e3bd.png)\r\n\r\n![screen shot 2015-04-15 at 10 12 40](https://cloud.githubusercontent.com/assets/3687/7155627/18d7af3e-e358-11e4-9a7d-8ae821d7954d.png)\r\n\r\n* [x] Product owner acceptance\r\n* [ ] Code review acceptance\r\n\r\nTrello: https://trello.com/c/7MGf90AG/172-merge-policy-areas-and-programmes-in-policy-publisher","created_at":"2015-04-14T16:57:27Z","updated_at":"2015-04-15T09:33:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6accdddf349585e10e084d23388c696d21416bf5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/policy-publisher/pulls/40/commits","review_comments_url":"https://api.github.com/repos/alphagov/policy-publisher/pulls/40/comments","review_comment_url":"https://api.github.com/repos/alphagov/policy-publisher/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/policy-publisher/issues/40/comments","statuses_url":"https://api.github.com/repos/alphagov/policy-publisher/statuses/eeed6f1b009e0446ca8e7364eb0678e38927e682","head":{"label":"alphagov:modelling-simplification","ref":"modelling-simplification","sha":"eeed6f1b009e0446ca8e7364eb0678e38927e682","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":30296685,"name":"policy-publisher","full_name":"alphagov/policy-publisher","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/policy-publisher","description":"Create and manage policies and policy programmes","fork":false,"url":"https://api.github.com/repos/alphagov/policy-publisher","forks_url":"https://api.github.com/repos/alphagov/policy-publisher/forks","keys_url":"https://api.github.com/repos/alphagov/policy-publisher/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/policy-publisher/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/policy-publisher/teams","hooks_url":"https://api.github.com/repos/alphagov/policy-publisher/hooks","issue_events_url":"https://api.github.com/repos/alphagov/policy-publisher/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/policy-publisher/events","assignees_url":"https://api.github.com/repos/alphagov/policy-publisher/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/policy-publisher/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/policy-publisher/tags","blobs_url":"https://api.github.com/repos/alphagov/policy-publisher/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/policy-publisher/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/policy-publisher/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/policy-publisher/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/policy-publisher/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/policy-publisher/languages","stargazers_url":"https://api.github.com/repos/alphagov/policy-publisher/stargazers","contributors_url":"https://api.github.com/repos/alphagov/policy-publisher/contributors","subscribers_url":"https://api.github.com/repos/alphagov/policy-publisher/subscribers","subscription_url":"https://api.github.com/repos/alphagov/policy-publisher/subscription","commits_url":"https://api.github.com/repos/alphagov/policy-publisher/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/policy-publisher/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/policy-publisher/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/policy-publisher/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/policy-publisher/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/policy-publisher/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/policy-publisher/merges","archive_url":"https://api.github.com/repos/alphagov/policy-publisher/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/policy-publisher/downloads","issues_url":"https://api.github.com/repos/alphagov/policy-publisher/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/policy-publisher/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/policy-publisher/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/policy-publisher/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/policy-publisher/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/policy-publisher/releases{/id}","created_at":"2015-02-04T11:57:35Z","updated_at":"2015-04-13T08:58:00Z","pushed_at":"2015-04-15T09:33:49Z","git_url":"git://github.com/alphagov/policy-publisher.git","ssh_url":"git@github.com:alphagov/policy-publisher.git","clone_url":"https://github.com/alphagov/policy-publisher.git","svn_url":"https://github.com/alphagov/policy-publisher","homepage":"","size":1380,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"86833e7960dad3225c72b6b421cc23cf1adb76e0","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":30296685,"name":"policy-publisher","full_name":"alphagov/policy-publisher","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/policy-publisher","description":"Create and manage policies and policy programmes","fork":false,"url":"https://api.github.com/repos/alphagov/policy-publisher","forks_url":"https://api.github.com/repos/alphagov/policy-publisher/forks","keys_url":"https://api.github.com/repos/alphagov/policy-publisher/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/policy-publisher/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/policy-publisher/teams","hooks_url":"https://api.github.com/repos/alphagov/policy-publisher/hooks","issue_events_url":"https://api.github.com/repos/alphagov/policy-publisher/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/policy-publisher/events","assignees_url":"https://api.github.com/repos/alphagov/policy-publisher/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/policy-publisher/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/policy-publisher/tags","blobs_url":"https://api.github.com/repos/alphagov/policy-publisher/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/policy-publisher/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/policy-publisher/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/policy-publisher/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/policy-publisher/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/policy-publisher/languages","stargazers_url":"https://api.github.com/repos/alphagov/policy-publisher/stargazers","contributors_url":"https://api.github.com/repos/alphagov/policy-publisher/contributors","subscribers_url":"https://api.github.com/repos/alphagov/policy-publisher/subscribers","subscription_url":"https://api.github.com/repos/alphagov/policy-publisher/subscription","commits_url":"https://api.github.com/repos/alphagov/policy-publisher/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/policy-publisher/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/policy-publisher/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/policy-publisher/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/policy-publisher/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/policy-publisher/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/policy-publisher/merges","archive_url":"https://api.github.com/repos/alphagov/policy-publisher/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/policy-publisher/downloads","issues_url":"https://api.github.com/repos/alphagov/policy-publisher/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/policy-publisher/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/policy-publisher/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/policy-publisher/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/policy-publisher/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/policy-publisher/releases{/id}","created_at":"2015-02-04T11:57:35Z","updated_at":"2015-04-13T08:58:00Z","pushed_at":"2015-04-15T09:33:49Z","git_url":"git://github.com/alphagov/policy-publisher.git","ssh_url":"git@github.com:alphagov/policy-publisher.git","clone_url":"https://github.com/alphagov/policy-publisher.git","svn_url":"https://github.com/alphagov/policy-publisher","homepage":"","size":1380,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/policy-publisher/pulls/40"},"html":{"href":"https://github.com/alphagov/policy-publisher/pull/40"},"issue":{"href":"https://api.github.com/repos/alphagov/policy-publisher/issues/40"},"comments":{"href":"https://api.github.com/repos/alphagov/policy-publisher/issues/40/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/policy-publisher/pulls/40/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/policy-publisher/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/policy-publisher/pulls/40/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/policy-publisher/statuses/eeed6f1b009e0446ca8e7364eb0678e38927e682"}}}}