gotime-cassandra_object 2.6.2 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/base.rb +1 -1
- data/lib/cassandra_object/types/array_type.rb +9 -15
- data/test/dirty_test.rb +0 -12
- data/test/test_helper.rb +6 -6
- data/test/types/array_type_test.rb +10 -21
- metadata +7 -7
@@ -1,41 +1,35 @@
|
|
1
1
|
module CassandraObject
|
2
2
|
module Types
|
3
3
|
class ArrayType < BaseType
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
attr_accessor :record, :name, :array, :options
|
4
|
+
class DirtyArray < Array
|
5
|
+
attr_accessor :record, :name, :options
|
8
6
|
def initialize(record, name, array, options)
|
9
7
|
@record = record
|
10
8
|
@name = name.to_s
|
11
|
-
@array = array.presence || []
|
12
9
|
@options = options
|
10
|
+
super(array.presence || [])
|
13
11
|
end
|
14
12
|
|
15
13
|
def <<(obj)
|
16
14
|
modifying do
|
17
|
-
|
18
|
-
|
15
|
+
super
|
16
|
+
uniq! if options[:unique]
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
20
|
private
|
23
|
-
def method_missing(method, *args, &block)
|
24
|
-
array.send(method, *args, &block)
|
25
|
-
end
|
26
|
-
|
27
21
|
def modifying
|
28
22
|
unless record.changed_attributes.include?(name)
|
29
|
-
original =
|
23
|
+
original = dup
|
30
24
|
end
|
31
25
|
|
32
26
|
yield
|
33
27
|
|
34
|
-
if !record.changed_attributes.key?(name) && original.sort !=
|
28
|
+
if !record.changed_attributes.key?(name) && original.sort != sort
|
35
29
|
record.changed_attributes[name] = original
|
36
30
|
end
|
37
31
|
|
38
|
-
record.send("#{name}=",
|
32
|
+
record.send("#{name}=", self)
|
39
33
|
end
|
40
34
|
end
|
41
35
|
|
@@ -55,7 +49,7 @@ module CassandraObject
|
|
55
49
|
end
|
56
50
|
|
57
51
|
def wrap(record, name, value)
|
58
|
-
|
52
|
+
DirtyArray.new(record, name, value, options)
|
59
53
|
end
|
60
54
|
end
|
61
55
|
end
|
data/test/dirty_test.rb
CHANGED
@@ -15,16 +15,4 @@ class CassandraObject::DirtyTest < CassandraObject::TestCase
|
|
15
15
|
|
16
16
|
assert !record.changed?
|
17
17
|
end
|
18
|
-
|
19
|
-
test 'reload clears dirty' do
|
20
|
-
record = TestRecord.create!(name: 'foo')
|
21
|
-
record = TestRecord.find(record.id)
|
22
|
-
|
23
|
-
record.name = 'bar'
|
24
|
-
assert record.changed?
|
25
|
-
|
26
|
-
record.reload
|
27
|
-
|
28
|
-
assert !record.changed?
|
29
|
-
end
|
30
18
|
end
|
data/test/test_helper.rb
CHANGED
@@ -4,11 +4,6 @@ require 'test/unit'
|
|
4
4
|
require 'cassandra/0.8'
|
5
5
|
require 'gotime-cassandra_object'
|
6
6
|
|
7
|
-
CassandraObject::Base.establish_connection(
|
8
|
-
keyspace: 'place_directory_development',
|
9
|
-
servers: '127.0.0.1:9160'
|
10
|
-
)
|
11
|
-
|
12
7
|
class Issue < CassandraObject::Base
|
13
8
|
key :uuid
|
14
9
|
string :description
|
@@ -17,6 +12,11 @@ end
|
|
17
12
|
module CassandraObject
|
18
13
|
class TestCase < ActiveSupport::TestCase
|
19
14
|
setup do
|
15
|
+
CassandraObject::Base.establish_connection(
|
16
|
+
keyspace: 'place_directory_development',
|
17
|
+
# servers: '192.168.0.100:9160'
|
18
|
+
servers: '127.0.0.1:9160'
|
19
|
+
)
|
20
20
|
end
|
21
21
|
|
22
22
|
teardown do
|
@@ -29,7 +29,7 @@ module CassandraObject
|
|
29
29
|
end
|
30
30
|
|
31
31
|
module Types
|
32
|
-
class TestCase <
|
32
|
+
class TestCase < ActiveSupport::TestCase
|
33
33
|
attr_accessor :coder
|
34
34
|
setup do
|
35
35
|
@coder = self.class.name.sub(/Test$/, '').constantize.new
|
@@ -18,30 +18,19 @@ class CassandraObject::Types::ArrayTypeTest < CassandraObject::Types::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class TestIssue < CassandraObject::Base
|
21
|
-
|
22
|
-
|
23
|
-
array :favorite_colors, unique: true
|
21
|
+
self.column_family = 'Issue'
|
22
|
+
array :favorite_colors
|
24
23
|
end
|
25
24
|
|
26
|
-
test '
|
27
|
-
issue = TestIssue.new
|
28
|
-
|
29
|
-
|
30
|
-
issue.favorite_colors << 'red'
|
31
|
-
|
32
|
-
assert issue.changed?
|
33
|
-
assert_equal({'favorite_colors' => [nil, ['red']]}, issue.changes)
|
34
|
-
end
|
25
|
+
test 'wrap' do
|
26
|
+
issue = TestIssue.new
|
27
|
+
colors = []
|
28
|
+
wrapper = coder.wrap(issue, 'favorite_colors', colors)
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
issue.favorite_colors << 'red'
|
40
|
-
assert_equal ['red', 'blue'], issue.favorite_colors
|
30
|
+
assert_kind_of Array, wrapper
|
31
|
+
|
41
32
|
assert !issue.changed?
|
42
|
-
|
43
|
-
issue.
|
44
|
-
assert_equal ['red', 'blue', 'yellow'], issue.favorite_colors
|
45
|
-
assert_equal({'favorite_colors' => [['red', 'blue'], ['red', 'blue', 'yellow']]}, issue.changes)
|
33
|
+
wrapper << 'red'
|
34
|
+
assert issue.changed?
|
46
35
|
end
|
47
36
|
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: 2.6.
|
4
|
+
version: 2.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2011-08-29 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
-
requirement: &
|
17
|
+
requirement: &70252009263440 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '3.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70252009263440
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: cassandra
|
28
|
-
requirement: &
|
28
|
+
requirement: &70252009262920 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.12.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70252009262920
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &70252009262340 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: 1.0.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70252009262340
|
48
48
|
description: Cassandra ActiveModel
|
49
49
|
email: gems@gotime.com
|
50
50
|
executables: []
|