I had a situation like that at my old job. I had been nursing for 3 years, completed my CMSRN, actively involved as a mentor/preceptor to new graduate/hires, always the superuser for new equipment/programs, and was interested in the educators position on the unit.
The educator was leaving to move across the country. I had a good relationship with my unit manager (or so I thought), and I let her know that I would like to apply for the position. She told me that theoretically she could not just give me the position, even though she thought I was perfect for it, but that she had to post it for a week and make sure others had an opportunity apply as well. It made total sense, so I waited. She told me to make time with the current educator to learn the ropes, which I did, and everything seemed fine.
Another nurse and I interviewed for the position. She was not involved at all with education, except as a preceptor, but she had 6 years of experience. We both interviewed very well, but they gave her the job. On one hand I understand, that she had more experience as a MS nurse, but on the other, I had much more experience in education and the way the job would work as an educator. Not to mention the effort I had put forth to get training from the current educator. I was pretty angry afterwards.
It did not help to know that they were friends.