My day job consists of architecting and maintaining several Rails
applications. Some of these must deal with custom data sources that
were architected before there were standards for inter-application
communication (SOAP, REST, XML-RPC, etc). One in particular is is a custom TCP
server that responds to method calls (using XML as the transport mechanism).
Replacing the service is not an option (as is usually the case with any
PITA
legacy problem), so I have to communicate with it.
Waiting on asset precompilation is a PITA, especially if no assets have been
changed. Thankfully,
Ben Curtis
came up with a workable solution. Except...
Ben's method fails on the initial deployment, because current_revision tries to
read /path/to/app/current/REVISION, which won't exist yet. After trying several
approaches, I have arrived at one which works for me. There are probably other,
more elegant approaches, but this one seems clear enough for my purposes.
Posting it here for posterity.
I've got an app I'm building that is comprised of several engines running in
vendor/nsweb. I want each engine to have its own specs, without cluttering
up the main app's spec folder. I also want to be able to run tests for ALL
engines at once, both using rake and through autotest. To accomplish the first
task, I added the following:
RSpec::Core::RakeTask.module_eval do
def pattern
extras = []
Dir[File.join( File.expand_path( 'vendor' ), 'nsweb', '*' )].flatten.each do |dir|
if File.directory?( dir )
extras += File.join( dir, 'spec', '**', '*_spec.rb' ).to_s
end
end
[@pattern] | extras
end
end
Found this today, and
banged my head on the desk for never thinking of this when trying to add a
cancel button to a form, regardless of the language.
Like everyone, I have a bunch of controller actions that need to be protected
from unauthorized users. I've got RSpec tests around these methods that look
like this:
describe UsersController, 'as guest' do
before( :each ) do
controller.stubs( :current_user ).returns( nil )
end
describe 'index' do
it 'should prevent access' do
lambda { get :index }.should
raise_error( Exceptions::PermissionDenied )
end
end
describe 'edit' do
it 'should prevent access' do
lambda { get :edit, :id => 1 }.should
raise_error( Exceptions::PermissionDenied )
end
end
describe 'create' do
it 'should prevent access' do
lambda { post :create, :id => 1 }.should
raise_error( Exceptions::PermissionDenied )
end
end
end