The respond_to? method tells you if an object responds to a method, but it doesn't tell you what its response actually is. So here, the conditions will always be true for logged out users, since all works respond to the restricted method. When you're writing a test for something like this, it's good to check all the variations that users can encounter: guests shouldn't be able to view restricted comments, guests should be able to view unrestricted comments, and logged-in users should be able to view restricted comments.

Also, you have access to the "@comment" and "@commentable" variables here if they're set, so you can save some database calls. I'd do something like this:

    parent =  if @comment.present?
                @comment.ultimate_parent
              elsif @commentable.present? && @commentable.respond_to?(:work)
                @commentable.work
              else
                @commentable
              end

    if parent.respond_to?(:restricted) && parent.restricted?
      ...
    end