relaxo-model 0.12.1 → 0.13.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baa54b93545e3c7e489fcdb605dbd7aeb216ad69
|
4
|
+
data.tar.gz: f175fdcf840161c8af177715f6e0fc712e14b3ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b93c725265744543dbd0bdce343ec5ffa0f9bd02fa70ad25abce0a7d01bdb3e92c5b73c1fd149463d7403c0ba30b755508dee4d8229b4e00ba5c7908254b41
|
7
|
+
data.tar.gz: 3b859844d5a4128604a0c55b8c8cd5d60a14af3bc47733d6bde81bae397c14f93684013fe09649bcd8446eb1eadd98c926a002ad2074c4be97b72de4e57b6540
|
data/Gemfile
CHANGED
@@ -25,16 +25,22 @@ module Relaxo
|
|
25
25
|
module Properties
|
26
26
|
Attribute.for_class(BCrypt::Password) do
|
27
27
|
def convert_to_primative(value)
|
28
|
+
unless value.is_a? BCrypt::Password
|
29
|
+
value = BCrypt::Password.create(value)
|
30
|
+
end
|
31
|
+
|
28
32
|
[value.salt, value.checksum]
|
29
33
|
end
|
30
34
|
|
31
35
|
def convert_from_primative(dataset, value)
|
32
|
-
if
|
33
|
-
#
|
34
|
-
BCrypt::Password.create(value)
|
35
|
-
else
|
36
|
-
# Otherwise the password is given by an array containing the salt and checksum:
|
36
|
+
if value.is_a? Array
|
37
|
+
# The password is given by an array containing the salt and checksum:
|
37
38
|
BCrypt::Password.new(value.join)
|
39
|
+
elsif BCrypt::Password.valid_hash?(value)
|
40
|
+
BCrypt::Password.new(value)
|
41
|
+
else
|
42
|
+
# Try to create a password from the supplied value:
|
43
|
+
BCrypt::Password.create(value)
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|
data/lib/relaxo/model/version.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
require 'relaxo/model'
|
3
3
|
|
4
|
+
require 'relaxo/model/properties/bcrypt'
|
5
|
+
|
4
6
|
class Invoice
|
5
7
|
class Transaction; end
|
6
8
|
|
@@ -43,6 +45,7 @@ class User
|
|
43
45
|
|
44
46
|
property :email, Attribute[String]
|
45
47
|
property :name
|
48
|
+
property :password, Attribute[BCrypt::Password]
|
46
49
|
property :intro
|
47
50
|
|
48
51
|
view :all, :type, index: unique(:email)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
require_relative '../model_context'
|
3
|
+
|
4
|
+
RSpec.describe Relaxo::Model::Properties do
|
5
|
+
context BCrypt::Password do
|
6
|
+
include_context "model"
|
7
|
+
|
8
|
+
it "can set password string" do
|
9
|
+
database.commit(message: "Add new user") do |changeset|
|
10
|
+
User.insert(changeset, email: "its@complicated.com", name: "Bob", password: "foobar")
|
11
|
+
end
|
12
|
+
|
13
|
+
bob = User.fetch_by_name(database.current, name: "Bob")
|
14
|
+
expect(bob).to_not be nil
|
15
|
+
|
16
|
+
expect(bob.password == "foobar").to be_truthy
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can set password instance" do
|
20
|
+
database.commit(message: "Add new user") do |changeset|
|
21
|
+
User.insert(changeset, email: "its@complicated.com", name: "Bob", password: BCrypt::Password.create("foobar"))
|
22
|
+
end
|
23
|
+
|
24
|
+
bob = User.fetch_by_name(database.current, name: "Bob")
|
25
|
+
expect(bob).to_not be nil
|
26
|
+
|
27
|
+
expect(bob.password == "foobar").to be_truthy
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can assign password string" do
|
31
|
+
database.commit(message: "Add new user") do |changeset|
|
32
|
+
user = User.insert(changeset, email: "its@complicated.com", name: "Bob")
|
33
|
+
|
34
|
+
user.assign(password: "foobar")
|
35
|
+
|
36
|
+
user.save(changeset)
|
37
|
+
end
|
38
|
+
|
39
|
+
bob = User.fetch_by_name(database.current, name: "Bob")
|
40
|
+
expect(bob).to_not be nil
|
41
|
+
|
42
|
+
expect(bob.password == "foobar").to be_truthy
|
43
|
+
end
|
44
|
+
|
45
|
+
it "can assign password hash" do
|
46
|
+
password = BCrypt::Password.create("foobar")
|
47
|
+
|
48
|
+
database.commit(message: "Add new user") do |changeset|
|
49
|
+
user = User.insert(changeset, email: "its@complicated.com", name: "Bob")
|
50
|
+
|
51
|
+
user.assign(password: password.to_s)
|
52
|
+
|
53
|
+
user.save(changeset)
|
54
|
+
end
|
55
|
+
|
56
|
+
bob = User.fetch_by_name(database.current, name: "Bob")
|
57
|
+
expect(bob).to_not be nil
|
58
|
+
|
59
|
+
expect(bob.password == "foobar").to be_truthy
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaxo-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- spec/relaxo/model/attribute_spec.rb
|
114
114
|
- spec/relaxo/model/document_spec.rb
|
115
115
|
- spec/relaxo/model/model_context.rb
|
116
|
+
- spec/relaxo/model/properties/bcrypt_spec.rb
|
116
117
|
- spec/relaxo/model/recordset_spec.rb
|
117
118
|
homepage: http://www.codeotaku.com/projects/relaxo/model
|
118
119
|
licenses:
|
@@ -142,4 +143,5 @@ test_files:
|
|
142
143
|
- spec/relaxo/model/attribute_spec.rb
|
143
144
|
- spec/relaxo/model/document_spec.rb
|
144
145
|
- spec/relaxo/model/model_context.rb
|
146
|
+
- spec/relaxo/model/properties/bcrypt_spec.rb
|
145
147
|
- spec/relaxo/model/recordset_spec.rb
|