/
time_entry_patch_test.rb
49 lines (39 loc) · 1.71 KB
/
time_entry_patch_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'test_helper'
class BulkTimeEntryPlugin::Patches::TimeEntryPatchTest < ActiveSupport::TestCase
context "TimeEntry#create_bulk_time_entry" do
setup do
User.current = @user = User.generate_with_protected!
@project = Project.generate!
@role = Role.generate!(:permissions => Redmine::AccessControl.permissions.collect(&:name))
Member.generate!(:project => @project, :roles => [@role], :user_id => @user.id)
@valid_params = {:project_id => @project.id, :hours => 5, :activity_id => TimeEntryActivity.generate!.id, :spent_on => Date.today.to_s}
end
should "return the unsaved TimeEntry if the current user is not allowed to log time to the project" do
@role.update_attributes(:permissions => [])
assert_no_difference('TimeEntry.count') do
@entry = TimeEntry.create_bulk_time_entry(@valid_params)
end
assert_equal false, @entry.valid?
end
context "saving a valid record" do
should "save a new Time Entry record" do
assert_difference('TimeEntry.count') do
@entry = TimeEntry.create_bulk_time_entry(@valid_params)
end
assert @entry.is_a? TimeEntry
end
should "set the project of the new record" do
@entry = TimeEntry.create_bulk_time_entry(@valid_params)
assert_equal @project, @entry.project
end
should "assign the current user" do
@entry = TimeEntry.create_bulk_time_entry(@valid_params)
assert_equal @user, @entry.user
end
should "set hours to nil if they are passed in as 0" do
@entry = TimeEntry.create_bulk_time_entry(@valid_params.merge(:hours => 0))
assert_equal @user, @entry.user
end
end
end
end