gotime-cassandra_object 2.6.3 → 2.6.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -30,11 +30,13 @@ module CassandraObject
|
|
30
30
|
|
31
31
|
def write_attribute(name, value)
|
32
32
|
name = name.to_s
|
33
|
-
|
34
|
-
|
35
|
-
changed_attributes[name] = old if old != value
|
36
|
-
end
|
33
|
+
old = read_attribute(name)
|
34
|
+
|
37
35
|
super
|
36
|
+
|
37
|
+
unless attribute_changed?(name) || old == read_attribute(name)
|
38
|
+
changed_attributes[name] = old
|
39
|
+
end
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
@@ -7,29 +7,40 @@ module CassandraObject
|
|
7
7
|
@record = record
|
8
8
|
@name = name.to_s
|
9
9
|
@options = options
|
10
|
-
|
10
|
+
|
11
|
+
super(array)
|
12
|
+
setify!
|
11
13
|
end
|
12
14
|
|
13
15
|
def <<(obj)
|
14
16
|
modifying do
|
15
17
|
super
|
16
|
-
uniq! if options[:unique]
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
22
|
+
def setify!
|
23
|
+
if options[:unique]
|
24
|
+
uniq!
|
25
|
+
sort!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
21
29
|
def modifying
|
22
30
|
unless record.changed_attributes.include?(name)
|
23
31
|
original = dup
|
24
32
|
end
|
25
33
|
|
26
|
-
yield
|
34
|
+
result = yield
|
35
|
+
setify!
|
27
36
|
|
28
|
-
if !record.changed_attributes.key?(name) && original
|
37
|
+
if !record.changed_attributes.key?(name) && original != self
|
29
38
|
record.changed_attributes[name] = original
|
30
39
|
end
|
31
40
|
|
32
41
|
record.send("#{name}=", self)
|
42
|
+
|
43
|
+
result
|
33
44
|
end
|
34
45
|
end
|
35
46
|
|
data/test/test_helper.rb
CHANGED
@@ -4,6 +4,11 @@ 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
|
+
|
7
12
|
class Issue < CassandraObject::Base
|
8
13
|
key :uuid
|
9
14
|
string :description
|
@@ -11,14 +16,6 @@ end
|
|
11
16
|
|
12
17
|
module CassandraObject
|
13
18
|
class TestCase < ActiveSupport::TestCase
|
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
|
-
end
|
21
|
-
|
22
19
|
teardown do
|
23
20
|
Issue.delete_all
|
24
21
|
end
|
@@ -29,7 +26,7 @@ module CassandraObject
|
|
29
26
|
end
|
30
27
|
|
31
28
|
module Types
|
32
|
-
class TestCase <
|
29
|
+
class TestCase < CassandraObject::TestCase
|
33
30
|
attr_accessor :coder
|
34
31
|
setup do
|
35
32
|
@coder = self.class.name.sub(/Test$/, '').constantize.new
|
@@ -18,19 +18,28 @@ class CassandraObject::Types::ArrayTypeTest < CassandraObject::Types::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class TestIssue < CassandraObject::Base
|
21
|
-
|
22
|
-
|
21
|
+
key :uuid
|
22
|
+
self.column_family = 'Issues'
|
23
|
+
array :favorite_colors, unique: true
|
23
24
|
end
|
24
25
|
|
25
26
|
test 'wrap' do
|
26
|
-
issue = TestIssue.
|
27
|
-
|
28
|
-
|
27
|
+
issue = TestIssue.create favorite_colors: []
|
28
|
+
assert !issue.changed?
|
29
|
+
assert_kind_of Array, issue.favorite_colors
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
issue.favorite_colors << 'red'
|
32
|
+
assert issue.changed?
|
33
|
+
assert_equal({'favorite_colors' => [[], ['red']]}, issue.changes)
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'unique array' do
|
37
|
+
issue = TestIssue.create favorite_colors: ['blue', 'red']
|
38
|
+
|
39
|
+
issue.favorite_colors = ['red', 'red', 'blue']
|
32
40
|
assert !issue.changed?
|
33
|
-
|
41
|
+
|
42
|
+
issue.favorite_colors = ['red', 'green']
|
34
43
|
assert issue.changed?
|
35
44
|
end
|
36
45
|
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.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-30 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
-
requirement: &
|
17
|
+
requirement: &70125957503400 !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: *70125957503400
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: cassandra
|
28
|
-
requirement: &
|
28
|
+
requirement: &70125957502800 !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: *70125957502800
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &70125957502140 !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: *70125957502140
|
48
48
|
description: Cassandra ActiveModel
|
49
49
|
email: gems@gotime.com
|
50
50
|
executables: []
|