leonardo 1.5.0 → 1.6.0
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 +9 -3
 - data/lib/generators/base.rb +262 -24
 - data/lib/generators/erb/leosca/leosca_generator.rb +38 -22
 - data/lib/generators/erb/leosca/templates/_form.html.erb +14 -3
 - data/lib/generators/erb/leosca/templates/_list.erb +13 -20
 - data/lib/generators/erb/leosca/templates/_show.erb +9 -0
 - data/lib/generators/erb/leosca/templates/edit.html.erb +3 -5
 - data/lib/generators/erb/leosca/templates/formtastic/_form.html.erb +10 -4
 - data/lib/generators/erb/leosca/templates/index.html.erb +15 -4
 - data/lib/generators/erb/leosca/templates/new.html.erb +1 -1
 - data/lib/generators/erb/leosca/templates/show.html.erb +5 -22
 - data/lib/generators/erb/leosca/templates/show.js.erb +7 -0
 - data/lib/generators/leolay/USAGE +1 -1
 - data/lib/generators/leolay/install_generator.rb +0 -1
 - data/lib/generators/leolay/leolay_generator.rb +24 -17
 - data/lib/generators/leolay/templates/config/locales/devise.en.yml +1 -0
 - data/lib/generators/leolay/templates/config/locales/devise.it.yml +1 -0
 - data/lib/generators/leolay/templates/config/locales/en.yml +5 -5
 - data/lib/generators/leolay/templates/config/locales/it.yml +5 -5
 - data/lib/generators/leolay/templates/lib/generators/rspec/scaffold/scaffold_generator.rb +173 -0
 - data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/controller_spec.rb +39 -39
 - data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/edit_spec.rb +4 -1
 - data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/index_spec.rb +15 -4
 - data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/new_spec.rb +5 -2
 - data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/routing_spec.rb +37 -0
 - data/lib/generators/leolay/templates/lib/templates/rspec/scaffold/show_spec.rb +3 -0
 - data/lib/generators/leolay/templates/styles/cloudy/{stylesheet.sass → stylesheets/app/stylesheet.sass} +0 -0
 - data/lib/generators/leolay/templates/{vendor/assets/stylesheets → styles/cloudy/stylesheets/vendor}/jquery-ui/jquery-ui-1.8.16.redcarpet.css +17 -17
 - data/lib/generators/leolay/templates/vendor/assets/javascripts/jquery-ui/jquery.ui.datepicker-de.js +1 -1
 - data/lib/generators/leolay/templates/vendor/assets/javascripts/jquery-ui/jquery.ui.datepicker-en.js +1 -1
 - data/lib/generators/leolay/templates/vendor/assets/javascripts/jquery-ui/jquery.ui.datepicker-it.js +1 -1
 - data/lib/generators/leosca/install_generator.rb +1 -1
 - data/lib/generators/rails/leosca/leosca_generator.rb +21 -0
 - data/lib/generators/rails/leosca_controller/leosca_controller_generator.rb +41 -114
 - data/lib/generators/rails/leosca_controller/templates/controller.rb +51 -23
 - data/template.rb +4 -1
 - metadata +10 -6
 
| 
         @@ -9,7 +9,6 @@ module Leolay 
     | 
|
| 
       9 
9 
     | 
    
         
             
                    copy_file "leolay/leolay_generator.rb", "lib/generators/leolay/leolay_generator.rb"
         
     | 
| 
       10 
10 
     | 
    
         
             
                    copy_file "leolay/USAGE", "lib/generators/leolay/USAGE"
         
     | 
| 
       11 
11 
     | 
    
         
             
                    directory "leolay/templates", "lib/generators/leolay/templates"
         
     | 
| 
       12 
     | 
    
         
            -
                    #copy_file "leonardo_shared.rb", "lib/generators/leonardo_shared.rb" unless File.exists? "lib/generators/leonardo_shared.rb"
         
     | 
| 
       13 
12 
     | 
    
         
             
                  end
         
     | 
| 
       14 
13 
     | 
    
         
             
                end
         
     | 
| 
       15 
14 
     | 
    
         
             
              end
         
     | 
| 
         @@ -1,20 +1,20 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class LeolayGenerator < Rails::Generators::Base
         
     | 
| 
       2 
2 
     | 
    
         
             
              source_root File.expand_path('../templates', __FILE__)
         
     | 
| 
       3 
3 
     | 
    
         
             
              argument :style, :type => :string, :default => "cloudy"
         
     | 
| 
       4 
     | 
    
         
            -
              class_option :pagination, :type => :boolean, :default => true, : 
     | 
| 
       5 
     | 
    
         
            -
              class_option :main_color, :type => :string, :default => nil, : 
     | 
| 
       6 
     | 
    
         
            -
              class_option :second_color, :type => :string, :default => nil, : 
     | 
| 
       7 
     | 
    
         
            -
              class_option :authentication, :type => :boolean, :default => true, : 
     | 
| 
       8 
     | 
    
         
            -
              class_option :authorization, :type => :boolean, :default => true, : 
     | 
| 
       9 
     | 
    
         
            -
              class_option :user_class, :type => :boolean, :default => 'user', : 
     | 
| 
       10 
     | 
    
         
            -
              class_option :formtastic, :type => :boolean, :default => true, : 
     | 
| 
       11 
     | 
    
         
            -
              class_option :jquery_ui, :type => :boolean, :default => true, : 
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
              class_option :pagination, :type => :boolean, :default => true, :desc => "Include pagination files"
         
     | 
| 
      
 5 
     | 
    
         
            +
              class_option :main_color, :type => :string, :default => nil, :desc => "Force a main color for the stylesheet"
         
     | 
| 
      
 6 
     | 
    
         
            +
              class_option :second_color, :type => :string, :default => nil, :desc => "Force a secondary color for the stylesheet"
         
     | 
| 
      
 7 
     | 
    
         
            +
              class_option :authentication, :type => :boolean, :default => true, :desc => "Add code to manage authentication with devise"
         
     | 
| 
      
 8 
     | 
    
         
            +
              class_option :authorization, :type => :boolean, :default => true, :desc => "Add code to manage authorization with cancan"
         
     | 
| 
      
 9 
     | 
    
         
            +
              class_option :user_class, :type => :boolean, :default => 'user', :desc => "Set the user class name"
         
     | 
| 
      
 10 
     | 
    
         
            +
              class_option :formtastic, :type => :boolean, :default => true, :desc => "Copy formtastic files into leosca custom folder (inside project)"
         
     | 
| 
      
 11 
     | 
    
         
            +
              class_option :jquery_ui, :type => :boolean, :default => true, :desc => "To use jQuery ui improvement"
         
     | 
| 
      
 12 
     | 
    
         
            +
              class_option :rspec, :type => :boolean, :default => true, :desc => "Include custom rspec generator and custom templates"
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
              def generate_layout
         
     | 
| 
       15 
15 
     | 
    
         
             
                template "config.rb", "config/initializers/config.rb"
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                template "styles/#{style_name}/stylesheet.sass", "app/assets/stylesheets/#{style_name}.sass"
         
     | 
