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
Stefan Frank 11 years ago
commit 12fedeaf97
  1. 43
      app/controllers/issues/auto_completes_controller.rb
  2. 43
      app/controllers/work_packages/auto_completes_controller.rb
  3. 2
      app/helpers/work_packages_helper.rb
  4. 2
      app/views/issues/bulk_edit.html.erb
  5. 2
      app/views/work_package_relations/_form.html.erb
  6. 8
      app/views/work_packages/auto_completes/index.html.erb
  7. 4
      config/routes.rb
  8. 2
      doc/CHANGELOG.md
  9. 154
      spec/controllers/work_packages/auto_completes_controller_spec.rb
  10. 19
      spec/routing/work_packages_spec.rb
  11. 64
      test/functional/issues/auto_completes_controller_test.rb
  12. 5
      test/integration/routing_test.rb

@ -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

@ -441,7 +441,7 @@ module WorkPackagesHelper
if User.current.allowed_to?(:manage_subtasks, locals[:project])
field = form.text_field :parent_id, :size => 10, :title => l(:description_autocomplete)
field += '<div id="parent_issue_candidates" class="autocomplete"></div>'.html_safe
field += javascript_tag "observeWorkPackageParentField('#{issues_auto_complete_path(:id => work_package, :project_id => locals[:project], :escape => false) }')"
field += javascript_tag "observeWorkPackageParentField('#{work_packages_auto_complete_path(:id => work_package, :project_id => locals[:project], :escape => false) }')"
WorkPackageAttribute.new(:parent_issue, field)
end

@ -76,7 +76,7 @@ See doc/COPYRIGHT.rdoc for more details.
<%= text_field_tag 'issue[parent_id]', '', :size => 10 %>
</p>
<div id="parent_issue_candidates" class="autocomplete"></div>
<%= javascript_tag "observeParentIssueField('#{issues_auto_complete_path }')" %>
<%= javascript_tag "observeParentIssueField('#{work_packages_auto_complete_path(project_id: @project.id)}')" %>
<% end %>
<p>
<label for='issue_start_date'><%= WorkPackage.human_attribute_name(:start_date) %></label>

@ -16,7 +16,7 @@ See doc/COPYRIGHT.rdoc for more details.
<%= f.select :relation_type, collection_for_relation_type_select, {}, :onchange => "setPredecessorFieldsVisibility();" %>
<%= WorkPackage.model_name.human %> #<%= f.text_field :issue_to_id, :size => 10 %>
<div id="related_issue_candidates" class="autocomplete"></div>
<%= javascript_tag "observeRelatedIssueField('#{issues_auto_complete_path(:id => controller.work_package, :project_id => @project, :escape => false) }')" %>
<%= javascript_tag "observeRelatedIssueField('#{work_packages_auto_complete_path(:id => controller.work_package, :project_id => @project, :escape => false) }')" %>
<span id="predecessor_fields" style="display:none;">
<%= IssueRelation.human_attribute_name(:delay) %>: <%= f.text_field :delay, :size => 3 %> <%= l(:label_day_plural) %>
</span>

@ -11,11 +11,11 @@ See doc/COPYRIGHT.rdoc for more details.
++#%>
<ul>
<% if @issues.any? -%>
<% @issues.each do |issue| -%>
<%= content_tag 'li', h("#{issue.type} ##{issue.id}: #{issue.subject}"), :id => issue.id %>
<% if @work_packages.any? -%>
<% @work_packages.each do |work_package| -%>
<%= content_tag 'li', h(work_package.to_s), id: work_package.id %>
<% end -%>
<% else -%>
<%= content_tag("li", l(:label_none), :style => 'display:none') %>
<%= content_tag("li", l(:label_none), style: 'display:none') %>
<% end -%>
</ul>

@ -277,6 +277,10 @@ OpenProject::Application.routes.draw do
end
end
namespace :work_packages do
match 'auto_complete' => 'auto_completes#index', :via => [:get, :post], :format => false
end
resources :work_packages, :only => [:show, :edit, :update, :index] do
get :new_type, :on => :member
put :preview, :on => :member

@ -12,6 +12,8 @@ See doc/COPYRIGHT.rdoc for more details.
# Changelog
* `#2019` Migrate auto completes controller tests
## 3.0.0pre16
* `#1418` Additional changes: Change links to issues/planning elements to use work_packages controller

@ -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

@ -62,19 +62,19 @@ describe WorkPackagesController do
it "should connect GET /work_packages/:work_package_id/moves/new to work_packages/moves#new" do
get("/work_packages/1/move/new").should route_to( :controller => 'work_packages/moves',
:action => 'new',
:work_package_id => '1' )
:action => 'new',
:work_package_id => '1' )
end
it "should connect POST /work_packages/:work_package_id/moves to work_packages/moves#create" do
post("/work_packages/1/move/").should route_to( :controller => 'work_packages/moves',
:action => 'create',
:work_package_id => '1' )
:action => 'create',
:work_package_id => '1' )
end
it "should connect GET /work_packages/moves/new?ids=1,2,3 to work_packages/moves#new" do
get("/work_packages/move/new?ids=1,2,3").should route_to( :controller => 'work_packages/moves',
:action => 'new' )
:action => 'new' )
end
it "should connect POST /work_packages/moves to work_packages/moves#create" do
@ -100,4 +100,13 @@ describe WorkPackagesController do
:project_id => '1' )
end
it "should connect GET /work_packages/auto_completes to work_package/auto_complete#index" do
get("/work_packages/auto_complete").should route_to( controller: 'work_packages/auto_completes',
action: 'index' )
end
it "should connect PUT /work_packages/auto_completes to work_package/auto_complete#index" do
get("/work_packages/auto_complete").should route_to( controller: 'work_packages/auto_completes',
action: 'index' )
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

@ -136,11 +136,6 @@ class RoutingTest < ActionDispatch::IntegrationTest
:action => 'index',
:project_id => 'project-name' )
should route(:get, "/issues/auto_complete").to( :controller => 'issues/auto_completes',
:action => 'issues')
should route(:post, "/issues/auto_complete").to( :controller => 'issues/auto_completes',
:action => 'issues')
should route(:get, "/issues/context_menu").to( :controller => 'issues/context_menus',
:action => 'issues')
should route(:post, "/issues/context_menu").to( :controller => 'issues/context_menus',

Loading…
Cancel
Save