Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
parent category shows contents of its child categories - same with sets
- Loading branch information
Showing
6 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
engines/adva_cms/test/unit/models/nested_categories_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper') | ||
|
||
class NestedCategoriesTest < ActiveSupport::TestCase | ||
def setup | ||
super | ||
@page = Page.first | ||
@category = Category.create!(:title => 'fi', :section => @page) | ||
@child_category = Category.create!(:title => 'joensuu', :section => @page) | ||
@child_category.move_to_child_of(@category) | ||
|
||
@article_1 = @page.articles.build(:title => 'finland', :body => 'polar bears & penguins', :author => User.first).save! | ||
@article_2 = @page.articles.build(:title => 'joensuu', :body => 'north karelian capital', :author => User.first).save! | ||
@article_1 = Article.find_by_title('finland') | ||
@article_2 = Article.find_by_title('joensuu') | ||
|
||
@article_1.categories << @category | ||
@article_2.categories << @child_category | ||
end | ||
|
||
test 'all_contents returns a scope of all the contents of category and its descendants' do | ||
assert_equal [@article_1, @article_2], @category.all_contents | ||
assert_equal [@article_2], @child_category.all_contents | ||
end | ||
|
||
test 'all_contents returns categories of a certain section only' do | ||
# There is a 'a category' named category for a blog, a page and for a wiki, | ||
# we do not want it to return wiki or blog category contents | ||
category = Category.find_by_title('a category') | ||
category.all_contents.each do |content| | ||
assert content.is_a?(Article) | ||
assert content.section.is_a?(Page) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper') | ||
|
||
class NestedSetsTest < ActiveSupport::TestCase | ||
def setup | ||
super | ||
@set = Category.find_by_title('Summer') | ||
@sub_set = Category.find_by_title('A Subset') | ||
@sub_set_photo = Photo.create!(:title => 'a subset photo', | ||
:data_content_type => 'image/jpeg', | ||
:data_file_name => 'test.png', | ||
:author => User.first, | ||
:section => @sub_set.section, | ||
:published_at => Time.parse('2008-01-01 12:00:00') ) | ||
|
||
@sub_set_photo.sets << @sub_set | ||
@photos = @set.photos << @sub_set_photo | ||
end | ||
|
||
test 'all_contents returns a scope of all the photos of set and its descendants' do | ||
assert_equal @photos, @set.all_contents | ||
assert_equal [@sub_set_photo], @sub_set.all_contents | ||
end | ||
end |