require "spec_helper" require 'action_controller' require 'action_controller/test_case' class FootnotesController < ActionController::Base attr_accessor :template, :performed_render end module Footnotes::Notes class TestNote < AbstractNote def self.to_sym; :test; end def valid?; true; end end class NoteXNote < TestNote; end class NoteYNote < TestNote; end class NoteZNote < TestNote; end end describe "Footnotes" do before do @controller = FootnotesController.new @controller.template = Object.new @controller.request = ActionController::TestRequest.new @controller.response = ActionController::TestResponse.new @controller.response_body = $html.dup @controller.params = {} Footnotes::Filter.notes = [ :test ] Footnotes::Filter.multiple_notes = false @footnotes = Footnotes::Filter.new(@controller) end it "footnotes_controller" do index = @controller.response.body.index(/This is the HTML page/) index.should eql 334 end it "foonotes_included" do footnotes_perform! @controller.response_body.should_not eql $html end specify "footnotes_not_included_when_request_is_xhr" do @controller.request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' @controller.request.env['HTTP_ACCEPT'] = 'text/javascript, text/html, application/xml, text/xml, */*' footnotes_perform! @controller.response.body.should eql $html end specify "footnotes_not_included_when_content_type_is_javascript" do @controller.response.headers['Content-Type'] = 'text/javascript' footnotes_perform! @controller.response.body.should eql $html end specify "footnotes_included_when_content_type_is_html" do @controller.response.headers['Content-Type'] = 'text/html' footnotes_perform! @controller.response.body.should_not eql $html end specify "footnotes_included_when_content_type_is_nil" do footnotes_perform! @controller.response.body.should_not eql $html end specify "not_included_when_body_is_not_a_string" do @controller.response.body = Proc.new { Time.now } expect { footnotes_perform! }.should_not raise_exception end specify "notes_are_initialized" do footnotes_perform! test_note = @footnotes.instance_variable_get('@notes').first test_note.class.name.should eql 'Footnotes::Notes::TestNote' test_note.to_sym.should eql :test end specify "notes_links" do note = Footnotes::Notes::TestNote.new note.should_receive(:row).twice @footnotes.instance_variable_set(:@notes, [note]) footnotes_perform! end specify "notes_fieldset" do note = Footnotes::Notes::TestNote.new note.should_receive(:has_fieldset?).exactly(3).times @footnotes.instance_variable_set(:@notes, [note]) footnotes_perform! end specify "multiple_notes" do Footnotes::Filter.multiple_notes = true note = Footnotes::Notes::TestNote.new note.should_receive(:has_fieldset?).twice @footnotes.instance_variable_set(:@notes, [note]) footnotes_perform! end specify "notes_are_reset" do note = Footnotes::Notes::TestNote.new note.class.should_receive(:close!) @footnotes.instance_variable_set(:@notes, [note]) @footnotes.send(:close!, @controller) end specify "links_helper" do note = Footnotes::Notes::TestNote.new @footnotes.send(:link_helper, note).should eql 'Test' note.should_receive(:link).once.and_return(:link) @footnotes.send(:link_helper, note).should eql 'Test' end specify "links_helper_has_fieldset?" do note = Footnotes::Notes::TestNote.new note.should_receive(:has_fieldset?).once.and_return(true) @footnotes.send(:link_helper, note).should eql 'Test' end specify "links_helper_onclick" do note = Footnotes::Notes::TestNote.new note.should_receive(:onclick).twice.and_return(:onclick) @footnotes.send(:link_helper, note).should eql 'Test' note.should_receive(:has_fieldset?).once.and_return(true) @footnotes.send(:link_helper, note).should eql 'Test' end specify "insert_style" do @controller.response.body = "
This is the HTML page. It works and is encoded just like any HTML page you have previously done. View the XHTML version of this page to view the difference between HTML and XHTML.
You will be glad to know that no changes need to be made to any of your CSS files.
HTML end