gotime-cassandra_object 4.2.0 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '4.2.0'
5
+ s.version = '4.2.2'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "gotime"]
@@ -40,7 +40,7 @@ module CassandraObject
40
40
 
41
41
  ids = ids.compact.map(&:to_s).uniq
42
42
 
43
- where("KEY in (#{ids * ','})").to_a
43
+ where("KEY" => ids).to_a
44
44
  end
45
45
  end
46
46
  end
@@ -30,7 +30,7 @@ module CassandraObject
30
30
 
31
31
  def to_a
32
32
  statement = [
33
- "select #{select_string} from #{klass.column_family}",
33
+ "SELECT #{select_string} FROM #{klass.column_family}",
34
34
  where_string,
35
35
  limit_string
36
36
  ].delete_if(&:blank?) * ' '
@@ -52,13 +52,7 @@ module CassandraObject
52
52
  wheres = []
53
53
 
54
54
  where_values.map do |where_value|
55
- if where_value.is_a?(String)
56
- wheres << where_value
57
- elsif where_value.is_a?(Hash)
58
- where_value.each do |column, value|
59
- wheres << "#{column} = #{value}"
60
- end
61
- end
55
+ wheres.concat format_where_statement(where_value)
62
56
  end
63
57
 
64
58
  "WHERE #{wheres * ' AND '}"
@@ -67,9 +61,34 @@ module CassandraObject
67
61
  end
68
62
  end
69
63
 
64
+ def format_where_statement(where_value)
65
+ if where_value.is_a?(String)
66
+ [where_value]
67
+ elsif where_value.is_a?(Hash)
68
+ where_value.map do |column, value|
69
+ if value.is_a?(Array)
70
+ "#{column} IN (#{escape_where_value(value)})"
71
+ else
72
+ "#{column} = #{escape_where_value(value)}"
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ def escape_where_value(value)
79
+ if value.is_a?(Array)
80
+ value.map { |v| escape_where_value(v) }.join(",")
81
+ elsif value.is_a?(String)
82
+ value = value.gsub("'", "''")
83
+ "'#{value}'"
84
+ else
85
+ value
86
+ end
87
+ end
88
+
70
89
  def limit_string
71
90
  if limit_value
72
- "limit #{limit_value}"
91
+ "LIMIT #{limit_value}"
73
92
  else
74
93
  ""
75
94
  end
@@ -0,0 +1,23 @@
1
+ CassandraObject::Base.class_eval do
2
+ class_attribute :created_records
3
+ self.created_records = []
4
+
5
+ after_create do
6
+ created_records << self
7
+ end
8
+
9
+ def self.delete_after_test
10
+ created_records.reject(&:destroyed?).each(&:destroy)
11
+ created_records.clear
12
+ end
13
+ end
14
+
15
+ module ActiveSupport
16
+ class TestCase
17
+ teardown do
18
+ if CassandraObject::Base.created_records.any?
19
+ Issue.delete_all
20
+ end
21
+ end
22
+ end
23
+ end
data/test/test_helper.rb CHANGED
@@ -3,14 +3,11 @@ require 'minitest/autorun'
3
3
  Bundler.require(:default, :test)
4
4
 
5
5
  require 'support/connect'
6
- autoload :Issue, 'support/issue'
6
+ require 'support/teardown'
7
+ require 'support/issue'
7
8
 
8
9
  module CassandraObject
9
10
  class TestCase < ActiveSupport::TestCase
10
- teardown do
11
- Issue.delete_all
12
- end
13
-
14
11
  def temp_object(&block)
15
12
  Class.new(CassandraObject::Base) do
16
13
  self.column_family = 'Issues'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gotime-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -137,6 +137,7 @@ files:
137
137
  - test/performance_helper.rb
138
138
  - test/support/connect.rb
139
139
  - test/support/issue.rb
140
+ - test/support/teardown.rb
140
141
  - test/test_helper.rb
141
142
  - test/unit/active_model_test.rb
142
143
  - test/unit/attribute_methods/definition_test.rb