Merge pull request #165 from abf/rosa-build:42-fix_issues_api

#42 fix rendering
This commit is contained in:
avokhmin 2013-06-17 14:00:56 +04:00
commit 4877edea97
2 changed files with 19 additions and 5 deletions

View File

@ -34,7 +34,6 @@ class Api::V1::IssuesController < Api::V1::BaseController
end end
def show def show
respond_with @issue
end end
def create def create
@ -65,9 +64,9 @@ class Api::V1::IssuesController < Api::V1::BaseController
when 'none' when 'none'
@issues = @issues.where(:assigned_id => nil) @issues = @issues.where(:assigned_id => nil)
when '*' when '*'
@issues = @issues.where('assigned_id IS NOT NULL') @issues = @issues.where('issues.assigned_id IS NOT NULL')
else else
@issues = @issues.where('assignees_issues.uname = ?', params[:assignee]) @issues = @issues.where('issues.assignees_issues.uname = ?', params[:assignee])
end end
end end
@ -92,9 +91,9 @@ class Api::V1::IssuesController < Api::V1::BaseController
direction = params[:direction] == 'asc' ? 'ASC' : 'DESC' direction = params[:direction] == 'asc' ? 'ASC' : 'DESC'
@issues = @issues.order("#{sort} #{direction}") @issues = @issues.order("#{sort} #{direction}")
@issues = @issues.where('created_at >= to_timestamp(?)', params[:since]) if params[:since] =~ /\A\d+\z/ @issues = @issues.where('issues.created_at >= to_timestamp(?)', params[:since]) if params[:since] =~ /\A\d+\z/
@issues.paginate(paginate_params) @issues.paginate(paginate_params)
respond_with @issues render :index
end end
def get_all_project_ids default_project_ids def get_all_project_ids default_project_ids

View File

@ -40,6 +40,11 @@ describe Api::V1::IssuesController do
response.should be_success response.should be_success
end end
it 'should render right template for show action' do
get :show, :project_id => @project.id, :id => @issue.serial_id, :format => :json
response.should render_template('api/v1/issues/show')
end
it 'can show issue in open project' do it 'can show issue in open project' do
get :show, :project_id => @open_project.id, :id => @open_issue.serial_id, :format => :json get :show, :project_id => @open_project.id, :id => @open_issue.serial_id, :format => :json
response.should be_success response.should be_success
@ -62,12 +67,22 @@ describe Api::V1::IssuesController do
assigns[:issues].should include(@membered_issue) assigns[:issues].should include(@membered_issue)
end end
it 'should render right template for all index action' do
get :all_index, :format => :json
response.should render_template('api/v1/issues/index')
end
it 'should return only assigned issue' do it 'should return only assigned issue' do
http_login(@issue.user) http_login(@issue.user)
get :user_index, :format => :json get :user_index, :format => :json
assigns[:issues].should include(@own_hidden_issue) assigns[:issues].should include(@own_hidden_issue)
assigns[:issues].count.should == 1 assigns[:issues].count.should == 1
end end
it 'should render right template for user index action' do
get :user_index, :format => :json
response.should render_template('api/v1/issues/index')
end
end end
context 'for anonymous user' do context 'for anonymous user' do