pull/6827/head
Hagen Schink 12 years ago
parent d2ed3d0da2
commit 5ec2a40347
  1. 8
      app/controllers/costlog_controller.rb
  2. 8
      app/models/cost_entry.rb
  3. 2
      app/views/costlog/edit.html.erb
  4. 2
      lib/open_project/costs/patches/issue_observer.rb
  5. 10
      spec/controllers/costlog_controller_spec.rb
  6. 2
      spec/factories/cost_entry_factory.rb
  7. 10
      spec/models/cost_entry_spec.rb
  8. 2
      spec/models/issue_spec.rb
  9. 4
      spec/models/time_entry_spec.rb
  10. 2
      spec/models/user_deletion_spec.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

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

@ -14,7 +14,7 @@
<%= back_url_hidden_field_tag %>
<div class="box">
<p><%= f.text_field :issue_id, :size => 6, :required => true %> <em><%= h("#{@cost_entry.issue.tracker.name} ##{@cost_entry.issue.id}: #{@cost_entry.issue.subject}") if @cost_entry.issue %></em></p>
<p><%= f.text_field :work_package_id, :size => 6, :required => true %> <em><%= h("#{@cost_entry.work_package.tracker.name} ##{@cost_entry.work_package.id}: #{@cost_entry.work_package.subject}") if @cost_entry.work_package%></em></p>
<p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('cost_entry_spent_on') %></p>
<% if User.current.allowed_to? :log_costs, @project %>
<p><%= f.select :user_id, user_collection_for_select_options, :required => true %></p>

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

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

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

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

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

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

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

Loading…
Cancel
Save