Commit bc84b9cc702cea9f7c82fcbc6f85910c04f3d39f
Committed by
Paulo Meireles
1 parent
6c00f66e
Exists in
staging
and in
42 other branches
[Mezuro] Tests to clone a configuration.
Showing
5 changed files
with
35 additions
and
16 deletions
Show diff stats
plugins/mezuro/lib/kalibro/metric_configuration.rb
| @@ -2,6 +2,14 @@ class Kalibro::MetricConfiguration < Kalibro::Model | @@ -2,6 +2,14 @@ class Kalibro::MetricConfiguration < Kalibro::Model | ||
| 2 | 2 | ||
| 3 | attr_accessor :id, :code, :metric, :base_tool_name, :weight, :aggregation_form, :reading_group_id, :configuration_id | 3 | attr_accessor :id, :code, :metric, :base_tool_name, :weight, :aggregation_form, :reading_group_id, :configuration_id |
| 4 | 4 | ||
| 5 | + def id=(value) | ||
| 6 | + @id = value.to_i | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + def reading_group_id=(value) | ||
| 10 | + @reading_group_id = value.to_i | ||
| 11 | + end | ||
| 12 | + | ||
| 5 | def metric=(value) | 13 | def metric=(value) |
| 6 | @metric = Kalibro::Metric.to_object(value) | 14 | @metric = Kalibro::Metric.to_object(value) |
| 7 | end | 15 | end |
plugins/mezuro/lib/mezuro_plugin/configuration_content.rb
| @@ -101,6 +101,10 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -101,6 +101,10 @@ class MezuroPlugin::ConfigurationContent < Article | ||
| 101 | end | 101 | end |
| 102 | end | 102 | end |
| 103 | 103 | ||
| 104 | + def remove_configuration_from_service | ||
| 105 | + kalibro_configuration.destroy unless kalibro_configuration.nil? | ||
| 106 | + end | ||
| 107 | + | ||
| 104 | def send_configuration_to_service | 108 | def send_configuration_to_service |
| 105 | attributes = {:id => configuration_id, :name => name, :description => description} | 109 | attributes = {:id => configuration_id, :name => name, :description => description} |
| 106 | created_configuration = Kalibro::Configuration.create attributes | 110 | created_configuration = Kalibro::Configuration.create attributes |
| @@ -108,16 +112,13 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -108,16 +112,13 @@ class MezuroPlugin::ConfigurationContent < Article | ||
| 108 | clone_configuration if cloning_configuration? | 112 | clone_configuration if cloning_configuration? |
| 109 | end | 113 | end |
| 110 | 114 | ||
| 111 | - def remove_configuration_from_service | ||
| 112 | - kalibro_configuration.destroy unless kalibro_configuration.nil? | ||
| 113 | - end | ||
| 114 | - | ||
| 115 | def configuration_to_clone_id | 115 | def configuration_to_clone_id |
| 116 | - (configuration_to_clone_name.nil?) ? nil : configuration_names_and_ids.index(configuration_to_clone_name) | 116 | + @configuration_to_clone_id ||= (configuration_to_clone_name.nil?) ? nil : configuration_names_and_ids.index(configuration_to_clone_name) |
| 117 | + @configuration_to_clone_id | ||
| 117 | end | 118 | end |
| 118 | 119 | ||
| 119 | def cloning_configuration? | 120 | def cloning_configuration? |
| 120 | - configuration_to_clone_id.present? | 121 | + !configuration_to_clone_id.nil? |
| 121 | end | 122 | end |
| 122 | 123 | ||
| 123 | def clone_configuration | 124 | def clone_configuration |
plugins/mezuro/test/fixtures/configuration_fixtures.rb
| @@ -8,7 +8,7 @@ class ConfigurationFixtures | @@ -8,7 +8,7 @@ class ConfigurationFixtures | ||
| 8 | 8 | ||
| 9 | def self.created_configuration | 9 | def self.created_configuration |
| 10 | Kalibro::Configuration.new({ | 10 | Kalibro::Configuration.new({ |
| 11 | - :name => 'Sample Configuration', | 11 | + :name => 'Created Sample Configuration', |
| 12 | :description => 'Kalibro configuration for Java projects.' | 12 | :description => 'Kalibro configuration for Java projects.' |
| 13 | }) | 13 | }) |
| 14 | end | 14 | end |
plugins/mezuro/test/unit/kalibro/metric_configuration_test.rb
| @@ -11,7 +11,10 @@ class MetricConfigurationTest < ActiveSupport::TestCase | @@ -11,7 +11,10 @@ class MetricConfigurationTest < ActiveSupport::TestCase | ||
| 11 | end | 11 | end |
| 12 | 12 | ||
| 13 | should 'create metric configuration from hash' do | 13 | should 'create metric configuration from hash' do |
| 14 | - assert_equal @native_metric_configuration_hash[:code], Kalibro::MetricConfiguration.new(@native_metric_configuration_hash).code | 14 | + metric_configuration = Kalibro::MetricConfiguration.new(@native_metric_configuration_hash) |
| 15 | + assert_equal @native_metric_configuration_hash[:code], metric_configuration.code | ||
| 16 | + assert_equal @native_metric_configuration_hash[:id].to_i, metric_configuration.id | ||
| 17 | + assert_equal @native_metric_configuration_hash[:reading_group_id].to_i, metric_configuration.reading_group_id | ||
| 15 | end | 18 | end |
| 16 | 19 | ||
| 17 | should 'convert metric configuration to hash' do | 20 | should 'convert metric configuration to hash' do |
plugins/mezuro/test/unit/mezuro_plugin/configuration_content_test.rb
| @@ -2,6 +2,8 @@ require "test_helper" | @@ -2,6 +2,8 @@ require "test_helper" | ||
| 2 | 2 | ||
| 3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | 3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" |
| 4 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_content_fixtures" | 4 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_content_fixtures" |
| 5 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" | ||
| 6 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | ||
| 5 | 7 | ||
| 6 | class ConfigurationContentTest < ActiveSupport::TestCase | 8 | class ConfigurationContentTest < ActiveSupport::TestCase |
| 7 | 9 | ||
| @@ -12,6 +14,9 @@ class ConfigurationContentTest < ActiveSupport::TestCase | @@ -12,6 +14,9 @@ class ConfigurationContentTest < ActiveSupport::TestCase | ||
| 12 | @content_hash = ConfigurationContentFixtures.configuration_content_hash | 14 | @content_hash = ConfigurationContentFixtures.configuration_content_hash |
| 13 | @configuration_hash = {:name => @content_hash[:name], :description => @content_hash[:description], :id => @content_hash[:configuration_id]} | 15 | @configuration_hash = {:name => @content_hash[:name], :description => @content_hash[:description], :id => @content_hash[:configuration_id]} |
| 14 | @created_content = ConfigurationContentFixtures.created_configuration_content | 16 | @created_content = ConfigurationContentFixtures.created_configuration_content |
| 17 | + | ||
| 18 | + @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration | ||
| 19 | + @range = RangeFixtures.range | ||
| 15 | end | 20 | end |
| 16 | 21 | ||
| 17 | should 'be an article' do | 22 | should 'be an article' do |
| @@ -38,13 +43,13 @@ class ConfigurationContentTest < ActiveSupport::TestCase | @@ -38,13 +43,13 @@ class ConfigurationContentTest < ActiveSupport::TestCase | ||
| 38 | 43 | ||
| 39 | should 'get configuration from service' do | 44 | should 'get configuration from service' do |
| 40 | Kalibro::Configuration.expects(:find).with(@content.configuration_id).returns(@configuration) | 45 | Kalibro::Configuration.expects(:find).with(@content.configuration_id).returns(@configuration) |
| 41 | - assert_equal @configuration, @content.configuration | 46 | + assert_equal @configuration, @content.kalibro_configuration |
| 42 | end | 47 | end |
| 43 | 48 | ||
| 44 | should 'send configuration to service after saving' do | 49 | should 'send configuration to service after saving' do |
| 45 | @content.expects :send_configuration_to_service | 50 | @content.expects :send_configuration_to_service |
| 46 | @content.stubs(:solr_save) | 51 | @content.stubs(:solr_save) |
| 47 | - @content.run_callbacks :after_save | 52 | + @content.run_callbacks :before_save |
| 48 | end | 53 | end |
| 49 | 54 | ||
| 50 | should 'create new configuration' do | 55 | should 'create new configuration' do |
| @@ -53,15 +58,17 @@ class ConfigurationContentTest < ActiveSupport::TestCase | @@ -53,15 +58,17 @@ class ConfigurationContentTest < ActiveSupport::TestCase | ||
| 53 | assert_equal @configuration.id, @created_content.configuration_id | 58 | assert_equal @configuration.id, @created_content.configuration_id |
| 54 | end | 59 | end |
| 55 | 60 | ||
| 56 | -=begin | ||
| 57 | should 'clone configuration' do | 61 | should 'clone configuration' do |
| 58 | - @content.configuration_to_clone_name = 'clone name' | ||
| 59 | - Kalibro::Configuration.expects(:create).with(:name => @content.configuration_id, :description => @content.description, :metric_configuration => @configuration.metric_configurations_hash) | ||
| 60 | - Kalibro::Configuration.expects(:find).with(@content.configuration_id).returns(nil) | ||
| 61 | - Kalibro::Configuration.expects(:find).with('clone name').returns(@configuration) | 62 | + clone_name = @configuration.name |
| 63 | + @content.configuration_to_clone_name = clone_name | ||
| 64 | + Kalibro::Configuration.expects(:create).with(:id => @content.configuration_id, :name => @content.name, :description => @content.description).returns(@configuration) | ||
| 65 | + Kalibro::Configuration.expects(:all).returns([@configuration]) | ||
| 66 | + Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration.id).returns([@metric_configuration]) | ||
| 67 | + Kalibro::MetricConfiguration.expects(:request).returns(:metric_configuration_id => @metric_configuration.id) | ||
| 68 | + Kalibro::Range.expects(:ranges_of).with(@metric_configuration.id).returns([@range]) | ||
| 69 | + @range.expects(:save).with(@metric_configuration.id).returns(true) | ||
| 62 | @content.send :send_configuration_to_service | 70 | @content.send :send_configuration_to_service |
| 63 | end | 71 | end |
| 64 | -=end | ||
| 65 | 72 | ||
| 66 | should 'edit configuration' do | 73 | should 'edit configuration' do |
| 67 | Kalibro::Configuration.expects(:new).with(@configuration_hash).returns(@configuration) | 74 | Kalibro::Configuration.expects(:new).with(@configuration_hash).returns(@configuration) |