Namespace
Methods
- A
- B
- C
- E
- M
- R
- S
- T
- U
Instance Public methods
add_to_config(str)
Link
# File railties/test/isolation/abstract_unit.rb, line 256 def add_to_config(str) environment = File.read("#{app_path}/config/application.rb") if environment =~ /(\n\s*end\s*end\s*)\Z/ File.open("#{app_path}/config/application.rb", 'w') do |f| f.puts $` + "\n#{str}\n" + $1 end end end
add_to_env_config(env, str)
Link
# File railties/test/isolation/abstract_unit.rb, line 265 def add_to_env_config(env, str) environment = File.read("#{app_path}/config/environments/#{env}.rb") if environment =~ /(\n\s*end\s*)\Z/ File.open("#{app_path}/config/environments/#{env}.rb", 'w') do |f| f.puts $` + "\n#{str}\n" + $1 end end end
add_to_top_of_config(str)
Link
# File railties/test/isolation/abstract_unit.rb, line 247 def add_to_top_of_config(str) environment = File.read("#{app_path}/config/application.rb") if environment =~ /(Rails::Application\s*)/ File.open("#{app_path}/config/application.rb", 'w') do |f| f.puts $` + $1 + "\n#{str}\n" + $' end end end
app_file(path, contents, mode = 'w')
Link
boot_rails()
Link
build_app(options = {})
Link
Build an application by invoking the generator and going through the whole stack.
# File railties/test/isolation/abstract_unit.rb, line 104 def build_app(options = {}) @prev_rails_env = ENV['RAILS_ENV'] ENV['RAILS_ENV'] = "development" ENV['SECRET_KEY_BASE'] ||= SecureRandom.hex(16) FileUtils.rm_rf(app_path) FileUtils.cp_r(app_template_path, app_path) # Delete the initializers unless requested unless options[:initializers] Dir["#{app_path}/config/initializers/**/*.rb"].each do |initializer| File.delete(initializer) end end gemfile_path = "#{app_path}/Gemfile" if options[:gemfile].blank? && File.exist?(gemfile_path) File.delete gemfile_path end routes = File.read("#{app_path}/config/routes.rb") if routes =~ /(\n\s*end\s*)\Z/ File.open("#{app_path}/config/routes.rb", 'w') do |f| f.puts $` + "\nActiveSupport::Deprecation.silence { match ':controller(/:action(/:id))(.:format)', via: :all }\n" + $1 end end File.open("#{app_path}/config/database.yml", "w") do |f| f.puts <<-YAML default: &default adapter: sqlite3 pool: 5 timeout: 5000 development: <<: *default database: db/development.sqlite3 test: <<: *default database: db/test.sqlite3 production: <<: *default database: db/production.sqlite3 YAML end add_to_config <<-RUBY config.eager_load = false config.session_store :cookie_store, key: "_myapp_session" config.active_support.deprecation = :log config.active_support.test_order = :random config.action_controller.allow_forgery_protection = false config.log_level = :info RUBY end
controller(name, contents)
Link
engine(name)
Link
# File railties/test/isolation/abstract_unit.rb, line 224 def engine(name) dir = "#{app_path}/random/#{name}" FileUtils.mkdir_p(dir) app = File.readlines("#{app_path}/config/application.rb") app.insert(2, "$:.unshift(\"#{dir}/lib\")") app.insert(3, "require #{name.inspect}") File.open("#{app_path}/config/application.rb", 'r+') do |f| f.puts app end Bukkit.new(dir).tap do |bukkit| yield bukkit if block_given? end end
make_basic_app()
Link
Make a very basic app, without creating the whole directory structure. This is faster and simpler than the method above.
# File railties/test/isolation/abstract_unit.rb, line 165 def make_basic_app require "rails" require "action_controller/railtie" require "action_view/railtie" require 'action_dispatch/middleware/flash' @app = Class.new(Rails::Application) @app.config.eager_load = false @app.secrets.secret_key_base = "3b7cd727ee24e8444053437c36cc66c4" @app.config.session_store :cookie_store, key: "_myapp_session" @app.config.active_support.deprecation = :log @app.config.active_support.test_order = :random @app.config.log_level = :info yield @app if block_given? @app.initialize! @app.routes.draw do get "/" => "omg#index" end require 'rack/test' extend ::Rack::Test::Methods end
remove_file(path)
Link
remove_from_config(str)
Link
remove_from_env_config(env, str)
Link
remove_from_file(file, str)
Link
script(script)
Link
simple_controller()
Link
# File railties/test/isolation/abstract_unit.rb, line 190 def simple_controller controller :foo, <<-RUBY class FooController < ApplicationController def index render text: "foo" end end RUBY app_file 'config/routes.rb', <<-RUBY Rails.application.routes.draw do get ':controller(/:action)' end RUBY end
teardown_app()
Link
use_frameworks(arr)
Link
# File railties/test/isolation/abstract_unit.rb, line 303 def use_frameworks(arr) to_remove = [:actionmailer, :activerecord] - arr if to_remove.include?(:activerecord) remove_from_config 'config.active_record.*' end $:.reject! {|path| path =~ %r'/(#{to_remove.join('|')})/' } end