Skip to content

Commit

Permalink
Find a initial binding for each session
Browse files Browse the repository at this point in the history
  • Loading branch information
sh19910711 committed May 26, 2016
1 parent ec8d5c5 commit e8f0f7b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/web_console/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def from(storage)
def initialize(bindings)
@id = SecureRandom.hex(16)
@bindings = Array(bindings)
@evaluator = Evaluator.new(@bindings[0])
@evaluator = Evaluator.new(initial_binding)

store_into_memory
end
Expand All @@ -64,6 +64,10 @@ def switch_binding_to(index)

private

def initial_binding
@bindings.find { |b| b.eval('__FILE__').to_s.start_with?(Rails.root.to_s) }
end

def store_into_memory
inmemory_storage[id] = self
end
Expand Down
1 change: 1 addition & 0 deletions test/web_console/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def body
end

setup do
Rails.stubs(:root).returns Pathname(__FILE__).parent
Request.stubs(:whitelisted_ips).returns(IPAddr.new('0.0.0.0/0'))

Middleware.mount_point = ''
Expand Down
3 changes: 2 additions & 1 deletion test/web_console/session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ def initialize(line)
end

setup do
Rails.stubs(:root).returns Pathname(__FILE__).parent
Session.inmemory_storage.clear
@session = Session.new TOPLEVEL_BINDING
@session = Session.new(binding)
end

test 'returns nil when a session is not found' do
Expand Down

0 comments on commit e8f0f7b

Please sign in to comment.