whi-cassie 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 + 'config' + 'cassie.yml'
11
+
12
+ config_file = Rails.root + "config" + "cassie.yml"
11
13
  if config_file.exist?
12
- options = YAML::load(ERB.new(config_file.read).result)[Rails.env]
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 + 'db' + 'cassandra'
15
- options['schema_directory'] = schema_dir.to_s if schema_dir.exist?
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
@@ -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 columnfamily_name FROM system.schema_columnfamilies WHERE keyspace_name = ?".freeze
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(';').collect{|s| s.strip.chomp(';')}
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(/#(.*)$/, '').gsub(/\s+/, ' ').strip
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['create']} IF NOT EXISTS #{object}")
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['drop']} IF EXISTS #{object}")
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
- tables = []
115
- results = Cassie.instance.execute(TABLES_CQL, keyspace)
116
- results.each do |row|
117
- tables << row['columnfamily_name']
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}")
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Thread safe list of subscribers. Each subscriber must respond to the :call method.
2
4
  class Cassie::Subscribers
3
-
4
5
  def initialize(parent_subscribers = nil)
5
6
  @array = [].freeze
6
7
  @lock = Mutex.new
7
8
  @parent_subscribers = parent_subscribers
8
9
  end
9
-
10
+
10
11
  def add(subscriber)
11
12
  @lock.synchronize do
12
13
  new_array = @array.dup
@@ -15,7 +16,7 @@ class Cassie::Subscribers
15
16
  end
16
17
  end
17
18
  alias_method :<<, :add
18
-
19
+
19
20
  def remove(subscriber)
20
21
  removed = nil
21
22
  @lock.synchronize do
@@ -26,28 +27,25 @@ class Cassie::Subscribers
26
27
  removed
27
28
  end
28
29
  alias_method :delete, :remove
29
-
30
+
30
31
  def clear
31
32
  @array = []
32
33
  end
33
-
34
+
34
35
  def size
35
36
  @array.size + (@parent_subscribers ? @parent_subscribers.size : 0)
36
37
  end
37
-
38
+
38
39
  def empty?
39
40
  size == 0
40
41
  end
41
-
42
+
42
43
  def each(&block)
43
44
  @array.each(&block)
44
- if @parent_subscribers
45
- @parent_subscribers.each(&block)
46
- end
45
+ @parent_subscribers&.each(&block)
47
46
  end
48
-
47
+
49
48
  def include?(subscriber)
50
49
  @array.include?(subscriber)
51
50
  end
52
-
53
51
  end
@@ -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,28 +18,26 @@ 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
- begin
25
- yield
26
- ensure
27
- if Thread.current[:cassie_inserted].present?
28
- Cassie.instance.batch do
29
- Thread.current[:cassie_inserted].each do |table|
30
- keyspace, table = table.split('.', 2)
31
- schema = Cassie::Schema.find(keyspace)
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
-
40
+
41
41
  module OverrideMethods
42
42
  def insert(table, *args)
43
43
  Thread.current[:cassie_inserted] ||= Set.new
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.expand_path("../cassie.rb", __FILE__)
@@ -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.should == {}
21
- config.keyspace_names.should == []
22
- config.default_keyspace.should == nil
23
- config.schema_directory.should == nil
24
- config.max_prepared_statements.should == 1000
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.should == {:consistency => :one, :timeout => 15}
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).should start_with("test_default")
35
- config.keyspace("other").should start_with("test_other")
36
- config.keyspace_names.should =~ ["default", "other"]
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.should == "another"
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.should == "/tmp"
47
- Cassie::Config.new({}).schema_directory.should == nil
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.should == 100
53
- Cassie::Config.new({}).max_prepared_statements.should == 1000
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
@@ -1,574 +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.should == "things"
8
- Cassie::Thing.keyspace.should == "cassie_specs"
9
- Cassie::Thing.full_table_name.should == "cassie_specs.things"
10
- Cassie::Thing.column_names.should =~ [:owner, :id, :val]
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.should == [:owner, :id]
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.should == 1
19
+ expect(m.identifier).to eq(1)
21
20
  m.identifier = 2
22
- m.id.should == 2
21
+ expect(m.id).to eq(2)
23
22
  end
24
-
23
+
25
24
  it "should allow null values" do
