ref: master
test/unit/forum_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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
require_relative "../test_helper" class ForumTest < ActiveSupport::TestCase should 'be an article' do assert_kind_of Article, Forum.new end should 'provide proper description' do assert_kind_of String, Forum.description end should 'provide own icon name' do assert_not_equal Article.icon_name, Forum.icon_name end should 'provide forum as icon name' do assert_equal 'forum', Forum.icon_name end should 'identify as folder' do assert Forum.new.folder?, 'forum must identity itself as folder' end should 'identify as forum' do assert Forum.new.forum?, 'forum must identity itself as forum' end should 'create rss feed automatically' do p = create_user('testuser').person b = create(Forum, :profile_id => p.id, :name => 'forum_feed_test', :body => 'Forum') assert_kind_of RssFeed, b.feed end should 'save feed options' do p = create_user('testuser').person p.articles << forum = build(Forum, :profile => p, :name => 'forum_feed_test', :body => 'Forum test') p.forum.feed = { :limit => 7 } assert_equal 7, Forum.find(forum.id).feed.limit end should 'save feed options after create forum' do p = create_user('testuser').person p.articles << forum = build(Forum, :profile => p, :name => 'forum_feed_test', :body => 'Forum test', :feed => { :limit => 7 }) assert_equal 7, Forum.find(forum.id).feed.limit end should 'list 5 posts per page by default' do forum = Forum.new assert_equal 5, forum.posts_per_page end should 'update posts per page setting' do p = create_user('testuser').person p.articles << forum = build(Forum, :profile => p, :name => 'Forum test', :body => 'Forum test') forum.posts_per_page = 7 assert forum.save! assert_equal 7, Forum.find(forum.id).posts_per_page end should 'has posts' do p = create_user('testuser').person p.articles << forum = build(Forum, :profile => p, :name => 'Forum test', :body => 'Forum test') post = fast_create(TextArticle, :name => 'First post', :profile_id => p.id, :parent_id => forum.id) forum.children << post assert_includes forum.posts, post end should 'not includes rss feed in posts' do p = create_user('testuser').person forum = create(Forum, :profile_id => p.id, :name => 'Forum test', :body => 'Forum') assert_includes forum.children, forum.feed assert_not_includes forum.posts, forum.feed end should 'list posts ordered by updated at' do p = create_user('testuser').person forum = fast_create(Forum, :profile_id => p.id, :name => 'Forum test') newer = create(TextArticle, :name => 'Post 2', :parent => forum, :profile => p) older = create(TextArticle, :name => 'Post 1', :parent => forum, :profile => p) older.updated_at = Time.now.in_time_zone - 1.month older.stubs(:record_timestamps).returns(false) older.save! assert_equal [newer, older], forum.posts end should 'profile has more then one forum' do p = create_user('testuser').person fast_create(Forum, :name => 'Forum test', :profile_id => p.id) assert_nothing_raised ActiveRecord::RecordInvalid do create(Forum, :name => 'Another Forum', :profile => p, :body => 'Forum test') end end should 'not update slug from name for existing forum' do p = create_user('testuser').person forum = create(Forum, :name => 'Forum test', :profile_id => p.id, :body => 'Forum') new_name = 'Changed name' assert_not_equal new_name.to_slug, forum.slug forum.name = new_name assert_not_equal new_name.to_slug, forum.slug end should 'have posts' do assert Forum.new.has_posts? end should 'not accept uploads' do folder = fast_create(Forum) refute folder.accept_uploads? end should 'be notifiable' do assert Forum.new.notifiable? end should 'get first paragraph' do f = fast_create(Forum, :body => '<p>First</p><p>Second</p>') assert_equal '<p>First</p>', f.first_paragraph end should 'not get first paragraph' do f = fast_create(Forum, :body => 'Nothing to do here') assert_equal '', f.first_paragraph end should 'provide first_paragraph even if body was not given' do f = fast_create(Forum) assert_equal '', f.first_paragraph end should 'provide first_paragraph even if body is nil' do f = fast_create(Forum, :body => nil) assert_equal '', f.first_paragraph end should 'include user that changes a forum as agreed with terms' do author = fast_create(Person) editor = fast_create(Person) forum = create(Forum, :profile => author, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true, :last_changed_by => author) forum.last_changed_by = editor forum.save assert_equivalent [author, editor], forum.users_with_agreement end should 'not crash if forum has terms and last_changed does not exist' do profile = fast_create(Person) forum = Forum.create(:profile => profile, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true) assert_equal [], forum.users_with_agreement end should 'agree with terms if forum doesn\'t have terms' do person = fast_create(Person) forum = fast_create(Forum) assert_equal true, forum.agrees_with_terms?(person) end should 'not agree with terms if user is logged in but did not accept it' do person = fast_create(Person) forum = Forum.create(:profile => person, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true) assert_equal false, forum.agrees_with_terms?(person) end should 'agree with terms if user is logged in and accept it' do person = fast_create(Person) forum = Forum.create(:profile => person, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true) forum.users_with_agreement << person forum.save assert_equal true, Forum.find(forum.id).agrees_with_terms?(person) end end |