I’m still new leas than 40 hours with rails, and while I’ve been
following
the discussion about testing I’m still further back along the line,
working
my way though AWDwR and trying variations.
One thing I noted is that functions - and I presume variables/accessors
that are defined in app/controllers/application.rb will be available
throughout the application. (Presumably, unless they are over-ridden)
I’m just playing with this but its not doing what I expect.
I’m defining some regular expressions as well as functions that use them
@regex = {
‘upperalpha’ => /[A-Z]/,
‘loweralpha’ => /[a-z]/,
‘numeric’ => /[0-9]/
‘upperalphanumeric’ => /[A-Z0-9]/,
‘loweralphanumeric’ => /[a-z0-9]/,
‘alphanumeric’ => /[A-Za-z0-9]/
}
def isanumber?(string)
/^#{@regex[‘numeric’]}$/o.match(name)
end
So, times comes to test this in a very basic way and I fire up the
console,
iterate through my typographic errors and …
Well, I don’t seem be able to find @regex or isanumber?
I tried adding read_accessor, I tried accessing Application::regex
all to no avail.
I’ve tried putting the regex definition in an initializer.
I know that the console script is reading
app/controllers/application.rb
because it blew up on some of my typos!
It here some special conditions about the console?
I can access the database objects OK.
–
“Opportunity is missed by most people because it is dressed in overalls
and
looks like work.”
– Thomas A. Edison