Hi Lukas,
You definitely can, by adding some temporary debug puts calls
interspersed in your method, and then calling your method either
using ./script/runner or from within a ./script/console session.
To make that method easier to test, I’d relocate that method outside
of ./app/controllers/application.rb and put it somewhere else, maybe
something like ./app/models/remote_socket_server.rb.
Possibly lame example, but:
add tmp debug calls to meth you want to test:
$ cat ./app/models/remote_socket_server.rb
class RemoteSocketServer
HOST = …
PORT = …
def RemoteSocketServer.add_user(category, email)
puts(“add_user: category=#{category} email=#{email}”) #DEBUG
socket = TCPSocket.open(HOST, PORT)
…
end
…
end
start console and call the meth:
$ ./script/console
…
RemoteSocketServer.add_user(“Stuff”, “[email protected]”)
add_user: category=Stuff [email protected]
…
or run the meth via runner:
$ ./script/runner ‘RemoteSocketServer.add_user(“Stuff”,
“[email protected]”)’
add_user: category=Stuff [email protected]
…
Also note that instead of using puts to stdout, you could change those
debug puts calls to use the environment’s logger instead:
...
ActionController::Base.logger.debug("add_user:
category=#{category} email=#{email}") #DEBUG
…
such that when that meth is called (via console, runner, or in the web
app), you can just look at the env log:
$ tail -100 ./log/development.log | grep “^add_user”
add_user: category=Stuff [email protected]
…
Once you’re done with your temp testing of the meth, just wipe out
those debug puts/logger calls.
Jeff