diff --git a/app/controllers/metric_configurations_controller.rb b/app/controllers/metric_configurations_controller.rb
index 10c0cde..8f1c3e4 100644
--- a/app/controllers/metric_configurations_controller.rb
+++ b/app/controllers/metric_configurations_controller.rb
@@ -18,7 +18,11 @@ class MetricConfigurationsController < ApplicationController
def create
@metric_configuration = MetricConfiguration.new(metric_configuration_params)
+ @base_tool_name = params[:base_tool_name]
+ @metric = KalibroGem::Entities::BaseTool.find_by_name(params[:base_tool_name]).metric(params[:metric_name])
@metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i
+ @metric_configuration.metric = @metric
+ @metric_configuration.base_tool_name = @base_tool_name
respond_to do |format|
create_and_redir(format)
end
diff --git a/app/helpers/metric_configurations_helper.rb b/app/helpers/metric_configurations_helper.rb
index 29ee69b..f737046 100644
--- a/app/helpers/metric_configurations_helper.rb
+++ b/app/helpers/metric_configurations_helper.rb
@@ -3,5 +3,9 @@ module MetricConfigurationsHelper
[["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],
["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]]
end
+
+ def reading_group_options
+ ReadingGroup.all.map { |reading_group| [reading_group.name, reading_group.id] }
+ end
end
diff --git a/app/views/metric_configurations/_form.html.erb b/app/views/metric_configurations/_form.html.erb
index 09d0bf5..ee87701 100644
--- a/app/views/metric_configurations/_form.html.erb
+++ b/app/views/metric_configurations/_form.html.erb
@@ -15,6 +15,14 @@
<%= f.select( :aggregation_form, aggregation_options, {class: 'form-control'} ) %>
+
+ <%= f.label :reading_group_id, 'Reading Group', class: 'control-label' %>
+ <%= f.select( :reading_group_id, reading_group_options, {class: 'form-control'} ) %>
+
+
+<%= hidden_field_tag(:metric_name, @metric.name) %>
+<%= hidden_field_tag(:base_tool_name, @base_tool_name) %>
+
<%= f.submit 'Save', class: 'btn btn-primary' %>
<%= link_to 'Back', mezuro_configuration_path(@mezuro_configuration_id), class: 'btn btn-default' %>
diff --git a/app/views/mezuro_configurations/_metric_configurations.html.erb b/app/views/mezuro_configurations/_metric_configurations.html.erb
index 1125d99..6e30813 100644
--- a/app/views/mezuro_configurations/_metric_configurations.html.erb
+++ b/app/views/mezuro_configurations/_metric_configurations.html.erb
@@ -4,7 +4,7 @@
<%= metric_configuration.weight %> |
<% if mezuro_configuration_owner? @mezuro_configuration.id %>
- <%= link_to 'Edit', edit_mezuro_configuration_metric_configurations_path(@mezuro_configuration.id, metric_configuration.id),
+ <%= link_to 'Edit', edit_mezuro_configuration_metric_configuration_path(@mezuro_configuration.id, metric_configuration.id),
class: 'btn btn-info' %>
|
diff --git a/features/metric_configuration/create.feature b/features/metric_configuration/create.feature
index 7b298c0..607edd1 100644
--- a/features/metric_configuration/create.feature
+++ b/features/metric_configuration/create.feature
@@ -14,17 +14,16 @@ Feature: Metric Configuration Creation
Given I am a regular user
And I am signed in
And I own a sample configuration
- And I have a reading group named "Schoolar"
+ And I have a reading group named "Scholar"
And I am at the Sample Configuration page
And I click the Add Metric link
+ And I click the "Analizo" h3
+ And I click the Total Lines of Code link
And I fill the Code field with "My Code"
- And I set the select field "BaseTool" as "Analizo"
- And I set the select field "Metric" as "Lines Of Code"
- And I fill the Description field with "Web Service to collect metrics"
- And I fill the Weigth field with "2"
- And I set the select field "AgregationForm" as "Average"
- And I set the select field "ReadingGroup" as "Schoolar"
+ And I fill the Weight field with "2"
+ And I set the select field "Aggregation Form" as "Average"
+ And I set the select field "Reading Group" as "Scholar"
When I press the Save button
Then I should see "My Code"
- Then I should see "Lines Of Code"
+ Then I should see "Total Lines of Code"
Then I should see "2"
\ No newline at end of file
diff --git a/spec/controllers/metric_configurations_controller_spec.rb b/spec/controllers/metric_configurations_controller_spec.rb
index 93e1686..db84435 100644
--- a/spec/controllers/metric_configurations_controller_spec.rb
+++ b/spec/controllers/metric_configurations_controller_spec.rb
@@ -51,6 +51,7 @@ describe MetricConfigurationsController do
describe 'create' do
let(:metric_configuration_params) { Hash[FactoryGirl.attributes_for(:metric_configuration).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers
let(:mezuro_configuration) {FactoryGirl.build(:mezuro_configuration)}
+ let(:base_tool) { FactoryGirl.build(:base_tool) }
before do
sign_in FactoryGirl.create(:user)
@@ -64,8 +65,9 @@ describe MetricConfigurationsController do
context 'with valid fields' do
before :each do
MetricConfiguration.any_instance.expects(:save).returns(true)
+ KalibroGem::Entities::BaseTool.expects(:find_by_name).with(base_tool.name).returns(base_tool)
- post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params
+ post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, base_tool_name: base_tool.name
end
it { should respond_with(:redirect) }
@@ -74,8 +76,9 @@ describe MetricConfigurationsController do
context 'with invalid fields' do
before :each do
MetricConfiguration.any_instance.expects(:save).returns(false)
+ KalibroGem::Entities::BaseTool.expects(:find_by_name).with(base_tool.name).returns(base_tool)
- post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params
+ post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, base_tool_name: base_tool.name
end
it { should render_template(:new) }
diff --git a/spec/helpers/metric_configurations_helper_spec.rb b/spec/helpers/metric_configurations_helper_spec.rb
index 80386d2..82c9fd9 100644
--- a/spec/helpers/metric_configurations_helper_spec.rb
+++ b/spec/helpers/metric_configurations_helper_spec.rb
@@ -7,4 +7,16 @@ describe MetricConfigurationsHelper do
["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]]
end
end
+
+ describe 'reading_group_options' do
+ let! (:reading_group) { FactoryGirl.build(:reading_group) }
+
+ before :each do
+ ReadingGroup.expects(:all).returns([reading_group])
+ end
+
+ it 'should return a pair with the reading group name and id' do
+ helper.reading_group_options.should eq [[reading_group.name, reading_group.id]]
+ end
+ end
end
--
libgit2 0.21.2 |