From d9680fb600b55d6b5f393f74e5fd9921677f9254 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Thu, 26 Sep 2013 17:28:13 -0300 Subject: [PATCH] rails3: fix tiny_mce_article tests --- test/unit/tiny_mce_article_test.rb | 58 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb index 4b92552..e7433a9 100644 --- a/test/unit/tiny_mce_article_test.rb +++ b/test/unit/tiny_mce_article_test.rb @@ -23,52 +23,52 @@ class TinyMceArticleTest < ActiveSupport::TestCase end should 'not sanitize target attribute' do - article = TinyMceArticle.create!(:name => 'open link in new window', :body => "open link in new window", :profile => profile) + article = create(TinyMceArticle, :name => 'open link in new window', :body => "open link in new window", :profile => profile) assert_tag_in_string article.body, :tag => 'a', :attributes => {:target => '_blank'} end should 'not translate & to amp; over times' do - article = TinyMceArticle.create!(:name => 'link', :body => "link", :profile => profile) + article = create(TinyMceArticle, :name => 'link', :body => "link", :profile => profile) assert article.save assert_no_match(/&amp;/, article.body) assert_match(/&/, article.body) end should 'not escape comments from tiny mce article body' do - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "the article ...") + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "the article ...") assert_equal "the article ...", article.body end should 'convert entities characters to UTF-8 instead of ISO-8859-1' do - article = TinyMceArticle.create!(:profile => profile, :name => 'teste ' + Time.now.to_s, :body => 'link') + article = create(TinyMceArticle, :profile => profile, :name => 'teste ' + Time.now.to_s, :body => 'link') assert(article.body.is_utf8?, "%s expected to be valid UTF-8 content" % article.body.inspect) end should 'fix tinymce mess with itheora comments for IE from tiny mce article body' do - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "the just for ie... ") - assert_equal "the just for ie... ", article.body + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "the just for ie... ") + assert_equal "the just for ie... ", article.body.html_safe end should 'remove iframe if it is not from a trusted site' do - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "") + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "") assert_equal "", article.body end should 'not mess with ") + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "") assert_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://itheora.org/demo/index.php?v=example.ogv"} end should 'allow iframe if it is from stream.softwarelivre.org by default' do assert_includes Environment.default.trusted_sites_for_iframe, 'stream.softwarelivre.org' - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "") + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "") assert_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://stream.softwarelivre.org/fisl10/sites/default/files/videos.ogg"} end should 'allow iframe if it is from tv.softwarelivre.org by default' do assert_includes Environment.default.trusted_sites_for_iframe, 'tv.softwarelivre.org' - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "") + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "") assert_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://tv.softwarelivre.org/embed/1170", :width => "482", :height => "406", :align => "right", :frameborder => "0", :scrolling => "no"} end @@ -77,12 +77,12 @@ class TinyMceArticleTest < ActiveSupport::TestCase env.trusted_sites_for_iframe = ['avideosite.com'] env.save assert_includes Environment.default.trusted_sites_for_iframe, 'avideosite.com' - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "") + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "") assert_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://avideosite.com/videos.ogg"} end should 'remove only the iframe from untrusted site' do - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "") + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "") assert_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://stream.softwarelivre.org/videos.ogg"} assert_no_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://untrusted_site.com/videos.ogg"} end @@ -90,13 +90,13 @@ class TinyMceArticleTest < ActiveSupport::TestCase should 'remove iframe if it has 2 or more src' do assert_includes Environment.default.trusted_sites_for_iframe, 'itheora.org' - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "") + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "") assert_equal '', article.body end #TinymMCE convert config={"key":(.*)} in config={"key":(.*)} should 'not replace " with &quot; when adding an Archive.org video' do - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => " ") + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => " ") assert_equal " ", article.body end @@ -109,12 +109,12 @@ class TinyMceArticleTest < ActiveSupport::TestCase end should 'not allow XSS on name' do - article = TinyMceArticle.create!(:name => 'title with ', :profile => profile) + article = create(TinyMceArticle, :name => 'title with ', :profile => profile) assert_no_match /script/, article.name end should 'not allow XSS on abstract' do - article = TinyMceArticle.create!(:name => "test 123", :abstract => 'abstract with ', :profile => profile) + article = create(TinyMceArticle, :name => "test 123", :abstract => 'abstract with ', :profile => profile) assert_no_match /script/, article.abstract end @@ -125,23 +125,24 @@ class TinyMceArticleTest < ActiveSupport::TestCase should 'notify activity on create' do ActionTracker::Record.delete_all - TinyMceArticle.create! :name => 'test', :profile_id => fast_create(Profile).id, :published => true + create TinyMceArticle, :name => 'test', :profile_id => fast_create(Profile).id, :published => true assert_equal 1, ActionTracker::Record.count end should 'not group trackers activity of article\'s creation' do ActionTracker::Record.delete_all profile = fast_create(Profile) - TinyMceArticle.create! :name => 'bar', :profile_id => profile.id, :published => true - TinyMceArticle.create! :name => 'another bar', :profile_id => profile.id, :published => true + create TinyMceArticle, :name => 'bar', :profile_id => profile.id, :published => true + create TinyMceArticle, :name => 'another bar', :profile_id => profile.id, :published => true assert_equal 2, ActionTracker::Record.count - TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true + create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true assert_equal 3, ActionTracker::Record.count end should 'not update activity on update of an article' do ActionTracker::Record.delete_all profile = fast_create(Profile) + ActionTracker::Record.stubs(:current_user_from_model).returns(fast_create(Person)) article = create(TinyMceArticle, :profile_id => profile.id) time = article.activity.updated_at Time.stubs(:now).returns(time + 1.day) @@ -154,8 +155,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase should 'not create trackers activity when updating articles' do ActionTracker::Record.delete_all - a1 = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true - a2 = TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true + a1 = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + a2 = create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true assert_no_difference ActionTracker::Record, :count do a1.name = 'foo';a1.save! a2.name = 'another foo';a2.save! @@ -164,8 +165,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase should 'remove activity when an article is destroyed' do ActionTracker::Record.delete_all - a1 = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true - a2 = TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true + a1 = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + a2 = create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true assert_difference ActionTracker::Record, :count, -2 do a1.destroy a2.destroy @@ -178,20 +179,21 @@ end p1 = Person.first community.add_member(p1) assert p1.is_member_of?(community) - article = TinyMceArticle.create! :name => 'test', :profile_id => community.id + article = create TinyMceArticle, :name => 'test', :profile_id => community.id assert_equal article, ActionTracker::Record.last.target end should "the tracker action target be defined as the article on articles'creation in profile" do ActionTracker::Record.delete_all person = Person.first - article = TinyMceArticle.create! :name => 'test', :profile_id => person.id + ActionTracker::Record.stubs(:current_user_from_model).returns(fast_create(Person)) + article = create TinyMceArticle, :name => 'test', :profile_id => person.id assert_equal article, ActionTracker::Record.last.target end should 'not notify activity if the article is not advertise' do ActionTracker::Record.delete_all - a = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false + a = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false assert_equal true, a.published? assert_equal true, a.notifiable? assert_equal false, a.image? @@ -204,7 +206,7 @@ end end should "the common trackable conditions return the correct value" do - a = TinyMceArticle.new(:profile => profile) + a = build(TinyMceArticle, :profile => profile) a.published = a.advertise = true assert_equal true, a.published? assert_equal true, a.notifiable? -- libgit2 0.21.2