influxer 0.5.0 → 0.5.1

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
  SHA1:
3
- metadata.gz: c7fc8c72105e35542e5c818fa97fc55b49c6c068
4
- data.tar.gz: eb461ecfc644cdf6a34789d940398ceda66c418e
3
+ metadata.gz: a56f1b17d497e12281a8ae86939c49f83d2037dc
4
+ data.tar.gz: c64d0f15b9a76e2fdd8190be12914c315651d166
5
5
  SHA512:
6
- metadata.gz: d470618c9e5f329ba66ba8f1c9da6ba330075c6ee5be825f527c0feab3c3995827b44a5a92fd3f133456896df4b25417b42f2abc2197702117930572d36d8c64
7
- data.tar.gz: 425b73368fafb1ff3e82dc6bab1ab005ab14ce9a2e1aac623359feb8eac763660aa13697a7dd3e8e9c018bfb6565b10109c66f7272fd34069ea4e38fdc35a830
6
+ metadata.gz: c2250060657155d5454d9a4603a1cb5d589f5ce3b66d66091c2d0267ec0e50968ebd0851811bb10bce1f655ab88a239741eb979343321fc4b30b8bd779e4e25a
7
+ data.tar.gz: 1ada172a89d606bb1d19399318c0976108ff5c7084ed68d274df07954550484dca58d2ec82474e1b3d11f54d6de98425441ccdc7883d1071a96acb196b7aae8c
data/.rubocop.yml CHANGED
@@ -7,10 +7,12 @@ AllCops:
7
7
  Exclude:
8
8
  - 'bin/**/*'
9
9
  - 'spec/dummy/**/*'
10
- RunRailsCops: true
11
10
  DisplayCopNames: true
12
11
  StyleGuideCopsOnly: false
13
12
 
13
+ Rails:
14
+ Enabled: true
15
+
14
16
  Style/AccessorMethodName:
15
17
  Enabled: false
16
18
 
@@ -47,4 +49,4 @@ Rails/Date:
47
49
  Enabled: false
48
50
 
49
51
  Rails/TimeZone:
50
- Enabled: false
52
+ Enabled: false
data/.travis.yml CHANGED
@@ -2,5 +2,5 @@ language: ruby
2
2
  cache: bundler
3
3
  matrix:
4
4
  include:
5
- - rvm: 2.2.2
5
+ - rvm: 2.3.0
6
6
  gemfile: gemfiles/rails42.gemfile
data/Changelog.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## master
2
+ - Fix whitespace around operators
3
+ - Add `Relation#from` method to redefine series
4
+ - Handle nil values for tags in #where clause
5
+
1
6
  ## 0.5.0
2
7
  - Update `timestamp` support
