In a class called 'Quality' I have the following constants defined:
class Quality < ActiveRecord::Base
[validations excluded in this example]
NEW = Quality.find_by_name("New")
LGT = Quality.find_by_name("Light use")
MED = Quality.find_by_name("Medium use")
HVY = Quality.find_by_name("Heavy use")
SCR = Quality.find_by_name("Scrap")
ANY = Quality.find_by_name("Any")
end
When running my unit tests, these constants are all nil. Why? I'm sure they're not nil during production/development since the code that uses these seems to work in my dev/prod environments.
I've setup fixtures for these records, so I expect the constant initialization to work. My fixture for qualities appears below. These fixtures are in a file at 'test/fixtures/qualities.yml'
any:
value: 0
name: Any
extended_name: /all
new:
value: 5
name: New
extended_name: (or like new)
lgt:
value: 4
name: Light use
extended_name: (cosmetic damange only)
med:
value: 3
name: Medium use
extended_name: (some functional damange)
hvy:
value: 2
name: Heavy use
extended_name: (needs work)
scr:
value: 1
name: Scrap
extended_name: (only good for parts)
Finally, here's my unit test, which fails with 'Expected not nil'
test "all constant qualities are not nil" do
assert_not_nil Quality::ANY
assert_not_nil Quality::NEW
assert_not_nil Quality::LGT
assert_not_nil Quality::MED
assert_not_nil Quality::HVY
assert_not_nil Quality::SCR
end