Sha256: d66eb8e1cb193d7718dccbe10e4988f263f2d3a7577580025520ed125a2c9d1e

Contents?: true

Size: 963 Bytes

Versions: 3

Compression:

Stored size: 963 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(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}.rb")
      end        
      
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
generator-spec-0.3.5 lib/rspec_for_generators/rails_helpers/rails_controller.rb
generator-spec-0.3.4 lib/rspec_for_generators/rails_helpers/rails_controller.rb
generator-spec-0.3.3 lib/rspec_for_generators/rails_helpers/rails_controller.rb