Rails: unit test fixture_path NameError.

Last day of my Holiday :(
Trying to write a unit test for my Rails application, I constantly got the error message below:


NameError: undefined local variable or method `fixture_path' for #<LessonTest:0x9a611f8>
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/test_process.rb:452:in `method_missing'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:593:in `load_fixtures'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:538:in `setup_with_fixtures'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:575:in `setup'

Very strange: the Unit Test I’ve written was generated and exactly the same as shown in the example in the “Agile Web Development with Rails 2nd Edition” book.


require File.dirname(__FILE__) + '/../test_helper'
class LessonTest < Test::Unit::TestCase
def test_truth
assert true
end
end

Well I found a solution, but I still haven’t found the reason WHY this is happening. You can see this is as a temporary hack.

In your: “/test/test_helper.rb” add the following method:


def fixture_path
File.dirname(__FILE__) + "/fixtures/"
end

Ruby on Rails automatic reload of libraries

Currently I’m busy developing a Rails Application. I’m busy developing some general classes that aren’t part of a model/controller or view. I placing these classes in the ‘lib’ directory.
Things are fine … well not quite …

The problem while developing is the libraries aren’t reloaded on each request. This is very frustrating when you are trying to write a library.

Some things I found (but don’t seam to work):

Rest the application in the console. Well the application reset, but not the libraries.

$ ./script.console
Loading development environment...
&gt;&gt; Dispatcher.reset_application!

I assume the libraries directory is loaded in the ruby booting class loader. ( I’m still thinking Java ). So when Webrick starts these libs are loaded.
The models and controllers etc. are loaded by the rails class loader.

Somehow I need to reload the library in the rails class loader space…. Doesn somebody have a solution!?
Perhaps I should find another directory…

I will keep you informed if I find a solutions.

1 august 2007: Well found a solution for the problem, I even wonder if it really was a problem….. (shame on me)
If I place the class “MyOwnClass” in the file “lib/my_own_class.rb” without including the source file. (This isn’t required, because Rails automatically includes it) it seems to be refreshed every time I do a request…

Nice.. !

Agile Web Development with Rails 2nd Edition – Part 2

Wel I’ve almost completely read the book while I was away on a summer holiday. I still like the book. Specially the Web 2.0 part has been improved very much. Also the RESTful routes part is interesting, but I don’t see the direct need for it.

I still need to read the part about deployment, but after a quick peek, I think it’s much completer and more mature then the description in the first book. Also it shifted the usage advice from fastcgi to Capistrano. Well an interesting chapter.

The Ajax part also hinted me about the “readystate 3″ problem, which simply means that the web server should not use keep-alive with ajax. It looks like this is the problem I’ve encountered with a project of mine… Need to figure this out!

Found another Rails calendar popup

I finally found a more friendly date select plugin for rails: http://code.google.com/p/calendardateselect/

I will test it in my project I currently involved in.

Using it seams very easy:

&lt;%= calendar_date_select_tag "e_date" %&gt;;

The only requirement is to include the following in the head of the layout


&lt;%= calendar_date_select_includes %&gt;;

calendardateselect.png