seejohnrun/ice_cube — pull request #236 by ajsharp (2014-05-24 17:20:17+00:00)
Title: Coerce validation intervals to int's

I'm running into this problem when passing values through an API, persisting them to the database, reading them out again, and then attempting to update them. I was getting an error for a daily interval that looked like this:

```
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validations/daily_interval.rb:34:in `/'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validations/daily_interval.rb:34:in `div'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validations/daily_interval.rb:34:in `%'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validations/daily_interval.rb:34:in `validate'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validated_rule.rb:138:in `block in validated_results'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validated_rule.rb:137:in `map'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validated_rule.rb:137:in `validated_results'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validated_rule.rb:124:in `validation_accepts_or_updates_time?'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validated_rule.rb:112:in `block in finds_acceptable_time?'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validated_rule.rb:111:in `each'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validated_rule.rb:111:in `all?'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validated_rule.rb:111:in `finds_acceptable_time?'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validated_rule.rb:117:in `find_acceptable_time_before'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/validated_rule.rb:43:in `next_time'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:430:in `block (2 levels) in next_time'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:428:in `each'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:428:in `reduce'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:428:in `block in next_time'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:427:in `loop'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:427:in `next_time'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:410:in `block (2 levels) in enumerate_occurrences'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:409:in `loop'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:409:in `block in enumerate_occurrences'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:171:in `each'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:171:in `each'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:171:in `take'
/Users/ajsharp/.rvm/gems/ruby-2.1.1/gems/ice_cube-0.12.0/lib/ice_cube/schedule.rb:171:in `next_occurrences'
```

Basically, the `validate` method is trying to divide by a string value of `"2"` when it should be an int.

One could argue that I need to handle serialization/deserialization better up the chain and pass the correct type to ice_cube, but this worked, and took about 10 seconds :)