This is my Action model:
class Action < ActiveRecord::Base end class Fold < Action end class Check < Action end class Call < Action end class Bet < Action end
In another model, I have this
class Deal < ActiveRecord::Base def Deal.parse_action(action_string) case action_string when 'folds': Fold.new() when 'checks': Check.new() when 'calls': Call.new() when 'bets': Bet.new() when 'raises': Bet.new() else nil end end # ... end
Now, when I test this if this works in my unit tests, everything appears to work. But as soon as I start the web server in development mode, I get this:
NameError (uninitialized constant Deal::Fold): app/models/deal.rb:115:in `parse_action' ...
Why does it think Fold exists within the namespace Deal? And why does this not happen in the test environment?
I don’t use Rails at work, but I sometimes come across the scenario of a class being known when I’m running tests, but not when I’m running the executable. That happens because I have the requisite ‘require’ statements in my test files for the relevant files, but I hadn’t got around to putting the requisite ‘require’ statements in production code.