signinable 2.0.11 → 2.0.12

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -4
  3. data/app/models/signin.rb +12 -2
  4. data/config/routes.rb +2 -0
  5. data/db/migrate/20140103165607_create_signins.rb +7 -5
  6. data/db/migrate/20180530131006_add_custom_data_to_sigins.rb +5 -5
  7. data/lib/signinable/engine.rb +4 -9
  8. data/lib/signinable/model_additions.rb +77 -51
  9. data/lib/signinable/version.rb +3 -1
  10. data/lib/signinable.rb +3 -1
  11. data/spec/dummy/Rakefile +3 -1
  12. data/spec/dummy/app/models/user.rb +2 -0
  13. data/spec/dummy/bin/bundle +3 -1
  14. data/spec/dummy/bin/rails +3 -1
  15. data/spec/dummy/bin/rake +2 -0
  16. data/spec/dummy/config/application.rb +5 -20
  17. data/spec/dummy/config/boot.rb +5 -3
  18. data/spec/dummy/config/environment.rb +3 -1
  19. data/spec/dummy/config/environments/development.rb +4 -2
  20. data/spec/dummy/config/environments/production.rb +2 -0
  21. data/spec/dummy/config/environments/test.rb +4 -2
  22. data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
  23. data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
  24. data/spec/dummy/config/initializers/inflections.rb +1 -0
  25. data/spec/dummy/config/initializers/mime_types.rb +1 -0
  26. data/spec/dummy/config/initializers/secret_token.rb +2 -0
  27. data/spec/dummy/config/initializers/session_store.rb +2 -0
  28. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  29. data/spec/dummy/config/routes.rb +2 -0
  30. data/spec/dummy/config.ru +3 -1
  31. data/spec/dummy/db/development.sqlite3 +0 -0
  32. data/spec/dummy/db/migrate/20140103165606_create_users.rb +3 -1
  33. data/spec/dummy/db/schema.rb +23 -24
  34. data/spec/dummy/db/test.sqlite3 +0 -0
  35. data/spec/dummy/log/development.log +427 -0
  36. data/spec/dummy/log/test.log +8192 -0
  37. data/spec/factories/signins.rb +8 -0
  38. data/spec/factories/users.rb +7 -0
  39. data/spec/models/signin_spec.rb +25 -23
  40. data/spec/models/user_spec.rb +71 -72
  41. data/spec/rails_helper.rb +20 -0
  42. data/spec/spec_helper.rb +11 -12
  43. data/spec/support/utilities.rb +2 -0
  44. metadata +39 -14
  45. data/spec/factories/signin.rb +0 -8
  46. data/spec/factories/user.rb +0 -7
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :signin do
5
+ ip { '127.0.0.1' }
6
+ signinable
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :user, aliases: [:signinable] do
5
+ name { 'test' }
6
+ end
7
+ end
@@ -1,49 +1,51 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
2
4
 
3
5
  describe Signin do
4
- it "has a valid factory" do
5
- signin = FactoryGirl.build(:signin)
6
- signin.should be_valid
6
+ it 'has a valid factory' do
7
+ signin = build(:signin)
8
+ expect(signin).to be_valid
7
9
  end
8
10
 
9
- context "is invalid without" do
10
- it "a token" do
11
- signin = FactoryGirl.create(:signin)
11
+ context 'is invalid without' do
12
+ it 'a token' do
13
+ signin = create(:signin)
12
14
  signin.token = nil
13
- signin.should_not be_valid
15
+ expect(signin).to_not be_valid
14
16
  end
15
17
 
16
- it "an ip" do
17
- FactoryGirl.build(:signin, ip: nil).should_not be_valid
18
+ it 'an ip' do
19
+ expect(build(:signin, ip: nil)).to_not be_valid
18
20
  end
19
21
  end
20
22
 
21
- it "should generate token on create" do
22
- signin = FactoryGirl.create(:signin, token: nil)
23
- signin.token.should_not be_nil
23
+ it 'should generate token on create' do
24
+ signin = create(:signin, token: nil)
25
+ expect(signin.token).to_not be_nil
24
26
  end
