ru.Bee 2.7.8 → 2.7.10
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 +4 -4
- data/lib/db/test.db +0 -0
- data/lib/rubee/cli/bee_knowledge.json +1 -1
- data/lib/rubee/extensions/validatable.rb +1 -1
- data/lib/rubee/models/assoc_array.rb +8 -0
- data/lib/rubee/models/sequel_object.rb +6 -2
- data/lib/rubee.rb +1 -1
- data/lib/tests/models/comment_model_test.rb +12 -2
- metadata +1 -1
|
@@ -35,7 +35,7 @@ module Rubee
|
|
|
35
35
|
value = @instance.send(@attribute)
|
|
36
36
|
|
|
37
37
|
error_hash = assemble_error_hash(error_message, :required, attribute: @attribute)
|
|
38
|
-
if value.nil?
|
|
38
|
+
if value.nil? # If there is any value empty string or empty array, we'r still good to go.
|
|
39
39
|
@state.add_error(@attribute, error_hash)
|
|
40
40
|
end
|
|
41
41
|
|
|
@@ -22,6 +22,14 @@ module Rubee
|
|
|
22
22
|
@__model.where(*args, __query_dataset: @__query_dataset)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
def find_first(*args)
|
|
26
|
+
@__model.find_first(*args, __query_dataset: @__query_dataset)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def find_last(*args)
|
|
30
|
+
@__model.find_last(*args, __query_dataset: @__query_dataset)
|
|
31
|
+
end
|
|
32
|
+
|
|
25
33
|
def order(*args)
|
|
26
34
|
@__model.order(*args, __query_dataset: @__query_dataset)
|
|
27
35
|
end
|
|
@@ -209,11 +209,15 @@ module Rubee
|
|
|
209
209
|
end
|
|
210
210
|
|
|
211
211
|
def find_first(args, options = {})
|
|
212
|
-
|
|
212
|
+
query_dataset = options[:__query_dataset] || dataset
|
|
213
|
+
|
|
214
|
+
::Rubee::AssocArray.new([], self, query_dataset.where(**args)).order(:id).limit(1).last
|
|
213
215
|
end
|
|
214
216
|
|
|
215
217
|
def find_last(args, options = {})
|
|
216
|
-
|
|
218
|
+
query_dataset = options[:__query_dataset] || dataset
|
|
219
|
+
|
|
220
|
+
::Rubee::AssocArray.new([], self, query_dataset.where(**args)).order(id: :desc).limit(1).last
|
|
217
221
|
end
|
|
218
222
|
|
|
219
223
|
def order(args, options = {})
|
data/lib/rubee.rb
CHANGED
|
@@ -124,7 +124,7 @@ describe 'Comment model' do
|
|
|
124
124
|
Comment.destroy_all
|
|
125
125
|
comment_1 = Comment.create(text: 'test123123')
|
|
126
126
|
comment_2 = Comment.create(text: 'test123123')
|
|
127
|
-
_(Comment.find_first(text: 'test123123').id).must_equal(comment_1.id)
|
|
127
|
+
_(Comment.where(text: 'test123123').find_first(text: 'test123123').id).must_equal(comment_1.id)
|
|
128
128
|
Comment.destroy_all
|
|
129
129
|
end
|
|
130
130
|
end
|
|
@@ -134,7 +134,7 @@ describe 'Comment model' do
|
|
|
134
134
|
Comment.destroy_all
|
|
135
135
|
comment_1 = Comment.create(text: 'test123123')
|
|
136
136
|
comment_2 = Comment.create(text: 'test123123')
|
|
137
|
-
_(Comment.find_last(text: 'test123123').id).must_equal(comment_2.id)
|
|
137
|
+
_(Comment.where(text: 'test123123').find_last(text: 'test123123').id).must_equal(comment_2.id)
|
|
138
138
|
Comment.destroy_all
|
|
139
139
|
end
|
|
140
140
|
end
|
|
@@ -346,5 +346,15 @@ describe 'Comment model' do
|
|
|
346
346
|
_(comment.errors[:text]).must_equal({ message: "Text length must be greater than 4" })
|
|
347
347
|
end
|
|
348
348
|
end
|
|
349
|
+
|
|
350
|
+
describe 'when validate required' do
|
|
351
|
+
describe 'when empty string' do
|
|
352
|
+
it 'is valid' do
|
|
353
|
+
Comment.validate { attribute(:text).required }
|
|
354
|
+
comment = Comment.new(text: '')
|
|
355
|
+
_(comment.valid?).must_equal(true)
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
end
|
|
349
359
|
end
|
|
350
360
|
end
|