diff --git a/app/controllers/costlog_controller.rb b/app/controllers/costlog_controller.rb index 38a4356272..3d6a4a626a 100644 --- a/app/controllers/costlog_controller.rb +++ b/app/controllers/costlog_controller.rb @@ -170,8 +170,8 @@ private User.find_by_id(user_id) issue_id = params[:cost_entry].delete(:issue_id) - @issue = @cost_entry.present? && @cost_entry.issue_id == issue_id ? - @cost_entry.issue : + @issue = @cost_entry.present? && @cost_entry.work_package_id == issue_id ? + @cost_entry.work_package : Issue.find_by_id(issue_id) cost_type_id = params[:cost_entry].delete(:cost_type_id) @@ -229,7 +229,7 @@ private def new_default_cost_entry @cost_entry = CostEntry.new.tap do |ce| ce.project = @project - ce.issue = @issue + ce.work_package = @issue ce.user = User.current ce.spent_on = Date.today # notice that cost_type is set to default cost_type in the model @@ -238,7 +238,7 @@ private def update_cost_entry_from_params @cost_entry.user = @user - @cost_entry.issue = @issue + @cost_entry.work_package = @issue @cost_entry.cost_type = @cost_type @cost_entry.attributes = permitted_params.cost_entry diff --git a/app/models/cost_entry.rb b/app/models/cost_entry.rb index ca27bc378a..fd1e1e5396 100644 --- a/app/models/cost_entry.rb +++ b/app/models/cost_entry.rb @@ -2,7 +2,7 @@ class CostEntry < ActiveRecord::Base unloadable belongs_to :project - belongs_to :issue + belongs_to :work_package belongs_to :user include ::OpenProject::Costs::DeletedUserFallback belongs_to :cost_type @@ -11,7 +11,7 @@ class CostEntry < ActiveRecord::Base include ActiveModel::ForbiddenAttributesProtection - validates_presence_of :issue_id, :project_id, :user_id, :cost_type_id, :units, :spent_on + validates_presence_of :work_package_id, :project_id, :user_id, :cost_type_id, :units, :spent_on validates_numericality_of :units, :allow_nil => false, :message => :invalid validates_length_of :comments, :maximum => 255, :allow_nil => true @@ -49,13 +49,13 @@ class CostEntry < ActiveRecord::Base end def before_validation - self.project = issue.project if issue && project.nil? + self.project = work_package.project if work_package && project.nil? end def validate errors.add :units, :invalid if units && (units < 0) errors.add :project_id, :invalid if project.nil? - errors.add :issue_id, :invalid if issue.nil? || (project != issue.project) + errors.add :work_package_id, :invalid if work_package.nil? || (project != work_package.project) errors.add :cost_type_id, :invalid if cost_type.present? && cost_type.deleted_at.present? errors.add :user_id, :invalid if project.present? && !project.users.include?(user) && user_id_changed? diff --git a/app/views/costlog/edit.html.erb b/app/views/costlog/edit.html.erb index 5e4108c61b..dc4682dc80 100644 --- a/app/views/costlog/edit.html.erb +++ b/app/views/costlog/edit.html.erb @@ -14,7 +14,7 @@ <%= back_url_hidden_field_tag %>
-

<%= f.text_field :issue_id, :size => 6, :required => true %> <%= h("#{@cost_entry.issue.tracker.name} ##{@cost_entry.issue.id}: #{@cost_entry.issue.subject}") if @cost_entry.issue %>

+

<%= f.text_field :work_package_id, :size => 6, :required => true %> <%= h("#{@cost_entry.work_package.tracker.name} ##{@cost_entry.work_package.id}: #{@cost_entry.work_package.subject}") if @cost_entry.work_package%>

<%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('cost_entry_spent_on') %>

<% if User.current.allowed_to? :log_costs, @project %>

<%= f.select :user_id, user_collection_for_select_options, :required => true %>

