require File.dirname(__FILE__) + '/spec_helper' include Merb::AssetsMixin describe "Accessing Assets" do it "should create link to name with absolute url" do link_to("The Merb home page", "http://www.merbivore.com/").should == "The Merb home page" end it "should create link to name with relative url" do link_to("The Entry Title", "/blog/show/13").should == "The Entry Title" end it "should create link with attributes" do link_to("The Ruby home page", "http://www.ruby-lang.org", {'class' => 'special', 'target' => 'blank'}).should match(%r{class="special"}) link_to("The Ruby home page", "http://www.ruby-lang.org", {'class' => 'special', 'target' => 'blank'}).should match(%r{target="blank"}) end it "should create link with explicit href" do link_to("The Foo home page", "http://not.foo.example.com/", :href => "http://foo.example.com").should == "The Foo home page" end it "should create image tag with absolute url" do image_tag('http://example.com/foo.gif').should == "" end it "should create image tag with relative url" do image_tag('foo.gif').should == "" end it "should create image tag with class" do result = image_tag('foo.gif', :class => 'bar') result.should match(%r{}) result.should match(%r{src="/images/foo.gif"}) result.should match(/class="bar"/) end it "should create image tag with specified path" do image_tag('foo.gif', :path => '/files/').should == "" end it "should create image tag without extension" do image_tag('/dynamic/charts').should == "" end it "should create image tag without extension and with specified path" do image_tag('charts', :path => '/dynamic/').should == "" end it "should create image tag with a random query string" do result = image_tag('foo.gif', :reload => true) result.should match(%r{}) end end describe "JavaScript related functions" do it "should escape js having quotes" do escape_js("'Lorem ipsum!' -- Some guy").should == "\\'Lorem ipsum!\\' -- Some guy" end it "should escape js having new lines" do escape_js("Please keep text\nlines as skinny\nas possible.").should == "Please keep text\\nlines as skinny\\nas possible." end it "should convert objects that respond to to_json to json" do js({'user' => 'Lewis', 'page' => 'home'}).should == "{\"user\":\"Lewis\",\"page\":\"home\"}" end it "should convert objects using inspect that don't respond to_json to json" do js([ 1, 2, {"a"=>3.141}, false, true, nil, 4..10 ]).should == "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]" end end describe "External JavaScript and Stylesheets" do it "should require a js file only once" do require_js :jquery require_js :jquery, :effects include_required_js.scan(%r{src="/javascripts/jquery.js"}).should have(1).things include_required_js.scan(%r{src="/javascripts/effects.js"}).should have(1).things end it "should require a css file only once" do require_css :style require_css :style, 'ie-specific' include_required_css.scan(%r{href="/stylesheets/style.css"}).should have(1).things include_required_css.scan(%r{href="/stylesheets/ie-specific.css"}).should have(1).things end it "should require included js" do require_js 'jquery', 'effects', 'validation' result = include_required_js result.scan(/" end it "should create a js include tag and and the extension" do js_include_tag('jquery').should == "" end it "should create a js include tag for multiple includes" do result = js_include_tag('jquery.js', :effects) result.scan(/" end it "should create a uniq js tag for each js file specified" do result = uniq_js_tag("jquery.js", :effects) result.scan(/