Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

only shows the delete link if you have permission to delete

  • Loading branch information...
commit 8e0d2577cfd86bd9099dd30b0b0ce47ba4eb6338 1 parent f8f8c58
Rahoul Baruah rahoulb authored
8 app/controllers/application.rb
@@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
6 6 filter_parameter_logging :password
7 7 layout 'isitruby19'
8 8 include ReCaptcha::AppHelper
  9 + helper_method :my_comments
9 10
10 11 protected
11 12 # build an rss feed for the given collection
@@ -29,4 +30,11 @@ def rss_for objects, mapping
29 30 end
30 31 end.to_s
31 32 end
  33 +
  34 + # uses the session to store which comments I created
  35 + def my_comments
  36 + session[:my_comments] ||= []
  37 + end
  38 +
  39 +
32 40 end
4 app/controllers/comments_controller.rb
@@ -57,10 +57,6 @@ def can_delete comment
57 57 end
58 58
59 59 private
60   - def my_comments
61   - session[:my_comments] ||= []
62   - end
63   -
64 60 def captcha_is_valid_for comment, options
65 61 return true if ENV['RAILS_ENV'] == 'test' # captcha is always valid in test mode
66 62 return validate_recap(options[:with], comment.errors, :rcc_pub => RECAPTCHA_PUBLIC_KEY, :rcc_priv => RECAPTCHA_PRIVATE_KEY)
4 app/helpers/comments_helper.rb
@@ -8,7 +8,9 @@ def name_link_for comment
8 8 end
9 9
10 10 def delete_link_for comment
11   - link_to "DELETE", comment_path(comment), :method => :delete, :class => 'delete-comment' unless comment.new_record?
  11 + return nil if comment.new_record?
  12 + return nil unless my_comments.include?(comment.id)
  13 + link_to "DELETE", comment_path(comment), :method => :delete, :class => 'delete-comment', :confirm => 'Are you sure?'
12 14 end
13 15
14 16 def opinion_for comment
9 features/adding-a-comment.feature
@@ -26,4 +26,11 @@ Feature: adding a comment
26 26 When I click the delete comment link
27 27 Then I do not see my comment on the page
28 28
29   - Scenario: viewing someone else's comment
  29 + Scenario: viewing someone else's comment
  30 +
  31 + Given an initialised database
  32 + And a gem called "rubynuts"
  33 + And a comment against "rubynuts"
  34 +
  35 + When I visit the page for "rubynuts"
  36 + Then I do not see the delete comment link
11 features/step_definitions/comment_steps.rb
... ... @@ -1,3 +1,9 @@
  1 +Given /^a comment against "(.*)"$/ do | name |
  2 + code = Code.find_by_name! name
  3 + comment = a_saved Comment, :code => code
  4 +end
  5 +
  6 +
1 7 Then /^I see the comment form$/ do
2 8 response.should have_tag('div#new-comment-form')
3 9 end
@@ -24,6 +30,11 @@
24 30 response.should have_tag('a.delete-comment')
25 31 end
26 32
  33 +Then /^I do not see the delete comment link$/ do
  34 + response.should_not have_tag('a.delete-comment')
  35 +end
  36 +
  37 +
27 38 Then /^I do not see my comment on the page$/ do
28 39 response.should_not include_text('Here is my test comment')
29 40 end
7 lib/object_factory_config.rb
... ... @@ -1,4 +1,11 @@
1 1 def prepare_object_factory
2 2 when_creating_a Code, :auto_generate => :name
3 3
  4 + when_creating_a Comment,
  5 + :auto_generate => :name,
  6 + :generate_email_address => :email,
  7 + :generate => {
  8 + :code => lambda { a_saved Code },
  9 + :platform => lambda { Platform.first }
  10 + }
4 11 end
8 public/stylesheets/styles.css
@@ -279,6 +279,14 @@ div.errorExplanation {
279 279 margin-bottom: 10px;
280 280 }
281 281
  282 +#flash_error {
  283 + border: 1px solid red;
  284 + background-color: #CC0000;
  285 + padding: 10px;
  286 + margin-bottom: 10px;
  287 +}
  288 +
  289 +
282 290 dt {
283 291 color: #95ABC3;
284 292 }

0 comments on commit 8e0d257

Please sign in to comment.
Something went wrong with that request. Please try again.