26
- Cassie::Thing.create!(:owner => 1, :id => 2)
27
- record = Cassie::Thing.find(:owner => 1, :id => 2)
28
- record.value.should == nil
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(:owner => 1, :identifier => 2, :value => 'foo')
35
- record.owner.should == 1
36
- Cassie::Thing.find(:owner => 1, :identifier => 2).value.should == 'foo'
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(:owner => 1, :value => 'foo')
41
- record.should_not be_valid
42
- Cassie::Thing.count(:owner => 1).should == 0
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
- lambda{ Cassie::Thing.create!(:owner => 1, :value => 'foo') }.should raise_error(Cassie::RecordInvalid)
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(:owner => 1, :id => 2, :val => 'foo')
53
- Cassie::Thing.create(:owner => 1, :id => 3, :val => 'bar')
54
- Cassie::Thing.count(:owner => 1).should == 2
55
- Cassie::Thing.delete_all(:owner => 1, :id => 2)
56
- Cassie::Thing.count(:owner => 1).should == 1
57
- Cassie::Thing.find(:owner => 1, :id => 2).should == nil
58
- Cassie::Thing.find(:owner => 1, :id => 3).should_not == nil
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(:owner => 1, :id => 2, :val => 'foo') }
64
- let!(:r2){ Cassie::Thing.create(:owner => 1, :id => 3, :val => 'bar') }
65
- let!(:r3){ Cassie::Thing.create(:owner => 2, :id => 3, :val => 'blah') }
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: {:owner => 1}, order: "id ASC").should == [r1, r2]
69
- Cassie::Thing.find_all(where: {:owner => 1}, order: "id DESC").should == [r2, r1]
70
- Cassie::Thing.find_all(where: {:owner => 1}, order: "id ASC", limit: 1).should == [r1]
71
- Cassie::Thing.find_all(where: "owner = 1", order: "id ASC").should == [r1, r2]
72
- Cassie::Thing.find_all(where: ["owner = ?", 1], order: "id ASC").should == [r1, r2]
73
- Cassie::Thing.find_all(where: {:owner => 0}, order: "id ASC").should == []
74
- Cassie::Thing.find_all(where: {:owner => 1, :id => 2}).should == [r1]
75
- Cassie::Thing.find_all(where: {:owner => [1, 2]}).should =~ [r1, r2, r3]
76
- Cassie::Thing.find_all(where: {:owner => [1, 2]}, options: {:page_size => 1}).should =~ [r1, r2, r3]
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(:owner => 1, :id => 2).should == r1
81
- Cassie::Thing.find(:owner => 1, :id => 3).should == r2
82
- Cassie::Thing.find(:owner => 1, :id => 0).should == nil
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!(:owner => 1, :id => 2).should == r1
87
- lambda{ Cassie::Thing.find!(:owner => 1, :id => 0) }.should raise_error(Cassie::RecordNotFound)
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(:owner => 1, :id => 2).persisted?.should == true
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(:owner => 1).should == 2
96
- Cassie::Thing.count(:owner => 1, :id => 2).should == 1
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.should == 3
99
+ expect { Cassie::Thing.find_all(where: {}) }.to raise_error(ArgumentError)
100
+ expect(Cassie::Thing.find_all(where: :all).size).to eq(3)
102
101
  end
103
-
102
+
104
103
  it "should be able to add subscribers" do
105
104
  global = nil
106
105
  local = nil
107
- Cassie::Model.find_subscribers << lambda{|info| global = info.rows}
108
- Cassie::Thing.find_subscribers << lambda{|info| local = info.rows}
109
- Cassie::Thing.find_all(where: {:owner => 1}).size.should == 2
110
- global.should == 2
111
- local.should == 2
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)
112
111
  end
113
112
  end
114
-
113
+
115
114
  describe "offset_to_id" do
116
- let!(:r1){ Cassie::Thing.create(:owner => 1, :id => 2, :val => 'foo') }
117
- let!(:r2){ Cassie::Thing.create(:owner => 1, :id => 3, :val => 'bar') }
118
- let!(:r3){ Cassie::Thing.create(:owner => 1, :id => 4, :val => 'blah') }
119
- let!(:r4){ Cassie::Thing.create(:owner => 1, :id => 5, :val => 'mip') }
120
- let!(:r5){ Cassie::Thing.create(:owner => 2, :id => 2, :val => 'grl') }
121
-
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
+
122
121
  it "should calculate the ordering key at a specified offset" do
123
- Cassie::Thing.offset_to_id({:owner => 1}, 2).should == 3
124
- Cassie::Thing.offset_to_id({:owner => 1}, 2, order: :asc).should == 4
125
- Cassie::Thing.offset_to_id({:owner => 1}, 2, batch_size: 1).should == 3
126
- Cassie::Thing.offset_to_id({:owner => 1}, 3, batch_size: 1).should == 2
127
- Cassie::Thing.offset_to_id({:owner => 1}, 4, batch_size: 1).should == nil
128
- Cassie::Thing.offset_to_id({:owner => 1}, 4, batch_size: 100).should == nil
129
- Cassie::Thing.offset_to_id({:owner => 1}, 1, batch_size: 1, min: 3).should == 4
130
- Cassie::Thing.offset_to_id({:owner => 1}, 1, order: :desc, batch_size: 1, max: 5).should == 3
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)
131
130
  end
