cassanity 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +11 -0
  5. data/Guardfile +17 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +99 -0
  8. data/Rakefile +16 -0
  9. data/cassanity.gemspec +21 -0
  10. data/examples/_shared.rb +8 -0
  11. data/examples/batch.rb +40 -0
  12. data/examples/column_families.rb +68 -0
  13. data/examples/keyspaces.rb +57 -0
  14. data/lib/cassanity/argument_generators/batch.rb +52 -0
  15. data/lib/cassanity/argument_generators/column_family_alter.rb +47 -0
  16. data/lib/cassanity/argument_generators/column_family_create.rb +44 -0
  17. data/lib/cassanity/argument_generators/column_family_delete.rb +65 -0
  18. data/lib/cassanity/argument_generators/column_family_drop.rb +18 -0
  19. data/lib/cassanity/argument_generators/column_family_insert.rb +53 -0
  20. data/lib/cassanity/argument_generators/column_family_select.rb +34 -0
  21. data/lib/cassanity/argument_generators/column_family_truncate.rb +18 -0
  22. data/lib/cassanity/argument_generators/column_family_update.rb +69 -0
  23. data/lib/cassanity/argument_generators/index_create.rb +22 -0
  24. data/lib/cassanity/argument_generators/index_drop.rb +13 -0
  25. data/lib/cassanity/argument_generators/keyspace_create.rb +51 -0
  26. data/lib/cassanity/argument_generators/keyspace_drop.rb +13 -0
  27. data/lib/cassanity/argument_generators/keyspace_use.rb +13 -0
  28. data/lib/cassanity/argument_generators/keyspaces.rb +12 -0
  29. data/lib/cassanity/argument_generators/set_clause.rb +30 -0
  30. data/lib/cassanity/argument_generators/using_clause.rb +24 -0
  31. data/lib/cassanity/argument_generators/where_clause.rb +29 -0
  32. data/lib/cassanity/argument_generators/with_clause.rb +32 -0
  33. data/lib/cassanity/column_family.rb +233 -0
  34. data/lib/cassanity/connection.rb +88 -0
  35. data/lib/cassanity/error.rb +28 -0
  36. data/lib/cassanity/executors/cassandra_cql.rb +120 -0
  37. data/lib/cassanity/keyspace.rb +118 -0
  38. data/lib/cassanity/result_transformers/column_family_select.rb +15 -0
  39. data/lib/cassanity/result_transformers/mirror.rb +12 -0
  40. data/lib/cassanity/schema.rb +26 -0
  41. data/lib/cassanity/version.rb +3 -0
  42. data/lib/cassanity.rb +5 -0
  43. data/spec/helper.rb +27 -0
  44. data/spec/integration/cassanity/column_family_spec.rb +243 -0
  45. data/spec/integration/cassanity/connection_spec.rb +87 -0
  46. data/spec/integration/cassanity/keyspace_spec.rb +64 -0
  47. data/spec/support/cassanity_helpers.rb +35 -0
  48. data/spec/unit/cassanity/argument_generators/batch_spec.rb +36 -0
  49. data/spec/unit/cassanity/argument_generators/column_family_alter_spec.rb +85 -0
  50. data/spec/unit/cassanity/argument_generators/column_family_create_spec.rb +107 -0
  51. data/spec/unit/cassanity/argument_generators/column_family_delete_spec.rb +92 -0
  52. data/spec/unit/cassanity/argument_generators/column_family_drop_spec.rb +25 -0
  53. data/spec/unit/cassanity/argument_generators/column_family_insert_spec.rb +70 -0
  54. data/spec/unit/cassanity/argument_generators/column_family_select_spec.rb +113 -0
  55. data/spec/unit/cassanity/argument_generators/column_family_truncate_spec.rb +25 -0
  56. data/spec/unit/cassanity/argument_generators/column_family_update_spec.rb +109 -0
  57. data/spec/unit/cassanity/argument_generators/index_create_spec.rb +39 -0
  58. data/spec/unit/cassanity/argument_generators/index_drop_spec.rb +14 -0
  59. data/spec/unit/cassanity/argument_generators/keyspace_create_spec.rb +53 -0
  60. data/spec/unit/cassanity/argument_generators/keyspace_drop_spec.rb +14 -0
  61. data/spec/unit/cassanity/argument_generators/keyspace_use_spec.rb +14 -0
  62. data/spec/unit/cassanity/argument_generators/keyspaces_spec.rb +12 -0
  63. data/spec/unit/cassanity/argument_generators/set_clause_spec.rb +85 -0
  64. data/spec/unit/cassanity/argument_generators/using_clause_spec.rb +44 -0
  65. data/spec/unit/cassanity/argument_generators/where_clause_spec.rb +57 -0
  66. data/spec/unit/cassanity/argument_generators/with_clause_spec.rb +63 -0
  67. data/spec/unit/cassanity/column_family_spec.rb +250 -0
  68. data/spec/unit/cassanity/connection_spec.rb +75 -0
  69. data/spec/unit/cassanity/error_spec.rb +35 -0
  70. data/spec/unit/cassanity/executors/cassandra_cql_spec.rb +178 -0
  71. data/spec/unit/cassanity/keyspace_spec.rb +137 -0
  72. data/spec/unit/cassanity/result_transformers/column_family_select_spec.rb +0 -0
  73. data/spec/unit/cassanity/result_transformers/mirror_spec.rb +12 -0
  74. data/spec/unit/cassanity/schema_spec.rb +23 -0
  75. data/spec/unit/cassanity_spec.rb +5 -0
  76. metadata +172 -0
