Some observations:
magicNumber=3should be defined as a class constant with a proper name such asCERTIFIED_HOST_TRESHOLD, this way we can also skip the comment since the variable name is self-explanatory.- the
Inquiry.findcall and the if conditional expression should not be in theUserclass at all. It makes more sense to have a method within theInquiryclass that returns whther or not a host has the required number of inquiries. - Everytime we save, the
before_save create_new_passwordcallback is triggered and changes the user's password to a new password. I doubt this is intended behaviour. Do you meanbefore_create? I'm going to assume this example ignores resetting password use cases. If we only allow thepasswordattribute to be set once on account creation, we could useread_attribute :passwordto prevent future tampering of thepasswordattribute. - The raw SQL query is hard to read. Alternatively, we could do
host.inquries.where(:status => [:status_1, :status_2])) - Usin
