Sha256: 0d6905986d72b0e94d1145ad64a397e01a93715ceeb94a4435125aa491af39f3

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

describe Arbre::HTML::Tag, "Attributes" do

  setup_arbre_context!

  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_s.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_s.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_s.should == <<-HTML
<tag &gt;bad="things"></tag>
HTML
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
activeadmin-0.4.4 spec/unit/arbre/html/tag_attributes_spec.rb
activeadmin-0.4.3 spec/unit/arbre/html/tag_attributes_spec.rb
activeadmin-0.4.2 spec/unit/arbre/html/tag_attributes_spec.rb
activeadmin-0.4.1 spec/unit/arbre/html/tag_attributes_spec.rb
activeadmin-0.4.0 spec/unit/arbre/html/tag_attributes_spec.rb
andrewroth_activeadmin-0.3.4.4 spec/unit/arbre/html/tag_attributes_spec.rb