relaxo-model 0.17.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/relaxo/model/base.rb +2 -2
- data/lib/relaxo/model/component.rb +26 -22
- data/lib/relaxo/model/document.rb +16 -20
- data/lib/relaxo/model/properties/attribute.rb +36 -24
- data/lib/relaxo/model/properties/composite.rb +10 -10
- data/lib/relaxo/model/version.rb +1 -1
- metadata +27 -49
- data/.gitignore +0 -12
- data/.rspec +0 -4
- data/.travis.yml +0 -20
- data/Gemfile +0 -11
- data/README.md +0 -119
- data/Rakefile +0 -17
- data/relaxo-model.gemspec +0 -30
- data/spec/relaxo/model/attribute_spec.rb +0 -55
- data/spec/relaxo/model/document_spec.rb +0 -152
- data/spec/relaxo/model/model_context.rb +0 -81
- data/spec/relaxo/model/properties/bcrypt_spec.rb +0 -81
- data/spec/relaxo/model/recordset_spec.rb +0 -45
- data/spec/spec_helper.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63fd2ee103b57f03ebfce40f23dcc3ac05daeb29120b227c18adf4b87d02b33c
|
4
|
+
data.tar.gz: 967f316145c175f04f58e0c0bb14c3ce7ec373fc11d02b2a73050d9b7ce8ddbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8723321b26441adb4bc97ca1003d483ac8bf41531c4cc4f760b198b404ab5d672634faabc36145d1cf90bb0d306e485ee01df4c004ef8309aa77f0cb073129f
|
7
|
+
data.tar.gz: bde1b5796ada74badcef1e6cfc870bb6ebafa3b426231a9abfee7e0fc04ac3d40b9a4f6ebbff5a73abdde67117d8a39ff09a3d4264ba35c851aeba708bda0e84
|
data/lib/relaxo/model/base.rb
CHANGED
@@ -120,9 +120,9 @@ module Relaxo
|
|
120
120
|
@properties[name] = klass
|
121
121
|
|
122
122
|
self.send(:define_method, name) do
|
123
|
-
if @changed.include?
|
123
|
+
if @changed.include?(name)
|
124
124
|
return @changed[name]
|
125
|
-
elsif @attributes.include?
|
125
|
+
elsif @attributes.include?(name)
|
126
126
|
if klass
|
127
127
|
value = @attributes[name]
|
128
128
|
|
@@ -54,6 +54,10 @@ module Relaxo
|
|
54
54
|
# Attributes that have been changed or de-serialized from the dataset:
|
55
55
|
attr :changed
|
56
56
|
|
57
|
+
def changed?(key)
|
58
|
+
@changed.include?(key)
|
59
|
+
end
|
60
|
+
|
57
61
|
def reload(dataset = @dataset)
|
58
62
|
@dataset = dataset
|
59
63
|
@changed.clear
|
@@ -64,32 +68,32 @@ module Relaxo
|
|
64
68
|
@changed.delete(key)
|
65
69
|
@attributes.delete(key)
|
66
70
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
enumerator = enumerator.select{|key, value| self.class.properties.include? key.to_sym}
|
73
|
-
elsif only.respond_to? :include?
|
74
|
-
enumerator = enumerator.select{|key, value| only.include? key.to_sym}
|
75
|
-
end
|
76
|
-
|
77
|
-
enumerator.each do |key, value|
|
71
|
+
|
72
|
+
ALL = Hash.new(true)
|
73
|
+
|
74
|
+
def assign(primative_attributes, only = ALL)
|
75
|
+
primative_attributes.each do |key, value|
|
78
76
|
key = key.to_sym
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
case mapping = only[key]
|
78
|
+
when true
|
79
|
+
# Assign from primitive value:
|
80
|
+
if klass = self.class.properties[key]
|
81
|
+
value = klass.convert_from_primative(@dataset, value)
|
82
|
+
end
|
83
|
+
|
84
|
+
self[key] = value
|
85
|
+
when false, nil
|
86
|
+
# Ignore:
|
87
|
+
next
|
88
|
+
else
|
89
|
+
# Nested assignment:
|
90
|
+
self[key].assign(value, mapping)
|
85
91
|
end
|
86
|
-
|
87
|
-
self[key] = value
|
88
92
|
end
|
89
93
|
|
90
94
|
return self
|
91
95
|
end
|
92
|
-
|
96
|
+
|
93
97
|
def [] name
|
94
98
|
if self.class.properties.include? name
|
95
99
|
self.send(name)
|
@@ -97,7 +101,7 @@ module Relaxo
|
|
97
101
|
raise KeyError.new(name)
|
98
102
|
end
|
99
103
|
end
|
100
|
-
|
104
|
+
|
101
105
|
def []= name, value
|
102
106
|
if self.class.properties.include? name
|
103
107
|
self.send("#{name}=", value)
|
@@ -105,7 +109,7 @@ module Relaxo
|
|
105
109
|
raise KeyError.new(name)
|
106
110
|
end
|
107
111
|
end
|
108
|
-
|
112
|
+
|
109
113
|
def validate(changeset)
|
110
114
|
# Do nothing :)
|
111
115
|
end
|
@@ -79,7 +79,7 @@ module Relaxo
|
|
79
79
|
# Fetch a record or create a model object from a hash of attributes.
|
80
80
|
def fetch(dataset, path = nil, **attributes)
|
81
81
|
if path and object = dataset.read(path)
|
82
|
-
instance = self.new(dataset, object, attributes)
|
82
|
+
instance = self.new(dataset, object, **attributes)
|
83
83
|
|
84
84
|
instance.load_object
|
85
85
|
|
@@ -100,10 +100,6 @@ module Relaxo
|
|
100
100
|
@object != nil
|
101
101
|
end
|
102
102
|
|
103
|
-
def changed? key
|
104
|
-
@changed.include? key.to_s
|
105
|
-
end
|
106
|
-
|
107
103
|
def type
|
108
104
|
@attributes[:type]
|
109
105
|
end
|
@@ -113,7 +109,7 @@ module Relaxo
|
|
113
109
|
end
|
114
110
|
|
115
111
|
# Update any calculations:
|
116
|
-
def before_save
|
112
|
+
def before_save(changeset)
|
117
113
|
end
|
118
114
|
|
119
115
|
def after_save
|
@@ -147,39 +143,39 @@ module Relaxo
|
|
147
143
|
|
148
144
|
self.class.keys.each do |name, key|
|
149
145
|
# @attributes is not modified until we call self.dump (which flattens @attributes into @changes). When we generate paths, we want to ensure these are done based on the non-mutable state of the object.
|
150
|
-
yield key.object_path(self,
|
146
|
+
yield key.object_path(self, **@attributes)
|
151
147
|
end
|
152
148
|
end
|
153
149
|
|
154
150
|
# Save the model object.
|
155
|
-
def save(
|
156
|
-
|
151
|
+
def save(changeset)
|
152
|
+
before_save(changeset)
|
157
153
|
|
158
|
-
|
154
|
+
return if persisted? and @changed.empty?
|
159
155
|
|
160
|
-
if errors = self.validate(
|
156
|
+
if errors = self.validate(changeset)
|
161
157
|
return errors
|
162
158
|
end
|
163
159
|
|
164
160
|
existing_paths = persisted? ? paths.to_a : []
|
165
161
|
|
166
162
|
# Write data, check if any actual changes made:
|
167
|
-
object =
|
163
|
+
object = changeset.append(self.dump)
|
168
164
|
return if object == @object
|
169
165
|
|
170
166
|
existing_paths.each do |path|
|
171
|
-
|
167
|
+
changeset.delete(path)
|
172
168
|
end
|
173
169
|
|
174
170
|
paths do |path|
|
175
|
-
if
|
171
|
+
if changeset.exist?(path)
|
176
172
|
raise KeyError, "Dataset already contains path: #{path}, when inserting #{@attributes.inspect}"
|
177
173
|
end
|
178
174
|
|
179
|
-
|
175
|
+
changeset.write(path, object)
|
180
176
|
end
|
181
177
|
|
182
|
-
@dataset =
|
178
|
+
@dataset = changeset
|
183
179
|
@object = object
|
184
180
|
|
185
181
|
after_save
|
@@ -187,8 +183,8 @@ module Relaxo
|
|
187
183
|
return true
|
188
184
|
end
|
189
185
|
|
190
|
-
def save!(
|
191
|
-
result = self.save(
|
186
|
+
def save!(changeset)
|
187
|
+
result = self.save(changeset)
|
192
188
|
|
193
189
|
if result != true
|
194
190
|
raise ValidationFailure.new(self, result)
|
@@ -203,13 +199,13 @@ module Relaxo
|
|
203
199
|
def after_delete
|
204
200
|
end
|
205
201
|
|
206
|
-
def delete(
|
202
|
+
def delete(changeset)
|
207
203
|
before_delete
|
208
204
|
|
209
205
|
@changed.clear
|
210
206
|
|
211
207
|
paths.each do |path|
|
212
|
-
|
208
|
+
changeset.delete(path)
|
213
209
|
end
|
214
210
|
|
215
211
|
after_delete
|
@@ -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
|
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
|
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)
|
data/lib/relaxo/model/version.rb
CHANGED
metadata
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaxo-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 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-
|
11
|
+
date: 2020-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: msgpack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: relaxo
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.5'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: bake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -67,48 +67,39 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: covered
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '3.4'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
97
|
-
description:
|
98
|
-
While it supports some traditional ORM style patterns, it is\n\t\tprimary focus
|
99
|
-
is to model business processes and logic.\n"
|
96
|
+
version: '3.4'
|
97
|
+
description:
|
100
98
|
email:
|
101
|
-
- samuel.williams@oriontransfer.co.nz
|
102
99
|
executables: []
|
103
100
|
extensions: []
|
104
101
|
extra_rdoc_files: []
|
105
102
|
files:
|
106
|
-
- ".gitignore"
|
107
|
-
- ".rspec"
|
108
|
-
- ".travis.yml"
|
109
|
-
- Gemfile
|
110
|
-
- README.md
|
111
|
-
- Rakefile
|
112
103
|
- lib/relaxo/model.rb
|
113
104
|
- lib/relaxo/model/base.rb
|
114
105
|
- lib/relaxo/model/component.rb
|
@@ -123,18 +114,11 @@ files:
|
|
123
114
|
- lib/relaxo/model/properties/uuid.rb
|
124
115
|
- lib/relaxo/model/recordset.rb
|
125
116
|
- lib/relaxo/model/version.rb
|
126
|
-
|
127
|
-
- spec/relaxo/model/attribute_spec.rb
|
128
|
-
- spec/relaxo/model/document_spec.rb
|
129
|
-
- spec/relaxo/model/model_context.rb
|
130
|
-
- spec/relaxo/model/properties/bcrypt_spec.rb
|
131
|
-
- spec/relaxo/model/recordset_spec.rb
|
132
|
-
- spec/spec_helper.rb
|
133
|
-
homepage: http://www.codeotaku.com/projects/relaxo/model
|
117
|
+
homepage: https://github.com/ioquatix/relaxo-model
|
134
118
|
licenses:
|
135
119
|
- MIT
|
136
120
|
metadata: {}
|
137
|
-
post_install_message:
|
121
|
+
post_install_message:
|
138
122
|
rdoc_options: []
|
139
123
|
require_paths:
|
140
124
|
- lib
|
@@ -142,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
126
|
requirements:
|
143
127
|
- - ">="
|
144
128
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
129
|
+
version: '2.5'
|
146
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
131
|
requirements:
|
148
132
|
- - ">="
|
@@ -150,13 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
134
|
version: '0'
|
151
135
|
requirements: []
|
152
136
|
rubygems_version: 3.1.2
|
153
|
-
signing_key:
|
137
|
+
signing_key:
|
154
138
|
specification_version: 4
|
155
|
-
summary: A model layer for
|
156
|
-
test_files:
|
157
|
-
- spec/relaxo/model/attribute_spec.rb
|
158
|
-
- spec/relaxo/model/document_spec.rb
|
159
|
-
- spec/relaxo/model/model_context.rb
|
160
|
-
- spec/relaxo/model/properties/bcrypt_spec.rb
|
161
|
-
- spec/relaxo/model/recordset_spec.rb
|
162
|
-
- spec/spec_helper.rb
|
139
|
+
summary: A model layer for the relaxo document database.
|
140
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
dist: xenial
|
3
|
-
cache: bundler
|
4
|
-
|
5
|
-
matrix:
|
6
|
-
include:
|
7
|
-
- rvm: 2.4
|
8
|
-
- rvm: 2.5
|
9
|
-
- rvm: 2.6
|
10
|
-
- rvm: 2.6
|
11
|
-
env: COVERAGE=PartialSummary,Coveralls
|
12
|
-
- rvm: truffleruby
|
13
|
-
- rvm: ruby-head
|
14
|
-
- rvm: 2.6
|
15
|
-
os: osx
|
16
|
-
allow_failures:
|
17
|
-
- rvm: truffleruby
|
18
|
-
- rvm: ruby-head
|
19
|
-
- rvm: jruby-head
|
20
|
-
- rvm: truffleruby
|
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
# Relaxo Model
|
2
|
-
|
3
|
-
Relaxo Model provides a framework for business logic on top of Relaxo, a document data store built on top of git. While it supports some traditional relational style patterns, it is primary focus is to model business processes and logic at the document level.
|
4
|
-
|
5
|
-
[![Build Status](https://secure.travis-ci.org/ioquatix/relaxo-model.svg)](http://travis-ci.org/ioquatix/relaxo-model)
|
6
|
-
[![Code Climate](https://codeclimate.com/github/ioquatix/relaxo-model.svg)](https://codeclimate.com/github/ioquatix/relaxo-model)
|
7
|
-
[![Coverage Status](https://coveralls.io/repos/ioquatix/relaxo-model/badge.svg)](https://coveralls.io/r/ioquatix/relaxo-model)
|
8
|
-
|
9
|
-
## Basic Usage
|
10
|
-
|
11
|
-
Here is a simple example of a traditional ORM style model:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
require 'relaxo/model'
|
15
|
-
|
16
|
-
database = Relaxo.connect("test")
|
17
|
-
|
18
|
-
trees = [
|
19
|
-
{:name => 'Hinoki', :planted => Date.parse("2013/11/17")},
|
20
|
-
{:name => 'Keyaki', :planted => Date.parse("2016/9/24")}
|
21
|
-
]
|
22
|
-
|
23
|
-
class Tree
|
24
|
-
include Relaxo::Model
|
25
|
-
|
26
|
-
property :id, UUID
|
27
|
-
property :name
|
28
|
-
property :planted, Attribute[Date]
|
29
|
-
|
30
|
-
view :all, [:type], index: [:id]
|
31
|
-
end
|
32
|
-
|
33
|
-
database.commit(message: "Create trees") do |changeset|
|
34
|
-
trees.each do |tree|
|
35
|
-
Tree.insert(changeset, tree)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
database.current do |dataset|
|
40
|
-
Tree.all(dataset).each do |tree|
|
41
|
-
puts "A #{tree.name} was planted on #{tree.planted.to_s}."
|
42
|
-
|
43
|
-
# Expected output:
|
44
|
-
# A Hinoki was planted on 2013-11-17.
|
45
|
-
# A Keyaki was planted on 2016-09-24.
|
46
|
-
end
|
47
|
-
end
|
48
|
-
```
|
49
|
-
|
50
|
-
### Non-UUID Primary Key
|
51
|
-
|
52
|
-
```ruby
|
53
|
-
#!/usr/bin/env ruby
|
54
|
-
|
55
|
-
gem 'relaxo'
|
56
|
-
|
57
|
-
require 'relaxo/model'
|
58
|
-
|
59
|
-
database = Relaxo.connect("test")
|
60
|
-
|
61
|
-
trees = [
|
62
|
-
{:name => 'Hinoki', :planted => Date.parse("2013/11/17")},
|
63
|
-
{:name => 'Keyaki', :planted => Date.parse("2016/9/24")}
|
64
|
-
]
|
65
|
-
|
66
|
-
class Tree
|
67
|
-
include Relaxo::Model
|
68
|
-
|
69
|
-
property :name
|
70
|
-
property :planted, Attribute[Date]
|
71
|
-
|
72
|
-
view :all, [:type], index: [:name]
|
73
|
-
end
|
74
|
-
|
75
|
-
database.commit(message: "Create trees") do |changeset|
|
76
|
-
trees.each do |tree|
|
77
|
-
Tree.insert(changeset, tree)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
database.current do |dataset|
|
82
|
-
trees.each do |tree|
|
83
|
-
object = Tree.fetch_all(dataset, name: tree[:name])
|
84
|
-
puts object
|
85
|
-
end
|
86
|
-
end
|
87
|
-
```
|
88
|
-
|
89
|
-
## Contributing
|
90
|
-
|
91
|
-
1. Fork it
|
92
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
93
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
94
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
95
|
-
5. Create new Pull Request
|
96
|
-
|
97
|
-
## License
|
98
|
-
|
99
|
-
Released under the MIT license.
|
100
|
-
|
101
|
-
Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
102
|
-
|
103
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
104
|
-
of this software and associated documentation files (the "Software"), to deal
|
105
|
-
in the Software without restriction, including without limitation the rights
|
106
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
107
|
-
copies of the Software, and to permit persons to whom the Software is
|
108
|
-
furnished to do so, subject to the following conditions:
|
109
|
-
|
110
|
-
The above copyright notice and this permission notice shall be included in
|
111
|
-
all copies or substantial portions of the Software.
|
112
|
-
|
113
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
114
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
115
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
116
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
117
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
118
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
119
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
# For RSpec
|
5
|
-
RSpec::Core::RakeTask.new(:spec)
|
6
|
-
|
7
|
-
task :console do
|
8
|
-
require 'pry'
|
9
|
-
|
10
|
-
require_relative 'lib/relaxo/model'
|
11
|
-
|
12
|
-
DB = Relaxo.connect(File.join(__dir__, 'testdb'))
|
13
|
-
|
14
|
-
Pry.start
|
15
|
-
end
|
16
|
-
|
17
|
-
task :default => :spec
|
data/relaxo-model.gemspec
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative 'lib/relaxo/model/version'
|
3
|
-
|
4
|
-
Gem::Specification.new do |spec|
|
5
|
-
spec.name = "relaxo-model"
|
6
|
-
spec.version = Relaxo::Model::VERSION
|
7
|
-
spec.authors = ["Samuel Williams"]
|
8
|
-
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
9
|
-
spec.description = <<-EOF
|
10
|
-
Relaxo Model provides a framework for business logic on top of
|
11
|
-
Relaxo. While it supports some traditional ORM style patterns, it is
|
12
|
-
primary focus is to model business processes and logic.
|
13
|
-
EOF
|
14
|
-
spec.summary = "A model layer for CouchDB with minimal global state."
|
15
|
-
spec.homepage = "http://www.codeotaku.com/projects/relaxo/model"
|
16
|
-
spec.license = "MIT"
|
17
|
-
|
18
|
-
spec.files = `git ls-files`.split($/)
|
19
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
spec.add_dependency("relaxo", "~> 1.5")
|
24
|
-
spec.add_dependency("msgpack", "~> 1.0")
|
25
|
-
|
26
|
-
spec.add_development_dependency "covered"
|
27
|
-
spec.add_development_dependency "bundler"
|
28
|
-
spec.add_development_dependency "rspec", "~> 3.4.0"
|
29
|
-
spec.add_development_dependency "rake"
|
30
|
-
end
|
@@ -1,55 +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) {File.join(__dir__, 'test')}
|
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
|
-
database.commit(message: "Adding test model") do |dataset|
|
46
|
-
model.save(dataset)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Force all attributes to be reloaded from the object store:
|
50
|
-
model.reload
|
51
|
-
|
52
|
-
expect(model.array_value).to be_kind_of Array
|
53
|
-
expect(model.hash_value).to be_kind_of Hash
|
54
|
-
end
|
55
|
-
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) {File.join(__dir__, 'test')}
|
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
|
data/spec/spec_helper.rb
DELETED
@@ -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
|