• Timothy Andrew's avatar
    Fix a bug with the User#abuse_report association. · 6a065074
    Timothy Andrew authored
    Introduction
    ------------
    
    1. The foreign key was not explicitly specified on the association.
    2. The `AbuseReport` model contains two references to user - `reporter_id` and
       `user_id`
    3. `user.abuse_report` is supposed to return the single abuse report where
       `user_id` refers to the given user.
    
    Bug Description
    ---------------
    
    1. `user.abuse_report` would return an abuse report where `reporter_id` referred
       to the current user, if such an abuse report was present.
    
    2. This implies a slightly more serious bug as well:
    
       - Assume User A filed an abuse report against User B
       - We have an abuse report where `reporter_id` is User A and `user_id` is User B
       - If User A is updated (`user_a.block`, for example), the abuse report would
         also be updated, such that both `reporter_id` _and_ `user_id` point to User A.
    
    Fix
    ---
    
    Explicitly declare the foreign key `user_id` in the `has_one` declaration
    6a065074
user_spec.rb 49.4 KB