groovy 0.2.8 → 0.2.9

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: 59f58f216c8fc9465c4eb8569145b401f55e71682e6c5361addb623eb3ad36aa
4
- data.tar.gz: bdacfc59885d00a8f6457ebc707c653fd63a8251ed09ddcb133eed50f6a4d8df
3
+ metadata.gz: 51ebfa4af97ba85e2b162fdf64eeec5f0eda2a3829a12759e6d8fb01420b2c6a
4
+ data.tar.gz: 2b814b93565a791d87fb9cb77121d211c18d709c862b02c9c2c14feed54d8e2d
5
5
  SHA512:
6
- metadata.gz: 7890d931e4ce3c20b6fb7c25772c7a3c078022640090fe18a2b2c5215a4e819951ee97ceb1485df5cdad5e148c7670f6de6e4f84e69f329db41a01f12b3e67ee
7
- data.tar.gz: 823259a7565bad47388f1fedade8a0e2c0aa277f15d55fc1921f003c333d9be76fb01d98001dc002316941b3364ca9ca9bd92a199a95fd7221efaca8a28cfb8e
6
+ metadata.gz: bbdcd0ef05d17dc23cfd6a1ee1886bb4b827397ff2385cf62e16edb66eaf0a68041774572797c11333774d3fa902c617c334de47044e88221c71f2c9d414e930
7
+ data.tar.gz: b12cae355c2a12aa9e46d181ca05d94c9002cc90e0adbdec5b7194ab4ada0d65ce072cde9a777c119644079c9eedb3723f0754375d36d143fa23347ab0937085
@@ -24,7 +24,7 @@ module Groovy
24
24
  Kernel.const_get(table_name.sub(/ies$/, 'y').sub(/s$/, ''))
25
25
  end
26
26
 
27
- def self.included(base)
27
+ def self.included(base)
28
28
  base.extend(ClassMethods)
29
29
  base.include(Forwardable)
30
30
  base.table_name = base.name.sub(/y$/, 'ie') + 's'
@@ -81,7 +81,7 @@ module Groovy
81
81
 
82
82
  def find_records(&block)
83
83
  records = table.select(&block)
84
- records.map do|r|
84
+ records.map do |r|
85
85
  find_and_init_record(r.attributes['_key']['_id'])
86
86
  end
87
87
  end
@@ -103,7 +103,8 @@ module Groovy
103
103
  end
104
104
 
105
105
  def delete_all
106
- all.each { |child| child.delete }.count
106
+ all.find_each { |child| child.delete }
107
+ # table.delete { |record| record.id > -1 }
107
108
  # schema.rebuild!
108
109
  end
109
110
 
@@ -144,7 +145,7 @@ module Groovy
144
145
  end
145
146
 
146
147
  def query
147
- query_class.new(self, table)
148
+ query_class.new(self, table)
148
149
  end
149
150
 
150
151
  def scope(name, obj)
@@ -159,7 +160,7 @@ module Groovy
159
160
  query.public_send(scope_method, *args, &block)
160
161
  end
161
162
  end
162
-
163
+
163
164
  # this seems to be the same as: `table[id]`
164
165
  # def search(key, options = nil)
165
166
  # raise "Not supported!" unless table.respond_to?(:search)
@@ -231,17 +232,17 @@ module Groovy
231
232
 
232
233
  if set_record(record)
233
234
  # TODO: lazy load this
234
- # self.class.schema.singular_references.each do |col|
235
+ # self.class.schema.singular_references.each do |col|
235
236
  # set_ref(col, record.public_send(col))
236
237
  # end
237
238
  end
238
239
 
239
240
  attrs ||= {}
240
241
  unless attrs.is_a?(Hash)
241
- raise ArgumentError.new("Attributes should be a hash")
242
+ raise ArgumentError.new("Attributes should be a hash")
242
243
  end
243
244
 
244
- # don't call set_attributes since we don't want to call
245
+ # don't call set_attributes since we don't want to call
245
246
  # setters, that might be overriden with custom logic.
246
247
  # attrs.each { |k,v| self[k] = v }
247
248
  set_attributes(attrs)
@@ -261,7 +262,7 @@ module Groovy
261
262
  return set_ref(key, val) if val.respond_to?(:record) || val.is_a?(Groonga::Record)
262
263
 
263
264
  unless self.class.attribute_names.include?(key.to_sym)
264
- raise "Invalid attribute: #{key}"
265
+ raise "Invalid attribute: #{key}"
265
266
  end
266
267
 
267
268
  set_attribute(key, val)
@@ -312,6 +313,7 @@ module Groovy
312
313
  end
313
314
 
314
315
  def reload
316
+ raise RecordNotPersisted if id.nil?
315
317
  ensure_persisted!
316
318
  record = self.class.table[id] # _key
317
319
  # TODO: fix duplication
