Commit bd8b5b89c70255aa51e31e0fb9e8adf1c64184c9
1 parent
89c73f89
Exists in
master
and in
29 other branches
ActionItem70: relationship to displayable categories
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@538 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
14 additions
and
0 deletions
Show diff stats
app/models/environment.rb
@@ -23,6 +23,7 @@ class Environment < ActiveRecord::Base | @@ -23,6 +23,7 @@ class Environment < ActiveRecord::Base | ||
23 | has_many :profiles | 23 | has_many :profiles |
24 | 24 | ||
25 | has_many :categories | 25 | has_many :categories |
26 | + has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null ', :order => 'display_color' | ||
26 | 27 | ||
27 | # ################################################# | 28 | # ################################################# |
28 | # Attributes | 29 | # Attributes |
test/unit/environment_test.rb
@@ -123,4 +123,17 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -123,4 +123,17 @@ class EnvironmentTest < Test::Unit::TestCase | ||
123 | assert cats.include?(subcat) | 123 | assert cats.include?(subcat) |
124 | end | 124 | end |
125 | 125 | ||
126 | + should 'list displayable categories' do | ||
127 | + env = Environment.create!(:name => 'a test environment') | ||
128 | + cat1 = env.categories.create(:name => 'category one', :display_color => 1) | ||
129 | + assert ! cat1.new_record? | ||
130 | + | ||
131 | + cat2 = env.categories.create(:name => 'category two') | ||
132 | + assert !cat2.new_record? | ||
133 | + | ||
134 | + assert_equal 1, env.display_categories.size | ||
135 | + assert env.display_categories.include?(cat1) | ||
136 | + assert !env.display_categories.include?(cat2) | ||
137 | + end | ||
138 | + | ||
126 | end | 139 | end |