Sha256: 20c95bbf0de63c001a7ba6b5a9983e5e187cff6a3698a7898645e62a7971327c

Contents?: true

Size: 980 Bytes

Versions: 4

Compression:

Stored size: 980 Bytes

Contents

module RSpec  
  module Rails
    module Controller
      def create_controller name, content=nil
        file = controller_file_name(name)
        unless File.exist?(file)    
          FileUtils.mkdir_p File.dirname(file)
          content ||= yield if block_given?          
          File.open(file, 'w') do |f|  
            f.puts controller_content(name, content)
          end
        end
      end  

      def controller_content name, content=nil
        %Q{class #{name.to_s.camelize}Controller < ActionController::Base
          #{content}
        end}        
      end

      def remove_controller name
        file = controller_file_name(name)
        FileUtils.rm_f(file) if File.exist?(file)
      end

      def remove_controllers *names
        names.each{|name| remove_controller name }
      end     
      
      def controller_file_name name
        File.join(::Rails.root, "app/controllers/#{name}_controller.rb")
      end        
      
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
generator-spec-0.4.3 lib/rspec_for_generators/rails_helpers/rails_controller.rb
generator-spec-0.4.2 lib/rspec_for_generators/rails_helpers/rails_controller.rb
generator-spec-0.4.1 lib/rspec_for_generators/rails_helpers/rails_controller.rb
generator-spec-0.4.0 lib/rspec_for_generators/rails_helpers/rails_controller.rb