| 
      
 17 
     | 
    
         
            +
                template "styles/#{style_name}/stylesheets/app/stylesheet.sass", "app/assets/stylesheets/#{style_name}.sass"
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                copy_file "layout_helper.rb", "app/helpers/layout_helper.rb"
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
         @@ -76,7 +76,7 @@ class LeolayGenerator < Rails::Generators::Base 
     | 
|
| 
       76 
76 
     | 
    
         
             
                    config.generators do |g|
         
     | 
| 
       77 
77 
     | 
    
         
             
                        g.stylesheets         false
         
     | 
| 
       78 
78 
     | 
    
         
             
                        g.javascripts         false
         
     | 
| 
       79 
     | 
    
         
            -
                        g.leosca_controller 
     | 
| 
      
 79 
     | 
    
         
            +
                        g.leosca_controller   :leosca_controller
         
     | 
| 
       80 
80 
     | 
    
         
             
                      end
         
     | 
| 
       81 
81 
     | 
    
         | 
| 
       82 
82 
     | 
    
         
             
                      config.autoload_paths += %W(\#{config.root}/lib/extras)
         
     | 
| 
         @@ -185,15 +185,16 @@ class LeolayGenerator < Rails::Generators::Base 
     | 
|
| 
       185 
185 
     | 
    
         
             
              def setup_formtastic
         
     | 
| 
       186 
186 
     | 
    
         
             
                return unless options.formtastic?
         
     | 
| 
       187 
187 
     | 
    
         | 
| 
       188 
     | 
    
         
            -
                path = " 
     | 
| 
      
 188 
     | 
    
         
            +
                path = "styles/#{style_name}/stylesheets/vendor/formtastic"
         
     | 
| 
      
 189 
     | 
    
         
            +
                dest_path = "vendor/assets/stylesheets/formtastic"
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
                path = dest_path unless File.exists?(path)
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
       189 
193 
     | 
    
         
             
                file = "#{path}/formtastic.css"
         
     | 
| 
       190 
194 
     | 
    
         
             
                copy_file file, file unless File.exists?(file)
         
     | 
| 
       191 
195 
     | 
    
         
             
                file = "#{path}/formtastic_changes.css"
         
     | 
| 
       192 
196 
     | 
    
         
             
                copy_file file, file
         
     | 
| 
       193 
197 
     | 
    
         | 
| 
       194 
     | 
    
         
            -
                path = "vendor/assets/stylesheets/jquery-ui"
         
     | 
| 
       195 
     | 
    
         
            -
                directory path, path
         
     | 
| 
       196 
     | 
    
         
            -
             
     | 
| 
       197 
198 
     | 
    
         
             
                file = "config/initializers/formtastic.rb"
         
     | 
| 
       198 
199 
     | 
    
         
             
                inject_into_file file, :after => "# Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false" do
         
     | 
| 
       199 
200 
     | 
    
         
             
                  <<-FILE.gsub(/^      /, '')
         
     | 
| 
         @@ -265,6 +266,8 @@ class LeolayGenerator < Rails::Generators::Base 
     | 
|
| 
       265 
266 
     | 
    
         
             
                copy_file file, file
         
     | 
| 
       266 
267 
     | 
    
         | 
| 
       267 
268 
     | 
    
         
             
                if options.jquery_ui?
         
     | 
| 
      
 269 
     | 
    
         
            +
                  directory "styles/#{style_name}/stylesheets/vendor/jquery-ui", "vendor/assets/stylesheets/jquery-ui"
         
     | 
| 
      
 270 
     | 
    
         
            +
             
     | 
| 
       268 
271 
     | 
    
         
             
                  file = "#{app_path}/application.css"
         
     | 
| 
       269 
272 
     | 
    
         
             
                  inject_into_file file, :before => "*/" do
         
     | 
| 
       270 
273 
     | 
    
         
             
                    <<-FILE.gsub(/^        /, '')
         
     | 
| 
         @@ -290,14 +293,14 @@ class LeolayGenerator < Rails::Generators::Base 
     | 
|
| 
       290 
293 
     | 
    
         | 
| 
       291 
294 
     | 
    
         
             
              def setup_rspec
         
     | 
| 
       292 
295 
     | 
    
         
             
                file = "spec/spec_helper.rb"
         
     | 
| 
       293 
     | 
    
         
            -
                return unless File.exists?  
     | 
| 
      
 296 
     | 
    
         
            +
                return unless File.exists?(file) && options.rspec?
         
     | 
| 
       294 
297 
     | 
    
         
             
                inject_into_file file, :after => "require 'rspec/rails'" do
         
     | 
| 
       295 
298 
     | 
    
         
             
                <<-FILE.gsub(/^    /, '')
         
     | 
| 
       296 
299 
     | 
    
         | 
| 
       297 
300 
     | 
    
         
             
                require 'capybara/rspec'
         
     | 
| 
       298 
301 
     | 
    
         
             
                require 'helpers/application_helpers_spec'
         
     | 
| 
       299 
302 
     | 
    
         | 
| 
       300 
     | 
    
         
            -
                Capybara.default_wait_time =  
     | 
| 
      
 303 
     | 
    
         
            +
                Capybara.default_wait_time = 10 #default=2
         
     | 
| 
       301 
304 
     | 
    
         
             
                FILE
         
     | 
| 
       302 
305 
     | 
    
         
             
                end
         
     | 
| 
       303 
306 
     | 
    
         | 
| 
         @@ -332,6 +335,10 @@ class LeolayGenerator < Rails::Generators::Base 
     | 
|
| 
       332 
335 
     | 
    
         
             
                copy_file file, file
         
     | 
| 
       333 
336 
     | 
    
         
             
                file = "lib/templates/rspec/scaffold"
         
     | 
| 
       334 
337 
     | 
    
         
             
                directory file, file
         
     | 
| 
      
 338 
     | 
    
         
            +
                file = "lib/templates/rspec/scaffold"
         
     | 
| 
      
 339 
     | 
    
         
            +
                directory file, file
         
     | 
| 
      
 340 
     | 
    
         
            +
                file = "lib/generators/rspec/scaffold"
         
     | 
| 
      
 341 
     | 
    
         
            +
                directory file, file
         
     | 
| 
       335 
342 
     | 
    
         | 
| 
       336 
343 
     | 
    
         
             
              end
         
     | 
| 
       337 
344 
     | 
    
         | 
| 
         @@ -27,6 +27,7 @@ en: 
     | 
|
| 
       27 
27 
     | 
    
         
             
                passwords:
         
     | 
| 
       28 
28 
     | 
    
         
             
                  send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
         
     | 
| 
       29 
29 
     | 
    
         
             
                  updated: 'Your password was changed successfully. You are now signed in.'
         
     | 
| 
      
 30 
     | 
    
         
            +
                  updated_not_active: 'Your password was changed successfully.'
         
     | 
| 
       30 
31 
     | 
    
         
             
                  send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
         
     | 
| 
       31 
32 
     | 
    
         
             
                confirmations:
         
     | 
| 
       32 
33 
     | 
    
         
             
                  send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
         
     | 
| 
         @@ -25,6 +25,7 @@ it: 
     | 
|
| 
       25 
25 
     | 
    
         
             
                passwords:
         
     | 
| 
       26 
26 
     | 
    
         
             
                  send_instructions: "Riceverai un messaggio email con le istruzioni per reimpostare la tua password entro qualche minuto."
         
     | 
| 
       27 
27 
     | 
    
         
             
                  updated: "La tua password è stata cambiata. Ora sei collegato."
         
     | 
| 
      
 28 
     | 
    
         
            +
                  updated_not_active: "La tua password è stata cambiata."
         
     | 
| 
       28 
29 
     | 
    
         
             
                  send_paranoid_instructions: "Se il tuo indirizzo e-mail esiste nel nostro database, riceverai un link per il recupero della password."
         
     | 
| 
       29 
30 
     | 
    
         
             
                confirmations:
         
     | 
| 
       30 
31 
     | 
    
         
             
                  send_instructions: "Riceverai un messaggio email con le istruzioni per confermare il tuo account entro qualche minuto."
         
     | 
| 
         @@ -51,7 +51,7 @@ en: 
     | 
|
| 
       51 
51 
     | 
    
         
             
                currency:
         
     | 
| 
       52 
52 
     | 
    
         
             
                  format:
         
     | 
| 
       53 
53 
     | 
    
         
             
                    # Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
         
     | 
| 
       54 
     | 
    
         
            -
                    format: "%u%n"
         
     | 
| 
      
 54 
     | 
    
         
            +
                    format: "%u %n"
         
     | 
| 
       55 
55 
     | 
    
         
             
                    unit: "$"
         
     | 
| 
       56 
56 
     | 
    
         
             
                    # These five are to override number.format and are optional
         
     | 
| 
       57 
57 
     | 
    
         
             
                    separator: "."
         
     | 
| 
         @@ -179,9 +179,9 @@ en: 
     | 
|
| 
       179 
179 
     | 
    
         
             
                  prompt: "Please select"
         
     | 
| 
       180 
180 
     | 
    
         
             
                # Default translation keys for submit FormHelper
         
     | 
| 
       181 
181 
     | 
    
         
             
                submit:
         
     | 
| 
       182 
     | 
    
         
            -
                  create:  
     | 
| 
       183 
     | 
    
         
            -
                  update:  
     | 
| 
       184 
     | 
    
         
            -
                  submit:  
     | 
| 
      
 182 
     | 
    
         
            +
                  create: "Create %{model}"
         
     | 
| 
      
 183 
     | 
    
         
            +
                  update: "Update %{model}"
         
     | 
| 
      
 184 
     | 
    
         
            +
                  submit: "Save %{model}"
         
     | 
| 
       185 
185 
     | 
    
         | 
| 
       186 
186 
     | 
    
         
             
              activerecord: &activerecord
         
     | 
| 
       187 
187 
     | 
    
         
             
                models: &models
         
     | 
| 
         @@ -220,7 +220,7 @@ en: 
     | 
|
| 
       220 
220 
     | 
    
         
             
                current_password: "Current password"
         
     | 
| 
       221 
221 
     | 
    
         
             
                new_password: "New password"
         
     | 
| 
       222 
222 
     | 
    
         | 
| 
       223 
     | 
    
         
            -
              unknown_request: "Sorry, this request is  
     | 
| 
      
 223 
     | 
    
         
            +
              unknown_request: "Sorry, this request is unknown and cannot be processed"
         
     | 
| 
       224 
224 
     | 
    
         
             
              generic_error: "An error was occured and doesn't permit to execute this operation"
         
     | 
| 
       225 
225 
     | 
    
         
             
              permission_denied: "You don't have authorization to perform this request."
         
     | 
| 
       226 
226 
     | 
    
         
             
              created: "%{model} was successfully created."
         
     | 
| 
         @@ -57,8 +57,8 @@ it: 
     | 
|
| 
       57 
57 
     | 
    
         
             
                    format: "%n %u"
         
     | 
| 
       58 
58 
     | 
    
         
             
                    unit: "€"
         
     | 
| 
       59 
59 
     | 
    
         
             
                    # These five are to override number.format and are optional
         
     | 
| 
       60 
     | 
    
         
            -
                    separator: " 
     | 
| 
       61 
     | 
    
         
            -
                    delimiter: " 
     | 
| 
      
 60 
     | 
    
         
            +
                    separator: ","
         
     | 
| 
      
 61 
     | 
    
         
            +
                    delimiter: "."
         
     | 
| 
       62 
62 
     | 
    
         
             
                    precision: 2
         
     | 
| 
       63 
63 
     | 
    
         
             
                    significant: false
         
     | 
| 
       64 
64 
     | 
    
         
             
                    strip_insignificant_zeros: false
         
     | 
| 
         @@ -177,9 +177,9 @@ it: 
     | 
|
| 
       177 
177 
     | 
    
         
             
                  prompt: "Seleziona ..."
         
     | 
| 
       178 
178 
     | 
    
         
             
                # Default translation keys for submit FormHelper
         
     | 
| 
       179 
179 
     | 
    
         
             
                submit:
         
     | 
| 
       180 
     | 
    
         
            -
                  create:  
     | 
| 
       181 
     | 
    
         
            -
                  update:  
     | 
| 
       182 
     | 
    
         
            -
                  submit:  
     | 
| 
      
 180 
     | 
    
         
            +
                  create: "Crea %{model}"
         
     | 
| 
      
 181 
     | 
    
         
            +
                  update: "Aggiorna %{model}"
         
     | 
| 
      
 182 
     | 
    
         
            +
                  submit: "Salva %{model}"
         
     | 
| 
       183 
183 
     | 
    
         | 
| 
       184 
184 
     | 
    
         
             
              activerecord: &activerecord
         
     | 
| 
       185 
185 
     | 
    
         
             
                models: &models
         
     | 
| 
         @@ -0,0 +1,173 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'generators/rspec'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rails/generators/resource_helpers'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'generators/base' #leonardo base
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            puts "*" * 22
         
     | 
| 
      
 6 
     | 
    
         
            +
            puts "Custom rspec generator"
         
     | 
| 
      
 7 
     | 
    
         
            +
            puts "*" * 22
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            module Rspec
         
     | 
| 
      
 10 
     | 
    
         
            +
              module Generators
         
     | 
| 
      
 11 
     | 
    
         
            +
                class ScaffoldGenerator < Base
         
     | 
| 
      
 12 
     | 
    
         
            +
                  include Rails::Generators::ResourceHelpers
         
     | 
| 
      
 13 
     | 
    
         
            +
                  include ::Leonardo::Leosca
         
     | 
| 
      
 14 
     | 
    
         
            +
                  include ::Leonardo::Nested
         
     | 
| 
      
 15 
     | 
    
         
            +
                  include ::Leonardo::Nested::Test
         
     | 
| 
      
 16 
     | 
    
         
            +
                  source_paths << File.expand_path("../../helper/templates", __FILE__)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  class_option :orm, :desc => "ORM used to generate the controller"
         
     | 
| 
      
 20 
     | 
    
         
            +
                  class_option :template_engine, :desc => "Template engine to generate view files"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  class_option :controller_specs, :type => :boolean, :default => true,  :desc => "Generate controller specs"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  class_option :view_specs,       :type => :boolean, :default => true,  :desc => "Generate view specs"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  #Leonardo includes custom views to support capybara
         
     | 
| 
      
 26 
     | 
    
         
            +
                  #class_option :webrat,           :type => :boolean, :default => false, :desc => "Use webrat methods/matchers"
         
     | 
| 
      
 27 
     | 
    
         
            +
                  #class_option :webrat_matchers,  :type => :boolean, :default => false, :desc => "Use webrat methods/matchers (deprecated - use --webrat)"
         
     | 
| 
      
 28 
     | 
    
         
            +
                  class_option :helper_specs,     :type => :boolean, :default => true,  :desc => "Generate helper specs"
         
     | 
| 
      
 29 
     | 
    
         
            +
                  class_option :routing_specs,    :type => :boolean, :default => true,  :desc => "Generate routing specs"
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  #Leonardo options
         
     | 
| 
      
 32 
     | 
    
         
            +
                  class_option :remote, :type => :boolean, :default => true, :desc => "It checks ajax sections"
         
     | 
| 
      
 33 
     | 
    
         
            +
                  class_option :under, :type => :string, :default => "", :banner => "brand/category", :desc => "Nested resources"
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  def generate_controller_spec
         
     | 
| 
      
 36 
     | 
    
         
            +
                    return unless options[:controller_specs]
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                    template 'controller_spec.rb',
         
     | 
| 
      
 39 
     | 
    
         
            +
                             File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
         
     | 
| 
      
 40 
     | 
    
         
            +
                  end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                  def generate_view_specs
         
     | 
| 
      
 43 
     | 
    
         
            +
                    return unless options[:view_specs]
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                    copy_view :edit
         
     | 
| 
      
 46 
     | 
    
         
            +
                    copy_view :index unless options[:singleton]
         
     | 
| 
      
 47 
     | 
    
         
            +
                    copy_view :new
         
     | 
| 
      
 48 
     | 
    
         
            +
                    copy_view :show
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  # Invoke the helper using the controller name (pluralized)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  hook_for :helper, :as => :scaffold do |invoked|
         
     | 
| 
      
 53 
     | 
    
         
            +
                    invoke invoked, [ controller_name ]
         
     | 
| 
      
 54 
     | 
    
         
            +
                  end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                  def generate_routing_spec
         
     | 
| 
      
 57 
     | 
    
         
            +
                    return unless options[:routing_specs]
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                    template 'routing_spec.rb',
         
     | 
| 
      
 60 
     | 
    
         
            +
                      File.join('spec/routing', controller_class_path, "#{controller_file_name}_routing_spec.rb")
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                  hook_for :integration_tool, :as => :integration
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                  protected
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                    def webrat?
         
     | 
| 
      
 68 
     | 
    
         
            +
                      RSpec.deprecate("--webrat-matchers", "--webrat") if options[:webrat_matchers]
         
     | 
| 
      
 69 
     | 
    
         
            +
                      options[:webrat] || options[:webrat_matchers]
         
     | 
| 
      
 70 
     | 
    
         
            +
                    end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                    def copy_view(view)
         
     | 
| 
      
 73 
     | 
    
         
            +
                      template "#{view}_spec.rb",
         
     | 
| 
      
 74 
     | 
    
         
            +
                               File.join("spec/views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
         
     | 
| 
      
 75 
     | 
    
         
            +
                    end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                    def params
         
     | 
| 
      
 78 
     | 
    
         
            +
                      "{'these' => 'params'}"
         
     | 
| 
      
 79 
     | 
    
         
            +
                    end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                    # support for namespaced-resources
         
     | 
| 
      
 82 
     | 
    
         
            +
                    def ns_file_name
         
     | 
| 
      
 83 
     | 
    
         
            +
                      if ARGV[0].match(/(\w+)\/(\w+)/)
         
     | 
| 
      
 84 
     | 
    
         
            +
                        "#{$1.underscore}_#{$2.singularize.underscore}"
         
     | 
| 
      
 85 
     | 
    
         
            +
                      else
         
     | 
| 
      
 86 
     | 
    
         
            +
                        file_name
         
     | 
| 
      
 87 
     | 
    
         
            +
                      end
         
     | 
| 
      
 88 
     | 
    
         
            +
                    end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                    # support for namespaced-resources
         
     | 
| 
      
 91 
     | 
    
         
            +
                    def ns_table_name
         
     | 
| 
      
 92 
     | 
    
         
            +
                      if ARGV[0].match(/(\w+)\/(\w+)/)
         
     | 
| 
      
 93 
     | 
    
         
            +
                        "#{$1.underscore}/#{$2.tableize}"
         
     | 
| 
      
 94 
     | 
    
         
            +
                      else
         
     | 
| 
      
 95 
     | 
    
         
            +
                        table_name
         
     | 
| 
      
 96 
     | 
    
         
            +
                      end
         
     | 
| 
      
 97 
     | 
    
         
            +
                    end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                    # Returns the name of the mock. For example, if the file name is user,
         
     | 
| 
      
 100 
     | 
    
         
            +
                    # it returns mock_user.
         
     | 
| 
      
 101 
     | 
    
         
            +
                    #
         
     | 
| 
      
 102 
     | 
    
         
            +
                    # If a hash is given, it uses the hash key as the ORM method and the
         
     | 
| 
      
 103 
     | 
    
         
            +
                    # value as response. So, for ActiveRecord and file name "User":
         
     | 
| 
      
 104 
     | 
    
         
            +
                    #
         
     | 
| 
      
 105 
     | 
    
         
            +
                    #   mock_file_name(:save => true)
         
     | 
| 
      
 106 
     | 
    
         
            +
                    #   #=> mock_user(:save => true)
         
     | 
| 
      
 107 
     | 
    
         
            +
                    #
         
     | 
| 
      
 108 
     | 
    
         
            +
                    # If another ORM is being used and another method instead of save is
         
     | 
| 
      
 109 
     | 
    
         
            +
                    # called, it will be the one used.
         
     | 
| 
      
 110 
     | 
    
         
            +
                    #
         
     | 
| 
      
 111 
     | 
    
         
            +
                    def mock_file_name(hash=nil)
         
     | 
| 
      
 112 
     | 
    
         
            +
                      if hash
         
     | 
| 
      
 113 
     | 
    
         
            +
                        method, and_return = hash.to_a.first
         
     | 
| 
      
 114 
     | 
    
         
            +
                        method = orm_instance.send(method).split('.').last.gsub(/\(.*?\)/, '')
         
     | 
| 
      
 115 
     | 
    
         
            +
                        "mock_#{ns_file_name}(:#{method} => #{and_return})"
         
     | 
| 
      
 116 
     | 
    
         
            +
                      else
         
     | 
| 
      
 117 
     | 
    
         
            +
                        "mock_#{ns_file_name}"
         
     | 
| 
      
 118 
     | 
    
         
            +
                      end
         
     | 
| 
      
 119 
     | 
    
         
            +
                    end
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                    # Receives the ORM chain and convert to expects. For ActiveRecord:
         
     | 
| 
      
 122 
     | 
    
         
            +
                    #
         
     | 
| 
      
 123 
     | 
    
         
            +
                    #   should! orm_class.find(User, "37")
         
     | 
| 
      
 124 
     | 
    
         
            +
                    #   #=> User.should_receive(:find).with(37)
         
     | 
| 
      
 125 
     | 
    
         
            +
                    #
         
     | 
| 
      
 126 
     | 
    
         
            +
                    # For Datamapper:
         
     | 
| 
      
 127 
     | 
    
         
            +
                    #
         
     | 
| 
      
 128 
     | 
    
         
            +
                    #   should! orm_class.find(User, "37")
         
     | 
| 
      
 129 
     | 
    
         
            +
                    #   #=> User.should_receive(:get).with(37)
         
     | 
| 
      
 130 
     | 
    
         
            +
                    #
         
     | 
| 
      
 131 
     | 
    
         
            +
                    def should_receive(chain)
         
     | 
| 
      
 132 
     | 
    
         
            +
                      stub_or_should_chain(:should_receive, chain)
         
     | 
| 
      
 133 
     | 
    
         
            +
                    end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
                    # Receives the ORM chain and convert to stub. For ActiveRecord:
         
     | 
| 
      
 136 
     | 
    
         
            +
                    #
         
     | 
| 
      
 137 
     | 
    
         
            +
                    #   stub orm_class.find(User, "37")
         
     | 
| 
      
 138 
     | 
    
         
            +
                    #   #=> User.stub(:find).with(37)
         
     | 
| 
      
 139 
     | 
    
         
            +
                    #
         
     | 
| 
      
 140 
     | 
    
         
            +
                    # For Datamapper:
         
     | 
| 
      
 141 
     | 
    
         
            +
                    #
         
     | 
| 
      
 142 
     | 
    
         
            +
                    #   stub orm_class.find(User, "37")
         
     | 
| 
      
 143 
     | 
    
         
            +
                    #   #=> User.stub(:get).with(37)
         
     | 
| 
      
 144 
     | 
    
         
            +
                    #
         
     | 
| 
      
 145 
     | 
    
         
            +
                    def stub(chain)
         
     | 
| 
      
 146 
     | 
    
         
            +
                      stub_or_should_chain(:stub, chain)
         
     | 
| 
      
 147 
     | 
    
         
            +
                    end
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                    def stub_or_should_chain(mode, chain)
         
     | 
| 
      
 150 
     | 
    
         
            +
                      receiver, method = chain.split(".")
         
     | 
| 
      
 151 
     | 
    
         
            +
                      method.gsub!(/\((.*?)\)/, '')
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
                      response = "#{receiver}.#{mode}(:#{method})"
         
     | 
| 
      
 154 
     | 
    
         
            +
                      response << ".with(#{$1})" unless $1.blank?
         
     | 
| 
      
 155 
     | 
    
         
            +
                      response
         
     | 
| 
      
 156 
     | 
    
         
            +
                    end
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                    def value_for(attribute)
         
     | 
| 
      
 159 
     | 
    
         
            +
                      case attribute.type
         
     | 
| 
      
 160 
     | 
    
         
            +
                      when :string
         
     | 
| 
      
 161 
     | 
    
         
            +
                        "#{attribute.name.titleize}".inspect
         
     | 
| 
      
 162 
     | 
    
         
            +
                      else
         
     | 
| 
      
 163 
     | 
    
         
            +
                        attribute.default.inspect
         
     | 
| 
      
 164 
     | 
    
         
            +
                      end
         
     | 
| 
      
 165 
     | 
    
         
            +
                    end
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                    def banner
         
     | 
| 
      
 168 
     | 
    
         
            +
                      self.class.banner
         
     | 
| 
      
 169 
     | 
    
         
            +
                    end
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
                end
         
     | 
| 
      
 172 
     | 
    
         
            +
              end
         
     | 
| 
      
 173 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,5 +1,4 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'helpers/application_helpers_spec'
         
     | 
| 
       3 
2 
     | 
    
         | 
| 
       4 
3 
     | 
    
         
             
            # This spec was generated by rspec-rails when you ran the scaffold generator.
         
     | 
| 
       5 
4 
     | 
    
         
             
            # It demonstrates how one might use RSpec to specify the controller code that
         
     | 
| 
         @@ -20,14 +19,13 @@ require 'helpers/application_helpers_spec' 
     | 
|
| 
       20 
19 
     | 
    
         
             
            # that an instance is receiving a specific message.
         
     | 
| 
       21 
20 
     | 
    
         | 
| 
       22 
21 
     | 
    
         
             
            describe <%= controller_class_name %>Controller do
         
     | 
| 
       23 
     | 
    
         
            -
              include ApplicationHelpers
         
     | 
| 
       24 
22 
     | 
    
         | 
| 
       25 
23 
     | 
    
         
             
            <% unless options[:singleton] -%>
         
     | 
| 
       26 
24 
     | 
    
         
             
              describe "GET index" do
         
     | 
| 
       27 
25 
     | 
    
         
             
                it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
         
     | 
| 
       28 
     | 
    
         
            -
                  login_controller_as(:user)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       29 
27 
     | 
    
         
             
                  <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       30 
     | 
    
         
            -
                  get :index
         
     | 
| 
      
 28 
     | 
    
         
            +
                  get :index<%= nested_params_http_request %>
         
     | 
| 
       31 
29 
     | 
    
         
             
                  assigns(:<%= table_name %>).should eq([<%= file_name %>])
         
     | 
| 
       32 
30 
     | 
    
         
             
                end
         
     | 
| 
       33 
31 
     | 
    
         
             
              end
         
     | 
| 
         @@ -35,26 +33,26 @@ describe <%= controller_class_name %>Controller do 
     | 
|
| 
       35 
33 
     | 
    
         
             
            <% end -%>
         
     | 
| 
       36 
34 
     | 
    
         
             
              describe "GET show" do
         
     | 
| 
       37 
35 
     | 
    
         
             
                it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
         
     | 
| 
       38 
     | 
    
         
            -
                  login_controller_as(:user)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       39 
37 
     | 
    
         
             
                  <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       40 
     | 
    
         
            -
                  get :show, :id => <%= file_name %>.id.to_s
         
     | 
| 
      
 38 
     | 
    
         
            +
                  get :show, :id => <%= file_name %>.id.to_s<%= nested_params_http_request %>
         
     | 
| 
       41 
39 
     | 
    
         
             
                  assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
         
     | 
| 
       42 
40 
     | 
    
         
             
                end
         
     | 
| 
       43 
41 
     | 
    
         
             
              end
         
     | 
| 
       44 
42 
     | 
    
         | 
| 
       45 
43 
     | 
    
         
             
              describe "GET new" do
         
     | 
| 
       46 
44 
     | 
    
         
             
                it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
         
     | 
| 
       47 
     | 
    
         
            -
                  login_controller_as(:user)
         
     | 
| 
       48 
     | 
    
         
            -
                  get :new
         
     | 
| 
      
 45 
     | 
    
         
            +
                  <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
      
 46 
     | 
    
         
            +
                  get :new<%= nested_params_http_request_new_parent %>
         
     | 
| 
       49 
47 
     | 
    
         
             
                  assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
         
     | 
| 
       50 
48 
     | 
    
         
             
                end
         
     | 
| 
       51 
49 
     | 
    
         
             
              end
         
     | 
| 
       52 
50 
     | 
    
         | 
| 
       53 
51 
     | 
    
         
             
              describe "GET edit" do
         
     | 
| 
       54 
52 
     | 
    
         
             
                it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
         
     | 
| 
       55 
     | 
    
         
            -
                  login_controller_as(:user)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       56 
54 
     | 
    
         
             
                  <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       57 
     | 
    
         
            -
                  get :edit, :id => <%= file_name %>.id.to_s
         
     | 
| 
      
 55 
     | 
    
         
            +
                  get :edit, :id => <%= file_name %>.id.to_s<%= nested_params_http_request %>
         
     | 
| 
       58 
56 
     | 
    
         
             
                  assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
         
     | 
| 
       59 
57 
     | 
    
         
             
                end
         
     | 
| 
       60 
58 
     | 
    
         
             
              end
         
     | 
| 
         @@ -62,40 +60,40 @@ describe <%= controller_class_name %>Controller do 
     | 
|
| 
       62 
60 
     | 
    
         
             
              describe "POST create" do
         
     | 
| 
       63 
61 
     | 
    
         
             
                describe "with valid params" do
         
     | 
| 
       64 
62 
     | 
    
         
             
                  it "creates a new <%= class_name %>" do
         
     | 
| 
       65 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
      
 63 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       66 
64 
     | 
    
         
             
                    expect {
         
     | 
| 
       67 
     | 
    
         
            -
                      post :create, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)
         
     | 
| 
      
 65 
     | 
    
         
            +
                      post :create, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)<%= nested_params_http_request_new_parent %>
         
     | 
| 
       68 
66 
     | 
    
         
             
                    }.to change(<%= class_name %>, :count).by(1)
         
     | 
