Sha256: d2d89b6569e6b4b8250971624081c11bd61b8ad0692ba2b5fa450f2e2f6d0ca4

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helper'

describe Arbre::HTML::Tag, "Attributes" do
  include Arbre::HTML
  let(:assigns){ {} }

  let(:tag){ Arbre::HTML::Tag.new }

  describe "attributes" do
    before { tag.build :id => "my_id" }

    it "should have an attributes hash" do
      tag.attributes.should == {:id => "my_id"}
    end

    it "should render the attributes to html" do
      tag.to_html.should == <<-HTML
<tag id="my_id"></tag>
HTML
    end

    it "should get an attribute value" do
      tag.attr(:id).should == "my_id"
    end

    describe "#has_attribute?" do
      context "when the attribute exists" do
        it "should return true" do
          tag.has_attribute?(:id).should == true
        end
      end

      context "when the attribute does not exist" do
        it "should return false" do
          tag.has_attribute?(:class).should == false
        end
      end
    end

    it "should remove an attribute" do
      tag.attributes.should == {:id => "my_id"}
      tag.remove_attribute(:id).should == "my_id"
      tag.attributes.should == {}
    end
  end

  describe "rendering attributes" do
    it "should html safe the attribute values" do
      tag.set_attribute(:class, "\">bad things!")
      tag.to_html.should == <<-HTML
<tag class="&quot;&gt;bad things!"></tag>
HTML
    end
    it "should should escape the attribute names" do
      tag.set_attribute(">bad", "things")
      tag.to_html.should == <<-HTML
<tag &gt;bad="things"></tag>
HTML
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
nsm-activeadmin-0.2.2 spec/unit/arbre/html/tag_attributes_spec.rb
saulolso-activeadmin-0.2.2.1 spec/unit/arbre/html/tag_attributes_spec.rb
saulolso-activeadmin-0.2.2 spec/unit/arbre/html/tag_attributes_spec.rb
activeadmin-0.2.2 spec/unit/arbre/html/tag_attributes_spec.rb
activeadmin-0.2.1 spec/unit/arbre/html/tag_attributes_spec.rb
activeadmin-0.2.0 spec/unit/arbre/html/tag_attributes_spec.rb