Commit e7e0fd8c by Rocky Duan

added spec & fixed bug

parent 0bf762e5
...@@ -12,8 +12,8 @@ class Comment < ActiveRecord::Base ...@@ -12,8 +12,8 @@ class Comment < ActiveRecord::Base
acts_as_voteable acts_as_voteable
validates_presence_of :title, :unless => Proc.new{|c| c.is_root? or c.body} validates_presence_of :title, :unless => Proc.new{|c| c.is_root? or not c.body.blank?}
validates_presence_of :body, :unless => Proc.new{|c| c.is_root? or c.title} validates_presence_of :body, :unless => Proc.new{|c| c.is_root? or not c.title.blank?}
validates_presence_of :user_id, :unless => :is_root? validates_presence_of :user_id, :unless => :is_root?
validates_presence_of :course_id, :unless => :is_root? validates_presence_of :course_id, :unless => :is_root?
validates_presence_of :comment_thread_id validates_presence_of :comment_thread_id
......
...@@ -18,6 +18,30 @@ describe "app" do ...@@ -18,6 +18,30 @@ describe "app" do
comment.user_id.should == 1 comment.user_id.should == 1
comment.user_id.should == 1 comment.user_id.should == 1
end end
it "should create a top-level comment with only title" do
post "/api/v1/commentables/questions/1/comments", :body => "", :title => "comment title", :user_id => 1, :course_id => 1
last_response.should be_ok
comment = CommentThread.first.root_comments.first
comment.should_not be_nil
comment.body.should == ""
comment.title.should == "comment title"
comment.user_id.should == 1
comment.user_id.should == 1
end
it "should create a top-level comment with only body" do
post "/api/v1/commentables/questions/1/comments", :body => "comment body", :title => "", :user_id => 1, :course_id => 1
last_response.should be_ok
comment = CommentThread.first.root_comments.first
comment.should_not be_nil
comment.body.should == "comment body"
comment.title.should == ""
comment.user_id.should == 1
comment.user_id.should == 1
end
it "should not create a top-level comment with neither title nor body" do
post "/api/v1/commentables/questions/1/comments", :body => "", :title => "", :user_id => 1, :course_id => 1
last_response.status.should == 400
end
end end
describe "POST on /api/v1/comments/:comment_id" do describe "POST on /api/v1/comments/:comment_id" do
before :each do before :each do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment