Just another Ruby on Rails weblog

rspec navigation using rails.vim

rspec, vim

Tim Pope hinted about adding custom Rcommands to supports navigation in rspec files with rails.vim plugin Something like :Rspecmodel, :Rspeccontroller, :Rspecview, :Rspechelper. Just add the following code in your .vimrc:

" RSpec navigation commands
autocmd User Rails Rcommand specmodel spec/models -glob=**/*
\-suffix=_spec.rb -default=model()
autocmd User Rails Rcommand spechelper spec/helpers -glob=**/*
\-suffix=_helper_spec.rb -default=controller()
autocmd User Rails Rcommand speccontroller spec/controllers -glob=**/*
\-suffix=_controller_spec.rb -default=controller()
autocmd User Rails Rcommand specview spec/views -glob=**/*
\-suffix=_view_spec.rb

You may customize :Rspecview command to match ‘html.erb’ suffix. And of course, :RSmodel, :RScontroller, etc. opens specs in split window.
See *rails-custom-navigation* and *rails-rspec* in docs

0 коментарів

Valuable addition to vim ruby/rails plugins

vim

snippetsEmu : An attempt to emulate TextMate’s snippet expansion

Here’s some of them which related to rails migrations:

  • mct create_table
  • mcdt create_table
  • mrnt rename_table
  • mdt drop_table
  • mcc t.column
  • mac add_column
  • marc add_column
  • mrnc rename_column
  • mrc remove_column

see also Rails Migration Cheat Sheet, section Snippets for more info

0 коментарів

Ruby method access levels: protected and private

ruby

Good example which illustrate the difference between protected and private methods in Ruby:

• Protected methods can be invoked only by objects of the defining class and its subclasses. Access is kept within the family.
• Private methods cannot be called with an explicit receiver—the receiver is always self. This means that private methods can be called only in the context of the current object; you can’t invoke another object’s private methods. (c) PickAxe.

0 коментарів

Adding custom hash methods to Edge Rails

hash

1. Read this
2. cd vendor/rails/activesupport/lib/active_support/core_ext/hash
3. make file filter.rb and add functions to the module Filter, as example use other files in this directory
4. make necessary changes in hash.rb in vendor/rails/activesupport/lib/active_support/core_ext

0 коментарів

Easy fixtures creation/extraction

fixtures

Need fixtures to be used in tests? And it should be real data which will be used in you application in future?

1. Feed your database with data using scaffolding forms. 
2. Extract them with rake task into your .yml file.
3. To make them convert correctly to UTF-8 use Ya2YAML instead to_yaml in above rake task.

0 коментарів