audited 4.8.0 → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of audited might be problematic. Click here for more details.

@@ -1,5 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
+ SingleCov.covered! uncovered: 13 # not testing proxy_respond_to? hack / 2 methods / deprecation of `version`
4
+
3
5
  describe Audited::Auditor do
4
6
 
5
7
  describe "configuration" do
@@ -210,7 +212,40 @@ describe Audited::Auditor do
210
212
  expect(user.audits.last.audited_changes.keys).to eq(%w{non_column_attr})
211
213
  end
212
214
 
213
- if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' && Rails.version >= "4.2.0.0" # Postgres json and jsonb support was added in Rails 4.2
215
+ it "should redact columns specified in 'redacted' option" do
216
+ redacted = Audited::Auditor::AuditedInstanceMethods::REDACTED
217
+ user = Models::ActiveRecord::UserRedactedPassword.create(password: "password")
218
+ user.save!
219
+ expect(user.audits.last.audited_changes['password']).to eq(redacted)
220
+ user.password = "new_password"
221
+ user.save!
222
+ expect(user.audits.last.audited_changes['password']).to eq([redacted, redacted])
223
+ end
224
+
225
+ it "should redact columns specified in 'redacted' option when there are multiple specified" do
226
+ redacted = Audited::Auditor::AuditedInstanceMethods::REDACTED
227
+ user =
228
+ Models::ActiveRecord::UserMultipleRedactedAttributes.create(
229
+ password: "password",
230
+ ssn: 123456789
231
+ )
232
+ user.save!
233
+ expect(user.audits.last.audited_changes['password']).to eq(redacted)
234
+ expect(user.audits.last.audited_changes['ssn']).to eq(redacted)
235
+ user.password = "new_password"
236
+ user.ssn = 987654321
237
+ user.save!
238
+ expect(user.audits.last.audited_changes['password']).to eq([redacted, redacted])
239
+ expect(user.audits.last.audited_changes['ssn']).to eq([redacted, redacted])
240
+ end
241
+
242
+ it "should redact columns in 'redacted' column with custom option" do
243
+ user = Models::ActiveRecord::UserRedactedPasswordCustomRedaction.create(password: "password")
244
+ user.save!
245
+ expect(user.audits.last.audited_changes['password']).to eq(["My", "Custom", "Value", 7])
246
+ end
247
+
248
+ if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
214
249
  describe "'json' and 'jsonb' audited_changes column type" do
215
250
  let(:migrations_path) { SPEC_ROOT.join("support/active_record/postgres") }
216
251
 
@@ -264,7 +299,7 @@ describe Audited::Auditor do
264
299
  end
265
300
 
266
301
  describe "on create" do
267
- let( :user ) { create_user audit_comment: "Create" }
302
+ let( :user ) { create_user status: :reliable, audit_comment: "Create" }
268
303
 
269
304
  it "should change the audit count" do