132
131
  end
133
-
132
+
134
133
  describe "batch" do
135
134
  it "should delegate to Cassie.batch using the write consistency" do
136
- Cassie::Thing.connection.should be_a(Cassie)
137
- expect(Cassie::Thing.connection).to receive(:batch).with(:consistency => :quorum).and_call_original
138
- Cassie::Thing.batch{}
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 {}
139
138
  end
140
139
  end
141
-
140
+
142
141
  describe "attributes" do
143
142
  it "should get and set attributes" do
144
- record = Cassie::Thing.new(:owner => 1, :id => 2, :val => 'foo')
145
- record.attributes.should == {:owner => 1, :id => 2, :val => 'foo'}
143
+ record = Cassie::Thing.new(owner: 1, id: 2, val: "foo")
144
+ expect(record.attributes).to eq({owner: 1, id: 2, val: "foo"})
146
145
  end
147
-
146
+
148
147
  it "should get and set attributes using human readable names" do
149
- record = Cassie::Thing.new(:owner => 1, :identifier => 2, :value => 'foo')
150
- record.attributes.should == {:owner => 1, :id => 2, :val => 'foo'}
148
+ record = Cassie::Thing.new(owner: 1, identifier: 2, value: "foo")
149
+ expect(record.attributes).to eq({owner: 1, id: 2, val: "foo"})
151
150
  end
152
151
  end
153
-
152
+
154
153
  describe "save" do
155
154
  it "should not save an invalid record" do
156
- record = Cassie::Thing.new(:owner => 1, :val => 'foo')
157
- record.save.should == false
158
- Cassie::Thing.count(:owner => 1).should == 0
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)
159
158
  end
160
-
159
+
161
160
  it "should raise an error on the bang version on an invalid record" do
162
- record = Cassie::Thing.new(:owner => 1, :val => 'foo')
163
- lambda{ record.save! }.should raise_error(Cassie::RecordInvalid)
164
- Cassie::Thing.count(:owner => 1).should == 0
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)
165
164
  end
166
-
165
+
167
166
  it "should save new records and invoke the create callbacks" do
168
- record = Cassie::Thing.new(:owner => 1, :id => 2, :val => 'foo')
169
- record.persisted?.should == false
170
- record.save.should == true
171
- record.persisted?.should == true
172
- record.callbacks.should == [:save, :create]
173
- Cassie::Thing.find(:owner => 1, :id => 2).should == record
174
- end
175
-
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
+
176
175
  it "should save existing records and invoke the update callbacks" do
177
- Cassie::Thing.create(:owner => 1, :id => 2, :val => 'foo')
178
- record = Cassie::Thing.find(:owner => 1, :id => 2)
179
- record.persisted?.should == true
180
- record.value = 'bar'
181
- record.save.should == true
182
- record.persisted?.should == true
183
- record.callbacks.should == [:save, :update]
184
- Cassie::Thing.find(:owner => 1, :id => 2).value.should == 'bar'
185
- end
186
-
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
+
187
186
  it "should save new records with a ttl" do
188
- expect(Cassie::Thing.connection).to receive(:insert).with("cassie_specs.things", {:owner=>1, :id=>2, :val=>'foo'}, {:consistency=>:quorum, :ttl=>10}).and_call_original
189
- record = Cassie::Thing.new(:owner => 1, :id => 2, :val => 'foo')
190
- record.persisted?.should == false
191
- record.save(ttl: 10).should == true
192
- record.persisted?.should == true
193
- record.callbacks.should == [:save, :create]
194
- Cassie::Thing.find(:owner => 1, :id => 2).should == record
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)
195
194
  end
196
195
  end
197
-
196
+
198
197
  describe "destroy" do
199
198
  it "should delete a record from Cassandra calling any destroy callbacks" do
200
- Cassie::Thing.create(:owner => 1, :id => 2, :val => 'foo')
201
- record = Cassie::Thing.find(:owner => 1, :id => 2)
199
+ Cassie::Thing.create(owner: 1, id: 2, val: "foo")
200
+ record = Cassie::Thing.find(owner: 1, id: 2)
202
201
  record.destroy
203
- Cassie::Thing.find(:owner => 1, :id => 2).should == nil
204
- record.callbacks.should =~ [:destroy]
202
+ expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(nil)
203
+ expect(record.callbacks).to match_array([:destroy])
205
204
  end
206
205
  end
207
-
206
+
208
207
  describe "consistency" do
209
- let(:connection){ Cassie::Thing.connection }
208
+ let(:connection) { Cassie::Thing.connection }
210
209
 
211
210
  it "should be able to set a model level read consistency" do
212
- expect(connection).to receive(:find).with("SELECT owner, id, val FROM cassie_specs.things WHERE owner = ?", [0], {:consistency => :one}).and_call_original
213
- Cassie::Thing.find_all(where: {:owner => 0})
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})
214
213
  end
