ajax_scaffold_generator 3.1.4 → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +6 -1
- data/MIT-LICENSE +20 -20
- data/README +32 -32
- data/ajax_scaffold_generator.rb +201 -201
- data/templates/controller.rb +135 -135
- data/templates/functional_test.rb +120 -116
- data/templates/partial_item.rhtml +36 -36
- data/templates/unit_test.rb +53 -50
- metadata +55 -49
    
        data/templates/controller.rb
    CHANGED
    
    | @@ -1,135 +1,135 @@ | |
| 1 | 
            -
            class <%= controller_class_name %>Controller < ApplicationController
         | 
| 2 | 
            -
              include AjaxScaffold::Controller
         | 
| 3 | 
            -
              
         | 
| 4 | 
            -
              after_filter :clear_flashes
         | 
| 5 | 
            -
              before_filter :update_params_filter
         | 
| 6 | 
            -
              
         | 
| 7 | 
            -
              def update_params_filter
         | 
| 8 | 
            -
                update_params :default_scaffold_id => "<%= singular_name %>", :default_sort => nil, :default_sort_direction => "asc"
         | 
| 9 | 
            -
              end
         | 
| 10 | 
            -
            <% unless suffix -%>
         | 
| 11 | 
            -
              def index
         | 
| 12 | 
            -
                redirect_to :action => 'list'
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
            <% end -%>
         | 
| 15 | 
            -
              def return_to_main
         | 
| 16 | 
            -
                # If you have multiple scaffolds on the same view then you will want to change this to
         | 
| 17 | 
            -
                # to whatever controller/action shows all the views 
         | 
| 18 | 
            -
                # (ex: redirect_to :controller => 'AdminConsole', :action => 'index')
         | 
| 19 | 
            -
                redirect_to :action => 'list'
         | 
| 20 | 
            -
              end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
              def list
         | 
| 23 | 
            -
              end
         | 
| 24 | 
            -
              
         | 
| 25 | 
            -
              # All posts to change scaffold level variables like sort values or page changes go through this action
         | 
| 26 | 
            -
              def component_update
         | 
| 27 | 
            -
                @show_wrapper = false # don't show the outer wrapper elements if we are just updating an existing scaffold 
         | 
| 28 | 
            -
                if request.xhr?
         | 
| 29 | 
            -
                  # If this is an AJAX request then we just want to delegate to the component to rerender itself
         | 
| 30 | 
            -
                  component
         | 
| 31 | 
            -
                else
         | 
| 32 | 
            -
                  # If this is from a client without javascript we want to update the session parameters and then delegate
         | 
| 33 | 
            -
                  # back to whatever page is displaying the scaffold, which will then rerender all scaffolds with these update parameters
         | 
| 34 | 
            -
                  return_to_main
         | 
| 35 | 
            -
                end
         | 
| 36 | 
            -
              end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
              def component  
         | 
| 39 | 
            -
                @show_wrapper = true if @show_wrapper.nil?
         | 
| 40 | 
            -
                @sort_sql = <%= model_name %>.scaffold_columns_hash[current_sort(params)].sort_sql rescue nil
         | 
| 41 | 
            -
                @sort_by = @sort_sql.nil? ? "#{<%= model_name %>.table_name}.#{<%= model_name %>.primary_key} asc" : @sort_sql  + " " + current_sort_direction(params)
         | 
| 42 | 
            -
                @paginator, @<%= plural_name %> = paginate(:<%= plural_name %>, :order => @sort_by, :per_page => default_per_page)
         | 
| 43 | 
            -
                
         | 
| 44 | 
            -
                render :action => "component", :layout => false
         | 
| 45 | 
            -
              end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
              def new
         | 
| 48 | 
            -
                @<%= singular_name %> = <%= model_name %>.new
         | 
| 49 | 
            -
                @successful = true
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                return render(:action => 'new.rjs') if request.xhr?
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                # Javascript disabled fallback
         | 
| 54 | 
            -
                if @successful
         | 
| 55 | 
            -
                  @options = { :action => "create" }
         | 
| 56 | 
            -
                  render :partial => "new_edit", :layout => true
         | 
| 57 | 
            -
                else 
         | 
| 58 | 
            -
                  return_to_main
         | 
| 59 | 
            -
                end
         | 
