groovy 0.4.2 → 0.4.3
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/groovy/model.rb +8 -2
- data/lib/groovy/schema.rb +15 -4
- data/lib/groovy/version.rb +1 -1
- data/spec/model_spec.rb +9 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ebda26142ef67b09916291cafb3941fd34db0310b259aaf5c2ecf1b5fee3596
|
4
|
+
data.tar.gz: 5ee7f4f6c39b0237b281c1d04f27c3cd77ce1d9bb840a34fe8de88aa5114d28b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a10d18486ab2f434fd83b46c2d74da3851a80a227af4a42caff4a070d3d7701716a202e52b26591041cd7c57cdb144b9c2abee06186415aeebbdb0b276df55d
|
7
|
+
data.tar.gz: af55ec1bb42eaf1fec2de9431fe9b16369348f000a3d8740abb6ec1b02297297826b97cec34c1955615901366427d87bf1b02192320faf92c8d1e1a255c44477
|
data/lib/groovy/model.rb
CHANGED
@@ -221,6 +221,12 @@ module Groovy
|
|
221
221
|
set_timestamp(attributes, :created_at)
|
222
222
|
set_timestamp(attributes, :updated_at)
|
223
223
|
|
224
|
+
# remove nil attributes for integer columns, otherwise
|
225
|
+
# we get a TypeError (no implicit conversion from nil to integer)
|
226
|
+
attributes.each do |k, v|
|
227
|
+
attributes.delete(k) if v.nil? # && schema.integer_columns.include?(k)
|
228
|
+
end
|
229
|
+
|
224
230
|
if table.support_key?
|
225
231
|
raise "Key required" if key.nil?
|
226
232
|
table.add(key, attributes)
|
@@ -297,7 +303,7 @@ module Groovy
|
|
297
303
|
else
|
298
304
|
attrs ||= {}
|
299
305
|
unless attrs.is_a?(Hash)
|
300
|
-
raise ArgumentError.new("Attributes should be a Hash")
|
306
|
+
raise ArgumentError.new("Attributes should be a Hash, not a #{attrs.class}")
|
301
307
|
end
|
302
308
|
|
303
309
|
# don't call set_attributes since we don't want to call
|
@@ -411,7 +417,7 @@ module Groovy
|
|
411
417
|
|
412
418
|
def get_record_attribute(key)
|
413
419
|
val = record[key]
|
414
|
-
if self.class.schema.
|
420
|
+
if self.class.schema.time_columns.include?(key)
|
415
421
|
fix_time_value(val)
|
416
422
|
else
|
417
423
|
val
|
data/lib/groovy/schema.rb
CHANGED
@@ -56,14 +56,25 @@ module Groovy
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def time_columns
|
59
|
-
|
60
|
-
get_names(table.columns.select { |c| c.column? && c.range.name == 'Time' })
|
59
|
+
columns_by_type('Time')
|
61
60
|
end
|
62
61
|
|
63
|
-
def
|
64
|
-
|
62
|
+
def integer_columns
|
63
|
+
columns_by_type('Int32')
|
65
64
|
end
|
66
65
|
|
66
|
+
def boolean_columns
|
67
|
+
columns_by_type('Bool')
|
68
|
+
end
|
69
|
+
|
70
|
+
def columns_by_type(type)
|
71
|
+
get_names(table.columns.select { |c| c.column? && c.range.name == type })
|
72
|
+
end
|
73
|
+
|
74
|
+
# def time_column?(name)
|
75
|
+
# time_columns.include?(name)
|
76
|
+
# end
|
77
|
+
|
67
78
|
def rebuild!
|
68
79
|
log("Rebuilding!")
|
69
80
|
# remove_table! if table
|
data/lib/groovy/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe Groovy::Model do
|
|
17
17
|
describe '.scope' do
|
18
18
|
|
19
19
|
before :all do
|
20
|
-
TestProduct.class_eval do
|
20
|
+
TestProduct.class_eval do
|
21
21
|
scope :with_name, -> (name) { where(name: name) if name }
|
22
22
|
scope :by_price_asc, -> { sort_by(price: :asc) }
|
23
23
|
scope :cheapest, -> { by_price_asc }
|
@@ -49,6 +49,13 @@ describe Groovy::Model do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe '.create' do
|
52
|
+
|
53
|
+
it 'does not explode when inserting nil values for columns' do
|
54
|
+
expect do
|
55
|
+
TestProduct.create({ price: nil })
|
56
|
+
end.not_to raise_error
|
57
|
+
end
|
58
|
+
|
52
59
|
end
|
53
60
|
|
54
61
|
describe '.find' do
|
@@ -60,6 +67,7 @@ describe Groovy::Model do
|
|
60
67
|
describe '.delete_all' do
|
61
68
|
|
62
69
|
before do
|
70
|
+
TestProduct.delete_all
|
63
71
|
@first = TestProduct.create!(name: 'A product', price: 100)
|
64
72
|
@second = TestProduct.create!(name: 'Another product', price: 200)
|
65
73
|
expect(TestProduct.count).to eq(2)
|