215
-
214
+
216
215
  it "should be able to override the model level read consistency" do
217
216
  save_val = Cassie::Thing.read_consistency
218
217
  begin
219
218
  Cassie::Thing.read_consistency = :quorum
220
- expect(connection).to receive(:find).with("SELECT owner, id, val FROM cassie_specs.things WHERE owner = ?", [0], {:consistency => :quorum}).and_call_original
221
- Cassie::Thing.find_all(where: {:owner => 0})
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})
222
221
  ensure
223
222
  Cassie::Thing.read_consistency = save_val
224
223
  end
225
224
  end
226
-
225
+
227
226
  it "should be able to set a model level write consistency" do
228
- thing = Cassie::Thing.new(:owner => 1, :id => 2)
229
- expect(connection).to receive(:insert).with("cassie_specs.things", {:owner=>1, :id=>2, :val=>nil}, {:consistency=>:quorum, :ttl=>nil}).and_call_original
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
230
229
  thing.save
231
-
230
+
232
231
  thing.val = "foo"
233
- expect(connection).to receive(:update).with("cassie_specs.things", {:val=>"foo"}, {:owner=>1, :id=>2}, {:consistency=>:quorum, :ttl=>nil}).and_call_original
232
+ expect(connection).to receive(:update).with("cassie_specs.things", {val: "foo"}, {owner: 1, id: 2}, {consistency: :quorum, ttl: nil}).and_call_original
234
233
  thing.save
235
-
236
- expect(connection).to receive(:delete).with("cassie_specs.things", {:owner=>1, :id=>2}, {:consistency=>:quorum}).and_call_original
234
+
235
+ expect(connection).to receive(:delete).with("cassie_specs.things", {owner: 1, id: 2}, {consistency: :quorum}).and_call_original
237
236
  thing.destroy
238
237
  end
239
-
238
+
240
239
  it "should be able to override the model level write consistency" do
241
- thing = Cassie::Thing.new(:owner => 1, :id => 2)
240
+ thing = Cassie::Thing.new(owner: 1, id: 2)
242
241
  thing.write_consistency = :local_quorum
243
-
244
- expect(connection).to receive(:insert).with("cassie_specs.things", {:owner=>1, :id=>2, :val=>nil}, {:consistency=>:local_quorum, :ttl=>nil}).and_call_original
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
245
244
  thing.save
246
-
245
+
247
246
  thing.val = "foo"
248
- expect(connection).to receive(:update).with("cassie_specs.things", {:val=>"foo"}, {:owner=>1, :id=>2}, {:consistency=>:local_quorum, :ttl=>nil}).and_call_original
247
+ expect(connection).to receive(:update).with("cassie_specs.things", {val: "foo"}, {owner: 1, id: 2}, {consistency: :local_quorum, ttl: nil}).and_call_original
249
248
  thing.save
250
-
251
- expect(connection).to receive(:delete).with("cassie_specs.things", {:owner=>1, :id=>2}, {:consistency=>:local_quorum}).and_call_original
249
+
250
+ expect(connection).to receive(:delete).with("cassie_specs.things", {owner: 1, id: 2}, {consistency: :local_quorum}).and_call_original
252
251
  thing.destroy
253
252
  end
254
253
  end
255
-
254
+
256
255
  describe "type conversion" do
257
- let(:model){ Cassie::TypeTester.new }
258
-
256
+ let(:model) { Cassie::TypeTester.new }
257
+
259
258
  it "should work with varchar columns" do
260
259
  model.varchar_value = "foo"
261
- model.varchar_value.should == "foo"
260
+ expect(model.varchar_value).to eq("foo")
262
261
  model.save
263
262
  id = model.id
264
- model = Cassie::TypeTester.find(:id => id)
265
- model.varchar_value.should == "foo"
266
-
263
+ model = Cassie::TypeTester.find(id: id)
264
+ expect(model.varchar_value).to eq("foo")
265
+
267
266
  model.varchar_value = nil
268
- model.varchar_value.should == nil
267
+ expect(model.varchar_value).to eq(nil)
269
268
  model.save
270
- model = Cassie::TypeTester.find(:id => id)
271
- model.varchar_value.should == nil
269
+ model = Cassie::TypeTester.find(id: id)
270
+ expect(model.varchar_value).to eq(nil)
272
271
  end
273
-
272
+
274
273
  it "should work with ascii columns" do
275
274
  model.ascii_value = "foo"
276
- model.ascii_value.should == "foo"
275
+ expect(model.ascii_value).to eq("foo")
277
276
  model.save
278
277
  id = model.id
279
- model = Cassie::TypeTester.find(:id => id)
280
- model.ascii_value.should == "foo"
278
+ model = Cassie::TypeTester.find(id: id)
279
+ expect(model.ascii_value).to eq("foo")
281
280
 