| 
       69 
67 
     | 
    
         
             
                  end
         
     | 
| 
       70 
68 
     | 
    
         | 
| 
       71 
69 
     | 
    
         
             
                  it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
         
     | 
| 
       72 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
       73 
     | 
    
         
            -
                    post :create, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)
         
     | 
| 
      
 70 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
      
 71 
     | 
    
         
            +
                    post :create, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)<%= nested_params_http_request_new_parent %>
         
     | 
| 
       74 
72 
     | 
    
         
             
                    assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
         
     | 
| 
       75 
73 
     | 
    
         
             
                    assigns(:<%= ns_file_name %>).should be_persisted
         
     | 
| 
       76 
74 
     | 
    
         
             
                  end
         
     | 
| 
       77 
75 
     | 
    
         | 
| 
       78 
76 
     | 
    
         
             
                  it "redirects to the created <%= ns_file_name %>" do
         
     | 
| 
       79 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
       80 
     | 
    
         
            -
                    post :create, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)
         
     | 
| 
       81 
     | 
    
         
            -
                    response.should redirect_to(<%= class_name  
     | 
| 
      
 77 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
      
 78 
     | 
    
         
            +
                    post :create, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)<%= nested_params_http_request_new_parent %>
         
     | 
| 
      
 79 
     | 
    
         
            +
                    response.should redirect_to(<%= show_resource_path_test "#{class_name}.last" %>)
         
     | 
