whi-cassie 1.0.5 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +12 -0
- data/.github/workflows/continuous_integration.yml +63 -0
- data/.gitignore +4 -15
- data/.standard.yml +11 -0
- data/Appraisals +13 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +89 -0
- data/HISTORY.md +49 -0
- data/README.md +30 -11
- data/Rakefile +13 -12
- data/VERSION +1 -1
- data/gemfiles/activemodel_4.gemfile +14 -0
- data/gemfiles/activemodel_5.gemfile +14 -0
- data/gemfiles/activemodel_6.gemfile +14 -0
- data/lib/cassie.rb +84 -62
- data/lib/cassie/config.rb +8 -7
- data/lib/cassie/model.rb +162 -107
- data/lib/cassie/railtie.rb +7 -5
- data/lib/cassie/schema.rb +35 -28
- data/lib/cassie/subscribers.rb +51 -0
- data/lib/cassie/testing.rb +22 -20
- data/lib/whi-cassie.rb +2 -0
- data/spec/cassie/config_spec.rb +20 -22
- data/spec/cassie/model_spec.rb +342 -275
- data/spec/cassie/subscribers_spec.rb +61 -0
- data/spec/cassie_spec.rb +116 -71
- data/spec/models/thing.rb +13 -11
- data/spec/models/type_tester.rb +7 -7
- data/spec/spec_helper.rb +35 -10
- data/whi-cassie.gemspec +16 -19
- metadata +21 -38
- data/HISTORY.txt +0 -25
data/lib/cassie/railtie.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Initialize Cassie instance with default behaviors for a Rails environment.
|
2
4
|
#
|
3
5
|
# Configuration will be gotten from config/cassie.yml.
|
@@ -6,13 +8,13 @@
|
|
6
8
|
class Cassie::Railtie < Rails::Railtie
|
7
9
|
initializer "cassie.initialization" do
|
8
10
|
Cassie.logger = Rails.logger
|
9
|
-
|
10
|
-
config_file = Rails.root +
|
11
|
+
|
12
|
+
config_file = Rails.root + "config" + "cassie.yml"
|
11
13
|
if config_file.exist?
|
12
|
-
options = YAML
|
14
|
+
options = YAML.load(ERB.new(config_file.read).result)[Rails.env] # rubocop:disable Security/YAMLLoad
|
13
15
|
if Rails.env.development? || Rails.env.test?
|
14
|
-
schema_dir = Rails.root +
|
15
|
-
options[
|
16
|
+
schema_dir = Rails.root + "db" + "cassandra"
|
17
|
+
options["schema_directory"] = schema_dir.to_s if schema_dir.exist?
|
16
18
|
end
|
17
19
|
Cassie.configure!(options)
|
18
20
|
end
|
data/lib/cassie/schema.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This class can be used to create, drop, or get information about the cassandra schemas. This class
|
2
4
|
# is intended only to provide support for creating schemas in development and test environments. You
|
3
5
|
# should not use this class with your production environment since some of the methods can be destructive.
|
@@ -8,39 +10,42 @@
|
|
8
10
|
# definition files live. The files should be named "#{abstract_keyspace}.cql". The actual keyspace name will
|
9
11
|
# be looked from the keyspace mapping in the configuration.
|
10
12
|
class Cassie::Schema
|
11
|
-
TABLES_CQL = "SELECT
|
12
|
-
|
13
|
+
TABLES_CQL = "SELECT table_name FROM system_schema.tables WHERE keyspace_name = ?"
|
14
|
+
VERSION_2_TABLES_CQL = "SELECT columnfamily_name FROM system.schema_columnfamilies WHERE keyspace_name = ?"
|
15
|
+
|
16
|
+
# rubocop:disable Lint/MixedRegexpCaptureTypes
|
13
17
|
CREATE_MATCHER = /\A(?<create>CREATE (TABLE|((CUSTOM )?INDEX)|TYPE|TRIGGER))(?<exist>( IF NOT EXISTS)?) (?<object>[a-z0-9_.]+)/i.freeze
|
14
18
|
DROP_MATCHER = /\A(?<drop>DROP (TABLE|INDEX|TYPE|TRIGGER))(?<exist>( IF EXISTS)?) (?<object>[a-z0-9_.]+)/i.freeze
|
15
|
-
|
19
|
+
# rubocop:enable Lint/MixedRegexpCaptureTypes
|
20
|
+
|
16
21
|
attr_reader :keyspace
|
17
|
-
|
22
|
+
|
18
23
|
class << self
|
19
24
|
# Get all the defined schemas.
|
20
25
|
def all
|
21
26
|
schemas.values
|
22
27
|
end
|
23
|
-
|
28
|
+
|
24
29
|
# Find the schema for a keyspace using the abstract name.
|
25
30
|
def find(keyspace)
|
26
31
|
schemas[keyspace]
|
27
32
|
end
|
28
|
-
|
33
|
+
|
29
34
|
# Throw out the cached schemas so they can be reloaded from the configuration.
|
30
35
|
def reset!
|
31
36
|
@schemas = nil
|
32
37
|
end
|
33
|
-
|
38
|
+
|
34
39
|
# Drop a specified keyspace by abstract name. The actual keyspace name will be looked up
|
35
40
|
# from the keyspaces in the configuration.
|
36
41
|
def drop!(keyspace_name)
|
37
42
|
keyspace = Cassie.instance.config.keyspace(keyspace_name)
|
38
43
|
raise ArgumentError.new("#{keyspace_name} is not defined as keyspace in the configuration") unless keyspace
|
39
|
-
|
44
|
+
|
40
45
|
drop_keyspace_cql = "DROP KEYSPACE IF EXISTS #{keyspace}"
|
41
46
|
Cassie.instance.execute(drop_keyspace_cql)
|
42
47
|
end
|
43
|
-
|
48
|
+
|
44
49
|
# Load a specified keyspace by abstract name. The actual keyspace name will be looked up
|
45
50
|
# from the keyspaces in the configuration.
|
46
51
|
def load!(keyspace_name)
|
@@ -49,24 +54,24 @@ class Cassie::Schema
|
|
49
54
|
|
50
55
|
schema_file = File.join(Cassie.instance.config.schema_directory, "#{keyspace_name}.cql")
|
51
56
|
raise ArgumentError.new("#{keyspace_name} schema file does not exist at #{schema_file}") unless File.exist?(schema_file)
|
52
|
-
schema_statements = File.read(schema_file).split(
|
53
|
-
|
57
|
+
schema_statements = File.read(schema_file).split(";").collect { |s| s.strip.chomp(";") }
|
58
|
+
|
54
59
|
create_keyspace_cql = "CREATE KEYSPACE IF NOT EXISTS #{keyspace} WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}"
|
55
60
|
Cassie.instance.execute(create_keyspace_cql)
|
56
|
-
|
61
|
+
|
57
62
|
schema_statements.each do |statement|
|
58
|
-
statement = statement.gsub(/#(.*)$/,
|
63
|
+
statement = statement.gsub(/#(.*)$/, "").gsub(/\s+/, " ").strip
|
59
64
|
create_match = statement.match(CREATE_MATCHER)
|
60
65
|
if create_match
|
61
66
|
object = create_match["object"]
|
62
|
-
object = "#{keyspace}.#{object}" unless object.include?(
|
63
|
-
statement = statement.sub(create_match.to_s, "#{create_match[
|
67
|
+
object = "#{keyspace}.#{object}" unless object.include?(".")
|
68
|
+
statement = statement.sub(create_match.to_s, "#{create_match["create"]} IF NOT EXISTS #{object}")
|
64
69
|
else
|
65
70
|
drop_match = statement.match(DROP_MATCHER)
|
66
71
|
if drop_match
|
67
72
|
object = drop_match["object"]
|
68
|
-
object = "#{keyspace}.#{object}" unless object.include?(
|
69
|
-
statement = statement.sub(drop_match.to_s, "#{drop_match[
|
73
|
+
object = "#{keyspace}.#{object}" unless object.include?(".")
|
74
|
+
statement = statement.sub(drop_match.to_s, "#{drop_match["drop"]} IF EXISTS #{object}")
|
70
75
|
end
|
71
76
|
end
|
72
77
|
unless statement.blank?
|
@@ -75,23 +80,23 @@ class Cassie::Schema
|
|
75
80
|
end
|
76
81
|
nil
|
77
82
|
end
|
78
|
-
|
83
|
+
|
79
84
|
# Drop all keyspaces defined in the configuration.
|
80
85
|
def drop_all!
|
81
86
|
Cassie.instance.config.keyspace_names.each do |keyspace|
|
82
87
|
drop!(keyspace)
|
83
88
|
end
|
84
89
|
end
|
85
|
-
|
90
|
+
|
86
91
|
# Drop all keyspaces defined in the configuration.
|
87
92
|
def load_all!
|
88
93
|
Cassie.instance.config.keyspace_names.each do |keyspace|
|
89
94
|
load!(keyspace)
|
90
95
|
end
|
91
96
|
end
|
92
|
-
|
97
|
+
|
93
98
|
private
|
94
|
-
|
99
|
+
|
95
100
|
def schemas
|
96
101
|
unless defined?(@schemas) && @schemas
|
97
102
|
schemas = {}
|
@@ -103,24 +108,26 @@ class Cassie::Schema
|
|
103
108
|
@schemas
|
104
109
|
end
|
105
110
|
end
|
106
|
-
|
111
|
+
|
107
112
|
def initialize(keyspace)
|
108
113
|
@keyspace = keyspace
|
109
114
|
end
|
110
|
-
|
115
|
+
|
111
116
|
# Returns a list of tables defined for the schema.
|
112
117
|
def tables
|
113
118
|
unless defined?(@tables) && @tables
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
119
|
+
results = nil
|
120
|
+
begin
|
121
|
+
results = Cassie.instance.execute(TABLES_CQL, keyspace)
|
122
|
+
rescue Cassandra::Errors::InvalidError
|
123
|
+
results = Cassie.instance.execute(VERSION_2_TABLES_CQL, keyspace)
|
118
124
|
end
|
125
|
+
tables = results.collect { |row| row.values.first }
|
119
126
|
@tables = tables
|
120
127
|
end
|
121
128
|
@tables
|
122
129
|
end
|
123
|
-
|
130
|
+
|
124
131
|
# Truncate the data from a table.
|
125
132
|
def truncate!(table)
|
126
133
|
statement = Cassie.instance.prepare("TRUNCATE #{keyspace}.#{table}")
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Thread safe list of subscribers. Each subscriber must respond to the :call method.
|
4
|
+
class Cassie::Subscribers
|
5
|
+
def initialize(parent_subscribers = nil)
|
6
|
+
@array = [].freeze
|
7
|
+
@lock = Mutex.new
|
8
|
+
@parent_subscribers = parent_subscribers
|
9
|
+
end
|
10
|
+
|
11
|
+
def add(subscriber)
|
12
|
+
@lock.synchronize do
|
13
|
+
new_array = @array.dup
|
14
|
+
new_array << subscriber
|
15
|
+
@array = new_array
|
16
|
+
end
|
17
|
+
end
|
18
|
+
alias_method :<<, :add
|
19
|
+
|
20
|
+
def remove(subscriber)
|
21
|
+
removed = nil
|
22
|
+
@lock.synchronize do
|
23
|
+
new_array = @array.dup
|
24
|
+
removed = new_array.delete(subscriber)
|
25
|
+
@array = new_array
|
26
|
+
end
|
27
|
+
removed
|
28
|
+
end
|
29
|
+
alias_method :delete, :remove
|
30
|
+
|
31
|
+
def clear
|
32
|
+
@array = []
|
33
|
+
end
|
34
|
+
|
35
|
+
def size
|
36
|
+
@array.size + (@parent_subscribers ? @parent_subscribers.size : 0)
|
37
|
+
end
|
38
|
+
|
39
|
+
def empty?
|
40
|
+
size == 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def each(&block)
|
44
|
+
@array.each(&block)
|
45
|
+
@parent_subscribers&.each(&block)
|
46
|
+
end
|
47
|
+
|
48
|
+
def include?(subscriber)
|
49
|
+
@array.include?(subscriber)
|
50
|
+
end
|
51
|
+
end
|
data/lib/cassie/testing.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This class provides helper methods for testing.
|
2
4
|
module Cassie::Testing
|
3
5
|
extend ActiveSupport::Concern
|
4
|
-
|
6
|
+
|
5
7
|
included do
|
6
|
-
|
8
|
+
prepend OverrideMethods
|
7
9
|
end
|
8
|
-
|
10
|
+
|
9
11
|
class << self
|
10
12
|
# Prepare the test environment. This method must be called before running the test suite.
|
11
13
|
def prepare!
|
@@ -16,31 +18,31 @@ module Cassie::Testing
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
19
|
-
|
21
|
+
|
20
22
|
# Wrap test cases as a block in this method. After the test case finishes, all tables
|
21
23
|
# that had data inserted into them will be truncated so that the data state will be clean
|
22
24
|
# for the next test case.
|
23
25
|
def cleanup!
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
schema.truncate!(table) if schema
|
33
|
-
end
|
26
|
+
yield
|
27
|
+
ensure
|
28
|
+
if Thread.current[:cassie_inserted].present?
|
29
|
+
Cassie.instance.batch do
|
30
|
+
Thread.current[:cassie_inserted].each do |table|
|
31
|
+
keyspace, table = table.split(".", 2)
|
32
|
+
schema = Cassie::Schema.find(keyspace)
|
33
|
+
schema&.truncate!(table)
|
34
34
|
end
|
35
|
-
Thread.current[:cassie_inserted] = nil
|
36
35
|
end
|
36
|
+
Thread.current[:cassie_inserted] = nil
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
|
41
|
+
module OverrideMethods
|
42
|
+
def insert(table, *args)
|
43
|
+
Thread.current[:cassie_inserted] ||= Set.new
|
44
|
+
Thread.current[:cassie_inserted] << table
|
45
|
+
super(table, *args)
|
46
|
+
end
|
45
47
|
end
|
46
48
|
end
|
data/lib/whi-cassie.rb
CHANGED
data/spec/cassie/config_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Cassie::Config do
|
4
|
-
|
5
4
|
let(:options) do
|
6
5
|
{
|
7
6
|
"cluster" => {
|
@@ -14,43 +13,42 @@ describe Cassie::Config do
|
|
14
13
|
"default_keyspace" => "another"
|
15
14
|
}
|
16
15
|
end
|
17
|
-
|
16
|
+
|
18
17
|
it "should handle empty options" do
|
19
18
|
config = Cassie::Config.new({})
|
20
|
-
config.cluster.
|
21
|
-
config.keyspace_names.
|
22
|
-
config.default_keyspace.
|
23
|
-
config.schema_directory.
|
24
|
-
config.max_prepared_statements.
|
19
|
+
expect(config.cluster).to eq({})
|
20
|
+
expect(config.keyspace_names).to eq([])
|
21
|
+
expect(config.default_keyspace).to eq(nil)
|
22
|
+
expect(config.schema_directory).to eq(nil)
|
23
|
+
expect(config.max_prepared_statements).to eq(1000)
|
25
24
|
end
|
26
|
-
|
25
|
+
|
27
26
|
it "should have cluster options" do
|
28
27
|
config = Cassie::Config.new(options)
|
29
|
-
config.cluster.
|
28
|
+
expect(config.cluster).to eq({consistency: :one, timeout: 15})
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
it "should have keyspaces" do
|
33
32
|
config = Cassie::Config.new(options)
|
34
|
-
config.keyspace(:default).
|
35
|
-
config.keyspace("other").
|
36
|
-
config.keyspace_names.
|
33
|
+
expect(config.keyspace(:default)).to start_with("test_default")
|
34
|
+
expect(config.keyspace("other")).to start_with("test_other")
|
35
|
+
expect(config.keyspace_names).to match_array(["default", "other"])
|
37
36
|
end
|
38
|
-
|
37
|
+
|
39
38
|
it "should have a default_keyspace" do
|
40
39
|
config = Cassie::Config.new(options)
|
41
|
-
config.default_keyspace.
|
40
|
+
expect(config.default_keyspace).to eq("another")
|
42
41
|
end
|
43
|
-
|
42
|
+
|
44
43
|
it "should get the schema_directory" do
|
45
44
|
config = Cassie::Config.new(options)
|
46
|
-
config.schema_directory.
|
47
|
-
Cassie::Config.new({}).schema_directory.
|
45
|
+
expect(config.schema_directory).to eq("/tmp")
|
46
|
+
expect(Cassie::Config.new({}).schema_directory).to eq(nil)
|
48
47
|
end
|
49
|
-
|
48
|
+
|
50
49
|
it "should get the max_prepared_statements" do
|
51
50
|
config = Cassie::Config.new(options)
|
52
|
-
config.max_prepared_statements.
|
53
|
-
Cassie::Config.new({}).max_prepared_statements.
|
51
|
+
expect(config.max_prepared_statements).to eq(100)
|
52
|
+
expect(Cassie::Config.new({}).max_prepared_statements).to eq(1000)
|
54
53
|
end
|
55
|
-
|
56
54
|
end
|
data/spec/cassie/model_spec.rb
CHANGED
@@ -1,506 +1,573 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Cassie::Model do
|
4
|
-
|
5
4
|
describe "definition" do
|
6
5
|
it "should define the table name" do
|
7
|
-
Cassie::Thing.table_name.
|
8
|
-
Cassie::Thing.keyspace.
|
9
|
-
Cassie::Thing.full_table_name.
|
10
|
-
Cassie::Thing.column_names.
|
6
|
+
expect(Cassie::Thing.table_name).to eq("things")
|
7
|
+
expect(Cassie::Thing.keyspace).to eq("cassie_specs")
|
8
|
+
expect(Cassie::Thing.full_table_name).to eq("cassie_specs.things")
|
9
|
+
expect(Cassie::Thing.column_names).to match_array([:owner, :id, :val])
|
11
10
|
end
|
12
|
-
|
11
|
+
|
13
12
|
it "should define the primary key" do
|
14
|
-
Cassie::Thing.primary_key.
|
13
|
+
expect(Cassie::Thing.primary_key).to eq([:owner, :id])
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
it "should alias abbreviated column names with human readable names" do
|
18
17
|
m = Cassie::Thing.new
|
19
18
|
m.id = 1
|
20
|
-
m.identifier.
|
19
|
+
expect(m.identifier).to eq(1)
|
21
20
|
m.identifier = 2
|
22
|
-
m.id.
|
21
|
+
expect(m.id).to eq(2)
|
23
22
|
end
|
24
|
-
|
23
|
+
|
25
24
|
it "should allow null values" do
|
26
|
-
Cassie::Thing.create!(:
|
27
|
-
record = Cassie::Thing.find(:
|
28
|
-
record.value.
|
25
|
+
Cassie::Thing.create!(owner: 1, id: 2)
|
26
|
+
record = Cassie::Thing.find(owner: 1, id: 2)
|
27
|
+
expect(record.value).to eq(nil)
|
29
28
|
end
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
describe "create" do
|
33
32
|
it "should create a record" do
|
34
|
-
record = Cassie::Thing.create(:
|
35
|
-
record.owner.
|
36
|
-
Cassie::Thing.find(:
|
33
|
+
record = Cassie::Thing.create(owner: 1, identifier: 2, value: "foo")
|
34
|
+
expect(record.owner).to eq(1)
|
35
|
+
expect(Cassie::Thing.find(owner: 1, identifier: 2).value).to eq("foo")
|
37
36
|
end
|
38
|
-
|
37
|
+
|
39
38
|
it "should not save an invalid record" do
|
40
|
-
record = Cassie::Thing.create(:
|
41
|
-
record.
|
42
|
-
Cassie::Thing.count(:
|
39
|
+
record = Cassie::Thing.create(owner: 1, value: "foo")
|
40
|
+
expect(record).not_to be_valid
|
41
|
+
expect(Cassie::Thing.count(owner: 1)).to eq(0)
|
43
42
|
end
|
44
|
-
|
43
|
+
|
45
44
|
it "should error on an invalid record using the bang version" do
|
46
|
-
|
45
|
+
expect { Cassie::Thing.create!(owner: 1, value: "foo") }.to raise_error(Cassie::RecordInvalid)
|
47
46
|
end
|
48
47
|
end
|
49
|
-
|
48
|
+
|
50
49
|
describe "delete_all" do
|
51
50
|
it "should delete all records matching the key" do
|
52
|
-
Cassie::Thing.create(:
|
53
|
-
Cassie::Thing.create(:
|
54
|
-
Cassie::Thing.count(:
|
55
|
-
Cassie::Thing.delete_all(:
|
56
|
-
Cassie::Thing.count(:
|
57
|
-
Cassie::Thing.find(:
|
58
|
-
Cassie::Thing.find(:
|
51
|
+
Cassie::Thing.create(owner: 1, id: 2, val: "foo")
|
52
|
+
Cassie::Thing.create(owner: 1, id: 3, val: "bar")
|
53
|
+
expect(Cassie::Thing.count(owner: 1)).to eq(2)
|
54
|
+
Cassie::Thing.delete_all(owner: 1, id: 2)
|
55
|
+
expect(Cassie::Thing.count(owner: 1)).to eq(1)
|
56
|
+
expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(nil)
|
57
|
+
expect(Cassie::Thing.find(owner: 1, id: 3)).not_to eq(nil)
|
59
58
|
end
|
60
59
|
end
|
61
|
-
|
60
|
+
|
62
61
|
describe "finding" do
|
63
|
-
let!(:r1){ Cassie::Thing.create(:
|
64
|
-
let!(:r2){ Cassie::Thing.create(:
|
65
|
-
let!(:r3){ Cassie::Thing.create(:
|
66
|
-
|
62
|
+
let!(:r1) { Cassie::Thing.create(owner: 1, id: 2, val: "foo") }
|
63
|
+
let!(:r2) { Cassie::Thing.create(owner: 1, id: 3, val: "bar") }
|
64
|
+
let!(:r3) { Cassie::Thing.create(owner: 2, id: 3, val: "blah") }
|
65
|
+
|
67
66
|
it "should find all records using a variety of syntaxes" do
|
68
|
-
Cassie::Thing.find_all(where: {:
|
69
|
-
Cassie::Thing.find_all(where: {:
|
70
|
-
Cassie::Thing.find_all(where: {:
|
71
|
-
Cassie::Thing.find_all(where: "owner = 1", order: "id ASC").
|
72
|
-
Cassie::Thing.find_all(where: ["owner = ?", 1], order: "id ASC").
|
73
|
-
Cassie::Thing.find_all(where: {:
|
74
|
-
Cassie::Thing.find_all(where: {:
|
75
|
-
Cassie::Thing.find_all(where: {:
|
76
|
-
Cassie::Thing.find_all(where: {:
|
77
|
-
end
|
78
|
-
|
67
|
+
expect(Cassie::Thing.find_all(where: {owner: 1}, order: "id ASC")).to eq([r1, r2])
|
68
|
+
expect(Cassie::Thing.find_all(where: {owner: 1}, order: "id DESC")).to eq([r2, r1])
|
69
|
+
expect(Cassie::Thing.find_all(where: {owner: 1}, order: "id ASC", limit: 1)).to eq([r1])
|
70
|
+
expect(Cassie::Thing.find_all(where: "owner = 1", order: "id ASC")).to eq([r1, r2])
|
71
|
+
expect(Cassie::Thing.find_all(where: ["owner = ?", 1], order: "id ASC")).to eq([r1, r2])
|
72
|
+
expect(Cassie::Thing.find_all(where: {owner: 0}, order: "id ASC")).to eq([])
|
73
|
+
expect(Cassie::Thing.find_all(where: {owner: 1, id: 2})).to eq([r1])
|
74
|
+
expect(Cassie::Thing.find_all(where: {owner: [1, 2]})).to match_array([r1, r2, r3])
|
75
|
+
expect(Cassie::Thing.find_all(where: {owner: [1, 2]}, options: {page_size: 1})).to match_array([r1, r2, r3])
|
76
|
+
end
|
77
|
+
|
79
78
|
it "should find one record" do
|
80
|
-
Cassie::Thing.find(:
|
81
|
-
Cassie::Thing.find(:
|
82
|
-
Cassie::Thing.find(:
|
79
|
+
expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(r1)
|
80
|
+
expect(Cassie::Thing.find(owner: 1, id: 3)).to eq(r2)
|
81
|
+
expect(Cassie::Thing.find(owner: 1, id: 0)).to eq(nil)
|
83
82
|
end
|
84
|
-
|
83
|
+
|
85
84
|
it "should raise an error if the record can't be found and called as find!" do
|
86
|
-
Cassie::Thing.find!(:
|
87
|
-
|
85
|
+
expect(Cassie::Thing.find!(owner: 1, id: 2)).to eq(r1)
|
86
|
+
expect { Cassie::Thing.find!(owner: 1, id: 0) }.to raise_error(Cassie::RecordNotFound)
|
88
87
|
end
|
89
|
-
|
88
|
+
|
90
89
|
it "should mark found records as persisted" do
|
91
|
-
Cassie::Thing.find(:
|
90
|
+
expect(Cassie::Thing.find(owner: 1, id: 2).persisted?).to eq(true)
|
92
91
|
end
|
93
|
-
|
92
|
+
|
94
93
|
it "should count records" do
|
95
|
-
Cassie::Thing.count(:
|
96
|
-
Cassie::Thing.count(:
|
94
|
+
expect(Cassie::Thing.count(owner: 1)).to eq(2)
|
95
|
+
expect(Cassie::Thing.count(owner: 1, id: 2)).to eq(1)
|
97
96
|
end
|
98
|
-
|
97
|
+
|
99
98
|
it "won't find all records with a blank where clause" do
|
100
|
-
expect{ Cassie::Thing.find_all(where: {}) }.to raise_error(ArgumentError)
|
101
|
-
Cassie::Thing.find_all(where: :all).size.
|
99
|
+
expect { Cassie::Thing.find_all(where: {}) }.to raise_error(ArgumentError)
|
100
|
+
expect(Cassie::Thing.find_all(where: :all).size).to eq(3)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should be able to add subscribers" do
|
104
|
+
global = nil
|
105
|
+
local = nil
|
106
|
+
Cassie::Model.find_subscribers << lambda { |info| global = info.rows }
|
107
|
+
Cassie::Thing.find_subscribers << lambda { |info| local = info.rows }
|
108
|
+
expect(Cassie::Thing.find_all(where: {owner: 1}).size).to eq(2)
|
109
|
+
expect(global).to eq(2)
|
110
|
+
expect(local).to eq(2)
|
102
111
|
end
|
103
112
|
end
|
104
|
-
|
113
|
+
|
105
114
|
describe "offset_to_id" do
|
106
|
-
let!(:r1){ Cassie::Thing.create(:
|
107
|
-
let!(:r2){ Cassie::Thing.create(:
|
108
|
-
let!(:r3){ Cassie::Thing.create(:
|
109
|
-
let!(:r4){ Cassie::Thing.create(:
|
110
|
-
let!(:r5){ Cassie::Thing.create(:
|
111
|
-
|
115
|
+
let!(:r1) { Cassie::Thing.create(owner: 1, id: 2, val: "foo") }
|
116
|
+
let!(:r2) { Cassie::Thing.create(owner: 1, id: 3, val: "bar") }
|
117
|
+
let!(:r3) { Cassie::Thing.create(owner: 1, id: 4, val: "blah") }
|
118
|
+
let!(:r4) { Cassie::Thing.create(owner: 1, id: 5, val: "mip") }
|
119
|
+
let!(:r5) { Cassie::Thing.create(owner: 2, id: 2, val: "grl") }
|
120
|
+
|
112
121
|
it "should calculate the ordering key at a specified offset" do
|
113
|
-
Cassie::Thing.offset_to_id({:
|
114
|
-
Cassie::Thing.offset_to_id({:
|
115
|
-
Cassie::Thing.offset_to_id({:
|
116
|
-
Cassie::Thing.offset_to_id({:
|
117
|
-
Cassie::Thing.offset_to_id({:
|
118
|
-
Cassie::Thing.offset_to_id({:
|
119
|
-
Cassie::Thing.offset_to_id({:
|
120
|
-
Cassie::Thing.offset_to_id({:
|
122
|
+
expect(Cassie::Thing.offset_to_id({owner: 1}, 2)).to eq(3)
|
123
|
+
expect(Cassie::Thing.offset_to_id({owner: 1}, 2, order: :asc)).to eq(4)
|
124
|
+
expect(Cassie::Thing.offset_to_id({owner: 1}, 2, batch_size: 1)).to eq(3)
|
125
|
+
expect(Cassie::Thing.offset_to_id({owner: 1}, 3, batch_size: 1)).to eq(2)
|
126
|
+
expect(Cassie::Thing.offset_to_id({owner: 1}, 4, batch_size: 1)).to eq(nil)
|
127
|
+
expect(Cassie::Thing.offset_to_id({owner: 1}, 4, batch_size: 100)).to eq(nil)
|
128
|
+
expect(Cassie::Thing.offset_to_id({owner: 1}, 1, batch_size: 1, min: 3)).to eq(4)
|
129
|
+
expect(Cassie::Thing.offset_to_id({owner: 1}, 1, order: :desc, batch_size: 1, max: 5)).to eq(3)
|
121
130
|
end
|
122
131
|
end
|
123
|
-
|
132
|
+
|
124
133
|
describe "batch" do
|
125
|
-
it "should delegate to Cassie.batch" do
|
126
|
-
Cassie::Thing.connection.
|
127
|
-
expect(Cassie::Thing.connection).to receive(:batch).and_call_original
|
128
|
-
Cassie::Thing.batch{}
|
134
|
+
it "should delegate to Cassie.batch using the write consistency" do
|
135
|
+
expect(Cassie::Thing.connection).to be_a(Cassie)
|
136
|
+
expect(Cassie::Thing.connection).to receive(:batch).with(consistency: :quorum).and_call_original
|
137
|
+
Cassie::Thing.batch {}
|
129
138
|
end
|
130
139
|
end
|
131
|
-
|
140
|
+
|
132
141
|
describe "attributes" do
|
133
142
|
it "should get and set attributes" do
|
134
|
-
record = Cassie::Thing.new(:
|
135
|
-
record.attributes.
|
143
|
+
record = Cassie::Thing.new(owner: 1, id: 2, val: "foo")
|
144
|
+
expect(record.attributes).to eq({owner: 1, id: 2, val: "foo"})
|
136
145
|
end
|
137
|
-
|
146
|
+
|
138
147
|
it "should get and set attributes using human readable names" do
|
139
|
-
record = Cassie::Thing.new(:
|
140
|
-
record.attributes.
|
148
|
+
record = Cassie::Thing.new(owner: 1, identifier: 2, value: "foo")
|
149
|
+
expect(record.attributes).to eq({owner: 1, id: 2, val: "foo"})
|
141
150
|
end
|
142
151
|
end
|
143
|
-
|
152
|
+
|
144
153
|
describe "save" do
|
145
154
|
it "should not save an invalid record" do
|
146
|
-
record = Cassie::Thing.new(:
|
147
|
-
record.save.
|
148
|
-
Cassie::Thing.count(:
|
155
|
+
record = Cassie::Thing.new(owner: 1, val: "foo")
|
156
|
+
expect(record.save).to eq(false)
|
157
|
+
expect(Cassie::Thing.count(owner: 1)).to eq(0)
|
149
158
|
end
|
150
|
-
|
159
|
+
|
151
160
|
it "should raise an error on the bang version on an invalid record" do
|
152
|
-
record = Cassie::Thing.new(:
|
153
|
-
|
154
|
-
Cassie::Thing.count(:
|
161
|
+
record = Cassie::Thing.new(owner: 1, val: "foo")
|
162
|
+
expect { record.save! }.to raise_error(Cassie::RecordInvalid)
|
163
|
+
expect(Cassie::Thing.count(owner: 1)).to eq(0)
|
155
164
|
end
|
156
|
-
|
165
|
+
|
157
166
|
it "should save new records and invoke the create callbacks" do
|
158
|
-
record = Cassie::Thing.new(:
|
159
|
-
record.persisted
|
160
|
-
record.save.
|
161
|
-
record.persisted
|
162
|
-
record.callbacks.
|
163
|
-
Cassie::Thing.find(:
|
164
|
-
end
|
165
|
-
|
167
|
+
record = Cassie::Thing.new(owner: 1, id: 2, val: "foo")
|
168
|
+
expect(record.persisted?).to eq(false)
|
169
|
+
expect(record.save).to eq(true)
|
170
|
+
expect(record.persisted?).to eq(true)
|
171
|
+
expect(record.callbacks).to eq([:save, :create])
|
172
|
+
expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(record)
|
173
|
+
end
|
174
|
+
|
166
175
|
it "should save existing records and invoke the update callbacks" do
|
167
|
-
Cassie::Thing.create(:
|
168
|
-
record = Cassie::Thing.find(:
|
169
|
-
record.persisted
|
170
|
-
record.value =
|
171
|
-
record.save.
|
172
|
-
record.persisted
|
173
|
-
record.callbacks.
|
174
|
-
Cassie::Thing.find(:
|
176
|
+
Cassie::Thing.create(owner: 1, id: 2, val: "foo")
|
177
|
+
record = Cassie::Thing.find(owner: 1, id: 2)
|
178
|
+
expect(record.persisted?).to eq(true)
|
179
|
+
record.value = "bar"
|
180
|
+
expect(record.save).to eq(true)
|
181
|
+
expect(record.persisted?).to eq(true)
|
182
|
+
expect(record.callbacks).to eq([:save, :update])
|
183
|
+
expect(Cassie::Thing.find(owner: 1, id: 2).value).to eq("bar")
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should save new records with a ttl" do
|
187
|
+
expect(Cassie::Thing.connection).to receive(:insert).with("cassie_specs.things", {owner: 1, id: 2, val: "foo"}, {consistency: :quorum, ttl: 10}).and_call_original
|
188
|
+
record = Cassie::Thing.new(owner: 1, id: 2, val: "foo")
|
189
|
+
expect(record.persisted?).to eq(false)
|
190
|
+
expect(record.save(ttl: 10)).to eq(true)
|
191
|
+
expect(record.persisted?).to eq(true)
|
192
|
+
expect(record.callbacks).to eq([:save, :create])
|
193
|
+
expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(record)
|
175
194
|
end
|
176
195
|
end
|
177
|
-
|
196
|
+
|
178
197
|
describe "destroy" do
|
179
198
|
it "should delete a record from Cassandra calling any destroy callbacks" do
|
180
|
-
Cassie::Thing.create(:
|
181
|
-
record = Cassie::Thing.find(:
|
199
|
+
Cassie::Thing.create(owner: 1, id: 2, val: "foo")
|
200
|
+
record = Cassie::Thing.find(owner: 1, id: 2)
|
182
201
|
record.destroy
|
183
|
-
Cassie::Thing.find(:
|
184
|
-
record.callbacks.
|
202
|
+
expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(nil)
|
203
|
+
expect(record.callbacks).to match_array([:destroy])
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "consistency" do
|
208
|
+
let(:connection) { Cassie::Thing.connection }
|
209
|
+
|
210
|
+
it "should be able to set a model level read consistency" do
|
211
|
+
expect(connection).to receive(:find).with("SELECT owner, id, val FROM cassie_specs.things WHERE owner = ?", [0], {consistency: :one}).and_call_original
|
212
|
+
Cassie::Thing.find_all(where: {owner: 0})
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should be able to override the model level read consistency" do
|
216
|
+
save_val = Cassie::Thing.read_consistency
|
217
|
+
begin
|
218
|
+
Cassie::Thing.read_consistency = :quorum
|
219
|
+
expect(connection).to receive(:find).with("SELECT owner, id, val FROM cassie_specs.things WHERE owner = ?", [0], {consistency: :quorum}).and_call_original
|
220
|
+
Cassie::Thing.find_all(where: {owner: 0})
|
221
|
+
ensure
|
222
|
+
Cassie::Thing.read_consistency = save_val
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should be able to set a model level write consistency" do
|
227
|
+
thing = Cassie::Thing.new(owner: 1, id: 2)
|
228
|
+
expect(connection).to receive(:insert).with("cassie_specs.things", {owner: 1, id: 2, val: nil}, {consistency: :quorum, ttl: nil}).and_call_original
|
229
|
+
thing.save
|
230
|
+
|
231
|
+
thing.val = "foo"
|
232
|
+
expect(connection).to receive(:update).with("cassie_specs.things", {val: "foo"}, {owner: 1, id: 2}, {consistency: :quorum, ttl: nil}).and_call_original
|
233
|
+
thing.save
|
234
|
+
|
235
|
+
expect(connection).to receive(:delete).with("cassie_specs.things", {owner: 1, id: 2}, {consistency: :quorum}).and_call_original
|
236
|
+
thing.destroy
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should be able to override the model level write consistency" do
|
240
|
+
thing = Cassie::Thing.new(owner: 1, id: 2)
|
241
|
+
thing.write_consistency = :local_quorum
|
242
|
+
|
243
|
+
expect(connection).to receive(:insert).with("cassie_specs.things", {owner: 1, id: 2, val: nil}, {consistency: :local_quorum, ttl: nil}).and_call_original
|
244
|
+
thing.save
|
245
|
+
|
246
|
+
thing.val = "foo"
|
247
|
+
expect(connection).to receive(:update).with("cassie_specs.things", {val: "foo"}, {owner: 1, id: 2}, {consistency: :local_quorum, ttl: nil}).and_call_original
|
248
|
+
thing.save
|
249
|
+
|
250
|
+
expect(connection).to receive(:delete).with("cassie_specs.things", {owner: 1, id: 2}, {consistency: :local_quorum}).and_call_original
|
251
|
+
thing.destroy
|
185
252
|
end
|
186
253
|
end
|
187
|
-
|
254
|
+
|
188
255
|
describe "type conversion" do
|
189
|
-
let(:model){ Cassie::TypeTester.new }
|
190
|
-
|
256
|
+
let(:model) { Cassie::TypeTester.new }
|
257
|
+
|
191
258
|
it "should work with varchar columns" do
|
192
259
|
model.varchar_value = "foo"
|
193
|
-
model.varchar_value.
|
260
|
+
expect(model.varchar_value).to eq("foo")
|
194
261
|
model.save
|
195
262
|
id = model.id
|
196
|
-
model = Cassie::TypeTester.find(:
|
197
|
-
model.varchar_value.
|
198
|
-
|
263
|
+
model = Cassie::TypeTester.find(id: id)
|
264
|
+
expect(model.varchar_value).to eq("foo")
|
265
|
+
|
199
266
|
model.varchar_value = nil
|
200
|
-
model.varchar_value.
|
267
|
+
expect(model.varchar_value).to eq(nil)
|
201
268
|
model.save
|
202
|
-
model = Cassie::TypeTester.find(:
|
203
|
-
model.varchar_value.
|
269
|
+
model = Cassie::TypeTester.find(id: id)
|
270
|
+
expect(model.varchar_value).to eq(nil)
|
204
271
|
end
|
205
|
-
|
272
|
+
|
206
273
|
it "should work with ascii columns" do
|
207
274
|
model.ascii_value = "foo"
|
208
|
-
model.ascii_value.
|
275
|
+
expect(model.ascii_value).to eq("foo")
|
209
276
|
model.save
|
210
277
|
id = model.id
|
211
|
-
model = Cassie::TypeTester.find(:
|
212
|
-
model.ascii_value.
|
278
|
+
model = Cassie::TypeTester.find(id: id)
|
279
|
+
expect(model.ascii_value).to eq("foo")
|
213
280
|
|
214
281
|
model.ascii_value = nil
|
215
|
-
model.ascii_value.
|
282
|
+
expect(model.ascii_value).to eq(nil)
|
216
283
|
model.save
|
217
|
-
model = Cassie::TypeTester.find(:
|
218
|
-
model.ascii_value.
|
284
|
+
model = Cassie::TypeTester.find(id: id)
|
285
|
+
expect(model.ascii_value).to eq(nil)
|
219
286
|
end
|
220
|
-
|
287
|
+
|
221
288
|
it "should work with text columns" do
|
222
289
|
model.text_value = "foo"
|
223
|
-
model.text_value.
|
290
|
+
expect(model.text_value).to eq("foo")
|
224
291
|
model.save
|
225
292
|
id = model.id
|
226
|
-
model = Cassie::TypeTester.find(:
|
227
|
-
model.text_value.
|
293
|
+
model = Cassie::TypeTester.find(id: id)
|
294
|
+
expect(model.text_value).to eq("foo")
|
228
295
|
|
229
296
|
model.text_value = nil
|
230
|
-
model.text_value.
|
297
|
+
expect(model.text_value).to eq(nil)
|
231
298
|
model.save
|
232
|
-
model = Cassie::TypeTester.find(:
|
233
|
-
model.text_value.
|
299
|
+
model = Cassie::TypeTester.find(id: id)
|
300
|
+
expect(model.text_value).to eq(nil)
|
234
301
|
end
|
235
|
-
|
302
|
+
|
236
303
|
it "should work with blob columns" do
|
237
304
|
model.blob_value = "foo"
|
238
|
-
model.blob_value.
|
305
|
+
expect(model.blob_value).to eq("foo")
|
239
306
|
model.save
|
240
307
|
id = model.id
|
241
|
-
model = Cassie::TypeTester.find(:
|
242
|
-
model.blob_value.
|
308
|
+
model = Cassie::TypeTester.find(id: id)
|
309
|
+
expect(model.blob_value).to eq("foo")
|
243
310
|
|
244
311
|
model.blob_value = nil
|
245
|
-
model.blob_value.
|
312
|
+
expect(model.blob_value).to eq(nil)
|
246
313
|
model.save
|
247
|
-
model = Cassie::TypeTester.find(:
|
248
|
-
model.blob_value.
|
314
|
+
model = Cassie::TypeTester.find(id: id)
|
315
|
+
expect(model.blob_value).to eq(nil)
|
249
316
|
end
|
250
|
-
|
317
|
+
|
251
318
|
it "should work with int columns" do
|
252
319
|
model.int_value = "1"
|
253
|
-
model.int_value.
|
320
|
+
expect(model.int_value).to eq(1)
|
254
321
|
model.int_value = 2
|
255
|
-
model.int_value.
|
322
|
+
expect(model.int_value).to eq(2)
|
256
323
|
model.save
|
257
324
|
id = model.id
|
258
|
-
model = Cassie::TypeTester.find(:
|
259
|
-
model.int_value.
|
325
|
+
model = Cassie::TypeTester.find(id: id)
|
326
|
+
expect(model.int_value).to eq(2)
|
260
327
|
|
261
328
|
model.int_value = nil
|
262
|
-
model.int_value.
|
329
|
+
expect(model.int_value).to eq(nil)
|
263
330
|
model.save
|
264
|
-
model = Cassie::TypeTester.find(:
|
265
|
-
model.int_value.
|
331
|
+
model = Cassie::TypeTester.find(id: id)
|
332
|
+
expect(model.int_value).to eq(nil)
|
266
333
|
end
|
267
|
-
|
334
|
+
|
268
335
|
it "should work with bigint columns" do
|
269
336
|
model.bigint_value = "1"
|
270
|
-
model.bigint_value.
|
337
|
+
expect(model.bigint_value).to eq(1)
|
271
338
|
model.bigint_value = 2
|
272
|
-
model.bigint_value.
|
339
|
+
expect(model.bigint_value).to eq(2)
|
273
340
|
model.save
|
274
341
|
id = model.id
|
275
|
-
model = Cassie::TypeTester.find(:
|
276
|
-
model.bigint_value.
|
342
|
+
model = Cassie::TypeTester.find(id: id)
|
343
|
+
expect(model.bigint_value).to eq(2)
|
277
344
|
|
278
345
|
model.bigint_value = nil
|
279
|
-
model.bigint_value.
|
346
|
+
expect(model.bigint_value).to eq(nil)
|
280
347
|
model.save
|
281
|
-
model = Cassie::TypeTester.find(:
|
282
|
-
model.bigint_value.
|
348
|
+
model = Cassie::TypeTester.find(id: id)
|
349
|
+
expect(model.bigint_value).to eq(nil)
|
283
350
|
end
|
284
|
-
|
351
|
+
|
285
352
|
it "should work with varint columns" do
|
286
353
|
model.varint_value = "1"
|
287
|
-
model.varint_value.
|
354
|
+
expect(model.varint_value).to eq(1)
|
288
355
|
model.varint_value = 2
|
289
|
-
model.varint_value.
|
356
|
+
expect(model.varint_value).to eq(2)
|
290
357
|
model.save
|
291
358
|
id = model.id
|
292
|
-
model = Cassie::TypeTester.find(:
|
293
|
-
model.varint_value.
|
359
|
+
model = Cassie::TypeTester.find(id: id)
|
360
|
+
expect(model.varint_value).to eq(2)
|
294
361
|
|
295
362
|
model.varint_value = nil
|
296
|
-
model.varint_value.
|
363
|
+
expect(model.varint_value).to eq(nil)
|
297
364
|
model.save
|
298
|
-
model = Cassie::TypeTester.find(:
|
299
|
-
model.varint_value.
|
365
|
+
model = Cassie::TypeTester.find(id: id)
|
366
|
+
expect(model.varint_value).to eq(nil)
|
300
367
|
end
|
301
|
-
|
368
|
+
|
302
369
|
it "should work with float columns" do
|
303
370
|
model.float_value = "1.1"
|
304
|
-
model.float_value.
|
371
|
+
expect(model.float_value).to eq(1.1)
|
305
372
|
model.float_value = 2.2
|
306
|
-
model.float_value.
|
373
|
+
expect(model.float_value).to eq(2.2)
|
307
374
|
model.save
|
308
375
|
id = model.id
|
309
|
-
model = Cassie::TypeTester.find(:
|
310
|
-
model.float_value.round(4).
|
376
|
+
model = Cassie::TypeTester.find(id: id)
|
377
|
+
expect(model.float_value.round(4)).to eq(2.2)
|
311
378
|
|
312
379
|
model.float_value = nil
|
313
|
-
model.float_value.
|
380
|
+
expect(model.float_value).to eq(nil)
|
314
381
|
model.save
|
315
|
-
model = Cassie::TypeTester.find(:
|
316
|
-
model.float_value.
|
382
|
+
model = Cassie::TypeTester.find(id: id)
|
383
|
+
expect(model.float_value).to eq(nil)
|
317
384
|
end
|
318
|
-
|
385
|
+
|
319
386
|
it "should work with double columns" do
|
320
387
|
model.double_value = "1.1"
|
321
|
-
model.double_value.
|
388
|
+
expect(model.double_value).to eq(1.1)
|
322
389
|
model.double_value = 2.2
|
323
|
-
model.double_value.
|
390
|
+
expect(model.double_value).to eq(2.2)
|
324
391
|
model.save
|
325
392
|
id = model.id
|
326
|
-
model = Cassie::TypeTester.find(:
|
327
|
-
model.double_value.
|
393
|
+
model = Cassie::TypeTester.find(id: id)
|
394
|
+
expect(model.double_value).to eq(2.2)
|
328
395
|
|
329
396
|
model.double_value = nil
|
330
|
-
model.double_value.
|
397
|
+
expect(model.double_value).to eq(nil)
|
331
398
|
model.save
|
332
|
-
model = Cassie::TypeTester.find(:
|
333
|
-
model.double_value.
|
399
|
+
model = Cassie::TypeTester.find(id: id)
|
400
|
+
expect(model.double_value).to eq(nil)
|
334
401
|
end
|
335
|
-
|
402
|
+
|
336
403
|
it "should work with decimal columns" do
|
337
404
|
model.decimal_value = "1.1"
|
338
|
-
model.decimal_value.
|
339
|
-
model.decimal_value.
|
340
|
-
model.decimal_value = BigDecimal
|
341
|
-
model.decimal_value.
|
405
|
+
expect(model.decimal_value).to eq(1.1)
|
406
|
+
expect(model.decimal_value).to be_a(BigDecimal)
|
407
|
+
model.decimal_value = BigDecimal("3.3", 2)
|
408
|
+
expect(model.decimal_value).to eq(BigDecimal("3.3", 2))
|
342
409
|
model.save
|
343
410
|
id = model.id
|
344
|
-
model = Cassie::TypeTester.find(:
|
345
|
-
model.decimal_value.
|
411
|
+
model = Cassie::TypeTester.find(id: id)
|
412
|
+
expect(model.decimal_value).to eq(BigDecimal("3.3", 2))
|
346
413
|
|
347
414
|
model.decimal_value = nil
|
348
|
-
model.decimal_value.
|
415
|
+
expect(model.decimal_value).to eq(nil)
|
349
416
|
model.save
|
350
|
-
model = Cassie::TypeTester.find(:
|
351
|
-
model.decimal_value.
|
417
|
+
model = Cassie::TypeTester.find(id: id)
|
418
|
+
expect(model.decimal_value).to eq(nil)
|
352
419
|
end
|
353
|
-
|
420
|
+
|
354
421
|
it "should work with timestamp columns" do
|
355
422
|
model.timestamp_value = "2015-04-23T15:23:30"
|
356
|
-
model.timestamp_value.
|
423
|
+
expect(model.timestamp_value).to eq(Time.new(2015, 4, 23, 15, 23, 30))
|
357
424
|
model.timestamp_value = Time.new(2015, 4, 23, 15, 25, 30)
|
358
|
-
model.timestamp_value.
|
425
|
+
expect(model.timestamp_value).to eq(Time.new(2015, 4, 23, 15, 25, 30))
|
359
426
|
model.save
|
360
427
|
id = model.id
|
361
|
-
model = Cassie::TypeTester.find(:
|
362
|
-
model.timestamp_value.
|
428
|
+
model = Cassie::TypeTester.find(id: id)
|
429
|
+
expect(model.timestamp_value).to eq(Time.new(2015, 4, 23, 15, 25, 30))
|
363
430
|
|
364
431
|
model.timestamp_value = nil
|
365
|
-
model.timestamp_value.
|
432
|
+
expect(model.timestamp_value).to eq(nil)
|
366
433
|
model.save
|
367
|
-
model = Cassie::TypeTester.find(:
|
368
|
-
model.timestamp_value.
|
434
|
+
model = Cassie::TypeTester.find(id: id)
|
435
|
+
expect(model.timestamp_value).to eq(nil)
|
369
436
|
end
|
370
|
-
|
437
|
+
|
371
438
|
it "should work with boolean columns" do
|
372
439
|
model.boolean_value = true
|
373
|
-
model.boolean_value.
|
440
|
+
expect(model.boolean_value).to eq(true)
|
374
441
|
model.boolean_value = false
|
375
|
-
model.boolean_value.
|
442
|
+
expect(model.boolean_value).to eq(false)
|
376
443
|
model.save
|
377
444
|
id = model.id
|
378
|
-
model = Cassie::TypeTester.find(:
|
379
|
-
model.boolean_value.
|
445
|
+
model = Cassie::TypeTester.find(id: id)
|
446
|
+
expect(model.boolean_value).to eq(false)
|
380
447
|
|
381
448
|
model.boolean_value = nil
|
382
|
-
model.boolean_value.
|
449
|
+
expect(model.boolean_value).to eq(nil)
|
383
450
|
model.save
|
384
|
-
model = Cassie::TypeTester.find(:
|
385
|
-
model.boolean_value.
|
451
|
+
model = Cassie::TypeTester.find(id: id)
|
452
|
+
expect(model.boolean_value).to eq(nil)
|
386
453
|
end
|
387
|
-
|
454
|
+
|
388
455
|
it "should work with inet columns" do
|
389
456
|
model.inet_value = "127.0.0.1"
|
390
|
-
model.inet_value.
|
457
|
+
expect(model.inet_value).to eq(IPAddr.new("127.0.0.1"))
|
391
458
|
model.inet_value = IPAddr.new("10.1.0.1")
|
392
|
-
model.inet_value.
|
459
|
+
expect(model.inet_value).to eq(IPAddr.new("10.1.0.1"))
|
393
460
|
model.save
|
394
461
|
id = model.id
|
395
|
-
model = Cassie::TypeTester.find(:
|
396
|
-
model.inet_value.
|
397
|
-
|
462
|
+
model = Cassie::TypeTester.find(id: id)
|
463
|
+
expect(model.inet_value).to eq(IPAddr.new("10.1.0.1"))
|
464
|
+
|
398
465
|
model.inet_value = nil
|
399
|
-
model.inet_value.
|
466
|
+
expect(model.inet_value).to eq(nil)
|
400
467
|
model.save
|
401
|
-
model = Cassie::TypeTester.find(:
|
402
|
-
model.inet_value.
|
468
|
+
model = Cassie::TypeTester.find(id: id)
|
469
|
+
expect(model.inet_value).to eq(nil)
|
403
470
|
end
|
404
|
-
|
471
|
+
|
405
472
|
it "should work with uuid columns" do
|
406
473
|
model.uuid_value = "eed6d678-ea0b-11e4-8772-793f91a64daf"
|
407
|
-
model.uuid_value.
|
474
|
+
expect(model.uuid_value).to eq(Cassandra::Uuid.new("eed6d678-ea0b-11e4-8772-793f91a64daf"))
|
408
475
|
model.uuid_value = Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
|
409
|
-
model.uuid_value.
|
476
|
+
expect(model.uuid_value).to eq(Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
|
410
477
|
model.save
|
411
478
|
id = model.id
|
412
|
-
model = Cassie::TypeTester.find(:
|
413
|
-
model.uuid_value.
|
479
|
+
model = Cassie::TypeTester.find(id: id)
|
480
|
+
expect(model.uuid_value).to eq(Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
|
414
481
|
|
415
482
|
model.uuid_value = nil
|
416
|
-
model.uuid_value.
|
483
|
+
expect(model.uuid_value).to eq(nil)
|
417
484
|
model.save
|
418
|
-
model = Cassie::TypeTester.find(:
|
419
|
-
model.uuid_value.
|
485
|
+
model = Cassie::TypeTester.find(id: id)
|
486
|
+
expect(model.uuid_value).to eq(nil)
|
420
487
|
end
|
421
|
-
|
488
|
+
|
422
489
|
it "should work with timeuuid columns" do
|
423
490
|
model.timeuuid_value = "eed6d678-ea0b-11e4-8772-793f91a64daf"
|
424
|
-
model.timeuuid_value.
|
491
|
+
expect(model.timeuuid_value).to eq(Cassandra::TimeUuid.new("eed6d678-ea0b-11e4-8772-793f91a64daf"))
|
425
492
|
model.timeuuid_value = Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
|
426
|
-
model.timeuuid_value.
|
493
|
+
expect(model.timeuuid_value).to eq(Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
|
427
494
|
model.save
|
428
495
|
id = model.id
|
429
|
-
model = Cassie::TypeTester.find(:
|
430
|
-
model.timeuuid_value.
|
496
|
+
model = Cassie::TypeTester.find(id: id)
|
497
|
+
expect(model.timeuuid_value).to eq(Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
|
431
498
|
|
432
499
|
model.timeuuid_value = nil
|
433
|
-
model.timeuuid_value.
|
500
|
+
expect(model.timeuuid_value).to eq(nil)
|
434
501
|
model.save
|
435
|
-
model = Cassie::TypeTester.find(:
|
436
|
-
model.timeuuid_value.
|
502
|
+
model = Cassie::TypeTester.find(id: id)
|
503
|
+
expect(model.timeuuid_value).to eq(nil)
|
437
504
|
end
|
438
|
-
|
505
|
+
|
439
506
|
it "should work with list columns" do
|
440
507
|
model.list_value = ["a", "b", "c"]
|
441
|
-
model.list_value.
|
508
|
+
expect(model.list_value).to eq(["a", "b", "c"])
|
442
509
|
model.save
|
443
510
|
id = model.id
|
444
|
-
model = Cassie::TypeTester.find(:
|
445
|
-
model.list_value.
|
511
|
+
model = Cassie::TypeTester.find(id: id)
|
512
|
+
expect(model.list_value).to eq(["a", "b", "c"])
|
446
513
|
|
447
514
|
model.list_value = nil
|
448
|
-
model.list_value.
|
515
|
+
expect(model.list_value).to eq(nil)
|
449
516
|
model.save
|
450
|
-
model = Cassie::TypeTester.find(:
|
451
|
-
model.list_value.
|
517
|
+
model = Cassie::TypeTester.find(id: id)
|
518
|
+
expect(model.list_value).to eq(nil)
|
452
519
|
end
|
453
|
-
|
520
|
+
|
454
521
|
it "should work with set columns" do
|
455
522
|
model.set_value = ["a", "b", "c", "a"]
|
456
|
-
model.set_value.
|
523
|
+
expect(model.set_value).to eq(["a", "b", "c"].to_set)
|
457
524
|
model.save
|
458
525
|
id = model.id
|
459
|
-
model = Cassie::TypeTester.find(:
|
460
|
-
model.set_value.
|
526
|
+
model = Cassie::TypeTester.find(id: id)
|
527
|
+
expect(model.set_value).to eq(["a", "b", "c"].to_set)
|
461
528
|
|
462
529
|
model.set_value = nil
|
463
|
-
model.set_value.
|
530
|
+
expect(model.set_value).to eq(nil)
|
464
531
|
model.save
|
465
|
-
model = Cassie::TypeTester.find(:
|
466
|
-
model.set_value.
|
532
|
+
model = Cassie::TypeTester.find(id: id)
|
533
|
+
expect(model.set_value).to eq(nil)
|
467
534
|
end
|
468
|
-
|
535
|
+
|
469
536
|
it "should work with map columns" do
|
470
537
|
model.map_value = [["a", "b"], ["c", "d"]]
|
471
|
-
model.map_value.
|
538
|
+
expect(model.map_value).to eq({"a" => "b", "c" => "d"})
|
472
539
|
model.map_value = {"e" => "f", "g" => "h"}
|
473
|
-
model.map_value.
|
540
|
+
expect(model.map_value).to eq({"e" => "f", "g" => "h"})
|
474
541
|
model.save
|
475
542
|
id = model.id
|
476
|
-
model = Cassie::TypeTester.find(:
|
477
|
-
model.map_value.
|
543
|
+
model = Cassie::TypeTester.find(id: id)
|
544
|
+
expect(model.map_value).to eq({"e" => "f", "g" => "h"})
|
478
545
|
|
479
546
|
model.map_value = nil
|
480
|
-
model.map_value.
|
547
|
+
expect(model.map_value).to eq(nil)
|
481
548
|
model.save
|
482
|
-
model = Cassie::TypeTester.find(:
|
483
|
-
model.map_value.
|
549
|
+
model = Cassie::TypeTester.find(id: id)
|
550
|
+
expect(model.map_value).to eq(nil)
|
484
551
|
end
|
485
|
-
|
552
|
+
|
486
553
|
it "should work with counter columns" do
|
487
554
|
id = SecureRandom.uuid
|
488
|
-
model = Cassie::TypeTesterCounter.new(:
|
489
|
-
model.counter_value.
|
555
|
+
model = Cassie::TypeTesterCounter.new(id: id)
|
556
|
+
expect(model.counter_value).to eq(0)
|
490
557
|
model.increment_counter_value!
|
491
|
-
model.counter_value.
|
492
|
-
model = Cassie::TypeTesterCounter.find(:
|
493
|
-
model.counter_value.
|
558
|
+
expect(model.counter_value).to eq(1)
|
559
|
+
model = Cassie::TypeTesterCounter.find(id: id)
|
560
|
+
expect(model.counter_value).to eq(1)
|
494
561
|
|
495
562
|
model.increment_counter_value!
|
496
|
-
model.counter_value.
|
497
|
-
model = Cassie::TypeTesterCounter.find(:
|
498
|
-
model.counter_value.
|
499
|
-
|
563
|
+
expect(model.counter_value).to eq(2)
|
564
|
+
model = Cassie::TypeTesterCounter.find(id: id)
|
565
|
+
expect(model.counter_value).to eq(2)
|
566
|
+
|
500
567
|
model.decrement_counter_value!
|
501
|
-
model.counter_value.
|
502
|
-
model = Cassie::TypeTesterCounter.find(:
|
503
|
-
model.counter_value.
|
568
|
+
expect(model.counter_value).to eq(1)
|
569
|
+
model = Cassie::TypeTesterCounter.find(id: id)
|
570
|
+
expect(model.counter_value).to eq(1)
|
504
571
|
end
|
505
572
|
end
|
506
573
|
end
|