Commit 52d84ce721d4cb6122a19de03d5d1691c7a6d985
Committed by
Rafael Manzo
1 parent
e08ecf84
Exists in
colab
and in
4 other branches
Edit feature for metric configuration
Pending acceptance test Still missing update feature Implemented persisted method for metric configuration model signed-off-by: Guilherme Rojas V. de Lima <guilhermehrojas@gmail.com>
Showing
4 changed files
with
59 additions
and
3 deletions
Show diff stats
app/controllers/metric_configurations_controller.rb
@@ -2,8 +2,8 @@ include OwnershipAuthentication | @@ -2,8 +2,8 @@ include OwnershipAuthentication | ||
2 | 2 | ||
3 | class MetricConfigurationsController < ApplicationController | 3 | class MetricConfigurationsController < ApplicationController |
4 | before_action :authenticate_user!, except: [:index] | 4 | before_action :authenticate_user!, except: [:index] |
5 | - before_action :set_metric_configuration, only: [:destroy] | ||
6 | - before_action :metric_configuration_owner?, only: [:destroy] | 5 | + before_action :set_metric_configuration, only: [:edit, :destroy] |
6 | + before_action :metric_configuration_owner?, only: [:edit, :destroy] | ||
7 | before_action :mezuro_configuration_owner?, only: [:new, :create, :choose_metric] | 7 | before_action :mezuro_configuration_owner?, only: [:new, :create, :choose_metric] |
8 | 8 | ||
9 | def choose_metric | 9 | def choose_metric |
@@ -28,6 +28,11 @@ class MetricConfigurationsController < ApplicationController | @@ -28,6 +28,11 @@ class MetricConfigurationsController < ApplicationController | ||
28 | end | 28 | end |
29 | end | 29 | end |
30 | 30 | ||
31 | + def edit | ||
32 | + @mezuro_configuration_id = params[:mezuro_configuration_id] | ||
33 | + @metric_configuration.configuration_id = @mezuro_configuration_id | ||
34 | + end | ||
35 | + | ||
31 | def destroy | 36 | def destroy |
32 | @metric_configuration.destroy | 37 | @metric_configuration.destroy |
33 | respond_to do |format| | 38 | respond_to do |format| |
app/models/metric_configuration.rb
@@ -9,4 +9,8 @@ class MetricConfiguration < KalibroGem::Entities::MetricConfiguration | @@ -9,4 +9,8 @@ class MetricConfiguration < KalibroGem::Entities::MetricConfiguration | ||
9 | validates :weight, presence: true | 9 | validates :weight, presence: true |
10 | validates :aggregation_form, presence: true | 10 | validates :aggregation_form, presence: true |
11 | 11 | ||
12 | + def persisted? | ||
13 | + self.id != nil #FIXME: create method exists in KalibroGem | ||
14 | + end | ||
15 | + | ||
12 | end | 16 | end |
@@ -0,0 +1,7 @@ | @@ -0,0 +1,7 @@ | ||
1 | +<div class="page-header"> | ||
2 | + <h1>Editing Metric Configuration</h1> | ||
3 | +</div> | ||
4 | + | ||
5 | +<%= form_for(@metric_configuration, :url => mezuro_configuration_metric_configuration_update_url(@mezuro_configuration_id, @metric_configuration.id), method: :put) do |f| %> | ||
6 | + <%= render partial: 'form', locals: {f: f} %> | ||
7 | +<% end %> |
spec/controllers/metric_configurations_controller_spec.rb
@@ -85,6 +85,46 @@ describe MetricConfigurationsController do | @@ -85,6 +85,46 @@ describe MetricConfigurationsController do | ||
85 | end | 85 | end |
86 | end | 86 | end |
87 | 87 | ||
88 | + describe 'edit' do | ||
89 | + let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | ||
90 | + | ||
91 | + context 'with an User logged in' do | ||
92 | + before do | ||
93 | + sign_in FactoryGirl.create(:user) | ||
94 | + end | ||
95 | + | ||
96 | + context 'when the user owns the metric configuration' do | ||
97 | + before :each do | ||
98 | + subject.expects(:metric_configuration_owner?).returns true | ||
99 | + MetricConfiguration.expects(:find).at_least_once.with(metric_configuration.id).returns(metric_configuration) | ||
100 | + get :edit, id: metric_configuration.id, mezuro_configuration_id: metric_configuration.configuration_id.to_s | ||
101 | + end | ||
102 | + | ||
103 | + it { should render_template(:edit) } | ||
104 | + end | ||
105 | + | ||
106 | + context 'when the user does not own the metric configuration' do | ||
107 | + before do | ||
108 | + MetricConfiguration.expects(:find).at_least_once.with(metric_configuration.id).returns(metric_configuration) | ||
109 | + get :edit, id: metric_configuration.id, mezuro_configuration_id: metric_configuration.configuration_id.to_s | ||
110 | + end | ||
111 | + | ||
112 | + it { should redirect_to(mezuro_configurations_path) } #FIXME : It should redirect to configuration show page | ||
113 | + it { should respond_with(:redirect) } | ||
114 | + it { should set_the_flash[:notice].to("You're not allowed to do this operation") } | ||
115 | + end | ||
116 | + end | ||
117 | + | ||
118 | + context 'with no user logged in' do | ||
119 | + before :each do | ||
120 | + get :edit, id: metric_configuration.id, mezuro_configuration_id: metric_configuration.configuration_id.to_s | ||
121 | + end | ||
122 | + | ||
123 | + it { should redirect_to new_user_session_path } | ||
124 | + end | ||
125 | + end | ||
126 | + | ||
127 | + | ||
88 | describe 'destroy' do | 128 | describe 'destroy' do |
89 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | 129 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } |
90 | 130 | ||
@@ -110,7 +150,7 @@ describe MetricConfigurationsController do | @@ -110,7 +150,7 @@ describe MetricConfigurationsController do | ||
110 | before :each do | 150 | before :each do |
111 | MetricConfiguration.expects(:find).at_least_once.with(metric_configuration.id).returns(metric_configuration) | 151 | MetricConfiguration.expects(:find).at_least_once.with(metric_configuration.id).returns(metric_configuration) |
112 | 152 | ||
113 | - delete :destroy, id: metric_configuration.id, mezuro_configuration_id: mezuro_configuration.id.to_s | 153 | + delete :destroy, id: metric_configuration.id, mezuro_configuration_id: metric_configuration.configuration_id.to_s |
114 | end | 154 | end |
115 | 155 | ||
116 | it { should redirect_to(mezuro_configurations_path) } #FIXME : It should redirect to configuration show page | 156 | it { should redirect_to(mezuro_configurations_path) } #FIXME : It should redirect to configuration show page |