282
281
  model.ascii_value = nil
283
- model.ascii_value.should == nil
282
+ expect(model.ascii_value).to eq(nil)
284
283
  model.save
285
- model = Cassie::TypeTester.find(:id => id)
286
- model.ascii_value.should == nil
284
+ model = Cassie::TypeTester.find(id: id)
285
+ expect(model.ascii_value).to eq(nil)
287
286
  end
288
-
287
+
289
288
  it "should work with text columns" do
290
289
  model.text_value = "foo"
291
- model.text_value.should == "foo"
290
+ expect(model.text_value).to eq("foo")
292
291
  model.save
293
292
  id = model.id
294
- model = Cassie::TypeTester.find(:id => id)
295
- model.text_value.should == "foo"
293
+ model = Cassie::TypeTester.find(id: id)
294
+ expect(model.text_value).to eq("foo")
296
295
 
297
296
  model.text_value = nil
298
- model.text_value.should == nil
297
+ expect(model.text_value).to eq(nil)
299
298
  model.save
300
- model = Cassie::TypeTester.find(:id => id)
301
- model.text_value.should == nil
299
+ model = Cassie::TypeTester.find(id: id)
300
+ expect(model.text_value).to eq(nil)
302
301
  end
303
-
302
+
304
303
  it "should work with blob columns" do
305
304
  model.blob_value = "foo"
306
- model.blob_value.should == "foo"
305
+ expect(model.blob_value).to eq("foo")
307
306
  model.save
308
307
  id = model.id
309
- model = Cassie::TypeTester.find(:id => id)
310
- model.blob_value.should == "foo"
308
+ model = Cassie::TypeTester.find(id: id)
309
+ expect(model.blob_value).to eq("foo")
311
310
 
312
311
  model.blob_value = nil
313
- model.blob_value.should == nil
312
+ expect(model.blob_value).to eq(nil)
314
313
  model.save
315
- model = Cassie::TypeTester.find(:id => id)
316
- model.blob_value.should == nil
314
+ model = Cassie::TypeTester.find(id: id)
315
+ expect(model.blob_value).to eq(nil)
317
316
  end
318
-
317
+
319
318
  it "should work with int columns" do
320
319
  model.int_value = "1"
321
- model.int_value.should == 1
320
+ expect(model.int_value).to eq(1)
322
321
  model.int_value = 2
323
- model.int_value.should == 2
322
+ expect(model.int_value).to eq(2)
324
323
  model.save
325
324
  id = model.id
326
- model = Cassie::TypeTester.find(:id => id)
327
- model.int_value.should == 2
325
+ model = Cassie::TypeTester.find(id: id)
326
+ expect(model.int_value).to eq(2)
328
327
 
329
328
  model.int_value = nil
330
- model.int_value.should == nil
329
+ expect(model.int_value).to eq(nil)
331
330
  model.save
332
- model = Cassie::TypeTester.find(:id => id)
333
- model.int_value.should == nil
331
+ model = Cassie::TypeTester.find(id: id)
332
+ expect(model.int_value).to eq(nil)
334
333
  end
335
-
334
+
336
335
  it "should work with bigint columns" do
337
336
  model.bigint_value = "1"
338
- model.bigint_value.should == 1
337
+ expect(model.bigint_value).to eq(1)
339
338
  model.bigint_value = 2
340
- model.bigint_value.should == 2
339
+ expect(model.bigint_value).to eq(2)
341
340
  model.save
342
341
  id = model.id
343
- model = Cassie::TypeTester.find(:id => id)
344
- model.bigint_value.should == 2
342
+ model = Cassie::TypeTester.find(id: id)
343
+ expect(model.bigint_value).to eq(2)
345
344
 
346
345
  model.bigint_value = nil
347
- model.bigint_value.should == nil
346
+ expect(model.bigint_value).to eq(nil)
348
347
  model.save
349
- model = Cassie::TypeTester.find(:id => id)
350
- model.bigint_value.should == nil
348
+ model = Cassie::TypeTester.find(id: id)
349
+ expect(model.bigint_value).to eq(nil)
351
350
  end
352
-
351
+
353
352
  it "should work with varint columns" do
354
353
  model.varint_value = "1"
355
- model.varint_value.should == 1
354
+ expect(model.varint_value).to eq(1)
356
355
  model.varint_value = 2
357
- model.varint_value.should == 2
356
+ expect(model.varint_value).to eq(2)
358
357
  model.save
359
358
  id = model.id
360
- model = Cassie::TypeTester.find(:id => id)
361
- model.varint_value.should == 2
359
+ model = Cassie::TypeTester.find(id: id)
360
+ expect(model.varint_value).to eq(2)
362
361
 
363
362
  model.varint_value = nil