| 
       82 
80 
     | 
    
         
             
                  end
         
     | 
| 
       83 
81 
     | 
    
         
             
                end
         
     | 
| 
       84 
82 
     | 
    
         | 
| 
       85 
83 
     | 
    
         
             
                describe "with invalid params" do
         
     | 
| 
       86 
84 
     | 
    
         
             
                  it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
         
     | 
| 
       87 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
      
 85 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       88 
86 
     | 
    
         
             
                    # Trigger the behavior that occurs when invalid params are submitted
         
     | 
| 
       89 
87 
     | 
    
         
             
                    <%= class_name %>.any_instance.stub(:save).and_return(false)
         
     | 
| 
       90 
     | 
    
         
            -
                    post :create, :<%= ns_file_name %> => {}
         
     | 
| 
      
 88 
     | 
    
         
            +
                    post :create, :<%= ns_file_name %> => {}<%= nested_params_http_request_new_parent %>
         
     | 
| 
       91 
89 
     | 
    
         
             
                    assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
         
     | 
| 
       92 
90 
     | 
    
         
             
                  end
         
     | 
| 
       93 
91 
     | 
    
         | 
| 
       94 
92 
     | 
    
         
             
                  it "re-renders the 'new' template" do
         
     | 
| 
       95 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
      
 93 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       96 
