Commit c07f1fb06bca7268823f130e7d5010eee20a1929

Authored by Carlos Morais
1 parent 7144978c

[Mezuro] Adding test for ConfigurationContent

plugins/mezuro/lib/kalibro/client/configuration_client.rb
1 1 class Kalibro::Client::ConfigurationClient
2 2  
  3 + def self.save(configuration_content)
  4 + configuration = Kalibro::Entities::Configuration.new
  5 + configuration.name = configuration_content.name
  6 + configuration.description = configuration_content.description
  7 + new.save(configuration)
  8 + end
  9 +
  10 + def self.remove(configuration_name)
  11 + client = new
  12 + client.remove(configuration_name) if client.configuration_names.include? configuration_name
  13 + end
  14 +
3 15 def initialize
4 16 @port = Kalibro::Client::Port.new('Configuration')
5 17 end
... ... @@ -8,10 +20,6 @@ class Kalibro::Client::ConfigurationClient
8 20 @port.request(:save_configuration, {:configuration => configuration.to_hash})
9 21 end
10 22  
11   - def self.save(configuration)
12   - new.save(configuration)
13   - end
14   -
15 23 def configuration_names
16 24 @port.request(:get_configuration_names)[:configuration_name].to_a
17 25 end
... ... @@ -25,7 +33,4 @@ class Kalibro::Client::ConfigurationClient
25 33 @port.request(:remove_configuration, {:configuration_name => configuration_name})
26 34 end
27 35  
28   - def self.remove(configuration_name)
29   - new.remove(configuration_name)
30   - end
31 36 end
... ...
plugins/mezuro/lib/mezuro_plugin/configuration_content.rb
... ... @@ -5,7 +5,7 @@ class MezuroPlugin::ConfigurationContent < Article
5 5 end
6 6  
7 7 def self.description
8   - 'Kalibro configuration for some project'
  8 + 'Sets of thresholds to interpret metrics'
9 9 end
10 10  
11 11 settings_items :description
... ... @@ -18,7 +18,7 @@ class MezuroPlugin::ConfigurationContent < Article
18 18 end
19 19  
20 20 def configuration
21   - Kalibro::Client::ConfigurationClient.new.configuration(title)
  21 + Kalibro::Client::ConfigurationClient.configuration(name)
22 22 end
23 23  
24 24 after_save :send_configuration_to_service
... ... @@ -27,18 +27,11 @@ class MezuroPlugin::ConfigurationContent < Article
27 27 private
28 28  
29 29 def send_configuration_to_service
30   - Kalibro::Client::ConfigurationClient.save(create_configuration)
  30 + Kalibro::Client::ConfigurationClient.save(self)
31 31 end
32 32  
33 33 def remove_configuration_from_service
34   - Kalibro::Client::ConfigurationClient.remove(title)
35   - end
36   -
37   - def create_configuration
38   - configuration = Kalibro::Entities::Configuration.new
39   - configuration.name = title
40   - configuration.description = description
41   - configuration
  34 + Kalibro::Client::ConfigurationClient.remove(name)
42 35 end
43 36  
44 37 end
... ...
plugins/mezuro/lib/mezuro_plugin/project_content.rb
... ... @@ -44,4 +44,3 @@ class MezuroPlugin::ProjectContent < Article
44 44 end
45 45  
46 46 end
47   -
... ...
plugins/mezuro/test/fixtures/configuration_fixtures.rb
  1 +require File.dirname(__FILE__) + '/metric_configuration_fixtures'
  2 +
1 3 class ConfigurationFixtures
2 4  
3 5 def self.kalibro_configuration
... ...
plugins/mezuro/test/fixtures/metric_configuration_fixtures.rb
  1 +require File.dirname(__FILE__) + '/compound_metric_fixtures'
  2 +require File.dirname(__FILE__) + '/native_metric_fixtures'
  3 +require File.dirname(__FILE__) + '/range_fixtures'
  4 +
1 5 class MetricConfigurationFixtures
2 6  
3 7 def self.amloc_configuration
... ...
plugins/mezuro/test/unit/mezuro_plugin/configuration_content_test.rb 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
  4 +
  5 +class ConfigurationContentTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @configuration = ConfigurationFixtures.kalibro_configuration
  9 + @content = MezuroPlugin::ConfigurationContent.new
  10 + @content.name = @configuration.name
  11 + @content.description = @configuration.description
  12 + end
  13 +
  14 + should 'be an article' do
  15 + assert_kind_of Article, @content
  16 + end
  17 +
  18 + should 'provide proper short description' do
  19 + assert_equal 'Kalibro configuration', MezuroPlugin::ConfigurationContent.short_description
  20 + end
  21 +
  22 + should 'provide proper description' do
  23 + assert_equal 'Sets of thresholds to interpret metrics', MezuroPlugin::ConfigurationContent.description
  24 + end
  25 +
  26 + should 'have an html view' do
  27 + assert_not_nil @content.to_html
  28 + end
  29 +
  30 + should 'get configuration from service' do
  31 + Kalibro::Client::ConfigurationClient.expects(:configuration).with(@content.name).returns(@configuration)
  32 + assert_equal @configuration, @content.configuration
  33 + end
  34 +
  35 + should 'send configuration to service after saving' do
  36 + @content.expects :send_configuration_to_service
  37 + @content.run_callbacks :after_save
  38 + end
  39 +
  40 + should 'send correct configuration to service' do
  41 + Kalibro::Client::ConfigurationClient.expects(:save).with(@content)
  42 + @content.send :send_configuration_to_service
  43 + end
  44 +
  45 + should 'remove project from service' do
  46 + Kalibro::Client::ConfigurationClient.expects(:remove).with(@content.name)
  47 + @content.send :remove_configuration_from_service
  48 + end
  49 +
  50 +end
... ...
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
... ... @@ -50,19 +50,20 @@ class ProjectContentTest &lt; ActiveSupport::TestCase
50 50 assert_equal module_result, @content.module_result(module_name)
51 51 end
52 52  
53   - should 'run send project to service on after_save callback' do
  53 + should 'send project to service after saving' do
54 54 @content.expects :send_project_to_service
55 55 @content.run_callbacks :after_save
56 56 end
57 57  
58 58 should 'send correct project to service' do
59 59 Kalibro::Client::ProjectClient.expects(:save).with(@content)
60   - Kalibro::Client::KalibroClient.expects(:process_project).with(@project.name)
  60 + Kalibro::Client::KalibroClient.expects(:process_project).with(@content.name)
61 61 @content.send :send_project_to_service
62 62 end
63 63  
64 64 should 'remove project from service' do
65   - Kalibro::Client::ProjectClient.expects(:remove).with(@project.name)
  65 + Kalibro::Client::ProjectClient.expects(:remove).with(@content.name)
66 66 @content.send :remove_project_from_service
67 67 end
  68 +
68 69 end
... ...