| 60 | 
            -
              end
         | 
| 61 | 
            -
              
         | 
| 62 | 
            -
              def create
         | 
| 63 | 
            -
                begin
         | 
| 64 | 
            -
                  @<%= singular_name %> = <%= model_name %>.new(params[:<%= singular_name %>])
         | 
| 65 | 
            -
                  @successful = @<%= singular_name %>.save
         | 
| 66 | 
            -
                rescue
         | 
| 67 | 
            -
                  flash[:error], @successful  = $!.to_s, false
         | 
| 68 | 
            -
                end
         | 
| 69 | 
            -
                
         | 
| 70 | 
            -
                return render(:action => 'create.rjs') if request.xhr?
         | 
| 71 | 
            -
                if @successful
         | 
| 72 | 
            -
                  return_to_main
         | 
| 73 | 
            -
                else
         | 
| 74 | 
            -
                  @options = { :scaffold_id => params[:scaffold_id], :action => "create" }
         | 
| 75 | 
            -
                  render :partial => 'new_edit', :layout => true
         | 
| 76 | 
            -
                end
         | 
| 77 | 
            -
              end
         | 
| 78 | 
            -
             | 
| 79 | 
            -
              def edit
         | 
| 80 | 
            -
                begin
         | 
| 81 | 
            -
                  @<%= singular_name %> = <%= model_name %>.find(params[:id])
         | 
| 82 | 
            -
                  @successful = !@<%= singular_name %>.nil?
         | 
| 83 | 
            -
                rescue
         | 
| 84 | 
            -
                  flash[:error], @successful  = $!.to_s, false
         | 
| 85 | 
            -
                end
         | 
| 86 | 
            -
                
         | 
| 87 | 
            -
                return render(:action => 'edit.rjs') if request.xhr?
         | 
| 88 | 
            -
             | 
| 89 | 
            -
                if @successful
         | 
| 90 | 
            -
                  @options = { :scaffold_id => params[:scaffold_id], :action => "update", :id => params[:id] }
         | 
| 91 | 
            -
                  render :partial => 'new_edit', :layout => true
         | 
| 92 | 
            -
                else
         | 
| 93 | 
            -
                  return_to_main
         | 
| 94 | 
            -
                end    
         | 
| 95 | 
            -
              end
         | 
| 96 | 
            -
             | 
| 97 | 
            -
              def update
         | 
| 98 | 
            -
                begin
         | 
| 99 | 
            -
                  @<%= singular_name %> = <%= model_name %>.find(params[:id])
         | 
| 100 | 
            -
                  @successful = @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
         | 
| 101 | 
            -
                rescue
         | 
| 102 | 
            -
                  flash[:error], @successful  = $!.to_s, false
         | 
| 103 | 
            -
                end
         | 
| 104 | 
            -
                
         | 
| 105 | 
            -
                return render(:action => 'update.rjs') if request.xhr?
         | 
| 106 | 
            -
             | 
| 107 | 
            -
                if @successful
         | 
| 108 | 
            -
                  return_to_main
         | 
| 109 | 
            -
                else
         | 
| 110 | 
            -
                  @options = { :action => "update" }
         | 
| 111 | 
            -
                  render :partial => 'new_edit', :layout => true
         | 
| 112 | 
            -
                end
         | 
| 113 | 
            -
              end
         | 
| 114 | 
            -
             | 
| 115 | 
            -
              def destroy
         | 
| 116 | 
            -
                begin
         | 
| 117 | 
            -
                  @successful = <%= model_name %>.find(params[:id]).destroy
         | 
| 118 | 
            -
                rescue
         | 
| 119 | 
            -
                  flash[:error], @successful  = $!.to_s, false
         | 
| 120 | 
            -
                end
         | 
| 121 | 
            -
                
         | 
| 122 | 
            -
                return render(:action => 'destroy.rjs') if request.xhr?
         | 
| 123 | 
            -
                
         | 
| 124 | 
            -
                # Javascript disabled fallback
         | 
| 125 | 
            -
                return_to_main
         | 
| 126 | 
            -
              end
         | 
| 127 | 
            -
              
         | 
| 128 | 
            -
              def cancel
         | 
| 129 | 
            -
                @successful = true
         | 
