From ce93ebbd7cbacbdb42619e8e3776519c5dc4b219 Mon Sep 17 00:00:00 2001 From: Nowa Date: Tue, 5 Apr 2011 03:16:57 +0800 Subject: [PATCH 01/10] =?UTF-8?q?Mod:=20=E8=B0=83=E6=95=B4newbie=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E8=AF=9D=E9=A2=98=E7=9A=84=E9=A2=91=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/home_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index df95367..c53b62d 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -23,8 +23,8 @@ def index end def newbie - ask_logs = Log.any_of({:_type => "AskLog"}, {:_type => "UserLog", :action.in => ["FOLLOW_ASK", "UNFOLLOW_ASK"]}).where(:created_at.gte => (Time.now - 1.day)) - answer_logs = Log.any_of({:_type => "AnswerLog"}, {:_type => "UserLog", :action => "AGREE"}).where(:created_at.gte => (Time.now - 1.day)) + ask_logs = Log.any_of({:_type => "AskLog"}, {:_type => "UserLog", :action.in => ["FOLLOW_ASK", "UNFOLLOW_ASK"]}).where(:created_at.gte => (Time.now - 2.hours)) + answer_logs = Log.any_of({:_type => "AnswerLog"}, {:_type => "UserLog", :action => "AGREE"}).where(:created_at.gte => (Time.now - 2.hours)) @asks = Ask.any_of({:_id.in => ask_logs.map {|l| l.target_id}.uniq}, {:_id.in => answer_logs.map {|l| l.target_parent_id}.uniq}).desc("answers_count") h = {} @hot_topics = @asks.inject([]) { |memo, ask| @@ -33,6 +33,9 @@ def newbie @hot_topics.delete("者也") @hot_topics.delete("知乎") @hot_topics.delete("反馈") + @hot_topics.delete("zheye") + @hot_topics.delete("Quora") + @hot_topics.delete("quora") @hot_topics.each { |str| h[str] = (h[str] || 0) + 1 From e1330cce0ac2a2da1c20380bc2e918c97c0c54c5 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 5 Apr 2011 03:26:05 +0800 Subject: [PATCH 02/10] =?UTF-8?q?Add:=20=E6=95=8F=E6=84=9F=E8=AF=8D?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/answer.rb | 9 ++++++++- app/models/ask.rb | 19 ++++++++++++++++++- app/models/base_model.rb | 16 ++++++++++++++++ app/models/comment.rb | 10 +++++++++- app/models/topic.rb | 13 ++++++++++++- app/views/asks/_form.html.erb | 7 +++++-- config/setting.yml.default | 1 + public/stylesheets/application.css | 2 ++ 8 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 app/models/base_model.rb diff --git a/app/models/answer.rb b/app/models/answer.rb index fa95c0d..f7db1d1 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -1,5 +1,5 @@ # coding: utf-8 -class Answer +class Answer < BaseModel include Mongoid::Document include Mongoid::Timestamps include Mongoid::Voteable @@ -15,6 +15,13 @@ class Answer has_many :logs, :class_name => "Log", :foreign_key => "target_id" validates_presence_of :user_id, :body + # 敏感词验证 + before_validation :check_spam_words + def check_spam_words + if self.spam?("body") + return false + end + end after_create :save_to_ask_and_update_answered_at before_update :log_update diff --git a/app/models/ask.rb b/app/models/ask.rb index 528cac3..c3f2452 100644 --- a/app/models/ask.rb +++ b/app/models/ask.rb @@ -1,5 +1,5 @@ # coding: utf-8 -class Ask +class Ask < BaseModel include Mongoid::Document include Mongoid::Timestamps include Mongoid::Sphinx @@ -59,6 +59,23 @@ class Ask after_destroy :dec_counter_cache before_update :update_log + # 敏感词验证 + before_validation :check_spam_words + def check_spam_words + if self.spam?("title") + return false + end + + if self.spam?("body") + return false + end + + if self.spam?("topics") + return false + end + + end + def inc_counter_cache self.user.inc(:asks_count, 1) end diff --git a/app/models/base_model.rb b/app/models/base_model.rb new file mode 100644 index 0000000..6c210f1 --- /dev/null +++ b/app/models/base_model.rb @@ -0,0 +1,16 @@ +# coding: utf-8 +class BaseModel + # 检测敏感词 + def spam?(attr) + value = eval("self.#{attr}") + return false if value.blank? + if value.class == [].class + value = value.join(" ") + end + spam_reg = Regexp.new(Setting.spam_words) + if matched = spam_reg.match(value) + self.errors.add(attr,"带有敏感内容[#{matched.to_a.join(",")}],请注意一下!") + return false + end + end +end diff --git a/app/models/comment.rb b/app/models/comment.rb index 32692e8..5de0d7d 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,5 @@ # coding: utf-8 -class Comment +class Comment < BaseModel include Mongoid::Document include Mongoid::Timestamps @@ -11,6 +11,14 @@ class Comment validates_presence_of :body + # 敏感词验证 + before_validation :check_spam_words + def check_spam_words + if self.spam?("body") + return false + end + end + before_create :fix_commentable_id def fix_commentable_id if self.commentable_id.class == "".class diff --git a/app/models/topic.rb b/app/models/topic.rb index f7ac895..9e753ef 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1,5 +1,5 @@ # coding: utf-8 -class Topic +class Topic < BaseModel include Mongoid::Document field :name @@ -17,6 +17,17 @@ class Topic validates_presence_of :name validates_uniqueness_of :name, :case_insensitive => true + # 敏感词验证 + before_validation :check_spam_words + def check_spam_words + if self.spam?("name") + return false + end + + if self.spam?("summary") + return false + end + end def self.save_topics(topics, current_user_id) topics.each do |item| diff --git a/app/views/asks/_form.html.erb b/app/views/asks/_form.html.erb index b9977a0..6aec25a 100644 --- a/app/views/asks/_form.html.erb +++ b/app/views/asks/_form.html.erb @@ -1,8 +1,11 @@
<%= simple_form_for(@ask) do |f| %>
- <%= f.input :title, :input_html => {:class => "long"}%> - <%= f.input :body, :as => :text, :input_html => {:class => "long"} %> + <%= f.input :title, :label => "标题", :input_html => {:class => "long"}%> + <%= f.input :body, :label => "正文", :as => :text, :input_html => {:class => "long"} %> +
或者 <%= link_to '返回', asks_path %> diff --git a/config/setting.yml.default b/config/setting.yml.default index 29341ce..01664ef 100644 --- a/config/setting.yml.default +++ b/config/setting.yml.default @@ -17,6 +17,7 @@ default: &defaults # 问题被多少次 spam 自动删除 ask_spam_max: 8 google_analytics_id: "UA-22413508-1" + spam_words: /敏感词1|敏感词2/ development: <<: *defaults diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index f4c5a72..f43f065 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -72,6 +72,8 @@ a.green_button:active { .simple_form .actions { margin:5px 0 10px 0; } .simple_form label { font-size: 12px; color:#666; display:block; } .form span.error-message { color:red; } +.simple_form span.error { display:block; color:red; display:block; } +.form span.error { display:block; color:red; display:block; } .alert_message, .notice_message, .error_explanation, #error_explanation { font-family: "adelle-1", "adelle-2", tahoma, sans-serif; From 9395d7df51dfac07c0ee3c790ca8014f65fd0f67 Mon Sep 17 00:00:00 2001 From: Nowa Date: Tue, 5 Apr 2011 03:27:19 +0800 Subject: [PATCH 03/10] =?UTF-8?q?Fixed:=20=E6=B7=BB=E5=8A=A0=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E6=97=B6timeline=E6=98=BE=E7=A4=BA=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E7=9A=84bug=20Fixed:=20=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E4=BF=AE=E6=94=B9spams=5Fcount=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/ask.rb | 3 ++- app/views/logs/_log.html.erb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/ask.rb b/app/models/ask.rb index 88431c0..592a432 100644 --- a/app/models/ask.rb +++ b/app/models/ask.rb @@ -39,7 +39,8 @@ class Ask attr_protected :user_id attr_accessor :current_user_id - validates_presence_of :user_id, :title, :current_user_id + validates_presence_of :user_id, :title + validates_presence_of :current_user_id, :if => proc { |obj| obj.title_changed? or obj.body_changed? } # 正常可显示的问题, 前台调用都带上这个过滤 scope :normal, where(:spams_count.lt => Setting.ask_spam_max) diff --git a/app/views/logs/_log.html.erb b/app/views/logs/_log.html.erb index 9b78af3..6471f0d 100644 --- a/app/views/logs/_log.html.erb +++ b/app/views/logs/_log.html.erb @@ -11,6 +11,7 @@ when "AskLog" case action when "NEW" %> + <% when "ADD_TOPIC", "DEL_TOPIC","EDIT" %> <% else %> From 59c622bd8f3c2c552c958da87884552005257923 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 5 Apr 2011 03:28:17 +0800 Subject: [PATCH 04/10] =?UTF-8?q?Add:=20=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=95=8F=E6=84=9F=E8=AF=8D=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 13ba0d1..d4ac7f7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,5 @@ # coding: utf-8 -class User +class User < BaseModel include Mongoid::Document include Mongoid::Timestamps include Mongoid::Voter @@ -47,6 +47,22 @@ class User validates_presence_of :name, :slug validates_uniqueness_of :slug + # 敏感词验证 + before_validation :check_spam_words + def check_spam_words + if self.spam?("tagline") + return false + end + if self.spam?("name") + return false + end + if self.spam?("slug") + return false + end + if self.spam?("bio") + return false + end + end def password_required? !persisted? || password.present? || password_confirmation.present? From cd1eb1ee2d30d5c5a82ae6558c067d0a4f2a30b0 Mon Sep 17 00:00:00 2001 From: Nowa Date: Tue, 5 Apr 2011 03:29:12 +0800 Subject: [PATCH 05/10] - --- app/views/logs/_log.html.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/logs/_log.html.erb b/app/views/logs/_log.html.erb index 6471f0d..eed7409 100644 --- a/app/views/logs/_log.html.erb +++ b/app/views/logs/_log.html.erb @@ -9,9 +9,7 @@ when "AskLog"
<% case action - when "NEW" %> - <% when "ADD_TOPIC", "DEL_TOPIC","EDIT" %> <% else %> From 91d1fdd9f204eb3adf5d0bba361e945461c1a5f2 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 5 Apr 2011 03:31:06 +0800 Subject: [PATCH 06/10] =?UTF-8?q?Fix:=20=E7=94=A8=E6=88=B7=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5=E4=BF=AE=E6=94=B9Bio=E6=A0=B7=E5=BC=8F=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_head.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/users/_head.html.erb b/app/views/users/_head.html.erb index ec6673f..7c2ee66 100644 --- a/app/views/users/_head.html.erb +++ b/app/views/users/_head.html.erb @@ -19,12 +19,12 @@ :rich => false, :text_id => "user_tagline") %> <% end %> <% if !user.website.blank? %> -

+

<%= user.website %> <% if owner?user %> <%= in_place_edit_tag(user,:website, :text_id => "user_website") %> <% end %> -

+
<% end %> -

+

<% if @user.bio.blank? and (not owner?@user) %> <%= @user.name %>还没来得及写他的个人介绍. @@ -33,7 +33,7 @@ <% end %> <% if owner?@user %> <%= in_place_edit_tag(@user,:bio,:type => :textarea, :text_id => "user_bio", :label => "修改个人经历") %> <% end %> -

+
From 03a5c8fe8339ac8bc3d025b85e5c38f2640191ef Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 5 Apr 2011 03:42:51 +0800 Subject: [PATCH 07/10] =?UTF-8?q?Add:=20=E8=80=85=E4=B9=9FIcon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/images/icon.png | Bin 0 -> 2581 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 public/images/icon.png diff --git a/public/images/icon.png b/public/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zzGgPFavvm8Y9~eUsKnEAcuCRXx2kHYi+VeAf8&k$l+{AGjT&IFvmoDwb{3S(up6Y=fNJaYJd7z7YB$=(&k6BTqr1VkZ{sD zVnfu+txb7lpUBLCTr> z-)^JIy3v{r?AMXn%*Sj+)H%kMcBevFr`>Ld52MHgSNzy$#Q7Cx=CRhwhTUbp_vzkB z9}AyPAexJy79}5Hpzzj-Kc+(`D0(g`~x+Zi#Z57hiDZEv%(Sh2=s~zd$1- za_clmd`>|EBaRVQRs039U*mr!h9^|S_lnua!fB| Date: Tue, 5 Apr 2011 03:53:18 +0800 Subject: [PATCH 08/10] =?UTF-8?q?Fix:=20=E4=B8=AA=E4=BA=BA=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5=E4=BF=AE=E6=94=B9tagline=E6=A0=B7=E5=BC=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_head.html.erb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/users/_head.html.erb b/app/views/users/_head.html.erb index 7c2ee66..d7bcfce 100644 --- a/app/views/users/_head.html.erb +++ b/app/views/users/_head.html.erb @@ -15,8 +15,7 @@

<%= user.name %><%= user.tagline %> <% if owner?user %> - <%= in_place_edit_tag(user,:tagline, :type => :textarea,:width => 200, :height => 80, - :rich => false, :text_id => "user_tagline") %> + <%= in_place_edit_tag(user,:tagline,:rich => false, :text_id => "user_tagline") %> <% end %>

<% if !user.website.blank? %>
From 4696120f03a7c82c1df1d9857e5329dd808d80c2 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 5 Apr 2011 03:58:14 +0800 Subject: [PATCH 09/10] =?UTF-8?q?Add:=20=E5=90=8E=E5=8F=B0=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/cpanel/comments_controller.rb | 74 +++++++++++++++++++ app/helpers/cpanel/comments_helper.rb | 2 + app/views/cpanel/comments/_base.html.erb | 15 ++++ app/views/cpanel/comments/_form.html.erb | 16 ++++ app/views/cpanel/comments/edit.html.erb | 6 ++ app/views/cpanel/comments/index.html.erb | 27 +++++++ app/views/cpanel/comments/new.html.erb | 5 ++ app/views/cpanel/comments/show.html.erb | 26 +++++++ config/routes.rb | 1 + .../cpanel/comments_controller_test.rb | 49 ++++++++++++ .../helpers/cpanel/comments_helper_test.rb | 4 + 11 files changed, 225 insertions(+) create mode 100644 app/controllers/cpanel/comments_controller.rb create mode 100644 app/helpers/cpanel/comments_helper.rb create mode 100644 app/views/cpanel/comments/_base.html.erb create mode 100644 app/views/cpanel/comments/_form.html.erb create mode 100644 app/views/cpanel/comments/edit.html.erb create mode 100644 app/views/cpanel/comments/index.html.erb create mode 100644 app/views/cpanel/comments/new.html.erb create mode 100644 app/views/cpanel/comments/show.html.erb create mode 100644 test/functional/cpanel/comments_controller_test.rb create mode 100644 test/unit/helpers/cpanel/comments_helper_test.rb diff --git a/app/controllers/cpanel/comments_controller.rb b/app/controllers/cpanel/comments_controller.rb new file mode 100644 index 0000000..54e72c6 --- /dev/null +++ b/app/controllers/cpanel/comments_controller.rb @@ -0,0 +1,74 @@ +# coding: UTF-8 +class Cpanel::CommentsController < CpanelController + + def index + @comments = initialize_grid(Comment, + :order => 'id', + :order_direction => 'desc') + + respond_to do |format| + format.html # index.html.erb + format.json + end + end + + def show + @comment = Comment.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json + end + end + + def new + @comment = Comment.new + + respond_to do |format| + format.html # new.html.erb + format.json + end + end + + def edit + @comment = Comment.find(params[:id]) + end + + def create + @comment = Comment.new(params[:comment]) + + respond_to do |format| + if @comment.save + format.html { redirect_to(cpanel_comments_path, :notice => 'Comment 创建成功。') } + format.json + else + format.html { render :action => "new" } + format.json + end + end + end + + def update + @comment = Comment.find(params[:id]) + + respond_to do |format| + if @comment.update_attributes(params[:comment]) + format.html { redirect_to(cpanel_comments_path, :notice => 'Comment 更新成功。') } + format.json + else + format.html { render :action => "edit" } + format.json + end + end + end + + def destroy + @comment = Comment.find(params[:id]) + @comment.destroy + + respond_to do |format| + format.html { redirect_to(cpanel_comments_path,:notice => "删除成功。") } + format.json + end + end +end diff --git a/app/helpers/cpanel/comments_helper.rb b/app/helpers/cpanel/comments_helper.rb new file mode 100644 index 0000000..5f9bf07 --- /dev/null +++ b/app/helpers/cpanel/comments_helper.rb @@ -0,0 +1,2 @@ +module Cpanel::CommentsHelper +end diff --git a/app/views/cpanel/comments/_base.html.erb b/app/views/cpanel/comments/_base.html.erb new file mode 100644 index 0000000..4905c76 --- /dev/null +++ b/app/views/cpanel/comments/_base.html.erb @@ -0,0 +1,15 @@ +<%= content_for :base_sitemap do %> +cpanel_comments » +<% end %> +<%= content_for :styles do %> +<% end %> + +<%= spaceless do %> +
+ ">查看所有 + <% if ["edit","update"].index(params[:action]) %> + 编辑 + <% end %> + ">新建 +
+<% end %> diff --git a/app/views/cpanel/comments/_form.html.erb b/app/views/cpanel/comments/_form.html.erb new file mode 100644 index 0000000..9ee6d15 --- /dev/null +++ b/app/views/cpanel/comments/_form.html.erb @@ -0,0 +1,16 @@ +
+<%= simple_form_for(@comment, + :url => (@comment.id.blank? ? cpanel_comments_path : cpanel_comment_path(@comment.id)) ) do |f| %> + +
+ <%= f.input :body %> + <%= f.input :user_id %> + <%= f.input :commentable_type %> + <%= f.input :commentable_id %> +
+
+ + 或者 <%= link_to '返回', cpanel_comments_path %> +
+<% end %> +
diff --git a/app/views/cpanel/comments/edit.html.erb b/app/views/cpanel/comments/edit.html.erb new file mode 100644 index 0000000..9f3bf71 --- /dev/null +++ b/app/views/cpanel/comments/edit.html.erb @@ -0,0 +1,6 @@ +<%= content_for :sitemap do %> +修改 +<% end %> +<%= render 'base' %> +<%= render 'form' %> + diff --git a/app/views/cpanel/comments/index.html.erb b/app/views/cpanel/comments/index.html.erb new file mode 100644 index 0000000..9c2b428 --- /dev/null +++ b/app/views/cpanel/comments/index.html.erb @@ -0,0 +1,27 @@ +<%= content_for :sitemap do %> +列表 +<% end %> +<%= render 'base' %> + +
+ <%= grid(@comments, :show_filters => :false) do |g| + g.column :column_name => 'body', :attribute_name => 'body' do |c| + c.body if !c.body.blank? + end + g.column :column_name => 'user_id', :attribute_name => 'user_id' do |c| + c.user_id if !c.user_id.blank? + end + g.column :column_name => 'commentable_type', :attribute_name => 'commentable_type' do |c| + c.commentable_type if !c.commentable_type.blank? + end + g.column :column_name => 'commentable_type', :attribute_name => 'commentable_type' do |c| + c.commentable_id if !c.commentable_id.blank? + end + g.column :column_name => '创建时间', :attribute_name => 'created_at', :td_html_attrs => { :style => "width:120px;" } + g.column :td_html_attrs => { :style => "width:50px; text-align:right;" } do |c| + raw "#{link_to image_tag("wice_grid/delete.png", :style => "margin-bottom:-4px"), cpanel_comment_path(c.id), :method => :delete, :confirm => '确定要删除吗?'}" + end + end %> +
+ + diff --git a/app/views/cpanel/comments/new.html.erb b/app/views/cpanel/comments/new.html.erb new file mode 100644 index 0000000..a6c1d08 --- /dev/null +++ b/app/views/cpanel/comments/new.html.erb @@ -0,0 +1,5 @@ +<%= content_for :sitemap do %> +新建 +<% end %> +<%= render 'base' %> +<%= render 'form' %> diff --git a/app/views/cpanel/comments/show.html.erb b/app/views/cpanel/comments/show.html.erb new file mode 100644 index 0000000..8eb3ed3 --- /dev/null +++ b/app/views/cpanel/comments/show.html.erb @@ -0,0 +1,26 @@ +<%= content_for :sitemap do %> +查看 +<% end %> +<%= render 'base' %> +
+ <%= link_to '修改', edit_cpanel_comment_path(@comment) %> | + <%= link_to '返回', cpanel_comments_path %> +
+
+

+ Body: + <%= @comment.body %> +

+

+ User: + <%= @comment.user_id %> +

+

+ Commentable type: + <%= @comment.commentable_type %> +

+

+ Commentable: + <%= @comment.commentable_id %> +

+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e6d1068..e1594eb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -67,5 +67,6 @@ resources :asks resources :answers resources :topics + resources :comments end end diff --git a/test/functional/cpanel/comments_controller_test.rb b/test/functional/cpanel/comments_controller_test.rb new file mode 100644 index 0000000..c8a1e9b --- /dev/null +++ b/test/functional/cpanel/comments_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class Cpanel::CommentsControllerTest < ActionController::TestCase + setup do + @cpanel_comment = cpanel_comments(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:cpanel_comments) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create cpanel_comment" do + assert_difference('Cpanel::Comment.count') do + post :create, :cpanel_comment => @cpanel_comment.attributes + end + + assert_redirected_to cpanel_comment_path(assigns(:cpanel_comment)) + end + + test "should show cpanel_comment" do + get :show, :id => @cpanel_comment.to_param + assert_response :success + end + + test "should get edit" do + get :edit, :id => @cpanel_comment.to_param + assert_response :success + end + + test "should update cpanel_comment" do + put :update, :id => @cpanel_comment.to_param, :cpanel_comment => @cpanel_comment.attributes + assert_redirected_to cpanel_comment_path(assigns(:cpanel_comment)) + end + + test "should destroy cpanel_comment" do + assert_difference('Cpanel::Comment.count', -1) do + delete :destroy, :id => @cpanel_comment.to_param + end + + assert_redirected_to cpanel_comments_path + end +end diff --git a/test/unit/helpers/cpanel/comments_helper_test.rb b/test/unit/helpers/cpanel/comments_helper_test.rb new file mode 100644 index 0000000..b2b0d65 --- /dev/null +++ b/test/unit/helpers/cpanel/comments_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class Cpanel::CommentsHelperTest < ActionView::TestCase +end From 95d38f729275d8cfc609e8f125997a0e4f753f4e Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 5 Apr 2011 04:16:43 +0800 Subject: [PATCH 10/10] =?UTF-8?q?Mod:=20Favicon=E6=9B=B4=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/application.html.erb | 2 +- public/favicon.ico | Bin 367 -> 1150 bytes public/images/favicon.png | Bin 0 -> 466 bytes 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 public/images/favicon.png diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 99d623b..97d753a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,7 +10,7 @@ <%= yield :styles %> - + <%= csrf_meta_tag %> <%= javascript_include_tag "jquery.min","rails","facebox","jquery.jdialog","jquery.qeditor","jcaches","application","asks", :cache => "cached_application" %> <%= yield :scripts %> diff --git a/public/favicon.ico b/public/favicon.ico index 923e7cc216cfe028ed275987f5a77b3098ca58a1..e7542b6c98c0a7413b2611235557b87682b17f53 100644 GIT binary patch literal 1150 zcmZQzU<5(|0R|wcz>vYhz#zuJz@P!dKp~(AL>x#lFaYH+fXa&h41*LK`0e<=eDlNq ziVmB}a^vNjAO3^DlNaCqTZQc**^K*-zkv0_h^pR8B$)xz|M>Y=m=XWmreFKds?gn+&t^Xf9MGbS18TL_oiP8@;Pu6x5 q*dH*vN!1TBgI9kIN_eZfY$4iyWIturo%s*K$YO(zjZq+wCIA57KQOld literal 367 zcmV-#0g(QQP)n7IR7eTBv)Cs+|0AkG!g(1(O95CIvYX7-Sd^ba>_u#2kREXl`+DT22h>v{`)`@Xx`oBGsUf3#I2k`-nf2Yr=KAf4UmY_&Z}1p zNV6fXLz(1A#x(u@x&^y~ z&5=a}iH;R?ABdSdpqYMW+4QTE8h*Teg)GR*CqSkJ@2_7#=3bxCeyO*LnnCpY(}y#) z=^w6N05Z@_2a4b^2A-x0HCa=^0$>?+XX*5JmrhZqPX2&eiU6bZQdc>C(}93FM2J`mzCO9n$jl<7YYGYU z3vESzzJH~(%0vdA@83G#S_mXxojic%8$5tPx# literal 0 HcmV?d00001