@@ -345,7 +347,7 @@ module Groovy
345
347
  end
346
348
 
347
349
  def set_ref(name, obj)
348
- unless obj.nil? || obj.respond_to?(:record)
350
+ unless obj.nil? || obj.respond_to?(:record)
349
351
  obj = Model.initialize_from_record(obj)
350
352
  end
351
353
 
@@ -47,9 +47,11 @@ module Groovy
47
47
  end
48
48
 
49
49
  def find_each(&block)
50
+ count = 0
50
51
  in_batches(of: 10) do |group|
51
- group.each { |item| yield(item) }
52
+ group.each { |item| count += 1; yield(item) }
52
53
  end
54
+ count
53
55
  end
54
56
 
55
57
  # http://groonga.org/docs/reference/grn_expr/query_syntax.html
@@ -74,7 +76,7 @@ module Groovy
74
76
  add_param(AND + str)
75
77
 
76
78
  else
77
- str = val.nil? || val.to_s.strip == '' ? '\\' : val.to_s
79
+ str = val.nil? || val == false || val.to_s.strip == '' ? '\\' : val.to_s
78
80
  add_param(AND + [key, str].join(':'))
79
81
  end
80
82
  end
@@ -108,7 +110,7 @@ module Groovy
108
110
  add_param(AND + str)
109
111
 
110
112
  else
111
- str = val.nil? || val.to_s.strip == '' ? '\\' : val.to_s
113
+ str = val.nil? || val == false || val.to_s.strip == '' ? '\\' : val.to_s
112
114
  add_param(AND + [key, str].join(':!')) # not
113
115
  end
114
116
  end
@@ -1,3 +1,3 @@
1
1
  module Groovy
2
- VERSION = '0.2.8'.freeze
2
+ VERSION = '0.2.9'.freeze
3
3
  end
@@ -58,6 +58,23 @@ describe Groovy::Model do
58
58
  end
59
59
 
60
60
  describe '.delete_all' do
61
+
62
+ before do
63
+ @first = TestProduct.create!(name: 'A product', price: 100)
64
+ @second = TestProduct.create!(name: 'Another product', price: 200)
65
+ expect(TestProduct.count).to eq(2)
66
+ end
67
+
68
+ it 'deletes all' do
69
+ TestProduct.delete_all
70
+ expect(TestProduct.count).to eq(0)
71
+
72
+ # expect { @first.reload }.to raise_error
73
+ # expect { @second.reload }.to raise_error
74
+ # expect { TestProduct.find(@first.id) }.to raise_error
75
+ # expect { TestProduct.find(@second.id) }.to raise_error
76
+ end
77
+
61
78
  end
62
79
 
63
80
  describe '#[]' do
@@ -17,6 +17,24 @@ describe Groovy::Query do
17
17
  end
18
18
 
19
19
  describe '#where' do
20
+ describe 'boolean value' do
21
+ it 'finds expected records' do
22
+ res = TestProduct.where(visible: true)
23
+ expect(res.map(&:id)).to eq([@p1.id, @p3.id, @p5.id])
24
+
25
+ res = TestProduct.where(visible: false)
26
+ expect(res.map(&:id)).to eq([@p2.id, @p4.id])
27
+ end
28
+
29
+ it 'works with other args too' do
30
+ res = TestProduct.where(visible: true).where(name: 'Product 5')
31
+ expect(res.map(&:id)).to eq([@p5.id])
32
+
33
+ res = TestProduct.where(visible: false).where(name: 'Product 2')
34
+ expect(res.map(&:id)).to eq([@p2.id])
35
+ end
36
+ end
37
+
20
38
  describe 'nil value' do
21
39
  it 'finds expected records' do
22
40
  res = TestProduct.where(tag_list: nil)
@@ -141,6 +159,24 @@ describe Groovy::Query do
141
159
  end
142
160
 
143
161
  describe '#not' do
162
+ describe 'boolean value' do
163
+ it 'finds expected records' do
164
+ res = TestProduct.where.not(visible: true)
165
+ expect(res.map(&:id)).to eq([@p2.id, @p4.id])
166
+
167
+ res = TestProduct.where.not(visible: false)
168
+ expect(res.map(&:id)).to eq([@p1.id, @p3.id, @p5.id])
169
+ end
170
+
171
+ it 'works with other args too' do
172
+ res = TestProduct.where.not(visible: true).where(name: 'Product 2')
173
+ expect(res.map(&:id)).to eq([@p2.id])
174
+
175
+ res = TestProduct.where.not(visible: false).where(name: 'Product 5')
176
+ expect(res.map(&:id)).to eq([@p5.id])
177
+ end
178
+ end
179
+
144
180
  describe 'nil value' do
145
181
  it 'finds expected records' do
146
182
  res = TestProduct.where.not(tag_list: nil)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groovy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-16 00:00:00.000000000 Z
11
+ date: 2020-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rroonga