| 130 | 
            -
                
         | 
| 131 | 
            -
                return render(:action => 'cancel.rjs') if request.xhr?
         | 
| 132 | 
            -
                
         | 
| 133 | 
            -
                return_to_main
         | 
| 134 | 
            -
              end
         | 
| 135 | 
            -
            end
         | 
| 1 | 
            +
            class <%= controller_class_name %>Controller < ApplicationController
         | 
| 2 | 
            +
              include AjaxScaffold::Controller
         | 
| 3 | 
            +
              
         | 
| 4 | 
            +
              after_filter :clear_flashes
         | 
| 5 | 
            +
              before_filter :update_params_filter
         | 
| 6 | 
            +
              
         | 
| 7 | 
            +
              def update_params_filter
         | 
| 8 | 
            +
                update_params :default_scaffold_id => "<%= singular_name %>", :default_sort => nil, :default_sort_direction => "asc"
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            <% unless suffix -%>
         | 
| 11 | 
            +
              def index
         | 
| 12 | 
            +
                redirect_to :action => 'list'
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            <% end -%>
         | 
| 15 | 
            +
              def return_to_main
         | 
| 16 | 
            +
                # If you have multiple scaffolds on the same view then you will want to change this to
         | 
| 17 | 
            +
                # to whatever controller/action shows all the views 
         | 
| 18 | 
            +
                # (ex: redirect_to :controller => 'AdminConsole', :action => 'index')
         | 
| 19 | 
            +
                redirect_to :action => 'list'
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              def list
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
              
         | 
| 25 | 
            +
              # All posts to change scaffold level variables like sort values or page changes go through this action
         | 
| 26 | 
            +
              def component_update
         | 
| 27 | 
            +
                @show_wrapper = false # don't show the outer wrapper elements if we are just updating an existing scaffold 
         | 
| 28 | 
            +
                if request.xhr?
         | 
| 29 | 
            +
                  # If this is an AJAX request then we just want to delegate to the component to rerender itself
         | 
| 30 | 
            +
                  component
         | 
| 31 | 
            +
                else
         | 
| 32 | 
            +
                  # If this is from a client without javascript we want to update the session parameters and then delegate
         | 
| 33 | 
            +
                  # back to whatever page is displaying the scaffold, which will then rerender all scaffolds with these update parameters
         | 
| 34 | 
            +
                  return_to_main
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              def component  
         | 
| 39 | 
            +
                @show_wrapper = true if @show_wrapper.nil?
         | 
| 40 | 
            +
                @sort_sql = <%= model_name %>.scaffold_columns_hash[current_sort(params)].sort_sql rescue nil
         | 
| 41 | 
            +
                @sort_by = @sort_sql.nil? ? "#{<%= model_name %>.table_name}.#{<%= model_name %>.primary_key} asc" : @sort_sql  + " " + current_sort_direction(params)
         | 
| 42 | 
            +
                @paginator, @<%= plural_name %> = paginate(:<%= plural_name %>, :order => @sort_by, :per_page => default_per_page)
         | 
| 43 | 
            +
                
         | 
| 44 | 
            +
                render :action => "component", :layout => false
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              def new
         | 
| 48 | 
            +
                @<%= singular_name %> = <%= model_name %>.new
         | 
| 49 | 
            +
                @successful = true
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                return render(:action => 'new.rjs') if request.xhr?
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                # Javascript disabled fallback
         | 
| 54 | 
            +
                if @successful
         | 
| 55 | 
            +
                  @options = { :action => "create" }
         | 
| 56 | 
            +
                  render :partial => "new_edit", :layout => true
         | 
| 57 | 
            +
                else 
         | 
| 58 | 
            +
                  return_to_main
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
              
         | 
| 62 | 
            +
              def create
         | 
| 63 | 
            +
                begin
         | 
| 64 | 
            +
                  @<%= singular_name %> = <%= model_name %>.new(params[:<%= singular_name %>])
         | 
| 65 | 
            +
                  @successful = @<%= singular_name %>.save
         | 
| 66 | 
            +
                rescue
         | 
| 67 | 
            +
                  flash[:error], @successful  = $!.to_s, false
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
                
         | 
| 70 | 
            +
                return render(:action => 'create.rjs') if request.xhr?
         | 