364
- model.varint_value.should == nil
363
+ expect(model.varint_value).to eq(nil)
365
364
  model.save
366
- model = Cassie::TypeTester.find(:id => id)
367
- model.varint_value.should == nil
365
+ model = Cassie::TypeTester.find(id: id)
366
+ expect(model.varint_value).to eq(nil)
368
367
  end
369
-
368
+
370
369
  it "should work with float columns" do
371
370
  model.float_value = "1.1"
372
- model.float_value.should == 1.1
371
+ expect(model.float_value).to eq(1.1)
373
372
  model.float_value = 2.2
374
- model.float_value.should == 2.2
373
+ expect(model.float_value).to eq(2.2)
375
374
  model.save
376
375
  id = model.id
377
- model = Cassie::TypeTester.find(:id => id)
378
- model.float_value.round(4).should == 2.2
376
+ model = Cassie::TypeTester.find(id: id)
377
+ expect(model.float_value.round(4)).to eq(2.2)
379
378
 
380
379
  model.float_value = nil
381
- model.float_value.should == nil
380
+ expect(model.float_value).to eq(nil)
382
381
  model.save
383
- model = Cassie::TypeTester.find(:id => id)
384
- model.float_value.should == nil
382
+ model = Cassie::TypeTester.find(id: id)
383
+ expect(model.float_value).to eq(nil)
385
384
  end
386
-
385
+
387
386
  it "should work with double columns" do
388
387
  model.double_value = "1.1"
389
- model.double_value.should == 1.1
388
+ expect(model.double_value).to eq(1.1)
390
389
  model.double_value = 2.2
391
- model.double_value.should == 2.2
390
+ expect(model.double_value).to eq(2.2)
392
391
  model.save
393
392
  id = model.id
394
- model = Cassie::TypeTester.find(:id => id)
395
- model.double_value.should == 2.2
393
+ model = Cassie::TypeTester.find(id: id)
394
+ expect(model.double_value).to eq(2.2)
396
395
 
397
396
  model.double_value = nil
398
- model.double_value.should == nil
397
+ expect(model.double_value).to eq(nil)
399
398
  model.save
400
- model = Cassie::TypeTester.find(:id => id)
401
- model.double_value.should == nil
399
+ model = Cassie::TypeTester.find(id: id)
400
+ expect(model.double_value).to eq(nil)
402
401
  end
403
-
402
+
404
403
  it "should work with decimal columns" do
405
404
  model.decimal_value = "1.1"
406
- model.decimal_value.should == 1.1
407
- model.decimal_value.should be_a(BigDecimal)
408
- model.decimal_value = BigDecimal.new("3.3", 2)
409
- model.decimal_value.should == BigDecimal.new("3.3", 2)
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))
410
409
  model.save
411
410
  id = model.id
412
- model = Cassie::TypeTester.find(:id => id)
413
- model.decimal_value.should == BigDecimal.new("3.3", 2)
411
+ model = Cassie::TypeTester.find(id: id)
412
+ expect(model.decimal_value).to eq(BigDecimal("3.3", 2))
414
413
 
415
414
  model.decimal_value = nil
416
- model.decimal_value.should == nil
415
+ expect(model.decimal_value).to eq(nil)
417
416
  model.save
418
- model = Cassie::TypeTester.find(:id => id)
419
- model.decimal_value.should == nil
417
+ model = Cassie::TypeTester.find(id: id)
418
+ expect(model.decimal_value).to eq(nil)
420
419
  end
421
-
420
+
422
421
  it "should work with timestamp columns" do
423
422
  model.timestamp_value = "2015-04-23T15:23:30"
424
- model.timestamp_value.should == Time.new(2015, 4, 23, 15, 23, 30)
423
+ expect(model.timestamp_value).to eq(Time.new(2015, 4, 23, 15, 23, 30))
425
424
  model.timestamp_value = Time.new(2015, 4, 23, 15, 25, 30)
426
- model.timestamp_value.should == Time.new(2015, 4, 23, 15, 25, 30)
425
+ expect(model.timestamp_value).to eq(Time.new(2015, 4, 23, 15, 25, 30))
427
426
  model.save
428
427
  id = model.id
429
- model = Cassie::TypeTester.find(:id => id)
430
- model.timestamp_value.should == Time.new(2015, 4, 23, 15, 25, 30)
428
+ model = Cassie::TypeTester.find(id: id)
429
+ expect(model.timestamp_value).to eq(Time.new(2015, 4, 23, 15, 25, 30))
431
430
 
432
431
  model.timestamp_value = nil
433
- model.timestamp_value.should == nil
432
+ expect(model.timestamp_value).to eq(nil)
434
433
  model.save
435
- model = Cassie::TypeTester.find(:id => id)
436
- model.timestamp_value.should == nil
434
+ model = Cassie::TypeTester.find(id: id)
435
+ expect(model.timestamp_value).to eq(nil)
437
436
  end
