Commit acf45dc90a81e3da6a7e6cbf244ccdcab2bc88d9

Authored by AntonioTerceiro
1 parent 2bc9351d

ActionItem102: adding relationship with regions to environment


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@661 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/environment.rb
... ... @@ -25,6 +25,8 @@ class Environment < ActiveRecord::Base
25 25 has_many :categories
26 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 30 has_many :role_assignments, :as => 'resource'
29 31 def superior_intances
30 32 [self, nil]
... ...
test/unit/environment_test.rb
... ... @@ -121,6 +121,17 @@ class EnvironmentTest < Test::Unit::TestCase
121 121 assert !env.display_categories.include?(cat2)
122 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 135 should 'have a contact email' do
125 136 env = Environment.new
126 137 assert_nil env.contact_email
... ...