| 71 | 
            +
                if @successful
         | 
| 72 | 
            +
                  return_to_main
         | 
| 73 | 
            +
                else
         | 
| 74 | 
            +
                  @options = { :scaffold_id => params[:scaffold_id], :action => "create" }
         | 
| 75 | 
            +
                  render :partial => 'new_edit', :layout => true
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
              def edit
         | 
| 80 | 
            +
                begin
         | 
| 81 | 
            +
                  @<%= singular_name %> = <%= model_name %>.find(params[:id])
         | 
| 82 | 
            +
                  @successful = !@<%= singular_name %>.nil?
         | 
| 83 | 
            +
                rescue
         | 
| 84 | 
            +
                  flash[:error], @successful  = $!.to_s, false
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
                
         | 
| 87 | 
            +
                return render(:action => 'edit.rjs') if request.xhr?
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                if @successful
         | 
| 90 | 
            +
                  @options = { :scaffold_id => params[:scaffold_id], :action => "update", :id => params[:id] }
         | 
| 91 | 
            +
                  render :partial => 'new_edit', :layout => true
         | 
| 92 | 
            +
                else
         | 
| 93 | 
            +
                  return_to_main
         | 
| 94 | 
            +
                end    
         | 
| 95 | 
            +
              end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
              def update
         | 
| 98 | 
            +
                begin
         | 
| 99 | 
            +
                  @<%= singular_name %> = <%= model_name %>.find(params[:id])
         | 
| 100 | 
            +
                  @successful = @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
         | 
| 101 | 
            +
                rescue
         | 
| 102 | 
            +
                  flash[:error], @successful  = $!.to_s, false
         | 
| 103 | 
            +
                end
         | 
| 104 | 
            +
                
         | 
| 105 | 
            +
                return render(:action => 'update.rjs') if request.xhr?
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                if @successful
         | 
| 108 | 
            +
                  return_to_main
         | 
| 109 | 
            +
                else
         | 
| 110 | 
            +
                  @options = { :action => "update" }
         | 
| 111 | 
            +
                  render :partial => 'new_edit', :layout => true
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
              end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
              def destroy
         | 
| 116 | 
            +
                begin
         | 
| 117 | 
            +
                  @successful = <%= model_name %>.find(params[:id]).destroy
         | 
| 118 | 
            +
                rescue
         | 
| 119 | 
            +
                  flash[:error], @successful  = $!.to_s, false
         | 
| 120 | 
            +
                end
         | 
| 121 | 
            +
                
         | 
| 122 | 
            +
                return render(:action => 'destroy.rjs') if request.xhr?
         | 
| 123 | 
            +
                
         | 
| 124 | 
            +
                # Javascript disabled fallback
         | 
| 125 | 
            +
                return_to_main
         | 
| 126 | 
            +
              end
         | 
| 127 | 
            +
              
         | 
| 128 | 
            +
              def cancel
         | 
| 129 | 
            +
                @successful = true
         | 
| 130 | 
            +
                
         | 
| 131 | 
            +
                return render(:action => 'cancel.rjs') if request.xhr?
         | 
| 132 | 
            +
                
         | 
| 133 | 
            +
                return_to_main
         | 
| 134 | 
            +
              end
         | 
| 135 | 
            +
            end
         | 
| @@ -1,116 +1,120 @@ | |
| 1 | 
            -
            require File.dirname(__FILE__) + '<%= "/.." * controller_class_nesting_depth %>/../test_helper'
         | 
| 2 | 
            -
            require '<%= base_controller_file_path %>_controller'
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            # Re-raise errors caught by the controller.
         | 
| 5 | 
            -
            class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
         | 
| 8 | 
            -
              fixtures :<%= table_name %>
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            	NEW_<%=  | 
| 11 | 
            -
            	REDIRECT_TO_MAIN = {:action => 'list'} # put hash or string redirection that you normally expect
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            	def setup
         | 
| 14 | 
            -
            		@controller = <%= controller_class_name %>Controller.new
         | 
| 15 | 
            -
            		@request    = ActionController::TestRequest.new
         | 
| 16 | 
            -
            		@response   = ActionController::TestResponse.new
         | 
| 17 | 
            -
            		# Retrieve fixtures via their name
         | 
