Sha256: 11ecad15d1817cb4161b1d94e2653cc8ba28b265a3b19995745ef72bb12b0e84

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

describe "Tag Tinter" do

  before(:each) do
    Post.delete_all
    ActsAsTaggableOn::Tag.delete_all
    ActsAsTaggableOn::Tagging.delete_all
  end

  context "calculate hex color to represent tag use as percentage of total taggings" do

    it "should give mix 25% white into black with four tags" do
      tags = ['red', 'yellow', 'green', 'blue']
      tags.each do |tag|
        Post.create(title: 'title', tag_list: tag)
      end
      TintedTags::TagTinter.new(Post, base: 'black', tint: 'white').update_tints
      ActsAsTaggableOn::Tag.first.tint.should eq '#bfbfbf'
    end

    it "should give mix 20% white into black with five tags" do
      tags = ['red', 'yellow', 'green', 'blue', 'orange']
      tags.each do |tag|
        Post.create(title: 'title', tag_list: tag)
      end
      TintedTags::TagTinter.new(Post, base: 'black', tint: 'white').update_tints
      ActsAsTaggableOn::Tag.first.tint.should eq '#cccccc'
    end
  end

  context "calculate percentage value from position within range" do
    it "should calculate hex color percentage as position within min-max tag usage range" do
      10.times { Post.create(title: 'title', tag_list: 'max') }
      5.times { Post.create(title: 'title', tag_list: 'median') }
      1.times { Post.create(title: 'title', tag_list: 'min') }
      TintedTags::TagTinter.new(Post, base:'black', tint:'white', strategy: :rated_as_range).update_tints
      # 'median' tag should be 44% (1 being 0%, 10 being 100%)
      t = ActsAsTaggableOn::Tag.where(name: 'median').first
      t.tint.should eq '#8e8e8e'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tinted_tags-0.0.2 spec/tinted_tags/tag_tinter_spec.rb