File: app_sessions.rb

package info (click to toggle)
camping 3.2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,312 kB
  • sloc: ruby: 5,032; javascript: 2,362; makefile: 29
file content (64 lines) | stat: -rw-r--r-- 1,254 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'test_helper'
require 'camping'
require 'camping/session'

Camping.goes :Sessions

module Sessions
  include Camping::Session
end

module Sessions::Controllers
  class One
    def get
      @state.clear
      @state.one = 42
      redirect R(Two)
    end
  end

  class Two
    def get
      @state.two = 56
      redirect R(Three)
    end
  end

  class Three
    def get
      @state.three = 99
      @state.values_at("one", "two", "three").inspect
    end
  end
end

class Sessions::Test < TestCase
  def test_session
    get '/one'
    follow_redirect!
    follow_redirect!
    assert_body "[42, 56, 99]"
  end

  def test_secret_length
    app.set :secret, "whateverloser"
    begin
      app.include Camping::Session
    rescue InsecureSecretError => e
      message = "Your Session Secret is too short. Minimum length is 64."
      assert_equal(e.message, message, "You're session secret wasn't long enough.")
    end

    e = "empty"
    message = "empty"
    begin
      app.set :secret, "whateverloserwhateverloserwhateverloserwhateverloserwhateverloser"
      app.include Camping::Session
    rescue InsecureSecretError => e
      message = e
    end

    assert_equal(e, message, "Your session secret wasn't long enough.")
  end
end