94 
     | 
    
         
             
                    # Trigger the behavior that occurs when invalid params are submitted
         
     | 
| 
       97 
95 
     | 
    
         
             
                    <%= class_name %>.any_instance.stub(:save).and_return(false)
         
     | 
| 
       98 
     | 
    
         
            -
                    post :create, :<%= ns_file_name %> => {}
         
     | 
| 
      
 96 
     | 
    
         
            +
                    post :create, :<%= ns_file_name %> => {}<%= nested_params_http_request_new_parent %>
         
     | 
| 
       99 
97 
     | 
    
         
             
                    response.should render_template("new")
         
     | 
| 
       100 
98 
     | 
    
         
             
                  end
         
     | 
| 
       101 
99 
     | 
    
         
             
                end
         
     | 
| 
         @@ -104,47 +102,47 @@ describe <%= controller_class_name %>Controller do 
     | 
|
| 
       104 
102 
     | 
    
         
             
              describe "PUT update" do
         
     | 
| 
       105 
103 
     | 
    
         
             
                describe "with valid params" do
         
     | 
| 
       106 
104 
     | 
    
         
             
                  it "updates the requested <%= ns_file_name %>" do
         
     | 
| 
       107 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
      
 105 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       108 
106 
     | 
    
         
             
                    <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       109 
