Commit 0c0b98b1d9001c40adc3b939bebe25348f14e26d
1 parent
d35abd31
Exists in
master
and in
29 other branches
rails3: fix unit tests for the Unit class
Showing
2 changed files
with
14 additions
and
6 deletions
Show diff stats
app/models/unit.rb
test/unit/unit_test.rb
| ... | ... | @@ -4,24 +4,30 @@ class UnitTest < ActiveSupport::TestCase |
| 4 | 4 | |
| 5 | 5 | should 'require singular name' do |
| 6 | 6 | unit = Unit.new; unit.valid? |
| 7 | - assert_match /can't be blank/, unit.errors["singular"] | |
| 7 | + assert_match /can't be blank/, unit.errors["singular"].first | |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | 10 | should 'require plural name' do |
| 11 | 11 | unit = Unit.new; unit.valid? |
| 12 | - assert_match /can't be blank/, unit.errors["plural"] | |
| 12 | + assert_match /can't be blank/, unit.errors["plural"].first | |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | should 'belongs and require an environment' do |
| 16 | 16 | unit = Unit.new; unit.valid? |
| 17 | - assert_match /can't be blank/, unit.errors["environment_id"] | |
| 17 | + assert_match /can't be blank/, unit.errors["environment_id"].first | |
| 18 | 18 | unit.environment = Environment.default; unit.valid? |
| 19 | - assert_nil unit.errors["environment_id"] | |
| 19 | + assert_nil unit.errors["environment_id"].first | |
| 20 | 20 | end |
| 21 | 21 | |
| 22 | 22 | should 'increment position automatically' do |
| 23 | - first = Unit.create!(:singular => 'Litre', :plural => 'Litres', :environment => Environment.default) | |
| 24 | - second = Unit.create!(:singular => 'Meter', :plural => 'Meters', :environment => Environment.default) | |
| 23 | + first = Unit.new(:singular => 'Litre', :plural => 'Litres').tap do |u| | |
| 24 | + u.environment = Environment.default | |
| 25 | + u.save! | |
| 26 | + end | |
| 27 | + second = Unit.new(:singular => 'Meter', :plural => 'Meters').tap do |u| | |
| 28 | + u.environment = Environment.default | |
| 29 | + u.save! | |
| 30 | + end | |
| 25 | 31 | assert_equal 1, first.position |
| 26 | 32 | assert_equal 2, second.position |
| 27 | 33 | end | ... | ... |