softwear-lib 1.5.0 → 1.5.1

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: 07abbcd1086c6337273c1b6536c2f3ada2c817ca
4
- data.tar.gz: afbd2b01e668364fd40d18e5f047a2297a824083
3
+ metadata.gz: aee29f7263adae53ab78fc85bbf5be053ab9e595
4
+ data.tar.gz: fb4122fcdf16d493d6458ccd6244b0389abed414
5
5
  SHA512:
6
- metadata.gz: 44716bcb3a8898364f4092328fc8c59217eb834768678204395dc469316d1b0b28ce27437f6df7ec650b7d15ecf5075ac004f4697d312611b2b77d16f97bee7f
7
- data.tar.gz: 4d54bb27f4ece39a7132503fa59759eca15fc39c337d8d1f16f513cad1367d7bf5a10f5a6cd631432af9b612fb122c1e3c02886c2c0074a94f35b31a74da6bad
6
+ metadata.gz: 1d9e0af480f85c41f40b64c63e26d1c6de7bc8a061117673373fe3889e7c606be2e49ab664a3f53296141be71c0a3a2a2bbdb470113a9008546d8f7ce6d4d975
7
+ data.tar.gz: 1eaf5225a3240a1e6d0b7953ce33ebab100cb836bf9388dcafc899ba84581a4feaf505cc87ca26696052f54fc443d668320fc12870e5a8e1a22c95a4c4149b0e
@@ -3,6 +3,10 @@ module Softwear
3
3
  class Controller < ApplicationController
4
4
  skip_before_filter :authenticate_user!, only: [:set_session_token, :clear_query_cache]
5
5
 
6
+ def self.abstract_class?
7
+ true
8
+ end
9
+
6
10
  # ====================
7
11
  # Comes from an img tag on softwear-hub to let an authorized app know that
8
12
  # a user has signed in.
@@ -15,6 +15,10 @@ module Softwear
15
15
 
16
16
  # ============================= CLASS METHODS ======================
17
17
  class << self
18
+ def abstract_class?
19
+ true
20
+ end
21
+
18
22
  attr_writer :query_cache
19
23
  attr_accessor :total_query_cache
20
24
  attr_writer :query_cache_expiry
@@ -0,0 +1,58 @@
1
+ module Softwear
2
+ module Auth
3
+ module Spec
4
+ def spec_users
5
+ User.instance_variable_get(:@_spec_users)
6
+ end
7
+
8
+ def stub_authentication!(config, *a)
9
+ config.before(:each, *a) do
10
+ User.instance_variable_set(:@_spec_users, [])
11
+
12
+ allow(User).to receive(:all) { spec_users }
13
+ allow(User).to receive(:find) { |n| spec_users.find { |u| u.id == n } }
14
+ allow(User).to receive(:auth) { @_signed_in_user or false }
15
+ allow(User).to receive(:raw_query) { |q| raise "Unstubbed authentication query \"#{q}\"" }
16
+
17
+ allow_any_instance_of(Softwear::Lib::ControllerAuthentication)
18
+ .to receive(:user_token)
19
+ .and_return('')
20
+
21
+ if (controller rescue false)
22
+ allow(controller).to receive(:current_user) { @_signed_in_user }
23
+ controller.class_eval { helper_method :current_user }
24
+
25
+ allow(controller).to receive(:user_signed_in?) { !!@_signed_in_user }
26
+ controller.class_eval { helper_method :user_signed_in? }
27
+
28
+ allow(controller).to receive(:destroy_user_session_path) { '#' }
29
+ controller.class_eval { helper_method :destroy_user_session_path }
30
+
31
+ allow(controller).to receive(:users_path) { '#' }
32
+ controller.class_eval { helper_method :users_path }
33
+
34
+ allow(controller).to receive(:edit_user_path) { '#' }
35
+ controller.class_eval { protected; helper_method :edit_user_path }
36
+ end
37
+ end
38
+
39
+ config.after(:each, *a) do
40
+ User.instance_variable_set(:@_spec_users, nil)
41
+ end
42
+ end
43
+
44
+ def sign_in_as(user)
45
+ @_signed_in_user = user
46
+
47
+ allow_any_instance_of(Softwear::Lib::ControllerAuthentication)
48
+ .to receive(:user_token).and_return 'abc123'
49
+
50
+ if respond_to?(:session) && session.respond_to?(:[]=)
51
+ session[:user_token] = 'abc123'
52
+ end
53
+ end
54
+ alias_method :sign_in, :sign_in_as
55
+ alias_method :login_as, :sign_in_as
56
+ end
57
+ end
58
+ end
data/lib/softwear/lib.rb CHANGED
@@ -6,6 +6,7 @@ require "softwear/lib/controller_authentication"
6
6
  require "softwear/auth/helper"
7
7
  require "softwear/auth/model"
8
8
  require "softwear/auth/belongs_to_user"
9
+ require "softwear/auth/spec"
9
10
 
10
11
  module Softwear
11
12
  module Lib
@@ -42,8 +42,15 @@ module Softwear
42
42
  respond_to do |format|
43
43
  format.html do
44
44
  render inline: \
45
- "<h1>#{error.message}</h1><div>Not all site functions will work until the problem is resolved. "\
46
- "<a href='javascripr' onclick='history.go(-1);return false;' class='btn btn-default'>Go back.</a></div>"
45
+ "<div class='panel panel-danger'>"\
46
+ "<div class='panel-heading'>"\
47
+ "<h3 class='panel-title'>#{error.message}</h3>"\
48
+ "</div>"\
49
+ "<div class='panel-body'>"\
50
+ "Not all site functions will work until the problem is resolved. "\
51
+ "<a href='javascripr' onclick='history.go(-1);return false;' class='btn btn-default'>Go back.</a>"\
52
+ "</div>"\
53
+ "</div>"
47
54
  end
48
55
 
49
56
  format.js do
@@ -57,16 +64,14 @@ module Softwear
57
64
  # just like in Devise.
58
65
  # ====================
59
66
  def authenticate_user!
60
- token = session[:user_token]
61
-
62
- if token.blank?
67
+ if user_token.blank?
63
68
  raise NotSignedInError, "No token"
64
69
  end
65
70
 
66
- if user = user_class.auth(token)
71
+ if user = user_class.auth(user_token)
67
72
  @current_user = user
68
73
  else
69
- session[:user_token] = nil
74
+ self.user_token = nil
70
75
  raise NotSignedInError, "Invalid token"
71
76
  end
72
77
  end
@@ -98,6 +103,16 @@ module Softwear
98
103
  def users_path
99
104
  Figaro.env.softwear_hub_url + "/users"
100
105
  end
106
+
107
+ private
108
+
109
+ def user_token
110
+ session[:user_token]
111
+ end
112
+
113
+ def user_token=(new_token)
114
+ session[:user_token] = new_token
115
+ end
101
116
  end
102
117
  end
103
118
  end
@@ -1,5 +1,5 @@
1
1
  module Softwear
2
2
  module Lib
3
- VERSION = "1.5.0"
3
+ VERSION = "1.5.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: softwear-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Baillie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,7 @@ files:
87
87
  - lib/softwear/auth/controller.rb
88
88
  - lib/softwear/auth/helper.rb
89
89
  - lib/softwear/auth/model.rb
90
+ - lib/softwear/auth/spec.rb
90
91
  - lib/softwear/lib.rb
91
92
  - lib/softwear/lib/api_controller.rb
92
93
  - lib/softwear/lib/authentication.rb