Skip to content

Commit

Permalink
[api] raising error against no user in api now
Browse files Browse the repository at this point in the history
  • Loading branch information
Shayon Mukherjee authored and adrianschroeter committed Aug 9, 2013
1 parent 4704edf commit 6af9ac8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/api/app/models/comment.rb
Expand Up @@ -5,6 +5,9 @@ class Comment < ActiveRecord::Base
class NoDataEnteredError < APIException
setup 'no_data_entered', 403, "No data Entered"
end
class NoUserFound < APIException
setup 'no_user_found', 403, "No user found"
end
def self.save(params)
@comment = {}
@comment['title'] = params[:title]
Expand All @@ -16,6 +19,8 @@ def self.save(params)
raise NoDataEnteredError.new "You didn't add a body to the comment."
elsif !@comment['parent_id'] && @comment['title'].blank?
raise NoDataEnteredError.new "You didnt add a title to the comment"
elsif @comment['user'].blank?
raise NoUserFound.new "No user found. Sign in before continuing."
end
end
end
7 changes: 5 additions & 2 deletions src/api/test/functional/comments_controller_test.rb
Expand Up @@ -10,16 +10,19 @@ def setup

def test_show_and_post_comments_on_project
# Testing new comment creation
post "/webui/comments/project/BaseDistro/new", {:project => "BaseDistro", :title => "This is a title", :body => "This is a body"}
post "/webui/comments/project/BaseDistro/new", {:project => "BaseDistro", :title => "This is a title", :body => "This is a body", :user => "Admin"}
assert_response :success

# testing empty comments
post "/webui/comments/project/BaseDistro/new", {:project => "BaseDistro", :title => "This is a title"}
post "/webui/comments/project/BaseDistro/new", {:project => "BaseDistro", :title => "This is a title", :user => "Admin"}
assert_response 403

# counter test
get "/webui/comments/project/BaseDistro"
assert_response :success

post "/webui/comments/project/BaseDistro/new", {:project => "BaseDistro", :title => "This is a title"}
assert_response 403
end
end

0 comments on commit 6af9ac8

Please sign in to comment.