<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>features/step_definitions/general_steps.rb</filename>
    </added>
    <added>
      <filename>public/images/misc/recreate.gif</filename>
    </added>
    <added>
      <filename>spec/controllers/comments_controller_spec.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -2,6 +2,8 @@ class CommentsController &lt; ApplicationController
   cache_sweeper :code_and_comment_sweeper
   skip_before_filter :verify_authenticity_token 
   
+  #&#160;index expects to be called in the context of a Code
+  # so a code_id is passed in
   def index
     @code = Code.find_by_slug_name! params[:code_id]
     respond_to do |wants|
@@ -15,15 +17,21 @@ class CommentsController &lt; ApplicationController
     end
   end
   
+  # create expects to be called in the context of a Code
+  # so a code_id is passed in
   def create
     @code = Code.find params[:code_id]
     @comment = @code.build_comment params[:comment]
+
+    # validate the comment, then test the captcha to ensure all errors are shown on the form    
     @comment.valid?
-    raise ActiveRecord::RecordInvalid.new(@comment) unless validate_recap(params, @comment.errors, :rcc_pub =&gt; RECAPTCHA_PUBLIC_KEY, :rcc_priv =&gt; RECAPTCHA_PRIVATE_KEY)
+    raise ActiveRecord::RecordInvalid.new(@comment) unless captcha_is_valid_for @comment, :with =&gt; params
     @comment.save!    
+    
     cookies[:comment_name] = @comment.name
     cookies[:comment_email] = @comment.email
     cookies[:comment_url] = @comment.url
+    my_comments &lt;&lt; @comment.id
     flash[:notice] = 'Thanks for your comment'
     redirect_to code_by_slug_path(@code.slug_name)
     
@@ -31,4 +39,31 @@ class CommentsController &lt; ApplicationController
     render :template =&gt; 'codes/show'
     flash[:error] = 'Sorry, unable to save your comment'
   end
+  
+  # destroy expects to be called with just an id, no code_id necessary
+  def destroy
+    @comment = Comment.find params[:id]
+    if can_delete @comment
+      @comment.destroy
+      flash[:notice] = 'Your comment has been deleted'
+    else
+      flash[:error] = 'You are not allowed to delete that comment'
+    end
+    redirect_to code_by_slug_path(@comment.code_slug_name)
+  end
+
+  def can_delete comment
+    my_comments.include? comment.id
+  end
+
+private
+  def my_comments
+    session[:my_comments] ||= []
+  end
+
+  def captcha_is_valid_for comment, options 
+    return true if ENV['RAILS_ENV'] == 'test' # captcha is always valid in test mode
+    return validate_recap(options[:with], comment.errors, :rcc_pub =&gt; RECAPTCHA_PUBLIC_KEY, :rcc_priv =&gt; RECAPTCHA_PRIVATE_KEY)  
+  end
+
 end</diff>
      <filename>app/controllers/comments_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,6 +7,10 @@ module CommentsHelper
     end
   end
   
+  def delete_link_for comment
+    link_to &quot;DELETE&quot;, comment_path(comment), :method =&gt; :delete, :class =&gt; 'delete-comment' unless comment.new_record?
+  end
+  
   def opinion_for comment
     if comment.works_for_me?
       &quot;&lt;span class=\&quot;works\&quot;&gt;Working&lt;/span&gt;&quot;</diff>
      <filename>app/helpers/comments_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
 &lt;div class=&quot;comment rounded&quot;&gt;
-  &lt;%= gravatar_for comment %&gt;
+  &lt;%= gravatar_for comment %&gt; 
   &lt;p class=&quot;status&quot;&gt;
 	&lt;%= link_to h(comment.code.slug_name), code_by_slug_path(comment.code.slug_name), :class =&gt; 'gem' %&gt;
 	&lt;%= &quot;(#{comment.version})&quot; unless comment.version.blank? %&gt;
@@ -7,4 +7,5 @@
 	for &lt;%= name_link_for comment %&gt; &lt;span class=&quot;lighterblue&quot;&gt;(&lt;%= comment.platform %&gt;)&lt;/span&gt;&lt;br /&gt;
 	&lt;/p&gt;
   &lt;%= &quot;&lt;blockquote&gt;#{format_comment(comment.body)}&lt;/blockquote&gt;&quot; if local_assigns[:show_quote] &amp;&amp; !comment.body.blank? %&gt;
+  &lt;p&gt;&lt;%= delete_link_for comment %&gt;&lt;/p&gt;
 &lt;/div&gt;</diff>
      <filename>app/views/comments/_comment.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -5,8 +5,9 @@ Feature: adding a comment
   So that I can help the community track which gems work with Ruby 1.9
   
   Scenario: adding a comment
-  
-    Given a gem called &quot;rubynuts&quot;
+
+    Given an initialised database  
+    And a gem called &quot;rubynuts&quot;
     
     When I visit the page for &quot;rubynuts&quot;
     Then I see the comment form
@@ -15,6 +16,14 @@ Feature: adding a comment
     And I press &quot;submit comment&quot;
     Then I see my comment on the page
     
-  Scenario: adding a comment and then editing it
+  Scenario: adding a comment and then deleting it
+  
+    GivenScenario: adding a comment
+    
+    When I visit the page for &quot;rubynuts&quot;
+    Then I see the delete comment link
+    
+    When I click the delete comment link
+    Then I do not see my comment on the page
   
   Scenario: viewing someone else's comment 
\ No newline at end of file</diff>
      <filename>features/adding-a-comment.feature</filename>
    </modified>
    <modified>
      <diff>@@ -7,12 +7,23 @@ When /^I add a comment$/ do
   fill_in &quot;Email&quot;, :with =&gt; 'henry@testing.com'
   choose :comment_works_for_me_true
   fill_in &quot;Version&quot;, :with =&gt; '1.0'
-  fill_in &quot;Platform&quot;, :with =&gt; 'Mac OSX'
+  select 'Mac OSX', :from =&gt; 'Platform'
   fill_in :comment_body, :with =&gt; 'Here is my test comment' # have to request via ID rather than label because of the span around the optional, making it hard to find
 end
 
+When /^I click the delete comment link$/ do
+  click_link 'DELETE'
+end
+
+
 Then /^I see my comment on the page$/ do
   response.should include_text('Here is my test comment')
 end
 
+Then /^I see the delete comment link$/ do
+  response.should have_tag('a.delete-comment')
+end
 
+Then /^I do not see my comment on the page$/ do
+  response.should_not include_text('Here is my test comment')
+end</diff>
      <filename>features/step_definitions/comment_steps.rb</filename>
    </modified>
    <modified>
      <diff>@@ -300,7 +300,6 @@ dd {
 #new-comment-form label {
 	font-size: 11px;
 	line-height: 130%;
-	
 }
 
 
@@ -314,3 +313,13 @@ dd {
 #new-comment-form .text_field {
 width: 250px;	
 }
+
+a.delete-comment {
+  background: url(/images/misc/recreate.gif) no-repeat;
+  padding: 2px 4px 4px 18px;
+  font-size: 8pt;
+  font-weight: bold;
+  text-transform: uppercase;
+  text-decoration: none;
+	color: #95ABC3;
+}
\ No newline at end of file</diff>
      <filename>public/stylesheets/styles.css</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a24de0e112fbad6285615041d932d9dd4db0da53</id>
    </parent>
  </parents>
  <author>
    <name>Rahoul Baruah</name>
    <email>rahoul@brightbox.co.uk</email>
  </author>
  <url>http://github.com/brightbox/isitruby19/commit/f8f8c5873b240614f9c700e70fffa2b049edc54a</url>
  <id>f8f8c5873b240614f9c700e70fffa2b049edc54a</id>
  <committed-date>2009-02-09T04:09:17-08:00</committed-date>
  <authored-date>2009-02-09T04:09:17-08:00</authored-date>
  <message>delete comments link now appears on page</message>
  <tree>696ee45d61232282c34908526d6e50a8e25ade8a</tree>
  <committer>
    <name>Rahoul Baruah</name>
    <email>rahoul@brightbox.co.uk</email>
  </committer>
</commit>
