I will not let a student test unless s/he is capable of passing - but not everyone who is capable of passing is able to perform appropriately under pressure. I have had a couple of students fail - one who lost it under the pressure of the testing - (she was testing for her I Dan, and went to pieces; she stuck with it and passed at another testing 9 months later - I am quite proud of her for retesting instead of dropping out, which is what most students would do, especially considering she was 17 at the time of the first testing. She still attends class as regularly as her college schedule will allow her - mostly on weekends and during school vacations.
The other was a different case entirely; he was 12 years old and wanted to drop out, but his parents wouldn't let him. He was very capable, and would do a good job if pushed, but totally unmotivated unless performance was part of a contest - and he apparently did not consider testing a contest worth his effort. He tested for 2nd gup red belt and failed miserably - he made significant mistakes (like adding or leaving out movements) in 5 of his 7 patterns (all patterns, for all ranks, are performed at testing), wandered through his sparring and step sparring, and barely touched the boards he was supposed to break. There were other issues with the family as well (like tendency to not pay dues and to drop the student's younger brother off because he "wants to try class again to see if he's ready" - translation: we need a babysitter while we go shopping for presents). After I returned the student's testing form to him, his father asked to speak to me about his son could possibly fail - I went through the form and comments with him point by point - then I told him it was up to him and his son if the boy came to class, but that if he did come, dues were due that day; I never saw him again.
I have only demoted a student once, and it was a special case. I have a couple of students who have cognitive delays (IQs below 70), and one came to my class with a green belt (6th gup) from a McDojo and no memory of anything he had learned there - if, indeed, he HAD learned anything there. In addition to the cognitive delay, he also has cerebral palsy, and I suspect that the McDojo in question had no clue what they were getting into in accepting him as a student; he's the only person I am aware of who has ever been refused when his parents tried to renew his contract. After 4 years in my class, his knowledge was up to that of a yellow belt (8th gup) but his behavior was poor - emotionally and cognitively, he's about 6 or 7, and his promotions are dependent primarily on performing his patterns closely enough to be recognizable, as he is physically and otherwise unable to perform at any reasonable standard, but he enjoys class and works hard most of the time. However, he has a problem with social skills, and I had tried everything I could think of to get his behavior in line with class standards - especially to get him to stop trying to have conversations with the students around him during class, especially during class exercises. I was out of town for a week and left my senior student to teach the class, and his behavior for her was horrific - to give my senior student credit, I didn't hear about it from her, as she thought it was her fault for being unable to control it; I heard about it from a parent who was watching her child in class. He was demoted for failing to maintain class behavior standards simply because I was not there - and it's been quite effective; I took his green belt and gave him a yellow belt (more in keeping with his actual abilities, and leaving room to demote him again if need be). This was an unusual and isolated incident, and I have never demoted anyone else. It was extremely difficult for me, and I sincerly hope I am never faced with such a situation again.
There are isolated cases in which a student makes a greivous error and must be disciplined, but the error is not so greivous as to show the student the door - generally when there are extenuating circumstances, as in the case I described. I know of another incident in which a pair of students, who never really liked each other, got into a fight (and I do mean fight, not sparring match - it was quite spectacular). One of them left the dojang without asking for permission rather than risk the fight restarting. They were both 1st gup high red belts. While neither of them lost their belts, they were limited to lower rank (blue and down) techniques and patterns for 6 months, and were not allowed to test (despite readiness) for over a year, when they were supposed to have tested the next month - the year was to give them time to demonstrate the type of control over themselves and their emotional outbursts that is necessary for a black belt, which they eventually did, and eventually tested successfully.