Sha256: c698c1ca6defbd2ab41c294279152b79c79020a003588ab3df128004e488261a

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Roadie
  describe StyleAttributeBuilder do
    it "sorts the added properties" do
      builder = StyleAttributeBuilder.new

      builder << StyleProperty.new("color", "green", true, 1)
      builder << StyleProperty.new("font-size", "110%", false, 15)
      builder << StyleProperty.new("color", "red", false, 15)

      expect(builder.attribute_string).to eq "font-size:110%;color:red;color:green !important"
    end

    it "preserves the order of added attributes with the same specificity" do
      builder = StyleAttributeBuilder.new

      builder << StyleProperty.new("color", "pink", false, 50)
      builder << StyleProperty.new("color", "red", false, 50)
      builder << StyleProperty.new("color", "green", false, 50)

      # We need one different element to trigger the problem with Ruby's
      # unstable sort
      builder << StyleProperty.new("background", "white", false, 1)

      expect(builder.attribute_string).to eq "background:white;color:pink;color:red;color:green"
    end

    it "removes duplicate properties" do
      builder = StyleAttributeBuilder.new

      builder << StyleProperty.new("color", "pink", false, 10)
      builder << StyleProperty.new("color", "green", false, 20)
      builder << StyleProperty.new("color", "pink", false, 50)

      expect(builder.attribute_string).to eq "color:green;color:pink"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
roadie-5.2.1 spec/lib/roadie/style_attribute_builder_spec.rb
roadie-5.2.0 spec/lib/roadie/style_attribute_builder_spec.rb
roadie-5.1.0 spec/lib/roadie/style_attribute_builder_spec.rb
roadie-5.0.1 spec/lib/roadie/style_attribute_builder_spec.rb
roadie-5.0.0 spec/lib/roadie/style_attribute_builder_spec.rb