Ticket #3352: hardened_scaffold.2.diff
| File hardened_scaffold.2.diff, 8.5 kB (added by nils@alumni.rice.edu, 3 years ago) |
|---|
-
railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb
old new 38 38 assert_not_nil assigns(:<%= plural_name %>) 39 39 end 40 40 41 def test_show<%= suffix %> 41 def test_show<%= suffix %>_with_id 42 42 get :show<%= suffix %>, :id => 1 43 43 44 44 assert_response :success 45 assert_template 'show '45 assert_template 'show<%= suffix %>' 46 46 47 47 assert_not_nil assigns(:<%= singular_name %>) 48 48 assert assigns(:<%= singular_name %>).valid? 49 49 end 50 50 51 def test_show<%= suffix %>_without_id 52 get :show<%= suffix %> 53 54 assert_response :redirect 55 assert_redirected_to :action => 'list<%= suffix %>' 56 end 57 51 58 def test_new<%= suffix %> 52 59 get :new<%= suffix %> 53 60 … … 57 64 assert_not_nil assigns(:<%= singular_name %>) 58 65 end 59 66 60 def test_create 67 def test_create<%= suffix %>_using_post 61 68 num_<%= plural_name %> = <%= model_name %>.count 62 69 63 70 post :create<%= suffix %>, :<%= singular_name %> => {} … … 68 75 assert_equal num_<%= plural_name %> + 1, <%= model_name %>.count 69 76 end 70 77 71 def test_edit<%= suffix %> 78 def test_create<%= suffix %>_using_get 79 num_<%= plural_name %> = <%= model_name %>.count 80 81 get :create<%= suffix %>, :<%= singular_name %> => {} 82 83 assert_response :success 84 assert_template 'new<%= suffix %>' 85 86 assert_equal num_<%= plural_name %>, <%= model_name %>.count 87 end 88 89 def test_edit<%= suffix %>_with_id 72 90 get :edit<%= suffix %>, :id => 1 73 91 74 92 assert_response :success … … 78 96 assert assigns(:<%= singular_name %>).valid? 79 97 end 80 98 81 def test_update<%= suffix %> 99 def test_edit<%= suffix %>_without_id 100 get :edit<%= suffix %> 101 102 assert_response :redirect 103 assert_redirected_to :action => 'list<%= suffix %>' 104 end 105 106 def test_update<%= suffix %>_with_id_using_post 82 107 post :update<%= suffix %>, :id => 1 83 108 assert_response :redirect 84 109 assert_redirected_to :action => 'show<%= suffix %>', :id => 1 85 110 end 86 111 87 def test_destroy<%= suffix %> 112 def test_update<%= suffix %>_with_id_using_get 113 get :update<%= suffix %>, :id => 1 114 assert_response :success 115 assert_template 'edit<%= suffix %>' 116 end 117 118 def test_update<%= suffix %>_without_id_using_post 119 post :update<%= suffix %> 120 assert_response :redirect 121 assert_redirected_to :action => 'list<%= suffix %>' 122 end 123 124 def test_update<%= suffix %>_without_id_using_get 125 get :update<%= suffix %> 126 assert_response :redirect 127 assert_redirected_to :action => 'list<%= suffix %>' 128 end 129 130 def test_destroy<%= suffix %>_with_id_using_post 88 131 assert_not_nil <%= model_name %>.find(1) 89 132 90 133 post :destroy, :id => 1 … … 95 138 <%= model_name %>.find(1) 96 139 } 97 140 end 141 142 def test_destroy<%= suffix %>_with_id_using_get 143 assert_not_nil <%= model_name %>.find(1) 144 145 get :destroy<%= suffix %>, :id => 1 146 assert_response :redirect 147 assert_redirected_to :action => 'edit<%= suffix %>' 148 149 assert_not_nil <%= model_name %>.find(1) 150 end 151 152 def test_destroy<%= suffix %>_without_id_using_post 153 assert_not_nil <%= model_name %>.find(1) 154 155 post :destroy<%= suffix %> 156 assert_response :redirect 157 assert_redirected_to :action => 'list<%= suffix %>' 158 159 assert_not_nil <%= model_name %>.find(1) 160 end 161 162 def test_destroy<%= suffix %>_without_id_using_get 163 assert_not_nil <%= model_name %>.find(1) 164 165 get :destroy<%= suffix %> 166 assert_response :redirect 167 assert_redirected_to :action => 'list<%= suffix %>' 168 169 assert_not_nil <%= model_name %>.find(1) 170 end 98 171 end -
railties/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml
old new 4 4 <%%= render :partial => 'form' %> 5 5 <%%= submit_tag 'Edit' %> 6 6 <%%= end_form_tag %> 7 <%%= button_to 'Destroy', { :action => 'destroy<%= suffix %>', :id => @<%= singular_name %> }, :confirm => 'Are you sure you want to destroy <%= singular_name %>?' %> 7 8 8 9 <%%= link_to 'Show', :action => 'show<%= suffix %>', :id => @<%= singular_name %> %> | 9 10 <%%= link_to 'Back', :action => 'list<%= suffix %>' %> -
railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb
old new 1 1 class <%= controller_class_name %>Controller < ApplicationController 2 verify :only => [ :show<%= suffix %>, :edit<%= suffix %>, :update<%= suffix %>, :destroy<%= suffix %> ], 3 :params => :id, 4 :add_flash => { :notice => '<%= model_name %> ID missing.' }, 5 :redirect_to => { :action => 'list<%= suffix %>' } 6 2 7 <% unless suffix -%> 3 8 def index 4 9 list … … 12 17 13 18 <% end -%> 14 19 def list<%= suffix %> 15 @<%= singular_name %>_pages, @<%= plural_name %> = paginate :<%= plural_name %>, :per_page => 1020 @<%= singular_name %>_pages, @<%= plural_name %> = paginate(:<%= plural_name %>, :per_page => 10) 16 21 end 17 22 18 23 def show<%= suffix %> … … 25 30 26 31 def create<%= suffix %> 27 32 @<%= singular_name %> = <%= model_name %>.new(params[:<%= singular_name %>]) 28 if @<%= singular_name %>.save 29 flash[:notice] = '<%= model_name %> was successfully created.' 30 redirect_to :action => 'list<%= suffix %>' 33 if request.post? 34 if @<%= singular_name %>.save 35 flash[:notice] = '<%= model_name %> was successfully created.' 36 redirect_to :action => 'list<%= suffix %>' 37 else 38 render :action => 'new<%= suffix %>' 39 end 31 40 else 41 flash[:notice] = '<%= model_name %> must be created using HTTP POST.' 32 42 render :action => 'new<%= suffix %>' 33 43 end 34 44 end … … 39 49 40 50 def update 41 51 @<%= singular_name %> = <%= model_name %>.find(params[:id]) 42 if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>]) 43 flash[:notice] = '<%= model_name %> was successfully updated.' 44 redirect_to :action => 'show<%= suffix %>', :id => @<%= singular_name %> 52 if request.post? 53 if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>]) 54 flash[:notice] = '<%= model_name %> was successfully updated.' 55 redirect_to :action => 'show<%= suffix %>', :id => @<%= singular_name %> 56 else 57 render :action => 'edit<%= suffix %>' 58 end 45 59 else 60 flash[:notice] = '<%= model_name %> must be updated using HTTP POST.' 46 61 render :action => 'edit<%= suffix %>' 47 62 end 48 63 end 49 64 50 65 def destroy<%= suffix %> 51 <%= model_name %>.find(params[:id]).destroy 52 redirect_to :action => 'list<%= suffix %>' 66 if request.post? 67 <%= model_name %>.find(params[:id]).destroy 68 flash[:notice] = '<%= model_name %> was successfully destroyed.' 69 redirect_to :action => 'list<%= suffix %>' 70 else 71 flash[:notice] = 'Click Destroy to destroy <%= model_name %>.' 72 redirect_to :action => 'edit<%= suffix %>', :id => params[:id] 73 end 53 74 end 54 75 end -
railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml
old new 14 14 <%% end %> 15 15 <td><%%= link_to 'Show', :action => 'show<%= suffix %>', :id => <%= singular_name %> %></td> 16 16 <td><%%= link_to 'Edit', :action => 'edit<%= suffix %>', :id => <%= singular_name %> %></td> 17 <td><%%= link_to 'Destroy', { :action => 'destroy<%= suffix %>', :id => <%= singular_name %> }, : confirm => 'Are you sure?' %></td>17 <td><%%= link_to 'Destroy', { :action => 'destroy<%= suffix %>', :id => <%= singular_name %> }, :post => true, :confirm => 'Are you sure you want to delete <%= singular_name %>?' %></td> 18 18 </tr> 19 19 <%% end %> 20 20 </table>