Commit ab0d054b3ab9b90b89365ac20e1a4cd09d10fb5b
1 parent
acba8492
Exists in
colab
and in
4 other branches
Projects and ReadingGroups controllers delegate attributes deletion to the respective models
Signed off by: Heitor Reis <marcheing@gmail.com>
Showing
4 changed files
with
2 additions
and
16 deletions
Show diff stats
app/controllers/projects_controller.rb
@@ -54,7 +54,6 @@ class ProjectsController < ApplicationController | @@ -54,7 +54,6 @@ class ProjectsController < ApplicationController | ||
54 | # DELETE /project/1.json | 54 | # DELETE /project/1.json |
55 | def destroy | 55 | def destroy |
56 | set_project | 56 | set_project |
57 | - current_user.project_attributes.find_by_project_id!(@project.id).destroy | ||
58 | @project.destroy | 57 | @project.destroy |
59 | respond_to do |format| | 58 | respond_to do |format| |
60 | format.html { redirect_to projects_url } | 59 | format.html { redirect_to projects_url } |
app/controllers/reading_groups_controller.rb
@@ -48,7 +48,6 @@ class ReadingGroupsController < ApplicationController | @@ -48,7 +48,6 @@ class ReadingGroupsController < ApplicationController | ||
48 | # DELETE /reading_group/1 | 48 | # DELETE /reading_group/1 |
49 | # DELETE /reading_group/1.json | 49 | # DELETE /reading_group/1.json |
50 | def destroy | 50 | def destroy |
51 | - current_user.reading_group_attributes.find_by_reading_group_id!(@reading_group.id).destroy | ||
52 | @reading_group.destroy | 51 | @reading_group.destroy |
53 | respond_to do |format| | 52 | respond_to do |format| |
54 | format.html { redirect_to reading_groups_url } | 53 | format.html { redirect_to reading_groups_url } |
spec/controllers/projects_controller_spec.rb
@@ -97,14 +97,9 @@ describe ProjectsController, :type => :controller do | @@ -97,14 +97,9 @@ describe ProjectsController, :type => :controller do | ||
97 | 97 | ||
98 | context 'when the user owns the project' do | 98 | context 'when the user owns the project' do |
99 | before :each do | 99 | before :each do |
100 | - @project_attributes.expects(:destroy) | ||
101 | @subject.expects(:destroy) | 100 | @subject.expects(:destroy) |
102 | 101 | ||
103 | - #Those two mocks looks the same but they are necessary since params[:id] is a String and @project.id is an Integer :( | ||
104 | - @attributes.expects(:find_by_project_id).with("#{@subject.id}").returns(@project_attributes) | ||
105 | - @attributes.expects(:find_by_project_id!).with(@subject.id).returns(@project_attributes) | ||
106 | - | ||
107 | - User.any_instance.expects(:project_attributes).at_least_once.returns(@attributes) | 102 | + subject.expects(:project_owner?) |
108 | 103 | ||
109 | Project.expects(:find).with(@subject.id).returns(@subject) | 104 | Project.expects(:find).with(@subject.id).returns(@subject) |
110 | delete :destroy, :id => @subject.id | 105 | delete :destroy, :id => @subject.id |
spec/controllers/reading_groups_controller_spec.rb
@@ -83,19 +83,12 @@ describe ReadingGroupsController, :type => :controller do | @@ -83,19 +83,12 @@ describe ReadingGroupsController, :type => :controller do | ||
83 | sign_in FactoryGirl.create(:user) | 83 | sign_in FactoryGirl.create(:user) |
84 | @ownership = FactoryGirl.build(:reading_group_attributes) | 84 | @ownership = FactoryGirl.build(:reading_group_attributes) |
85 | @ownerships = [] | 85 | @ownerships = [] |
86 | - | ||
87 | end | 86 | end |
88 | 87 | ||
89 | context 'when the user owns the reading group' do | 88 | context 'when the user owns the reading group' do |
90 | before :each do | 89 | before :each do |
91 | - @ownership.expects(:destroy) | ||
92 | @subject.expects(:destroy) | 90 | @subject.expects(:destroy) |
93 | - | ||
94 | - #Those two mocks looks the same but they are necessary since params[:id] is a String and @ReadingGroup.id is an Integer :( | ||
95 | - @ownerships.expects(:find_by_reading_group_id).with("#{@subject.id}").returns(@ownership) | ||
96 | - @ownerships.expects(:find_by_reading_group_id!).with(@subject.id).returns(@ownership) | ||
97 | - | ||
98 | - User.any_instance.expects(:reading_group_attributes).at_least_once.returns(@ownerships) | 91 | + subject.expects(:reading_group_owner?) |
99 | 92 | ||
100 | ReadingGroup.expects(:find).with(@subject.id).returns(@subject) | 93 | ReadingGroup.expects(:find).with(@subject.id).returns(@subject) |
101 | delete :destroy, :id => @subject.id | 94 | delete :destroy, :id => @subject.id |