I went to replace a ceiling fan on a cathedral ceiling in my house yesterday, and upon removing the old fan I noticed that there is no electrical box where the fan was mounted. The fan was hung from a ceiling joist with romex running to the location, and the wiring was done underneath the fan's mounting bracket and canopy cover. It looks like the replacement fan would be wired in the same area, so does it matter if there's no electrical box under the drywall? If so, why?
Electrical boxes serve several functions. They protect wiring where insulation has been removed. They prevent inadvertent contact with exposed components. They contain sparks when the worst occurs. And they provide standard mounting points for fixtures.
I'd be inclined to "code things up" with a wraparound box like so:
Nonmetallic ceiling joist box for ceiling fans. 4'' diameter x 2 1/8'' deep, 12.0 cu. in. 4 clamps, 2 1/2'' knockouts. Maximum fixture weight is 150 lb., maximum fan weight is 70 lb. Exceeds National Electrical code requirements. Recommended for earthquake areas.
As far as code goes, the wiring must be done in a box and that box must be rated to support the weight of the fan. It's not code compliant if it were to be inspected.
But on to what this means to you, since most likely an inspector wouldn't check it.. You could say that the joist will support the fan and that the wires are secured, but if any were to come loose it could cause a fire since there isn't a box to protect it. That's about it.
I have this exact thing done under one of my ceiling fans in my new house and it seems to be a common issue. I've not gotten around to fixing it and it most likely won't ever cause a fire, but it would still be safer to pay a couple dollars and prevent it in any case.