summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Mathiesen <marius@shortcut.no>2009-12-15 12:39:23 +0100
committerMarius Mathiesen <marius@shortcut.no>2009-12-15 12:39:41 +0100
commit3c070cd9ee7a61ab8869c76d4673eb18281ec96f (patch)
treeadb127b1b6b723a32d53d2cc387a35d486e94d9c
parentb922abbbf5acec147bfd1fde78ac041e5c6deaa6 (diff)
downloadgitorious-mainline-outdated-3c070cd9ee7a61ab8869c76d4673eb18281ec96f.zip
gitorious-mainline-outdated-3c070cd9ee7a61ab8869c76d4673eb18281ec96f.tar.gz
gitorious-mainline-outdated-3c070cd9ee7a61ab8869c76d4673eb18281ec96f.tar.bz2
Make it possible to start watching a merge request when submitting a comment on it.
Currently only for non-inline comments, this is up next
-rw-r--r--app/controllers/comments_controller.rb5
-rw-r--r--app/views/comments/_form.html.erb12
-rw-r--r--test/functional/comments_controller_test.rb31
3 files changed, 48 insertions, 0 deletions
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
index 9130c70..f7eb88d 100644
--- a/app/controllers/comments_controller.rb
+++ b/app/controllers/comments_controller.rb
@@ -80,6 +80,7 @@ class CommentsController < ApplicationController
def comment_was_created
create_new_commented_posted_event
+ add_to_favorites if params[:add_to_favorites]
respond_to do |wants|
wants.html do
flash[:success] = I18n.t "comments_controller.create_success"
@@ -113,6 +114,10 @@ class CommentsController < ApplicationController
end
end
+ def add_to_favorites
+ current_user.favorites.create!(:watchable => @target)
+ end
+
def comment_was_invalid
respond_to { |wants|
wants.html { render :action => "new" }
diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb
index 911639c..b8ab8a0 100644
--- a/app/views/comments/_form.html.erb
+++ b/app/views/comments/_form.html.erb
@@ -52,6 +52,18 @@
<%= f.select :state, statuses_for_merge_request_for_select(parent),
:selected => parent.status_tag.to_s, :include_blank => true -%>
</p>
+
+ <p>
+ <%- if !parent.watched_by?(current_user) -%>
+ <%= label_tag(:add_to_favorites, "Add to favorites") %>:
+ <%= check_box_tag(:add_to_favorites, "on") %> <br />
+ <span class="hint">
+ If you later on want to stop watching this <%= parent.class.human_name -%>,
+ simply click the button on the merge request labelled
+ &quot;Stop watching&quot; at the top of the page
+ </span>
+ <%- end -%>
+ </p>
<%- end -%>
<p>
<input type="button" value="Preview" id="comment_preview_button" />
diff --git a/test/functional/comments_controller_test.rb b/test/functional/comments_controller_test.rb
index fe9bd85..3de4be4 100644
--- a/test/functional/comments_controller_test.rb
+++ b/test/functional/comments_controller_test.rb
@@ -150,6 +150,37 @@ class CommentsControllerTest < ActionController::TestCase
end
end
+ context "Watching a merge request" do
+ setup do
+ @repo = @merge_request.target_repository
+ @project = @repo.project
+ end
+
+ should "be watched when user wants it" do
+ login_as :moe
+# @controller.expects(:add_to_favorites)
+ assert_incremented_by(users(:moe).favorites, :size, 1) do
+ post(:create, :project_id => @project.to_param,
+ :repository_id => @repo.to_param,
+ :comment => {
+ :body => "This feature is highly anticipated!"
+ },
+ :add_to_favorites => "1")
+ users(:moe).favorites.reload
+ end
+ end
+
+ should "only be watched if so wanted" do
+ login_as :moe
+ @controller.expects(:add_to_favorites).never
+ post(:create, :project_id => @project.to_param,
+ :repository_id => @repo.to_param,
+ :comment => {
+ :body => "This feature is highly anticipated!"
+ })
+ end
+ end
+
context "Merge request versions" do
should "set the merge request version as polymorphic parent" do
@version = create_new_version