@@ -0,0 +1,250 @@
1
+ require 'helper'
2
+ require 'cassanity/column_family'
3
+
4
+ describe Cassanity::ColumnFamily do
5
+ let(:column_family_name) { 'analytics' }
6
+ let(:keyspace_name) { 'foo' }
7
+
8
+ let(:keyspace) {
9
+ double('Keyspace', {
10
+ executor: executor,
11
+ name: keyspace_name,
12
+ })
13
+ }
14
+
15
+ let(:executor) {
16
+ lambda { |args| ['GOTTA KEEP EM EXECUTED', args] }
17
+ }
18
+
19
+ let(:schema) { double('Schema') }
20
+
21
+ let(:required_arguments) {
22
+ {
23
+ name: column_family_name,
24
+ keyspace: keyspace,
25
+ }
26
+ }
27
+
28
+ subject { described_class.new(required_arguments) }
29
+
30
+ it { should respond_to(:name) }
31
+ it { should respond_to(:keyspace) }
32
+
33
+ describe "#initialize" do
34
+ it "sets name" do
35
+ subject.name.should eq(column_family_name)
36
+ end
37
+
38
+ it "sets keyspace" do
39
+ subject.keyspace.should eq(keyspace)
40
+ end
41
+
42
+ it "defaults executor to keyspace's executor" do
43
+ subject.executor.should eq(keyspace.executor)
44
+ end
45
+
46
+ it "sets schema if provided" do
47
+ instance = described_class.new(required_arguments.merge({
48
+ schema: schema,
49
+ }))
50
+ instance.schema.should eq(schema)
51
+ end
52
+
53
+ it "allows overriding executor" do
54
+ other_executor = lambda { |args| }
55
+ column_family = described_class.new(required_arguments.merge({
56
+ executor: other_executor,
57
+ }))
58
+ column_family.executor.should eq(other_executor)
59
+ end
60
+
61
+ [:name, :keyspace].each do |key|
62
+ it "raises error without :#{key} key" do
63
+ args = required_arguments.reject { |k, v| k == key }
64
+ expect { described_class.new(args) }.to raise_error(KeyError)
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "#schema" do
70
+ it "returns schema if set" do
71
+ described_class.new(required_arguments.merge({
72
+ schema: schema,
73
+ })).schema.should eq(schema)
74
+ end
75
+
76
+ it "raises error if not set" do
77
+ expect {
78
+ subject.schema
79
+ }.to raise_error(Cassanity::Error, "No schema found to create #{column_family_name} column family. Please set :schema during initialization or include it as a key in #create call.")
80
+ end
81
+ end
82
+
83
+ describe "#create" do
84
+ context "with schema set during initialization" do
85
+ subject {
86
+ described_class.new(required_arguments.merge({
87
+ schema: schema,
88
+ }))
89
+ }
90
+
91
+ it "sends command and arguments, including schema, to executor" do
92
+ args = {something: 'else'}
93
+ executor.should_receive(:call).with({
94
+ command: :column_family_create,
95
+ arguments: args.merge({
96
+ name: column_family_name,
97
+ keyspace_name: keyspace_name,
98
+ schema: schema,
99
+ }),
100
+ })
101
+ subject.create(args)
102
+ end
103
+
104
+ it "uses passed in :schema if present" do
105
+ schema_argument = double('Schema')
106
+ args = {schema: schema_argument}
107
+ executor.should_receive(:call).with({
108
+ command: :column_family_create,
109
+ arguments: args.merge({
110
+ name: column_family_name,
111
+ keyspace_name: keyspace_name,
112
+ schema: schema_argument,
113
+ }),
114
+ })
115
+ subject.create(args)
116
+ end
117
+ end
118
+
119
+ context "with no schema" do
120
+ it "raises error" do
121
+ expect {
122
+ subject.create
123
+ }.to raise_error(Cassanity::Error, "No schema found to create #{column_family_name} column family. Please set :schema during initialization or include it as a key in #create call.")
124
+ end
125
+
126
+ it "sends passed in schema if present" do
127
+ args = {schema: schema}
128
+ command_arguments = args.merge({
129
+ name: column_family_name,
130
+ keyspace_name: keyspace_name,
131
+ schema: schema,
132
+ })
133
+ executor.should_receive(:call).with({
134
+ command: :column_family_create,
135
+ arguments: command_arguments,
136
+ })
137
+ subject.create(args)
138
+ end
139
+ end
140
+ end
141
+
142
+ describe "#truncate" do
143
+ it "sends command and arguments, including :name, to executor" do
144
+ args = {something: 'else'}
145
+ executor.should_receive(:call).with({
146
+ command: :column_family_truncate,
147
+ arguments: args.merge({
148
+ name: column_family_name,
149
+ keyspace_name: keyspace_name,
150
+ }),
151
+ })
152
+ subject.truncate(args)
153
+ end
154
+ end
155
+
156
+ describe "#drop" do
157
+ it "sends command and arguments, including :name, to executor" do
158
+ args = {something: 'else'}
159
+ executor.should_receive(:call).with({
160
+ command: :column_family_drop,
161
+ arguments: args.merge({
162
+ name: column_family_name,
163
+ keyspace_name: keyspace_name,
164
+ }),
165
+ })
166
+ subject.drop(args)
167
+ end
168
+ end
169
+
170
+ describe "#alter" do
171
+ it "sends command and arguments, including :name and :keyspace_name, to executor" do
172
+ args = {drop: :name, something: 'else'}
173
+ executor.should_receive(:call).with({
174
+ command: :column_family_alter,
175
+ arguments: args.merge({
176
+ name: column_family_name,
177
+ keyspace_name: keyspace_name,
178
+ }),
179
+ })
180
+ subject.alter(args)
181
+ end
182
+ end
183
+
184
+ describe "#create_index" do
185
+ it "sends command and arguments, including :name, to executor" do
186
+ args = {something: 'else'}
187
+ executor.should_receive(:call).with({
188
+ command: :index_create,
189
+ arguments: args.merge({
190
+ column_family_name: column_family_name,
191
+ keyspace_name: keyspace_name,
192
+ }),
193
+ })
194
+ subject.create_index(args)
195
+ end
196
+ end
197
+
198
+ describe "#drop_index" do
199
+ it "sends command and arguments, including :name, to executor" do
200
+ args = {something: 'else', name: 'users_state_idx'}
201
+ executor.should_receive(:call).with({
202
+ command: :index_drop,
203
+ arguments: args,
204
+ })
205
+ subject.drop_index(args)
206
+ end
207
+ end
208
+
209
+ describe "#insert" do
210
+ it "sends command and arguments, including :name, to executor" do
211
+ args = {data: {id: '1', name: 'GitHub'}}
212
+ executor.should_receive(:call).with({
213
+ command: :column_family_insert,
214
+ arguments: args.merge({
215
+ name: column_family_name,
216
+ keyspace_name: keyspace_name,
217
+ }),
218
+ })
219
+ subject.insert(args)
220
+ end
221
+ end
222
+
223
+ describe "#update" do
224
+ it "sends command and arguments, including :name, to executor" do
225
+ args = {set: {name: 'GitHub'}, where: {id: '1'}}
226
+ executor.should_receive(:call).with({
227
+ command: :column_family_update,
228
+ arguments: args.merge({
229
+ name: column_family_name,
230
+ keyspace_name: keyspace_name,
231
+ }),
232
+ })
233
+ subject.update(args)
234
+ end
235
+ end
236
+
237
+ describe "#delete" do
238
+ it "sends command and arguments, including :name, to executor" do
239
+ args = {where: {id: '1'}}
240
+ executor.should_receive(:call).with({
241
+ command: :column_family_delete,
242
+ arguments: args.merge({
243
+ name: column_family_name,
244
+ keyspace_name: keyspace_name,
245
+ }),
246
+ })
247
+ subject.delete(args)
248
+ end
249
+ end
250
+ end
@@ -0,0 +1,75 @@
1
+ require 'helper'
2
+ require 'cassanity/connection'
3
+
4
+ describe Cassanity::Connection do
5
+ let(:keyspace_name) { 'analytics' }
6
+ let(:executor) {
7
+ double('Executor', {
8
+ call: nil,
9
+ })
10
+ }
11
+
12
+ let(:required_arguments) {
13
+ {
14
+ executor: executor,
15
+ }
16
+ }
17
+
18
+ subject { described_class.new(required_arguments) }
19
+
20
+ it { should respond_to(:executor) }
21
+
22
+ [:executor].each do |key|
23
+ it "raises error if initialized without :#{key} key" do
24
+ args = required_arguments.reject { |k, v| k == key }
25
+ expect { described_class.new(args) }.to raise_error(KeyError)
26
+ end
27
+ end
28
+
29
+ describe "#batch" do
30
+ it "sends command and arguments, including :name, to executor" do
31
+ args = {modifications: [[:insert, data: {id: '1', name: 'GitHub'}]]}
32
+ executor.should_receive(:call).with({
33
+ command: :batch,
34
+ arguments: args,
35
+ })
36
+ subject.batch(args)
37
+ end
38
+ end
39
+
40
+ describe "#keyspace" do
41
+ before do
42
+ @return_value = subject.keyspace(keyspace_name)
43
+ end
44
+
45
+ it "returns instance of keyspace" do
46
+ @return_value.should be_instance_of(Cassanity::Keyspace)
47
+ end
48
+
49
+ context "with args" do
50
+ before do
51
+ @return_value = subject.keyspace(keyspace_name, {
52
+ strategy_class: 'NetworkTopologyStrategy',
53
+ })
54
+ end
55
+
56
+ it "passes args to initialization" do
57
+ @return_value.strategy_class.should eq('NetworkTopologyStrategy')
58
+ end
59
+
60
+ it "returns instance of keyspace" do
61
+ @return_value.should be_instance_of(Cassanity::Keyspace)
62
+ end
63
+ end
64
+ end
65
+
66
+ describe "#[]" do
67
+ before do
68
+ @return_value = subject[keyspace_name]
69
+ end
70
+
71
+ it "returns instance of keyspace" do
72
+ @return_value.should be_instance_of(Cassanity::Keyspace)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,35 @@
1
+ require 'helper'
2
+ require 'cassanity/error'
3
+
4
+ describe Cassanity::Error do
5
+ HorribleBadThing = Class.new(Exception)
6
+
7
+ it "can wrap original error" do
8
+ original = HorribleBadThing.new
9
+ error = described_class.new(original: original)
10
+ error.original.should eq(original)
11
+ end
12
+
13
+ it "defaults original to last raised exception" do
14
+ begin
15
+ begin
16
+ raise HorribleBadThing, 'Yep, really bad'
17
+ rescue Exception => e
18
+ raise described_class
19
+ end
20
+ rescue described_class => e
21
+ e.original.should be_instance_of(HorribleBadThing)
22
+ e.message.should eq("Original Exception: HorribleBadThing: Yep, really bad")
23
+ end
24
+ end
25
+
26
+ it "does not require original error" do
27
+ error = described_class.new(:message => 'Is this thing on?')
28
+ error.message.should eq('Is this thing on?')
29
+ end
30
+
31
+ it "does not require any arguments" do
32
+ error = described_class.new
33
+ error.message.should eq("Something truly horrible went wrong")
34
+ end
35
+ end
@@ -0,0 +1,178 @@
1
+ require 'helper'
2
+ require 'cassanity/executors/cassandra_cql'
3
+
4
+ describe Cassanity::Executors::CassandraCql do
5
+ let(:client) { double('Client', :execute => nil) }
6
+
7
+ let(:required_arguments) {
8
+ {
9
+ client: client,
10
+ }
11
+ }
12
+
13
+ let(:argument_generators) {
14
+ {
15
+ :foo => lambda { |args| ['mapped', args] },
16
+ }
17
+ }
18
+
19
+ let(:result_transformers) {
20
+ {
21
+ :foo => lambda { |args| ['transformed', args] }
22
+ }
23
+ }
24
+
25
+ subject { described_class.new(required_arguments) }
26
+
27
+ describe "#initialize" do
28
+ [:client].each do |key|
29
+ it "raises error without :#{key} key" do
30
+ args = required_arguments.reject { |k, v| k == key }
31
+ expect { described_class.new(args) }.to raise_error(KeyError)
32
+ end
33
+ end
34
+
35
+ it "sets client" do
36
+ subject.client.should eq(client)
37
+ end
38
+
39
+ it "defaults :argument_generators" do
40
+ subject.argument_generators.should eq(described_class::ArgumentGenerators)
41
+ end
42
+
43
+ it "defaults :result_transformers" do
44
+ subject.result_transformers.should eq(described_class::ResultTransformers)
45
+ end
46
+
47
+ it "allows overriding :argument_generators" do
48
+ instance = described_class.new(required_arguments.merge({
49
+ argument_generators: argument_generators
50
+ }))
51
+
52
+ instance.argument_generators.should eq(argument_generators)
53
+ end
54
+
55
+ it "allows overriding :result_transformers" do
56
+ instance = described_class.new(required_arguments.merge({
57
+ result_transformers: result_transformers
58
+ }))
59
+
60
+ instance.result_transformers.should eq(result_transformers)
61
+ end
62
+ end
63
+
64
+ KnownCommands = [
65
+ :keyspaces,
66
+ :keyspace_create,
67
+ :keyspace_drop,
68
+ :keyspace_use,
69
+ :column_family_create,
70
+ :column_family_drop,
71
+ :column_family_truncate,
72
+ :column_family_select,
73
+ :column_family_insert,
74
+ :column_family_update,
75
+ :column_family_delete,
76
+ :column_family_alter,
77
+ :index_create,
78
+ :index_drop,
79
+ :batch,
80
+ ]
81
+
82
+ KnownCommands.each do |key|
83
+ it "responds to #{key} command by default" do
84
+ subject.argument_generators.should have_key(key)
85
+ end
86
+ end
87
+
88
+ describe "#call" do
89
+ subject {
90
+ described_class.new(required_arguments.merge({
91
+ argument_generators: argument_generators,
92
+ }))
93
+ }
94
+
95
+ context "for known command" do
96
+ it "generates arguments based on command to argument map and passes generated arguments client execute method" do
97
+ args = {
98
+ command: :foo,
99
+ arguments: {
100
+ something: 'else',
101
+ },
102
+ }
103
+
104
+ client.should_receive(:execute).with('mapped', args[:arguments])
105
+ subject.call(args)
106
+ end
107
+
108
+ context "with result transformer" do
109
+ subject {
110
+ described_class.new(required_arguments.merge({
111
+ argument_generators: argument_generators,
112
+ result_transformers: result_transformers,
113
+ }))
114
+ }
115
+
116
+ it "returns result transformed" do
117
+ result = double('Result')
118
+ client.stub(:execute => result)
119
+ tranformer = result_transformers[:foo]
120
+
121
+ args = {
122
+ command: :foo,
123
+ arguments: {
124
+ something: 'else',
125
+ },
126
+ }
127
+
128
+ subject.call(args).should eq(['transformed', result])
129
+ end
130
+ end
131
+
132
+ context "without result transformer" do
133
+ subject {
134
+ described_class.new(required_arguments.merge({
135
+ argument_generators: argument_generators,
136
+ result_transformers: {},
137
+ }))
138
+ }
139
+
140
+ it "returns result transformed" do
141
+ result = double('Result')
142
+ client.stub(:execute => result)
143
+ tranformer = result_transformers[:foo]
144
+
145
+ args = {
146
+ command: :foo,
147
+ arguments: {
148
+ something: 'else',
149
+ },
150
+ }
151
+
152
+ subject.call(args).should eq(result)
153
+ end
154
+ end
155
+ end
156
+
157
+ context "for unknown command" do
158
+ it "generates arguments based on command to argument map and passes generated arguments client execute method" do
159
+ expect {
160
+ subject.call({
161
+ command: :surprise,
162
+ })
163
+ }.to raise_error(Cassanity::UnknownCommand, 'Original Exception: KeyError: key not found: :surprise')
164
+ end
165
+ end
166
+
167
+ context "when client raises exception" do
168
+ it "raises Cassanity::Error" do
169
+ client.should_receive(:execute).and_raise(Exception.new)
170
+ expect {
171
+ subject.call({
172
+ command: :foo,
173
+ })
174
+ }.to raise_error(Cassanity::Error, /Exception: Exception/)
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,137 @@
1
+ require 'helper'
2
+ require 'cassanity/keyspace'
3
+
4
+ describe Cassanity::Keyspace do
5
+ let(:keyspace_name) { 'analytics' }
6
+
7
+ let(:executor) {
8
+ lambda { |args| ['GOTTA KEEP EM EXECUTED', args] }
9
+ }
10
+
11
+ let(:required_arguments) {
12
+ {
13
+ name: keyspace_name,
14
+ executor: executor,
15
+ }
16
+ }
17
+
18
+ subject { described_class.new(required_arguments) }
19
+
20
+ it { should respond_to(:name) }
21
+ it { should respond_to(:executor) }
22
+
23
+ describe "#initialize" do
24
+ it "sets name" do
25
+ subject.name.should eq(keyspace_name)
26
+ end
27
+
28
+ it "sets executor" do
29
+ subject.executor.should eq(executor)
30
+ end
31
+
32
+ [:name, :executor].each do |key|
33
+ it "raises error without :#{key} key" do
34
+ args = required_arguments.reject { |k, v| k == key }
35
+ expect { described_class.new(args) }.to raise_error(KeyError)
36
+ end
37
+ end
38
+
39
+ it "sets strategy_class if provided" do
40
+ instance = described_class.new(required_arguments.merge({
41
+ strategy_class: 'NetworkTopologyStrategy',
42
+ }))
43
+
44
+ instance.strategy_class.should eq('NetworkTopologyStrategy')
45
+ end
46
+
47
+ it "sets strategy_options if provided" do
48
+ instance = described_class.new(required_arguments.merge({
49
+ strategy_options: {
50
+ dc1: 3,
51
+ dc2: 5,
52
+ },
53
+ }))
54
+
55
+ instance.strategy_options.should eq({
56
+ dc1: 3,
57
+ dc2: 5,
58
+ })
59
+ end
60
+ end
61
+
62
+ describe "#column_family" do
63
+ let(:column_family_name) { 'apps' }
64
+
65
+ before do
66
+ @return_value = subject.column_family(column_family_name)
67
+ end
68
+
69
+ it "returns instance of column family" do
70
+ @return_value.should be_instance_of(Cassanity::ColumnFamily)
71
+ end
72
+
73
+ context "with args" do
74
+ let(:schema) { double('Schema') }
75
+
76
+ before do
77
+ @return_value = subject.column_family(column_family_name, {
78
+ schema: schema,
79
+ })
80
+ end
81
+
82
+ it "passes args to initialization" do
83
+ @return_value.schema.should eq(schema)
84
+ end
85
+
86
+ it "returns instance of column family" do
87
+ @return_value.should be_instance_of(Cassanity::ColumnFamily)
88
+ end
89
+ end
90
+ end
91
+
92
+ describe "#table" do
93
+ let(:column_family_name) { 'apps' }
94
+
95
+ before do
96
+ @return_value = subject.table(column_family_name)
97
+ end
98
+
99
+ it "returns instance of column family" do
100
+ @return_value.should be_instance_of(Cassanity::ColumnFamily)
101
+ end
102
+ end
103
+
104
+ describe "#[]" do
105
+ let(:column_family_name) { 'apps' }
106
+
107
+ before do
108
+ @return_value = subject[column_family_name]
109
+ end
110
+
111
+ it "returns instance of column family" do
112
+ @return_value.should be_instance_of(Cassanity::ColumnFamily)
113
+ end
114
+ end
115
+
116
+ describe "#use" do
117
+ it "sends command and arguments, including :name, to executor" do
118
+ args = {something: 'else'}
119
+ executor.should_receive(:call).with({
120
+ command: :keyspace_use,
121
+ arguments: args.merge(name: keyspace_name),
122
+ })
123
+ subject.use(args)
124
+ end
125
+ end
126
+
127
+ describe "#drop" do
128
+ it "sends command and arguments, including :name, to executor" do
129
+ args = {something: 'else'}
130
+ executor.should_receive(:call).with({
131
+ command: :keyspace_drop,
132
+ arguments: args.merge(name: keyspace_name),
133
+ })
134
+ subject.drop(args)
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,12 @@
1
+ require 'helper'
2
+ require 'cassanity/result_transformers/mirror'
3
+
4
+ describe Cassanity::ResultTransformers::Mirror do
5
+ describe "#call" do
6
+ it "returns whatever is passed it" do
7
+ [1, '2', ['something'], {something: 'else'}].each do |result|
8
+ subject.call(result).should be(result)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+ require 'cassanity/schema'
3
+
4
+ describe Cassanity::Schema do
5
+ let(:required_arguments) {
6
+ {
7
+ primary_key: :id,
8
+ columns: {
9
+ id: :text,
10
+ name: :text,
11
+ }
12
+ }
13
+ }
14
+
15
+ describe "#initialize" do
16
+ [:primary_key, :columns].each do |key|
17
+ it "raises error without :#{key} key" do
18
+ args = required_arguments.reject { |k, v| k == key }
19
+ expect { described_class.new(args) }.to raise_error(KeyError)
20
+ end
21
+ end
22
+ end
23
+ end