assigns planning element attributes on work_package creation

pull/243/head
Jens Ulferts 11 years ago
parent d23fbf13e4
commit b38c37f9f5
  1. 4
      app/controllers/work_packages_controller.rb
  2. 4
      app/models/project.rb
  3. 14
      spec/models/project_spec.rb

@ -72,7 +72,7 @@ class WorkPackagesController < ApplicationController
def new_work_package
@new_work_package ||= begin
type = params[:type] || (params[:work_package] && params[:work_package][:type])
type = params.delete(:type) || (params[:work_package] && params[:work_package].delete(:type)) || 'Issue'
if params[:work_package]
params[:work_package][:author] = current_user
@ -80,7 +80,7 @@ class WorkPackagesController < ApplicationController
wp = case type
when PlanningElement.to_s
project.add_planning_element(params[:work_package]) #TODO: StrongParameters
project.add_planning_element(params[:work_package].permit!) #TODO: StrongParameters
when Issue.to_s
project.add_issue(params[:work_package]) #TODO: StrongParameters
else

@ -878,7 +878,9 @@ class Project < ActiveRecord::Base
def add_planning_element(attributes = {})
attributes ||= {}
self.planning_elements.build
self.planning_elements.build do |pe|
pe.attributes = attributes
end
end
# TODO: merge with add_planning_elemement once tracker or similar is defined there and safe_attributes is removed

@ -64,6 +64,18 @@ describe Project do
it 'should have the project associated' do
project.add_planning_element.project.should == project
end
it 'should assign the attributes' do
attributes = { :blubs => double('blubs') }
new_pe = FactoryGirl.build_stubbed(:planning_element)
project.planning_elements.should_receive(:build).and_yield(new_pe)
new_pe.should_receive(:attributes=).with(attributes)
project.add_planning_element(attributes)
end
end
describe "add_issue" do
@ -112,7 +124,7 @@ describe Project do
attributes = { :blubs => double('blubs') }
new_issue = FactoryGirl.build_stubbed(:issue)
new_issue.should_receive(:safe_attributes=).with(attributes)
new_issue.should_receive(:assign_attributes).with(attributes, :without_protection => true)
Issue.stub!(:new).and_yield(new_issue)

Loading…
Cancel
Save