Sha256: 0ebb3d848de39ed84eede976241d12fa5f2e475516ff4b3155ec3d8f3220124d

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "../../../spec_helper"))
describe WebResourceBundler::Filters::BundleFilter::Filter do
  before(:each) do
    clean_cache_dir
    @settings = settings
    @bundle_settings = bundle_settings
    @filter = Filters::BundleFilter::Filter.new(@bundle_settings, FileManager.new(@settings[:resource_dir], @settings[:cache_dir]))
    @block_data = @sample_block_helper.sample_block_data
    css_type = ResourceFileType::CSS
    js_type = ResourceFileType::JS
    items = [@block_data.styles.map {|f| f.path}.sort] + @bundle_settings[:md5_additional_data]
    @css_md5_value = Digest::MD5.hexdigest(items.flatten.join('|'))
    @css_bundle_file = File.join(@settings[:cache_dir], [css_type[:name] + '_' + @css_md5_value, 'en', css_type[:ext]].join('.'))
    items = [@block_data.scripts.map {|f| f.path}.sort]  + @bundle_settings[:md5_additional_data]
    js_md5_value = Digest::MD5.hexdigest(items.flatten.join('|'))
    @js_bundle_file = File.join(@settings[:cache_dir], [js_type[:name] + '_' + js_md5_value, 'en', js_type[:ext]].join('.'))
  end

  describe "#apply" do
    it "bundles each block_data resources in single file" do
      @filter.apply!(@block_data)
      @block_data.styles.first.path.should == @css_bundle_file
      @block_data.scripts.first.path.should == @js_bundle_file
    end
  end

  describe "#get_md5" do
    it "returns md5 from sorted filepaths and another additional data" do
      @filter.get_md5(@block_data.styles).should == @css_md5_value
    end
  end

  describe "#bundle_filepath" do
    it "returns filename of bundle constructed from passed files" do
      @filter.bundle_filepath(WebResourceBundler::ResourceFileType::CSS, @block_data.styles).should == @css_bundle_file 
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
web_resource_bundler-0.0.14 spec/web_resource_bundler/filters/bundle_filter/filter_spec.rb