25
27
 
26
- context "not valid with" do
27
- it "wrong ip" do
28
- FactoryGirl.build(:signin, ip: "123").should_not be_valid
28
+ context 'not valid with' do
29
+ it 'wrong ip' do
30
+ expect(build(:signin, ip: '123')).to_not be_valid
29
31
  end
30
32
  end
31
33
 
32
- it "should expire" do
34
+ it 'should expire' do
33
35
  Timecop.freeze
34
36
  expiration_time = Time.zone.now + 1.hour
35
- signin = FactoryGirl.create(:signin, expiration_time: expiration_time)
37
+ signin = create(:signin, expiration_time: expiration_time)
36
38
  Timecop.travel(expiration_time)
37
- signin.should be_expired
39
+ expect(signin).to be_expired
38
40
  Timecop.return
39
41
  end
40
42
 
41
- describe ".expire!" do
42
- it "should set expiration_time to now" do
43
+ describe '.expire!' do
44
+ it 'should set expiration_time to now' do
43
45
  Timecop.freeze
44
- signin = FactoryGirl.create(:signin, expiration_time: (Time.zone.now + 1.hour))
46
+ signin = create(:signin, expiration_time: (Time.zone.now + 1.hour))
45
47
  signin.expire!
46
- signin.should be_expired
48
+ expect(signin).to be_expired
47
49
  Timecop.return
48
50
  end
49
51
  end
@@ -1,131 +1,130 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
2
4
 
3
5
  describe User do
6
+ let(:credentials) { ['127.0.0.1', 'user_agent'] }
7
+ let(:other_credentials) { ['127.0.0.2', 'user_agent2'] }
8
+ let(:user) { create(:user) }
9
+
4
10
  before :each do
5
11
  Timecop.freeze
6
- User.signin_expiration = 2.hours
7
- User.signin_simultaneous = true
8
- User.signin_restrictions = []
9
- @user = FactoryGirl.create(:user)
10
- @credentials = ['127.0.0.1', 'user_agent']
11
- @other_credentials = ['127.0.0.2', 'user_agent2']
12
12
  end
13
13
 
14
14
  after :each do
15
15
  Timecop.return
16
16
  end
17
17
 
18
- describe ".signin" do
19
- it "should create Signin" do
20
- expect {
21
- sign_in_user(@user, @credentials)
22
- }.to change(Signin, :count).by(1)
18
+ describe '.signin' do
19
+ it 'should create Signin' do
20
+ expect do
21
+ sign_in_user(user, credentials)
22
+ end.to change(Signin, :count).by(1)
23
23
  end
24
24
 
25
- it "should set expiration_time" do
26
- signin = sign_in_user(@user, @credentials)
27
- signin.expiration_time.to_i.should eq((Time.zone.now + User.signin_expiration).to_i)
25
+ it 'should set expiration_time' do
26
+ signin = sign_in_user(user, credentials)
27
+ expect(signin.expiration_time.to_i).to eq((Time.zone.now + User.signin_expiration).to_i)
28
28
  end
29
29
 
30
- it "should not set expiration_time" do
31
- User.signin_expiration = 0
32
- signin = sign_in_user(@user, @credentials)
33
- signin.expiration_time.should be_nil
30
+ it 'should not set expiration_time' do
31
+ allow(User).to receive(:signin_expiration).and_return(0)
32
+ signin = sign_in_user(user, credentials)
33
+ expect(signin.expiration_time).to be_nil
34
34
  end
35
35
  end
36
36
 
37
- describe ".signout" do
38
- it "should expire signin" do
39
- signin = sign_in_user(@user, @credentials)
40
- sign_out_user(signin, @credentials)
41
- signin.reload
42
- signin.should be_expired
37
+ describe '.signout' do
38
+ it 'should expire signin' do
39
+ signin = sign_in_user(user, credentials)
40
+ sign_out_user(signin, credentials)
41
+ expect(signin.reload).to be_expired
43
42
  end
44
43
 
