Commit 170be947c9b95643e91b586e9bcb4062e7649b9d
1 parent
f59fbe22
Exists in
colab
and in
4 other branches
Renamed BaseConfigurationsController to BaseMetricConfigurationsController
Showing
6 changed files
with
54 additions
and
54 deletions
Show diff stats
app/controllers/base_configurations_controller.rb
| ... | ... | @@ -1,45 +0,0 @@ |
| 1 | -include OwnershipAuthentication | |
| 2 | -include MetricConfigurationsConcern | |
| 3 | - | |
| 4 | -class BaseConfigurationsController < ApplicationController | |
| 5 | - before_action :authenticate_user!, except: [:show, :index] | |
| 6 | - before_action :metric_configuration_owner?, only: [:edit, :update, :destroy] | |
| 7 | - before_action :mezuro_configuration_owner?, only: [:new, :create, :choose_metric] | |
| 8 | - before_action :set_metric_configuration, only: [:show, :edit, :update, :destroy] | |
| 9 | - | |
| 10 | - def new | |
| 11 | - update_metric_configuration(MetricConfiguration.new) | |
| 12 | - metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i | |
| 13 | - end | |
| 14 | - | |
| 15 | - def show | |
| 16 | - if metric_configuration | |
| 17 | - @reading_group = ReadingGroup.find(metric_configuration.reading_group_id) | |
| 18 | - @mezuro_ranges = metric_configuration.mezuro_ranges | |
| 19 | - metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i | |
| 20 | - else | |
| 21 | - raise NotImplementedError | |
| 22 | - end | |
| 23 | - end | |
| 24 | - | |
| 25 | - def create | |
| 26 | - update_metric_configuration(MetricConfiguration.new(metric_configuration_params)) | |
| 27 | - metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i | |
| 28 | - end | |
| 29 | - | |
| 30 | - protected | |
| 31 | - | |
| 32 | - def metric_configuration | |
| 33 | - raise NotImplementedError | |
| 34 | - end | |
| 35 | - | |
| 36 | - def update_metric_configuration (new_metric_configuration) | |
| 37 | - raise NotImplementedError | |
| 38 | - end | |
| 39 | - | |
| 40 | - # Never trust parameters from the scary internet, only allow the white list through. | |
| 41 | - # TODO: this should be refactored to the concern metric configuration | |
| 42 | - def metric_configuration_params | |
| 43 | - params[:metric_configuration] | |
| 44 | - end | |
| 45 | -end | |
| 46 | 0 | \ No newline at end of file |
app/controllers/base_metric_configurations_controller.rb
0 → 100644
| ... | ... | @@ -0,0 +1,45 @@ |
| 1 | +include OwnershipAuthentication | |
| 2 | +include MetricConfigurationsConcern | |
| 3 | + | |
| 4 | +class BaseMetricConfigurationsController < ApplicationController | |
| 5 | + before_action :authenticate_user!, except: [:show, :index] | |
| 6 | + before_action :metric_configuration_owner?, only: [:edit, :update, :destroy] | |
| 7 | + before_action :mezuro_configuration_owner?, only: [:new, :create, :choose_metric] | |
| 8 | + before_action :set_metric_configuration, only: [:show, :edit, :update, :destroy] | |
| 9 | + | |
| 10 | + def new | |
| 11 | + update_metric_configuration(MetricConfiguration.new) | |
| 12 | + metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i | |
| 13 | + end | |
| 14 | + | |
| 15 | + def show | |
| 16 | + if metric_configuration | |
| 17 | + @reading_group = ReadingGroup.find(metric_configuration.reading_group_id) | |
| 18 | + @mezuro_ranges = metric_configuration.mezuro_ranges | |
| 19 | + metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i | |
| 20 | + else | |
| 21 | + raise NotImplementedError | |
| 22 | + end | |
| 23 | + end | |
| 24 | + | |
| 25 | + def create | |
| 26 | + update_metric_configuration(MetricConfiguration.new(metric_configuration_params)) | |
| 27 | + metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i | |
| 28 | + end | |
| 29 | + | |
| 30 | + protected | |
| 31 | + | |
| 32 | + def metric_configuration | |
| 33 | + raise NotImplementedError | |
| 34 | + end | |
| 35 | + | |
| 36 | + def update_metric_configuration (new_metric_configuration) | |
| 37 | + raise NotImplementedError | |
| 38 | + end | |
| 39 | + | |
| 40 | + # Never trust parameters from the scary internet, only allow the white list through. | |
| 41 | + # TODO: this should be refactored to the concern metric configuration | |
| 42 | + def metric_configuration_params | |
| 43 | + params[:metric_configuration] | |
| 44 | + end | |
| 45 | +end | |
| 0 | 46 | \ No newline at end of file | ... | ... |
app/controllers/compound_metric_configurations_controller.rb
app/controllers/concerns/ownership_authentication.rb
| ... | ... | @@ -16,7 +16,7 @@ module OwnershipAuthentication |
| 16 | 16 | def repository_owner? |
| 17 | 17 | check_project_ownership(params[:project_id]) |
| 18 | 18 | end |
| 19 | - | |
| 19 | + | |
| 20 | 20 | def reading_group_owner? |
| 21 | 21 | if self.kind_of?(ReadingGroupsController) |
| 22 | 22 | id = params[:id] |
| ... | ... | @@ -36,7 +36,7 @@ module OwnershipAuthentication |
| 36 | 36 | def mezuro_configuration_owner? |
| 37 | 37 | if self.kind_of?(MezuroConfigurationsController) |
| 38 | 38 | id = params[:id] |
| 39 | - elsif (self.kind_of?(BaseConfigurationsController)) | |
| 39 | + elsif (self.kind_of?(BaseMetricConfigurationsController)) | |
| 40 | 40 | id = params[:mezuro_configuration_id] |
| 41 | 41 | else |
| 42 | 42 | raise "Not supported" | ... | ... |
app/controllers/metric_configurations_controller.rb
| 1 | -class MetricConfigurationsController < BaseConfigurationsController | |
| 1 | +class MetricConfigurationsController < BaseMetricConfigurationsController | |
| 2 | 2 | def choose_metric |
| 3 | 3 | @mezuro_configuration_id = params[:mezuro_configuration_id].to_i |
| 4 | 4 | @metric_configuration_id = params[:metric_configuration_id].to_i | ... | ... |
spec/controllers/base_metric_configurations_controller_spec.rb
| 1 | 1 | require 'spec_helper' |
| 2 | 2 | |
| 3 | -class CleanInheritsFromBaseConfigurationsController < BaseConfigurationsController | |
| 3 | +class CleanInheritsFromBaseMetricConfigurationsController < BaseMetricConfigurationsController | |
| 4 | 4 | def metric_configuration; super; end |
| 5 | 5 | def update_metric_configuration (new_metric_configuration); super; end |
| 6 | 6 | end |
| 7 | 7 | |
| 8 | -class InheritsFromBaseConfigurationsController < BaseConfigurationsController | |
| 8 | +class InheritsFromBaseMetricConfigurationsController < BaseMetricConfigurationsController | |
| 9 | 9 | def new |
| 10 | 10 | render :nothing => true |
| 11 | 11 | super |
| ... | ... | @@ -40,14 +40,14 @@ class InheritsFromBaseConfigurationsController < BaseConfigurationsController |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | 42 | |
| 43 | -describe InheritsFromBaseConfigurationsController do | |
| 43 | +describe InheritsFromBaseMetricConfigurationsController do | |
| 44 | 44 | let(:mezuro_configuration) { FactoryGirl.build(:mezuro_configuration) } |
| 45 | 45 | |
| 46 | 46 | before do |
| 47 | 47 | Rails.application.routes.draw do |
| 48 | 48 | resources :mezuro_configurations do |
| 49 | 49 | match '/metric_configurations/choose_metric' => 'metric_configurations#choose_metric', as: :choose_metric, :via => [:get] |
| 50 | - resources :inherits_from_base_configurations do | |
| 50 | + resources :inherits_from_base_metric_configurations do | |
| 51 | 51 | match '/metric_configurations/new' => 'metric_configurations#new', as: :new_metric_configuration, :via => [:post] |
| 52 | 52 | match '/metric_configurations/:id' => 'metric_configurations#update', as: :metric_configuration_update, :via => [:put] |
| 53 | 53 | end |
| ... | ... | @@ -141,7 +141,7 @@ describe InheritsFromBaseConfigurationsController do |
| 141 | 141 | |
| 142 | 142 | |
| 143 | 143 | context 'with a inheritance without overrides methods' do |
| 144 | - subject { CleanInheritsFromBaseConfigurationsController.new } | |
| 144 | + subject { CleanInheritsFromBaseMetricConfigurationsController.new } | |
| 145 | 145 | |
| 146 | 146 | describe 'metric_configuration' do |
| 147 | 147 | it 'should raise a NotImplementedError' do | ... | ... |