| 18 | 
            -
            		# @first = <%= table_name %>(:first)
         | 
| 19 | 
            -
            		@first = <%= class_name %>.find_first
         | 
| 20 | 
            -
            	end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
              def test_component
         | 
| 23 | 
            -
                get :component
         | 
| 24 | 
            -
                assert_response :success
         | 
| 25 | 
            -
                assert_template '<%= base_controller_file_path %>/component'
         | 
| 26 | 
            -
                <%= table_name %> = check_attrs(%w(<%= table_name %>))
         | 
| 27 | 
            -
                assert_equal <%= class_name %>.find(:all).length, <%= table_name %>.length, "Incorrect number of <%= table_name %> shown"
         | 
| 28 | 
            -
              end
         | 
| 29 | 
            -
             | 
| 30 | 
            -
              def test_component_update
         | 
| 31 | 
            -
                get :component_update
         | 
| 32 | 
            -
                assert_response :redirect
         | 
| 33 | 
            -
                assert_redirected_to REDIRECT_TO_MAIN
         | 
| 34 | 
            -
              end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
              def test_component_update_xhr
         | 
| 37 | 
            -
                xhr :get, :component_update
         | 
| 38 | 
            -
                assert_response :success
         | 
| 39 | 
            -
                assert_template '<%= base_controller_file_path %>/component'
         | 
| 40 | 
            -
                <%= table_name %> = check_attrs(%w(<%= table_name %>))
         | 
| 41 | 
            -
                assert_equal <%= class_name %>.find(:all).length, <%= table_name %>.length, "Incorrect number of <%= table_name %> shown"
         | 
| 42 | 
            -
              end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
              def test_create
         | 
| 45 | 
            -
              	<%=  | 
