# encoding: UTF-8 require_relative "../test_helper" class ArticleTest < ActiveSupport::TestCase fixtures :environments def setup ActiveSupport::TestCase::setup @profile = create_user('testing').person end attr_reader :profile should 'have and require an associated profile' do a = Article.new a.valid? assert a.errors[:profile_id.to_s].present? a.profile = profile a.valid? assert !a.errors[:profile_id.to_s].present? end should 'require value for name' do a = Article.new a.valid? assert a.errors[:name.to_s].present? a.name = 'my article' a.valid? assert !a.errors[:name.to_s].present? end should 'limit length of names' do a = build(Article, :name => 'a'*151) a.valid? assert a.errors[:name.to_s].present? a.name = 'a'*150 a.valid? assert !a.errors[:name.to_s].present? end should 'require value for slug and path if name is filled' do a = build(Article, :name => 'test article') a.slug = nil a.path = nil a.valid? assert a.errors[:slug.to_s].present? assert a.errors[:path.to_s].present? end should 'not require value for slug and path if name is blank' do a = Article.new a.valid? assert !a.errors[:slug.to_s].present? assert !a.errors[:path.to_s].present? end should 'act as versioned' do a = create(Article, :name => 'my article', :body => 'my text', :profile_id => profile.id) assert_equal 1, a.versions(true).size a.name = 'some other name' a.save! assert_equal 2, a.versions(true).size end should 'act as taggable' do a = create(Article, :name => 'my article', :profile_id => profile.id) a.tag_list = ['one', 'two'] tags = a.tag_list assert tags.include?('one') assert tags.include?('two') end should 'act as filesystem' do a = create(Article, :profile_id => profile.id) b = create(Article, :profile_id => profile.id, :parent_id => a.id) b.save! assert_equal "#{a.slug}/#{b.slug}", b.path a = Article.find(a.id); a.name = 'another name' a.save! b.reload assert_equal "another-name/#{b.slug}", b.path end should 'provide HTML version' do profile = create_user('testinguser').person a = fast_create(Article, :name => 'my article', :profile_id => profile.id) a.expects(:body).returns('the body of the article') assert_equal 'the body of the article', a.to_html end should 'provide HTML version when body is nil' do a = fast_create(Article, :profile_id => profile.id, :body => nil) assert_equal '', a.to_html end should 'provide short html version' do a = fast_create(Article, :body => 'full body', :abstract => 'lead', :profile_id => profile.id) expects(:display_short_format).with(a).once instance_eval(&a.to_html(:format=>'short')) end should 'provide full html version' do a = fast_create(Article, :body => 'full body', :abstract => 'lead') assert_equal 'full body', a.to_html(:format=>'full body') end should 'provide first paragraph of HTML version' do profile = create_user('testinguser').person a = fast_create(Article, :name => 'my article', :profile_id => profile.id) a.expects(:body).returns('

the first paragraph of the article

The second paragraph

') assert_equal '

the first paragraph of the article

