diff --git a/Gemfile.lock b/Gemfile.lock index f2800771f616070b2646b2d0368e49462a86f3bb..ffbef9488e439b531178a2889f9cda728a3c07b8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,17 @@ +GIT + remote: https://github.com/ctran/annotate_models.git + revision: be4e26825b521f0b2d86b181e2dff89901aa9b1e + specs: + annotate (2.6.0.beta1) + activerecord (>= 2.3.0) + rake (>= 0.8.7) + +GIT + remote: https://github.com/gitlabhq/raphael-rails.git + revision: cb2c92a040b9b941a5f1aa1ea866cc26e944fe58 + specs: + raphael-rails (2.1.0) + GIT remote: https://github.com/gollum/gollum.git revision: 5dcd3c8c8f68158e43ff79861279088ee56d0ebe @@ -15,20 +29,6 @@ GIT stringex (~> 1.5.1) useragent (~> 0.4.16) -GIT - remote: https://github.com/ctran/annotate_models.git - revision: be4e26825b521f0b2d86b181e2dff89901aa9b1e - specs: - annotate (2.6.0.beta1) - activerecord (>= 2.3.0) - rake (>= 0.8.7) - -GIT - remote: https://github.com/gitlabhq/raphael-rails.git - revision: cb2c92a040b9b941a5f1aa1ea866cc26e944fe58 - specs: - raphael-rails (2.1.0) - GEM remote: https://rubygems.org/ specs: diff --git a/app/models/event.rb b/app/models/event.rb index ae14454c59a34ad0603cc5f73c2cdc4018733d0f..d39445c4ffe8ef443c7c75027f5587bcb3f6c36b 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -259,6 +259,10 @@ class Event < ActiveRecord::Base target.noteable_type == "Commit" end + def note_project_snippet? + target.noteable_type == "Snippet" + end + def note_target target.noteable end diff --git a/app/models/note.rb b/app/models/note.rb index f56f999fda1518f152f3ce416706dd6790a71d21..2f3b059918afed6805d0380dece52d55dbc0765c 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -170,4 +170,10 @@ class Note < ActiveRecord::Base "wall" end end + + # FIXME: Hack for polymorphic associations with STI + # For more information wisit http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#label-Polymorphic+Associations + def noteable_type=(sType) + super(sType.to_s.classify.constantize.base_class.to_s) + end end diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 5d09c6b6e47dcc80ae36b67cba2682a4dc05422f..1b37ffe83392c8dcb004e8132ec1d4246fde39a3 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -20,6 +20,7 @@ class Snippet < ActiveRecord::Base attr_accessible :title, :content, :file_name, :expires_at, :private belongs_to :author, class_name: "User" + has_many :notes, as: :noteable, dependent: :destroy delegate :name, :email, to: :author, prefix: true, allow_nil: true diff --git a/app/views/events/event/_note.html.haml b/app/views/events/event/_note.html.haml index 8bcfa95ff62a7db737d7aa221443e72b1a52f6b0..81b8ff9bf24536c51cdc5fc88f6c0898b6e9040c 100644 --- a/app/views/events/event/_note.html.haml +++ b/app/views/events/event/_note.html.haml @@ -5,6 +5,10 @@ - if event.note_commit? = event.note_target_type = link_to event.note_short_commit_id, project_commit_path(event.project, event.note_commit_id), class: "commit_short_id" + - if event.note_project_snippet? + = link_to project_snippet_path(event.project, event.note_target) do + %strong + #{event.note_target_type} ##{truncate event.note_target_id} - else = link_to [event.project, event.note_target] do %strong