Skip to content

Commit ba53749

Browse files
committed
[PasswordAuth] do not check for column when table doesn't exist
1 parent ad09e55 commit ba53749

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

lib/rails/concerns.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "rails/concerns/version"
2+
require "rails/concerns/helpers"
23

34
module Rails
45
module Concerns

lib/rails/concerns/helpers.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Rails
2+
module Concerns
3+
module Helpers
4+
def require_column base, column_name
5+
if base.table_exists? and base.columns.map(&:name).exclude?(column_name)
6+
raise NotImplementedError, "#{base} must have '#{column_name}' column"
7+
end
8+
end
9+
end
10+
end
11+
end

lib/rails/concerns/models/password_auth.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require "bcrypt"
22

33
module PasswordAuth
4+
extend Rails::Concerns::Helpers
5+
46
def self.included base
5-
if base.columns.map(&:name).exclude? "encrypted_password"
6-
raise NotImplementedError, "model must have 'encrypted_password' column"
7-
end
7+
require_column base, "encrypted_password"
88
end
99

1010
def password= unencrypted_password

spec/models/password_auth_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "spec_helper"
2+
require "rails/concerns/helpers"
23
require "models/password_auth"
34

45
ActiveRecord::Migration.create_table :users do |t|

0 commit comments

Comments
 (0)