mbleigh/acts-as-taggable-on — pull request #416 by jonseaberg (2013-09-30 19:02:18+00:00)
Title: Possible fix for issue #409 

I had a similar problem to the one reported in https://github.com/mbleigh/acts-as-taggable-on/issues/409. I think this is a very specific problem limited to the following setup:

- MySQL using utf_unicode_ci or utf_general_ci collation
- A unique index on the names column of the tags table

In my case I had a tag with text "inupiat" and someone was trying to add the tag "Iñupiat". With my setup these strings are considered the same to the database, but compare differently in ruby. My solution was to tie the given text "Iñupiat" to the existing tag with text "inupiat". I did this by creating a table of strings from the given list and joining that to the tags table.

```sql
mysql> SELECT tags.*, names.list_name FROM `tags` INNER JOIN (SELECT 'IÑUPIAT' AS list_name) AS names ON tags.name = names.list_name WHERE (lower(name) = 'iñupiat');
+--------+---------+---------+------+-----------+
| id | name | context | sort | list_name |
+--------+---------+---------+------+-----------+
| 168084 | inupiat | NULL | 0 | IÑUPIAT |
+--------+---------+---------+------+-----------+
1 row in set (0.00 sec)
```

This gives back the original string and the existing tag if one exists. Now we can return the matched tag or create one if needed.

The other two commits are changes I made to get the specs running on my machine. They may be addressed by other work, so I am happy to remove them if needed.