[#4289] Ported the billing plugin's timesheet hooks.

This commit is contained in:
Eric Davis
2010-07-23 10:16:41 -07:00
parent 7192adb231
commit e541270461
14 changed files with 180 additions and 15 deletions
@@ -0,0 +1,26 @@
require File.dirname(__FILE__) + '/../../../../test_helper'
class RedmineRate::Hooks::PluginTimesheetViewTimesheetsReportHeaderTagsTest < ActionController::TestCase
include Redmine::Hook::Helper
def controller
@controller ||= ApplicationController.new
@controller.response ||= ActionController::TestResponse.new
@controller
end
def request
@request ||= ActionController::TestRequest.new
end
def hook(args={})
call_hook :plugin_timesheet_view_timesheets_report_header_tags, args
end
context "#plugin_timesheet_view_timesheets_report_header_tags" do
should "return a css string" do
@response.body = hook
assert_select "style", :text => /missing-rate/
end
end
end
@@ -18,9 +18,9 @@ class RedmineRate::Hooks::PluginTimesheetViewsTimesheetGroupHeaderTest < ActionC
end
context "#plugin_timesheet_views_timesheet_group_header" do
should "return an empty string" do
should "render the cost table header" do
@response.body = hook
assert @response.body.blank?
assert_select "th", :text => "Cost"
end
end
end
@@ -18,9 +18,30 @@ class RedmineRate::Hooks::PluginTimesheetViewsTimesheetTimeEntryTest < ActionCon
end
context "#plugin_timesheet_views_timesheet_time_entry" do
should "return an empty string" do
@response.body = hook
assert @response.body.blank?
context "for users with view rate permission" do
should "render a cost cell showing the cost for the time entry" do
User.current = User.generate!(:admin => true)
rate = Rate.generate!(:amount => 100)
time_entry = TimeEntry.generate!(:hours => 2, :rate => rate)
@response.body = hook(:time_entry => time_entry)
assert_select 'td', :text => "$200.00"
end
end
context "for users without view rate permission" do
should "render an empty cost cell" do
User.current = nil
rate = Rate.generate!(:amount => 100)
time_entry = TimeEntry.generate!(:hours => 2, :rate => rate)
@response.body = hook(:time_entry => time_entry)
assert_select 'td', :text => '&nbsp;'
end
end
end
end
@@ -18,9 +18,31 @@ class RedmineRate::Hooks::PluginTimesheetViewsTimesheetTimeEntrySumTest < Action
end
context "#plugin_timesheet_views_timesheet_time_entry_sum" do
should "return an empty string" do
@response.body = hook
assert @response.body.blank?
context "for users with view rate permission" do
should "render a cost cell showing the total cost for the time entries" do
User.current = User.generate!(:admin => true)
rate = Rate.generate!(:amount => 100)
time_entry1 = TimeEntry.generate!(:hours => 2, :rate => rate)
time_entry2 = TimeEntry.generate!(:hours => 10, :rate => rate)
@response.body = hook(:time_entries => [time_entry1, time_entry2])
assert_select 'td', :text => "$1,200.00"
end
end
context "for users without view rate permission" do
should "render an empty cost cell" do
User.current = nil
rate = Rate.generate!(:amount => 100)
time_entry = TimeEntry.generate!(:hours => 2, :rate => rate)
@response.body = hook(:time_entries => [time_entry])
assert_select 'td', :text => '$0.00'
end
end
end
end
@@ -18,9 +18,43 @@ class RedmineRate::Hooks::PluginTimesheetViewsTimesheetsTimeEntryRowClassTest <
end
context "#plugin_timesheet_views_timesheets_time_entry_row_class" do
should "return an empty string" do
@response.body = hook
assert @response.body.blank?
context "for users with view rate permission" do
setup do
User.current = User.generate!(:admin => true)
end
should "render a missing rate css class if the time entry has no cost" do
time_entry = TimeEntry.generate!(:hours => 2, :rate => nil)
assert_equal "missing-rate", hook(:time_entry => time_entry)
end
should "render nothing if the time entry has a cost" do
rate = Rate.generate!(:amount => 100)
time_entry = TimeEntry.generate!(:hours => 2, :rate => rate)
assert_equal "", hook(:time_entry => time_entry)
end
end
context "for users without view rate permission" do
setup do
User.current = nil
end
should "render nothing if the time entry has no cost" do
time_entry = TimeEntry.generate!(:hours => 2, :rate => nil)
assert_equal "", hook(:time_entry => time_entry)
end
should "render nothing if the time entry has a cost" do
rate = Rate.generate!(:amount => 100)
time_entry = TimeEntry.generate!(:hours => 2, :rate => rate)
assert_equal "", hook(:time_entry => time_entry)
end
end
end
end