public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
comments fully tested and working

git-svn-id: http://svn.techno-weenie.net/projects/mephisto@611 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Tue Jan 10 12:59:28 -0800 2006
commit  1a3ae78d7cc49c56807e0938a4d8bc99d59904cb
tree    b4794448491218e97653f20b3a66e4e5a3d47ef0
parent  19981d5612cdab6151e76386da0364a0f1221c9c
...
1
 
 
2
3
 
 
 
 
 
 
4
5
6
 
7
8
 
 
 
 
9
10
11
...
1
2
3
4
5
6
7
8
9
10
11
12
13
 
14
15
 
16
17
18
19
20
21
22
0
@@ -1,11 +1,22 @@
0
 class CommentsController < ApplicationController
0
+ verify :params => [:year, :month, :day, :permalink], :redirect_to => { :controller => 'mephisto', :action => 'list', :tags => [] }
0
+
0
   def create
0
     @article = Article.find_by_permalink(params[:year], params[:month], params[:day], params[:permalink])
0
+
0
+ redirect_to(tags_url(:tags => [])) and return unless @article
0
+ if request.get? or params[:comment].blank?
0
+ redirect_to(article_url(@article.hash_for_permalink)) and return
0
+ end
0
+
0
     @comment = @article.comments.create(params[:comment].merge(:author_ip => request.remote_ip))
0
     if @comment.new_record?
0
- @comments = @article.comments.collect { |c| c.to_liquid }
0
+ @comments = @article.comments.select { |c| not c.new_record? }.collect { |c| c.to_liquid }
0
       @article = @article.to_liquid(:single)
0
- render_liquid_template_for(:single, 'articles' => [@article], 'article' => @article, 'comments' => @comments)
0
+ render_liquid_template_for(:single, 'articles' => [@article],
0
+ 'article' => @article,
0
+ 'comments' => @comments,
0
+ 'errors' => @comment.errors.full_messages)
0
     else
0
       redirect_to article_url(@article.hash_for_permalink(:anchor => "comment_#{@comment.id}"))
0
     end
...
6
7
8
 
 
9
10
11
...
14
15
16
17
 
18
19
20
...
6
7
8
9
10
11
12
13
...
16
17
18
 
19
20
21
22
0
@@ -6,6 +6,8 @@ module Mephisto
0
     def render(context)
0
       result = []
0
       context.stack do
0
+ errors = context['errors'] ? %Q{<ul id="comment_errors"><li>#{context['errors'].join('</li><li>')}</li></ul>} : ''
0
+
0
         context['form'] = {
0
           'body' => text_area_tag('comment_description', nil, :name => 'comment[description]'),
0
           'name' => text_field_tag('comment_author', nil, :name => 'comment[author]'),
0
@@ -14,7 +16,7 @@ module Mephisto
0
           'submit' => submit_tag('Send')
0
         }
0
 
0
- result << content_tag(:form, render_all(@nodelist, context), :method => :post, :action => "#{context['article']['url']}/comment")
0
+ result << content_tag(:form, [errors]+render_all(@nodelist, context), :method => :post, :action => "#{context['article']['url']}/comment")
0
       end
0
       result
0
     end
...
38
39
40
41
 
42
43
44
45
...
38
39
40
 
41
42
43
44
45
0
@@ -38,7 +38,7 @@ module Mephisto
0
     end
0
 
0
     def format_date(date, format)
0
- date.to_s(format.to_sym)
0
+ date ? date.to_s(format.to_sym) : nil
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
0
@@ -46,4 +46,23 @@ class CommentsControllerTest < Test::Unit::TestCase
0
       end
0
     end
0
   end
0
+
0
+ def test_should_reject_missing_article_params
0
+ get :create
0
+ assert_redirected_to @controller.send(:tags_url, { :tags => [] })
0
+ post :create, :year => '2006', :month => '01', :day => '01', :permalink => 'foo'
0
+ assert_redirected_to @controller.send(:tags_url, { :tags => [] })
0
+ end
0
+
0
+ def test_should_reject_get_request
0
+ get :create, articles(:welcome).hash_for_permalink
0
+ assert_redirected_to @controller.url_for(articles(:welcome).hash_for_permalink(:controller => 'mephisto',
0
+ :action => 'show'))
0
+ end
0
+
0
+ def test_should_reject_invalid_post
0
+ post :create, articles(:welcome).hash_for_permalink
0
+ assert_redirected_to @controller.url_for(articles(:welcome).hash_for_permalink(:controller => 'mephisto',
0
+ :action => 'show'))
0
+ end
0
 end
...
71
72
73
74
75
76
77
78
79
80
81
 
 
 
 
 
 
 
 
82
83
84
...
71
72
73
 
 
 
 
 
 
 
 
74
75
76
77
78
79
80
81
82
83
84
0
@@ -71,14 +71,14 @@ class MephistoControllerTest < Test::Unit::TestCase
0
   def test_should_show_comments_form
0
     date = 3.days.ago
0
     get :show, :year => date.year, :month => date.month, :day => date.day, :permalink => 'welcome_to_mephisto'
0
- assert_tag :tag => 'form', :descendant => {
0
- :tag => 'input', :attributes => { :type => 'text', :id => 'comment_author', :name => 'comment[author]' } }
0
- assert_tag :tag => 'form', :descendant => {
0
- :tag => 'input', :attributes => { :type => 'text', :id => 'comment_url', :name => 'comment[url]' } }
0
- assert_tag :tag => 'form', :descendant => {
0
- :tag => 'input', :attributes => { :type => 'text', :id => 'comment_email', :name => 'comment[email]' } }
0
- assert_tag :tag => 'form', :descendant => {
0
- :tag => 'input', :attributes => { :type => 'text', :id => 'comment_description', :name => 'comment[description]' } }
0
+ assert_tag :tag => 'form', :descendant => {
0
+ :tag => 'input', :attributes => { :type => 'text', :id => 'comment_author', :name => 'comment[author]' } }
0
+ assert_tag :tag => 'form', :descendant => {
0
+ :tag => 'input', :attributes => { :type => 'text', :id => 'comment_author_url', :name => 'comment[author_url]' } }
0
+ assert_tag :tag => 'form', :descendant => {
0
+ :tag => 'input', :attributes => { :type => 'text', :id => 'comment_author_email', :name => 'comment[author_email]' } }
0
+ assert_tag :tag => 'form', :descendant => {
0
+ :tag => 'textarea', :attributes => { :id => 'comment_description', :name => 'comment[description]' } }
0
   end
0
 
0
   def test_should_show_daily_entries

Comments

    No one has commented yet.