timesheet_plugin 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYRIGHT.txt +16 -0
- data/CREDITS.txt +21 -0
- data/GPL.txt +339 -0
- data/README.rdoc +56 -0
- data/Rakefile +33 -0
- data/VERSION +1 -0
- data/app/controllers/timesheet_controller.rb +145 -0
- data/app/helpers/timesheet_helper.rb +42 -0
- data/app/models/timesheet.rb +277 -0
- data/app/views/settings/_timesheet_settings.rhtml +4 -0
- data/app/views/timesheet/_by_issue.rhtml +35 -0
- data/app/views/timesheet/_form.rhtml +90 -0
- data/app/views/timesheet/_issue_time_entries.rhtml +43 -0
- data/app/views/timesheet/_time_entry.rhtml +31 -0
- data/app/views/timesheet/_timesheet_group.rhtml +21 -0
- data/app/views/timesheet/context_menu.html.erb +4 -0
- data/app/views/timesheet/index.rhtml +11 -0
- data/app/views/timesheet/no_projects.rhtml +5 -0
- data/app/views/timesheet/report.rhtml +52 -0
- data/app/views/timesheet/timelog.rhtml +5 -0
- data/assets/images/toggle-arrow-closed.gif +0 -0
- data/assets/images/toggle-arrow-open.gif +0 -0
- data/config/locales/ca.yml +9 -0
- data/config/locales/cs.yml +7 -0
- data/config/locales/da.yml +10 -0
- data/config/locales/de.yml +10 -0
- data/config/locales/en.yml +10 -0
- data/config/locales/es.yml +9 -0
- data/config/locales/fr.yml +10 -0
- data/config/locales/hu.yml +10 -0
- data/config/locales/it.yml +7 -0
- data/config/locales/lt.yml +9 -0
- data/config/locales/pl.yml +10 -0
- data/config/locales/ru.yml +9 -0
- data/init.rb +2 -0
- data/lang/ca.yml +8 -0
- data/lang/cs.yml +6 -0
- data/lang/da.yml +9 -0
- data/lang/de.yml +9 -0
- data/lang/en.yml +9 -0
- data/lang/es.yml +8 -0
- data/lang/fr.yml +9 -0
- data/lang/hu.yml +9 -0
- data/lang/it.yml +6 -0
- data/lang/lt.yml +8 -0
- data/lang/pl.yml +9 -0
- data/lang/ru.yml +8 -0
- data/lib/tasks/plugin_stat.rake +38 -0
- data/lib/timesheet_compatibility.rb +14 -0
- data/rails/init.rb +29 -0
- data/spec/controllers/timesheet_controller_spec.rb +263 -0
- data/spec/models/timesheet_spec.rb +537 -0
- data/spec/sanity_spec.rb +7 -0
- data/spec/spec_helper.rb +40 -0
- metadata +107 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
fr:
|
2
|
+
timesheet_title: Feuille de temps
|
3
|
+
timesheet_date_from_label: De
|
4
|
+
timesheet_date_to_label: A
|
5
|
+
timesheet_project_label: Projet
|
6
|
+
timesheet_activities_label: Activite
|
7
|
+
timesheet_users_label: Utilisateurs
|
8
|
+
timesheet_showing_users: 'showing time for: '
|
9
|
+
timesheet_permalink: '(Permalink to this timesheet)'
|
10
|
+
timesheet_group_by: Group by
|
@@ -0,0 +1,10 @@
|
|
1
|
+
hu:
|
2
|
+
timesheet_title: Időlap
|
3
|
+
timesheet_date_from_label: Kezdő dátum
|
4
|
+
timesheet_date_to_label: Vég dátum
|
5
|
+
timesheet_project_label: Projekt
|
6
|
+
timesheet_activities_label: Aktivitás
|
7
|
+
timesheet_users_label: Felhasználók
|
8
|
+
timesheet_showing_users: 'mutatás ettől a felhasználótól: '
|
9
|
+
timesheet_permalink: '(Permalink erre az időlapra)'
|
10
|
+
timesheet_group_by: Csoportosítás
|
@@ -0,0 +1,9 @@
|
|
1
|
+
lt:
|
2
|
+
timesheet_title: Sunaudoto laiko suvestinė lentelė
|
3
|
+
timesheet_date_from_label: Pradedant nuo
|
4
|
+
timesheet_date_to_label: iki
|
5
|
+
timesheet_project_label: Projektas
|
6
|
+
timesheet_activities_label: Aktivumas
|
7
|
+
timesheet_users_label: Vartotojai
|
8
|
+
timesheet_permalink: '(Pastovi nuoroda į šį lentelę)'
|
9
|
+
timesheet_group_by: Grupuoti pagal
|
@@ -0,0 +1,10 @@
|
|
1
|
+
pl:
|
2
|
+
timesheet_title: Czas Pracy
|
3
|
+
timesheet_date_from_label: Od
|
4
|
+
timesheet_date_to_label: Do
|
5
|
+
timesheet_project_label: Projekt
|
6
|
+
timesheet_activities_label: Aktywności
|
7
|
+
timesheet_users_label: Użytkownicy
|
8
|
+
timesheet_showing_users: 'czas pracy użytkownika: '
|
9
|
+
timesheet_permalink: '(Permalink do tego czasu pracy)'
|
10
|
+
timesheet_group_by: Grupuj
|
@@ -0,0 +1,9 @@
|
|
1
|
+
ru:
|
2
|
+
timesheet_title: Сводная таблица затраченного времени
|
3
|
+
timesheet_date_from_label: Начиная с
|
4
|
+
timesheet_date_to_label: по
|
5
|
+
timesheet_project_label: Проект
|
6
|
+
timesheet_activities_label: Активность
|
7
|
+
timesheet_users_label: Пользователи
|
8
|
+
timesheet_permalink: '(Постоянная ссылка на эту таблицу)'
|
9
|
+
timesheet_group_by: Группировать по
|
data/init.rb
ADDED
data/lang/ca.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
timesheet_title: Full de temps
|
2
|
+
timesheet_date_from_label: De
|
3
|
+
timesheet_date_to_label: A
|
4
|
+
timesheet_project_label: Projecte
|
5
|
+
timesheet_activities_label: Activitat
|
6
|
+
timesheet_users_label: Usuaris
|
7
|
+
timesheet_showing_users: 'mostrant temps per a: '
|
8
|
+
timesheet_permalink: "(Enllaç permanent a aquest full de temps)"
|
data/lang/cs.yml
ADDED
data/lang/da.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
timesheet_title: Timeseddel
|
2
|
+
timesheet_date_from_label: Fra
|
3
|
+
timesheet_date_to_label: Til
|
4
|
+
timesheet_project_label: Projekt
|
5
|
+
timesheet_activities_label: Aktivitet
|
6
|
+
timesheet_users_label: Brugere
|
7
|
+
timesheet_showing_users: 'viser tidsregistreringer for: '
|
8
|
+
timesheet_permalink: '(Permanent link til denne timeseddel)'
|
9
|
+
timesheet_group_by: Gruppér efter
|
data/lang/de.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
timesheet_title: Stundenzettel
|
2
|
+
timesheet_date_from_label: Von
|
3
|
+
timesheet_date_to_label: Bis
|
4
|
+
timesheet_project_label: Projekt
|
5
|
+
timesheet_activities_label: Aktivität
|
6
|
+
timesheet_users_label: Benutzer
|
7
|
+
timesheet_showing_users: 'zeige Zeit für: '
|
8
|
+
timesheet_permalink: '(Permalink zu diesem Stundenzettel)'
|
9
|
+
timesheet_group_by: Gruppiere nach
|
data/lang/en.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
timesheet_title: Timesheet
|
2
|
+
timesheet_date_from_label: From
|
3
|
+
timesheet_date_to_label: To
|
4
|
+
timesheet_project_label: Project
|
5
|
+
timesheet_activities_label: Activity
|
6
|
+
timesheet_users_label: Users
|
7
|
+
timesheet_showing_users: 'showing time for: '
|
8
|
+
timesheet_permalink: '(Permalink to this timesheet)'
|
9
|
+
timesheet_group_by: Group by
|
data/lang/es.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
timesheet_title: Hoja de tiempos
|
2
|
+
timesheet_date_from_label: De
|
3
|
+
timesheet_date_to_label: A
|
4
|
+
timesheet_project_label: Proyecto
|
5
|
+
timesheet_activities_label: Actividad
|
6
|
+
timesheet_users_label: Usuarios
|
7
|
+
timesheet_showing_users: 'mostrando tiempos para: '
|
8
|
+
timesheet_permalink: '(Permalink a esta hoja de tiempos)'
|
data/lang/fr.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
timesheet_title: Feuille de temps
|
2
|
+
timesheet_date_from_label: De
|
3
|
+
timesheet_date_to_label: A
|
4
|
+
timesheet_project_label: Projet
|
5
|
+
timesheet_activities_label: Activite
|
6
|
+
timesheet_users_label: Utilisateurs
|
7
|
+
timesheet_showing_users: 'showing time for: '
|
8
|
+
timesheet_permalink: '(Permalink to this timesheet)'
|
9
|
+
timesheet_group_by: Group by
|
data/lang/hu.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
timesheet_title: Időlap
|
2
|
+
timesheet_date_from_label: Kezdő dátum
|
3
|
+
timesheet_date_to_label: Vég dátum
|
4
|
+
timesheet_project_label: Projekt
|
5
|
+
timesheet_activities_label: Aktivitás
|
6
|
+
timesheet_users_label: Felhasználók
|
7
|
+
timesheet_showing_users: 'mutatás ettől a felhasználótól: '
|
8
|
+
timesheet_permalink: '(Permalink erre az időlapra)'
|
9
|
+
timesheet_group_by: Csoportosítás
|
data/lang/it.yml
ADDED
data/lang/lt.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
timesheet_title: Sunaudoto laiko suvestinė lentelė
|
2
|
+
timesheet_date_from_label: Pradedant nuo
|
3
|
+
timesheet_date_to_label: iki
|
4
|
+
timesheet_project_label: Projektas
|
5
|
+
timesheet_activities_label: Aktivumas
|
6
|
+
timesheet_users_label: Vartotojai
|
7
|
+
timesheet_permalink: '(Pastovi nuoroda į šį lentelę)'
|
8
|
+
timesheet_group_by: Grupuoti pagal
|
data/lang/pl.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
timesheet_title: Czas Pracy
|
2
|
+
timesheet_date_from_label: Od
|
3
|
+
timesheet_date_to_label: Do
|
4
|
+
timesheet_project_label: Projekt
|
5
|
+
timesheet_activities_label: Aktywności
|
6
|
+
timesheet_users_label: Użytkownicy
|
7
|
+
timesheet_showing_users: 'czas pracy użytkownika: '
|
8
|
+
timesheet_permalink: '(Permalink do tego czasu pracy)'
|
9
|
+
timesheet_group_by: Grupuj
|
data/lang/ru.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
timesheet_title: Сводная таблица затраченного времени
|
2
|
+
timesheet_date_from_label: Начиная с
|
3
|
+
timesheet_date_to_label: по
|
4
|
+
timesheet_project_label: Проект
|
5
|
+
timesheet_activities_label: Активность
|
6
|
+
timesheet_users_label: Пользователи
|
7
|
+
timesheet_permalink: '(Постоянная ссылка на эту таблицу)'
|
8
|
+
timesheet_group_by: Группировать по
|
@@ -0,0 +1,38 @@
|
|
1
|
+
namespace :spec do
|
2
|
+
task :statsetup do
|
3
|
+
require 'code_statistics'
|
4
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
|
5
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
|
6
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
|
7
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
|
8
|
+
::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
|
9
|
+
::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
|
10
|
+
::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration')
|
11
|
+
::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
|
12
|
+
::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
|
13
|
+
::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
|
14
|
+
::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
|
15
|
+
::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
|
16
|
+
::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
|
17
|
+
::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
STATS_DIRECTORIES = [
|
23
|
+
%w(Controllers app/controllers),
|
24
|
+
%w(Helpers app/helpers),
|
25
|
+
%w(Models app/models),
|
26
|
+
%w(Libraries lib/),
|
27
|
+
%w(APIs app/apis),
|
28
|
+
%w(Integration\ tests test/integration),
|
29
|
+
%w(Functional\ tests test/functional),
|
30
|
+
%w(Unit\ tests test/unit)
|
31
|
+
|
32
|
+
].collect { |name, dir| [ name, "./#{dir}" ] }.select { |name, dir| File.directory?(dir) }
|
33
|
+
|
34
|
+
desc "Report code statistics (KLOCs, etc) from the application"
|
35
|
+
task :stats do
|
36
|
+
require 'code_statistics'
|
37
|
+
CodeStatistics.new(*STATS_DIRECTORIES).to_s
|
38
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Wrappers around the Redmine core API changes between versions
|
2
|
+
module TimesheetCompatibility
|
3
|
+
class Enumeration
|
4
|
+
# Wrapper around Redmine's API since Enumerations changed in r2472
|
5
|
+
# This can be removed once 0.9.0 is stable
|
6
|
+
def self.activities
|
7
|
+
if ::Enumeration.respond_to?(:activities)
|
8
|
+
return ::Enumeration.activities
|
9
|
+
else
|
10
|
+
return ::Enumeration::get_values('ACTI')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'redmine'
|
2
|
+
|
3
|
+
unless Redmine::Plugin.registered_plugins.keys.include?(:timesheet_plugin)
|
4
|
+
Redmine::Plugin.register :timesheet_plugin do
|
5
|
+
name 'Timesheet Plugin'
|
6
|
+
author 'Eric Davis of Little Stream Software'
|
7
|
+
description 'This is a Timesheet plugin for Redmine to show timelogs for all projects'
|
8
|
+
url 'https://projects.littlestreamsoftware.com/projects/redmine-timesheet'
|
9
|
+
author_url 'http://www.littlestreamsoftware.com'
|
10
|
+
|
11
|
+
version '0.5.0'
|
12
|
+
requires_redmine :version_or_higher => '0.8.0'
|
13
|
+
|
14
|
+
settings :default => {'list_size' => '5', 'precision' => '2'}, :partial => 'settings/timesheet_settings'
|
15
|
+
|
16
|
+
permission :see_project_timesheets, { }, :require => :member
|
17
|
+
|
18
|
+
menu(:top_menu,
|
19
|
+
:timesheet,
|
20
|
+
{:controller => 'timesheet', :action => 'index'},
|
21
|
+
:caption => :timesheet_title,
|
22
|
+
:if => Proc.new {
|
23
|
+
User.current.allowed_to?(:see_project_timesheets, nil, :global => true) ||
|
24
|
+
User.current.allowed_to?(:view_time_entries, nil, :global => true) ||
|
25
|
+
User.current.admin?
|
26
|
+
})
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,263 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module TimesheetControllerHelper
|
4
|
+
# Sets up the default mocks
|
5
|
+
def default_mocks(options = {})
|
6
|
+
# User
|
7
|
+
@current_user = mock_model(User)
|
8
|
+
@current_user.stub!(:admin?).and_return(false)
|
9
|
+
@user_project_mock = mock_model(Project)
|
10
|
+
@user_project_mock.stub!(:find).and_return([ ])
|
11
|
+
@current_user.stub!(:projects).and_return(@user_project_mock)
|
12
|
+
stub_current_user
|
13
|
+
|
14
|
+
# Redmine application controller
|
15
|
+
controller.stub!(:check_if_login_required).and_return(true)
|
16
|
+
controller.stub!(:set_localization)
|
17
|
+
|
18
|
+
# Timesheet
|
19
|
+
@timesheet = mock_model(Timesheet)
|
20
|
+
@timesheet.stub!(:projects).and_return([ ])
|
21
|
+
@timesheet.stub!(:projects=)
|
22
|
+
@timesheet.stub!(:allowed_projects).and_return(['not empty'])
|
23
|
+
@timesheet.stub!(:allowed_projects=)
|
24
|
+
@timesheet.stub!(:date_from)
|
25
|
+
@timesheet.stub!(:date_from=)
|
26
|
+
@timesheet.stub!(:date_to)
|
27
|
+
@timesheet.stub!(:date_to=)
|
28
|
+
@timesheet.stub!(:activities)
|
29
|
+
@timesheet.stub!(:activities=)
|
30
|
+
@timesheet.stub!(:users)
|
31
|
+
@timesheet.stub!(:users=)
|
32
|
+
@timesheet.stub!(:fetch_time_entries)
|
33
|
+
@timesheet.stub!(:time_entries).and_return([ ])
|
34
|
+
@timesheet.stub!(:sort)
|
35
|
+
@timesheet.stub!(:sort=)
|
36
|
+
@timesheet.stub!(:period_type=)
|
37
|
+
stub_timesheet unless options[:skip_timesheet_stub]
|
38
|
+
end
|
39
|
+
|
40
|
+
# Converts current user to admin
|
41
|
+
def mock_admin
|
42
|
+
@current_user.stub!(:admin?).and_return(true)
|
43
|
+
stub_current_user
|
44
|
+
end
|
45
|
+
|
46
|
+
# Restubs the current user
|
47
|
+
def stub_current_user
|
48
|
+
User.stub!(:current).and_return(@current_user)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Restubs the new timesheet
|
52
|
+
def stub_timesheet
|
53
|
+
Timesheet.stub!(:new).and_return(@timesheet)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'TimesheetControllerShared', :shared => true do
|
58
|
+
it 'should set @timesheet.allowed_projects to the list of current projects the user is a member of' do
|
59
|
+
project1 = mock_model(Project)
|
60
|
+
project2 = mock_model(Project)
|
61
|
+
projects = [project1, project2]
|
62
|
+
|
63
|
+
# Adjust mocks
|
64
|
+
@user_project_mock.should_receive(:find).and_return(projects)
|
65
|
+
stub_current_user
|
66
|
+
@timesheet.should_receive(:allowed_projects=).with(projects)
|
67
|
+
@timesheet.stub!(:allowed_projects).and_return(projects)
|
68
|
+
stub_timesheet
|
69
|
+
|
70
|
+
send_request
|
71
|
+
assigns[:timesheet].allowed_projects.should eql(projects)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should set @timesheet.allowed_projects to all the projects if the user is an admin' do
|
75
|
+
mock_admin
|
76
|
+
project1 = mock_model(Project)
|
77
|
+
project2 = mock_model(Project)
|
78
|
+
projects = [project1, project2]
|
79
|
+
|
80
|
+
# Adjust mocks
|
81
|
+
Project.stub!(:find).with(:all, { :order => "name ASC" }).and_return(projects)
|
82
|
+
@timesheet.should_receive(:allowed_projects=).with(projects)
|
83
|
+
@timesheet.stub!(:allowed_projects).and_return(projects)
|
84
|
+
stub_timesheet
|
85
|
+
|
86
|
+
send_request
|
87
|
+
assigns[:timesheet].allowed_projects.should eql(projects)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should get the list size from the settings' do
|
91
|
+
settings = { 'list_size' => 10, 'precision' => '2' }
|
92
|
+
Setting.should_receive(:plugin_timesheet_plugin).twice.and_return(settings)
|
93
|
+
|
94
|
+
send_request
|
95
|
+
assigns[:list_size].should eql(10)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should get the precision from the settings' do
|
99
|
+
settings = { 'list_size' => 10, 'precision' => '2' }
|
100
|
+
Setting.should_receive(:plugin_timesheet_plugin).twice.and_return(settings)
|
101
|
+
|
102
|
+
send_request
|
103
|
+
assigns[:precision].should eql(2)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should create a new @timesheet' do
|
107
|
+
Timesheet.should_receive(:new).and_return(@timesheet)
|
108
|
+
|
109
|
+
send_request
|
110
|
+
assigns[:timesheet].should eql(@timesheet)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
describe TimesheetController do
|
116
|
+
it "should use TimesheetController" do
|
117
|
+
controller.should be_an_instance_of(TimesheetController)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
describe TimesheetController,"#index with GET request" do
|
122
|
+
include TimesheetControllerHelper
|
123
|
+
|
124
|
+
def send_request
|
125
|
+
get 'index'
|
126
|
+
end
|
127
|
+
|
128
|
+
before(:each) do
|
129
|
+
default_mocks
|
130
|
+
end
|
131
|
+
|
132
|
+
it_should_behave_like "TimesheetControllerShared"
|
133
|
+
|
134
|
+
it 'should have no timelog entries' do
|
135
|
+
get 'index'
|
136
|
+
assigns[:timesheet].time_entries.should be_empty
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should render the index template' do
|
140
|
+
get 'index'
|
141
|
+
response.should render_template('index')
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe TimesheetController,"#index with GET request and a session" do
|
146
|
+
include TimesheetControllerHelper
|
147
|
+
it 'should read the session data' do
|
148
|
+
default_mocks(:skip_timesheet_stub => true)
|
149
|
+
|
150
|
+
projects = []
|
151
|
+
4.times do |i|
|
152
|
+
projects << mock_model(Project, :id => i + 1)
|
153
|
+
end
|
154
|
+
|
155
|
+
controller.stub!(:allowed_projects).and_return(projects)
|
156
|
+
session[TimesheetController::SessionKey] = HashWithIndifferentAccess.new(
|
157
|
+
:projects => projects.collect(&:id).collect(&:to_s),
|
158
|
+
:date_to => '2009-01-01',
|
159
|
+
:date_from => '2009-01-01'
|
160
|
+
)
|
161
|
+
|
162
|
+
get :index
|
163
|
+
assigns[:timesheet].date_from.should eql('2009-01-01')
|
164
|
+
assigns[:timesheet].date_to.should eql('2009-01-01')
|
165
|
+
assigns[:timesheet].projects.should eql(projects)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe TimesheetController,"#index with GET request from an Anonymous user" do
|
170
|
+
include TimesheetControllerHelper
|
171
|
+
|
172
|
+
it 'should render the no_projects template' do
|
173
|
+
get 'index'
|
174
|
+
response.should render_template('no_projects')
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
describe TimesheetController,"#report with GET request from an Anonymous user" do
|
180
|
+
include TimesheetControllerHelper
|
181
|
+
|
182
|
+
it 'should redirect to the index' do
|
183
|
+
get 'report'
|
184
|
+
response.should be_redirect
|
185
|
+
response.should redirect_to(:action => 'index')
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
describe TimesheetController,"#report with POST request from an Anonymous user" do
|
191
|
+
include TimesheetControllerHelper
|
192
|
+
|
193
|
+
it 'should redirect to the index' do
|
194
|
+
get 'report'
|
195
|
+
response.should be_redirect
|
196
|
+
response.should redirect_to(:action => 'index')
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
describe TimesheetController,"#report with POST request" do
|
202
|
+
include TimesheetControllerHelper
|
203
|
+
|
204
|
+
before(:each) do
|
205
|
+
default_mocks
|
206
|
+
end
|
207
|
+
|
208
|
+
def send_request
|
209
|
+
post_report
|
210
|
+
end
|
211
|
+
|
212
|
+
def post_report(data={ :timesheet => { } })
|
213
|
+
post 'report', data
|
214
|
+
end
|
215
|
+
|
216
|
+
it_should_behave_like "TimesheetControllerShared"
|
217
|
+
|
218
|
+
it 'should only allow the allowed projects into @timesheet.projects' do
|
219
|
+
project1 = mock_model(Project, :to_param => '1', :id => 1)
|
220
|
+
project2 = mock_model(Project, :to_param => '2', :id => 2)
|
221
|
+
projects = [project1, project2]
|
222
|
+
|
223
|
+
# Adjust mocks
|
224
|
+
@user_project_mock.should_receive(:find).and_return(projects)
|
225
|
+
stub_current_user
|
226
|
+
|
227
|
+
@timesheet.should_receive(:allowed_projects=).with(projects)
|
228
|
+
@timesheet.should_receive(:allowed_projects).twice.and_return(projects)
|
229
|
+
@timesheet.should_receive(:projects=).with([project1])
|
230
|
+
stub_timesheet
|
231
|
+
|
232
|
+
post_report({ :timesheet => { :projects => ['1'] } })
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should save the session data' do
|
236
|
+
post_report({ :timesheet => { :projects => ['1'] } })
|
237
|
+
session[TimesheetController::SessionKey].should_not be_nil
|
238
|
+
session[TimesheetController::SessionKey].keys.should include('projects')
|
239
|
+
session[TimesheetController::SessionKey]['projects'].should eql(['1'])
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe TimesheetController,"#report with request with no data" do
|
244
|
+
include TimesheetControllerHelper
|
245
|
+
|
246
|
+
before(:each) do
|
247
|
+
default_mocks
|
248
|
+
end
|
249
|
+
|
250
|
+
describe 'should redirect to the index' do
|
251
|
+
it 'from a GET request' do
|
252
|
+
post 'report', { }
|
253
|
+
response.should be_redirect
|
254
|
+
response.should redirect_to(:action => 'index')
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'from a POST request' do
|
258
|
+
post 'report', { }
|
259
|
+
response.should be_redirect
|
260
|
+
response.should redirect_to(:action => 'index')
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|