diff --git a/lib/open_project/costs/patches/issue_observer.rb b/lib/open_project/costs/patches/issue_observer.rb index e9ac213732..a4a7d45ebb 100644 --- a/lib/open_project/costs/patches/issue_observer.rb +++ b/lib/open_project/costs/patches/issue_observer.rb @@ -7,7 +7,7 @@ class CostsIssueObserver < ActiveRecord::Observer def after_update(issue) if issue.project_id_changed? # TODO: This only works with the global cost_rates - CostEntry.update_all({:project_id => issue.project_id}, {:issue_id => issue.id}) + CostEntry.update_all({:project_id => issue.project_id}, {:work_package_id => issue.id}) end end diff --git a/spec/controllers/costlog_controller_spec.rb b/spec/controllers/costlog_controller_spec.rb index 2ed635cfb3..b398da55c6 100644 --- a/spec/controllers/costlog_controller_spec.rb +++ b/spec/controllers/costlog_controller_spec.rb @@ -10,7 +10,7 @@ describe CostlogController do let (:user2) { FactoryGirl.build(:user) } let (:controller) { FactoryGirl.build(:role, :permissions => [:log_costs, :edit_cost_entries]) } let (:cost_type) { FactoryGirl.build(:cost_type) } - let (:cost_entry) { FactoryGirl.build(:cost_entry, :issue => issue, + let (:cost_entry) { FactoryGirl.build(:cost_entry, :work_package => issue, :project => project, :spent_on => Date.today, :overridden_costs => 400, @@ -35,7 +35,7 @@ describe CostlogController do shared_examples_for "assigns" do it { assigns(:cost_entry).project.should == expected_project } - it { assigns(:cost_entry).issue.should == expected_issue } + it { assigns(:cost_entry).work_package.should == expected_issue } it { assigns(:cost_entry).user.should == expected_user } it { assigns(:cost_entry).spent_on.should == expected_spent_on } it { assigns(:cost_entry).cost_type.should == expected_cost_type } @@ -208,7 +208,7 @@ describe CostlogController do grant_current_user_permissions user, [:edit_cost_entries] cost_entry.project = FactoryGirl.create(:project_with_trackers) - cost_entry.issue = FactoryGirl.create(:issue, :project => cost_entry.project, + cost_entry.work_package = FactoryGirl.create(:issue, :project => cost_entry.project, :tracker => cost_entry.project.trackers.first, :author => user) cost_entry.save! @@ -474,7 +474,7 @@ describe CostlogController do describe "PUT update" do let(:params) { { "id" => cost_entry.id.to_s, "cost_entry" => { "comments" => "lorem", - "issue_id" => cost_entry.issue.id.to_s, + "work_package_id" => cost_entry.work_package.id.to_s, "units" => cost_entry.units.to_s, "spent_on" => cost_entry.spent_on.to_s, "user_id" => cost_entry.user.id.to_s, @@ -484,7 +484,7 @@ describe CostlogController do cost_entry.save(:validate => false) end - let(:expected_issue) { cost_entry.issue } + let(:expected_issue) { cost_entry.work_package } let(:expected_user) { cost_entry.user } let(:expected_project) { cost_entry.project } let(:expected_cost_type) { cost_entry.cost_type } diff --git a/spec/factories/cost_entry_factory.rb b/spec/factories/cost_entry_factory.rb index 66d1d2e5d2..ca0308a4f9 100644 --- a/spec/factories/cost_entry_factory.rb +++ b/spec/factories/cost_entry_factory.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :cost_entry do project user { FactoryGirl.create(:user, :member_in_project => project)} - issue { FactoryGirl.create(:issue, :project => project) } + work_package { FactoryGirl.create(:issue, :project => project) } cost_type spent_on Date.today units 1 diff --git a/spec/models/cost_entry_spec.rb b/spec/models/cost_entry_spec.rb index e86b06e6f6..b0905b5456 100644 --- a/spec/models/cost_entry_spec.rb +++ b/spec/models/cost_entry_spec.rb @@ -18,7 +18,7 @@ describe CostEntry do member FactoryGirl.build(:cost_entry, :cost_type => cost_type, :project => project, - :issue => issue, + :work_package => issue, :spent_on => date, :units => units, :user => user, @@ -28,7 +28,7 @@ describe CostEntry do let(:cost_entry2) do FactoryGirl.build(:cost_entry, :cost_type => cost_type, :project => project, - :issue => issue, + :work_package => issue, :spent_on => date, :units => units, :user => user, @@ -239,20 +239,20 @@ describe CostEntry do cost_entry.project = nil # unfortunately the project get's set to the issue's project if no project is provided # TODO: check if that is necessary - cost_entry.issue = nil + cost_entry.work_package = nil end it { cost_entry.should_not be_valid } end describe "WHEN no issue is provided" do - before { cost_entry.issue = nil } + before { cost_entry.work_package = nil } it { cost_entry.should_not be_valid } end describe "WHEN the issue is not in the project" do - before { cost_entry.issue = issue2 } + before { cost_entry.work_package = issue2 } it { cost_entry.should_not be_valid } end diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 2848465a9f..2aa1b5b60c 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -13,7 +13,7 @@ describe Issue do let(:issue) { FactoryGirl.create(:issue, :project => project, :tracker => project.trackers.first, :author => user) } - let!(:cost_entry) { FactoryGirl.create(:cost_entry, issue: issue, project: project, units: 3, spent_on: Date.today, user: user, comments: "test entry") } + let!(:cost_entry) { FactoryGirl.create(:cost_entry, work_package: issue, project: project, units: 3, spent_on: Date.today, user: user, comments: "test entry") } let!(:cost_object) { FactoryGirl.create(:cost_object, project: project) } before(:each) do diff --git a/spec/models/time_entry_spec.rb b/spec/models/time_entry_spec.rb index a1e7160dfb..f032ee3499 100644 --- a/spec/models/time_entry_spec.rb +++ b/spec/models/time_entry_spec.rb @@ -23,7 +23,7 @@ describe TimeEntry do let(:hours) { 5.0 } let(:time_entry) do FactoryGirl.create(:time_entry, :project => project, - :issue => issue, + :work_package => issue, :spent_on => date, :hours => hours, :user => user, @@ -33,7 +33,7 @@ describe TimeEntry do let(:time_entry2) do FactoryGirl.create(:time_entry, :project => project, - :issue => issue, + :work_package => issue, :spent_on => date, :hours => hours, :user => user, diff --git a/spec/models/user_deletion_spec.rb b/spec/models/user_deletion_spec.rb index 04b9c20d51..72603cf0f0 100644 --- a/spec/models/user_deletion_spec.rb +++ b/spec/models/user_deletion_spec.rb @@ -125,7 +125,7 @@ describe User, "#destroy" do :project => issue.project, :units => 100.0, :spent_on => Date.today, - :issue => issue, + :work_package => issue, :comments => "") } before do