Changeset 565

Show
Ignore:
Timestamp:
08/24/05 22:40:48 (3 years ago)
Author:
scott
Message:

Filter plugins. This adds a *lot* of code.

See http://scottstuff.net/blog/articles/2005/08/23/introduction-to-typo-filters
for details.

Closes #346, #299

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk

    • Property svn:ignore changed from public/stylesheets/theme to cache
  • trunk/app/apis/blogger_service.rb

    r444 r565  
    4141class BloggerService < TypoWebService 
    4242  web_service_api BloggerApi 
    43  
    4443  before_invocation :authenticate   
    45   attr_reader :controller 
    46    
    47   def initialize(controller) 
    48     @controller = controller 
    49   end 
    5044   
    5145  def deletePost(appkey, postid, username, password, publish) 
     
    8478    article.created_at  = Time.now 
    8579    article.user        = @user 
     80    article.text_filter ||= TextFilter.find_by_name(config[:text_filter]) 
    8681 
    8782    if categories 
     
    9186    end 
    9287 
     88    update_html(article) 
     89     
    9390    article.save 
    9491    article.id 
    9592  end 
    96  
     93   
    9794end 
  • trunk/app/apis/meta_weblog_service.rb

    r554 r565  
    6666class MetaWeblogService < TypoWebService 
    6767  web_service_api MetaWeblogApi 
    68    
    6968  before_invocation :authenticate   
    70   attr_reader :controller 
    71  
    72   def initialize(controller) 
    73     @controller = controller 
    74   end 
    7569 
    7670  def getCategories(blogid, username, password) 
     
    9892 
    9993    # Movable Type API support 
    100     article.allow_comments = struct['mt_allow_comments'] || config['default_allow_comments'
    101     article.allow_pings    = struct['mt_allow_pings'] || config['default_allow_pings'
     94    article.allow_comments = struct['mt_allow_comments'] || config[:default_allow_comments
     95    article.allow_pings    = struct['mt_allow_pings'] || config[:default_allow_pings
    10296    article.extended       = struct['mt_text_more'] || '' 
    10397    article.excerpt        = struct['mt_excerpt'] || '' 
    10498    article.keywords       = struct['mt_keywords'] || '' 
    105     article.text_filter    = struct['mt_convert_breaks'] || '' 
     99    article.text_filter    = TextFilter.find_by_name(struct['mt_convert_breaks'] || config[:text_filter]) 
    106100     
    107101    if struct['categories'] 
     
    113107 
    114108    article.send_pings(article_url(article), struct['mt_tb_ping_urls']) 
     109    update_html(article) 
    115110     
    116111    article.save 
     
    138133    article.excerpt        = struct['mt_excerpt'] || '' 
    139134    article.keywords       = struct['mt_keywords'] || '' 
    140     article.text_filter    = struct['mt_convert_breaks'] || '' 
     135    article.text_filter    = TextFilter.find_by_name(struct['mt_convert_breaks'] || config[:text_filter]) 
    141136 
    142137    if struct['categories'] 
     
    148143    RAILS_DEFAULT_LOGGER.info(struct['mt_tb_ping_urls']) 
    149144    article.send_pings(article_url(article), struct['mt_tb_ping_urls']) 
    150  
     145    update_html(article) 
    151146    article.save     
    152147    true 
     
    174169      :mt_allow_comments => article.allow_comments.to_i, 
    175170      :mt_allow_pings    => article.allow_pings.to_i, 
    176       :mt_convert_breaks => article.text_filter.to_s
     171      :mt_convert_breaks => (article.text_filter.name.to_s rescue '')
    177172      :mt_tb_ping_urls   => article.pings.collect { |p| p.url }, 
    178173      :dateCreated       => (article.created_at.to_formatted_s(:db) rescue "") 
     
    196191  def pub_date(time) 
    197192    time.strftime "%a, %e %b %Y %H:%M:%S %Z" 
    198   end 
     193  end   
    199194end 
  • trunk/app/apis/movable_type_service.rb

    r548 r565  
    109109      article.categories.push_with_attributes(category, :is_primary => c['isPrimary']) 
    110110    end 
    111      
     111    update_html(article) 
    112112    article.save 
    113113  end 
     
    120120  # translators being available. 
    121121  def supportedTextFilters() 
    122     filters = [] 
    123     filters << MovableTypeStructs::TextFilter.new(:key => 'markdown', :label => 'Markdown') if defined?(BlueCloth) 
    124     filters << MovableTypeStructs::TextFilter.new(:key => 'smartypants', :label => 'SmartyPants') if defined?(RubyPants) 
    125     filters << MovableTypeStructs::TextFilter.new(:key => 'markdown smartypants', :label => 'Markdown with SmartyPants') if defined?(RubyPants) and defined?(BlueCloth) 
    126     filters << MovableTypeStructs::TextFilter.new(:key => 'textile', :label => 'Textile') if defined?(RedCloth) 
    127     filters 
     122    TextFilter.find(:all).collect do |filter| 
     123      MovableTypeStructs::TextFilter.new(:key => filter.name, :label => filter.description) 
     124    end 
    128125  end 
    129126 
     
    150147    time.strftime "%a, %e %b %Y %H:%M:%S %Z" 
    151148  end 
     149   
    152150end 
  • trunk/app/apis/typo_web_service.rb

    r431 r565  
    11class TypoWebService < ActionWebService::Base 
     2  attr_accessor :controller 
     3 
     4  def initialize(controller) 
     5    @controller = controller 
     6  end 
    27 
    38  protected 
     
    1520    end 
    1621  end 
     22 
     23  private 
     24  def update_html(article) 
     25    article.body_html = controller.filter_text_by_name(article.body, (article.text_filter.name rescue nil)) 
     26    article.extended_html = controller.filter_text_by_name(article.extended, (article.text_filter.name rescue nil)) 
     27  end   
    1728end 
  • trunk/app/controllers/admin/comments_controller.rb

    r310 r565  
    1919  def new 
    2020    @comment = @article.comments.build(params[:comment]) 
     21    @comment.body_html = filter_text_by_name(@comment.body, config[:comment_text_filter],true) 
    2122 
    2223    if request.post? and @comment.save 
     
    2930    @comment = @article.comments.find(params[:id]) 
    3031    @comment.attributes = params[:comment] 
     32    @comment.body_html = filter_text_by_name(@comment.body, config[:comment_text_filter],true) 
    3133    if request.post? and @comment.save 
    3234      flash[:notice] = 'Comment was successfully updated.' 
  • trunk/app/controllers/admin/content_controller.rb

    r544 r565  
    2525    @article.allow_comments ||= config[:default_allow_comments] 
    2626    @article.allow_pings ||= config[:default_allow_pings] 
    27     @article.text_filter ||= config[:text_filter] 
     27    @article.text_filter ||= TextFilter.find_by_name(config[:text_filter]) 
    2828    @article.user = session[:user] 
     29    update_html(@article) 
    2930     
    3031    @categories = Category.find(:all, :order => 'UPPER(name)') 
     
    5354      @article.categories.clear 
    5455      @article.categories << Category.find(params[:categories]) if params[:categories] 
     56      update_html(@article) 
    5557       
    5658      params[:attachments].each do |k,v| 
     
    9496  def preview 
    9597    @headers["Content-Type"] = "text/html; charset=utf-8" 
    96     @article = params[:article] 
     98    @article = Article.new 
     99    @article.attributes = params[:article] 
     100    update_html(@article) 
    97101    render :layout => false 
    98102  end 
     
    134138    end 
    135139  end 
     140 
     141  private 
     142  def update_html(article) 
     143    article.body_html = filter_text_by_name(article.body, article.text_filter.name) rescue article.body 
     144    article.extended_html = filter_text_by_name(article.extended, article.text_filter.name) rescue article.extended 
     145  end 
     146   
    136147end 
  • trunk/app/controllers/admin/pages_controller.rb

    r461 r565  
    2121    @page.user_id = session[:user].id 
    2222    @page.text_filter ||= config[:text_filter] 
     23    @page.body_html = filter_text_by_name(@page.body,@page.text_filter) 
    2324    if request.post? and @page.save 
    2425      flash[:notice] = 'Page was successfully created.' 
     
    3031    @page = Page.find(params[:id]) 
    3132    @page.attributes = params[:page] 
     33    @page.body_html = filter_text_by_name(@page.body,@page.text_filter) 
    3234    if request.post? and @page.save 
    3335      flash[:notice] = 'Page was successfully updated.' 
     
    4648  def preview 
    4749    @headers["Content-Type"] = "text/html; charset=utf-8" 
    48     @page = params[:page] 
     50    @page = Page.new 
     51    @page.attributes = params[:page] 
     52    @page.body_html = filter_text_by_name(@page.body,@page.text_filter) 
    4953    render :layout => false 
    5054  end 
  • trunk/app/controllers/admin/themes_controller.rb

    r442 r565  
    33  def index 
    44    @themes = Theme.find_all 
     5    @themes.each do |theme| 
     6      theme.description_html = filter_text(theme.description,[:markdown,:smartypants]) 
     7    end 
    58    @active = Theme.current 
    69  end 
  • trunk/app/controllers/application.rb

    r462 r565  
    1  
    21# The filters added to this controller will be run for all controllers in the application. 
    32# Likewise will all the methods added be available for all controllers. 
     
    3736    Theme.current.layout 
    3837  end 
     38   
     39  def filter_text(text, filters, filterparams={}, filter_html=false) 
     40    map=TextFilter.filters_map 
     41 
     42    if(filter_html) 
     43      filters = [:htmlfilter, filters].flatten 
     44    end 
     45 
     46    filters.each do |filter| 
     47      begin 
     48        filter_component = map[filter.to_s].controller_path 
     49        text = render_component_as_string(:controller => filter_component,  
     50          :action => 'filtertext',  
     51          :params => {:text => text, :filterparams => filterparams} ) 
     52      rescue => err 
     53        logger.error "Filter #{filter} failed: #{err}" 
     54      end 
     55    end 
     56 
     57    text 
     58  end 
     59 
     60  def filter_text_by_name(text, filtername, filter_html=false) 
     61    f = TextFilter.find_by_name(filtername) 
     62    if (f) 
     63      filters = [:macropre, f.markup, :macropost, f.filters].flatten 
     64      filter_text(text,filters,f.params,filter_html) 
     65    else 
     66      filter_text(text,[:macropre,:macropost],{},filter_html) 
     67    end 
     68  end 
    3969end 
     70 
     71require_dependency 'controllers/textfilter_controller' 
  • trunk/app/controllers/articles_controller.rb

    r557 r565  
    108108    @comment.article = @article 
    109109    @comment.ip = request.remote_ip 
     110    @comment.body_html = filter_text_by_name(@comment.body, config[:comment_text_filter],true) 
    110111 
    111112    if request.post? and @comment.save       
     
    119120      render :partial => "comment", :object => @comment 
    120121    else 
     122      STDERR.puts @comment.errors.inspect 
    121123      render :text => @comment.errors.full_messages.join(", "), :status => 500 
    122124    end 
  • trunk/app/controllers/backend_controller.rb

    r196 r565  
    44  web_service_dispatching_mode :layered 
    55  web_service(:metaWeblog)  { MetaWeblogService.new(self) } 
    6   web_service(:mt)          { MovableTypeService.new
     6  web_service(:mt)          { MovableTypeService.new(self)
    77  web_service(:blogger)     { BloggerService.new(self) } 
    88 
  • trunk/app/helpers/admin/base_helper.rb

    r558 r565  
    6161  end     
    6262 
    63   def text_filter_options   
    64     text_filter_options = Array.new 
    65     text_filter_options << [ 'None', 'none' ] 
    66     text_filter_options << [ 'Textile', 'textile' ] if defined?(RedCloth) 
    67     text_filter_options << [ 'Markdown', 'markdown' ] if defined?(BlueCloth) 
    68     text_filter_options << [ 'SmartyPants', 'smartypants' ] if defined?(RubyPants) 
    69     text_filter_options << [ 'Markdown with SmartyPants', 'markdown smartypants' ] if defined?(RubyPants) and defined?(BlueCloth) 
    70     text_filter_options 
     63  def text_filter_options 
     64    TextFilter.find(:all).collect do |filter| 
     65      [ filter.description, filter ] 
     66    end 
    7167  end 
    7268   
    7369  def alternate_class 
    7470    @class = @class != '' ? '' : 'class="shade"' 
     71  end 
     72   
     73  def reset_alternation 
     74    @class = nil 
    7575  end 
    7676   
     
    103103  end 
    104104 
     105  def task_help(title, id) 
     106    task(title, 'show_help', id) 
     107  end 
     108 
    105109  def task(title, action, id = nil) 
    106110    content_tag :li, link_to(title, :action => action, :id => id) 
  • trunk/app/helpers/articles_helper.rb

    r556 r565  
    9191 
    9292    image_tag("http://www.gravatar.com/avatar.php?" << 
    93       options.map { |key, value| "#{key}=#{value}" }.join("&"), :class => "gravatar") 
     93      options.map { |key,value| "#{key}=#{value}" }.sort.join("&"), :class => "gravatar") 
    9494  end 
    9595end 
  • trunk/app/models/aggregations/flickr.rb

    r364 r565  
    1010# end 
    1111# 
    12 class Flickr 
     12class FlickrAggregation 
    1313  include REXML 
    1414 
     
    2424     
    2525  # This object holds given information of a picture 
    26   class Picture < Struct.new(:link, :title, :date, :description) 
    27     def to_s; title end           
    28     def date=(value); super(Time.parse(value)) end 
     26  class Picture 
     27    attr_accessor :link, :title, :date, :description 
     28 
     29    def to_s 
     30      title 
     31    end 
     32 
     33    def date=(value) 
     34      @date = Time.parse(value) 
     35    end 
     36 
    2937    def image  
    3038      description.scan( /http\:\/\/photo.*\.jpg/ ).to_s 
  • trunk/app/models/article.rb

    r557 r565  
    1212  has_and_belongs_to_many :tags 
    1313  belongs_to :user 
     14  belongs_to :text_filter 
    1415   
    1516  after_destroy :fix_resources 
     17   
     18  # Compatibility hack, so Article.attributes(params[:article]) still works. 
     19  def text_filter=(filter) 
     20    if filter.nil? 
     21      self.text_filter_id = nil 
     22    elsif filter.kind_of? TextFilter 
     23      self.text_filter_id = filter.id 
     24    else 
     25      new_filter = TextFilter.find_by_name(filter.to_s) 
     26      self.text_filter_id = (new_filter.nil? ? nil : new_filter.id) 
     27    end 
     28  end 
    1629   
    1730  def stripped_title 
     
    108121  protected   
    109122 
    110   before_save :set_defaults, :transform_body 
     123  before_save :set_defaults 
    111124   
    112125  def set_defaults 
     
    120133 
    121134    self.published ||= 1 
    122     self.text_filter = config['text_filter'] if self.text_filter.blank? 
     135    self.text_filter = TextFilter.find_by_name(config['text_filter']) if self.text_filter_id.blank? 
    123136     
    124137    if schema_version >= 7 
     
    136149   
    137150  def transform_body 
    138     self.body_html = HtmlEngine.transform(body, self.text_filter) 
    139     self.extended_html = HtmlEngine.transform(extended, self.text_filter) 
     151#    self.body_html = TextFilter.filter_by_name(body,text_filter) 
     152#    self.extended_html = TextFilter.filter_by_name(extended,text_filter) 
    140153  end   
    141154 
  • trunk/app/models/comment.rb

    r287 r565  
    1010  protected 
    1111   
    12   before_save :correct_url, :make_nofollow, :transform_body, :make_nofollow 
    13  
     12  before_save :correct_url, :make_nofollow 
     13   
    1414  def correct_url 
    1515    unless url.to_s.empty? 
     
    2222  def make_nofollow 
    2323    self.author = nofollowify(author) 
    24     self.body = nofollowify(body
     24    self.body_html = nofollowify(body_html.to_s
    2525  end 
    26  
    27   def transform_body 
    28     # Escape HTML in comments 
    29     self.body_html = HtmlEngine.transform(body, config["comment_text_filter"], [:filter_html])  
    30   end 
    31  
    3226end 
  • trunk/app/models/page.rb

    r464 r565  
    11class Page < ActiveRecord::Base 
    22  belongs_to :user 
    3   before_save :transform_body 
     3  belongs_to :text_filter 
    44  validates_presence_of :name, :title, :body 
    55  validates_uniqueness_of :name 
    6  
    7   protected 
    86   
    9   def transform_body 
    10     self.body_html = HtmlEngine.transform(body, self.text_filter) 
    11   end   
     7  # Compatibility hack, so Page.attributes(params[:page]) still works. 
     8  def text_filter=(filter) 
     9    if filter.nil? 
     10      self.text_filter_id = nil 
     11    elsif filter.kind_of? TextFilter 
     12      self.text_filter_id = filter.id 
     13    else 
     14      new_filter = TextFilter.find_by_name(filter.to_s) 
     15      self.text_filter_id = (new_filter.nil? ? nil : new_filter.id) 
     16    end 
     17  end 
    1218end 
  • trunk/app/models/theme.rb

    r463 r565  
    33  @@cache_theme_lookup = false 
    44 
    5   attr_accessor :name, :path 
     5  attr_accessor :name, :path, :description_html 
    66 
    77  def initialize(name, path) 
     
    1414 
    1515  def description 
    16     readme = File.read("#{path}/about.markdown") 
    17     HtmlEngine.transform(readme, "markdown smartypants") 
     16    File.read("#{path}/about.markdown") 
    1817  end 
    1918   
  • trunk/app/views/admin/content/preview.rhtml

    r461 r565  
    11<h4><%= @article[:title] %></h4> 
    22 
    3 <% [:body, :extended].each do |text| -%> 
    4 <p><%= HtmlEngine.transform(@article[text], @article[:text_filter]) %></p> 
    5 <% end -%> 
     3<%= @article.full_html %> 
  • trunk/app/views/admin/general/index.rhtml

    r556 r565  
    7676      <p> 
    7777        <select name="setting[text_filter]" id="text_filter"> 
    78           <%= options_for_select text_filter_options, config_value(:text_filter) %> 
     78          <%= options_for_select text_filter_options, TextFilter.find_by_name(config_value(:text_filter)) %> 
    7979        </select> 
    8080        <label for="text_filter">Article filter</label>  
     
    8282      <p> 
    8383        <select name="setting[comment_text_filter]" id="comment_text_filter"> 
    84         <%= options_for_select text_filter_options, config_value(:comment_text_filter) %> 
     84        <%= options_for_select text_filter_options, TextFilter.find_by_name(config_value(:comment_text_filter)) %> 
    8585        </select> 
    8686        <label for="comment_text_filter">Comments filter</label>  
  • trunk/app/views/admin/pages/preview.rhtml

    r464 r565  
    11<h3><%= @page[:title] %></h3> 
    22 
    3 <p><%= HtmlEngine.transform(@page[:body], @page[:text_filter]) %></p> 
     3<p><%= @page.body_html %></p> 
  • trunk/app/views/admin/themes/index.rhtml

    r498 r565  
    22<div class="set theme" style="margin-top:10px;"> 
    33  <div class="preview"><img src="<%= url_for :action => 'preview', :theme => theme.name %>" alt="<%= theme.name %>" /></div> 
    4   <%= theme.description %> 
     4  <%= theme.description_html %> 
    55  <% if theme.path == @active.path -%> 
    66  <em>(Active theme)</em> 
  • trunk/app/views/layouts/administration.rhtml

    r558 r565  
    3737            <%= tab "Users", :controller=>"/admin/users", :action => 'index' %> 
    3838            <%= tab "Resources", :controller=>"/admin/resources", :action => 'index' %> 
     39            <%= tab "Filters", :controller=>"/admin/textfilters", :action => 'index' %> 
    3940          </ul> 
    4041        </div>   
  • trunk/components/plugins/sidebars/flickr_controller.rb

    r440 r565  
    1313 
    1414  def content 
    15     @flickr=check_cache(Flickr, @sb_config['feed']) rescue nil 
     15    @flickr=check_cache(FlickrAggregration, @sb_config['feed']) rescue nil 
    1616  end 
    1717 
  • trunk/config/environment.rb

    r561 r565  
    2424  vendor/redcloth/lib 
    2525  vendor/bluecloth/lib 
     26  vendor/flickr 
     27  vendor/sparklines/lib 
    2628  vendor/rails/railties 
    2729  vendor/rails/railties/lib 
     
    4042require 'bluecloth'  
    4143require 'rubypants'  
     44require 'flickr' 
    4245 
    4346# Require Rails libraries. 
     
    9598 
    9699ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:database_manager => CGI::Session::ActiveRecordStore)       
     100ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::FileStore.new("#{RAILS_ROOT}/cache/fragment/") 
    97101 
    98102ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( 
  • trunk/config/routes.rb

    r563 r565  
    6464    :controller => 'theme', :action => 'images' 
    6565 
     66  map.connect 'plugins/filters/:filter/:public_action', 
     67    :controller => 'textfilter', :action => 'public_action' 
     68 
    6669  # Kill attempts to connect directly to the theme controller. 
    6770  # Ideally we'd disable these by removing the default route (below), 
  • trunk/test/fixtures/pages.yml

    r464 r565  
    1010  title: Another Page Title 
    1111  body: another body for yet another page 
     12markdown_page: 
     13  id: 3 
     14  name: markdown-page 
     15  title: Markdown Page 
     16  text_filter_id: 1 
     17  body: this is *markdown*. 
     18 
  • trunk/test/functional/admin/content_controller_test.rb

    r534 r565  
    66 
    77class Admin::ContentControllerTest < Test::Unit::TestCase 
    8   fixtures :articles, :users, :categories, :resources 
     8  fixtures :articles, :users, :categories, :resources, :text_filters, :settings 
    99 
    1010  def setup 
     
    5353    assert_equal @tobi, new_article.user 
    5454  end 
     55     
     56  def test_create_filtered 
     57    body = "body via *textile*" 
     58    extended="*foo*" 
     59    post :new, 'article' => { :title => "another test", :body => body, :extended => extended} 
     60    assert_redirected_to :action => 'show' 
     61     
     62    new_article = Article.find(:first, :order => "id DESC") 
     63    assert_equal body, new_article.body 
     64    assert_equal extended, new_article.extended 
     65    assert_equal "textile", new_article.text_filter.name 
     66    assert_equal '<p>body via <strong>textile</strong></p>', new_article.body_html 
     67    assert_equal '<p><strong>foo</strong></p>', new_article.extended_html 
     68  end 
    5569 
    5670  def test_edit 
     
    6276 
    6377  def test_update 
    64     post :edit, 'id' => 1 
     78    body = "another *textile* test" 
     79    post :edit, 'id' => 1, 'article' => {:body => body, :text_filter => 'textile'} 
    6580    assert_redirected_to :action => 'show', :id => 1 
     81 
     82    article = Article.find(1) 
     83    assert_equal "textile", article.text_filter.name 
     84    assert_equal body, article.body 
     85    assert_equal '<p>another <strong>textile</strong> test</p>', article.body_html 
    6686  end 
    6787 
  • trunk/test/functional/articles_controller_test.rb

    r560 r565  
    66 
    77class ArticlesControllerTest < Test::Unit::TestCase 
    8   fixtures :articles, :categories, :settings, :users, :comments, :trackbacks, :pages, :articles_categories 
     8  fixtures :articles, :categories, :settings, :users, :comments, :trackbacks, :pages, :articles_categories, :text_filters 
    99 
    1010  def setup 
     
    5454  end 
    5555   
     56  def test_comment_posting 
     57    post :comment, { :id => 1, :comment => {'body' => 'This is *textile*', 'author' => 'bob' }} 
     58     
     59    assert_response :success 
     60    assert_tag :tag => 'strong', :content => 'textile' 
     61     
     62    comment = Comment.find(:first, :order => 'created_at desc') 
     63    assert comment 
     64     
     65    assert_equal '<p>This is <strong>textile</strong></p>', comment.body_html 
     66  end 
     67   
     68  def test_comment_spam1 
     69    post :comment, { 
     70      :id => 1,  
     71      :comment => { 
     72        'body' => 'Link to <a href="http://spammer.example.com">spammy goodness</a>', 
     73        'author' => 'bob', 
     74        'url' => 'http://spam2.example.com', 
     75        'email' => 'foo'}} 
     76 
     77    assert_response :success 
     78 
     79    comment = Comment.find(:first, :order => 'created_at desc') 
     80    assert comment 
     81 
     82    assert_equal '<p>Link to &lt;a href=&#8221;http://spammer.example.com&#8221;&gt;spammy goodness&lt;/a&gt;</p>', 
     83      comment.body_html 
     84  end 
     85 
     86  def test_comment_spam2 
     87    post :comment, { 
     88      :id => 1,  
     89      :comment => { 
     90        'body' => 'Link to "spammy goodness":http://spammer.example.com', 
     91        'author' => 'bob', 
     92        'url' => 'http://spam2.example.com', 
     93        'email' => 'foo'}} 
     94 
     95    assert_response :success 
     96 
     97    comment = Comment.find(:first, :order => 'created_at desc') 
     98    assert comment 
     99 
     100    assert_equal '<p>Link to <a href="http://spammer.example.com" rel="nofollow">spammy goodness</a></p>', 
     101      comment.body_html 
     102  end 
     103 
    56104  def test_comment_nuking  
    57105    num_comments = Comment.count 
  • trunk/test/functional/backend_controller_test.rb

    r553 r565  
    4040   
    4141  def test_blogger_new_post 
    42     args = [ 'foo', '1', 'tobi', 'whatever', '<title>new post title</title>new post body', 1] 
     42    args = [ 'foo', '1', 'tobi', 'whatever', '<title>new post title</title>new post *body*', 1] 
    4343 
    4444    result = invoke_layered :blogger, :newPost, *args 
     
    4646    new_post = Article.find(result) 
    4747    assert_equal "new post title", new_post.title 
    48     assert_equal "new post body", new_post.body 
    49     assert_equal "textile", new_post.text_filter 
     48    assert_equal "new post *body*", new_post.body 
     49    assert_equal "<p>new post <strong>body</strong></p>", new_post.body_html 
     50    assert_equal "textile", new_post.text_filter.name 
    5051    assert_equal @tobi, new_post.user 
    5152  end 
     
    5960    assert_equal "new post body for post without", new_post.title 
    6061    assert_equal "new post body for post without title but with a lenghty body", new_post.body 
     62    assert_equal "<p>new post body for post without title but with a lenghty body</p>", new_post.body_html 
    6163  end 
    6264 
     
    120122    article = Article.find(1) 
    121123    article.title = "Modified!" 
     124    article.body = "this is a *test*" 
     125    article.text_filter = TextFilter.find_by_name("textile") 
    122126    article.created_at = Time.now.midnight 
    123127 
     
    126130    result = invoke_layered :metaWeblog, :editPost, *args 
    127131    assert result 
    128     assert_equal "Modified!", Article.find(1).title 
    129     assert_equal Time.now.midnight.to_s, Article.find(1).created_at.to_s 
     132 
     133    new_article = Article.find(1) 
     134     
     135    assert_equal article.title, new_article.title 
     136    assert_equal article.body, new_article.body 
     137    assert_equal "<p>this is a <strong>test</strong></p>", new_article.body_html 
     138    assert_equal Time.now.midnight.to_s, new_article.created_at.to_s 
    130139  end 
    131140 
     
    134143    article.title = "Posted via Test" 
    135144    article.body = "body" 
     145    article.extended = "extend me" 
     146    article.text_filter = TextFilter.find_by_name("textile") 
    136147    article.created_at = Time.now.midnight 
    137148     
     
    142153    new_post = Article.find(result) 
    143154    assert_equal "Posted via Test", new_post.title 
    144     assert_equal "textile", new_post.text_filter 
     155    assert_equal "textile", new_post.text_filter.name 
     156    as