Commit b51c937e6ceec5ecea483aa8fca4d9fe387598bb
Exists in
colab
and in
2 other branches
Merge pull request #331 from mezuro/compound_dont_show_hotspot
Make Compound Metric Config. metric list not include Hotspot metrics
Showing
7 changed files
with
70 additions
and
4 deletions
Show diff stats
CHANGELOG.rdoc
... | ... | @@ -11,6 +11,7 @@ Prezento is the web interface for Mezuro. |
11 | 11 | * Add latest configurations list to the homepage |
12 | 12 | * Move tutorials to mezuro.github.io |
13 | 13 | * Pluralize navigation menu links |
14 | +* Make Compound Metric Config. metric list not include Hotspot metrics | |
14 | 15 | * Fix 'Tree Metrics' and 'Hotspot Metrics' PT translations in Configuration show view |
15 | 16 | |
16 | 17 | == v0.11.3 - 01/04/2016 | ... | ... |
app/controllers/compound_metric_configurations_controller.rb
1 | 1 | class CompoundMetricConfigurationsController < BaseMetricConfigurationsController |
2 | + ALLOWED_METRIC_TYPES = %w(NativeMetricSnapshot CompoundMetricSnapshot) | |
3 | + | |
2 | 4 | before_action :set_metric_configurations, only: [:new, :edit] |
3 | 5 | |
4 | 6 | protected |
... | ... | @@ -11,8 +13,14 @@ class CompoundMetricConfigurationsController < BaseMetricConfigurationsControlle |
11 | 13 | params.require(:metric_configuration).permit(:reading_group_id, :weight, :metric => [:name, :description, :script, :code, :scope => [:type]]) |
12 | 14 | end |
13 | 15 | |
16 | + def allowed_metric_configurations(kalibro_configuration_id) | |
17 | + MetricConfiguration.metric_configurations_of(kalibro_configuration_id).select { |metric_configuration| | |
18 | + ALLOWED_METRIC_TYPES.include?(metric_configuration.metric.type) | |
19 | + } | |
20 | + end | |
21 | + | |
14 | 22 | def set_metric_configurations |
15 | - @metric_configurations = MetricConfiguration.metric_configurations_of(@kalibro_configuration.id) | |
23 | + @metric_configurations = allowed_metric_configurations(@kalibro_configuration.id) | |
16 | 24 | end |
17 | 25 | |
18 | 26 | def metric_type | ... | ... |
features/compound_metric_configuration/create.feature
... | ... | @@ -49,3 +49,16 @@ Feature: Compound Metric Configuration Creation |
49 | 49 | When I press the Save button |
50 | 50 | Then I should see "Code must be unique within a kalibro configuration" |
51 | 51 | |
52 | + @kalibro_configuration_restart @javascript | |
53 | + Scenario: compound metric configuration creation must not include non-tree metrics | |
54 | + Given I am a regular user | |
55 | + And I am signed in | |
56 | + And I own a sample configuration | |
57 | + And I have a reading group named "Scholar" | |
58 | + And I have a tree metric configuration | |
59 | + And I have a hotspot metric configuration | |
60 | + And I have a sample compound metric configuration within the given mezuro configuration | |
61 | + And I am at the Sample Configuration page | |
62 | + And I click the Add Metric link | |
63 | + When I click the Compound Metric link | |
64 | + Then I should see only tree and compound metrics in the Created Metrics list | ... | ... |
features/step_definitions/compound_metric_configuration_steps.rb
... | ... | @@ -40,3 +40,14 @@ Then(/^I should be at compound metric configuration sample page$/) do |
40 | 40 | expect(page).to have_content(@compound_metric_configuration.metric.name) |
41 | 41 | expect(page).to have_content("Ranges") |
42 | 42 | end |
43 | + | |
44 | +Then(/^I should see only tree and compound metrics in the Created Metrics list$/) do | |
45 | + metrics = MetricConfiguration.metric_configurations_of(@kalibro_configuration.id).map(&:metric) | |
46 | + metrics_by_code = Hash[metrics.map { |metric| [metric.code, metric] }] | |
47 | + | |
48 | + get_table_column_values('#created-metrics-accordion', 'Code') do |code| | |
49 | + metric = metrics_by_code[code] | |
50 | + expect(metric).not_to be_nil | |
51 | + expect(%w(NativeMetricSnapshot CompoundMetricSnapshot)).to include(metric.type) | |
52 | + end | |
53 | +end | ... | ... |
features/support/env.rb
... | ... | @@ -24,6 +24,7 @@ require 'warden' |
24 | 24 | require 'cucumber/rails' |
25 | 25 | require 'capybara/poltergeist' |
26 | 26 | require_relative 'header' |
27 | +require_relative 'tables' | |
27 | 28 | |
28 | 29 | #Capybara.default_driver = :poltergeist |
29 | 30 | Capybara.javascript_driver = :poltergeist |
... | ... | @@ -85,5 +86,4 @@ Cucumber::Rails::Database.javascript_strategy = :truncation |
85 | 86 | require 'kalibro_client/kalibro_cucumber_helpers/hooks.rb' |
86 | 87 | |
87 | 88 | Warden.test_mode! |
88 | -World(Warden::Test::Helpers, HeaderUtils) | |
89 | - | |
89 | +World(Warden::Test::Helpers, HeaderUtils, TableUtils) | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +module TableUtils | |
2 | + def get_table_column_values(selector, column) | |
3 | + column = column.strip | |
4 | + | |
5 | + within(selector) do | |
6 | + table_columns = all('th').map { |table_column| table_column.text.strip } | |
7 | + column_index = table_columns.index(column) | |
8 | + expect(column_index).not_to be_nil | |
9 | + | |
10 | + all("tr > td:nth-child(#{column_index + 1})").each do |element| | |
11 | + yield element.text.strip | |
12 | + end | |
13 | + end | |
14 | + end | |
15 | +end | ... | ... |
spec/controllers/compound_metric_configurations_controller_spec.rb
... | ... | @@ -4,6 +4,23 @@ describe CompoundMetricConfigurationsController, :type => :controller do |
4 | 4 | let(:reading_group) { FactoryGirl.build(:reading_group, :with_id) } |
5 | 5 | let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration, :with_id) } |
6 | 6 | |
7 | + describe 'allowed_metric_configurations' do | |
8 | + let(:metric_configurations) { [ | |
9 | + FactoryGirl.build(:metric_configuration, reading_group_id: reading_group.id), | |
10 | + FactoryGirl.build(:compound_metric_configuration, reading_group_id: reading_group.id), | |
11 | + FactoryGirl.build(:hotspot_metric_configuration), | |
12 | + ] } | |
13 | + let(:allowed_metric_configurations) { metric_configurations[0..1] } | |
14 | + | |
15 | + before :each do | |
16 | + MetricConfiguration.expects(:metric_configurations_of).with(kalibro_configuration.id).returns(metric_configurations) | |
17 | + end | |
18 | + | |
19 | + it 'is expected to filter out hotspot metric configurations' do | |
20 | + expect(subject.send(:allowed_metric_configurations, kalibro_configuration.id)).to eq(allowed_metric_configurations) | |
21 | + end | |
22 | + end | |
23 | + | |
7 | 24 | describe 'new' do |
8 | 25 | before :each do |
9 | 26 | sign_in FactoryGirl.create(:user) |
... | ... | @@ -11,10 +28,11 @@ describe CompoundMetricConfigurationsController, :type => :controller do |
11 | 28 | |
12 | 29 | context 'when the current user owns the kalibro configuration' do |
13 | 30 | let!(:metric_configuration) { FactoryGirl.build(:metric_configuration, reading_group_id: reading_group.id) } |
31 | + let(:metric_configurations) { [metric_configuration] } | |
14 | 32 | before :each do |
15 | 33 | KalibroConfiguration.expects(:find).with(kalibro_configuration.id).returns kalibro_configuration |
16 | 34 | subject.expects(:kalibro_configuration_owner?).returns true |
17 | - MetricConfiguration.expects(:metric_configurations_of).with(kalibro_configuration.id).returns([metric_configuration]) | |
35 | + subject.expects(:allowed_metric_configurations).with(kalibro_configuration.id).returns metric_configurations | |
18 | 36 | |
19 | 37 | get :new, kalibro_configuration_id: kalibro_configuration.id |
20 | 38 | end | ... | ... |