Sha256: 776364e22e0ebda3f3ee7e93c4c33cc058680d9ae1549fa9604d69d6b3e68780

Contents?: true

Size: 1.58 KB

Versions: 17

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

describe ContentfulMiddleman::VersionHash do
  let(:path) { File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures', 'space_hash_fixtures')) }
  describe 'class methods' do
    it '::source_root=' do
      described_class.source_root = 'foobar'
      expect(described_class.instance_variable_get(:@source_root)).to eq('foobar')
    end

    describe '::read_for_space' do
      before do
        described_class.source_root = path
      end

      it 'unhashed space returns nil' do
        expect(described_class.read_for_space('i_dont_exist')).to eq(nil)
      end

      it 'hashed space returns hash' do
        expect(described_class.read_for_space('foo').chomp).to eq('bar')
      end
    end

    describe '::write_for_space_with_entries' do
      let(:entries) { [EntryDouble.new(1, {}, {}, '2015-11-25'), EntryDouble.new(2, {}, {}, '2015-11-25')] }

      before do
        described_class.source_root = path
      end

      it 'hashes entries and saves them on a file' do
        allow(::File).to receive(:open).with(File.join(path, '.my_space-space-hash'), 'w')
        expect(Digest::SHA1).to receive(:hexdigest)

        described_class.write_for_space_with_entries('my_space', entries)
      end

      it 'matches hash on next read' do
        sorted_entries = entries.sort { |a, b| a.id <=> b.id }
        hash = Digest::SHA1.hexdigest(sorted_entries.map { |e| "#{e.id}#{e.updated_at}" }.join)

        described_class.write_for_space_with_entries('my_space', entries)

        expect(described_class.read_for_space('my_space')).to eq(hash)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
contentful_middleman-4.2.0 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-4.1.0 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-3.0.1 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-4.0.1 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-4.0.0 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-3.0.0 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-2.1.3 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-2.1.2 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-2.1.1 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-2.1.0 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-2.0.1 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-2.0.0 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-1.5.0 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-1.4.2 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-1.4.1 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-1.4.0 spec/contentful_middleman/version_hash_spec.rb
contentful_middleman-1.3.2 spec/contentful_middleman/version_hash_spec.rb