require "spec/spec_helper" describe Irwi::Helpers::WikiPagesHelper do it { should_not be_nil } context "included in class" do before(:each) do @m = Object.new @m.send :extend, Irwi::Helpers::WikiPagesHelper end it { @m.should respond_to :wiki_page_form } it { @m.should respond_to :wiki_page_edit_path } it { @m.should respond_to :wiki_page_history_path } it { @m.should respond_to :wiki_page_compare_path } it { @m.should respond_to :wiki_page_path } it { @m.should respond_to :wiki_content } it { @m.should respond_to :wiki_diff } it { @m.should respond_to :wiki_user } it { @m.should respond_to :wiki_page_info } it { @m.should respond_to :wiki_page_actions } it { @m.should respond_to :wiki_page_history } it { @m.should respond_to :wiki_page_style } it { @m.should respond_to :wiki_link } it { @m.should respond_to :wiki_linkify } it { @m.should respond_to :wt } specify "should format and sanitize content with current formatter and #sanitize" do Irwi.config.formatter = mock 'Formatter' Irwi.config.formatter.should_receive(:format).with('Page content').and_return('Formatted content') @m.should_receive(:sanitize).with('Formatted content').and_return('Formatted and sanitized content') @m.wiki_content( 'Page content' ).should == 'Formatted and sanitized content' end specify "should render wiki_page_info partial" do @m.should_receive(:template_dir).and_return('partial_dir') @m.should_receive(:render).with(:partial => "partial_dir/wiki_page_info", :locals => { :page => 'MyPage' }).and_return('partial_body') @m.wiki_page_info( 'MyPage' ).should == 'partial_body' end specify "should render wiki_page_actions partial" do @m.should_receive(:template_dir).and_return('partial_dir') @m.should_receive(:render).with(:partial => "partial_dir/wiki_page_actions", :locals => { :page => 'MyPage' }).and_return('partial_body') @m.wiki_page_actions( 'MyPage' ).should == 'partial_body' end specify "should render wiki_page_history partial" do @m.should_receive(:template_dir).and_return('partial_dir') @m.should_receive(:render).with(:partial => "partial_dir/wiki_page_history", :locals => { :page => 'MyPage', :versions => [1,2], :with_form => true }).and_return('partial_body') @m.wiki_page_history( 'MyPage', [1,2] ).should == 'partial_body' end specify "should render wiki_page_history partial (with default versions)" do page = mock 'MyPage' page.should_receive(:versions).and_return([1]) @m.should_receive(:template_dir).and_return('partial_dir') @m.should_receive(:render).with(:partial => "partial_dir/wiki_page_history", :locals => { :page => page, :versions => [1], :with_form => false }).and_return('partial_body') @m.wiki_page_history( page ).should == 'partial_body' end specify "should linkify string" do @m.should_receive(:wiki_link).with('Some other page').and_return('url') @m.wiki_linkify( '[[Some other page]] - link' ).should == 'Some other page - link' end specify "should generate link for non-existent page" do page_class = mock "WikiPageClass" page_class.should_receive(:find_by_title).with('Page title').and_return(nil) Irwi.config.should_receive(:page_class).and_return(page_class) @m.should_receive(:url_for).with( :controller => 'wiki_pages', :action => :show, :path => 'Page title' ).and_return('url') @m.wiki_link( 'Page title' ).should == 'url' end specify "should generate link for existent page" do page = mock "WikiPage" page.should_receive(:path).and_return('page_path') page_class = mock "WikiPageClass" page_class.should_receive(:find_by_title).with('Page title').and_return(page) Irwi.config.should_receive(:page_class).and_return(page_class) @m.should_receive(:url_for).with( :controller => 'wiki_pages', :action => :show, :path => 'page_path' ).and_return('url') @m.wiki_link( 'Page title' ).should == 'url' end end end