Commit 27eeb8a0e6310d0298c4b0241582cd4601610aaa
1 parent
03e491a7
Exists in
colab
and in
4 other branches
Fixed ReadingGroup creation
Showing
7 changed files
with
41 additions
and
11 deletions
Show diff stats
app/controllers/metric_configurations_controller.rb
... | ... | @@ -18,7 +18,11 @@ class MetricConfigurationsController < ApplicationController |
18 | 18 | |
19 | 19 | def create |
20 | 20 | @metric_configuration = MetricConfiguration.new(metric_configuration_params) |
21 | + @base_tool_name = params[:base_tool_name] | |
22 | + @metric = KalibroGem::Entities::BaseTool.find_by_name(params[:base_tool_name]).metric(params[:metric_name]) | |
21 | 23 | @metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i |
24 | + @metric_configuration.metric = @metric | |
25 | + @metric_configuration.base_tool_name = @base_tool_name | |
22 | 26 | respond_to do |format| |
23 | 27 | create_and_redir(format) |
24 | 28 | end | ... | ... |
app/helpers/metric_configurations_helper.rb
... | ... | @@ -3,5 +3,9 @@ module MetricConfigurationsHelper |
3 | 3 | [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"], |
4 | 4 | ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] |
5 | 5 | end |
6 | + | |
7 | + def reading_group_options | |
8 | + ReadingGroup.all.map { |reading_group| [reading_group.name, reading_group.id] } | |
9 | + end | |
6 | 10 | end |
7 | 11 | ... | ... |
app/views/metric_configurations/_form.html.erb
... | ... | @@ -15,6 +15,14 @@ |
15 | 15 | <%= f.select( :aggregation_form, aggregation_options, {class: 'form-control'} ) %> |
16 | 16 | </div> |
17 | 17 | |
18 | +<div class="form-group"> | |
19 | + <%= f.label :reading_group_id, 'Reading Group', class: 'control-label' %> | |
20 | + <%= f.select( :reading_group_id, reading_group_options, {class: 'form-control'} ) %> | |
21 | +</div> | |
22 | + | |
23 | +<%= hidden_field_tag(:metric_name, @metric.name) %> | |
24 | +<%= hidden_field_tag(:base_tool_name, @base_tool_name) %> | |
25 | + | |
18 | 26 | <br> |
19 | 27 | <%= f.submit 'Save', class: 'btn btn-primary' %> |
20 | 28 | <%= link_to 'Back', mezuro_configuration_path(@mezuro_configuration_id), class: 'btn btn-default' %> | ... | ... |
app/views/mezuro_configurations/_metric_configurations.html.erb
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | <td><%= metric_configuration.weight %></td> |
5 | 5 | <% if mezuro_configuration_owner? @mezuro_configuration.id %> |
6 | 6 | <td> |
7 | - <%= link_to 'Edit', edit_mezuro_configuration_metric_configurations_path(@mezuro_configuration.id, metric_configuration.id), | |
7 | + <%= link_to 'Edit', edit_mezuro_configuration_metric_configuration_path(@mezuro_configuration.id, metric_configuration.id), | |
8 | 8 | class: 'btn btn-info' %> |
9 | 9 | </td> |
10 | 10 | <td> | ... | ... |
features/metric_configuration/create.feature
... | ... | @@ -14,17 +14,16 @@ Feature: Metric Configuration Creation |
14 | 14 | Given I am a regular user |
15 | 15 | And I am signed in |
16 | 16 | And I own a sample configuration |
17 | - And I have a reading group named "Schoolar" | |
17 | + And I have a reading group named "Scholar" | |
18 | 18 | And I am at the Sample Configuration page |
19 | 19 | And I click the Add Metric link |
20 | + And I click the "Analizo" h3 | |
21 | + And I click the Total Lines of Code link | |
20 | 22 | And I fill the Code field with "My Code" |
21 | - And I set the select field "BaseTool" as "Analizo" | |
22 | - And I set the select field "Metric" as "Lines Of Code" | |
23 | - And I fill the Description field with "Web Service to collect metrics" | |
24 | - And I fill the Weigth field with "2" | |
25 | - And I set the select field "AgregationForm" as "Average" | |
26 | - And I set the select field "ReadingGroup" as "Schoolar" | |
23 | + And I fill the Weight field with "2" | |
24 | + And I set the select field "Aggregation Form" as "Average" | |
25 | + And I set the select field "Reading Group" as "Scholar" | |
27 | 26 | When I press the Save button |
28 | 27 | Then I should see "My Code" |
29 | - Then I should see "Lines Of Code" | |
28 | + Then I should see "Total Lines of Code" | |
30 | 29 | Then I should see "2" |
31 | 30 | \ No newline at end of file | ... | ... |
spec/controllers/metric_configurations_controller_spec.rb
... | ... | @@ -51,6 +51,7 @@ describe MetricConfigurationsController do |
51 | 51 | describe 'create' do |
52 | 52 | 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 |
53 | 53 | let(:mezuro_configuration) {FactoryGirl.build(:mezuro_configuration)} |
54 | + let(:base_tool) { FactoryGirl.build(:base_tool) } | |
54 | 55 | |
55 | 56 | before do |
56 | 57 | sign_in FactoryGirl.create(:user) |
... | ... | @@ -64,8 +65,9 @@ describe MetricConfigurationsController do |
64 | 65 | context 'with valid fields' do |
65 | 66 | before :each do |
66 | 67 | MetricConfiguration.any_instance.expects(:save).returns(true) |
68 | + KalibroGem::Entities::BaseTool.expects(:find_by_name).with(base_tool.name).returns(base_tool) | |
67 | 69 | |
68 | - post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params | |
70 | + post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, base_tool_name: base_tool.name | |
69 | 71 | end |
70 | 72 | |
71 | 73 | it { should respond_with(:redirect) } |
... | ... | @@ -74,8 +76,9 @@ describe MetricConfigurationsController do |
74 | 76 | context 'with invalid fields' do |
75 | 77 | before :each do |
76 | 78 | MetricConfiguration.any_instance.expects(:save).returns(false) |
79 | + KalibroGem::Entities::BaseTool.expects(:find_by_name).with(base_tool.name).returns(base_tool) | |
77 | 80 | |
78 | - post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params | |
81 | + post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, base_tool_name: base_tool.name | |
79 | 82 | end |
80 | 83 | |
81 | 84 | it { should render_template(:new) } | ... | ... |
spec/helpers/metric_configurations_helper_spec.rb
... | ... | @@ -7,4 +7,16 @@ describe MetricConfigurationsHelper do |
7 | 7 | ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] |
8 | 8 | end |
9 | 9 | end |
10 | + | |
11 | + describe 'reading_group_options' do | |
12 | + let! (:reading_group) { FactoryGirl.build(:reading_group) } | |
13 | + | |
14 | + before :each do | |
15 | + ReadingGroup.expects(:all).returns([reading_group]) | |
16 | + end | |
17 | + | |
18 | + it 'should return a pair with the reading group name and id' do | |
19 | + helper.reading_group_options.should eq [[reading_group.name, reading_group.id]] | |
20 | + end | |
21 | + end | |
10 | 22 | end | ... | ... |