270
305
  expect {
@@ -288,6 +323,10 @@ describe Audited::Auditor do
288
323
  expect(user.audits.first.audited_changes).to eq(user.audited_attributes)
289
324
  end
290
325
 
326
+ it "should store enum value" do
327
+ expect(user.audits.first.audited_changes["status"]).to eq(1)
328
+ end
329
+
291
330
  it "should store comment" do
292
331
  expect(user.audits.first.comment).to eq('Create')
293
332
  end
@@ -306,7 +345,7 @@ describe Audited::Auditor do
306
345
 
307
346
  describe "on update" do
308
347
  before do
309
- @user = create_user( name: 'Brandon', audit_comment: 'Update' )
348
+ @user = create_user( name: 'Brandon', status: :active, audit_comment: 'Update' )
310
349
  end
311
350
 
312
351
  it "should save an audit" do
@@ -319,17 +358,22 @@ describe Audited::Auditor do
319
358
  end
320
359
 
321
360
  it "should set the action to 'update'" do
322
- @user.update_attributes name: 'Changed'
361
+ @user.update! name: 'Changed'
323
362
  expect(@user.audits.last.action).to eq('update')
324
363
  expect(Audited::Audit.updates.order(:id).last).to eq(@user.audits.last)
325
364
  expect(@user.audits.updates.last).to eq(@user.audits.last)
326
365
  end
327
366
 
328
367
  it "should store the changed attributes" do
329
- @user.update_attributes name: 'Changed'
368
+ @user.update! name: 'Changed'
330
369
  expect(@user.audits.last.audited_changes).to eq({ 'name' => ['Brandon', 'Changed'] })
331
370
  end
332
371
 
372
+ it "should store changed enum values" do
373
+ @user.update! status: 1
374
+ expect(@user.audits.last.audited_changes["status"]).to eq([0, 1])
375
+ end
376
+
333
377
  it "should store audit comment" do
334
378
  expect(@user.audits.last.comment).to eq('Update')
335
379
  end
@@ -337,12 +381,12 @@ describe Audited::Auditor do
337
381
  it "should not save an audit if only specified on create/destroy" do
338
382
  on_create_destroy = Models::ActiveRecord::OnCreateDestroy.create( name: 'Bart' )
339
383
  expect {
340
- on_create_destroy.update_attributes name: 'Changed'
384
+ on_create_destroy.update! name: 'Changed'
341
385
  }.to_not change( Audited::Audit, :count )
342
386
  end
343
387
 
344
388
  it "should not save an audit if the value doesn't change after type casting" do
345
- @user.update_attributes! logins: 0, activated: true
389
+ @user.update! logins: 0, activated: true
346
390
  expect { @user.update_attribute :logins, '0' }.to_not change( Audited::Audit, :count )
347
391
  expect { @user.update_attribute :activated, 1 }.to_not change( Audited::Audit, :count )
348
392
  expect { @user.update_attribute :activated, '1' }.to_not change( Audited::Audit, :count )
@@ -366,7 +410,7 @@ describe Audited::Auditor do
366
410
 
367
411
  describe "on destroy" do
368
412
  before do
369
- @user = create_user
413
+ @user = create_user(status: :active)
370
414
  end
371
415
 
372
416
  it "should save an audit" do
@@ -391,6 +435,11 @@ describe Audited::Auditor do
391
435
  expect(@user.audits.last.audited_changes).to eq(@user.audited_attributes)
392
436
  end
393
437
 
438
+ it "should store enum value" do
439
+ @user.destroy
440
+ expect(@user.audits.last.audited_changes["status"]).to eq(0)
441
+ end
442
+
394
443
  it "should be able to reconstruct a destroyed record without history" do
395
444
  @user.audits.delete_all
396
445
  @user.destroy
@@ -492,13 +541,13 @@ describe Audited::Auditor do
492
541
  it "should delete old extra audits after introducing limit" do
493
542
  stub_global_max_audits(nil) do
494
543
  user = Models::ActiveRecord::User.create!(name: 'Brandon', username: 'brandon')
495
- user.update_attributes(name: 'Foobar')
496
- user.update_attributes(name: 'Awesome', username: 'keepers')
497
- user.update_attributes(activated: true)
544
+ user.update!(name: 'Foobar')
545
+ user.update!(name: 'Awesome', username: 'keepers')
546
+ user.update!(activated: true)
498
547
 
499
548
  Audited.max_audits = 3
500
549
  Models::ActiveRecord::User.send(:normalize_audited_options)
501
- user.update_attributes(favourite_device: 'Android Phone')
550
+ user.update!(favourite_device: 'Android Phone')
502
551
  audits = user.audits
503
552
 
504
553
  expect(audits.count).to eq(3)
@@ -549,8 +598,8 @@ describe Audited::Auditor do
549
598
 
550
599
  it "should set the attributes for each revision" do
551
600
  u = Models::ActiveRecord::User.create(name: 'Brandon', username: 'brandon')
552
- u.update_attributes name: 'Foobar'
553
- u.update_attributes name: 'Awesome', username: 'keepers'
601
+ u.update! name: 'Foobar'
602
+ u.update! name: 'Awesome', username: 'keepers'
554
603
 
555
604
  expect(u.revisions.size).to eql(3)
556
605
 
@@ -566,8 +615,8 @@ describe Audited::Auditor do
566
615
 
567
616
  it "access to only recent revisions" do
568
617
  u = Models::ActiveRecord::User.create(name: 'Brandon', username: 'brandon')
569
- u.update_attributes name: 'Foobar'
570
- u.update_attributes name: 'Awesome', username: 'keepers'
618
+ u.update! name: 'Foobar'
619
+ u.update! name: 'Awesome', username: 'keepers'
571
620
 
572
621
  expect(u.revisions(2).size).to eq(2)
573
622
 
@@ -584,7 +633,7 @@ describe Audited::Auditor do
584
633
  end
585
634
 
586
635
  it "should ignore attributes that have been deleted" do
587
- user.audits.last.update_attributes audited_changes: {old_attribute: 'old value'}
636
+ user.audits.last.update! audited_changes: {old_attribute: 'old value'}
588
637
  expect { user.revisions }.to_not raise_error
589
638
  end
590
639
  end
@@ -633,8 +682,8 @@ describe Audited::Auditor do
633
682
 
634
683
  it "should set the attributes for each revision" do
635
684
  u = Models::ActiveRecord::User.create(name: 'Brandon', username: 'brandon')
636
- u.update_attributes name: 'Foobar'
637
- u.update_attributes name: 'Awesome', username: 'keepers'
685
+ u.update! name: 'Foobar'
686
+ u.update! name: 'Awesome', username: 'keepers'
638
687
 
639
688
  expect(u.revision(3).name).to eq('Awesome')
640
689
  expect(u.revision(3).username).to eq('keepers')
@@ -646,6 +695,16 @@ describe Audited::Auditor do
646
695
  expect(u.revision(1).username).to eq('brandon')
647
696
  end
648
697
 
698
+ it "should correctly restore revision with enum" do
699
+ u = Models::ActiveRecord::User.create(status: :active)
700
+ u.update_attribute(:status, :reliable)
701
+ u.update_attribute(:status, :banned)
702
+
703
+ expect(u.revision(3)).to be_banned
704
+ expect(u.revision(2)).to be_reliable
705
+ expect(u.revision(1)).to be_active
706
+ end
707
+
649
708
  it "should be able to get time for first revision" do
650
709
  suspended_at = Time.zone.now
651
710
  u = Models::ActiveRecord::User.create(suspended_at: suspended_at)
@@ -686,7 +745,7 @@ describe Audited::Auditor do
686
745
  audit = user.audits.first
687
746
  audit.created_at = 1.hour.ago
688
747
  audit.save!
689
- user.update_attributes name: 'updated'
748
+ user.update! name: 'updated'
690
749
  expect(user.revision_at( 2.minutes.ago ).audit_version).to eq(1)
691
750
  end
692
751
 
@@ -702,7 +761,7 @@ describe Audited::Auditor do
702
761
  company.update!(name: "Collective Idea")
703
762
 
704
763
  other_owner = Models::ActiveRecord::Owner.create!
705
- other_company = other_owner.companies.create!
764
+ other_owner.companies.create!
706
765
 
707
766
  expect(owner.own_and_associated_audits).to match_array(owner.audits + company.audits)
708
767
  end
@@ -778,8 +837,67 @@ describe Audited::Auditor do
778
837
  Audited.auditing_enabled = true
779
838
  expect(Models::ActiveRecord::User.auditing_enabled).to eq(true)
780
839
 
781
- user.update_attributes(name: 'Test')
840
+ user.update!(name: 'Test')
782
841
  expect(user.audits.count).to eq(1)
842
+ Models::ActiveRecord::User.enable_auditing
843
+ end
844
+ end
845
+
846
+ describe "with auditing" do
847
+ it "should save an audit when calling #save_with_auditing" do
848
+ expect {
849
+ u = Models::ActiveRecord::User.new(name: 'Brandon')
850
+ Models::ActiveRecord::User.auditing_enabled = false
851
+ expect(u.save_with_auditing).to eq(true)
852
+ Models::ActiveRecord::User.auditing_enabled = true
853
+ }.to change( Audited::Audit, :count ).by(1)
854
+ end
855
+
856
+ it "should save an audit inside of the #with_auditing block" do
857
+ expect {
858
+ Models::ActiveRecord::User.auditing_enabled = false
859
+ Models::ActiveRecord::User.with_auditing { Models::ActiveRecord::User.create!( name: 'Brandon' ) }
860
+ Models::ActiveRecord::User.auditing_enabled = true
861
+ }.to change( Audited::Audit, :count ).by(1)
862
+ end
863
+
864
+ it "should reset auditing status even it raises an exception" do
865
+ Models::ActiveRecord::User.disable_auditing
866
+ Models::ActiveRecord::User.with_auditing { raise } rescue nil
867
+ expect(Models::ActiveRecord::User.auditing_enabled).to eq(false)
868
+ Models::ActiveRecord::User.enable_auditing
869
+ end
870
+
871
+ it "should be thread safe using a #with_auditing block" do
872
+ skip if Models::ActiveRecord::User.connection.class.name.include?("SQLite")
873
+
874
+ t1 = Thread.new do
875
+ Models::ActiveRecord::User.disable_auditing
876
+ expect(Models::ActiveRecord::User.auditing_enabled).to eq(false)
877
+ Models::ActiveRecord::User.with_auditing do
878
+ expect(Models::ActiveRecord::User.auditing_enabled).to eq(true)
879
+
880
+ Models::ActiveRecord::User.create!( name: 'Shaggy' )
881
+ sleep 1
882
+ expect(Models::ActiveRecord::User.auditing_enabled).to eq(true)
883
+ end
884
+ expect(Models::ActiveRecord::User.auditing_enabled).to eq(false)
885
+ Models::ActiveRecord::User.enable_auditing
886
+ end
887
+
888
+ t2 = Thread.new do
889
+ sleep 0.5
890
+ Models::ActiveRecord::User.disable_auditing
891
+ expect(Models::ActiveRecord::User.auditing_enabled).to eq(false)
892
+ Models::ActiveRecord::User.create!( name: 'Scooby' )
893
+ Models::ActiveRecord::User.enable_auditing
894
+ end
895
+ t1.join
896
+ t2.join
897
+
898
+ Models::ActiveRecord::User.enable_auditing
899
+ expect(Models::ActiveRecord::User.find_by_name('Shaggy').audits.count).to eq(1)
900
+ expect(Models::ActiveRecord::User.find_by_name('Scooby').audits.count).to eq(0)
783
901
  end
784
902
  end
785
903
 
@@ -816,21 +934,21 @@ describe Audited::Auditor do
816
934
  let( :on_destroy_user ) { Models::ActiveRecord::OnDestroyCommentRequiredUser.create }
817
935
 
818
936
  it "should not validate when audit_comment is not supplied" do
819
- expect(user.update_attributes(name: 'Test')).to eq(false)
937
+ expect(user.update(name: 'Test')).to eq(false)
820
938
  end
821
939
 
822
940
  it "should validate when audit_comment is not supplied, and updating is not being audited" do
823
- expect(on_create_user.update_attributes(name: 'Test')).to eq(true)
824
- expect(on_destroy_user.update_attributes(name: 'Test')).to eq(true)
941
+ expect(on_create_user.update(name: 'Test')).to eq(true)
942
+ expect(on_destroy_user.update(name: 'Test')).to eq(true)
825
943
  end
826
944
 
827
945
  it "should validate when audit_comment is supplied" do
828
- expect(user.update_attributes(name: 'Test', audit_comment: 'Update')).to eq(true)
946
+ expect(user.update(name: 'Test', audit_comment: 'Update')).to eq(true)
829
947
  end
830
948
 
831
949
  it "should validate when audit_comment is not supplied, and auditing is disabled" do
832
950
  Models::ActiveRecord::CommentRequiredUser.disable_auditing
833
- expect(user.update_attributes(name: 'Test')).to eq(true)
951
+ expect(user.update(name: 'Test')).to eq(true)
834
952
  Models::ActiveRecord::CommentRequiredUser.enable_auditing
835
953
  end
836
954
  end
@@ -863,6 +981,16 @@ describe Audited::Auditor do
863
981
 
864
982
  end
865
983
 
984
+ describe "no update with comment only" do
985
+ let( :user ) { Models::ActiveRecord::NoUpdateWithCommentOnlyUser.create }
986
+
987
+ it "does not create an audit when only an audit_comment is present" do
988
+ user.audit_comment = "Comment"
989
+ expect { user.save! }.to_not change( Audited::Audit, :count )
990
+ end
991
+
992
+ end
993
+
866
994
  describe "attr_protected and attr_accessible" do
867
995
 
868
996
  it "should not raise error when attr_accessible is set and protected is false" do
@@ -884,7 +1012,7 @@ describe Audited::Auditor do
884
1012
  it "should record user objects" do
885
1013
  Models::ActiveRecord::Company.audit_as( user ) do
886
1014
  company = Models::ActiveRecord::Company.create name: 'The auditors'
887
- company.update_attributes name: 'The Auditors'
1015
+ company.update! name: 'The Auditors'
888
1016
 
889
1017
  company.audits.each do |audit|
890
1018
  expect(audit.user).to eq(user)
@@ -895,7 +1023,7 @@ describe Audited::Auditor do
895
1023
  it "should record usernames" do
896
1024
  Models::ActiveRecord::Company.audit_as( user.name ) do
897
1025
  company = Models::ActiveRecord::Company.create name: 'The auditors'
898
- company.update_attributes name: 'The Auditors'
1026
+ company.update! name: 'The Auditors'
899
1027
 
900
1028
  company.audits.each do |audit|
901
1029
  expect(audit.user).to eq(user.name)
@@ -905,7 +1033,7 @@ describe Audited::Auditor do
905
1033
  end
906
1034
 
907
1035
  describe "after_audit" do
908
- let( :user ) { user = Models::ActiveRecord::UserWithAfterAudit.new }
1036
+ let( :user ) { Models::ActiveRecord::UserWithAfterAudit.new }
909
1037
 
910
1038
  it "should invoke after_audit callback on create" do
911
1039
  expect(user.bogus_attr).to be_nil
@@ -915,7 +1043,7 @@ describe Audited::Auditor do
915
1043
  end
916
1044
 
917
1045
  describe "around_audit" do
918
- let( :user ) { user = Models::ActiveRecord::UserWithAfterAudit.new }
1046
+ let( :user ) { Models::ActiveRecord::UserWithAfterAudit.new }
919
1047
 
920
1048
  it "should invoke around_audit callback on create" do
921
1049
  expect(user.around_attr).to be_nil
@@ -930,7 +1058,7 @@ describe Audited::Auditor do
930
1058
  expect(company.type).to eq("Models::ActiveRecord::Company::STICompany")
931
1059
  expect {
932
1060
  Models::ActiveRecord::Company.auditing_enabled = false
933
- company.update_attributes name: 'STI auditors'
1061
+ company.update! name: 'STI auditors'
934
1062
  Models::ActiveRecord::Company.auditing_enabled = true
935
1063
  }.to_not change( Audited::Audit, :count )
936
1064
  end
@@ -1,5 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
+ SingleCov.covered! uncovered: 2 # 2 conditional on_load conditions
4
+
3
5
  class AuditsController < ActionController::Base
4
6
  before_action :populate_user
5
7
 
@@ -11,7 +13,7 @@ class AuditsController < ActionController::Base
11
13
  end
12
14
 
13
15
  def update
14
- current_user.update_attributes(password: 'foo')
16
+ current_user.update!(password: 'foo')
15
17
  head :ok
16
18
  end
17
19
 
@@ -27,14 +29,13 @@ describe AuditsController do
27
29
  include RSpec::Rails::ControllerExampleGroup
28
30
  render_views
29
31
 
30
- before(:each) do
32
+ before do
31
33
  Audited.current_user_method = :current_user
32
34
  end
33
35
 
34
36
  let(:user) { create_user }
35
37
 
36
38
  describe "POST audit" do
37
-
38
39
  it "should audit user" do
39
40
  controller.send(:current_user=, user)
40
41
  expect {
@@ -44,6 +45,15 @@ describe AuditsController do
44
45
  expect(controller.company.audits.last.user).to eq(user)
45
46
  end
46
47
 
48
+ it "does not audit when method is not found" do
49
+ controller.send(:current_user=, user)
50
+ Audited.current_user_method = :nope
51
+ expect {
52
+ post :create
53
+ }.to change( Audited::Audit, :count )
54
+ expect(controller.company.audits.last.user).to eq(nil)
55
+ end
56
+
47
57
  it "should support custom users for sweepers" do
48
58
  controller.send(:custom_user=, user)
49
59
  Audited.current_user_method = :custom_user
@@ -84,7 +94,6 @@ describe AuditsController do
84
94
 
85
95
  expect(controller.company.audits.last.user).to eq(user)
86
96
  end
87
-
88
97
  end
89
98
 
90
99
  describe "PUT update" do
@@ -92,13 +101,13 @@ describe AuditsController do
92
101
  controller.send(:current_user=, user)
93
102
 
94
103
  expect {
95
- put :update, Rails::VERSION::MAJOR == 4 ? {id: 123} : {params: {id: 123}}
104
+ params = Rails::VERSION::MAJOR == 4 ? {id: 123} : {params: {id: 123}}
105
+ put :update, **params
96
106
  }.to_not change( Audited::Audit, :count )
97
107
  end
98
108
  end
99
109
  end
100
110
 
101
-
102
111
  describe Audited::Sweeper do
103
112
 
104
113
  it "should be thread-safe" do
@@ -20,8 +20,10 @@ module AuditedSpecHelpers
20
20
  def run_migrations(direction, migrations_paths, target_version = nil)
21
21
  if rails_below?('5.2.0.rc1')
22
22
  ActiveRecord::Migrator.send(direction, migrations_paths, target_version)
23
- else
23
+ elsif rails_below?('6.0.0.rc1')
24
24
  ActiveRecord::MigrationContext.new(migrations_paths).send(direction, target_version)
25
+ else
26
+ ActiveRecord::MigrationContext.new(migrations_paths, ActiveRecord::SchemaMigration).send(direction, target_version)
25
27
  end
26
28
  end
27
29
 
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -19,6 +19,7 @@ mysql: &MYSQL
19
19
  username: root
20
20
  password:
21
21
  database: audited_test
22
+ charset: utf8
22
23
 
23
24
  test:
24
25
  <<: *<%= ENV['DB'] || 'SQLITE3MEM' %>
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  ENV['RAILS_ENV'] = 'test'
2
+ require 'bundler/setup'
3
+ require 'single_cov'
4
+ SingleCov.setup :rspec
2
5
 
3
- require 'bundler'
4
6
  if Bundler.definition.dependencies.map(&:name).include?('protected_attributes')
5
7
  require 'protected_attributes'
6
8
  end
@@ -7,6 +7,7 @@ module Models
7
7
  audited except: :password
8
8
  attribute :non_column_attr if Rails.version >= '5.1'
9
9
  attr_protected :logins if respond_to?(:attr_protected)
10
+ enum status: { active: 0, reliable: 1, banned: 2 }
10
11
 
11
12
  def name=(val)
12
13
  write_attribute(:name, CGI.escapeHTML(val))
@@ -24,6 +25,21 @@ module Models
24
25
  audited only: :password
25
26
  end
26
27
 
28
+ class UserRedactedPassword < ::ActiveRecord::Base
29
+ self.table_name = :users
30
+ audited redacted: :password
31
+ end
32
+
33
+ class UserMultipleRedactedAttributes < ::ActiveRecord::Base
34
+ self.table_name = :users
35
+ audited redacted: [:password, :ssn]
36
+ end
37
+
38
+ class UserRedactedPasswordCustomRedaction < ::ActiveRecord::Base
39
+ self.table_name = :users
40
+ audited redacted: :password, redaction_value: ["My", "Custom", "Value", 7]
41
+ end
42
+
27
43
  class CommentRequiredUser < ::ActiveRecord::Base
28
44
  self.table_name = :users
29
45
  audited comment_required: true
@@ -44,6 +60,11 @@ module Models
44
60
  audited comment_required: true, on: :destroy
45
61
  end
46
62
 
63
+ class NoUpdateWithCommentOnlyUser < ::ActiveRecord::Base
64
+ self.table_name = :users
65
+ audited update_with_comment_only: false
66
+ end
67
+
47
68
  class AccessibleAfterDeclarationUser < ::ActiveRecord::Base
48
69
  self.table_name = :users
49
70
  audited
@@ -15,10 +15,10 @@ begin
15
15
  db_config[:configure_connection] = false
16
16
  end
17
17
  adapter = ActiveRecord::Base.send("#{db_type}_connection", db_config)
18
- adapter.recreate_database db_name
18
+ adapter.recreate_database db_name, db_config.slice('charset').symbolize_keys
19
19
  adapter.disconnect!
20
20
  end
21
- rescue Exception => e
21
+ rescue => e
22
22
  Kernel.warn e
23
23
  end
24
24
 
@@ -35,11 +35,13 @@ ActiveRecord::Schema.define do
35
35
  t.column :username, :string
36
36
  t.column :password, :string
37
37
  t.column :activated, :boolean
38
+ t.column :status, :integer, default: 0
38
39
  t.column :suspended_at, :datetime
39
40
  t.column :logins, :integer, default: 0
40
41
  t.column :created_at, :datetime
41
42
  t.column :updated_at, :datetime
42
43
  t.column :favourite_device, :string
44
+ t.column :ssn, :integer
43
45
  end
44
46
 
45
47
  create_table :companies do |t|