Commit acf45dc90a81e3da6a7e6cbf244ccdcab2bc88d9
1 parent
2bc9351d
Exists in
staging
and in
42 other branches
ActionItem102: adding relationship with regions to environment
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@661 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
13 additions
and
0 deletions
Show diff stats
app/models/environment.rb
@@ -25,6 +25,8 @@ class Environment < ActiveRecord::Base | @@ -25,6 +25,8 @@ class Environment < ActiveRecord::Base | ||
25 | has_many :categories | 25 | has_many :categories |
26 | has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color' | 26 | has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color' |
27 | 27 | ||
28 | + has_many :regions | ||
29 | + | ||
28 | has_many :role_assignments, :as => 'resource' | 30 | has_many :role_assignments, :as => 'resource' |
29 | def superior_intances | 31 | def superior_intances |
30 | [self, nil] | 32 | [self, nil] |
test/unit/environment_test.rb
@@ -121,6 +121,17 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -121,6 +121,17 @@ class EnvironmentTest < Test::Unit::TestCase | ||
121 | assert !env.display_categories.include?(cat2) | 121 | assert !env.display_categories.include?(cat2) |
122 | end | 122 | end |
123 | 123 | ||
124 | + should 'have regions' do | ||
125 | + env = Environment.create!(:name => 'a test environment') | ||
126 | + assert_kind_of Array, env.regions | ||
127 | + assert_raise ActiveRecord::AssociationTypeMismatch do | ||
128 | + env.regions << 1 | ||
129 | + end | ||
130 | + assert_nothing_raised do | ||
131 | + env.regions << Region.new | ||
132 | + end | ||
133 | + end | ||
134 | + | ||
124 | should 'have a contact email' do | 135 | should 'have a contact email' do |
125 | env = Environment.new | 136 | env = Environment.new |
126 | assert_nil env.contact_email | 137 | assert_nil env.contact_email |