Commit 527b4c869237ed99b7fdb095de4bc09332a3b8af

Authored by João M. M. da Silva
1 parent 078f4eec

[Mezuro] Fixed models and helper unit tests and fixed repository model

plugins/mezuro/lib/kalibro/model.rb
@@ -52,7 +52,7 @@ class Kalibro::Model @@ -52,7 +52,7 @@ class Kalibro::Model
52 if(exists?(id)) 52 if(exists?(id))
53 new request(find_action, id_params(id))["#{class_name.underscore}".to_sym] 53 new request(find_action, id_params(id))["#{class_name.underscore}".to_sym]
54 else 54 else
55 - raise Errors::RecordNotFound 55 + raise Kalibro::Errors::RecordNotFound
56 end 56 end
57 end 57 end
58 58
plugins/mezuro/lib/kalibro/repository.rb
@@ -22,8 +22,14 @@ class Kalibro::Repository < Kalibro::Model @@ -22,8 +22,14 @@ class Kalibro::Repository < Kalibro::Model
22 self.class.request(:cancel_processing_of_repository, {:repository_id => self.id}) 22 self.class.request(:cancel_processing_of_repository, {:repository_id => self.id})
23 end 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 end 33 end
28 34
29 end 35 end
plugins/mezuro/test/unit/kalibro/configuration_test.rb
@@ -29,9 +29,9 @@ class ConfigurationTest < ActiveSupport::TestCase @@ -29,9 +29,9 @@ class ConfigurationTest < ActiveSupport::TestCase
29 assert_equal @hash[:name], Kalibro::Configuration.find(@configuration.id).name 29 assert_equal @hash[:name], Kalibro::Configuration.find(@configuration.id).name
30 end 30 end
31 31
32 - should 'return nil when configuration doesnt exist' do 32 + should 'return exception when configuration doesnt exist' do
33 Kalibro::Configuration.expects(:request).with(:configuration_exists, {:configuration_id => @configuration.id}).returns({:exists => false}) 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 end 35 end
36 36
37 should 'get configuration of a repository' do 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,9 +31,9 @@ class ProjectTest < ActiveSupport::TestCase
31 assert_equal @hash[:name], Kalibro::Project.find(@project.id).name 31 assert_equal @hash[:name], Kalibro::Project.find(@project.id).name
32 end 32 end
33 33
34 - should 'verify when project doesnt exist' do 34 + should 'raise RecordNotFound exception when project doesnt exist' do
35 Kalibro::Project.expects(:request).with(:project_exists, {:project_id => @project.id}).returns({:exists => false}) 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 end 37 end
38 38
39 should 'get project of a repository' do 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,14 +38,16 @@ class RepositoryTest < ActiveSupport::TestCase
38 38
39 should 'return true when repository is saved successfully' do 39 should 'return true when repository is saved successfully' do
40 id_from_kalibro = 1 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 assert_equal id_from_kalibro, @created_repository.id 44 assert_equal id_from_kalibro, @created_repository.id
44 end 45 end
45 46
46 should 'return false when repository is not saved successfully' do 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 assert_nil @created_repository.id 51 assert_nil @created_repository.id
50 end 52 end
51 53
@@ -58,7 +60,7 @@ class RepositoryTest < ActiveSupport::TestCase @@ -58,7 +60,7 @@ class RepositoryTest < ActiveSupport::TestCase
58 Kalibro::Repository.expects(:request).with(:process_repository, {:repository_id => @repository.id}); 60 Kalibro::Repository.expects(:request).with(:process_repository, {:repository_id => @repository.id});
59 @repository.process_repository 61 @repository.process_repository
60 end 62 end
61 - 63 +
62 should 'cancel processing of a repository' do 64 should 'cancel processing of a repository' do
63 Kalibro::Repository.expects(:request).with(:cancel_processing_of_repository, {:repository_id => @repository.id}); 65 Kalibro::Repository.expects(:request).with(:cancel_processing_of_repository, {:repository_id => @repository.id});
64 @repository.cancel_processing_of_repository 66 @repository.cancel_processing_of_repository
plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb
1 require "test_helper" 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 class ContentViewerHelperTest < ActiveSupport::TestCase 4 class ContentViewerHelperTest < ActiveSupport::TestCase
5 5
@@ -13,9 +13,9 @@ class ContentViewerHelperTest &lt; ActiveSupport::TestCase @@ -13,9 +13,9 @@ class ContentViewerHelperTest &lt; ActiveSupport::TestCase
13 assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]], MezuroPlugin::Helpers::ContentViewerHelper.create_periodicity_options 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 end 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 end 19 end
20 20
21 end 21 end