438
-
437
+
439
438
  it "should work with boolean columns" do
440
439
  model.boolean_value = true
441
- model.boolean_value.should == true
440
+ expect(model.boolean_value).to eq(true)
442
441
  model.boolean_value = false
443
- model.boolean_value.should == false
442
+ expect(model.boolean_value).to eq(false)
444
443
  model.save
445
444
  id = model.id
446
- model = Cassie::TypeTester.find(:id => id)
447
- model.boolean_value.should == false
445
+ model = Cassie::TypeTester.find(id: id)
446
+ expect(model.boolean_value).to eq(false)
448
447
 
449
448
  model.boolean_value = nil
450
- model.boolean_value.should == nil
449
+ expect(model.boolean_value).to eq(nil)
451
450
  model.save
452
- model = Cassie::TypeTester.find(:id => id)
453
- model.boolean_value.should == nil
451
+ model = Cassie::TypeTester.find(id: id)
452
+ expect(model.boolean_value).to eq(nil)
454
453
  end
455
-
454
+
456
455
  it "should work with inet columns" do
457
456
  model.inet_value = "127.0.0.1"
458
- model.inet_value.should == IPAddr.new("127.0.0.1")
457
+ expect(model.inet_value).to eq(IPAddr.new("127.0.0.1"))
459
458
  model.inet_value = IPAddr.new("10.1.0.1")
460
- model.inet_value.should == IPAddr.new("10.1.0.1")
459
+ expect(model.inet_value).to eq(IPAddr.new("10.1.0.1"))
461
460
  model.save
462
461
  id = model.id
463
- model = Cassie::TypeTester.find(:id => id)
464
- model.inet_value.should == IPAddr.new("10.1.0.1")
465
-
462
+ model = Cassie::TypeTester.find(id: id)
463
+ expect(model.inet_value).to eq(IPAddr.new("10.1.0.1"))
464
+
466
465
  model.inet_value = nil
467
- model.inet_value.should == nil
466
+ expect(model.inet_value).to eq(nil)
468
467
  model.save
469
- model = Cassie::TypeTester.find(:id => id)
470
- model.inet_value.should == nil
468
+ model = Cassie::TypeTester.find(id: id)
469
+ expect(model.inet_value).to eq(nil)
471
470
  end
472
-
471
+
473
472
  it "should work with uuid columns" do
474
473
  model.uuid_value = "eed6d678-ea0b-11e4-8772-793f91a64daf"
475
- model.uuid_value.should == Cassandra::Uuid.new("eed6d678-ea0b-11e4-8772-793f91a64daf")
474
+ expect(model.uuid_value).to eq(Cassandra::Uuid.new("eed6d678-ea0b-11e4-8772-793f91a64daf"))
476
475
  model.uuid_value = Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
