Merge pull request #430 from opf/feature/remove_issue_auto_completes_controller
[Feature] Remove issue auto completes controller looks good to me,works&jenkins likes it also.pull/424/merge
commit
12fedeaf97
@ -1,43 +0,0 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Issues::AutoCompletesController < ApplicationController |
||||
before_filter :find_project |
||||
|
||||
def issues |
||||
@issues = [] |
||||
q = params[:q].to_s |
||||
|
||||
if q.present? |
||||
query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? WorkPackage : @project.work_packages |
||||
|
||||
@issues |= query.visible.find_all_by_id(q.to_i) if q =~ /^\d+$/ |
||||
|
||||
@issues |= query.visible.find(:all, |
||||
:limit => 10, |
||||
:order => "#{WorkPackage.table_name}.id ASC", |
||||
:conditions => ["LOWER(#{WorkPackage.table_name}.subject) LIKE :q OR CAST(#{WorkPackage.table_name}.id AS CHAR(13)) LIKE :q", {:q => "%#{q.downcase}%" }]) |
||||
end |
||||
|
||||
render :layout => false |
||||
end |
||||
|
||||
private |
||||
|
||||
def find_project |
||||
project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] |
||||
@project = Project.find(project_id) |
||||
rescue ActiveRecord::RecordNotFound |
||||
render_404 |
||||
end |
||||
|
||||
end |
@ -0,0 +1,43 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class WorkPackages::AutoCompletesController < ApplicationController |
||||
before_filter :find_project |
||||
|
||||
def index |
||||
@work_packages = [] |
||||
q = params[:q].to_s |
||||
|
||||
if q.present? |
||||
query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? WorkPackage : @project.work_packages |
||||
|
||||
@work_packages |= query.visible.find_all_by_id(q.to_i) if q =~ /^\d+$/ |
||||
|
||||
@work_packages |= query.visible.find(:all, |
||||
limit: 10, |
||||
order: "#{WorkPackage.table_name}.id ASC", |
||||
conditions: ["LOWER(#{WorkPackage.table_name}.subject) LIKE :q OR CAST(#{WorkPackage.table_name}.id AS CHAR(13)) LIKE :q", {q: "%#{q.downcase}%" }]) |
||||
end |
||||
|
||||
render layout: false |
||||
end |
||||
|
||||
private |
||||
|
||||
def find_project |
||||
project_id = (params[:work_package] && params[:work_package][:project_id]) || params[:project_id] |
||||
@project = Project.find(project_id) |
||||
rescue ActiveRecord::RecordNotFound |
||||
render_404 |
||||
end |
||||
|
||||
end |
@ -0,0 +1,154 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe WorkPackages::AutoCompletesController do |
||||
let(:user) { FactoryGirl.create(:user) } |
||||
let(:project) { FactoryGirl.create(:project) } |
||||
let(:role) { FactoryGirl.create(:role, |
||||
permissions: [:view_work_packages]) } |
||||
let(:member) { FactoryGirl.create(:member, |
||||
project: project, |
||||
principal: user, |
||||
roles: [role]) } |
||||
let(:work_package_1) { FactoryGirl.create(:work_package, |
||||
id: 21, |
||||
subject: "Can't print recipes", |
||||
project: project) } |
||||
let(:work_package_2) { FactoryGirl.create(:work_package, |
||||
id: 2101, |
||||
subject: "Error 281 when updating a recipe", |
||||
project: project) } |
||||
let(:work_package_3) { FactoryGirl.create(:work_package, |
||||
id: 2102, |
||||
project: project) } |
||||
|
||||
before do |
||||
member |
||||
|
||||
User.stub(:current).and_return user |
||||
|
||||
work_package_1 |
||||
work_package_2 |
||||
work_package_3 |
||||
end |
||||
|
||||
shared_examples_for "successful response" do |
||||
subject { response } |
||||
|
||||
it { should be_success } |
||||
end |
||||
|
||||
shared_examples_for "contains expected values" do |
||||
subject { assigns(:work_packages) } |
||||
|
||||
it { should include(*expected_values) } |
||||
end |
||||
|
||||
describe :work_packages do |
||||
describe "search is case insensitive" do |
||||
let(:expected_values) { [work_package_1, work_package_2] } |
||||
|
||||
before { get :index, |
||||
project_id: project.id, |
||||
q: 'ReCiPe' } |
||||
|
||||
it_behaves_like "successful response" |
||||
|
||||
it_behaves_like "contains expected values" |
||||
end |
||||
|
||||
describe "returns work package for given id" do |
||||
let(:expected_values) { work_package_1 } |
||||
|
||||
before { get :index, |
||||
project_id: project.id, |
||||
q: work_package_1.id } |
||||
|
||||
it_behaves_like "successful response" |
||||
|
||||
it_behaves_like "contains expected values" |
||||
end |
||||
|
||||
describe "returns work package for given id" do |
||||
let(:expected_values) { [work_package_1, work_package_2, work_package_3] } |
||||
let(:ids) { '21' } |
||||
|
||||
before { get :index, |
||||
project_id: project.id, |
||||
q: ids } |
||||
|
||||
it_behaves_like "successful response" |
||||
|
||||
it_behaves_like "contains expected values" |
||||
|
||||
context :uniq do |
||||
let(:assigned) { assigns(:work_packages) } |
||||
|
||||
subject { assigned.size } |
||||
|
||||
it { should eq(assigned.uniq.size) } |
||||
end |
||||
end |
||||
|
||||
describe :cross_project_issue_relations do |
||||
let(:project_2) { FactoryGirl.create(:project, |
||||
parent: project) } |
||||
let(:member_2) { FactoryGirl.create(:member, |
||||
project: project_2, |
||||
principal: user, |
||||
roles: [role]) } |
||||
let(:work_package_4) { FactoryGirl.create(:work_package, |
||||
project: project_2) } |
||||
|
||||
before do |
||||
member_2 |
||||
|
||||
work_package_4 |
||||
end |
||||
|
||||
context "with scope all and cross project relations" do |
||||
let(:expected_values) { work_package_4 } |
||||
|
||||
before do |
||||
Setting.stub(:cross_project_issue_relations?).and_return(true) |
||||
|
||||
get :index, |
||||
project_id: project.id, |
||||
q: work_package_4.id, |
||||
scope: 'all' |
||||
end |
||||
|
||||
it_behaves_like "successful response" |
||||
|
||||
it_behaves_like "contains expected values" |
||||
end |
||||
|
||||
context "with scope all but w/o cross project relations" do |
||||
before do |
||||
Setting.stub(:cross_project_issue_relations?).and_return(false) |
||||
|
||||
get :index, |
||||
project_id: project.id, |
||||
q: work_package_4.id, |
||||
scope: 'all' |
||||
end |
||||
|
||||
it_behaves_like "successful response" |
||||
|
||||
subject { assigns(:work_packages) } |
||||
|
||||
it { should eq([]) } |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,64 +0,0 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__) |
||||
|
||||
class Issues::AutoCompletesControllerTest < ActionController::TestCase |
||||
fixtures :all |
||||
|
||||
def test_issues_should_not_be_case_sensitive |
||||
get :issues, :project_id => 'ecookbook', :q => 'ReCiPe' |
||||
assert_response :success |
||||
assert_not_nil assigns(:issues) |
||||
assert assigns(:issues).detect {|issue| issue.subject.match /recipe/} |
||||
end |
||||
|
||||
def test_issues_should_return_issue_with_given_id |
||||
get :issues, :project_id => 'subproject1', :q => '13' |
||||
assert_response :success |
||||
assert_not_nil assigns(:issues) |
||||
assert assigns(:issues).include?(WorkPackage.find(13)) |
||||
end |
||||
|
||||
test 'should return issues matching a given id' do |
||||
@project = Project.find('subproject1') |
||||
@issue_21 = FactoryGirl.create(:work_package, project: @project, :id => 21) |
||||
@issue_2101 = FactoryGirl.create(:work_package, project: @project, :id => 2101) |
||||
@issue_2102 = FactoryGirl.create(:work_package, project: @project, :id => 2102) |
||||
@issue_with_subject = FactoryGirl.create(:work_package, project: @project, :subject => 'This has 21 in the subject') |
||||
|
||||
get :issues, :project_id => @project.id, :q => '21' |
||||
|
||||
assert_response :success |
||||
assert_not_nil assigns(:issues) |
||||
assert assigns(:issues).include?(@issue_21) |
||||
assert assigns(:issues).include?(@issue_2101) |
||||
assert assigns(:issues).include?(@issue_2102) |
||||
assert assigns(:issues).include?(@issue_with_subject) |
||||
assert_equal assigns(:issues).size, assigns(:issues).uniq.size, "Issues list includes duplicates" |
||||
end |
||||
|
||||
def test_auto_complete_with_scope_all_and_cross_project_relations |
||||
Setting.cross_project_issue_relations = '1' |
||||
get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all' |
||||
assert_response :success |
||||
assert_not_nil assigns(:issues) |
||||
assert assigns(:issues).include?(WorkPackage.find(13)) |
||||
end |
||||
|
||||
def test_auto_complete_with_scope_all_without_cross_project_relations |
||||
Setting.cross_project_issue_relations = '0' |
||||
get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all' |
||||
assert_response :success |
||||
assert_equal [], assigns(:issues) |
||||
end |
||||
end |
Loading…
Reference in new issue