107 
     | 
    
         
             
                    # Assuming there are no other <%= table_name %> in the database, this
         
     | 
| 
       110 
108 
     | 
    
         
             
                    # specifies that the <%= class_name %> created on the previous line
         
     | 
| 
       111 
109 
     | 
    
         
             
                    # receives the :update_attributes message with whatever params are
         
     | 
| 
       112 
110 
     | 
    
         
             
                    # submitted in the request.
         
     | 
| 
       113 
111 
     | 
    
         
             
                    <%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= params %>)
         
     | 
| 
       114 
     | 
    
         
            -
                    put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => <%= params %>
         
     | 
| 
      
 112 
     | 
    
         
            +
                    put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => <%= params %><%= nested_params_http_request %>
         
     | 
| 
       115 
113 
     | 
    
         
             
                  end
         
     | 
| 
       116 
114 
     | 
    
         | 
| 
       117 
115 
     | 
    
         
             
                  it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
         
     | 
| 
       118 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
      
 116 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       119 
117 
     | 
    
         
             
                    <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       120 
     | 
    
         
            -
                    put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)
         
     | 
| 
      
 118 
     | 
    
         
            +
                    put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)<%= nested_params_http_request %>
         
     | 
| 
       121 
119 
     | 
    
         
             
                    assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
         
     | 
