require 'spec_helper' module Deface describe TemplateHelper do include_context "mock Rails.application" include Deface::TemplateHelper describe "load_template_source" do before do #stub view paths to be local spec/assets directory ActionController::Base.stub(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")]) end describe "with no overrides defined" do it "should return source for partial" do load_template_source("shared/post", true).should == "

I'm from shared/post partial

\n<%= \"And I've got ERB\" %>\n" end it "should return converted source for partial containing haml" do load_template_source("shared/hello", true).should =="
<%= 'Hello, World!' %>\n
\n" end it "should return source for template" do load_template_source("shared/person", false).should == "

I'm from shared/person template

\n<%= \"I've got ERB too\" %>\n" end it "should return converted source for template containing haml" do load_template_source("shared/pirate", false).gsub(/\s/, '').should == "

<%=print_information%>

'><%=render:partial=>\"sidebar\"%>" end it "should return source for namespaced template" do load_template_source("admin/posts/index", false).should == "

Manage Posts

\n" end it "should raise exception for non-existing file" do lambda { load_template_source("tester/post", true) }.should raise_error(ActionView::MissingTemplate) end end describe "with overrides defined" do include_context "mock Rails.application" before(:each) do Deface::Override.new(:virtual_path => "shared/_post", :name => "shared#post", :remove => "p") Deface::Override.new(:virtual_path => "shared/person", :name => "shared#person", :replace => "p", :text => "

Argh!

") Deface::Override.new(:virtual_path => "shared/_hello", :name => "shared#hello", :replace_contents => "div#message", :text => "<%= 'Goodbye World!' %>") Deface::Override.new(:virtual_path => "shared/pirate", :name => "shared#pirate", :replace => "p", :text => "

Argh!

") Deface::Override.new(:virtual_path => "admin/posts/index", :name => "admin#posts#index", :replace => "h1", :text => "

Argh!

") end it "should return overridden source for partial including overrides" do load_template_source("shared/post", true).should == "\n<%= \"And I've got ERB\" %>" end it "should return converted and overridden source for partial containing haml" do load_template_source("shared/hello", true).should =="
\" id=\"message\"><%= 'Goodbye World!' %>
" end it "should return overridden source for partial excluding overrides" do load_template_source("shared/post", true, false).should == "

I'm from shared/post partial

\n<%= \"And I've got ERB\" %>\n" end it "should return overridden source for template including overrides" do load_template_source("shared/person", false).should == "

Argh!

\n<%= \"I've got ERB too\" %>" end it "should return converted and overridden source for template containing haml" do load_template_source("shared/pirate", false).gsub(/\s/, '').should == "

Argh!

\"><%=render:partial=>\"sidebar\"%>" end it "should return source for namespaced template including overrides" do load_template_source("admin/posts/index", false).should == "

Argh!

" end end end end end