0
+require File.dirname(__FILE__) + '/spec_helper'
0
+include Merb::AssetsMixin
0
+describe "Accessing Assets" do
0
+ it "should create link to name with absolute url" do
0
+ link_to("The Merb home page", "http://www.merbivore.com/").should ==
0
+ "<a href=\"http://www.merbivore.com/\">The Merb home page</a>"
0
+ it "should create link to name with relative url" do
0
+ link_to("The Entry Title", "/blog/show/13").should ==
0
+ "<a href=\"/blog/show/13\">The Entry Title</a>"
0
+ it "should create link with attributes" do
0
+ link_to("The Ruby home page", "http://www.ruby-lang.org", {'class' => 'special', 'target' => 'blank'}).should ==
0
+ "<a class=\"special\" href=\"http://www.ruby-lang.org\" target=\"blank\">The Ruby home page</a>"
0
+ it "should create link with explicit href" do
0
+ link_to("The Foo home page", "http://not.foo.example.com/", :href => "http://foo.example.com").should ==
0
+ "<a href=\"http://foo.example.com\">The Foo home page</a>"
0
+ it "should create image tag with absolute url" do
0
+ image_tag('http://example.com/foo.gif').should ==
0
+ "<img src=\"http://example.com/foo.gif\" />"
0
+ it "should create image tag with relative url" do
0
+ image_tag('foo.gif').should ==
0
+ "<img src=\"/images/foo.gif\" />"
0
+ it "should create image tag with class" do
0
+ result = image_tag('foo.gif', :class => 'bar')
0
+ result.should match(%r{<img .*? />})
0
+ result.should match(%r{src="/images/foo.gif"})
0
+ result.should match(/class="bar"/)
0
+ it "should create image tag with specified path" do
0
+ image_tag('foo.gif', :path => '/files/').should ==
0
+ "<img src=\"/files/foo.gif\" />"
0
+ it "should create image tag without extension" do
0
+ image_tag('/dynamic/charts').should ==
0
+ "<img src=\"/dynamic/charts\" />"
0
+ it "should create image tag without extension and with specified path" do
0
+ image_tag('charts', :path => '/dynamic/').should ==
0
+ "<img src=\"/dynamic/charts\" />"
0
+describe "JavaScript related functions" do
0
+ it "should escape js having quotes" do
0
+ escape_js("'Lorem ipsum!' -- Some guy").should ==
0
+ "\\'Lorem ipsum!\\' -- Some guy"
0
+ it "should escape js having new lines" do
0
+ escape_js("Please keep text\nlines as skinny\nas possible.").should ==
0
+ "Please keep text\\nlines as skinny\\nas possible."
0
+ it "should create link to a function" do
0
+ link_to_function('Click me', "alert('hi!')").should ==
0
+ "<a href=\"#\" onclick=\"alert('hi!'); return false;\">Click me</a>"
0
+ it "should create a link to a function having multiple statements" do
0
+ link_to_function('Add to cart', "item_total += 1; alert('Item added!');").should ==
0
+ "<a href=\"#\" onclick=\"item_total += 1; alert('Item added!'); return false;\">Add to cart</a>"
0
+ it "should convert objects that respond to to_json to json" do
0
+ js({'user' => 'Lewis', 'page' => 'home'}).should ==
0
+ "{\"user\":\"Lewis\",\"page\":\"home\"}"
0
+ it "should convert objects using inspect that don't respond to_json to json" do
0
+ js([ 1, 2, {"a"=>3.141}, false, true, nil, 4..10 ]).should ==
0
+ "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
0
+describe "External JavaScript and Stylesheets" do
0
+ it "should require a js file only once" do
0
+ require_js 'jquery', 'effects'
0
+ include_required_js.scan(%r{/javascripts/jquery.js}).should have(1).things
0
+ include_required_js.scan(%r{/javascripts/effects.js}).should have(1).things
0
+ it "should require a css file only once" do
0
+ require_css('style', 'ie-specific')
0
+ include_required_css.scan(%r{/stylesheets/style.css}).should have(1).things
0
+ include_required_css.scan(%r{/stylesheets/ie-specific.css}).should have(1).things
0
+ it "should require included js" do
0
+ require_js 'jquery', 'effects', 'validation'
0
+ result = include_required_js
0
+ result.scan(/<script/).should have(3).things
0
+ result.should match(%r{/javascripts/jquery.js})
0
+ result.should match(%r{/javascripts/effects.js})
0
+ result.should match(%r{/javascripts/validation.js})
0
+ it "should require included css" do
0
+ require_css 'style', 'ie-specific'
0
+ result = include_required_css
0
+ result.scan(/<link/).should have(2).things
0
+ result.should match(%r{/stylesheets/style.css})
0
+ result.should match(%r{/stylesheets/ie-specific.css})
0
+ it "should create a js include tag with the extension specified" do
0
+ js_include_tag('jquery.js').should ==
0
+ "<script type=\"text/javascript\" src=\"/javascripts/jquery.js\"></script>"
0
+ it "should create a js include tag and and the extension" do
0
+ js_include_tag('jquery').should ==
0
+ "<script type=\"text/javascript\" src=\"/javascripts/jquery.js\"></script>"
0
+ it "should create a js include tag for multiple includes" do
0
+ result = js_include_tag('jquery.js', :effects)
0
+ result.scan(/<script/).should have(2).things
0
+ result.should match(%r{/javascripts/jquery.js})
0
+ result.should match(%r{/javascripts/effects.js})
0
+ it "should create a css include tag with the extension specified" do
0
+ result = css_include_tag('style.css')
0
+ result.should match(%r{<link (.*?) />})
0
+ result.should match(/charset="utf-8"/)
0
+ result.should match(%r{type="text/css"})
0
+ result.should match(%r{href="/stylesheets/style.css"})
0
+ result.should match(%r{rel="Stylesheet"})
0
+ result.should match(%r{media="all"})
0
+ it "should create a css include tag and add the extension" do
0
+ result = css_include_tag('style')
0
+ result.should match(%r{<link (.*?) />})
0
+ result.should match(/charset="utf-8"/)
0
+ result.should match(%r{type="text/css"})
0
+ result.should match(%r{href="/stylesheets/style.css"})
0
+ result.should match(%r{rel="Stylesheet"})
0
+ result.should match(%r{media="all"})
0
+ it "should create a css include tag for multiple includes" do
0
+ result = css_include_tag('style.css', :layout)
0
+ result.scan(/<link/).should have(2).things
0
+ result.should match(%r{/stylesheets/style.css})
0
+ result.should match(%r{/stylesheets/layout.css})
0
+ it "should create a css include tag with the specified media" do
0
+ css_include_tag('style', :media => :print).should match(%r{media="print"})
0
+ it "should create a css include tag with the specified charset" do
0
+ css_include_tag('style', :charset => 'iso-8859-1').should match(%r{charset="iso-8859-1"})
0
+ it "should return a uniq path for a single asset" do
0
+ uniq_path("/javascripts/my.js").should ==
0
+ "http://assets2.my-awesome-domain.com/javascripts/my.js"
0
+ it "should return a uniq path for multiple assets" do
0
+ uniq_path("/javascripts/my.js","/javascripts/my.css").should ==
0
+ ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets2.my-awesome-domain.com/javascripts/my.css"]
0
+ it "should return a uniq path for multiple assets passed as a single array" do
0
+ uniq_path(["/javascripts/my.js","/javascripts/my.css"]).should ==
0
+ ["http://assets2.my-awesome-domain.com/javascripts/my.js", "http://assets2.my-awesome-domain.com/javascripts/my.css"]
0
+ it "should return a uniq js path for a single js file" do
0
+ uniq_js_path("my").should ==
0
+ "http://assets2.my-awesome-domain.com/javascripts/my.js"
0
+ it "should return a uniq js path for multiple js files" do
0
+ uniq_js_path(["admin/secrets","home/signup"]).should ==
0
+ ["http://assets1.my-awesome-domain.com/javascripts/admin/secrets.js", "http://assets2.my-awesome-domain.com/javascripts/home/signup.js"]
0
+ it "should return a uniq css path for a single css file" do
0
+ uniq_css_path("my").should ==
0
+ "http://assets1.my-awesome-domain.com/stylesheets/my.css"
0
+ it "should return a uniq css path for multiple css files" do
0
+ uniq_css_path(["admin/secrets","home/signup"]).should ==
0
+ ["http://assets4.my-awesome-domain.com/stylesheets/admin/secrets.css", "http://assets1.my-awesome-domain.com/stylesheets/home/signup.css"]
0
+ it "should create a uniq js tag for a single js file" do
0
+ uniq_js_tag("my").should ==
0
+ "<script type=\"text/javascript\" src=\"http://assets2.my-awesome-domain.com/javascripts/my.js\"></script>"
0
+ it "should create a uniq js tag for each js file specified" do
0
+ result = uniq_js_tag("jquery.js", :effects)
0
+ result.scan(/<script/).should have(2).things
0
+ result.should match(%r{/javascripts/jquery.js})
0
+ result.should match(%r{/javascripts/effects.js})
0
+ it "should create a uniq css tag for a single css file" do
0
+ result = uniq_css_tag("my")
0
+ result.should match(%r{<link (.*?) />})
0
+ result.should match(/charset="utf-8"/)
0
+ result.should match(%r{type="text/css"})
0
+ result.should match(%r{http://assets1.my-awesome-domain.com/stylesheets/my.css})
0
+ result.should match(%r{rel="Stylesheet"})
0
+ result.should match(%r{media="all"})
0
+ it "should create a uniq css tag for each css file specified" do
0
+ result = uniq_css_tag("style.css", :layout)
0
+ result.scan(/<link/).should have(2).things
0
+ result.should match(%r{/stylesheets/style.css})
0
+ result.should match(%r{/stylesheets/layout.css})
Comments
No one has commented yet.