auto-session-timeout 0.9.4 → 0.9.5
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 +4 -4
 - data/lib/auto/session/timeout/version.rb +1 -1
 - data/lib/auto_session_timeout.rb +1 -0
 - data/lib/auto_session_timeout_helper.rb +16 -23
 - data/test/auto_session_timeout_helper_test.rb +19 -23
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3561cc313c2dc97c96fb2a2a5931c01c8a442706
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: d5c805a2efeb3af57dad7d2b23aa4aa55b1df902
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 3dff428123f23f12a7cd5f9cba6a25a8d8576db3519ab01c1a70586e6ec84cf52377910207339adcc4a0360106bdd69b35dcb8bad73f68b452d005223ac0452f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 022ed3b160ee413a4e703bd097acdec9b865994c2d42cf57276b1087591e220f2859b69edae1c293815741ea6daa01b4bc69a4c11fdf920dba5e9ad76cbb8ba0
         
     | 
    
        data/lib/auto_session_timeout.rb
    CHANGED
    
    | 
         @@ -6,6 +6,7 @@ module AutoSessionTimeout 
     | 
|
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
              module ClassMethods
         
     | 
| 
       8 
8 
     | 
    
         
             
                def auto_session_timeout(seconds=nil)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  protect_from_forgery except: [:active, :timeout]
         
     | 
| 
       9 
10 
     | 
    
         
             
                  prepend_before_action do |c|
         
     | 
| 
       10 
11 
     | 
    
         
             
                    if c.session[:auto_session_expires_at] && c.session[:auto_session_expires_at] < Time.now
         
     | 
| 
       11 
12 
     | 
    
         
             
                      c.send :reset_session
         
     | 
| 
         @@ -2,33 +2,26 @@ module AutoSessionTimeoutHelper 
     | 
|
| 
       2 
2 
     | 
    
         
             
              def auto_session_timeout_js(options={})
         
     | 
| 
       3 
3 
     | 
    
         
             
                frequency = options[:frequency] || 60
         
     | 
| 
       4 
4 
     | 
    
         
             
                verbosity = options[:verbosity] || 2
         
     | 
| 
      
 5 
     | 
    
         
            +
                attributes = options[:attributes] || {}
         
     | 
| 
       5 
6 
     | 
    
         
             
                code = <<JS
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
               
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                $.ajax({
         
     | 
| 
       13 
     | 
    
         
            -
                  url: '/active',
         
     | 
| 
       14 
     | 
    
         
            -
                  success: function(data) {
         
     | 
| 
       15 
     | 
    
         
            -
                    if(data == 'false'){
         
     | 
| 
       16 
     | 
    
         
            -
                      window.location.href = '/timeout';
         
     | 
| 
       17 
     | 
    
         
            -
                    }
         
     | 
| 
       18 
     | 
    
         
            -
                  }
         
     | 
| 
       19 
     | 
    
         
            -
                });
         
     | 