| 46 | 
            -
                post :create, {:<%=  | 
| 47 | 
            -
                <%=  | 
| 48 | 
            -
                 | 
| 49 | 
            -
                 | 
| 50 | 
            -
                 | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
                 | 
| 57 | 
            -
                 | 
| 58 | 
            -
                 | 
| 59 | 
            -
                 | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
               | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
                <%=  | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
                 | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
                 | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
                 | 
| 83 | 
            -
                 | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
             | 
| 105 | 
            -
             | 
| 106 | 
            -
               | 
| 107 | 
            -
             | 
| 108 | 
            -
             | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
             | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
               | 
| 116 | 
            -
             | 
| 1 | 
            +
            require File.dirname(__FILE__) + '<%= "/.." * controller_class_nesting_depth %>/../test_helper'
         | 
| 2 | 
            +
            require '<%= base_controller_file_path %>_controller'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # Re-raise errors caught by the controller.
         | 
| 5 | 
            +
            class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
         | 
| 8 | 
            +
              fixtures :<%= table_name %>
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            	NEW_<%= singular_name.upcase %> = {}	# e.g. {:name => 'Test <%= class_name %>', :description => 'Dummy'}
         | 
| 11 | 
            +
            	REDIRECT_TO_MAIN = {:action => 'list'} # put hash or string redirection that you normally expect
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            	def setup
         | 
| 14 | 
            +
            		@controller = <%= controller_class_name %>Controller.new
         | 
| 15 | 
            +
            		@request    = ActionController::TestRequest.new
         | 
| 16 | 
            +
            		@response   = ActionController::TestResponse.new
         | 
| 17 | 
            +
            		# Retrieve fixtures via their name
         | 
| 18 | 
            +
            		# @first = <%= table_name %>(:first)
         | 
| 19 | 
            +
            		@first = <%= class_name %>.find_first
         | 
| 20 | 
            +
            	end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              def test_component
         | 
| 23 | 
            +
                get :component
         | 
| 24 | 
            +
                assert_response :success
         | 
| 25 | 
            +
                assert_template '<%= base_controller_file_path %>/component'
         | 
| 26 | 
            +
                <%= table_name %> = check_attrs(%w(<%= table_name %>))
         | 
| 27 | 
            +
                assert_equal <%= class_name %>.find(:all).length, <%= table_name %>.length, "Incorrect number of <%= table_name %> shown"
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              def test_component_update
         | 
| 31 | 
            +
                get :component_update
         | 
| 32 | 
            +
                assert_response :redirect
         | 
| 33 | 
            +
                assert_redirected_to REDIRECT_TO_MAIN
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              def test_component_update_xhr
         | 
| 37 | 
            +
                xhr :get, :component_update
         | 
| 38 | 
            +
                assert_response :success
         | 
| 39 | 
            +
                assert_template '<%= base_controller_file_path %>/component'
         | 
| 40 | 
            +
                <%= table_name %> = check_attrs(%w(<%= table_name %>))
         | 
| 41 | 
            +
                assert_equal <%= class_name %>.find(:all).length, <%= table_name %>.length, "Incorrect number of <%= table_name %> shown"
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              def test_create
         | 
| 45 | 
            +
              	<%= singular_name %>_count = <%= class_name %>.find(:all).length
         | 
| 46 | 
            +
                post :create, {:<%= singular_name %> => NEW_<%= singular_name.upcase %>}
         | 
| 47 | 
            +
                <%= singular_name %>, successful = check_attrs(%w(<%= singular_name %> successful))
         | 
| 48 | 
            +
                assert successful, "Should be successful"
         | 
| 49 | 
            +
                assert_response :redirect
         | 
| 50 | 
            +
                assert_redirected_to REDIRECT_TO_MAIN
         | 
| 51 | 
            +
                assert_equal <%= singular_name %>_count + 1, <%= class_name %>.find(:all).length, "Expected an additional <%= class_name %>"
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              def test_create_xhr
         | 
| 55 | 
            +
              	<%= singular_name %>_count = <%= class_name %>.find(:all).length
         | 
| 56 | 
            +
                xhr :post, :create, {:<%= singular_name %> => NEW_<%= singular_name.upcase %>}
         | 
| 57 | 
            +
                <%= singular_name %>, successful = check_attrs(%w(<%= singular_name %> successful))
         | 
| 58 | 
            +
                assert successful, "Should be successful"
         | 
| 59 | 
            +
                assert_response :success
         | 
| 60 | 
            +
                assert_template 'create.rjs'
         | 
| 61 | 
            +
                assert_equal <%= singular_name %>_count + 1, <%= class_name %>.find(:all).length, "Expected an additional <%= class_name %>"
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              def test_update
         | 
| 65 | 
            +
              	<%= singular_name %>_count = <%= class_name %>.find(:all).length
         | 
| 66 | 
            +
                post :update, {:id => @first.id, :<%= singular_name %> => @first.attributes.merge(NEW_<%= singular_name.upcase %>)}
         | 
| 67 | 
            +
                <%= singular_name %>, successful = check_attrs(%w(<%= singular_name %> successful))
         | 
| 68 | 
            +
                assert successful, "Should be successful"
         | 
| 69 | 
            +
                <%= singular_name %>.reload
         | 
| 70 | 
            +
               	NEW_<%= singular_name.upcase %>.each do |attr_name|
         | 
| 71 | 
            +
                  assert_equal NEW_<%= singular_name.upcase %>[attr_name], <%= singular_name %>.attributes[attr_name], "@<%= singular_name %>.#{attr_name.to_s} incorrect"
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
                assert_equal <%= singular_name %>_count, <%= class_name %>.find(:all).length, "Number of <%= class_name %>s should be the same"
         | 
| 74 | 
            +
                assert_response :redirect
         | 
| 75 | 
            +
                assert_redirected_to REDIRECT_TO_MAIN
         | 
| 76 | 
            +
              end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
              def test_update_xhr
         | 
| 79 | 
            +
              	<%= singular_name %>_count = <%= class_name %>.find(:all).length
         | 
| 80 | 
            +
                xhr :post, :update, {:id => @first.id, :<%= singular_name %> => @first.attributes.merge(NEW_<%= singular_name.upcase %>)}
         | 
| 81 | 
            +
                <%= singular_name %>, successful = check_attrs(%w(<%= singular_name %> successful))
         | 
| 82 | 
            +
                assert successful, "Should be successful"
         | 
| 83 | 
            +
                <%= singular_name %>.reload
         | 
| 84 | 
            +
               	NEW_<%= singular_name.upcase %>.each do |attr_name|
         | 
| 85 | 
            +
                  assert_equal NEW_<%= singular_name.upcase %>[attr_name], <%= singular_name %>.attributes[attr_name], "@<%= singular_name %>.#{attr_name.to_s} incorrect"
         | 
| 86 | 
            +
                end
         | 
| 87 | 
            +
                assert_equal <%= singular_name %>_count, <%= class_name %>.find(:all).length, "Number of <%= class_name %>s should be the same"
         | 
| 88 | 
            +
                assert_response :success
         | 
| 89 | 
            +
                assert_template 'update.rjs'
         | 
| 90 | 
            +
              end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
              def test_destroy
         | 
| 93 | 
            +
              	<%= singular_name %>_count = <%= class_name %>.find(:all).length
         | 
| 94 | 
            +
                post :destroy, {:id => @first.id}
         | 
| 95 | 
            +
                assert_response :redirect
         | 
| 96 | 
            +
                assert_equal <%= singular_name %>_count - 1, <%= class_name %>.find(:all).length, "Number of <%= class_name %>s should be one less"
         | 
| 97 | 
            +
                assert_redirected_to REDIRECT_TO_MAIN
         | 
| 98 | 
            +
              end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
              def test_destroy_xhr
         | 
| 101 | 
            +
              	<%= singular_name %>_count = <%= class_name %>.find(:all).length
         | 
| 102 | 
            +
                xhr :post, :destroy, {:id => @first.id}
         | 
| 103 | 
            +
                assert_response :success
         | 
| 104 | 
            +
                assert_equal <%= singular_name %>_count - 1, <%= class_name %>.find(:all).length, "Number of <%= class_name %>s should be one less"
         | 
| 105 | 
            +
                assert_template 'destroy.rjs'
         | 
| 106 | 
            +
              end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
            protected
         | 
| 109 | 
            +
            	# Could be put in a Helper library and included at top of test class
         | 
| 110 | 
            +
              def check_attrs(attr_list)
         | 
| 111 | 
            +
                attrs = []
         | 
| 112 | 
            +
                attr_list.each do |attr_sym|
         | 
| 113 | 
            +
                  attr = assigns(attr_sym.to_sym)
         | 
| 114 | 
            +
                  assert_not_nil attr,       "Attribute @#{attr_sym} should not be nil"
         | 
| 115 | 
            +
                  assert !attr.new_record?,  "Should have saved the @#{attr_sym} obj" if attr.class == ActiveRecord
         | 
| 116 | 
            +
                  attrs << attr
         | 
| 117 | 
            +
                end
         | 
| 118 | 
            +
                attrs.length > 1 ? attrs : attrs[0]
         | 
| 119 | 
            +
              end
         | 
| 120 | 
            +
            end
         | 
| @@ -1,36 +1,36 @@ | |
| 1 | 
            -
            <%% # The following is used when the browser doesn't have javascript enabled %>
         | 
| 2 | 
            -
            <%% classAttr = cycle("", "class=\"even\"") %>
         | 
| 3 | 
            -
            <%% @options = params.merge(:controller => '<%= controller_file_path %>', :action => "view", :id => <%= singular_name %>.send("#{<%= model_name %>.primary_key}")) %>
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            <tr <%%= classAttr %> id="<%%= element_row_id(@options) %>" <%%= "style=\"display: none;\"" if hidden %>>
         | 
| 6 | 
            -
            	<%% for scaffold_column in scaffold_columns %>
         | 
| 7 | 
            -
            	  <%% column_value = eval(scaffold_column.eval) rescue nil %>
         | 
| 8 | 
            -
            	  <td class="<%%= column_class(scaffold_column.name, column_value, current_sort(params)) %>" >
         | 
| 9 | 
            -
            	    <%%= format_column(column_value) %>
         | 
| 10 | 
            -
            	  </td>
         | 
| 11 | 
            -
            	<%% end %>
         | 
| 12 | 
            -
              <td class="actions">
         | 
| 13 | 
            -
                <table cellpadding="0" cellspacing="0">
         | 
| 14 | 
            -
                  <tr>
         | 
| 15 | 
            -
                    <td class="indicator-container">
         | 
| 16 | 
            -
                      <%%= loading_indicator_tag(@options) %>
         | 
| 17 | 
            -
                    </td>
         | 
| 18 | 
            -
                    <td> 
         | 
| 19 | 
            -
                      <%% edit_options = @options.merge(:action => 'edit') %>
         | 
| 20 | 
            -
             	        <%%= link_to_remote "Edit", 
         | 
| 21 | 
            -
               	                    { :url => edit_options, 
         | 
| 22 | 
            -
                                      :loading => "Element.show('#{loading_indicator_id(@options)}');" },
         | 
| 23 | 
            -
               	                    { :href => url_for(edit_options) } %>
         | 
| 24 | 
            -
               	     </td>
         | 
| 25 | 
            -
               	     <td>
         | 
| 26 | 
            -
               	       <%% delete_options = @options.merge(:action => 'destroy') %>
         | 
| 27 | 
            -
             	         <%%= link_to_remote "Delete", 
         | 
| 28 | 
            -
               	                    { :url => delete_options, 
         | 
| 29 | 
            -
               	                      :confirm => 'Are you sure?',
         | 
| 30 | 
            -
                                      :loading => "Element.show('#{loading_indicator_id(@options)}');" },
         | 
| 31 | 
            -
               	                    { :href => url_for( delete_options ) } %>
         | 
| 32 | 
            -
               	      </td>
         | 
| 33 | 
            -
               	    </tr>
         | 
| 34 | 
            -
               	  </table>
         | 
| 35 | 
            -
              </td>
         | 
| 36 | 
            -
            </tr>
         | 
| 1 | 
            +
            <%% # The following is used when the browser doesn't have javascript enabled %>
         | 
| 2 | 
            +
            <%% classAttr = cycle("", "class=\"even\"") %>
         | 
| 3 | 
            +
            <%% @options = params.merge(:controller => '<%= controller_file_path %>', :action => "view", :id => <%= singular_name %>.send("#{<%= model_name %>.primary_key}")) %>
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            <tr <%%= classAttr %> id="<%%= element_row_id(@options) %>" <%%= "style=\"display: none;\"" if hidden %>>
         | 
| 6 | 
            +
            	<%% for scaffold_column in scaffold_columns %>
         | 
| 7 | 
            +
            	  <%% column_value = eval(scaffold_column.eval) rescue nil %>
         | 
| 8 | 
            +
            	  <td class="<%%= column_class(scaffold_column.name, column_value, current_sort(params)) %>" >
         | 
| 9 | 
            +
            	    <%%= format_column(column_value) %>
         | 
| 10 | 
            +
            	  </td>
         | 
| 11 | 
            +
            	<%% end %>
         | 
| 12 | 
            +
              <td class="actions">
         | 
| 13 | 
            +
                <table cellpadding="0" cellspacing="0">
         | 
| 14 | 
            +
                  <tr>
         | 
| 15 | 
            +
                    <td class="indicator-container">
         | 
| 16 | 
            +
                      <%%= loading_indicator_tag(@options) %>
         | 
| 17 | 
            +
                    </td>
         | 
| 18 | 
            +
                    <td> 
         | 
| 19 | 
            +
                      <%% edit_options = @options.merge(:action => 'edit') %>
         | 
| 20 | 
            +
             	        <%%= link_to_remote "Edit", 
         | 
| 21 | 
            +
               	                    { :url => edit_options, 
         | 
| 22 | 
            +
                                      :loading => "Element.show('#{loading_indicator_id(@options)}');" },
         | 
| 23 | 
            +
               	                    { :href => url_for(edit_options) } %>
         | 
| 24 | 
            +
               	     </td>
         | 
| 25 | 
            +
               	     <td>
         | 
| 26 | 
            +
               	       <%% delete_options = @options.merge(:action => 'destroy') %>
         | 
| 27 | 
            +
             	         <%%= link_to_remote "Delete", 
         | 
| 28 | 
            +
               	                    { :url => delete_options, 
         | 
| 29 | 
            +
               	                      :confirm => 'Are you sure?',
         | 
| 30 | 
            +
                                      :loading => "Element.show('#{loading_indicator_id(@options)}');" },
         | 
| 31 | 
            +
               	                    { :href => url_for( delete_options ) } %>
         | 
| 32 | 
            +
               	      </td>
         | 
| 33 | 
            +
               	    </tr>
         | 
| 34 | 
            +
               	  </table>
         | 
| 35 | 
            +
              </td>
         | 
| 36 | 
            +
            </tr>
         |