3
8
  - Add `epoch` method
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Gem Version](https://badge.fury.io/rb/influxer.svg)](https://rubygems.org/gems/influxer) [![Build Status](https://travis-ci.org/palkan/influxer.svg?branch=master)](https://travis-ci.org/palkan/influxer) [![Vexor Status](https://ci.vexor.io/projects/55e92786-f1de-4e69-8f58-889453c2d71c/status.svg)](https://ci.vexor.io/ui/projects/55e92786-f1de-4e69-8f58-889453c2d71c/builds)
1
+ [![Gem Version](https://badge.fury.io/rb/influxer.svg)](https://rubygems.org/gems/influxer) [![Build Status](https://travis-ci.org/palkan/influxer.svg?branch=master)](https://travis-ci.org/palkan/influxer)
2
2
  ## Influxer
3
3
 
4
4
  **NOTE**: Version 0.3.x supports InfluxDB >= 0.9.0. For InfluxDB 0.8.x use [version 0.2.5](https://github.com/palkan/influxer/tree/0.2.5).
@@ -4,7 +4,4 @@ gem 'sqlite3', platform: :mri
4
4
  gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
5
5
  gem 'activerecord', '~> 4.2.0'
6
6
 
7
- # TEMP
8
- gem 'influxdb', github: 'influxdb/influxdb-ruby'
9
-
10
7
  gemspec path: '..'
data/influxer.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = ["lib"]
17
17
 
18
18
  s.add_dependency "activemodel", '>= 4.0'
19
- s.add_dependency "influxdb", "~> 0.2.3"
19
+ s.add_dependency "influxdb", "~> 0.3"
20
20
  s.add_dependency "anyway_config", "~>0.3.0"
21
21
 
22
22
  s.add_development_dependency "timecop"
@@ -40,7 +40,7 @@ module Influxer
40
40
  @attributes[name] = val
41
41
  end
42
42
 
43
- define_method("#{name}") do
43
+ define_method(name.to_s) do
44
44
  @attributes[name]
45
45
  end
46
46
  end
@@ -102,7 +102,7 @@ module Influxer
102
102
  quoted_series(val.first)
103
103
  end
104
104
  else
105
- '"' + val.to_s.gsub(/\"/) { %q(\") } + '"'
105
+ '"' + val.to_s.gsub(/\"/) { '\"' } + '"'
106
106
  end
107
107
  end
108
108
  # rubocop:enable Metrics/MethodLength
@@ -118,9 +118,9 @@ module Influxer
118
118
  end
119
119
 
120
120
  def write
121
- fail MetricsError if self.persisted?
121
+ raise MetricsError if persisted?
122
122
 
123
- return false if self.invalid?
123
+ return false if invalid?
124
124
 
125
125
  run_callbacks :write do
126
126
  write_point
@@ -129,7 +129,7 @@ module Influxer
129
129
  end
130
130
 
131
131
  def write!
132
- fail MetricsInvalid if self.invalid?
132
+ raise MetricsInvalid if invalid?
133
133
  write
134
134
  end
135
135
 
@@ -166,6 +166,8 @@ module Influxer
166
166
 
167
167
  private
168
168
 
169
+ # rubocop:disable Metrics/MethodLength
170
+ # rubocop:disable Metrics/AbcSize
169
171
  def parsed_timestamp
170
172
  return @timestamp unless client.time_precision == 'ns'
171
173
 
@@ -180,6 +182,8 @@ module Influxer
180
182
  (@timestamp.to_r * TIME_FACTOR).to_i
181
183
  end
182
184
  end
185
+ # rubocop:enable Metrics/MethodLength
186
+ # rubocop:enable Metrics/AbcSize
183
187
 
184
188
  def unquote(name)
185
189
  name.gsub(/(\A['"]|['"]\z)/, '')
@@ -12,17 +12,17 @@ module Influxer
12
12
 
13
13
  attr_reader :values
14
14
 
15
- SUPPORTED_EPOCH_FORMAT = [:h, :m, :s, :ms, :u, :ns]
15
+ SUPPORTED_EPOCH_FORMAT = %i(h m s ms u ns).freeze
16
16
 
17
- MULTI_VALUE_METHODS = [:select, :where, :group, :order]
17
+ MULTI_VALUE_METHODS = %i(select where group order).freeze
18
18
 
19
- MULTI_KEY_METHODS = [:fanout]
19
+ MULTI_KEY_METHODS = %i(fanout).freeze
20
20
 
21
- SINGLE_VALUE_METHODS = [:fill, :time, :limit, :offset, :slimit, :soffset, :normalized]
21
+ SINGLE_VALUE_METHODS = %i(fill time limit offset slimit soffset from normalized).freeze
22
22
 
23
- MULTI_VALUE_SIMPLE_METHODS = [:select, :group]
23
+ MULTI_VALUE_SIMPLE_METHODS = %i(select group).freeze
24
24
 
25
- SINGLE_VALUE_SIMPLE_METHODS = [:fill, :limit, :offset, :slimit, :soffset]
25
+ SINGLE_VALUE_SIMPLE_METHODS = %i(fill limit offset slimit soffset from).freeze
26
26
 
27
27
  MULTI_VALUE_METHODS.each do |name|
28
28
  class_eval <<-CODE, __FILE__, __LINE__ + 1
@@ -100,7 +100,7 @@ module Influxer
100
100
  point
101
101
  end
102
102
 
103
- alias_method :new, :build
103
+ alias new build
104
104
 
105
105
  def normalized
106
106
  @values[:normalized] = true
@@ -136,7 +136,7 @@ module Influxer
136
136
  sql = ["select"]
137
137
  select_values << "*" if select_values.empty?
138
138
 
139
- sql << select_values.uniq.join(",")
139
+ sql << select_values.uniq.join(", ")
140
140
 
141
141
  sql << "from #{build_series_name}"
142
142
 
@@ -145,7 +145,7 @@ module Influxer
145
145
  unless group_values.empty? && time_value.nil?
146
146
  group_fields = (time_value.nil? ? [] : ['time(' + @values[:time] + ')']) + group_values
147
147
  group_fields.uniq!
148
- sql << "group by #{group_fields.join(',')}"
148
+ sql << "group by #{group_fields.join(', ')}"
149
149
  end
150
150
 
151
151
  sql << "fill(#{fill_value})" unless fill_value.nil?
@@ -189,7 +189,11 @@ module Influxer
189
189
  end
190
190
 
191
191
  def load
192
- @records = get_points(@instance.client.query(to_sql, denormalize: !normalized?, epoch: @values[:epoch]))
192
+ @records = get_points(
193
+ @instance.client.query(
194
+ to_sql,
195
+ denormalize: !normalized?,
196
+ epoch: @values[:epoch]))
193
197
  @loaded = true
194
198
  @records
195
199
  end
@@ -207,7 +211,8 @@ module Influxer
207
211
  end
208
212
 
209
213
  def scoping
210
- previous, @klass.current_scope = @klass.current_scope, self
214
+ previous = @klass.current_scope
215
+ @klass.current_scope = self
211
216
  yield
212
217
  ensure
213
218
  @klass.current_scope = previous
@@ -237,7 +242,7 @@ module Influxer
237
242
  protected
238
243
 
239
244
  def build_series_name
240
- @instance.series
245
+ from_value.present? ? @klass.quoted_series(from_value) : @instance.series
241
246
  end
242
247
 
243
248
  def loaded?
@@ -5,9 +5,8 @@ module Influxer
5
5
  :count, :min, :max, :mean,
6
6
  :mode, :median, :distinct, :derivative,
7
7
  :stddev, :sum, :first, :last
8
- ]
8
+ ].freeze
9
9
 
10
- # rubocop:disable Metrics/LineLength
11
10
  CALCULATION_METHODS.each do |name|
12
11
  class_eval <<-CODE, __FILE__, __LINE__ + 1
13
12
  def #{name}(val, alias_name = nil) # def count(val)
@@ -20,7 +19,7 @@ module Influxer
20
19
 
21
20
  def percentile(name, val, alias_name = nil)
22
21
  @values[:has_calculations] = true
23
- select_values << "percentile(#{name},#{val})#{alias_name ? ' as ' + alias_name.to_s : ''}"
22
+ select_values << "percentile(#{name}, #{val})#{alias_name ? ' as ' + alias_name.to_s : ''}"
24
23
  self
25
24
  end
26
25
  end
@@ -24,11 +24,11 @@ module Influxer
24
24
  # Metrics.time("4d", fill: 0)
25
25
  # # select * from metrics group by time(4d) fill(0)
26
26
  def time(val, options = {})
27
- if val.is_a?(Symbol)
28
- @values[:time] = TIME_ALIASES[val] || '1' + val.to_s
29
- else
30
- @values[:time] = val
31
- end
27
+ @values[:time] = if val.is_a?(Symbol)
28
+ TIME_ALIASES[val] || '1' + val.to_s
29
+ else
30
+ val
31
+ end
32
32
 
33
33
  build_fill(options[:fill])
34
34
  self
@@ -30,32 +30,38 @@ module Influxer
30
30
  end
31
31
  end
32
32
 
33
+ # rubocop:disable Metrics/CyclomaticComplexity
34
+ # rubocop:disable Metrics/MethodLength
33
35
  def build_eql(key, val, negate)
34
36
  case val
37
+ when NilClass
38
+ build_eql(key, /.*/, !negate)
35
39
  when Regexp
36
- "#{key}#{negate ? '!~' : '=~'}#{val.inspect}"
40
+ "#{key}#{negate ? ' !~ ' : ' =~ '}#{val.inspect}"
37
41
  when Array
38
42
  build_in(key, val, negate)
39
43
  when Range
40
44
  build_range(key, val, negate)
41
45
  else
42
- "#{key}#{negate ? '<>' : '='}#{quoted(val, key)}"
46
+ "#{key}#{negate ? ' <> ' : ' = '}#{quoted(val, key)}"
43
47
  end
44
48
  end
49
+ # rubocop:enable Metrics/CyclomaticComplexity
50
+ # rubocop:enable Metrics/MethodLength
45
51
 
46
52
  def build_in(key, arr, negate)
47
53
  buf = []
48
54
  arr.each do |val|
49
55
  buf << build_eql(key, val, negate)
50
56
  end
51
- "#{buf.join(negate ? ' and ' : ' or ')}"
57
+ buf.join(negate ? ' and ' : ' or ').to_s
52
58
  end
53
59
 
54
60
  def build_range(key, val, negate)
55
61
  if negate
56
- "#{key}<#{quoted(val.begin)} and #{key}>#{quoted(val.end)}"
62
+ "#{key} < #{quoted(val.begin)} and #{key} > #{quoted(val.end)}"
57
63
  else
58
- "#{key}>#{quoted(val.begin)} and #{key}<#{quoted(val.end)}"
64
+ "#{key} > #{quoted(val.begin)} and #{key} < #{quoted(val.end)}"
59
65
  end
60
66
  end
61
67
  end
@@ -27,7 +27,7 @@ module Influxer
27
27
  class ScopeRegistry # :nodoc:
28
28
  extend ActiveSupport::PerThreadRegistry
29
29
 
30
- VALID_SCOPE_TYPES = [:current_scope]
30
+ VALID_SCOPE_TYPES = [:current_scope].freeze
31
31
 
32
32
  def initialize
33
33
  @registry = Hash.new { |hash, key| hash[key] = {} }
@@ -49,7 +49,7 @@ module Influxer
49
49
 
50
50
  def raise_invalid_scope_type!(scope_type)
51
51
  return if VALID_SCOPE_TYPES.include?(scope_type)
52
- fail ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. \
52
+ raise ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. \
53
53
  Scope types must be included in VALID_SCOPE_TYPES"
54
54
  end
55
55
  end
@@ -7,7 +7,7 @@ module Influxer
7
7
 
8
8
  module ClassMethods
9
9
  def scope(name, scope)
10
- fail "Scope not defined: #{name}" if scope.nil? || !scope.respond_to?(:call)
10
+ raise "Scope not defined: #{name}" if scope.nil? || !scope.respond_to?(:call)
11
11
  singleton_class.send(:define_method, name) do |*args|
12
12
  rel = all
13
13
  rel.merge!(rel.scoping { scope.call(*args) })
@@ -9,18 +9,15 @@ module Influxer
9
9
  # rubocop:disable Style/PredicateName
10
10
  # rubocop:disable Metrics/MethodLength
11
11
  # rubocop:disable Metrics/AbcSize
12
- # rubocop:disable Metrics/CyclomaticComplexity
13
12
  def has_metrics(*args, **params)
14
13
  metrics_name = args.empty? ? "metrics" : args.first.to_s
15
14
 
16
15
  klass = params[:class_name].present? ? params[:class_name] : "#{self}Metrics"
17
16
  klass = klass.constantize
18
17
 
19
- attrs = nil
20
-
21
18
  attrs = params[:inherits] if params[:inherits].present?
22
19
 
23
- foreign_key = params.key?(:foreign_key) ? params[:foreign_key] : to_s.foreign_key
20
+ foreign_key = params.fetch(:foreign_key, to_s.foreign_key)
24
21
 
25
22
  define_method(metrics_name) do
26
23
  rel_attrs = foreign_key ? { foreign_key => id } : {}
@@ -19,7 +19,7 @@ module Influxer
19
19
  res = yield
20
20
  duration = (Time.now - start_ts) * 1000
21
21
 
22
- name = "InfluxDB SQL (#{duration.round(1)}ms)"
22
+ name = "InfluxDB SQL (#{duration.round(1)}ms)"
23
23
 
24
24
  # bold black name and blue query string
25
25
  msg = "\e[1m\e[30m#{name}\e[0m \e[34m#{sql}\e[0m"
@@ -1,3 +1,3 @@
1
1
  module Influxer # :nodoc:
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1".freeze
3
3
  end
@@ -193,8 +193,8 @@ describe Influxer::Metrics, :query do
193
193
  timestamp_test = Time.now
194
194
  expected_time = (timestamp_test.to_r * 1_000_000_000).to_i
195
195
 
196
- expect(client).
197
- to receive(:write_point).with("dummies", tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 }, timestamp: expected_time)
196
+ expect(client)
197
+ .to receive(:write_point).with("dummies", tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 }, timestamp: expected_time)
198
198
 
199
199
  point = dummy_metrics.write(user_id: 1, dummy_id: 2, host: 'test', timestamp: timestamp_test)
200
200
  expect(point.persisted?).to be_truthy
@@ -205,10 +205,10 @@ describe Influxer::Metrics, :query do
205
205
 
206
206
  it "test write data with string time" do
207
207
  base_time = Time.now
208
- timestamp_test = "#{base_time.to_s}"
208
+ timestamp_test = base_time.to_s
209
209
 
210
- expect(client).
211
- to receive(:write_point).with("dummies", tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 }, timestamp: (base_time.to_i * 1_000_000_000).to_i)
210
+ expect(client)
211
+ .to receive(:write_point).with("dummies", tags: { dummy_id: 2, host: 'test' }, values: { user_id: 1 }, timestamp: (base_time.to_i * 1_000_000_000).to_i)
212
212
 
213
213
  point = dummy_metrics.write(user_id: 1, dummy_id: 2, host: 'test', timestamp: timestamp_test)
214
214
  expect(point.persisted?).to be_truthy
@@ -27,15 +27,15 @@ describe Influxer::Relation, :query do
27
27
  r2 = Influxer::Relation.new(DummyMetrics).where.not(user_id: 0).group(:user_id).order(user_id: :asc)
28
28
  r1.merge!(r2)
29
29
  expect(r1.to_sql)
30
- .to eq "select * from \"dummy\" where (id=1 or id=2) and (dummy='qwe') and (user_id<>0) " \
31
- "group by time(1h),user_id order by user_id asc"
30
+ .to eq "select * from \"dummy\" where (id = 1 or id = 2) and (dummy = 'qwe') and (user_id <> 0) " \
31
+ "group by time(1h), user_id order by user_id asc"
32
32
  end
33
33
 
34
34
  it "merge single values" do
35
35
  r1 = rel.time(:hour, fill: 0).slimit(10)
36
36
  r2 = Influxer::Relation.new(DummyMetrics).group(:dummy_id).offset(10).slimit(5)
37
37
  r1.merge!(r2)
38
- expect(r1.to_sql).to eq "select * from \"dummy\" group by time(1h),dummy_id fill(0) offset 10 slimit 5"
38
+ expect(r1.to_sql).to eq "select * from \"dummy\" group by time(1h), dummy_id fill(0) offset 10 slimit 5"
39
39
  end
40
40
  end
41
41
 
@@ -44,11 +44,15 @@ describe Influxer::Relation, :query do
44
44
  it "generates valid from if no conditions" do
45
45
  expect(rel.to_sql).to eq "select * from \"dummy\""
46
46
  end
47
+
48
+ it "generates sql using custom from clause" do
49
+ expect(rel.from(:doomy).to_sql).to eq "select * from \"doomy\""
50
+ end
47
51
  end
48
52
 
49
53
  describe "#select" do
50
54
  it "select array of symbols" do
51
- expect(rel.select(:user_id, :dummy_id).to_sql).to eq "select user_id,dummy_id from \"dummy\""
55
+ expect(rel.select(:user_id, :dummy_id).to_sql).to eq "select user_id, dummy_id from \"dummy\""
52
56
  end
53
57
 
54
58
  it "select string" do
@@ -63,7 +67,7 @@ describe Influxer::Relation, :query do
63
67
  describe "#where" do
64
68
  it "sgenerate valid conditions from hash" do
65
69
  Timecop.freeze(Time.now)
66
- expect(rel.where(user_id: 1, dummy: 'q', timer: Time.now).to_sql).to eq "select * from \"dummy\" where (user_id=1) and (dummy='q') and (timer=#{Time.now.to_i}s)"
70
+ expect(rel.where(user_id: 1, dummy: 'q', timer: Time.now).to_sql).to eq "select * from \"dummy\" where (user_id = 1) and (dummy = 'q') and (timer = #{Time.now.to_i}s)"
67
71
  end
68
72
 
69
73
  it "generate valid conditions from strings" do
@@ -71,43 +75,53 @@ describe Influxer::Relation, :query do
71
75
  end
72
76
 
73
77
  it "handle regexps" do
74
- expect(rel.where(user_id: 1, dummy: /^du.*/).to_sql).to eq "select * from \"dummy\" where (user_id=1) and (dummy=~/^du.*/)"
78
+ expect(rel.where(user_id: 1, dummy: /^du.*/).to_sql).to eq "select * from \"dummy\" where (user_id = 1) and (dummy =~ /^du.*/)"
75
79
  end
76
80
 
77
81
  it "handle ranges" do
78
- expect(rel.where(user_id: 1..4).to_sql).to eq "select * from \"dummy\" where (user_id>1 and user_id<4)"
82
+ expect(rel.where(user_id: 1..4).to_sql).to eq "select * from \"dummy\" where (user_id > 1 and user_id < 4)"
79
83
  end
80
84
 
81
85
  it "handle arrays" do
82
- expect(rel.where(user_id: [1, 2, 3]).to_sql).to eq "select * from \"dummy\" where (user_id=1 or user_id=2 or user_id=3)"
86
+ expect(rel.where(user_id: [1, 2, 3]).to_sql).to eq "select * from \"dummy\" where (user_id = 1 or user_id = 2 or user_id = 3)"
83
87
  end
84
88
 
85
89
  context "with tags" do
86
90
  it "integer tag values" do
87
- expect(rel.where(dummy_id: 10).to_sql).to eq "select * from \"dummy\" where (dummy_id='10')"
91
+ expect(rel.where(dummy_id: 10).to_sql).to eq "select * from \"dummy\" where (dummy_id = '10')"
88
92
  end
89
93
 
90
94
  it "array tag values" do
91
- expect(rel.where(dummy_id: [10, 'some']).to_sql).to eq "select * from \"dummy\" where (dummy_id='10' or dummy_id='some')"
95
+ expect(rel.where(dummy_id: [10, 'some']).to_sql).to eq "select * from \"dummy\" where (dummy_id = '10' or dummy_id = 'some')"
96
+ end
97
+
98
+ it "nil value" do
99
+ expect(rel.where(dummy_id: nil).to_sql).to eq "select * from \"dummy\" where (dummy_id !~ /.*/)"
92
100
  end
93
101
  end
94
102
  end
95
103
 
96
104
  describe "#not" do
97
105
  it "negate simple values" do
98
- expect(rel.where.not(user_id: 1, dummy: :a).to_sql).to eq "select * from \"dummy\" where (user_id<>1) and (dummy<>'a')"
106
+ expect(rel.where.not(user_id: 1, dummy: :a).to_sql).to eq "select * from \"dummy\" where (user_id <> 1) and (dummy <> 'a')"
99
107
  end
100
108
 
101
109
  it "handle regexp" do
102
- expect(rel.where.not(user_id: 1, dummy: /^du.*/).to_sql).to eq "select * from \"dummy\" where (user_id<>1) and (dummy!~/^du.*/)"
110
+ expect(rel.where.not(user_id: 1, dummy: /^du.*/).to_sql).to eq "select * from \"dummy\" where (user_id <> 1) and (dummy !~ /^du.*/)"
103
111
  end
104
112
 
105
113
  it "handle ranges" do
106
- expect(rel.where.not(user_id: 1..4).to_sql).to eq "select * from \"dummy\" where (user_id<1 and user_id>4)"
114
+ expect(rel.where.not(user_id: 1..4).to_sql).to eq "select * from \"dummy\" where (user_id < 1 and user_id > 4)"
107
115
  end
108
116
 
109
117
  it "handle arrays" do
110
- expect(rel.where.not(user_id: [1, 2, 3]).to_sql).to eq "select * from \"dummy\" where (user_id<>1 and user_id<>2 and user_id<>3)"
118
+ expect(rel.where.not(user_id: [1, 2, 3]).to_sql).to eq "select * from \"dummy\" where (user_id <> 1 and user_id <> 2 and user_id <> 3)"
119
+ end
120
+
121
+ context "with tags" do
122
+ it "nil value" do
123
+ expect(rel.not(dummy_id: nil).to_sql).to eq "select * from \"dummy\" where (dummy_id =~ /.*/)"
124
+ end
111
125
  end
112
126
  end
113
127
 
@@ -137,7 +151,7 @@ describe Influxer::Relation, :query do
137
151
 
138
152
  describe "#group" do
139
153
  it "generate valid groups" do
140
- expect(rel.group(:user_id, "time(1m) fill(0)").to_sql).to eq "select * from \"dummy\" group by user_id,time(1m) fill(0)"
154
+ expect(rel.group(:user_id, "time(1m) fill(0)").to_sql).to eq "select * from \"dummy\" group by user_id, time(1m) fill(0)"
141
155
  end
142
156
 
143
157
  context "group by time predefined values" do
@@ -189,11 +203,11 @@ describe Influxer::Relation, :query do
189
203
  end
190
204
 
191
205
  it "group by time and other fields with fill zero" do
192
- expect(rel.time("4d", fill: 0).group(:dummy_id).to_sql).to eq "select * from \"dummy\" group by time(4d),dummy_id fill(0)"
206
+ expect(rel.time("4d", fill: 0).group(:dummy_id).to_sql).to eq "select * from \"dummy\" group by time(4d), dummy_id fill(0)"
193
207
  end
194
208
 
195
209
  it "group by time and other fields with fill negative" do
196
- expect(rel.time("4d", fill: -1).group(:dummy_id).to_sql).to eq "select * from \"dummy\" group by time(4d),dummy_id fill(-1)"
210
+ expect(rel.time("4d", fill: -1).group(:dummy_id).to_sql).to eq "select * from \"dummy\" group by time(4d), dummy_id fill(-1)"
197
211
  end
198
212
  end
199
213
 
@@ -241,7 +255,7 @@ describe Influxer::Relation, :query do
241
255
  describe "##{method}" do
242
256
  specify do
243
257
  expect(rel.where(user_id: 1).calc(method, :column_name).to_sql)
244
- .to eq "select #{method}(column_name) from \"dummy\" where (user_id=1)"
258
+ .to eq "select #{method}(column_name) from \"dummy\" where (user_id = 1)"
245
259
  end
246
260
  end
247
261
  end
@@ -253,7 +267,7 @@ describe Influxer::Relation, :query do
253
267
  end
254
268
 
255
269
  it "select percentile as alias" do
256
- expect(rel.percentile(:val, 90, 'p1').to_sql).to eq "select percentile(val,90) as p1 from \"dummy\""
270
+ expect(rel.percentile(:val, 90, 'p1').to_sql).to eq "select percentile(val, 90) as p1 from \"dummy\""
257
271
  end
258
272
  end
259
273
  end
@@ -261,19 +275,19 @@ describe Influxer::Relation, :query do
261
275
  context "complex queries" do
262
276
  it "group + where" do
263
277
  expect(rel.count('user_id').group(:traffic_source).fill(0).where(user_id: 123).past('28d').to_sql)
264
- .to eq "select count(user_id) from \"dummy\" where (user_id=123) and (time > now() - 28d) " \
278
+ .to eq "select count(user_id) from \"dummy\" where (user_id = 123) and (time > now() - 28d) " \
265
279
  "group by traffic_source fill(0)"
266
280
  end
267
281
 
268
282
  it "where + group + order + limit" do
269
283
  expect(rel.group(:user_id).where(account_id: 123).order(account_id: :desc).limit(10).offset(10).to_sql)
270
- .to eq "select * from \"dummy\" where (account_id=123) group by user_id " \
284
+ .to eq "select * from \"dummy\" where (account_id = 123) group by user_id " \
271
285
  "order by account_id desc limit 10 offset 10"
272
286
  end
273
287
 
274
288
  it "offset + slimit" do
275
289
  expect(rel.where(account_id: 123).slimit(10).offset(10).to_sql)
276
- .to eq "select * from \"dummy\" where (account_id=123) " \
290
+ .to eq "select * from \"dummy\" where (account_id = 123) " \
277
291
  "offset 10 slimit 10"
278
292
  end
279
293
  end
@@ -310,7 +324,7 @@ describe Influxer::Relation, :query do
310
324
 
311
325
  it "with tags" do
312
326
  expect(rel.where(dummy_id: 1, host: 'eu').delete_all)
313
- .to eq "drop series from \"dummy\" where (dummy_id='1') and (host='eu')"
327
+ .to eq "drop series from \"dummy\" where (dummy_id = '1') and (host = 'eu')"
314
328
  end
315
329
  end
316
330
 
@@ -42,14 +42,14 @@ describe Influxer::Metrics, :query do
42
42
 
43
43
  it "works with several defaults" do
44
44
  expect(dappy.where(user_id: 1).to_sql)
45
- .to eq "select * from \"dummy\" where (user_id=1) group by time(1h) limit 100"
45
+ .to eq "select * from \"dummy\" where (user_id = 1) group by time(1h) limit 100"
46
46
  end
47
47
  end
48
48
 
49
49
  describe "named scope" do
50
50
  it "works with named scope" do
51
51
  expect(doomy.by_user(1).to_sql)
52
- .to eq "select * from \"dummy\" where (user_id=1) group by time(1h) limit 100"
52
+ .to eq "select * from \"dummy\" where (user_id = 1) group by time(1h) limit 100"
53
53
  end
54
54
 
55
55
  it "works with named scope with empty relation" do
@@ -58,7 +58,7 @@ describe Influxer::Metrics, :query do
58
58
 
59
59
  it "works with several scopes" do
60
60
  expect(doomy.where(dummy_id: 100).by_user([1, 2, 3]).daily.to_sql)
61
- .to eq "select * from \"dummy\" where (dummy_id=100) and (user_id=1 or user_id=2 or user_id=3) group by time(1d) limit 100"
61
+ .to eq "select * from \"dummy\" where (dummy_id = 100) and (user_id = 1 or user_id = 2 or user_id = 3) group by time(1d) limit 100"
62
62
  end
63
63
  end
64
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Dem
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2016-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.3
33
+ version: '0.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.3
40
+ version: '0.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: anyway_config
43
43
  requirement: !ruby/object:Gem::Requirement