45
- context "should be allowed with" do
46
- %w{ip user_agent}.each do |c|
44
+ context 'should be allowed with' do
45
+ %i[ip user_agent].each do |c|
47
46
  it "changed #{c} if not restricted" do
48
- signin = sign_in_user(@user, @credentials)
49
- sign_out_user(signin, @credentials).should be_true
47
+ signin = sign_in_user(user, credentials)
48
+ expect(sign_out_user(signin, credentials)).to be_truthy
50
49
  end
51
50
  end
52
51
  end
53
52
 
54
- context "should not be allowed with" do
55
- %w{ip user_agent}.each do |c|
53
+ context 'should not be allowed with' do
54
+ %i[ip user_agent].each do |c|
56
55
  it "changed #{c} if restricted" do
57
- User.signin_restrictions = [c]
58
- signin = sign_in_user(@user, @credentials)
59
- sign_out_user(signin, @other_credentials).should be_nil
56
+ allow(User).to receive(:signin_restrictions).and_return([c])
57
+ signin = sign_in_user(user, credentials)
58
+ expect(sign_out_user(signin, other_credentials)).to be_nil
60
59
  end
61
60
  end
62
61
  end
63
62
  end
64
63
 
65
- describe "#authenticate_with_token" do
66
- context "expiration_time" do
67
- it "should be changed after authentication" do
68
- signin = sign_in_user(@user, @credentials)
64
+ describe '#authenticate_with_token' do
65
+ context 'expiration_time' do
66
+ it 'should be changed after authentication' do
67
+ signin = sign_in_user(user, credentials)
69
68
  old_time = signin.expiration_time
70
69
  new_time = signin.expiration_time - 1.hour
71
70
  Timecop.travel(new_time)
72
- User.authenticate_with_token(signin.token, *@credentials)
71
+ User.authenticate_with_token(signin.token, *credentials)
73
72
  signin.reload
74
- signin.expiration_time.to_i.should eq((new_time + User.signin_expiration).to_i)
73
+ expect(signin.expiration_time.to_i).to eq((new_time + User.signin_expiration).to_i)
75
74
  end
76
75
 
77
- it "should not be changed after authentication" do
78
- User.signin_expiration = 0
79
- signin = sign_in_user(@user, @credentials)
76
+ it 'should not be changed after authentication' do
77
+ allow(User).to receive(:signin_expiration).and_return(0)
78
+ signin = sign_in_user(user, credentials)
80
79
  old_time = signin.expiration_time
81
80
  Timecop.travel(Time.zone.now + 1.hour)
82
- User.authenticate_with_token(signin.token, *@credentials)
81
+ User.authenticate_with_token(signin.token, *credentials)
83
82
  signin.reload
84
- signin.expiration_time.to_i.should eq(old_time.to_i)
83
+ expect(signin.expiration_time.to_i).to eq(old_time.to_i)
85
84
  end
86
85
  end
87
86
 
88
- context "should allow signin with" do
89
- it "not last token if simultaneous is permitted" do
90
- signin1 = sign_in_user(@user, @credentials)
91
- signin2 = sign_in_user(@user, @credentials)
92
- User.authenticate_with_token(signin1.token, *@credentials).should eq(@user)
93
- User.authenticate_with_token(signin2.token, *@credentials).should eq(@user)
87
+ context 'should allow signin with' do
88
+ it 'not last token if simultaneous is permitted' do
89
+ signin1 = sign_in_user(user, credentials)
90
+ signin2 = sign_in_user(user, credentials)
91
+ expect(User.authenticate_with_token(signin1.token, *credentials)).to eq(user)
92
+ expect(User.authenticate_with_token(signin2.token, *credentials)).to eq(user)
94
93
  end
95
94
 
96
- it "valid token" do
97
- signin = sign_in_user(@user, @credentials)
98
- User.authenticate_with_token(signin.token, *@credentials).should eq(@user)
95
+ it 'valid token' do
96
+ signin = sign_in_user(user, credentials)
97
+ expect(User.authenticate_with_token(signin.token, *credentials)).to eq(user)
99
98
  end
