Module: RSpec::Rails::Controller
- Defined in:
- lib/rspec_for_generators/rails_helpers/rails_controller.rb
Instance Method Summary collapse
- #controller_content(name) ⇒ Object
- #controller_file_name(name) ⇒ Object
- #create_controller(name) ⇒ Object
- #remove_controller(name) ⇒ Object
- #remove_controllers(*names) ⇒ Object
Instance Method Details
#controller_content(name) ⇒ Object
14 15 16 17 |
# File 'lib/rspec_for_generators/rails_helpers/rails_controller.rb', line 14 def controller_content name %Q{class #{name.to_s.camelize}Controller < ActionController::Base end} end |
#controller_file_name(name) ⇒ Object
28 29 30 |
# File 'lib/rspec_for_generators/rails_helpers/rails_controller.rb', line 28 def controller_file_name name File.join(::Rails.root, "app/controllers/#{name}.rb") end |
#create_controller(name) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/rspec_for_generators/rails_helpers/rails_controller.rb', line 4 def create_controller name file = controller_file_name(name) unless File.exist?(file) FileUtils.mkdir_p File.dirname(file) File.open(file, 'w') do |f| f.puts controller_content end end end |
#remove_controller(name) ⇒ Object
19 20 21 22 |
# File 'lib/rspec_for_generators/rails_helpers/rails_controller.rb', line 19 def remove_controller name file = controller_file_name(name) FileUtils.rm_f(file) if File.exist?(file) end |
#remove_controllers(*names) ⇒ Object
24 25 26 |
# File 'lib/rspec_for_generators/rails_helpers/rails_controller.rb', line 24 def remove_controllers *names names.each{|name| remove_controller name } end |