groovy 0.4.2 → 0.4.3

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: c2e735dd501cd86a3ee2ab21b111bf7aa4ab3d76d9d14acf8be86b97e34335b1
4
- data.tar.gz: 97b3b88d1f297ab6d74b9818858272c8fa711a27a3c0d64964508988a3304b85
3
+ metadata.gz: 5ebda26142ef67b09916291cafb3941fd34db0310b259aaf5c2ecf1b5fee3596
4
+ data.tar.gz: 5ee7f4f6c39b0237b281c1d04f27c3cd77ce1d9bb840a34fe8de88aa5114d28b
5
5
  SHA512:
6
- metadata.gz: deb85e6549f328555d795e542e282c6e3a50c574fdac769530648c69292f02ed469bc293304db863b7c9ac28a5bb653bd85eb79a7652f6390b3f5309fc492552
7
- data.tar.gz: 7546011290684eca615cf4823df5886908fe823c9bee086a80504a01a7d3aa846a0fd34dc05efc023a061078ac3645d352618c64a03b614989cb51bc3ca4c5c9
6
+ metadata.gz: 4a10d18486ab2f434fd83b46c2d74da3851a80a227af4a42caff4a070d3d7701716a202e52b26591041cd7c57cdb144b9c2abee06186415aeebbdb0b276df55d
7
+ data.tar.gz: af55ec1bb42eaf1fec2de9431fe9b16369348f000a3d8740abb6ec1b02297297826b97cec34c1955615901366427d87bf1b02192320faf92c8d1e1a255c44477
@@ -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.time_column?(key)
420
+ if self.class.schema.time_columns.include?(key)
415
421
  fix_time_value(val)
416
422
  else
417
423
  val
@@ -56,14 +56,25 @@ module Groovy
56
56
  end
57
57
 
58
58
  def time_columns
59
- # @time_columns ||=
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 time_column?(name)
64
- time_columns.include?(name)
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
@@ -1,3 +1,3 @@
1
1
  module Groovy
2
- VERSION = '0.4.2'.freeze
2
+ VERSION = '0.4.3'.freeze
3
3
  end
@@ -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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groovy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak