water/mainline — Issue #82: When-factoryn 'går in i väggen' efter 200 anrop
Author: oleander
Created: 2012-03-06 22:07:54+00:00
State: open
Labels: Bug, Test

`When`-factoryn fallerar efter 200 anrop då `When#year` överstigit `2100`.

``` ruby
Factory.define(:when) do |c|
c.sequence(:year){ |n| 1900 + n }
c.sequence(:study_period)
end
```

``` ruby
class When < ActiveRecord::Base
validate :year_span
# ...
private
def year_span
unless year.to_i.between?(1900, 2100)
errors[:year] << "must be between 1900 and 2100"
end
end
# ...
end
```

``` ruby
201.times { Factory.create(:when) }
# => "Validation failed: Year must be between 1950 and 2050"
```

`When`-modellen borde nollställas efter varje test/each-block.
Följande kod, som finns i `spec/spec_helper.rb`, **bör** nollställa modellen, men icke.

``` ruby
config.before(:suite) { DatabaseCleaner.strategy = :truncation }
config.before(:each) { DatabaseCleaner.start }
config.after(:each) { DatabaseCleaner.clean }
```