diff --git a/lib/click_house/definition/column_set.rb b/lib/click_house/definition/column_set.rb index 66c2d17..fe56f25 100644 --- a/lib/click_house/definition/column_set.rb +++ b/lib/click_house/definition/column_set.rb @@ -22,10 +22,10 @@ def method_name_for_type(type) class_eval <<-METHODS, __FILE__, __LINE__ + 1 def #{method_name}(*definition) name = definition[0] - extentions = [] + extensions = [] options = {} - extensions = Array(definition[1..-1]).each do |el| - el.is_a?(Hash) ? options.merge!(el) : extentions.push(el) + Array(definition[1..-1]).each do |el| + el.is_a?(Hash) ? options.merge!(el) : extensions.push(el) end columns << Column.new(type: "#{type}", name: name, extensions: extensions, **options) diff --git a/spec/click_house/definition/column_set_spec.rb b/spec/click_house/definition/column_set_spec.rb index c5fc7c9..4362440 100644 --- a/spec/click_house/definition/column_set_spec.rb +++ b/spec/click_house/definition/column_set_spec.rb @@ -10,6 +10,7 @@ def squish(string) t.UInt16 :year_birth, low_cardinality: true t.UInt16 :year_death, low_cardinality: true, nullable: true, default: 0 t.Float32 :city_id, default: 0, nullable: true + t.DateTime :updated_at, 'UTC', default: 'NOW()' t.Nested :json do |n| n.UInt8 :cid, nullable: true n.Date :created_at, default: 'NOW()' @@ -23,24 +24,26 @@ def squish(string) let(:expectation) do <<~SQL - ( - money Decimal(5, 5), - year_birth LowCardinality(UInt16), + ( + money Decimal(5, 5), + year_birth LowCardinality(UInt16), year_death LowCardinality(Nullable(UInt16)) DEFAULT 0, - city_id Nullable(Float32) DEFAULT 0, - json Nested ( - cid Nullable(UInt8) , - created_at Date DEFAULT NOW(), + city_id Nullable(Float32) DEFAULT 0, + updated_at DateTime('UTC') DEFAULT NOW(), + json Nested ( + cid Nullable(UInt8) , + created_at Date DEFAULT NOW(), updated_at DateTime('UTC'), - deleted_at DateTime64(6, 'UTC') - ), - words Enum('hello' = 1, 'world' = 2), - tags Array(String) + deleted_at DateTime64(6, 'UTC') + ), + words Enum('hello' = 1, 'world' = 2), + tags Array(String) ) SQL end it 'works' do + expect(subject.columns).to include(have_attributes default: "NOW()", extensions: ["UTC"], name: :updated_at, type: "DateTime('%s')") # Correctly handles columns with a mix of hash and non-hash arguments expect(squish(subject.to_s)).to eq(squish(expectation)) end end