| 
       122 
120 
     | 
    
         
             
                  end
         
     | 
| 
       123 
121 
     | 
    
         | 
| 
       124 
122 
     | 
    
         
             
                  it "redirects to the <%= ns_file_name %>" do
         
     | 
| 
       125 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
      
 123 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       126 
124 
     | 
    
         
             
                    <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       127 
     | 
    
         
            -
                    put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)
         
     | 
| 
       128 
     | 
    
         
            -
                    response.should redirect_to(<%=  
     | 
| 
      
 125 
     | 
    
         
            +
                    put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => Factory.attributes_for(:<%= file_name %>)<%= nested_params_http_request %>
         
     | 
| 
      
 126 
     | 
    
         
            +
                    response.should redirect_to(<%= show_resource_path_test %>)
         
     | 
| 
       129 
127 
     | 
    
         
             
                  end
         
     | 
| 
       130 
128 
     | 
    
         
             
                end
         
     | 
| 
       131 
129 
     | 
    
         | 
| 
       132 
130 
     | 
    
         
             
                describe "with invalid params" do
         
     | 
| 
       133 
131 
     | 
    
         
             
                  it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
         
     | 
| 
       134 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
      
 132 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       135 
133 
     | 
    
         
             
                    <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       136 
134 
     | 
    
         
             
                    # Trigger the behavior that occurs when invalid params are submitted
         
     | 
| 
       137 
135 
     | 
    
         
             
                    <%= class_name %>.any_instance.stub(:save).and_return(false)
         
     | 
| 
       138 
     | 
    
         
            -
                    put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
         
     | 
| 
      
 136 
     | 
    
         
            +
                    put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}<%= nested_params_http_request %>
         
     | 
| 
       139 
137 
     | 
    
         
             
                    assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
         
     | 
| 
       140 
138 
     | 
    
         
             
                  end
         
     | 
| 
       141 
139 
     | 
    
         | 
| 
       142 
140 
     | 
    
         
             
                  it "re-renders the 'edit' template" do
         
     | 
| 
       143 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
      
 141 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       144 
142 
     | 
    
         
             
                    <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       145 
143 
     | 
    
         
             
                    # Trigger the behavior that occurs when invalid params are submitted
         
     | 
| 
       146 
144 
     | 
    
         
             
                    <%= class_name %>.any_instance.stub(:save).and_return(false)
         
     | 
| 
       147 
     | 
    
         
            -
                    put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
         
     | 
| 
      
 145 
     | 
    
         
            +
                    put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}<%= nested_params_http_request %>
         
     | 
| 
       148 
146 
     | 
    
         
             
                    response.should render_template("edit")
         
     | 
| 
       149 
147 
     | 
    
         
             
                  end
         
     | 
| 
       150 
148 
     | 
    
         
             
                end
         
     | 
| 
         @@ -153,29 +151,31 @@ describe <%= controller_class_name %>Controller do 
     | 
|
| 
       153 
151 
     | 
    
         
             
              describe "DELETE destroy" do
         
     | 
| 
       154 
152 
     | 
    
         
             
                describe "with authorization" do
         
     | 
| 
       155 
153 
     | 
    
         
             
                  it "destroys the requested <%= ns_file_name %>" do
         
     | 
| 
       156 
     | 
    
         
            -
                    login_controller_as(:user_manager)
         
     | 
| 
      
 154 
     | 
    
         
            +
                    <%= "login_controller_as(:user_manager)" if authentication? %>
         
     | 
| 
       157 
155 
     | 
    
         
             
                    <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       158 
156 
     | 
    
         
             
                    expect {
         
     | 
| 
       159 
     | 
    
         
            -
                      delete :destroy, :id => <%= file_name %>.id.to_s
         
     | 
| 
      
 157 
     | 
    
         
            +
                      delete :destroy, :id => <%= file_name %>.id.to_s<%= nested_params_http_request %>
         
     | 
| 
       160 
158 
     | 
    
         
             
                    }.to change(<%= class_name %>, :count).by(-1)
         
     | 
| 
       161 
159 
     | 
    
         
             
                  end
         
     | 
| 
       162 
160 
     | 
    
         | 
| 
       163 
161 
     | 
    
         
             
                  it "redirects to the <%= table_name %> list" do
         
     | 
| 
       164 
     | 
    
         
            -
                    login_controller_as(:user_manager)
         
     | 
| 
      
 162 
     | 
    
         
            +
                    <%= "login_controller_as(:user_manager)" if authentication? %>
         
     | 
| 
       165 
163 
     | 
    
         
             
                    <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       166 
     | 
    
         
            -
                    delete :destroy, :id => <%= file_name %>.id.to_s
         
     | 
| 
       167 
     | 
    
         
            -
                    response.should redirect_to(<%=  
     | 
| 
      
 164 
     | 
    
         
            +
                    delete :destroy, :id => <%= file_name %>.id.to_s<%= nested_params_http_request %>
         
     | 
| 
      
 165 
     | 
    
         
            +
                    response.should redirect_to(<%= list_resources_path_test %>)
         
     | 
| 
       168 
166 
     | 
    
         
             
                  end
         
     | 
| 
       169 
167 
     | 
    
         
             
                end
         
     | 
| 
      
 168 
     | 
    
         
            +
                <%- if authorization? -%>
         
     | 
| 
       170 
169 
     | 
    
         
             
                describe "without authorization" do
         
     | 
| 
       171 
170 
     | 
    
         
             
                  it "destroys the requested <%= ns_file_name %>" do
         
     | 
| 
       172 
     | 
    
         
            -
                    login_controller_as(:user)
         
     | 
| 
      
 171 
     | 
    
         
            +
                    <%= "login_controller_as(:user)" if authentication? %>
         
     | 
| 
       173 
172 
     | 
    
         
             
                    <%= file_name %> = Factory(:<%= file_name %>)
         
     | 
| 
       174 
173 
     | 
    
         
             
                    expect {
         
     | 
| 
       175 
     | 
    
         
            -
                      delete :destroy, :id => <%= file_name %>.id.to_s
         
     | 
| 
      
 174 
     | 
    
         
            +
                      delete :destroy, :id => <%= file_name %>.id.to_s<%= nested_params_http_request %>
         
     | 
| 
       176 
175 
     | 
    
         
             
                    }.to change(<%= class_name %>, :count).by(0)
         
     | 
| 
       177 
176 
     | 
    
         
             
                  end
         
     | 
| 
       178 
177 
     | 
    
         
             
                end
         
     | 
| 
      
 178 
     | 
    
         
            +
                <%- end -%>
         
     | 
| 
       179 
179 
     | 
    
         
             
              end
         
     | 
| 
       180 
180 
     | 
    
         | 
| 
       181 
181 
     | 
    
         
             
            end
         
     | 
| 
         @@ -4,12 +4,15 @@ require 'spec_helper' 
     | 
|
| 
       4 
4 
     | 
    
         
             
            describe "<%= ns_table_name %>/edit.html.<%= options[:template_engine] %>" do
         
     | 
| 
       5 
5 
     | 
    
         
             
              before(:each) do
         
     | 
| 
       6 
6 
     | 
    
         
             
                @<%= ns_file_name %> = assign(:<%= ns_file_name %>, Factory(:<%= ns_file_name %>) )
         
     | 
| 
      
 7 
     | 
    
         
            +
                <%- base_parent_resources.each do |parent| -%>
         
     | 
| 
      
 8 
     | 
    
         
            +
                @<%= parent %> = assign(:<%= parent %>, @<%= ns_file_name %>.<%= parent %> )
         
     | 
| 
      
 9 
     | 
    
         
            +
                <%- end -%>
         
     | 
| 
       7 
10 
     | 
    
         
             
              end
         
     | 
| 
       8 
11 
     | 
    
         | 
| 
       9 
12 
     | 
    
         
             
              it "renders the edit <%= ns_file_name %> form" do
         
     | 
| 
       10 
13 
     | 
    
         
             
                render
         
     | 
| 
       11 
14 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                rendered.should have_selector("form", :action => <%=  
     | 
| 
      
 15 
     | 
    
         
            +
                rendered.should have_selector("form", :action => <%= underscore_resource_path :parent_singular_resource_plural %>_path(<%= formatted_resource_path "@", "@" %>), :method => "post") do |form|
         
     | 
| 
       13 
16 
     | 
    
         
             
                <% for attribute in output_attributes -%>
         
     | 
| 
       14 
17 
     | 
    
         
             
              form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
         
     | 
| 
       15 
18 
     | 
    
         
             
                <% end -%>
         
     | 
| 
         @@ -17,8 +17,7 @@ def value_for_check(attribute) 
     | 
|
| 
       17 
17 
     | 
    
         
             
                nil
         
     | 
| 
       18 
18 
     | 
    
         
             
              else
         
     | 
| 
       19 
19 
     | 
    
         
             
                "#{name} => r.#{attribute.name}"
         
     | 
| 
       20 
     | 
    
         
            -
              end 
     | 
| 
       21 
     | 
    
         
            -
              ":count => 1"
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
       22 
21 
     | 
    
         
             
              ).compact.join(', ')
         
     | 
| 
       23 
22 
     | 
    
         
             
            end
         
     | 
| 
       24 
23 
     | 
    
         
             
            %>
         
     | 
| 
         @@ -26,8 +25,20 @@ end 
     | 
|
| 
       26 
25 
     | 
    
         
             
            <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
         
     | 
| 
       27 
26 
     | 
    
         
             
            describe "<%= ns_table_name %>/index.html.<%= options[:template_engine] %>" do
         
     | 
| 
       28 
27 
     | 
    
         
             
              before(:each) do
         
     | 
| 
       29 
     | 
    
         
            -
                 
     | 
| 
       30 
     | 
    
         
            -
                 
     | 
| 
      
 28 
     | 
    
         
            +
                <%- parents = []; str_parents_create = str_parents_where = "" -%>
         
     | 
| 
      
 29 
     | 
    
         
            +
                <%- base_parent_resources.each do |parent| -%>
         
     | 
| 
      
 30 
     | 
    
         
            +
                @<%= parent %> = assign(:<%= parent %>, Factory(:<%= parent %>) )
         
     | 
| 
      
 31 
     | 
    
         
            +
                <%- parents << ":#{parent}_id => @#{parent}.id" -%>
         
     | 
| 
      
 32 
     | 
    
         
            +
                <%- end -%>
         
     | 
| 
      
 33 
     | 
    
         
            +
                <%- str_parents_create = ", #{parents.join(', ')}" if parents.any? -%>
         
     | 
| 
      
 34 
     | 
    
         
            +
                <%- str_parents_where = ".where(#{parents.join(', ')})" if parents.any? -%>
         
     | 
| 
      
 35 
     | 
    
         
            +
                <%- if pagination? -%>
         
     | 
| 
      
 36 
     | 
    
         
            +
                FactoryGirl.create_list(:<%= ns_file_name %>, 2<%= str_parents_create %>)
         
     | 
| 
      
 37 
     | 
    
         
            +
                @records = assign(:<%= table_name %>, <%= class_name %><%= str_parents_where %>.order(:id).page(1) )
         
     | 
| 
      
 38 
     | 
    
         
            +
                <%- else -%>
         
     | 
| 
      
 39 
     | 
    
         
            +
                @records = assign(:<%= table_name %>, FactoryGirl.create_list(:<%= ns_file_name %>, 2<%= str_parents_create %>) )
         
     | 
| 
      
 40 
     | 
    
         
            +
                <%- end -%>
         
     | 
| 
      
 41 
     | 
    
         
            +
                assign(:<%= ns_file_name %>, Factory.build(:<%= ns_file_name %>) )
         
     | 
| 
       31 
42 
     | 
    
         
             
              end
         
     | 
| 
       32 
43 
     | 
    
         | 
| 
       33 
44 
     | 
    
         
             
              it "renders a list of <%= ns_table_name %>" do
         
     | 
| 
         @@ -3,14 +3,17 @@ require 'spec_helper' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
         
     | 
| 
       4 
4 
     | 
    
         
             
            describe "<%= ns_table_name %>/new.html.<%= options[:template_engine] %>" do
         
     | 
| 
       5 
5 
     | 
    
         
             
              before(:each) do
         
     | 
| 
       6 
     | 
    
         
            -
                assign(:<%= ns_file_name %>, Factory.build(:<%= ns_file_name %>) )
         
     | 
| 
      
 6 
     | 
    
         
            +
                <%= "#{ns_file_name} = " if nested? %>assign(:<%= ns_file_name %>, Factory.build(:<%= ns_file_name %>) )
         
     | 
| 
      
 7 
     | 
    
         
            +
                <%- base_parent_resources.each do |parent| -%>
         
     | 
| 
      
 8 
     | 
    
         
            +
                @<%= parent %> = assign(:<%= parent %>, <%= ns_file_name %>.<%= parent %>)
         
     | 
| 
      
 9 
     | 
    
         
            +
                <%- end -%>
         
     | 
| 
       7 
10 
     | 
    
         
             
              end
         
     | 
| 
       8 
11 
     | 
    
         | 
| 
       9 
12 
     | 
    
         | 
| 
       10 
13 
     | 
    
         
             
              it "renders new <%= ns_file_name %> form" do
         
     | 
| 
       11 
14 
     | 
    
         
             
                render
         
     | 
| 
       12 
15 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                rendered.should have_selector("form", :action => <%=  
     | 
| 
      
 16 
     | 
    
         
            +
                rendered.should have_selector("form", :action => <%= list_resources_path_test nil, "@" %>, :method => "post") do |form|
         
     | 
| 
       14 
17 
     | 
    
         
             
                <% for attribute in output_attributes -%>
         
     | 
| 
       15 
18 
     | 
    
         
             
              form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
         
     | 
| 
       16 
19 
     | 
    
         
             
                <% end -%>
         
     |