100
99
 
101
- %w{ip user_agent}.each do |c|
100
+ %i[ip user_agent].each do |c|
102
101
  it "changed #{c} if not restricted" do
103
- signin = sign_in_user(@user, @credentials)
104
- User.authenticate_with_token(signin.token, *@other_credentials).should eq(@user)
102
+ signin = sign_in_user(user, credentials)
103
+ expect(User.authenticate_with_token(signin.token, *other_credentials)).to eq(user)
105
104
  end
106
105
  end
107
106
  end
108
107
 
109
- context "should not allow signin with" do
110
- it "not last token if simultaneous not permitted" do
111
- User.signin_simultaneous = false
112
- signin1 = sign_in_user(@user, @credentials)
113
- signin2 = sign_in_user(@user, @credentials)
114
- User.authenticate_with_token(signin1.token, *@credentials).should be_nil
115
- User.authenticate_with_token(signin2.token, *@credentials).should eq(@user)
108
+ context 'should not allow signin with' do
109
+ it 'not last token if simultaneous not permitted' do
110
+ allow(User).to receive(:simultaneous_signings).and_return(false)
111
+ signin1 = sign_in_user(user, credentials)
112
+ signin2 = sign_in_user(user, credentials)
113
+ expect(User.authenticate_with_token(signin1.token, *credentials)).to be_nil
114
+ expect(User.authenticate_with_token(signin2.token, *credentials)).to eq(user)
116
115
  end
117
116
 
118
- it "expired token" do
119
- signin = sign_in_user(@user, @credentials)
120
- @user.signout(signin.token, *@credentials)
121
- User.authenticate_with_token(signin.token, *@credentials).should be_nil
117
+ it 'expired token' do
118
+ signin = sign_in_user(user, credentials)
119
+ user.signout(signin.token, *credentials)
120
+ expect(User.authenticate_with_token(signin.token, *credentials)).to be_nil
122
121
  end
123
122
 
124
- %w{ip user_agent}.each do |c|
123
+ %i[ip user_agent].each do |c|
125
124
  it "changed #{c} if restricted" do
126
- User.signin_restrictions = [c]
127
- signin = sign_in_user(@user, @credentials)
128
- User.authenticate_with_token(signin.token, *@other_credentials).should be_nil
125
+ allow(User).to receive(:signin_restrictions).and_return([c])
126
+ signin = sign_in_user(user, credentials)
127
+ expect(User.authenticate_with_token(signin.token, *other_credentials)).to be_nil
129
128
  end
130
129
  end
131
130
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+
5
+ require File.expand_path('dummy/config/environment', __dir__)
6
+
7
+ require 'spec_helper'
8
+ require 'rspec/rails'
9
+
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
11
+
12
+ RSpec.configure do |config|
13
+ config.use_transactional_fixtures = true
14
+
15
+ config.infer_spec_type_from_file_location!
16
+
17
+ config.filter_rails_from_backtrace!
18
+
19
+ config.include FactoryBot::Syntax::Methods
20
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,17 @@
1
- ENV['RAILS_ENV'] ||= 'test'
1
+ # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../dummy/config/environment', __FILE__)
4
- require 'rspec/rails'
5
- require 'rspec/autorun'
6
- require 'factory_girl_rails'
3
+ require 'factory_bot_rails'
4
+ require 'pry'
7
5
  require 'timecop'
8
6
 
9
- Rails.backtrace_cleaner.remove_silencers!
7
+ RSpec.configure do |config|
8
+ config.expect_with :rspec do |expectations|
9
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
10
+ end
10
11
 
11
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+ config.mock_with :rspec do |mocks|
13
+ mocks.verify_partial_doubles = true
14
+ end
12
15
 
13
- RSpec.configure do |config|
14
- config.mock_with :rspec
15
- config.use_transactional_fixtures = false
16
- config.infer_base_class_for_anonymous_controllers = false
17
- config.order = 'random'
16
+ config.shared_context_metadata_behavior = :apply_to_host_groups
18
17
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  def sign_in_user(user, credentials)
2
4
  token = user.signin(*credentials, 'referer')
