ref: master
test/unit/tags_block_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
require_relative "../test_helper" class TagsCloudBlockTest < ActiveSupport::TestCase def setup @user = create_user('testinguser').person @user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save! @user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save! @user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save! box = Box.new box.owner = @user box.save! @block = TagsCloudBlock.new @block.box = box @block.save end attr_reader :block should 'describe itself' do assert_not_equal Block.description, TagsCloudBlock.description end should 'provide a default title' do assert_not_equal Block.new.default_title, TagsCloudBlock.new.default_title end include BoxesHelper should 'return the max value in the range between zero and limit' do block = TagsCloudBlock.new assert_equal 12, block.get_limit end should '' do block = TagsCloudBlock.new block.limit = -5 assert_equal 0, block.get_limit end end require 'tags_helper' class TagsCloudBlockViewTest < ActionView::TestCase include BoxesHelper ActionView::Base.send :include, TagsHelper def setup @user = create_user('testinguser').person @user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save! @user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save! @user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save! box = Box.new box.owner = @user box.save! @block = TagsCloudBlock.new @block.box = box @block.save end attr_reader :block should 'return (none) when no tags to display' do ActionView::Base.any_instance.stubs(:block_title).returns("") block.owner.expects(:article_tags).returns([]) assert_equal "\n\n\n", render_block_content(block) end should 'order tags alphabetically' do ActionView::Base.any_instance.stubs(:block_title).returns("") assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ render_block_content(block) end should 'generate links to tags' do ActionView::Base.any_instance.stubs(:block_title).returns("") content = render_block_content(block) assert_match /profile\/testinguser\/tags\/first-tag/, content assert_match /profile\/testinguser\/tags\/second-tag/, content assert_match /profile\/testinguser\/tags\/third-tag/, content end should 'generate links to tags on a environment page' do @otheruser = create_user('othertestinguser').person @otheruser.articles.build(:name => 'article A', :tag_list => 'other-tag').save! @otheruser.articles.build(:name => 'article B', :tag_list => 'other-tag, second-tag').save! box = create(Box, :owner => Environment.default) @block = create(TagsCloudBlock, :box => box) ActionView::Base.any_instance.stubs(:block_title).returns("") content = render_block_content(block) assert_match /3 items[^>]+\/tag\/first-tag/, content assert_match /3 items[^>]+\/tag\/second-tag/, content assert_match /one item[^>]+\/tag\/third-tag/, content assert_match /2 item[^>]+\/tag\/other-tag"/, content end should 'generate links when profile has own hostname' do @user.domains << Domain.new(:name => 'testuser.net'); @user.save! ActionView::Base.any_instance.stubs(:block_title).returns("") assert_match /profile\/testinguser\/tags\/first-tag/, render_block_content(block) end end |