Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api] add routes to get XML view of comments
issue 545
- Loading branch information
1 parent
1fd5a65
commit ba64d2f
Showing
8 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class CommentsController < ApplicationController | ||
|
||
before_filter :find_request, only: [:show_request_comments] | ||
|
||
def find_request | ||
@obj = BsRequest.find(params[:id]) | ||
end | ||
|
||
def show_request_comments | ||
show_comments | ||
end | ||
|
||
before_filter :find_package, only: [:show_package_comments] | ||
|
||
def find_package | ||
@obj = Package.get_by_project_and_name(params[:project], params[:package]) | ||
end | ||
|
||
def show_package_comments | ||
show_comments | ||
end | ||
|
||
before_filter :find_project, only: [:show_project_comments] | ||
|
||
def find_project | ||
@obj = Project.get_by_name(params[:project]) | ||
end | ||
|
||
def show_project_comments | ||
show_comments | ||
end | ||
|
||
def show_comments | ||
@comments = @obj.comments.order(:id) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
comments.each do |c| | ||
c.to_xml(builder) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
xml.comments(project: @obj.project.name, package: @obj.name) do | ||
render(partial: 'comments', locals: { builder: xml, comments: @comments }) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
xml.comments(project: @obj.name) do | ||
render(partial: 'comments', locals: { builder: xml, comments: @comments }) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
xml.comments(request: @obj.id) do | ||
render(partial: 'comments', locals: { builder: xml, comments: @comments }) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require_relative '../test_helper' | ||
|
||
class CommentsControllerTest < ActionDispatch::IntegrationTest | ||
|
||
test 'package comments' do | ||
get comments_package_path(project: 'BaseDistro3', package: 'pack2') | ||
assert_response 401 | ||
|
||
login_tom | ||
get comments_package_path(project: 'BaseDistro3', package: 'pack2') | ||
assert_response :success | ||
|
||
assert_xml_tag tag: 'comment', attributes: { who: 'tom' } | ||
|
||
end | ||
|
||
test 'hidden project comments' do | ||
login_tom | ||
get comments_project_path(project: 'HiddenProject') | ||
assert_response 404 # huh? Nothing here | ||
|
||
prepare_request_with_user "hidden_homer", "homer" | ||
get comments_project_path(project: 'HiddenProject') | ||
assert_response :success | ||
end | ||
|
||
test 'show request comments' do | ||
login_tom | ||
get comments_request_path(id: 4) | ||
assert_response :success | ||
assert_xml_tag tag: 'comment', attributes: { who: 'tom', parent: '300' } | ||
|
||
end | ||
end |