Commit 7ebe26c3c57aa71d9200c5785d64f737f8b2c2bc
1 parent
f185c568
Exists in
master
and in
29 other branches
ActionItem70: adding categories to environment
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@523 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
17 additions
and
0 deletions
Show diff stats
app/models/environment.rb
@@ -129,4 +129,9 @@ class Environment < ActiveRecord::Base | @@ -129,4 +129,9 @@ class Environment < ActiveRecord::Base | ||
129 | self.find(:first, :conditions => [ 'is_default = ?', true ] ) | 129 | self.find(:first, :conditions => [ 'is_default = ?', true ] ) |
130 | end | 130 | end |
131 | 131 | ||
132 | + # returns an array with the top level categories for this environment. | ||
133 | + def top_level_categories | ||
134 | + Category.top_level_for(self) | ||
135 | + end | ||
136 | + | ||
132 | end | 137 | end |
test/unit/environment_test.rb
@@ -97,4 +97,16 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -97,4 +97,16 @@ class EnvironmentTest < Test::Unit::TestCase | ||
97 | assert_equal 'bli', v.flexible_template_icon_theme | 97 | assert_equal 'bli', v.flexible_template_icon_theme |
98 | end | 98 | end |
99 | 99 | ||
100 | + def test_should_list_top_level_categories | ||
101 | + env = Environment.create!(:name => 'a test environment') | ||
102 | + cat1 = Category.create!(:name => 'first category', :environment_id => env.id) | ||
103 | + cat2 = Category.create!(:name => 'second category', :environment_id => env.id) | ||
104 | + | ||
105 | + cats = env.top_level_categories | ||
106 | + assert_equal 2, cats.size | ||
107 | + assert cats.include?(cat1) | ||
108 | + assert cats.include?(cat2) | ||
109 | + | ||
110 | + end | ||
111 | + | ||
100 | end | 112 | end |