gotime-cassandra_object 4.7.2 → 4.7.3

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.7.2'
5
+ s.version = '4.7.3'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "gotime"]
@@ -31,12 +31,25 @@ module CassandraObject
31
31
  execute statement_with_options(stmt, options)
32
32
  end
33
33
 
34
- def alter_column_family(column_family, options)
35
- stmt = "ALTER TABLE #{column_family}"
34
+ def alter_column_family(column_family, instruction, options = {})
35
+ stmt = "ALTER TABLE #{column_family} #{instruction}"
36
36
  execute statement_with_options(stmt, options)
37
37
  end
38
38
 
39
- def add_index()
39
+ def drop_column_family(column_family)
40
+ stmt = "DROP TABLE #{column_family}"
41
+ execute stmt
42
+ end
43
+
44
+ def add_index(column_family, column, index_name = nil)
45
+ stmt = "CREATE INDEX #{index_name.nil? ? '' : index_name} ON #{column_family} (#{column})"
46
+ execute stmt
47
+ end
48
+
49
+ def drop_index(index_name)
50
+ # If the index was not given a name during creation, the index name is <columnfamily_name>_<column_name>_idx.
51
+ stmt = "DROP INDEX #{index_name}"
52
+ execute stmt
40
53
  end
41
54
 
42
55
  private
@@ -9,7 +9,6 @@ module CassandraObject
9
9
 
10
10
  def decode(str)
11
11
  return nil if str.empty?
12
- raise ArgumentError.new("Cannot convert #{str} into a Float") unless str.kind_of?(String) && str.match(REGEX)
13
12
  str.to_f
14
13
  end
15
14
  end
@@ -9,7 +9,6 @@ module CassandraObject
9
9
 
10
10
  def decode(str)
11
11
  return nil if str.empty?
12
- raise ArgumentError.new("Cannot convert #{str} into an Integer") unless str.kind_of?(String) && str.match(REGEX)
13
12
  str.to_i
14
13
  end
15
14
  end
@@ -15,8 +15,7 @@ module CassandraObject
15
15
  end
16
16
 
17
17
  def decode(str)
18
- return nil if str.empty?
19
- raise ArgumentError.new("Cannot convert #{str} into a Time") unless str.kind_of?(String) && str.match(TimeType::REGEX)
18
+ return nil unless str && str.match(TimeType::REGEX)
20
19
  Time.xmlschema(str).in_time_zone
21
20
  end
22
21
  end
@@ -1,7 +1,9 @@
1
1
  CassandraObject::Base.config = {
2
2
  keyspace: 'cassandra_object_test',
3
3
  servers: '127.0.0.1:9160',
4
- thrift: {timeout: 10000}
4
+ thrift: {
5
+ timeout: 5
6
+ }
5
7
  }
6
8
 
7
9
  begin
@@ -10,4 +10,38 @@ class CassandraObject::SchemaTest < CassandraObject::TestCase
10
10
  rescue Exception => e
11
11
  end
12
12
  end
13
+
14
+ test "drop_column_family" do
15
+ CassandraObject::Schema.create_column_family 'TestCFToDrop'
16
+
17
+ CassandraObject::Schema.drop_column_family 'TestCFToDrop'
18
+
19
+ begin
20
+ CassandraObject::Schema.drop_column_family 'TestCFToDrop'
21
+ assert false, 'TestCFToDrop should not exist'
22
+ rescue Exception => e
23
+ end
24
+ end
25
+
26
+ test "create_index" do
27
+ CassandraObject::Schema.create_column_family 'TestIndexed'
28
+
29
+ CassandraObject::Schema.alter_column_family 'TestIndexed', "ADD id_value varchar"
30
+
31
+ CassandraObject::Schema.add_index 'TestIndexed', 'id_value'
32
+ end
33
+
34
+ test "drop_index" do
35
+ CassandraObject::Schema.create_column_family 'TestDropIndexes'
36
+
37
+ CassandraObject::Schema.alter_column_family 'TestDropIndexes', "ADD id_value1 varchar"
38
+ CassandraObject::Schema.alter_column_family 'TestDropIndexes', "ADD id_value2 varchar"
39
+
40
+ CassandraObject::Schema.add_index 'TestDropIndexes', 'id_value1'
41
+ CassandraObject::Schema.add_index 'TestDropIndexes', 'id_value2', 'special_name'
42
+
43
+ CassandraObject::Schema.drop_index 'TestDropIndexes_id_value1_idx'
44
+ CassandraObject::Schema.drop_index 'special_name'
45
+ end
46
+
13
47
  end
@@ -10,11 +10,8 @@ class CassandraObject::Types::FloatTypeTest < CassandraObject::Types::TestCase
10
10
  end
11
11
 
12
12
  test 'decode' do
13
+ assert_equal 0.0, coder.decode('xyz')
13
14
  assert_equal 3.14, coder.decode('3.14')
14
15
  assert_equal 5, coder.decode('5')
15
-
16
- assert_raise ArgumentError do
17
- coder.decode('xyz')
18
- end
19
16
  end
20
17
  end
@@ -12,6 +12,7 @@ class CassandraObject::Types::IntegerTypeTest < CassandraObject::Types::TestCase
12
12
 
13
13
  test 'decode' do
14
14
  assert_nil coder.decode('')
15
+ assert_equal 0, coder.decode('abc')
15
16
  assert_equal 3, coder.decode('3')
16
17
  assert_equal -3, coder.decode('-3')
17
18
  end
@@ -4,4 +4,10 @@ class CassandraObject::Types::TimeTypeTest < CassandraObject::Types::TestCase
4
4
  test 'encode' do
5
5
  assert_equal '2004-12-24T01:02:03.000000Z', coder.encode(Time.utc(2004, 12, 24, 1, 2, 3))
6
6
  end
7
+
8
+ test 'decode' do
9
+ assert_nil coder.decode(nil)
10
+ assert_nil coder.decode('bad format')
11
+ assert_equal Time.utc(2004, 12, 24, 1, 2, 3), coder.decode('2004-12-24T01:02:03.000000Z')
12
+ end
7
13
  end
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.7.2
4
+ version: 4.7.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-12 00:00:00.000000000 Z
13
+ date: 2013-01-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel