diff --git a/plugins/mezuro/lib/kalibro/model.rb b/plugins/mezuro/lib/kalibro/model.rb index 30d9654..369a749 100644 --- a/plugins/mezuro/lib/kalibro/model.rb +++ b/plugins/mezuro/lib/kalibro/model.rb @@ -52,7 +52,7 @@ class Kalibro::Model if(exists?(id)) new request(find_action, id_params(id))["#{class_name.underscore}".to_sym] else - raise Errors::RecordNotFound + raise Kalibro::Errors::RecordNotFound end end diff --git a/plugins/mezuro/lib/kalibro/repository.rb b/plugins/mezuro/lib/kalibro/repository.rb index 415fcef..fbeab1f 100644 --- a/plugins/mezuro/lib/kalibro/repository.rb +++ b/plugins/mezuro/lib/kalibro/repository.rb @@ -22,8 +22,14 @@ class Kalibro::Repository < Kalibro::Model self.class.request(:cancel_processing_of_repository, {:repository_id => self.id}) end - def save_params - {:repository => self.to_hash, :project_id => Kalibro::Project.project_of(id).id} + def save(project_id) + begin + self.id = self.class.request(:save_repository, {:repository => self.to_hash, :project_id => project_id})[:repository_id] + true + rescue Exception => exception + add_error exception + false + end end end diff --git a/plugins/mezuro/test/unit/kalibro/configuration_test.rb b/plugins/mezuro/test/unit/kalibro/configuration_test.rb index 4499f00..a3d13dd 100644 --- a/plugins/mezuro/test/unit/kalibro/configuration_test.rb +++ b/plugins/mezuro/test/unit/kalibro/configuration_test.rb @@ -29,9 +29,9 @@ class ConfigurationTest < ActiveSupport::TestCase assert_equal @hash[:name], Kalibro::Configuration.find(@configuration.id).name end - should 'return nil when configuration doesnt exist' do + should 'return exception when configuration doesnt exist' do Kalibro::Configuration.expects(:request).with(:configuration_exists, {:configuration_id => @configuration.id}).returns({:exists => false}) - assert_nil Kalibro::Configuration.find(@configuration.id) + assert_raise(Kalibro::Errors::RecordNotFound){Kalibro::Configuration.find(@configuration.id)} end should 'get configuration of a repository' do diff --git a/plugins/mezuro/test/unit/kalibro/project_test.rb b/plugins/mezuro/test/unit/kalibro/project_test.rb index 091cfbc..7f5bf1a 100644 --- a/plugins/mezuro/test/unit/kalibro/project_test.rb +++ b/plugins/mezuro/test/unit/kalibro/project_test.rb @@ -31,9 +31,9 @@ class ProjectTest < ActiveSupport::TestCase assert_equal @hash[:name], Kalibro::Project.find(@project.id).name end - should 'verify when project doesnt exist' do + should 'raise RecordNotFound exception when project doesnt exist' do Kalibro::Project.expects(:request).with(:project_exists, {:project_id => @project.id}).returns({:exists => false}) - assert_nil Kalibro::Project.find(@project.id) + assert_raise(Kalibro::Errors::RecordNotFound){Kalibro::Project.find(@project.id)} end should 'get project of a repository' do diff --git a/plugins/mezuro/test/unit/kalibro/repository_test.rb b/plugins/mezuro/test/unit/kalibro/repository_test.rb index d9d3bcb..fa379c1 100644 --- a/plugins/mezuro/test/unit/kalibro/repository_test.rb +++ b/plugins/mezuro/test/unit/kalibro/repository_test.rb @@ -38,14 +38,16 @@ class RepositoryTest < ActiveSupport::TestCase should 'return true when repository is saved successfully' do id_from_kalibro = 1 - Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash}).returns(:repository_id => id_from_kalibro) - assert @created_repository.save + project_id = 56 + Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash, :project_id => project_id}).returns(:repository_id => id_from_kalibro) + assert @created_repository.save(project_id) assert_equal id_from_kalibro, @created_repository.id end should 'return false when repository is not saved successfully' do - Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash}).raises(Exception.new) - assert !(@created_repository.save) + project_id = 56 + Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash, :project_id => project_id}).raises(Exception.new) + assert !(@created_repository.save(project_id)) assert_nil @created_repository.id end @@ -58,7 +60,7 @@ class RepositoryTest < ActiveSupport::TestCase Kalibro::Repository.expects(:request).with(:process_repository, {:repository_id => @repository.id}); @repository.process_repository end - + should 'cancel processing of a repository' do Kalibro::Repository.expects(:request).with(:cancel_processing_of_repository, {:repository_id => @repository.id}); @repository.cancel_processing_of_repository diff --git a/plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb b/plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb index 1bc7052..916535c 100644 --- a/plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb +++ b/plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb @@ -1,5 +1,5 @@ require "test_helper" -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures" +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures" class ContentViewerHelperTest < ActiveSupport::TestCase @@ -13,9 +13,9 @@ class ContentViewerHelperTest < ActiveSupport::TestCase assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]], MezuroPlugin::Helpers::ContentViewerHelper.create_periodicity_options end - should 'format metric name for module result' do - metric_result = MetricResultFixtures.native_metric_result - assert_equal 'AverageMethodLOC', MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) + should 'format metric name for metric configuration snapshot' do + metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot + assert_equal 'AverageMethodLOC', MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) end end -- libgit2 0.21.2