Commit 5f0d0a34bcd3e0d2ee7dc0afa42738d56b4e8dd4
1 parent
6a7965a4
Exists in
master
and in
29 other branches
Do not list regions with validators multiple times
(ActionItem1482)
Showing
2 changed files
with
9 additions
and
4 deletions
Show diff stats
app/models/region.rb
| ... | ... | @@ -16,7 +16,7 @@ class Region < Category |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | 18 | def self.with_validators |
| 19 | - Region.find(:all, :joins => 'INNER JOIN region_validators on (region_validators.region_id = categories.id)') | |
| 19 | + Region.find(:all, :joins => 'INNER JOIN region_validators on (region_validators.region_id = categories.id)', :select => "distinct #{table_name}.*") | |
| 20 | 20 | end |
| 21 | 21 | |
| 22 | 22 | end | ... | ... |
test/unit/region_test.rb
| ... | ... | @@ -55,13 +55,18 @@ class RegionTest < Test::Unit::TestCase |
| 55 | 55 | |
| 56 | 56 | should 'list regions with validators' do |
| 57 | 57 | bahia = fast_create(Region, :name => 'Bahia') |
| 58 | - forum_ecosol_ba = fast_create(Enterprise, :name => 'Forum Baiano de Economia Solidaria', :identifier => 'ecosol-ba') | |
| 59 | - bahia.validators << forum_ecosol_ba | |
| 58 | + bahia.validators << fast_create(Enterprise, :name => 'Forum Baiano de Economia Solidaria', :identifier => 'ecosol-ba') | |
| 60 | 59 | |
| 61 | 60 | sergipe = fast_create(Region, :name => 'Sergipe') |
| 62 | 61 | # Sergipe has no validators |
| 63 | 62 | |
| 64 | - assert_equivalent Region.with_validators, [bahia] | |
| 63 | + assert_equivalent [bahia], Region.with_validators | |
| 64 | + end | |
| 65 | + | |
| 66 | + should 'list each region with validatores only once' do | |
| 67 | + bahia = fast_create(Region, :name => 'Bahia') | |
| 68 | + 2.times { |i| bahia.validators << fast_create(Enterprise, :name => "validator #{i}", :identifier => "validator-#{i}")} | |
| 69 | + assert_equal [bahia], Region.with_validators | |
| 65 | 70 | end |
| 66 | 71 | |
| 67 | 72 | end | ... | ... |