Commit ab0d054b3ab9b90b89365ac20e1a4cd09d10fb5b

Authored by Rafael Manzo
1 parent acba8492

Projects and ReadingGroups controllers delegate attributes deletion to the respective models

Signed off by: Heitor Reis <marcheing@gmail.com>
app/controllers/projects_controller.rb
... ... @@ -54,7 +54,6 @@ class ProjectsController &lt; ApplicationController
54 54 # DELETE /project/1.json
55 55 def destroy
56 56 set_project
57   - current_user.project_attributes.find_by_project_id!(@project.id).destroy
58 57 @project.destroy
59 58 respond_to do |format|
60 59 format.html { redirect_to projects_url }
... ...
app/controllers/reading_groups_controller.rb
... ... @@ -48,7 +48,6 @@ class ReadingGroupsController &lt; ApplicationController
48 48 # DELETE /reading_group/1
49 49 # DELETE /reading_group/1.json
50 50 def destroy
51   - current_user.reading_group_attributes.find_by_reading_group_id!(@reading_group.id).destroy
52 51 @reading_group.destroy
53 52 respond_to do |format|
54 53 format.html { redirect_to reading_groups_url }
... ...
spec/controllers/projects_controller_spec.rb
... ... @@ -97,14 +97,9 @@ describe ProjectsController, :type =&gt; :controller do
97 97  
98 98 context 'when the user owns the project' do
99 99 before :each do
100   - @project_attributes.expects(:destroy)
101 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 104 Project.expects(:find).with(@subject.id).returns(@subject)
110 105 delete :destroy, :id => @subject.id
... ...
spec/controllers/reading_groups_controller_spec.rb
... ... @@ -83,19 +83,12 @@ describe ReadingGroupsController, :type =&gt; :controller do
83 83 sign_in FactoryGirl.create(:user)
84 84 @ownership = FactoryGirl.build(:reading_group_attributes)
85 85 @ownerships = []
86   -
87 86 end
88 87  
89 88 context 'when the user owns the reading group' do
90 89 before :each do
91   - @ownership.expects(:destroy)
92 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 93 ReadingGroup.expects(:find).with(@subject.id).returns(@subject)
101 94 delete :destroy, :id => @subject.id
... ...