Sha256: 097db4c61dc1785e201d1f237cd14c2f1e014d0104539b2e43d91d2302f58527

Contents?: true

Size: 1.55 KB

Versions: 11

Compression:

Stored size: 1.55 KB

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'

require 'tdiary/compatible'
require 'fileutils'

describe PStore, "auto convert library" do
	before do
		# rake specで動かすと、comppatible.rb が既に読み込まれてしまっているため、
		# このPStoreがASCII-8BITではなくUTF-8になってしまう。
		# そのため、下記と同様の ascii8bit-pstore.db をテストフィクスチャとしている。
		# PStore.new(@dbfile).transaction do |db|
		# 	db["key1".to_8bit] = "val1".to_8bit
		# 	db["key2".to_8bit] = 2
		# 	db["key3".to_8bit] = [1, :sym, "string".to_8bit]
		# end
		dbfilename = '../fixtures/ascii8bit-pstore.db'
		dbfile_orig = File.join(File.dirname(__FILE__), dbfilename)
		@dbfile = File.join(File.dirname(__FILE__), "#{dbfilename}.work")
		FileUtils.cp dbfile_orig, @dbfile
	end

	after do
		FileUtils.rm @dbfile
	end

	it "should convert an encoding to UTF-8 automatically" do
		PStore.new(@dbfile).transaction do |db|
			db["key1"].encoding.should == Encoding::UTF_8
			db["key2"].should  == 2
			db["key3"][2].encoding.should  == Encoding::UTF_8
		end
	end

	it "1回目のtransactionではMashal.loadが3回呼ばれる" do
		Marshal.should_receive(:load).exactly(3).and_return({})
		PStore.new(@dbfile).transaction {}
	end

	it "2回目のtransactionではMashal.loadが1回だけ呼ばれる" do
		Marshal.should_receive(:load).exactly(4).and_return({})
		PStore.new(@dbfile).transaction {}
		PStore.new(@dbfile).transaction {}
	end
end

# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tdiary-4.0.2.20140201 spec/core/compatible_spec.rb
tdiary-4.0.2 spec/core/compatible_spec.rb
tdiary-4.0.1.20131102 spec/core/compatible_spec.rb
tdiary-4.0.1.20130929 spec/core/compatible_spec.rb
tdiary-4.0.1.20130903 spec/core/compatible_spec.rb
tdiary-4.0.1 spec/core/compatible_spec.rb
tdiary-4.0.0.20130826 spec/core/compatible_spec.rb
tdiary-4.0.0 spec/core/compatible_spec.rb
tdiary-3.2.2.20130727 spec/core/compatible_spec.rb
tdiary-3.2.2.20130722 spec/core/compatible_spec.rb
tdiary-3.2.2.20130720 spec/core/compatible_spec.rb