Will Read's blog
Interesting Things
- "... not missing constant" ERROR To reproduce this error you do something like this:
Generate a rails app, call it "test".
Create a module scoped model called Post in app/models/mumble/post.rb
class Mumble::Comment < ActiveRecord::Base
belongs_to :post
end
Create a module scoped model called Comment in app/models/mumble/comment.rb
class Mumble::Comment < ActiveRecord::Base
belongs_to :post
end
Then at the command line
$ script/console
Loading development environment (Rails 2.3.3)
comment = Mumble::Comment.first
=> #
comment.post
=> #
exit
$ script/console
Loading development environment (Rails 2.3.3)
post = Mumble::Post.new
=> #
exit
$ script/console
Loading development environment (Rails 2.3.3)
post = Mumble::Post.create!
=> #
comment = post.comments.create!
=> #
comment.post
ArgumentError: Mumble is not missing constant Post!
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:417:inload_missing_constant' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:80:inconst_missing'
Apparently, there are various situations that can cause the infamous "Mumble is not missing constant Post!" error. In this case it appears the associations do not understand the module scoping, despite the statement:
By default, associations will look for objects within the current module scope.
at http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
The solution was to explicitly declare the class name in the association:
class Mumble::Post < ActiveRecord::Base
has_many :comments, :class_name => "Mumble::Comment"
end
and
class Mumble::Comment < ActiveRecord::Base
belongs_to :post, :class_name => "Mumble::Post"
end
Then to show the error is no longer present
$ script/console
Loading development environment (Rails 2.3.3)
post = Mumble::Post.create!
=> #
comment = post.comments.create!
=> #
comment.post
=> #
- "Rake Set Theory" when running the same thing in rake multiple times, Rake strips out the extra commands. For example: $rake db:rollback db:rollback which you might expect to preform two rollbacks, only does one rollback. This can be frustrating if you're trying to couple rollbacks with a db:test:prepare or some other logical chain of events. At the command line you can of course work around most situations by && together multiple rake commands.
This is Part 2 of my two part series on working with queues in Ruby. If you want some context please head over to part 1. In this post I'll touch on Moqueue, using RSpec to stub out Bunny, and a few other hurdles along the way.
Q: How do you catch a unique rabbit?
A: Unique (you-neek) up on it!
Q: How do you catch a tame rabbit?
A: Tame way!!!!!
We've been using RabbitMQ as a queue server, alongside the clients, Bunny, and AMQP. In this series I'm hoping (hopping?) to show you some of the pitfalls we've learned to avoid and talk about how to write tests that test your code without getting stuck running a queue server in your test environment.
In Part 1 I'll focus on our situation and creating some context around our choices so that you can decide what makes sense for your project. In Part 2, I'll get into the nitty gritty of how to write some tests/specs around your queues.
