relaxo-model 0.18.0 → 0.19.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
  SHA256:
3
- metadata.gz: 43646c8e87ba1baad72dd21037a91817468427e6c990f82ed1f6201d319961f7
4
- data.tar.gz: 3b7e4d1c13908a5fc015e2160e037b3492cf5c41f7ce1b17773de8aaa9bbea6b
3
+ metadata.gz: 63fd2ee103b57f03ebfce40f23dcc3ac05daeb29120b227c18adf4b87d02b33c
4
+ data.tar.gz: 967f316145c175f04f58e0c0bb14c3ce7ec373fc11d02b2a73050d9b7ce8ddbe
5
5
  SHA512:
6
- metadata.gz: 7a34f73d1f6931122401aa1b3c678adf6894ed9c275ee03420f624d732eafeaac28e854a8f192e34ad3fb15eb3bc7bd2b77e72283620bc4fb165d31bc6924c91
7
- data.tar.gz: 0dde3caeb52c3cb6ee779986db3568a7acef6fb1786be0b302505ab0c3ca8788be515c632cab06262ec634d4becf5a3f551168b0b3c0a3ae19593e5d65a2b1eb
6
+ metadata.gz: e8723321b26441adb4bc97ca1003d483ac8bf41531c4cc4f760b198b404ab5d672634faabc36145d1cf90bb0d306e485ee01df4c004ef8309aa77f0cb073129f
7
+ data.tar.gz: bde1b5796ada74badcef1e6cfc870bb6ebafa3b426231a9abfee7e0fc04ac3d40b9a4f6ebbff5a73abdde67117d8a39ff09a3d4264ba35c851aeba708bda0e84
@@ -26,18 +26,18 @@ module Relaxo
26
26
  # Handle conversions for standard datatypes.
27
27
  class Attribute
28
28
  @@attributes = {}
29
-
29
+
30
30
  def self.for_class(klass, &block)
31
31
  @@attributes[klass] = Proc.new(&block)
32
32
  end
33
-
33
+
34
34
  def self.[](klass, proc = nil)
35
35
  self.new(klass, &proc)
36
36
  end
37
-
37
+
38
38
  def initialize(klass, &serialization)
39
39
  @klass = klass
40
-
40
+
41
41
  if block_given?
42
42
  self.instance_eval(&serialization)
43
43
  else
@@ -45,7 +45,7 @@ module Relaxo
45
45
  end
46
46
  end
47
47
  end
48
-
48
+
49
49
  class Serialized
50
50
  def self.[](klass, proc = nil)
51
51
  self.new(klass, &proc)
@@ -63,93 +63,105 @@ module Relaxo
63
63
  @klass.load(value)
64
64
  end
65
65
  end
66
-
66
+
67
67
  Required = Attribute
68
-
68
+
69
69
  class Optional
70
70
  def self.[] klass
71
71
  self.new(klass)
72
72
  end
73
-
73
+
74
74
  def initialize(klass)
75
75
  @klass = klass
76
76
  end
77
77
 
78
+ def blank?(value)
79
+ if value.nil?
80
+ return true
81
+ end
82
+
83
+ if value.respond_to?(:empty?) && value.empty?
84
+ return true
85
+ end
86
+
87
+ return false
88
+ end
89
+
78
90
  def convert_to_primative(value)
79
- if value.nil? or (value.respond_to?(:empty?) and value.empty?)
91
+ if blank?(value)
80
92
  nil
81
93
  else
82
94
  @klass.convert_to_primative(value)
83
95
  end
84
96
  end
85
-
97
+
86
98
  def convert_from_primative(dataset, value)
87
- if value.nil? or value.empty?
99
+ if blank?(value)
88
100
  nil
89
101
  else
90
102
  @klass.convert_from_primative(dataset, value)
91
103
  end
92
104
  end
93
105
  end
94
-
106
+
95
107
  class Boolean
96
108
  end
97
-
109
+
98
110
  Attribute.for_class(Boolean) do
99
111
  def convert_to_primative(value)
100
112
  value ? true : false
101
113
  end
102
-
114
+
103
115
  def convert_from_primative(dataset, value)
104
116
  [true, "on", "true"].include?(value)
105
117
  end
106
118
  end
107
-
119
+
108
120
  Attribute.for_class(Integer) do
109
121
  def convert_to_primative(value)