| 
       20 
     | 
    
         
            -
                setTimeout(PeriodicalQuery, (#{frequency} * 1000));
         
     | 
| 
       21 
     | 
    
         
            -
              }
         
     | 
| 
       22 
     | 
    
         
            -
              setTimeout(PeriodicalQuery, (#{frequency} * 1000));
         
     | 
| 
       23 
     | 
    
         
            -
            } else {
         
     | 
| 
       24 
     | 
    
         
            -
              $.PeriodicalUpdater('/active', {minTimeout:#{frequency * 1000}, multiplier:0, method:'get', verbose:#{verbosity}}, function(remoteData, success) {
         
     | 
| 
       25 
     | 
    
         
            -
                if (success == 'success' && remoteData == 'false')
         
     | 
| 
      
 7 
     | 
    
         
            +
            function PeriodicalQuery() {
         
     | 
| 
      
 8 
     | 
    
         
            +
              var request = new XMLHttpRequest();
         
     | 
| 
      
 9 
     | 
    
         
            +
              request.onload = function (event) {
         
     | 
| 
      
 10 
     | 
    
         
            +
                var status = event.target.status;
         
     | 
| 
      
 11 
     | 
    
         
            +
                var response = event.target.response;
         
     | 
| 
      
 12 
     | 
    
         
            +
                if (status === 200 && (response === false || response === 'false')) {
         
     | 
| 
       26 
13 
     | 
    
         
             
                  window.location.href = '/timeout';
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                }
         
     | 
| 
      
 15 
     | 
    
         
            +
              };
         
     | 
| 
      
 16 
     | 
    
         
            +
              request.open('GET', '/active', true);
         
     | 
| 
      
 17 
     | 
    
         
            +
              request.responseType = 'json';
         
     | 
| 
      
 18 
     | 
    
         
            +
              request.send();
         
     | 
| 
      
 19 
     | 
    
         
            +
              setTimeout(PeriodicalQuery, (#{frequency} * 1000));
         
     | 
| 
       28 
20 
     | 
    
         
             
            }
         
     | 
| 
      
 21 
     | 
    
         
            +
            setTimeout(PeriodicalQuery, (#{frequency} * 1000));
         
     | 
| 
       29 
22 
     | 
    
         
             
            JS
         
     | 
| 
       30 
     | 
    
         
            -
                javascript_tag(code)
         
     | 
| 
      
 23 
     | 
    
         
            +
                javascript_tag(code, attributes)
         
     | 
| 
       31 
24 
     | 
    
         
             
              end
         
     | 
| 
       32 
25 
     | 
    
         
             
            end
         
     | 
| 
       33 
26 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
            ActionView::Base.send :include, AutoSessionTimeoutHelper
         
     | 
| 
      
 27 
     | 
    
         
            +
            ActionView::Base.send :include, AutoSessionTimeoutHelper
         
     | 
| 
         @@ -8,40 +8,36 @@ describe AutoSessionTimeoutHelper do 
     | 
|
| 
       8 
8 
     | 
    
         
             
                it "returns correct JS" do
         
     | 
| 
       9 
9 
     | 
    
         
             
                  assert_equal "<script type=\"text/javascript\">
         
     | 
| 
       10 
10 
     | 
    
         
             
            //<![CDATA[
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
               
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                $.ajax({
         
     | 
| 
       18 
     | 
    
         
            -
                  url: '/active',
         
     | 
| 
       19 
     | 
    
         
            -
                  success: function(data) {
         
     | 
| 
       20 
     | 
    
         
            -
                    if(data == 'false'){
         
     | 
| 
       21 
     | 
    
         
            -
                      window.location.href = '/timeout';
         
     | 
| 
       22 
     | 
    
         
            -
                    }
         
     | 
| 
       23 
     | 
    
         
            -
                  }
         
     | 
| 
       24 
     | 
    
         
            -
                });
         
     | 
| 
       25 
     | 
    
         
            -
                setTimeout(PeriodicalQuery, (60 * 1000));
         
     | 
| 
       26 
     | 
    
         
            -
              }
         
     | 
| 
       27 
     | 
    
         
            -
              setTimeout(PeriodicalQuery, (60 * 1000));
         
     | 
| 
       28 
     | 
    
         
            -
            } else {
         
     | 
| 
       29 
     | 
    
         
            -
              $.PeriodicalUpdater('/active', {minTimeout:60000, multiplier:0, method:'get', verbose:2}, function(remoteData, success) {
         
     | 
| 
       30 
     | 
    
         
            -
                if (success == 'success' && remoteData == 'false')
         
     | 
| 
      
 11 
     | 
    
         
            +
            function PeriodicalQuery() {
         
     | 
| 
      
 12 
     | 
    
         
            +
              var request = new XMLHttpRequest();
         
     | 
| 
      
 13 
     | 
    
         
            +
              request.onload = function (event) {
         
     | 
| 
      
 14 
     | 
    
         
            +
                var status = event.target.status;
         
     | 
| 
      
 15 
     | 
    
         
            +
                var response = event.target.response;
         
     | 
| 
      
 16 
     | 
    
         
            +
                if (status === 200 && (response === false || response === 'false')) {
         
     | 
| 
       31 
17 
     | 
    
         
             
                  window.location.href = '/timeout';
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
                }
         
     | 
| 
      
 19 
     | 
    
         
            +
              };
         
     | 
| 
      
 20 
     | 
    
         
            +
              request.open('GET', '/active', true);
         
     | 
| 
      
 21 
     | 
    
         
            +
              request.responseType = 'json';
         
     | 
| 
      
 22 
     | 
    
         
            +
              request.send();
         
     | 
| 
      
 23 
     | 
    
         
            +
              setTimeout(PeriodicalQuery, (60 * 1000));
         
     | 
| 
       33 
24 
     | 
    
         
             
            }
         
     | 
| 
      
 25 
     | 
    
         
            +
            setTimeout(PeriodicalQuery, (60 * 1000));
         
     | 
| 
       34 
26 
     | 
    
         | 
| 
       35 
27 
     | 
    
         
             
            //]]>
         
     | 
| 
       36 
28 
     | 
    
         
             
            </script>", subject.auto_session_timeout_js
         
     | 
| 
       37 
29 
     | 
    
         
             
                end
         
     | 
| 
       38 
30 
     | 
    
         | 
| 
       39 
31 
     | 
    
         
             
                it "uses custom frequency when given" do
         
     | 
| 
       40 
     | 
    
         
            -
                  assert_match / 
     | 
| 
      
 32 
     | 
    
         
            +
                  assert_match /120/, subject.auto_session_timeout_js(frequency: 120)
         
     | 
| 
       41 
33 
     | 
    
         
             
                end
         
     | 
| 
       42 
34 
     | 
    
         | 
| 
       43 
35 
     | 
    
         
             
                it "uses 60 when custom frequency is nil" do
         
     | 
| 
       44 
     | 
    
         
            -
                  assert_match / 
     | 
| 
      
 36 
     | 
    
         
            +
                  assert_match /60/, subject.auto_session_timeout_js(frequency: nil)
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                it "accepts attributes" do
         
     | 
| 
      
 40 
     | 
    
         
            +
                  assert_match /data-turbolinks-eval="false"/, subject.auto_session_timeout_js(attributes: { 'data-turbolinks-eval': 'false' })
         
     | 
| 
       45 
41 
     | 
    
         
             
                end
         
     | 
| 
       46 
42 
     | 
    
         
             
              end
         
     | 
| 
       47 
43 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: auto-session-timeout
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.9. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.9.5
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Matthew Bass
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2017- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-06-13 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |