Skip to content

Commit

Permalink
Merge pull request #247 from opf/fix/work_package_form_issue_categories
Browse files Browse the repository at this point in the history
Fix/work package form issue categories
  • Loading branch information
mfrister committed Jul 16, 2013
2 parents 7f2942b + 134f5b3 commit 81592e1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
5 changes: 1 addition & 4 deletions app/controllers/issue_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ def create
redirect_to :controller => '/projects', :action => 'settings', :tab => 'categories', :id => @project
end
format.js do
# IE doesn't support the replace_html rjs method for select box options
render(:update) {|page| page.replace "issue_category_id",
content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
}
render :locals => { :project => @project, :category => @category }
end
end
else
Expand Down
11 changes: 7 additions & 4 deletions app/helpers/work_packages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,15 @@ def work_package_form_responsible_attribute(form, work_package, locals = {})

def work_package_form_issue_category_attribute(form, work_package, locals = {})
unless locals[:project].issue_categories.empty?
field = form.select(:category_id, (locals[:project].issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true)
field = form.select(:category_id,
(locals[:project].issue_categories.collect {|c| [c.name, c.id]}),
:include_blank => true)

field += prompt_to_remote(image_tag('plus.png', :style => 'vertical-align: middle;'),
l(:label_issue_category_new),
t(:label_issue_category_new),
'category[name]',
{:controller => '/issue_categories', :action => 'new', :project_id => project},
:title => l(:label_issue_category_new)) if authorize_for('issue_categories', 'new')
project_issue_categories_path(locals[:project]),
:title => t(:label_issue_category_new)) if authorize_for('issue_categories', 'new')

WorkPackageAttribute.new(:category, field)
end
Expand Down
13 changes: 13 additions & 0 deletions app/views/issue_categories/create.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%#-- 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.

++#%>

jQuery('#work_package_category_id').empty().append("<%= escape_javascript(options_from_collection_for_select(project.issue_categories, 'id', 'name', category.id)) %>");
1 change: 1 addition & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

* `#1391` Opening the new issue form in a project with an issue category defined produces 500 response
* `#1063` Added helper to format the time as a date in the current user or the system time zone
* `#1024` Add 'assign random password' option to user settings

Expand Down
45 changes: 43 additions & 2 deletions spec/helpers/work_packages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
require 'spec_helper'

describe WorkPackagesHelper do


describe :work_package_breadcrumb do
it 'should provide a link to index as the first element and all ancestors as links' do
index_link = double('work_package_index_link')
Expand Down Expand Up @@ -49,4 +47,47 @@
helper.work_package_index_link.should have_selector("a[href='#{issues_path}']", :text => I18n.t(:label_issue_plural))
end
end

describe :work_package_form_issue_category_attribute do
let(:stub_project) { FactoryGirl.build_stubbed(:project) }
let(:stub_work_package) { FactoryGirl.build_stubbed(:planning_element) }
let(:stub_category) { FactoryGirl.build_stubbed(:issue_category) }
let(:form) { double('form', :select => "").as_null_object }

before do
# set sensible defaults
stub!(:authorize_for).and_return(false)
stub_project.stub!(:issue_categories).and_return([stub_category])
end

it "should return nothing if the project has no categories assigned" do
stub_project.stub!(:issue_categories).and_return([])

work_package_form_issue_category_attribute(form, stub_work_package, :project => stub_project).should be_nil
end

it "should have a :category symbol as the attribute" do
work_package_form_issue_category_attribute(form, stub_work_package, :project => stub_project).attribute.should == :category
end

it "should render a select with the project's issue category" do
select = double('select')

form.should_receive(:select).with(:category_id,
[[stub_category.name, stub_category.id]],
:include_blank => true).and_return(select)

work_package_form_issue_category_attribute(form, stub_work_package, :project => stub_project).field.should == select
end

it "should add an additional remote link to create new categories if allowed" do
remote = "remote"

stub!(:authorize_for).and_return(true)

should_receive(:prompt_to_remote).with(*([anything()] * 3), project_issue_categories_path(stub_project), anything()).and_return(remote)

work_package_form_issue_category_attribute(form, stub_work_package, :project => stub_project).field.should include(remote)
end
end
end

0 comments on commit 81592e1

Please sign in to comment.