110
122
  value.to_i
111
123
  end
112
-
124
+
113
125
  def convert_from_primative(dataset, value)
114
126
  value.to_i
115
127
  end
116
128
  end
117
-
129
+
118
130
  Attribute.for_class(Float) do
119
131
  def convert_to_primative(value)
120
132
  value.to_f
121
133
  end
122
-
134
+
123
135
  def convert_from_primative(dataset, value)
124
136
  value.to_f
125
137
  end
126
138
  end
127
-
139
+
128
140
  Attribute.for_class(Date) do
129
141
  def convert_to_primative(value)
130
142
  value.iso8601
131
143
  end
132
-
144
+
133
145
  def convert_from_primative(dataset, value)
134
146
  Date.parse(value)
135
147
  end
136
148
  end
137
-
149
+
138
150
  Attribute.for_class(DateTime) do
139
151
  def convert_to_primative(value)
140
152
  value.iso8601
141
153
  end
142
-
154
+
143
155
  def convert_from_primative(dataset, value)
144
156
  DateTime.parse(value)
145
157
  end
146
158
  end
147
-
159
+
148
160
  Attribute.for_class(String) do
149
161
  def convert_to_primative(value)
150
162
  value.to_s
151
163
  end
152
-
164
+
153
165
  def convert_from_primative(dataset, value)
154
166
  value.to_s
155
167
  end
@@ -46,10 +46,10 @@ module Relaxo
46
46
 
47
47
  def convert_to_primative(document)
48
48
  raise ArgumentError.new("Document must be saved before adding to relationship") unless document.persisted?
49
-
49
+
50
50
  document.paths.first
51
51
  end
52
-
52
+
53
53
  def convert_from_primative(dataset, path)
54
54
  type, _, _ = path.rpartition('/')
55
55
 
@@ -58,7 +58,7 @@ module Relaxo
58
58
  klass.fetch(dataset, path)
59
59
  end
60
60
  end
61
-
61
+
62
62
  class BelongsTo
63
63
  def self.[] *klasses
64
64
  if klasses.size == 1
@@ -67,17 +67,17 @@ module Relaxo
67
67
  Polymorphic.new(klasses)
68
68
  end
69
69
  end
70
-
70
+
71
71
  def initialize(klass)
72
72
  @klass = klass
73
73
  end
74
-
74
+
75
75
  def convert_to_primative(document)
76
76
  raise ArgumentError.new("Document must be saved before adding to relationship") unless document.persisted?
77
77
 
78
78
  document.paths.first
79
79
  end
80
-
80
+
81
81
  def convert_from_primative(dataset, path)
82
82
  @klass.fetch(dataset, path)
83
83
  end
@@ -85,7 +85,7 @@ module Relaxo
85
85
 
86
86
  class HasOne < BelongsTo
87
87
  end
88
-
88
+
89
89
  class HasMany < HasOne
90
90
  def convert_to_primative(documents)
91
91
  documents.each do |document|
@@ -94,7 +94,7 @@ module Relaxo
94
94
 
95
95
  documents.collect{|document| document.paths.first}
96
96
  end
97
-
97
+
98
98
  def convert_from_primative(dataset, value)
99
99
  value.collect{|id| @klass.fetch(dataset, id)}
100
100
  end
@@ -115,13 +115,13 @@ module Relaxo
115
115
  def initialize(klass)
116
116
  @klass = Attribute.new(klass)
117
117
  end
118
-
118
+
119
119
  def convert_to_primative(value)
120
120
  value.collect do |item|
121
121
  @klass.convert_to_primative(item)
122
122
  end
123
123
  end
124
-
124
+
125
125
  def convert_from_primative(dataset, value)
126
126
  value.collect do |item|
127
127
  @klass.convert_from_primative(dataset, item)
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Relaxo
22
22
  module Model
23
- VERSION = "0.18.0"
23
+ VERSION = "0.19.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaxo-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-01 00:00:00.000000000 Z
11
+ date: 2020-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -52,34 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: bake-bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: bake-modernize
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
55
  - !ruby/object:Gem::Dependency
84
56
  name: bundler
85
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,8 +94,8 @@ dependencies:
122
94
  - - "~>"
123
95
  - !ruby/object:Gem::Version
124
96
  version: '3.4'
