require 'spec_helper' describe HamlAssets do it "should have the proper format" do RailsApp::Application.assets['link_to.jst.ejs.haml'].to_s.should == "(function() { this.JST || (this.JST = {}); this.JST[\"link_to\"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('');}return __p.join('');};\n}).call(this);\n" end context 'rendering' do let(:path) { 'app/assets/templates/quotes.haml' } context "quoted attributes" do after { Haml::Template.options[:attr_wrapper] = "'" } it "handles data attributes" do template = HamlAssets::HamlSprocketsEngine.new(path) { %Q(%div{data:{bind:'attr: { "data-something": someValue }'}}) } template.send(:evaluate, Object.new, {}).strip.should eq(%Q(
)) end it "allows nested quotes with ()" do template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div(ng-model-options='{updateOn: "blur"}')| } template.send(:evaluate, Object.new, {}).strip.should eq(%Q()) end it "allows nested quotes with {}" do Haml::Template.options[:attr_wrapper] = '"' template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div{"ng-model-options" => "{updateOn: 'blur'}"}| } template.send(:evaluate, Object.new, {}).strip.should eq(%Q()) end it "allows nested quote with {} ('\"\"')" do template = HamlAssets::HamlSprocketsEngine.new(path) { %Q|%div{"ng-model-options" => '{updateOn: "blur"}'}| } template.send(:evaluate, Object.new, {}).strip.should eq(%Q()) end end it "renders with a partial" do template = HamlAssets::HamlSprocketsEngine.new('app/assets/templates/with_partial.haml') { %Q(%div= render 'partial') } partial = stub(identifier: 'identifier', render: 'partial', formats: []) HamlAssets::HamlSprocketsEngine::LookupContext.any_instance.should_receive(:find_template).and_return(partial) context = Class.new do include HamlAssets::HamlSprocketsEngine::ViewContext end.new context.stub(environment_paths: []) template.send(:evaluate, context, {}).strip.should eq(%Q(