477
- model.uuid_value.should == Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
476
+ expect(model.uuid_value).to eq(Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
478
477
  model.save
479
478
  id = model.id
480
- model = Cassie::TypeTester.find(:id => id)
481
- model.uuid_value.should == Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
479
+ model = Cassie::TypeTester.find(id: id)
480
+ expect(model.uuid_value).to eq(Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
482
481
 
483
482
  model.uuid_value = nil
484
- model.uuid_value.should == nil
483
+ expect(model.uuid_value).to eq(nil)
485
484
  model.save
486
- model = Cassie::TypeTester.find(:id => id)
487
- model.uuid_value.should == nil
485
+ model = Cassie::TypeTester.find(id: id)
486
+ expect(model.uuid_value).to eq(nil)
488
487
  end
489
-
488
+
490
489
  it "should work with timeuuid columns" do
491
490
  model.timeuuid_value = "eed6d678-ea0b-11e4-8772-793f91a64daf"
492
- model.timeuuid_value.should == Cassandra::TimeUuid.new("eed6d678-ea0b-11e4-8772-793f91a64daf")
491
+ expect(model.timeuuid_value).to eq(Cassandra::TimeUuid.new("eed6d678-ea0b-11e4-8772-793f91a64daf"))
493
492
  model.timeuuid_value = Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
494
- model.timeuuid_value.should == Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
493
+ expect(model.timeuuid_value).to eq(Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
495
494
  model.save
496
495
  id = model.id
497
- model = Cassie::TypeTester.find(:id => id)
498
- model.timeuuid_value.should == Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
496
+ model = Cassie::TypeTester.find(id: id)
497
+ expect(model.timeuuid_value).to eq(Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
499
498
 
500
499
  model.timeuuid_value = nil
501
- model.timeuuid_value.should == nil
500
+ expect(model.timeuuid_value).to eq(nil)
502
501
  model.save
503
- model = Cassie::TypeTester.find(:id => id)
504
- model.timeuuid_value.should == nil
502
+ model = Cassie::TypeTester.find(id: id)
503
+ expect(model.timeuuid_value).to eq(nil)
505
504
  end
506
-
505
+
507
506
  it "should work with list columns" do
508
507
  model.list_value = ["a", "b", "c"]
509
- model.list_value.should == ["a", "b", "c"]
508
+ expect(model.list_value).to eq(["a", "b", "c"])
510
509
  model.save
511
510
  id = model.id
512
- model = Cassie::TypeTester.find(:id => id)
513
- model.list_value.should == ["a", "b", "c"]
511
+ model = Cassie::TypeTester.find(id: id)
512
+ expect(model.list_value).to eq(["a", "b", "c"])
514
513
 
515
514
  model.list_value = nil
516
- model.list_value.should == nil
515
+ expect(model.list_value).to eq(nil)
517
516
  model.save
518
- model = Cassie::TypeTester.find(:id => id)
519
- model.list_value.should == nil
517
+ model = Cassie::TypeTester.find(id: id)
518
+ expect(model.list_value).to eq(nil)
520
519
  end
521
-
520
+
522
521
  it "should work with set columns" do
523
522
  model.set_value = ["a", "b", "c", "a"]
524
- model.set_value.should == ["a", "b", "c"].to_set
523
+ expect(model.set_value).to eq(["a", "b", "c"].to_set)
525
524
  model.save
526
525
  id = model.id
527
- model = Cassie::TypeTester.find(:id => id)
528
- model.set_value.should == ["a", "b", "c"].to_set
526
+ model = Cassie::TypeTester.find(id: id)
527
+ expect(model.set_value).to eq(["a", "b", "c"].to_set)
529
528
 
530
529
  model.set_value = nil
531
- model.set_value.should == nil
530
+ expect(model.set_value).to eq(nil)
532
531
  model.save
533
- model = Cassie::TypeTester.find(:id => id)
534
- model.set_value.should == nil
532
+ model = Cassie::TypeTester.find(id: id)
533
+ expect(model.set_value).to eq(nil)
535
534
  end
536
-
535
+
537
536
  it "should work with map columns" do
538
537
  model.map_value = [["a", "b"], ["c", "d"]]
539
- model.map_value.should == {"a" => "b", "c" => "d"}
538
+ expect(model.map_value).to eq({"a" => "b", "c" => "d"})
540
539
  model.map_value = {"e" => "f", "g" => "h"}
541
- model.map_value.should == {"e" => "f", "g" => "h"}
540
+ expect(model.map_value).to eq({"e" => "f", "g" => "h"})
542
541
  model.save
543
542
  id = model.id
544
- model = Cassie::TypeTester.find(:id => id)
545
- model.map_value.should == {"e" => "f", "g" => "h"}
543
+ model = Cassie::TypeTester.find(id: id)
544
+ expect(model.map_value).to eq({"e" => "f", "g" => "h"})
546
545
 
547
546
  model.map_value = nil
548
- model.map_value.should == nil
547
+ expect(model.map_value).to eq(nil)
549
548
  model.save
550
- model = Cassie::TypeTester.find(:id => id)
551
- model.map_value.should == nil
549
+ model = Cassie::TypeTester.find(id: id)
550
+ expect(model.map_value).to eq(nil)
552
551
  end
553
-
552
+
554
553
  it "should work with counter columns" do
555
554
  id = SecureRandom.uuid
556
- model = Cassie::TypeTesterCounter.new(:id => id)
557
- model.counter_value.should == 0
555
+ model = Cassie::TypeTesterCounter.new(id: id)
556
+ expect(model.counter_value).to eq(0)
558
557
  model.increment_counter_value!
559
- model.counter_value.should == 1
560
- model = Cassie::TypeTesterCounter.find(:id => id)
561
- model.counter_value.should == 1
558
+ expect(model.counter_value).to eq(1)
559
+ model = Cassie::TypeTesterCounter.find(id: id)
560
+ expect(model.counter_value).to eq(1)
562
561
 
563
562
  model.increment_counter_value!
564
- model.counter_value.should == 2
565
- model = Cassie::TypeTesterCounter.find(:id => id)
566
- model.counter_value.should == 2
567
-
563
+ expect(model.counter_value).to eq(2)
564
+ model = Cassie::TypeTesterCounter.find(id: id)
565
+ expect(model.counter_value).to eq(2)
566
+
568
567
  model.decrement_counter_value!
569
- model.counter_value.should == 1
570
- model = Cassie::TypeTesterCounter.find(:id => id)
571
- model.counter_value.should == 1
568
+ expect(model.counter_value).to eq(1)
569
+ model = Cassie::TypeTesterCounter.find(id: id)
570
+ expect(model.counter_value).to eq(1)
572
571
  end
573
572
  end
574
573
  end