125
- description:
126
- email:
97
+ description:
98
+ email:
127
99
  executables: []
128
100
  extensions: []
129
101
  extra_rdoc_files: []
@@ -142,17 +114,11 @@ files:
142
114
  - lib/relaxo/model/properties/uuid.rb
143
115
  - lib/relaxo/model/recordset.rb
144
116
  - lib/relaxo/model/version.rb
145
- - spec/relaxo/model/attribute_spec.rb
146
- - spec/relaxo/model/document_spec.rb
147
- - spec/relaxo/model/model_context.rb
148
- - spec/relaxo/model/properties/bcrypt_spec.rb
149
- - spec/relaxo/model/recordset_spec.rb
150
- - spec/spec_helper.rb
151
- homepage: http://www.codeotaku.com/projects/relaxo/model
117
+ homepage: https://github.com/ioquatix/relaxo-model
152
118
  licenses:
153
119
  - MIT
154
120
  metadata: {}
155
- post_install_message:
121
+ post_install_message:
156
122
  rdoc_options: []
157
123
  require_paths:
158
124
  - lib
@@ -160,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
126
  requirements:
161
127
  - - ">="
162
128
  - !ruby/object:Gem::Version
163
- version: '0'
129
+ version: '2.5'
164
130
  required_rubygems_version: !ruby/object:Gem::Requirement
165
131
  requirements:
166
132
  - - ">="
@@ -168,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
134
  version: '0'
169
135
  requirements: []
170
136
  rubygems_version: 3.1.2
171
- signing_key:
137
+ signing_key:
172
138
  specification_version: 4
173
139
  summary: A model layer for the relaxo document database.
174
140
  test_files: []
@@ -1,57 +0,0 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'relaxo/model'
22
-
23
- class Aggregate
24
- include Relaxo::Model
25
-
26
- property :id, UUID
27
- property :array_value
28
- property :hash_value
29
- end
30
-
31
- RSpec.describe Relaxo::Model::Document do
32
- let(:database_path) {'tmp/attributes'}
33
- let(:database) {Relaxo.connect(database_path)}
34
-
35
- let(:document_path) {'test/document.json'}
36
-
37
- before(:each) {FileUtils.rm_rf(database_path)}
38
-
39
- it "should create and save document" do
40
- model = Aggregate.create(database.current,
41
- array_value: [1, 2, 3],
42
- hash_value: {x: 10, y: 20}
43
- )
44
-
45
- expect(model).to be_changed(:array_value)
46
-
47
- database.commit(message: "Adding test model") do |dataset|
48
- model.save(dataset)
49
- end
50
-
51
- # Force all attributes to be reloaded from the object store:
52
- model.reload
53
-
54
- expect(model.array_value).to be_kind_of Array
55
- expect(model.hash_value).to be_kind_of Hash
56
- end
57
- end
@@ -1,152 +0,0 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require_relative 'model_context'
22
-
23
- RSpec.describe Relaxo::Model::Document do
24
- include_context "model"
25
-
26
- it "should create and save document" do
27
- model = Invoice.create(database.current,
28
- name: "Software Development"
29
- )
30
-
31
- expect(model.persisted?).to be_falsey
32
-
33
- database.commit(message: "Adding test model") do |dataset|
34
- model.save(dataset)
35
- end
36
-
37
- expect(model.id).to_not be nil
38
- expect(model.persisted?).to be_truthy
39
- end
40
-
41
- it "should enumerate model objects" do
42
- database.commit(message: "Adding test model") do |dataset|
43
- Invoice.insert(dataset, name: "Software Development")
44
- Invoice.insert(dataset, name: "Website Hosting")
45
- Invoice.insert(dataset, name: "Backup Services")
46
- end
47
-
48
- expect(Invoice.all(database.current).count).to be == 3
49
- end
50
-
51
- it "should have valid type" do
52
- expect(Invoice.type).to be == "invoice"
53
- expect(Invoice::Transaction.type).to be == "invoice/transaction"
54
- end
55
-
56
- it "should have resolved type" do
57
- transaction = Invoice::Transaction.create(database.current, {id: 'test'})
58
-
59
- transaction.attributes[:type] = ["Invoice", "Transaction"]
60
-
61
- expect(transaction.paths.first).to be == "Invoice/Transaction/test"
62
- end
63
-
64
- it "should create model indexes" do
65
- database.commit(message: "Adding test model") do |dataset|
66
- invoice = Invoice.create(dataset, name: "Software Development")
67
- invoice.save(dataset)
68
-
69
- transaction = Invoice::Transaction.create(dataset, date: Date.today, invoice: invoice)
70
- transaction.save(dataset)
71
- end
72
-
73
- expect(Invoice.all(database.current).count).to be == 1
74
- expect(Invoice::Transaction.all(database.current).count).to be == 1
75
-
76
- invoice = Invoice.all(database.current).first
77
- expect(invoice).to_not be nil
78
-
79
- transactions = Invoice::Transaction.by_invoice(database.current, invoice: invoice)
80
- expect(transactions.path).to be == "invoice/transaction/by_invoice/invoice/#{invoice.id}"
81
- expect(transactions).to_not be_empty
82
-
83
- transaction = transactions.first
84
- expect(transaction.to_s).to be == "invoice/transaction/#{transaction.id}"
85
- end
86
-
87
- it "can edit model objects" do
88
- invoice = nil
89
-
90
- database.commit(message: "Adding test model") do |dataset|
91
- invoice = Invoice.create(dataset, name: "Software Development")
92
- invoice.save(dataset)
93
- end
94
-
95
- # Fetch the invoice from the database:
96
- invoice = Invoice.fetch_all(database.current, id: invoice.id)
97
- invoice.name = "Software Engineering"
98
-
99
- database.commit(message: "Editing test model") do |dataset|
100
- invoice.save(dataset)
101
- end
102
-
103
- invoice = Invoice.fetch_all(database.current, id: invoice.id)
104
- expect(invoice.name).to be == "Software Engineering"
105
- end
106
-
107
- it "updates indexes correctly" do
108
- transaction = nil
109
-
110
- database.commit(message: "Adding test model") do |dataset|
111
- invoice = Invoice.create(dataset, name: "Software Development")
112
- invoice.save(dataset)
113
-
114
- transaction = Invoice::Transaction.create(dataset, date: Date.today, invoice: invoice)
115
- transaction.save(dataset)
116
- end
117
-
118
- transactions = Invoice::Transaction.all(database.current)
119
-
120
- database.commit(message: "Adding test model") do |dataset|
121
- transaction.date = Date.today - 1
122
- transaction.save(dataset)
123
- end
124
-
125
- transactions = Invoice::Transaction.all(database.current)
126
- end
127
-
128
- it "can query by index" do
129
- database.commit(message: 'Adding new users.') do |changes|
130
- User.insert(changes, email: 'john.doe@aol.com', name: 'John Doe')
131
- User.insert(changes, email: 'jane.doe@aol.com', name: 'Jane Doe')
132
- end
133
-
134
- expect(User.fetch_all(database.current, email: 'john.doe@aol.com').name).to be == 'John Doe'
135
- end
136
-
137
- it "can handle indexes with reserved characters" do
138
- database.commit(message: "Add new user") do |changeset|
139
- User.insert(changeset, email: "its@complicated.com", name: "/John/James/")
140
- end
141
-
142
- expect(User.fetch_all(database.current, email: 'its@complicated.com').name).to be == '/John/James/'
143
- end
144
-
145
- it "can handle indexes with unicode" do
146
- database.commit(message: "Add new user") do |changeset|
147
- User.insert(changeset, email: "its@complicated.com", name: "こんにちは")
148
- end
149
-
150
- expect(User.fetch_by_name(database.current, name: "こんにちは")).to_not be nil
151
- end
152
- end
@@ -1,81 +0,0 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'relaxo/model'
22
- require 'relaxo/model/properties/bcrypt'
23
-
24
- class Invoice
25
- class Transaction; end
26
-
27
- include Relaxo::Model
28
-
29
- property :id, UUID
30
- property :number
31
- property :name
32
-
33
- property :date, Attribute[Date]
34
-
35
- view :all, :type, index: :id
36
-
37
- def transactions
38
- Invoice::Transaction.by_invoice(@dataset, invoice: self)
39
- end
40
- end
41
-
42
- class Invoice::Transaction
43
- include Relaxo::Model
44
-
45
- parent_type Invoice
46
-
47
- property :id, UUID
48
- property :invoice, BelongsTo[Invoice]
49
- property :date, Attribute[Date]
50
-
51
- def year
52
- date.year
53
- end
54
-
55
- view :all, :type, index: :id
56
-
57
- view :by_invoice, index: unique(:date, :id)
58
- view :by_year, :type, 'by_year', index: unique(:year)
59
- end
60
-
61
- class User
62
- include Relaxo::Model
63
-
64
- property :email, Attribute[String]
65
- property :name
66
- property :password, Attribute[BCrypt::Password]
67
- property :intro
68
-
69
- view :all, :type, index: unique(:email)
70
-
71
- view :by_name, :type, 'by_name', index: unique(:name)
72
- end
73
-
74
- RSpec.shared_context "model" do
75
- let(:database_path) {'tmp/model'}
76
- let(:database) {Relaxo.connect(database_path)}
77
-
78
- let(:document_path) {'test/document.json'}
79
-
80
- before(:each) {FileUtils.rm_rf(database_path)}
81
- end
@@ -1,81 +0,0 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require_relative '../model_context'
22
-
23
- RSpec.describe Relaxo::Model::Properties do
24
- context BCrypt::Password do
25
- include_context "model"
26
-
27
- it "can set password string" do
28
- database.commit(message: "Add new user") do |changeset|
29
- User.insert(changeset, email: "its@complicated.com", name: "Bob", password: "foobar")
30
- end
31
-
32
- bob = User.fetch_by_name(database.current, name: "Bob")
33
- expect(bob).to_not be nil
34
-
35
- expect(bob.password == "foobar").to be_truthy
36
- end
37
-
38
- it "can set password instance" do
39
- database.commit(message: "Add new user") do |changeset|
40
- User.insert(changeset, email: "its@complicated.com", name: "Bob", password: BCrypt::Password.create("foobar"))
41
- end
42
-
43
- bob = User.fetch_by_name(database.current, name: "Bob")
44
- expect(bob).to_not be nil
45
-
46
- expect(bob.password == "foobar").to be_truthy
47
- end
48
-
49
- it "can assign password string" do
50
- database.commit(message: "Add new user") do |changeset|
51
- user = User.insert(changeset, email: "its@complicated.com", name: "Bob")
52
-
53
- user.assign(password: "foobar")
54
-
55
- user.save(changeset)
56
- end
57
-
58
- bob = User.fetch_by_name(database.current, name: "Bob")
59
- expect(bob).to_not be nil
60
-
61
- expect(bob.password == "foobar").to be_truthy
62
- end
63
-
64
- it "can assign password hash" do
65
- password = BCrypt::Password.create("foobar")
66
-
67
- database.commit(message: "Add new user") do |changeset|
68
- user = User.insert(changeset, email: "its@complicated.com", name: "Bob")
69
-
70
- user.assign(password: password.to_s)
71
-
72
- user.save(changeset)
73
- end
74
-
75
- bob = User.fetch_by_name(database.current, name: "Bob")
76
- expect(bob).to_not be nil
77
-
78
- expect(bob.password == "foobar").to be_truthy
79
- end
80
- end
81
- end
@@ -1,45 +0,0 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require_relative 'model_context'
22
-
23
- RSpec.describe Relaxo::Model::Recordset do
24
- include_context 'model'
25
-
26
- context "with several invoices" do
27
- before(:each) do
28
- database.commit(message: "Adding test model") do |dataset|
29
- @first = Invoice.insert(dataset, id: "a", name: "Software Development")
30
- @middle = Invoice.insert(dataset, id: "b", name: "Website Hosting")
31
- @last = Invoice.insert(dataset, id: "c", name: "Backup Services")
32
- end
33
- end
34
-
35
- it "should have a first and last invoice" do
36
- recordset = Invoice.all(database.current)
37
-
38
- expect(recordset.count).to be == 3
39
- expect(recordset).to_not be_empty
40
-
41
- expect(recordset.first).to be == @first
42
- expect(recordset.last).to be == @last
43
- end
44
- end
45
- end
@@ -1,31 +0,0 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require "bundler/setup"
22
- require "covered/rspec"
23
-
24
- RSpec.configure do |config|
25
- # Enable flags like --only-failures and --next-failure
26
- config.example_status_persistence_file_path = ".rspec_status"
27
-
28
- config.expect_with :rspec do |c|
29
- c.syntax = :expect
30
- end
31
- end