3
5
  Signin.find_by_token(token)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: signinable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.11
4
+ version: 2.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Novozhenets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-17 00:00:00.000000000 Z
11
+ date: 2022-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,16 +16,30 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: 5.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0
26
+ version: 5.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: sqlite3
28
+ name: factory_bot_rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-rails
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -53,7 +67,7 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: timecop
70
+ name: sqlite3
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -67,7 +81,7 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: factory_girl_rails
84
+ name: timecop
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -121,21 +135,27 @@ files:
121
135
  - spec/dummy/config/initializers/wrap_parameters.rb
122
136
  - spec/dummy/config/locales/en.yml
123
137
  - spec/dummy/config/routes.rb
138
+ - spec/dummy/db/development.sqlite3
124
139
  - spec/dummy/db/migrate/20140103165606_create_users.rb
125
140
  - spec/dummy/db/schema.rb
141
+ - spec/dummy/db/test.sqlite3
142
+ - spec/dummy/log/development.log
143
+ - spec/dummy/log/test.log
126
144
  - spec/dummy/public/404.html
127
145
  - spec/dummy/public/422.html
128
146
  - spec/dummy/public/500.html
129
147
  - spec/dummy/public/favicon.ico
130
- - spec/factories/signin.rb
131
- - spec/factories/user.rb
148
+ - spec/factories/signins.rb
149
+ - spec/factories/users.rb
132
150
  - spec/models/signin_spec.rb
133
151
  - spec/models/user_spec.rb
152
+ - spec/rails_helper.rb
134
153
  - spec/spec_helper.rb
135
154
  - spec/support/utilities.rb
136
155
  homepage: https://github.com/novozhenets/signinable
137
156
  licenses: []
138
- metadata: {}
157
+ metadata:
158
+ rubygems_mfa_required: 'true'
139
159
  post_install_message:
140
160
  rdoc_options: []
141
161
  require_paths:
@@ -144,20 +164,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
164
  requirements:
145
165
  - - ">="
146
166
  - !ruby/object:Gem::Version
147
- version: '0'
167
+ version: '2.5'
148
168
  required_rubygems_version: !ruby/object:Gem::Requirement
149
169
  requirements:
150
170
  - - ">="
151
171
  - !ruby/object:Gem::Version
152
172
  version: '0'
153
173
  requirements: []
154
- rubygems_version: 3.1.4
174
+ rubygems_version: 3.1.6
155
175
  signing_key:
156
176
  specification_version: 4
157
177
  summary: Token based signin
158
178
  test_files:
159
179
  - spec/dummy/config.ru
160
180
  - spec/dummy/README.rdoc
181
+ - spec/dummy/db/test.sqlite3
182
+ - spec/dummy/db/development.sqlite3
161
183
  - spec/dummy/db/migrate/20140103165606_create_users.rb
162
184
  - spec/dummy/db/schema.rb
163
185
  - spec/dummy/config/environment.rb
@@ -185,9 +207,12 @@ test_files:
185
207
  - spec/dummy/public/favicon.ico
186
208
  - spec/dummy/public/404.html
187
209
  - spec/dummy/public/422.html
210
+ - spec/dummy/log/test.log
211
+ - spec/dummy/log/development.log
212
+ - spec/rails_helper.rb
188
213
  - spec/support/utilities.rb
189
- - spec/factories/user.rb
190
- - spec/factories/signin.rb
214
+ - spec/factories/users.rb
215
+ - spec/factories/signins.rb
191
216
  - spec/spec_helper.rb
192
217
  - spec/models/signin_spec.rb
193
218
  - spec/models/user_spec.rb
@@ -1,8 +0,0 @@
1
- # Read about factories at https://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :signin do
5
- ip "127.0.0.1"
6
- signinable
7
- end
8
- end
@@ -1,7 +0,0 @@
1
- # Read about factories at https://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :user, :aliases => [:signinable] do
5
- name "test"
6
- end
7
- end