From 2890b1fbcb8505ef35832f588318c1bd945e4b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cain=C3=A3=20Costa?= Date: Sun, 18 Oct 2015 22:01:58 -0200 Subject: [PATCH 1/2] Sets env for session before calling action --- lib/lotus/action/session.rb | 1 + test/session_test.rb | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/lotus/action/session.rb b/lib/lotus/action/session.rb index e9f6607c..5ee97706 100644 --- a/lib/lotus/action/session.rb +++ b/lib/lotus/action/session.rb @@ -60,6 +60,7 @@ def self.included(action) # end # end def session + @_env ||= {} @_env[SESSION_KEY] ||= {} end diff --git a/test/session_test.rb b/test/session_test.rb index e3de543f..6aa23c08 100644 --- a/test/session_test.rb +++ b/test/session_test.rb @@ -20,7 +20,12 @@ action = SessionAction.new action.call({'rack.session' => session = { 'foo' => 'bar' }}) - action.exposures[:session].must_equal(session) + action.__send__(:session).must_equal(session) + end + + it 'has a default of Hash' do + action = SessionAction.new + action.__send__(:session).must_equal({}) end end end From cee51070f9a482de5d3fa5ff7e8a30396c812700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cain=C3=A3=20Costa?= Date: Sun, 18 Oct 2015 22:09:51 -0200 Subject: [PATCH 2/2] Changes #session to be public --- lib/lotus/action/session.rb | 2 -- test/fixtures.rb | 3 ++- test/session_test.rb | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/lotus/action/session.rb b/lib/lotus/action/session.rb index 5ee97706..7123d8ab 100644 --- a/lib/lotus/action/session.rb +++ b/lib/lotus/action/session.rb @@ -30,8 +30,6 @@ def self.included(action) end end - protected - # Gets the session from the request and expose it as an Hash. # # @return [Hash] the HTTP session from the request diff --git a/test/fixtures.rb b/test/fixtures.rb index 453a1812..4f636a64 100644 --- a/test/fixtures.rb +++ b/test/fixtures.rb @@ -962,6 +962,8 @@ def call(params) self.headers.merge!('X-Custom' => 'OK') headers.merge!('Y-Custom' => 'YO') + self.session[:foo] = 'bar' + # PRIVATE # self.configuration # self.finish @@ -969,7 +971,6 @@ def call(params) # PROTECTED self.response self.cookies - self.session response cookies diff --git a/test/session_test.rb b/test/session_test.rb index 6aa23c08..9cc4e953 100644 --- a/test/session_test.rb +++ b/test/session_test.rb @@ -6,26 +6,26 @@ action = SessionAction.new action.call({'rack.session' => session = { 'user_id' => '23' }}) - action.__send__(:session).must_equal(session) + action.session.must_equal(session) end it 'returns empty hash when it is missing' do action = SessionAction.new action.call({}) - action.__send__(:session).must_equal({}) + action.session.must_equal({}) end it 'exposes session' do action = SessionAction.new action.call({'rack.session' => session = { 'foo' => 'bar' }}) - action.__send__(:session).must_equal(session) + action.session.must_equal(session) end it 'has a default of Hash' do action = SessionAction.new - action.__send__(:session).must_equal({}) + action.session.must_equal({}) end end end