Sha256: ece1a5ca5b95a76141d7260990c2451b722b9bbb237c8d1da9ec2929ef42067e

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

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|
      content.should be_an(Article)
      content.section.should be_a(Page)
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
adva-0.3.2 test/unit/models/nested_categories_test.rb
adva-0.3.1 test/unit/models/nested_categories_test.rb
adva-0.3.0 test/unit/models/nested_categories_test.rb
adva-0.2.4 test/unit/models/nested_categories_test.rb
adva-0.2.3 test/unit/models/nested_categories_test.rb
adva-0.2.2 test/unit/models/nested_categories_test.rb
adva-0.2.1 test/unit/models/nested_categories_test.rb
adva-0.2.0 test/unit/models/nested_categories_test.rb
adva-0.1.4 test/unit/models/nested_categories_test.rb
adva-0.1.3 test/unit/models/nested_categories_test.rb
adva-0.1.2 test/unit/models/nested_categories_test.rb
adva-0.1.1 test/unit/models/nested_categories_test.rb
adva-0.1.0 test/unit/models/nested_categories_test.rb
adva_cms-0.0.1 test/unit/models/nested_categories_test.rb
adva-0.0.1 adva_cms/test/unit/models/nested_categories_test.rb