tute/merit — pull request #206 by bullfight (2014-12-09 21:11:08+00:00)
Title: Allow Rule to find Badge by `:badge_id`

I want to be able to edit Badge name and descriptions in my database, unfortunately by using a finder which relies on badge name I can’t easily modify badges without using a separate locked db column just to support the merit badge string name id. Since IDs in relational databases aren’t modified it makes more sense to write the rules using attributes that aren’t going to be changing. Merit badges have assigned IDs and already have a finder so I just modified the Rule class a little to support an added `:badge_id` attribute.

As it is a single attribute I set the finder to check for it first and use it for finding the badge if it is available, if not the finder falls back to `:find_by_name_and_level`

* Added `:badge_id` attribute to `Rule`
* Modified badge finder method to prefer `:badge_id` over `:badge_name` and `:level`
* Added test for Rule to support modified finder
* Added test for dummy app to support modified finder
* Documented use in badge rule template
* Documented use in README

The new use case would look something like this where `:badge_id` is the preferred finder attribute

```ruby
# If it has 10 comments, grant commenter-10 badge, find badge by badge_id
grant_on 'comments#create', badge_id: 1, badge: 'commenter', level: 10 do |comment|
comment.user.comments.count >= 10
end
```