project_content_test.rb
5.74 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
require "test_helper"
require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures"
require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_content_fixtures"
require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/processing_fixtures"
require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures"
require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_metric_result_fixtures"
class ProjectContentTest < ActiveSupport::TestCase
def setup
@project_content = ProjectContentFixtures.project_content
@project = ProjectFixtures.project
@repository = RepositoryFixtures.repository
@processing = ProcessingFixtures.processing
@date = @processing.date
@module = ModuleFixtures.module
@module_result = ModuleResultFixtures.module_result
@date_metric_result = DateMetricResultFixtures.date_metric_result
end
should 'provide proper short description' do
assert_equal 'Mezuro project', MezuroPlugin::ProjectContent.short_description
end
should 'provide proper description' do
assert_equal 'Software project tracked by Kalibro', MezuroPlugin::ProjectContent.description
end
should 'have an html view' do
assert_not_nil @project_content.to_html
end
should 'get project from service' do
Kalibro::Project.expects(:find).with(@project.id).returns(@project)
assert_equal @project, @project_content.project
end
should 'add error to base when the project does not exist' do
Kalibro::Project.expects(:find).with(@project.id).raises(Kalibro::Errors::RecordNotFound)
assert_nil @project_content.errors[:base]
@project_content.project
assert_not_nil @project_content.errors[:base]
end
should 'get repositories of the project from service' do
Kalibro::Repository.expects(:repositories_of).with(@project.id).returns([@repository])
assert_equal [@repository], @project_content.repositories
end
should 'add error to base when getting the repositories of a project that does not exist' do
Kalibro::Repository.expects(:repositories_of).with(@project.id).raises(Kalibro::Errors::RecordNotFound)
assert_nil @project_content.errors[:base]
@project_content.repositories
assert_not_nil @project_content.errors[:base]
end
should 'get processing of a repository' do
Kalibro::Processing.expects(:has_ready_processing).with(@repository.id).returns(true)
Kalibro::Processing.expects(:last_ready_processing_of).with(@repository.id).returns(@processing)
assert_equal @processing, @project_content.processing(@repository.id)
end
should 'get not ready processing of a repository' do
Kalibro::Processing.expects(:has_ready_processing).with(@repository.id).returns(false)
Kalibro::Processing.expects(:last_processing_of).with(@repository.id).returns(@processing)
assert_equal @processing, @project_content.processing(@repository.id)
end
should 'get processing of a repository after date' do
Kalibro::Processing.expects(:has_processing_after).with(@repository.id, @date).returns(true)
Kalibro::Processing.expects(:first_processing_after).with(@repository.id, @date).returns(@processing)
assert_equal @processing, @project_content.processing_with_date(@repository.id, @date)
end
should 'get processing of a repository before date' do
Kalibro::Processing.expects(:has_processing_after).with(@repository.id, @date).returns(false)
Kalibro::Processing.expects(:has_processing_before).with(@repository.id, @date).returns(true)
Kalibro::Processing.expects(:last_processing_before).with(@repository.id, @date).returns(@processing)
assert_equal @processing, @project_content.processing_with_date(@repository.id, @date)
end
should 'get module result' do
@project_content.expects(:processing).with(@repository.id).returns(@processing)
Kalibro::ModuleResult.expects(:find).with(@processing.results_root_id).returns(@module_result)
assert_equal @module_result, @project_content.module_result(@repository.id)
end
should 'get module result with date' do
@project_content.expects(:processing_with_date).with(@repository.id,@date.to_s).returns(@processing)
Kalibro::ModuleResult.expects(:find).with(@processing.results_root_id).returns(@module_result)
assert_equal @module_result, @project_content.module_result(@repository.id, @date.to_s)
end
should 'get result history' do
Kalibro::MetricResult.expects(:history_of).with(@module_result.id).returns([@date_metric_result])
assert_equal [@date_metric_result], @project_content.result_history(@module_result.id)
end
should 'add error to base when the module_result does not exist' do
Kalibro::MetricResult.expects(:history_of).with(@module_result.id).raises(Kalibro::Errors::RecordNotFound)
assert_nil @project_content.errors[:base]
@project_content.result_history(@module_result.id)
assert_not_nil @project_content.errors[:base]
end
=begin
should 'send project to service after saving' do
@project_content.expects :send_project_to_service
@project_content.run_callbacks :after_save
end
should 'destroy project from service' do
Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name})
@project_content.send :destroy_project_from_service
end
should 'send correct project to service' do
hash = ProjectFixtures.project_hash
hash.delete(:attributes!)
hash.delete(:state)
Kalibro::Project.expects(:create).with(hash).returns(@project)
@project.expects(:process_project).with(@project_content.periodicity_in_days)
@project_content.send :send_project_to_service
end
=end
end