Commit bc84b9cc702cea9f7c82fcbc6f85910c04f3d39f
Committed by
Paulo Meireles
1 parent
6c00f66e
Exists in
master
and in
29 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 | 2 | |
3 | 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 | 13 | def metric=(value) |
6 | 14 | @metric = Kalibro::Metric.to_object(value) |
7 | 15 | end | ... | ... |
plugins/mezuro/lib/mezuro_plugin/configuration_content.rb
... | ... | @@ -101,6 +101,10 @@ class MezuroPlugin::ConfigurationContent < Article |
101 | 101 | end |
102 | 102 | end |
103 | 103 | |
104 | + def remove_configuration_from_service | |
105 | + kalibro_configuration.destroy unless kalibro_configuration.nil? | |
106 | + end | |
107 | + | |
104 | 108 | def send_configuration_to_service |
105 | 109 | attributes = {:id => configuration_id, :name => name, :description => description} |
106 | 110 | created_configuration = Kalibro::Configuration.create attributes |
... | ... | @@ -108,16 +112,13 @@ class MezuroPlugin::ConfigurationContent < Article |
108 | 112 | clone_configuration if cloning_configuration? |
109 | 113 | end |
110 | 114 | |
111 | - def remove_configuration_from_service | |
112 | - kalibro_configuration.destroy unless kalibro_configuration.nil? | |
113 | - end | |
114 | - | |
115 | 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 | 118 | end |
118 | 119 | |
119 | 120 | def cloning_configuration? |
120 | - configuration_to_clone_id.present? | |
121 | + !configuration_to_clone_id.nil? | |
121 | 122 | end |
122 | 123 | |
123 | 124 | def clone_configuration | ... | ... |
plugins/mezuro/test/fixtures/configuration_fixtures.rb
... | ... | @@ -8,7 +8,7 @@ class ConfigurationFixtures |
8 | 8 | |
9 | 9 | def self.created_configuration |
10 | 10 | Kalibro::Configuration.new({ |
11 | - :name => 'Sample Configuration', | |
11 | + :name => 'Created Sample Configuration', | |
12 | 12 | :description => 'Kalibro configuration for Java projects.' |
13 | 13 | }) |
14 | 14 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/metric_configuration_test.rb
... | ... | @@ -11,7 +11,10 @@ class MetricConfigurationTest < ActiveSupport::TestCase |
11 | 11 | end |
12 | 12 | |
13 | 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 | 18 | end |
16 | 19 | |
17 | 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 | 2 | |
3 | 3 | require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" |
4 | 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 | 8 | class ConfigurationContentTest < ActiveSupport::TestCase |
7 | 9 | |
... | ... | @@ -12,6 +14,9 @@ class ConfigurationContentTest < ActiveSupport::TestCase |
12 | 14 | @content_hash = ConfigurationContentFixtures.configuration_content_hash |
13 | 15 | @configuration_hash = {:name => @content_hash[:name], :description => @content_hash[:description], :id => @content_hash[:configuration_id]} |
14 | 16 | @created_content = ConfigurationContentFixtures.created_configuration_content |
17 | + | |
18 | + @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration | |
19 | + @range = RangeFixtures.range | |
15 | 20 | end |
16 | 21 | |
17 | 22 | should 'be an article' do |
... | ... | @@ -38,13 +43,13 @@ class ConfigurationContentTest < ActiveSupport::TestCase |
38 | 43 | |
39 | 44 | should 'get configuration from service' do |
40 | 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 | 47 | end |
43 | 48 | |
44 | 49 | should 'send configuration to service after saving' do |
45 | 50 | @content.expects :send_configuration_to_service |
46 | 51 | @content.stubs(:solr_save) |
47 | - @content.run_callbacks :after_save | |
52 | + @content.run_callbacks :before_save | |
48 | 53 | end |
49 | 54 | |
50 | 55 | should 'create new configuration' do |
... | ... | @@ -53,15 +58,17 @@ class ConfigurationContentTest < ActiveSupport::TestCase |
53 | 58 | assert_equal @configuration.id, @created_content.configuration_id |
54 | 59 | end |
55 | 60 | |
56 | -=begin | |
57 | 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 | 70 | @content.send :send_configuration_to_service |
63 | 71 | end |
64 | -=end | |
65 | 72 | |
66 | 73 | should 'edit configuration' do |
67 | 74 | Kalibro::Configuration.expects(:new).with(@configuration_hash).returns(@configuration) | ... | ... |