Giter Site home page Giter Site logo

commands's Introduction

Commands

Run Rake and Rails commands during a development console session and run tests during a test console session. This side-steps the need to load the entire environment over and over again when you run these commands from the shell. This constant reloading of the environment is what causes slow boot time on big applications. Think of this like a baby Zeus or the Turbolinks of commands.

Installation

Add this line to your application's Gemfile:

gem 'commands'

And then execute:

$ bundle

Usage

When your console boots, it'll automatically have a commander object instantiated. The following methods are delegated to this object: rake, generate, destroy, update. It's used like this:

> generate "scaffold post title:string"
> rake "db:migrate"

To use a persistent console for testing, be sure to first start it in the test environment, like so ./script/rails console test. Then you can run tests like this:

> test "models"
> test "controllers"
> test "models/person"

You can see the options available for all the commands by running them with no parameters.

commands's People

Contributors

adamgamble avatar dhh avatar gbuesing avatar nviennot avatar rafaelfranca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

commands's Issues

db:migrate doesn't reload migration files

After fat fingering a migration file
PG::Error: ERROR: type "stringa" does not exist

I fix the migration, but rake "db:migrate" does not pick up the new corrected file, if running the command again it will either say:

** Invoke db:migrate => "Completed"

or throw the same exception again. I try reload! but it does not help.

When launching the console: uninitialized constant Rails::ConsoleMethods

Once I've added gem 'commands' to my Gemfile, nothing works anymore, everything stops with:
uninitialized constant Rails::ConsoleMethods

Am I doing something wrong? I love the idea of this mini-Zeus.

Stack:

/Users/gamov/.rvm/gems/ruby-1.9.3-p327@ector/gems/commands-0.2.0/lib/commands.rb:4:in `<top (required)>': uninitialized constant Rails::ConsoleMethods (NameError)
    from /Users/gamov/.rvm/gems/ruby-1.9.3-p327@global/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `require'

Ruby 1.8.7 not supported

Unfortunately I can't use commands because my project uses ruby 1.8.7

The problem is the new Hash Syntax.

/XXX/vendor/bundle/gems/backports-3.3.2/lib/backports/tools.rb:328:in 'require_without_backports': /XXX/vendor/bundle/gems/commands-0.2.1/lib/rails/commands/console_delegation.rb:19: syntax error, unexpected ':', expecting kEND (SyntaxError)
      delegate :rake, :generate, :destroy, :update, to: :commander
                                                       ^

rake -T support

doesn't support rake -T. Again more useful for development than anything.

Useful for dev

Could we add a "server" command to bring up webrick (rails s) in background and server stop could stop it. Would be nice to leave it up in one terminal.

Enable running test command in development console

I've got a working implementation of this here: https://github.com/gbuesing/duoconsole

The test environment is forked after loading Rails and gems, so this work only needs to be performed once -- should be a win for apps with lots of gems.

Commands are sent to the test process via a Unix socket -- the implementation is pretty straightforward.

App reloading behavior works as expected. To pick up changes to config/, lib/ and Gemfile, however, you need to exit the console and reload. I've got code in the "reloadable" branch that enables manual reloading of the entire app (excluding gems), but this requires keeping an additional process around, and I'm not yet sure if this is worth it.

Also, this forking fixes issue #13 (Stop sending ActiveRecord logs to STDOUT during test/rake) when running the test command, and fixes Postgres compatibility (re-establishing the AR connection before forking causes an issue.)

Let me know if there's interest in pulling any of this in here -- I'd be happy to create patches.

Watch for file system changes

Hey

I was wondering what option there are to watch for file changes and automatically have my tests run.

Would it make sense to add support for something like test watch from the rails console, or do I have to wire up some logic myself (e.g. by launching something like guard from the rails console?)

Or are there any other issues which prevent this kind of automated integration?

Options passed to rake are ignored

You currently can't pass "--trace" and friends to the rake options. It's a bit tricky because we're reusing the Rake application instance, so if we just load the options from ARGV, they'll be sticky from run to run. Need a way to reset the option list.

Classes are not being reloaded on test environment

To make test 'unit' work properly I had to change cache_classes to true in Rails 3.2.13, otherwise changes in classes are not detected.

DummyApp::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # The test environment is used exclusively to run your application's
  # test suite. You never need to work with it otherwise. Remember that
  # your test database is "scratch space" for the test suite and is wiped
  # and recreated between test runs. Don't rely on the data there!
  # config.cache_classes = true
  config.cache_classes = false
  ...
end

Seems this case should be handled by https://github.com/rails/commands/blob/master/lib/rails/commands/test_environment.rb#L24-L31 but is not.

Stop sending ActiveRecord logs to STDOUT during test/rake

I can't seem to find how ActiveRecord is sending the log lines both to STDOUT and to the development.log file. But when we're running rake and test, it shouldn't send to STDOUT (because it'll spam it with INSERTS for fixtures etc).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.