Commit 527b4c869237ed99b7fdb095de4bc09332a3b8af
1 parent
078f4eec
Exists in
master
and in
29 other branches
[Mezuro] Fixed models and helper unit tests and fixed repository model
Showing
6 changed files
with
24 additions
and
16 deletions
Show diff stats
plugins/mezuro/lib/kalibro/model.rb
plugins/mezuro/lib/kalibro/repository.rb
... | ... | @@ -22,8 +22,14 @@ class Kalibro::Repository < Kalibro::Model |
22 | 22 | self.class.request(:cancel_processing_of_repository, {:repository_id => self.id}) |
23 | 23 | end |
24 | 24 | |
25 | - def save_params | |
26 | - {:repository => self.to_hash, :project_id => Kalibro::Project.project_of(id).id} | |
25 | + def save(project_id) | |
26 | + begin | |
27 | + self.id = self.class.request(:save_repository, {:repository => self.to_hash, :project_id => project_id})[:repository_id] | |
28 | + true | |
29 | + rescue Exception => exception | |
30 | + add_error exception | |
31 | + false | |
32 | + end | |
27 | 33 | end |
28 | 34 | |
29 | 35 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/configuration_test.rb
... | ... | @@ -29,9 +29,9 @@ class ConfigurationTest < ActiveSupport::TestCase |
29 | 29 | assert_equal @hash[:name], Kalibro::Configuration.find(@configuration.id).name |
30 | 30 | end |
31 | 31 | |
32 | - should 'return nil when configuration doesnt exist' do | |
32 | + should 'return exception when configuration doesnt exist' do | |
33 | 33 | Kalibro::Configuration.expects(:request).with(:configuration_exists, {:configuration_id => @configuration.id}).returns({:exists => false}) |
34 | - assert_nil Kalibro::Configuration.find(@configuration.id) | |
34 | + assert_raise(Kalibro::Errors::RecordNotFound){Kalibro::Configuration.find(@configuration.id)} | |
35 | 35 | end |
36 | 36 | |
37 | 37 | should 'get configuration of a repository' do | ... | ... |
plugins/mezuro/test/unit/kalibro/project_test.rb
... | ... | @@ -31,9 +31,9 @@ class ProjectTest < ActiveSupport::TestCase |
31 | 31 | assert_equal @hash[:name], Kalibro::Project.find(@project.id).name |
32 | 32 | end |
33 | 33 | |
34 | - should 'verify when project doesnt exist' do | |
34 | + should 'raise RecordNotFound exception when project doesnt exist' do | |
35 | 35 | Kalibro::Project.expects(:request).with(:project_exists, {:project_id => @project.id}).returns({:exists => false}) |
36 | - assert_nil Kalibro::Project.find(@project.id) | |
36 | + assert_raise(Kalibro::Errors::RecordNotFound){Kalibro::Project.find(@project.id)} | |
37 | 37 | end |
38 | 38 | |
39 | 39 | should 'get project of a repository' do | ... | ... |
plugins/mezuro/test/unit/kalibro/repository_test.rb
... | ... | @@ -38,14 +38,16 @@ class RepositoryTest < ActiveSupport::TestCase |
38 | 38 | |
39 | 39 | should 'return true when repository is saved successfully' do |
40 | 40 | id_from_kalibro = 1 |
41 | - Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash}).returns(:repository_id => id_from_kalibro) | |
42 | - assert @created_repository.save | |
41 | + project_id = 56 | |
42 | + Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash, :project_id => project_id}).returns(:repository_id => id_from_kalibro) | |
43 | + assert @created_repository.save(project_id) | |
43 | 44 | assert_equal id_from_kalibro, @created_repository.id |
44 | 45 | end |
45 | 46 | |
46 | 47 | should 'return false when repository is not saved successfully' do |
47 | - Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash}).raises(Exception.new) | |
48 | - assert !(@created_repository.save) | |
48 | + project_id = 56 | |
49 | + Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash, :project_id => project_id}).raises(Exception.new) | |
50 | + assert !(@created_repository.save(project_id)) | |
49 | 51 | assert_nil @created_repository.id |
50 | 52 | end |
51 | 53 | |
... | ... | @@ -58,7 +60,7 @@ class RepositoryTest < ActiveSupport::TestCase |
58 | 60 | Kalibro::Repository.expects(:request).with(:process_repository, {:repository_id => @repository.id}); |
59 | 61 | @repository.process_repository |
60 | 62 | end |
61 | - | |
63 | + | |
62 | 64 | should 'cancel processing of a repository' do |
63 | 65 | Kalibro::Repository.expects(:request).with(:cancel_processing_of_repository, {:repository_id => @repository.id}); |
64 | 66 | @repository.cancel_processing_of_repository | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb
1 | 1 | require "test_helper" |
2 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures" | |
2 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures" | |
3 | 3 | |
4 | 4 | class ContentViewerHelperTest < ActiveSupport::TestCase |
5 | 5 | |
... | ... | @@ -13,9 +13,9 @@ class ContentViewerHelperTest < ActiveSupport::TestCase |
13 | 13 | assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]], MezuroPlugin::Helpers::ContentViewerHelper.create_periodicity_options |
14 | 14 | end |
15 | 15 | |
16 | - should 'format metric name for module result' do | |
17 | - metric_result = MetricResultFixtures.native_metric_result | |
18 | - assert_equal 'AverageMethodLOC', MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) | |
16 | + should 'format metric name for metric configuration snapshot' do | |
17 | + metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot | |
18 | + assert_equal 'AverageMethodLOC', MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) | |
19 | 19 | end |
20 | 20 | |
21 | 21 | end | ... | ... |