Commit 109fffc3d4d73cd4dd6efeb181045fe987a786a0
1 parent
c51cf308
Exists in
master
and in
22 other branches
[postgres-tests] Fixing category tests
Also removing useless methods sub_category and sub_tree.
Showing
2 changed files
with
7 additions
and
46 deletions
Show diff stats
app/models/category.rb
... | ... | @@ -22,14 +22,6 @@ class Category < ActiveRecord::Base |
22 | 22 | |
23 | 23 | named_scope :on_level, lambda { |parent| {:conditions => {:parent_id => parent}} } |
24 | 24 | |
25 | - named_scope :sub_categories, lambda { |category| | |
26 | - {:conditions => ['categories.path LIKE ? AND categories.id != ?', "%#{category.slug}%", category.id]} | |
27 | - } | |
28 | - | |
29 | - named_scope :sub_tree, lambda { |category| | |
30 | - {:conditions => ['categories.path LIKE ?', "%#{category.slug}%"]} | |
31 | - } | |
32 | - | |
33 | 25 | acts_as_filesystem |
34 | 26 | |
35 | 27 | has_many :article_categorizations | ... | ... |
test/unit/category_test.rb
... | ... | @@ -490,10 +490,13 @@ class CategoryTest < ActiveSupport::TestCase |
490 | 490 | should 'paginate upcoming events' do |
491 | 491 | category = Category.create!(:name => 'category1', :environment_id => Environment.default.id) |
492 | 492 | profile = fast_create(Profile) |
493 | - event1 = category.events.build(:name => 'event1', :start_date => Time.now, :profile => profile) | |
494 | - event2 = category.events.build(:name => 'event2', :start_date => Time.now + 1.hour, :profile => profile) | |
495 | - event3 = category.events.build(:name => 'event3', :start_date => Time.now + 1.day, :profile => profile) | |
496 | - category.save! | |
493 | + event1 = Event.create!(:name => 'event1', :profile => profile, :start_date => Time.now) | |
494 | + event2 = Event.create!(:name => 'event2', :profile => profile, :start_date => Time.now + 1.hour) | |
495 | + event3 = Event.create!(:name => 'event3', :profile => profile, :start_date => Time.now + 1.day) | |
496 | + ArticleCategorization.add_category_to_article(category, event1) | |
497 | + ArticleCategorization.add_category_to_article(category, event2) | |
498 | + ArticleCategorization.add_category_to_article(category, event3) | |
499 | + | |
497 | 500 | assert_equal [event1, event2], category.upcoming_events(2) |
498 | 501 | end |
499 | 502 | |
... | ... | @@ -537,38 +540,4 @@ class CategoryTest < ActiveSupport::TestCase |
537 | 540 | assert_includes Category.on_level(parent.id), category |
538 | 541 | end |
539 | 542 | |
540 | - should 'list category sub-categories' do | |
541 | - c1 = Category.create!(:name => 'Category 1', :environment => Environment.default) | |
542 | - c2 = Category.create!(:name => 'Category 2', :environment => Environment.default) | |
543 | - c3 = Category.create!(:name => 'Category 3', :environment => Environment.default, :parent_id => c1) | |
544 | - c4 = Category.create!(:name => 'Category 4', :environment => Environment.default, :parent_id => c1) | |
545 | - c5 = Category.create!(:name => 'Category 5', :environment => Environment.default, :parent_id => c3) | |
546 | - | |
547 | - sub_categories = Category.sub_categories(c1) | |
548 | - | |
549 | - assert ActiveRecord::NamedScope::Scope, sub_categories.class | |
550 | - assert_not_includes sub_categories, c1 | |
551 | - assert_not_includes sub_categories, c2 | |
552 | - assert_includes sub_categories, c3 | |
553 | - assert_includes sub_categories, c4 | |
554 | - assert_includes sub_categories, c5 | |
555 | - end | |
556 | - | |
557 | - should 'list category sub-tree' do | |
558 | - c1 = Category.create!(:name => 'Category 1', :environment => Environment.default) | |
559 | - c2 = Category.create!(:name => 'Category 2', :environment => Environment.default) | |
560 | - c3 = Category.create!(:name => 'Category 3', :environment => Environment.default, :parent_id => c1) | |
561 | - c4 = Category.create!(:name => 'Category 4', :environment => Environment.default, :parent_id => c1) | |
562 | - c5 = Category.create!(:name => 'Category 5', :environment => Environment.default, :parent_id => c3) | |
563 | - | |
564 | - sub_tree = Category.sub_tree(c1) | |
565 | - | |
566 | - assert ActiveRecord::NamedScope::Scope, sub_tree.class | |
567 | - assert_includes sub_tree, c1 | |
568 | - assert_not_includes sub_tree, c2 | |
569 | - assert_includes sub_tree, c3 | |
570 | - assert_includes sub_tree, c4 | |
571 | - assert_includes sub_tree, c5 | |
572 | - end | |
573 | - | |
574 | 543 | end | ... | ... |