php_session 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f64dc34ff5c36c8bce6e5a9b402eb25f01285cbd
4
- data.tar.gz: ac9b9f04c37483983660f4ac73a8a62eb93ac9a3
3
+ metadata.gz: 91b55063968fec647a72fe0aa42537907c1a3d79
4
+ data.tar.gz: 05aa36fdc96ad702c03316ae749de25b2c088eba
5
5
  SHA512:
6
- metadata.gz: 38e564743257d37ada276eca63b3648269d06e58ff9bb4805ff6085bcac48f76f44b9318144b379ba1aaf1c71aabf308de25feb2e5b63a6e77ebd9285384d4d7
7
- data.tar.gz: 258ff69f3b9db0f348d126827a5f746a1a4f947d05ab9f342eb23773393b62f5e684278dc0e96dec9785ba170c96c4e684c6dab28879ddb34791f66e5e360401
6
+ metadata.gz: fe4b25bbf30ece559c174961af6f18d0ee6cfbcf88d8f807dab3bca0a047663f4dfe86ace91cd1b7bf54f435ee2edf63af370ce8911844fbf584fbd2b4b44006
7
+ data.tar.gz: f6121e69661e82a29dba92db0319c4bc892211cfbd60a7683f065523c7c921589c766f30368cbee0e4816425961e2e6f544d405d02cc2f3d5697f0da381dff21
data/lib/php_session.rb CHANGED
@@ -33,6 +33,10 @@ class PHPSession
33
33
  data
34
34
  end
35
35
 
36
+ def loaded?
37
+ ! @file.nil?
38
+ end
39
+
36
40
  def destroy
37
41
  if @file && ! @file.closed?
38
42
  @file.truncate(0)
@@ -44,6 +48,7 @@ class PHPSession
44
48
  end
45
49
 
46
50
  def commit(data)
51
+ self.load(@session_id) unless @file
47
52
  @file.truncate(0)
48
53
  @file.write(Encoder.encode(data, @option[:external_encoding], @option[:encoding_option]))
49
54
  ensure_file_closed
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  class PHPSession
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.2"
4
4
  end
@@ -2,8 +2,29 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe PHPSession do
5
+ describe "loaded?" do
6
+ before do
7
+ @session_file = create_dummy_session_file('key|s:1:"a";')
8
+ end
9
+
10
+ it "should return true when file is loaded" do
11
+ session = PHPSession.new(@session_file[:dir_name])
12
+ session.load(@session_file[:session_id])
13
+ expect(session.loaded?).to be_true
14
+ end
15
+
16
+ it "should return false when file is loaded" do
17
+ session = PHPSession.new(@session_file[:dir_name])
18
+ expect(session.loaded?).to be_false
19
+ end
20
+
21
+ after do
22
+ File.delete(@session_file[:file_path])
23
+ end
24
+ end
25
+
5
26
  describe "load" do
6
- context "when session file encoding is utf8" do
27
+ context "when session file encoding is utf8" do
7
28
  before do
8
29
  @session_file = create_dummy_session_file('key|s:13:"テスト🍺";')
9
30
  end
@@ -49,6 +70,7 @@ describe PHPSession do
49
70
  session.ensure_file_closed
50
71
  end
51
72
  end
73
+
52
74
  after do
53
75
  File.delete(@session_file[:file_path])
54
76
  end
@@ -107,6 +129,13 @@ describe PHPSession do
107
129
  expect(byte_sequence.force_encoding('EUC-JP')).to eq('key|s:7:"テスト?";'.encode("EUC-JP"))
108
130
  end
109
131
 
132
+ it "should save session data even if session_file is not loaded" do
133
+ session = PHPSession.new(@session_file[:dir_name])
134
+ expect {
135
+ session.commit({:hoge => "nyan"})
136
+ }.not_to raise_error
137
+ end
138
+
110
139
  after do
111
140
  File.delete(@session_file[:file_path])
112
141
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: php_session
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinpei Maruyama