As someone stated, the catch to all this is that as long as it is illegal in the US, an employer can test and fire you.
In many states, they could fire you for it regardless. Marijuana users, like cigarette smokers, aren't a protected class. It's a flimsy argument, but with at-will employment, that's just how it works. If it's not "He was smoking it on the job" it's "the smell was distracting and leading to a terrible work environment." Of course, the real reason might be because they don't like weed and don't like you smoking weed, but they could still get away with firing you for that, too. Even if it 's for a medical condition. It's all a liability issue. Personally, if you work with heavy machinery at all, it's probably safer not to partake, and it saves companies big in the long run. Even if you're the best employee they've ever had, a split second delay could mean you lose your fingers. If they think marijuana use could lead to more such accidents, they're fully within their rights to ban the use thereof.