Commit 6965920bdefef9e8dc697eb4a1f30cf9faec4e72
1 parent
25d29c2d
Exists in
colab
and in
4 other branches
KalibroConfigurationsController#destroy leaves the attributes destroying to the model
Showing
3 changed files
with
6 additions
and
13 deletions
Show diff stats
app/controllers/kalibro_configurations_controller.rb
... | ... | @@ -54,12 +54,14 @@ class KalibroConfigurationsController < ApplicationController |
54 | 54 | # DELETE /kalibro_configurations/1.json |
55 | 55 | def destroy |
56 | 56 | set_kalibro_configuration |
57 | - current_user.kalibro_configuration_attributes.find_by_kalibro_configuration_id!(@kalibro_configuration.id).destroy | |
57 | + | |
58 | 58 | @kalibro_configuration.destroy |
59 | + | |
59 | 60 | respond_to do |format| |
60 | 61 | format.html { redirect_to kalibro_configurations_url } |
61 | 62 | format.json { head :no_content } |
62 | 63 | end |
64 | + | |
63 | 65 | Rails.cache.delete("#{@kalibro_configuration.id}_metrics") |
64 | 66 | end |
65 | 67 | ... | ... |
features/step_definitions/kalibro_configuration_steps.rb
... | ... | @@ -51,6 +51,7 @@ Then(/^I should be in the All configurations page$/) do |
51 | 51 | end |
52 | 52 | |
53 | 53 | Then(/^the sample configuration should not be there$/) do |
54 | + expect(@kalibro_configuration.attributes).to be_nil | |
54 | 55 | expect { KalibroConfiguration.find(@kalibro_configuration.id) }.to raise_error |
55 | 56 | end |
56 | 57 | ... | ... |
spec/controllers/kalibro_configurations_controller_spec.rb
... | ... | @@ -91,7 +91,6 @@ describe KalibroConfigurationsController, :type => :controller do |
91 | 91 | |
92 | 92 | context 'with an User logged in' do |
93 | 93 | let(:kalibro_configuration_attribute) { FactoryGirl.build(:kalibro_configuration_attributes) } |
94 | - let(:kalibro_configuration_attributes) { mock('kalibro_configuration_attributes') } | |
95 | 94 | |
96 | 95 | before do |
97 | 96 | sign_in FactoryGirl.create(:user) |
... | ... | @@ -99,16 +98,10 @@ describe KalibroConfigurationsController, :type => :controller do |
99 | 98 | |
100 | 99 | context 'when the user owns the kalibro_configuration' do |
101 | 100 | before :each do |
102 | - kalibro_configuration_attribute.expects(:destroy) | |
103 | 101 | kalibro_configuration.expects(:destroy) |
104 | - | |
105 | - #Those two mocks looks the same but they are necessary since params[:id] is a String and @configuration.id is an Integer :( | |
106 | - kalibro_configuration_attributes.expects(:find_by_kalibro_configuration_id).with("#{kalibro_configuration.id}").returns(kalibro_configuration_attribute) | |
107 | - kalibro_configuration_attributes.expects(:find_by_kalibro_configuration_id!).with(kalibro_configuration.id).returns(kalibro_configuration_attribute) | |
108 | - | |
109 | - User.any_instance.expects(:kalibro_configuration_attributes).at_least_once.returns(kalibro_configuration_attributes) | |
110 | - | |
111 | 102 | KalibroConfiguration.expects(:find).with(kalibro_configuration.id).returns(kalibro_configuration) |
103 | + subject.expects(:kalibro_configuration_owner?) | |
104 | + | |
112 | 105 | delete :destroy, :id => kalibro_configuration.id |
113 | 106 | end |
114 | 107 | |
... | ... | @@ -121,9 +114,6 @@ describe KalibroConfigurationsController, :type => :controller do |
121 | 114 | |
122 | 115 | context "when the user doesn't own the kalibro_configuration" do |
123 | 116 | before :each do |
124 | - kalibro_configuration_attributes.expects(:find_by_kalibro_configuration_id).with("#{kalibro_configuration.id}").returns(nil) | |
125 | - User.any_instance.expects(:kalibro_configuration_attributes).at_least_once.returns(kalibro_configuration_attributes) | |
126 | - | |
127 | 117 | delete :destroy, :id => kalibro_configuration.id |
128 | 118 | end |
129 | 119 | ... | ... |