mirror of
https://github.com/meineerde/redmine.git
synced 2026-01-09 09:01:31 +00:00
Validates that activity belongs to project activities (#19656).
git-svn-id: http://svn.redmine.org/redmine/trunk@14288 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
216a153421
commit
62bed8b93f
@ -116,6 +116,7 @@ class TimeEntry < ActiveRecord::Base
|
||||
errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000)
|
||||
errors.add :project_id, :invalid if project.nil?
|
||||
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
|
||||
errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
|
||||
end
|
||||
|
||||
def hours=(h)
|
||||
|
||||
@ -142,6 +142,14 @@ class TimeEntryTest < ActiveSupport::TestCase
|
||||
assert_equal 1, te.errors.count
|
||||
end
|
||||
|
||||
def test_acitivity_should_belong_to_project_activities
|
||||
activity = TimeEntryActivity.create!(:name => 'Other project activity', :project_id => 2, :active => true)
|
||||
|
||||
entry = TimeEntry.new(:spent_on => Date.today, :hours => 1.0, :user => User.find(1), :project_id => 1, :activity => activity)
|
||||
assert !entry.valid?
|
||||
assert_include I18n.translate('activerecord.errors.messages.inclusion'), entry.errors[:activity_id]
|
||||
end
|
||||
|
||||
def test_spent_on_with_2_digits_year_should_not_be_valid
|
||||
entry = TimeEntry.new(:project => Project.find(1), :user => User.find(1), :activity => TimeEntryActivity.first, :hours => 1)
|
||||
entry.spent_on = "09-02-04"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user