Commit 1f61651826585bf48310b2dde58e106689a9ceac
Committed by
Paulo Meireles
1 parent
c5e6187f
Exists in
master
and in
22 other branches
[Mezuro] refactored clone configuration.
Showing
4 changed files
with
15 additions
and
24 deletions
Show diff stats
plugins/mezuro/lib/mezuro_plugin/configuration_content.rb
| ... | ... | @@ -32,18 +32,15 @@ class MezuroPlugin::ConfigurationContent < Article |
| 32 | 32 | end |
| 33 | 33 | |
| 34 | 34 | def configuration_names_and_ids |
| 35 | - all_names_and_ids = {} | |
| 36 | 35 | begin |
| 37 | 36 | all_configurations = Kalibro::Configuration.all |
| 38 | - if(!all_configurations.empty?) | |
| 39 | - all_configurations.each do |configuration| | |
| 40 | - all_names_and_ids[configuration.id] = configuration.name | |
| 41 | - end | |
| 42 | - end | |
| 37 | + all_names_and_ids = all_configurations.map { |configuration| [configuration.name, configuration.id] } | |
| 38 | + [["None", -1]] + (all_names_and_ids.sort { |x,y| x.first.downcase <=> y.first.downcase }) | |
| 43 | 39 | rescue Exception => exception |
| 44 | 40 | errors.add_to_base(exception.message) |
| 41 | + [["None", -1]] | |
| 45 | 42 | end |
| 46 | - all_names_and_ids | |
| 43 | + | |
| 47 | 44 | end |
| 48 | 45 | |
| 49 | 46 | def description=(value) |
| ... | ... | @@ -59,16 +56,16 @@ class MezuroPlugin::ConfigurationContent < Article |
| 59 | 56 | @description |
| 60 | 57 | end |
| 61 | 58 | |
| 62 | - def configuration_to_clone_name | |
| 59 | + def configuration_to_clone_id | |
| 63 | 60 | begin |
| 64 | - @configuration_to_clone_name | |
| 61 | + @configuration_to_clone_id | |
| 65 | 62 | rescue Exception => exception |
| 66 | 63 | nil |
| 67 | 64 | end |
| 68 | 65 | end |
| 69 | 66 | |
| 70 | - def configuration_to_clone_name=(value) | |
| 71 | - @configuration_to_clone_name = (value == "None") ? nil : value | |
| 67 | + def configuration_to_clone_id=(value) | |
| 68 | + @configuration_to_clone_id = (value == -1) ? nil : value | |
| 72 | 69 | end |
| 73 | 70 | |
| 74 | 71 | def metric_configurations |
| ... | ... | @@ -93,7 +90,7 @@ class MezuroPlugin::ConfigurationContent < Article |
| 93 | 90 | end |
| 94 | 91 | |
| 95 | 92 | def validate_configuration_name |
| 96 | - existing = configuration_names_and_ids.values.map { |a| a.downcase} | |
| 93 | + existing = configuration_names_and_ids.map { |a| a.first.downcase} | |
| 97 | 94 | |
| 98 | 95 | if existing.include?(name.downcase) |
| 99 | 96 | errors.add_to_base("Configuration name already exists in Kalibro") |
| ... | ... | @@ -111,11 +108,6 @@ class MezuroPlugin::ConfigurationContent < Article |
| 111 | 108 | clone_configuration if cloning_configuration? |
| 112 | 109 | end |
| 113 | 110 | |
| 114 | - def configuration_to_clone_id | |
| 115 | - @configuration_to_clone_id ||= (configuration_to_clone_name.nil?) ? nil : configuration_names_and_ids.index(configuration_to_clone_name) | |
| 116 | - @configuration_to_clone_id | |
| 117 | - end | |
| 118 | - | |
| 119 | 111 | def cloning_configuration? |
| 120 | 112 | !configuration_to_clone_id.nil? |
| 121 | 113 | end | ... | ... |
plugins/mezuro/test/fixtures/metric_configuration_fixtures.rb
| ... | ... | @@ -18,7 +18,7 @@ class MetricConfigurationFixtures |
| 18 | 18 | Kalibro::MetricConfiguration.new({ |
| 19 | 19 | :code => 'amloc', |
| 20 | 20 | :metric => MetricFixtures.amloc_hash, |
| 21 | - :base_tool_name => MetricFixtures.amloc_hash[:origin], | |
| 21 | + :base_tool_name => "Analizo", | |
| 22 | 22 | :weight => "1.0", |
| 23 | 23 | :aggregation_form => 'AVERAGE', |
| 24 | 24 | :reading_group_id => "31", |
| ... | ... | @@ -31,7 +31,7 @@ class MetricConfigurationFixtures |
| 31 | 31 | :id => "42", |
| 32 | 32 | :code => 'amloc', |
| 33 | 33 | :metric => MetricFixtures.amloc_hash, |
| 34 | - :base_tool_name => MetricFixtures.amloc_hash[:origin], | |
| 34 | + :base_tool_name => "Analizo", | |
| 35 | 35 | :weight => "1.0", |
| 36 | 36 | :aggregation_form => 'AVERAGE', |
| 37 | 37 | :reading_group_id => "31", | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin/configuration_content_test.rb
| ... | ... | @@ -59,10 +59,9 @@ class ConfigurationContentTest < ActiveSupport::TestCase |
| 59 | 59 | end |
| 60 | 60 | |
| 61 | 61 | should 'clone configuration' do |
| 62 | - clone_name = @configuration.name | |
| 63 | - @content.configuration_to_clone_name = clone_name | |
| 62 | + clone_id = @configuration.id | |
| 63 | + @content.configuration_to_clone_id = clone_id | |
| 64 | 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 | 65 | Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration.id).returns([@metric_configuration]) |
| 67 | 66 | Kalibro::MetricConfiguration.expects(:request).returns(:metric_configuration_id => @metric_configuration.id) |
| 68 | 67 | Kalibro::Range.expects(:ranges_of).with(@metric_configuration.id).returns([@range]) | ... | ... |
plugins/mezuro/views/cms/mezuro_plugin/_configuration_content.html.erb
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | <% |
| 4 | 4 | kalibro_configuration = @article.title.nil? ? nil : @article.kalibro_configuration |
| 5 | - kalibro_configuration_names = ["None"] + @article.configuration_names_and_ids.values.sort | |
| 5 | + configuration_names_and_ids = @article.configuration_names_and_ids | |
| 6 | 6 | %> |
| 7 | 7 | |
| 8 | 8 | <%= error_messages_for 'kalibro_configuration' %> |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | |
| 21 | 21 | <%= if kalibro_configuration.nil? |
| 22 | 22 | required labelled_form_field _('Clone Configuration'), |
| 23 | - f.select(:configuration_to_clone_name, kalibro_configuration_names) | |
| 23 | + f.select(:configuration_to_clone_id, configuration_names_and_ids) | |
| 24 | 24 | end %> |
| 25 | 25 | <br/> |
| 26 | 26 | ... | ... |