Added test cases and a fix for rails/rails#10865.

Assuming Topic has_many Replies and Reply belongs_to Topic, the counter cache
was incremented twice if reply is saved after reassignment, as follows:

    reply.topic = topic  # triggers BelongsToAssocation#replace
    reply.save           # triggers belongs_to_counter_cache_after_update

This commit adds a flag to the reply if it has already triggered an increment,
but has not been saved yet. Thus, when the reply is actually saved, the
superfluous increment does not occur.