cassandro 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +1 -1
- data/cassandro.gemspec +1 -1
- data/lib/cassandro/ext/soft_delete.rb +11 -0
- data/test/cassandro_migration_test.rb +2 -0
- data/test/cassandro_migrator_test.rb +1 -0
- data/test/cassandro_soft_delete_test.rb +44 -0
- data/test/support/tables.rb +10 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmNlNzM0YjQyYTIyYjAzN2NjMzA5ODJjNjI1N2Y1ODhiNjZhMDBjMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjFhNWQyY2UyMzI1YmY0MzBkMjBhODE5NDk3ZjczNTYwYmM0YzU3MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2RlYTkzOWM1N2ZlNzQ1MTQ4NjA1YzI0MDNmYWQ3ZTViZTkxZWFjMmE0ZWRj
|
10
|
+
ZDY2MmQyM2U0NWMyMmE5OWZlZjZmNWY4ODg0N2ZmN2NmMzRlZWRiM2I5MzZk
|
11
|
+
NjFlZDM3YzE2NmZiNjViNGIwMjhhNzhhY2NmM2IxYWY5ZDRlZDI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODI4NjY1YmUwNWZlMTFhMTI5Yzc4ODg0Yzk1ZmYyYWQzNGU1ZTUzMGM0MmQ1
|
14
|
+
NDhmMzQyZGJiMjc1NjY0YTMwYzE2ZWRlYTBjZmViMTJlMDBjZGE4NThlMGVj
|
15
|
+
NTRjZGNlYzFmMmM2ZDk1ZWJjMTdmYWM3NmIwMmUyYzczNDI2YzE=
|
data/README.md
CHANGED
data/cassandro.gemspec
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
module Cassandro
|
2
2
|
module SoftDelete
|
3
|
+
module ClassMethods
|
4
|
+
def all(with_deleted = false)
|
5
|
+
results = super()
|
6
|
+
|
7
|
+
results.reject!{ |r| r.deleted } unless with_deleted
|
8
|
+
|
9
|
+
results
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
3
13
|
def self.included(model)
|
4
14
|
model.attribute :deleted, :boolean
|
15
|
+
model.extend ClassMethods
|
5
16
|
end
|
6
17
|
|
7
18
|
def destroy
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'support/tables'
|
3
|
+
|
4
|
+
Protest.describe "Cassandro Model Soft Delete" do
|
5
|
+
setup do
|
6
|
+
Cassandro.connect(hosts: ['127.0.0.1'], keyspace: 'cassandro_test')
|
7
|
+
|
8
|
+
class Admin < Cassandro::Model
|
9
|
+
include Cassandro::SoftDelete
|
10
|
+
|
11
|
+
table :admins
|
12
|
+
attribute :nickname, :text
|
13
|
+
|
14
|
+
primary_key :nickname
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
Admin.all(true).each do |a|
|
19
|
+
Cassandro.execute("DELETE FROM admins WHERE nickname = '#{a.nickname}'")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test "all not include deleted" do
|
24
|
+
|
25
|
+
me = Admin.create(:nickname => "k4nd4lf")
|
26
|
+
other = Admin.create(:nickname => "Jim")
|
27
|
+
|
28
|
+
me.destroy
|
29
|
+
|
30
|
+
assert !Admin.all.include?(me)
|
31
|
+
end
|
32
|
+
|
33
|
+
test "all should include deleted if asked" do
|
34
|
+
me = Admin.create(:nickname => "k4nd4lf")
|
35
|
+
other = Admin.create(:nickname => "Jim")
|
36
|
+
|
37
|
+
me.destroy
|
38
|
+
|
39
|
+
assert !Admin.all.include?(me)
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
data/test/support/tables.rb
CHANGED
@@ -18,3 +18,13 @@ table = <<-TABLEDEF
|
|
18
18
|
)
|
19
19
|
TABLEDEF
|
20
20
|
SESSION.execute(table)
|
21
|
+
|
22
|
+
SESSION.execute("DROP TABLE IF EXISTS admins")
|
23
|
+
table = <<-TABLEDEF
|
24
|
+
CREATE TABLE IF NOT EXISTS admins (
|
25
|
+
nickname VARCHAR,
|
26
|
+
deleted BOOLEAN,
|
27
|
+
PRIMARY KEY(nickname)
|
28
|
+
)
|
29
|
+
TABLEDEF
|
30
|
+
SESSION.execute(table)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassandro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lautaro Orazi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cassandra-driver
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- test/cassandro_migration_test.rb
|
78
78
|
- test/cassandro_migrator_test.rb
|
79
79
|
- test/cassandro_model_test.rb
|
80
|
+
- test/cassandro_soft_delete_test.rb
|
80
81
|
- test/cassandro_test.rb
|
81
82
|
- test/helper.rb
|
82
83
|
- test/support/migrations/animals_table.rb
|