relaxo-model 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47752f1b7559c0d9655e5e672a02be42349906ff
4
- data.tar.gz: 35fadf3fe42a32cd640272232224f3f92fef8c90
3
+ metadata.gz: baa54b93545e3c7e489fcdb605dbd7aeb216ad69
4
+ data.tar.gz: f175fdcf840161c8af177715f6e0fc712e14b3ab
5
5
  SHA512:
6
- metadata.gz: e02d21e29e82f65f25a08c3580db7028c770d35f84810a38821065bf49b695c4b190f18e63226de8e722c8148f7145c61a2d5f3dbda715996053a49e3309e6b9
7
- data.tar.gz: dbe2d8acaf7fc724a6fb63c4b7ca1d0d9ea4067dfbcfb410f6af98d0e0a3fcb19b057601743cea5bf85f4e7a3136ce12fa59e88c45b2067a23624a4ce915ad3c
6
+ metadata.gz: a3b93c725265744543dbd0bdce343ec5ffa0f9bd02fa70ad25abce0a7d01bdb3e92c5b73c1fd149463d7403c0ba30b755508dee4d8229b4e00ba5c7908254b41
7
+ data.tar.gz: 3b859844d5a4128604a0c55b8c8cd5d60a14af3bc47733d6bde81bae397c14f93684013fe09649bcd8446eb1eadd98c926a002ad2074c4be97b72de4e57b6540
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gem 'rugged', git: 'git://github.com/libgit2/rugged.git', submodules: true
7
7
 
8
8
  group :development do
9
9
  gem "pry"
10
+ gem "bcrypt"
10
11
  end
11
12
 
12
13
  group :test do
@@ -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 String === value
33
- # If the primative value is a string, we are saving the password:
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
@@ -29,7 +29,7 @@ module Relaxo
29
29
  end
30
30
 
31
31
  def convert_from_primative(dataset, value)
32
- if Array === value
32
+ if value.is_a? Array
33
33
  @klass.new(value[0], value[1])
34
34
  else
35
35
  @klass.parse(value)
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Relaxo
22
22
  module Model
23
- VERSION = "0.12.1"
23
+ VERSION = "0.13.0"
24
24
  end
25
25
  end
@@ -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.12.1
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