', a.first_paragraph end should 'inform the icon to be used' do assert_equal 'text-html', Article.icon_name end should 'provide a (translatable) description' do result = 'the description' a = Article.new a.expects(:_).returns(result) assert_same result, a.mime_type_description end should 'not accept articles with same slug under the same level' do # top level articles first profile = create_user('testinguser').person a1 = profile.articles.build(:name => 'test') a1.save! # cannot add another top level article with same slug a2 = profile.articles.build(:name => 'test') a2.valid? assert a2.errors[:slug.to_s].present? # now create a child of a1 a3 = profile.articles.build(:name => 'test') a3.parent = a1 a3.valid? assert !a3.errors[:slug.to_s].present? a3.save! # cannot add another child of a1 with same slug a4 = profile.articles.build(:name => 'test') a4.parent = a1 a4.valid? assert a4.errors[:slug.to_s].present? end should 'last_changed_by be a person' do a = profile.articles.build(:name => 'test') # must be a person assert_raise ActiveRecord::AssociationTypeMismatch do a.last_changed_by = Profile.new end assert_nothing_raised do a.last_changed_by = Person.new a.save! end end should 'created_by be a person' do a = profile.articles.build(:name => 'test') # must be a person assert_raise ActiveRecord::AssociationTypeMismatch do a.created_by = Profile.new end assert_nothing_raised do a.created_by = Person.new a.save! end end should 'not show private documents as recent' do p = create_user('usr1').person Article.destroy_all first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) assert_equal [ first ], Article.recent(nil) end should 'not show unpublished documents as recent' do p = create_user('usr1').person Article.destroy_all first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) assert_equal [ first ], Article.recent(nil) end should 'not show documents from a private profile as recent' do p = fast_create(Person, :public_profile => false) Article.destroy_all first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) assert_equal [ ], Article.recent(nil) end should 'not show documents from a invisible profile as recent' do p = fast_create(Person, :visible => false) Article.destroy_all first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) assert_equal [ ], Article.recent(nil) end should 'order recent articles by published_at' do p = create_user('usr1').person Article.destroy_all now = Time.now first = create(Article, :name => 'first', :published => true, :created_at => now, :published_at => now, :profile_id => p.id) second = create(Article, :name => 'second', :published => true, :updated_at => now, :published_at => now + 1.second, :profile_id => p.id) assert_equal [ second, first ], Article.recent(2) Article.record_timestamps = false first.published_at = second.published_at + 1.second first.save! Article.record_timestamps = true assert_equal [ first, second ], Article.recent(2) end should 'not show UploadedFile as recent' do p = create_user('usr1').person Article.destroy_all first = build(UploadedFile, :profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')); first.save! second = fast_create(TextArticle, :profile_id => p.id, :name => 'second') assert_equal [ second ], Article.recent(nil) end should 'not show RssFeed as recent' do p = create_user('usr1').person Article.destroy_all first = fast_create(RssFeed, :profile_id => p.id, :name => 'my feed', :advertise => true) first.limit = 10; first.save! second = p.articles.build(:name => 'second'); second.save! assert_equal [ second ], Article.recent(nil) end should 'not show blog as recent' do p = create_user('usr1').person Article.destroy_all first = fast_create(Blog, :profile_id => p.id, :name => 'my blog', :advertise => true) second = create(Article, :name => 'second', :profile_id => p.id) assert_equal [ second ], Article.recent(nil) end should 'accept extra conditions to find recent' do p = create_user('usr1').person Article.destroy_all a1 = create(Article, :name => 'first', :profile_id => p.id) a2 = create(Article, :name => 'second', :profile_id => p.id) assert_equal [ a1 ], Article.recent(nil, :name => 'first') end should 'require that subclasses define description' do assert_raise NotImplementedError do Article.description end end should 'require that subclasses define short description' do assert_raise NotImplementedError do Article.short_description end end should 'indicate wheter children articles are allowed or not' do assert_equal true, Article.new.allow_children? end should 'provide a url to itself' do article = create(Article, :name => 'myarticle', :profile_id => profile.id) assert_equal(profile.url.merge(:page => ['myarticle']), article.url) end should 'provide a url to itself having a parent topic' do parent = create(Article, :name => 'parent', :profile_id => profile.id) child = create(Article, :name => 'child', :parent => parent, :profile_id => profile.id) assert_equal(profile.url.merge(:page => [ 'parent', 'child']), child.url) end should 'associate with categories' do env = Environment.default parent_cat = create(Category, :name => "parent category", :environment_id => env.id) c1 = create(Category, :name => "test category 1", :parent_id => parent_cat.id, :environment_id => env.id) c2 = create(Category, :name => "test category 2", :environment_id => env.id) article = create(Article, :name => 'withcategories', :profile_id => profile.id) article.save! article.add_category c1 article.add_category c2 assert_equivalent [c1,c2], article.categories(true) assert_equivalent [c1, parent_cat, c2], article.categories_including_virtual(true) end should 'remove comments when removing article' do assert_no_difference 'Comment.count' do a = create(Article, :name => 'test article', :profile_id => profile.id) assert_difference 'Comment.count', 1 do comment = a.comments.build comment.author = profile comment.title = 'test comment' comment.body = 'you suck!' comment.save! end a.destroy end end should 'list most commented articles' do Article.delete_all a1 = create(TextileArticle, :name => "art 1", :profile_id => profile.id) a2 = create(TextileArticle, :name => "art 2", :profile_id => profile.id) a3 = create(TextileArticle, :name => "art 3", :profile_id => profile.id) 2.times { create(Comment, :title => 'test', :body => 'asdsad', :author => profile, :source => a2).save! } 4.times { create(Comment, :title => 'test', :body => 'asdsad', :author => profile, :source => a3).save! } # should respect the order (more commented comes first) assert_equal [a3, a2, a1], profile.articles.most_commented(3) end should 'identify itself as a non-folder' do assert !Article.new.folder?, 'should identify itself as non-folder' end should 'identify itself as a non-blog' do assert !Article.new.blog?, 'should identify itself as non-blog' end should 'always display if public content' do person = create_user('testuser').person assert_equal true, person.home_page.display_to?(nil) end should 'display to owner' do # a person with private contents ... person = create_user('testuser').person person.public_content = false person.save! # ... can see his own articles a = create(Article, :name => 'test article', :profile_id => person.id) assert_equal true, a.display_to?(person) end should 'cache children count' do owner = create_user('testuser').person art = create(Article, :name => 'ytest', :profile_id => owner.id) # two children articles create(Article, :profile => owner, :name => 'c1', :parent_id => art.id) create(Article, :profile => owner, :name => 'c2', :parent_id => art.id) art.reload assert_equal 2, art.children_count assert_equal 2, art.children.size end should 'categorize in the entire category hierarchy' do c1 = create(Category, :environment => Environment.default, :name => 'c1') c2 = create(Category, :environment => Environment.default, :name => 'c2', :parent_id => c1.id) c3 = create(Category, :environment => Environment.default, :name => 'c3', :parent_id => c2.id) owner = create_user('testuser').person art = create(Article, :name => 'ytest', :profile_id => owner.id) art.add_category(c3) assert_equal [c3], art.categories(true) assert_equal [art], c2.articles(true) assert_includes c3.articles(true), art assert_includes c2.articles(true), art assert_includes c1.articles(true), art assert_includes art.categories_including_virtual(true), c2 assert_includes art.categories_including_virtual(true), c1 end should 'redefine the entire category set at once' do c1 = create(Category, :environment => Environment.default, :name => 'c1') c2 = create(Category, :environment => Environment.default, :name => 'c2', :parent_id => c1.id) c3 = create(Category, :environment => Environment.default, :name => 'c3', :parent_id => c2.id) c4 = create(Category, :environment => Environment.default, :name => 'c4', :parent_id => c1.id) owner = create_user('testuser').person art = create(Article, :name => 'ytest', :profile_id => owner.id) art.add_category(c4) art.category_ids = [c2,c3].map(&:id) assert_equivalent [c2, c3], art.categories(true) assert_includes art.categories_including_virtual(true), c1 assert !art.categories_including_virtual(true).include?(c4) end should 'be able to create an article already with categories' do parent1 = fast_create(Category, :environment_id => Environment.default.id, :name => 'parent1') c1 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c1', :parent_id => parent1.id) c2 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c2') p = create_user('testinguser').person a = create(Article, :name => 'test', :category_ids => [c1.id, c2.id], :profile_id => p.id) assert_equivalent [c1, c2], a.categories(true) assert_includes a.categories_including_virtual(true), parent1 end should 'not add a category twice to article' do c1 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c1') c2 = create(Category, :environment => Environment.default, :name => 'c2', :parent_id => c1.id) c3 = create(Category, :environment => Environment.default, :name => 'c3', :parent_id => c1.id) owner = create_user('testuser').person art = create(Article, :name => 'ytest', :profile_id => owner.id) art.category_ids = [c2,c3,c3].map(&:id) categories = art.categories(true) categories_including_virtual = art.categories_including_virtual(true) assert_not_includes categories, c1 assert_includes categories, c2 assert_includes categories, c3 assert_includes categories_including_virtual, c1 assert_includes categories_including_virtual, c2 assert_includes categories_including_virtual, c3 end should 'not accept Product category as category' do assert !Article.new.accept_category?(ProductCategory.new) end should 'accept published attribute' do assert_respond_to Article.new, :published assert_respond_to Article.new, :published= end should 'say that logged off user cannot see private article' do profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) assert !article.display_to?(nil) end should 'say that not member of profile cannot see private article' do profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) person = create_user('test_user').person assert !article.display_to?(person) end should 'say that member user can not see private article' do profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false, :show_to_followers => false) person = create_user('test_user').person profile.affiliate(person, Profile::Roles.member(profile.environment.id)) assert !article.display_to?(person) end should 'say that profile admin can see private article' do profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) person = create_user('test_user').person profile.affiliate(person, Profile::Roles.admin(profile.environment.id)) assert article.display_to?(person) end should 'say that profile moderator can see private article' do profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) person = create_user('test_user').person profile.affiliate(person, Profile::Roles.moderator(profile.environment.id)) assert article.display_to?(person) end should 'show article to non member if article public but profile private' do profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile', :public_profile => false) article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => true) person1 = create_user('test_user1').person profile.affiliate(person1, Profile::Roles.member(profile.environment.id)) person2 = create_user('test_user2').person assert article.display_to?(nil) assert article.display_to?(person2) assert article.display_to?(person1) end should 'make new article private if created inside a private folder' do profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) article = fast_create(Article, :name => 'my private article', :profile_id => profile.id, :parent_id => folder.id) assert !article.published? end should 'save as private' do profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) article = fast_create(Article, :name => 'my private article') article.profile = profile article.parent = folder article.save! article.reload assert !article.published? end should 'not allow friends of private person see the article' do person = create_user('test_user').person article = create(Article, :name => 'test article', :profile => person, :published => false, :show_to_followers => false) friend = create_user('test_friend').person person.add_friend(friend) person.save! friend.save! assert !article.display_to?(friend) end should 'display private articles to people who can view private content' do person = create_user('test_user').person article = fast_create(Article, :name => 'test article', :profile_id => person.id, :published => false) admin_user = create_user('admin_user').person admin_user.stubs(:has_permission?).with('view_private_content', article.profile).returns('true') assert article.display_to?(admin_user) end should 'make a copy of the article as child of it' do person = create_user('test_user').person a = create(Article, :name => 'test article', :body => 'some text', :profile_id => person.id) b = a.copy(:parent => a, :profile => a.profile) assert_includes a.children, b assert_equal 'some text', b.body end should 'make a copy of the article to other profile' do p1 = create_user('test_user1').person p2 = create_user('test_user2').person a = create(Article, :name => 'test article', :body => 'some text', :profile_id => p1.id) b = a.copy(:parent => a, :profile => p2) p2 = Person.find(p2.id) assert_includes p2.articles, b assert_equal 'some text', b.body end should 'mantain the type in a copy' do p = create_user('test_user').person a = fast_create(Folder, :name => 'test folder', :profile_id => p.id) b = a.copy(:parent => a, :profile => p) assert_kind_of Folder, b end should 'not copy slug' do a = fast_create(Article, :slug => 'slug123') b = a.copy({}) assert a.slug != b.slug end should 'load article under an old path' do p = create_user('test_user').person a = create(Article, :name => 'old-name', :profile_id => p.id) old_path = a.explode_path a.name = 'new-name' a.save! page = Article.find_by_old_path(old_path) assert_equal a.path, page.path end should 'load new article name equal of another article old name' do p = create_user('test_user').person a1 = create(Article, :name => 'old-name', :profile_id => p.id) old_path = a1.explode_path a1.name = 'new-name' a1.save! a2 = p.articles.create!(:name => 'old-name') page = Article.find_by_old_path(old_path) assert_equal a2.path, page.path end should 'article with most recent version with the name must be loaded if no aritcle with the name' do p = create_user('test_user').person a1 = create(Article, :name => 'old-name', :profile_id => p.id) old_path = a1.explode_path a1.name = 'new-name' a1.save! a2 = create(Article, :name => 'old-name', :profile_id => p.id) a2.name = 'other-new-name' a2.save! page = Article.find_by_old_path(old_path) assert_equal a2.path, page.path end should 'not return an article of a different user' do p1 = create_user('test_user').person a = create(Article, :name => 'old-name', :profile_id => p1.id) old_path = a.explode_path a.name = 'new-name' a.save! p2 = create_user('another_user').person page = p2.articles.find_by_old_path(old_path) assert_nil page end should 'identify if belongs to blog' do p = create_user('user_blog_test').person blog = fast_create(Blog, :name => 'Blog test', :profile_id => p.id) post = fast_create(TextileArticle, :name => 'First post', :profile_id => p.id, :parent_id => blog.id) assert post.belongs_to_blog? end should 'not belongs to blog' do p = create_user('user_blog_test').person folder = fast_create(Folder, :name => 'Not Blog', :profile_id => p.id) a = fast_create(TextileArticle, :name => 'Not blog post', :profile_id => p.id, :parent_id => folder.id) assert !a.belongs_to_blog? end should 'has comments notifier true by default' do a = Article.new assert a.notify_comments? end should 'has moderate comments false by default' do a = create(Article, :name => 'my article', :body => 'my text', :profile_id => profile.id) a.reload assert a.moderate_comments == false end should 'save a article with moderate comments as true' do a = create(Article, :name => 'my article', :body => 'my text', :profile_id => profile.id, :moderate_comments => true) a.reload assert a.moderate_comments end should 'moderate_comments? return true if moderate_comments variable is true' do a = Article.new a.moderate_comments= true assert a.moderate_comments? end should 'moderate_comments? return false if moderate_comments variable is false' do a = Article.new a.moderate_comments= false assert !a.moderate_comments? end should 'hold hits count' do a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) a.hits = 10 a.save! a.reload assert_equal 10, a.hits end should 'increment hit counter when hitted' do a = fast_create(Article, :name => 'Test article', :profile_id => profile.id, :hits => 10) a.hit assert_equal 11, a.hits a.reload assert_equal 11, a.hits end should 'have display_hits setting with default true' do a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) assert_respond_to a, :display_hits assert_equal true, a.display_hits end should 'can display hits' do a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) assert_respond_to a, :can_display_hits? assert_equal true, a.can_display_hits? end should 'return a view url when image' do image = create(UploadedFile, :profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) assert_equal image.url.merge(:view => true), image.view_url end should 'not return a view url when common article' do a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) assert_equal a.url, a.view_url end should 'have published_at' do assert_respond_to Article.new, :published_at end should 'fill published_at with current date if not set' do now = Time.now Time.stubs(:now).returns(now) a = create(Article, :name => 'Published at', :profile_id => profile.id) assert_equal now, a.published_at end should 'use npage to compose cache key' do a = fast_create(Article, :name => 'Published at', :profile_id => profile.id) assert_match(/-npage-2/,a.cache_key(:npage => 2)) end should 'use year and month to compose cache key' do a = fast_create(Article, :name => 'Published at', :profile_id => profile.id) assert_match(/-year-2009-month-04/, a.cache_key(:year => '2009', :month => '04')) end should 'use revision number to compose cache key' do a = fast_create(Article, :name => 'Versioned article', :profile_id => profile.id) assert_match(/-version-2/,a.cache_key(:version => 2)) end should 'not be highlighted by default' do a = Article.new assert !a.highlighted end should 'get tagged with tag' do a = create(Article, :name => 'Published at', :profile_id => profile.id, :tag_list => 'bli') as = Article.tagged_with('bli') assert_includes as, a end should 'get tagged with tag that contains special chars' do a = create(Article, :name => 'Published at', :profile_id => profile.id, :tag_list => 'Métodos Ágeis') as = Article.tagged_with('Métodos Ágeis') assert_includes as, a end should 'not get tagged with tag from other environment' do article_from_this_environment = create(Article, :profile => profile, :tag_list => 'bli') other_environment = fast_create(Environment) user_from_other_environment = create_user('other_user', :environment => other_environment).person article_from_other_enviroment = create(Article, :profile => user_from_other_environment, :tag_list => 'bli') tagged_articles_in_other_environment = other_environment.articles.tagged_with('bli') assert_includes tagged_articles_in_other_environment, article_from_other_enviroment assert_not_includes tagged_articles_in_other_environment, article_from_this_environment end should 'ignore category with zero as id' do a = create(Article, :name => 'a test article', :profile_id => profile.id) c = fast_create(Category, :name => 'test category', :environment_id => profile.environment.id, :parent_id => 0) a.category_ids = ['0', c.id, nil] assert a.save assert_equal [c], a.categories # also ignore parent with id = 0 assert_equal [c], a.categories_including_virtual a = profile.articles.find_by_name 'a test article' assert_equal [c], a.categories end should 'add owner on cache_key when has profile' do a = create(Article, :name => 'a test article', :profile_id => profile.id) assert_match(/-owner/, a.cache_key({}, profile)) end should 'not add owner on cache_key when has no profile' do a = create(Article, :name => 'a test article', :profile_id => profile.id) assert_no_match(/-owner/, a.cache_key({})) end should 'add owner on cache_key when profile is community' do c = fast_create(Community) a = create(Article, :name => 'a test article', :profile_id => c.id) assert_match(/-owner/, a.cache_key({}, c)) end should 'allow author to edit if is publisher' do c = fast_create(Community) p = create_user_with_permission('test_user', 'publish_content', c) a = create(Article, :name => 'a test article', :author => p, :profile_id => c.id) assert a.allow_post_content?(p) end should 'allow user with "Manage content" permissions to edit' do c = fast_create(Community) p = create_user_with_permission('test_user', 'post_content', c) a = create(Article, :name => 'a test article', :profile_id => c.id) assert a.allow_post_content?(p) end should 'update slug from name' do article = create(Article, :name => 'A test article', :profile_id => profile.id) assert_equal 'a-test-article', article.slug article.name = 'Changed name' assert_equal 'changed-name', article.slug end should 'find articles in a specific category' do env = Environment.default parent_category = create(Category, :name => "parent category", :environment_id => env.id) category_with_articles = create(Category, :name => "Category with articles", :parent_id => parent_category.id, :environment_id => env.id) category_without_articles = create(Category, :name => "Category without articles", :environment_id => env.id) article_in_category = create(Article, :name => 'Article in category', :profile_id => profile.id) article_in_category.add_category(category_with_articles) assert_includes profile.articles.in_category(category_with_articles), article_in_category assert_includes profile.articles.in_category(parent_category), article_in_category assert_not_includes profile.articles.in_category(category_without_articles), article_in_category end should 'has external_link attr' do assert_nothing_raised NoMethodError do build(Article, :external_link => 'http://some.external.link') end end should 'validates format of external_link' do article = build(Article, :external_link => 'http://invalid-url') article.valid? assert_not_nil article.errors[:external_link] end should 'put http in external_link' do article = build(Article, :external_link => 'url.without.http') assert_equal 'http://url.without.http', article.external_link end should 'list only published articles' do profile = fast_create(Person) published = create(Article, :name => 'Published', :published => true, :profile_id => profile.id) unpublished = create(Article, :name => 'Unpublished', :published => false, :profile_id => profile.id) assert_equal [ published ], profile.articles.published end should 'sanitize tags after save article' do article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) tag = build(ActsAsTaggableOn::Tag, :name => "TV Web w") assert_match /[<>]/, tag.name article.tag_list.add(tag.name) article.save! assert_no_match /[<>]/, article.tags.last.name end should 'strip HTML from tag names after save article' do article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) tag = build(ActsAsTaggableOn::Tag, :name => "TV Web w') a.valid? assert_no_match(/