Commit 2bc9351da94664a6ffda00aab1625cb48f5febb4
1 parent
016bb575
Exists in
master
and in
22 other branches
ActionItem102: adding HABTM between Region and organization
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@660 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
12 additions
and
0 deletions
Show diff stats
app/models/region.rb
| 1 | # Region is a special type of category that is related to geographical issues. | 1 | # Region is a special type of category that is related to geographical issues. |
| 2 | class Region < Category | 2 | class Region < Category |
| 3 | + has_and_belongs_to_many :validators, :class_name => Organization.name, :join_table => :region_validators | ||
| 3 | end | 4 | end |
test/unit/region_test.rb
| @@ -5,4 +5,15 @@ class RegionTest < Test::Unit::TestCase | @@ -5,4 +5,15 @@ class RegionTest < Test::Unit::TestCase | ||
| 5 | should 'be a subclass of category' do | 5 | should 'be a subclass of category' do |
| 6 | assert_equal Category, Region.superclass | 6 | assert_equal Category, Region.superclass |
| 7 | end | 7 | end |
| 8 | + | ||
| 9 | + should 'have an array of validators' do | ||
| 10 | + region = Region.new | ||
| 11 | + assert_raise ActiveRecord::AssociationTypeMismatch do | ||
| 12 | + region.validators = [ 1 ] | ||
| 13 | + end | ||
| 14 | + assert_nothing_raised do | ||
| 15 | + region.validators = [ Organization.new ] | ||
| 16 | + end | ||
| 17 | + end | ||
| 18 | + | ||
| 8 | end | 19 | end |