enables status for issues

pull/243/head
Jens Ulferts 11 years ago
parent 57604d70dd
commit 3c909e6d65
  1. 9
      app/controllers/work_packages_controller.rb
  2. 16
      app/helpers/work_packages_helper.rb
  3. 1
      app/views/work_packages/_attributes.html.erb
  4. 2
      app/views/work_packages/_form.html.erb
  5. 1
      app/views/work_packages/new.html.erb
  6. 41
      spec/controllers/work_packages_controller_spec.rb

@ -61,7 +61,11 @@ class WorkPackagesController < ApplicationController
when PlanningElement.to_s when PlanningElement.to_s
PlanningElement.new :project => project PlanningElement.new :project => project
when Issue.to_s when Issue.to_s
Issue.new :project => project #TODO: generating a new work_package should probably be moved inside work_package
tracker = project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
Issue.new :project => project,
:tracker => tracker
else else
raise ArgumentError, "type #{params[:type]} is not supported" raise ArgumentError, "type #{params[:type]} is not supported"
end end
@ -128,8 +132,7 @@ class WorkPackagesController < ApplicationController
end end
[:changesets, :relations, :priorities].each do |method|
[:changesets, :relations, :allowed_statuses, :priorities].each do |method|
define_method method do define_method method do
[] []
end end

@ -141,13 +141,17 @@ module WorkPackagesHelper
end end
def work_package_form_status_attribute(form, work_package, locals = {}) def work_package_form_status_attribute(form, work_package, locals = {})
field = if locals[:allowed_statuses].any? if work_package.is_a?(Issue)
form.select(:status_id, (locals[:allowed_statuses].map {|p| [p.name, p.id]}), :required => true) allowed = work_package.new_statuses_allowed_to(User.current, true)
else
form.label(:status) + work_package.status.name
end
WorkPackageAttribute.new(:status, field) field = if allowed.any?
form.select(:status_id, (allowed.map {|p| [p.name, p.id]}), :required => true)
else
form.label(:status) + work_package.status.name
end
WorkPackageAttribute.new(:status, field)
end
end end
def work_package_form_priority_attribute(form, work_package, locals = {}) def work_package_form_priority_attribute(form, work_package, locals = {})

@ -12,7 +12,6 @@ See doc/COPYRIGHT.rdoc for more details.
<%= fields_for :work_package, work_package, :builder => TabularFormBuilder do |f| %> <%= fields_for :work_package, work_package, :builder => TabularFormBuilder do |f| %>
<% attributes = work_package_form_two_column_attributes(f, work_package, <% attributes = work_package_form_two_column_attributes(f, work_package,
:allowed_statuses => allowed_statuses,
:priorities => priorities, :priorities => priorities,
:project => project) %> :project => project) %>

@ -15,7 +15,6 @@ See doc/COPYRIGHT.rdoc for more details.
<div id="issue_descr_fields"<% unless work_package.new_record? || work_package.errors.any? %> style="display:none;"<% end %>> <div id="issue_descr_fields"<% unless work_package.new_record? || work_package.errors.any? %> style="display:none;"<% end %>>
<% work_package_form_top_attributes(f, work_package, <% work_package_form_top_attributes(f, work_package,
:allowed_statuses => allowed_statuses,
:priorities => priorities, :priorities => priorities,
:project => project).each do |attribute| %> :project => project).each do |attribute| %>
<p> <p>
@ -29,7 +28,6 @@ See doc/COPYRIGHT.rdoc for more details.
<div id="attributes" class="attributes"> <div id="attributes" class="attributes">
<%= render :partial => 'attributes', :locals => { :work_package => work_package, <%= render :partial => 'attributes', :locals => { :work_package => work_package,
:project => project, :project => project,
:allowed_statuses => allowed_statuses,
:priorities => priorities :priorities => priorities
} %> } %>
</div> </div>

@ -25,7 +25,6 @@ See doc/COPYRIGHT.rdoc for more details.
<%= render :partial => 'form', :locals => { :f => f, <%= render :partial => 'form', :locals => { :f => f,
:work_package => controller.new_work_package, :work_package => controller.new_work_package,
:project => controller.project, :project => controller.project,
:allowed_statuses => controller.allowed_statuses,
:priorities => controller.priorities } %> :priorities => controller.priorities } %>
<%= send_notification_option %> <%= send_notification_option %>
</div> </div>

@ -54,6 +54,10 @@ describe WorkPackagesController do
let(:planning_element) { FactoryGirl.create(:planning_element, :project_id => project.id) } let(:planning_element) { FactoryGirl.create(:planning_element, :project_id => project.id) }
let(:project) { FactoryGirl.create(:project, :identifier => 'test_project', :is_public => false) } let(:project) { FactoryGirl.create(:project, :identifier => 'test_project', :is_public => false) }
let(:stub_planning_element) { FactoryGirl.build_stubbed(:planning_element, :project_id => stub_project.id) }
let(:stub_project) { FactoryGirl.build_stubbed(:project, :identifier => 'test_project', :is_public => false) }
let(:stub_issue) { FactoryGirl.build_stubbed(:issue, :project_id => stub_project.id) }
let(:current_user) { FactoryGirl.create(:user) } let(:current_user) { FactoryGirl.create(:user) }
describe 'show.html' do describe 'show.html' do
@ -223,6 +227,43 @@ describe WorkPackagesController do
it 'should have the project associated' do it 'should have the project associated' do
controller.new_work_package.project.should == project controller.new_work_package.project.should == project
end end
it "should have the project's first tracker assigned tracker is not specified" do
expected_tracker = FactoryGirl.build_stubbed(:tracker)
trackers = double('trackers')
project.stub!(:trackers).and_return(trackers)
trackers.stub!(:find).with(:first).and_return(expected_tracker)
controller.stub!(:project).and_return(project)
controller.new_work_package.tracker.should == expected_tracker
end
it "should have the project's tracker identified by tracker_id param if provided" do
expected_tracker = FactoryGirl.build_stubbed(:tracker)
trackers = double('trackers')
project.stub!(:trackers).and_return(trackers)
trackers.stub!(:find).with('2').and_return(expected_tracker)
controller.params.merge!({ :tracker_id => '2' })
controller.stub!(:project).and_return(project)
controller.new_work_package.tracker.should == expected_tracker
end
it "should have the project's tracker identified by tracker_id param inside issue param if provided" do
expected_tracker = FactoryGirl.build_stubbed(:tracker)
trackers = double('trackers')
project.stub!(:trackers).and_return(trackers)
trackers.stub!(:find).with('2').and_return(expected_tracker)
controller.params.merge!({ :issue => { :tracker_id => '2' } })
controller.stub!(:project).and_return(project)
controller.new_work_package.tracker.should == expected_tracker
end
end end
describe 'when the type is "Project"' do describe 'when the type is "Project"' do

Loading…
Cancel
Save