Sha256: 90e56425af82d3938086360e814b695846fb86844fb53db2508815c644cfc6b4
Contents?: true
Size: 1.67 KB
Versions: 8
Compression:
Stored size: 1.67 KB
Contents
require 'spec_helper' require 'template' describe Template::OutputBuffer do describe "#attributes" do it "compiles an empty attribute set as ''" do attributes({}).should == "" end it "can compile simple attributes" do result = attributes(name: 'foo', height: '100') expect(result).to include("name='foo'", "height='100'") end it "can compile nested attributes" do result = attributes(data: { foo: { bar: 'baz' }, another: 'one' }) expect(result).to include("data-foo-bar='baz'") expect(result).to include("data-another='one'") end it "combines input hashes" do result = subject.attributes({ 'class' => 'foo' }, nil, { class: 'bar', data: 'baz' }) expect(result).to include("class='foo bar'") expect(result).to include("data='baz'") end it "removes nil from arrays" do result = attributes(foo: [ 'bar', nil, 'baz' ]) expect(result).to include("foo='bar baz'") end it "escapes attribute values" do result = attributes(foo: 'a<>&"\'b') expect(result).to include("foo='a<>&"'b'") end it "skips the attribute for false values" do result = attributes(name: false) expect(result).to_not include('name') end it "skips the attribute for nil values" do result = attributes(name: nil) expect(result).to_not include('name') end it "generates a simple named attribute for true values" do result = attributes(closable: true) expect(result).to include('closable') expect(result).to_not include('closable=') end def attributes(attrs) subject.attributes({}, nil, attrs) end end end
Version data entries
8 entries across 8 versions & 1 rubygems