cassandra_migrations 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTkyY2FiYmVjMzk2NGFlYzczZjJkYjE4MDE2MDc4NTM4ZmE5MzBlYg==
5
+ data.tar.gz: !binary |-
6
+ Y2UxMzZlYWI3YjcwYzJjYTkyYjQ1ZmJkODg5YzBhYTRlOWRkYzVmZg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YmU2YmZhMmVhYmM3ZjU3MzBmOWMxNjRhYmI0ZjBhNTU0NTUxNjJlZmExN2U5
10
+ MGM5ZTk5ZWU0ZGIwY2FiZTFiZGQ2NTZjYzNiMzlmNmY2YWIwZjc4OWM3OWNl
11
+ MWEyMWNlN2IxOWY0ZDJmZjkxYTk0ZGMxNDAxNjg3MTk3NTdlZDk=
12
+ data.tar.gz: !binary |-
13
+ OGI5YmNkZTE5ZjJjZjIxMzk2ZjJkZDBkMTY5ZDgzYzc1YWRlMGUzZGM5NzUw
14
+ ZTYyNmUzZDY2NWU5NGVmOTQwOGZkOTBmYmY0YjlmNjQyY2M1OGRmOWNhYmM5
15
+ YWFiMmU1MzhiOTFkYTkxMDNlOGVjZGVkNzQ1ZjcyNmMyYTEzZDU=
@@ -106,7 +106,7 @@ module CassandraMigrations
106
106
  "'#{value}'"
107
107
  elsif value.is_a?(Array)
108
108
  type = get_column_type(table, column)
109
- values = %[#{value.map {|v| "'#{v}'"} * ', '}]
109
+ values = %[#{value.map { |v| to_cql_value(nil, v, nil) } * ', '}]
110
110
 
111
111
  if type && type == :list
112
112
  %[#{operation}[#{values}]]
@@ -67,6 +67,12 @@ module CassandraMigrations
67
67
  define_primary_keys(column_name) if options[:primary_key]
68
68
  end
69
69
 
70
+ def double(column_name, options={})
71
+ options[:limit] = 8
72
+ @columns_name_type_hash[column_name.to_sym] = column_type_for(:float, options)
73
+ define_primary_keys(column_name) if options[:primary_key]
74
+ end
75
+
70
76
  def string(column_name, options={})
71
77
  @columns_name_type_hash[column_name.to_sym] = column_type_for(:string, options)
72
78
  define_primary_keys(column_name) if options[:primary_key]
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassandra_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Henrique Gubert
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-10 00:00:00.000000000 Z
11
+ date: 2014-01-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: cql-rb
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - '='
20
18
  - !ruby/object:Gem::Version
21
- version: 1.0.1
19
+ version: 1.1.2
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - '='
28
25
  - !ruby/object:Gem::Version
29
- version: 1.0.1
26
+ version: 1.1.2
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,23 +41,20 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rails
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - ! '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '3.2'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - ! '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '3.2'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: colorize
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: debugger
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ! '>='
100
88
  - !ruby/object:Gem::Version
@@ -102,71 +90,117 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: coveralls
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
106
149
  requirements:
107
150
  - - ! '>='
108
151
  - !ruby/object:Gem::Version
109
152
  version: '0'
110
153
  description: A gem to manage Cassandra database schema for Rails. This gem offers
111
- migrations and environment specific databases out-of-the-box for Rails users.
154
+ migrations and environment sific databases out-of-the-box for Rails users.
112
155
  email: guberthenrique@hotmail.com
113
156
  executables:
114
157
  - prepare_for_cassandra
115
158
  extensions: []
116
159
  extra_rdoc_files: []
117
160
  files:
118
- - lib/cassandra_migrations.rb
119
- - lib/cassandra_migrations/capistrano.rb
120
- - lib/cassandra_migrations/migration.rb
121
- - lib/cassandra_migrations/migrator.rb
122
- - lib/cassandra_migrations/cassandra.rb
123
- - lib/cassandra_migrations/railtie.rb
124
161
  - lib/cassandra_migrations/cassandra/keyspace_operations.rb
125
- - lib/cassandra_migrations/cassandra/query_result.rb
126
162
  - lib/cassandra_migrations/cassandra/queries.rb
127
- - lib/cassandra_migrations/config.rb
163
+ - lib/cassandra_migrations/cassandra/query_result.rb
128
164
  - lib/cassandra_migrations/migration/table_operations.rb
129
- - lib/cassandra_migrations/migration/column_operations.rb
130
165
  - lib/cassandra_migrations/migration/table_definition.rb
131
- - lib/cassandra_migrations/railtie/initializer.rb
166
+ - lib/cassandra_migrations/migration/column_operations.rb
167
+ - lib/cassandra_migrations/migration.rb
168
+ - lib/cassandra_migrations/errors.rb
169
+ - lib/cassandra_migrations/railtie.rb
170
+ - lib/cassandra_migrations/config.rb
171
+ - lib/cassandra_migrations/migrator.rb
172
+ - lib/cassandra_migrations/cassandra.rb
132
173
  - lib/cassandra_migrations/railtie/generators/cassandra_migration/cassandra_migration_generator.rb
133
174
  - lib/cassandra_migrations/railtie/generators/cassandra_migration/templates/empty_migration.rb.erb
134
175
  - lib/cassandra_migrations/railtie/generators/cassandra_migration/USAGE
135
176
  - lib/cassandra_migrations/railtie/tasks.rake
136
- - lib/cassandra_migrations/errors.rb
177
+ - lib/cassandra_migrations/railtie/initializer.rb
178
+ - lib/cassandra_migrations/capistrano.rb
179
+ - lib/cassandra_migrations.rb
137
180
  - template/cassandra.yml
138
- - spec/cassandra_migrations_spec.rb
139
- - spec/cassandra_migrations/config_spec.rb
140
- - spec/cassandra_migrations/cassandra/queries_spec.rb
141
- - spec/cassandra_migrations/cassandra_spec.rb
142
181
  - bin/prepare_for_cassandra
143
182
  homepage: https://github.com/hsgubert/cassandra_migrations
144
183
  licenses:
145
184
  - MIT
185
+ metadata: {}
146
186
  post_install_message:
147
187
  rdoc_options: []
148
188
  require_paths:
149
189
  - lib
150
190
  required_ruby_version: !ruby/object:Gem::Requirement
151
- none: false
152
191
  requirements:
153
192
  - - ! '>='
154
193
  - !ruby/object:Gem::Version
155
194
  version: '0'
156
195
  required_rubygems_version: !ruby/object:Gem::Requirement
157
- none: false
158
196
  requirements:
159
197
  - - ! '>='
160
198
  - !ruby/object:Gem::Version
161
199
  version: 1.8.0
162
200
  requirements: []
163
201
  rubyforge_project:
164
- rubygems_version: 1.8.25
202
+ rubygems_version: 2.0.7
165
203
  signing_key:
166
- specification_version: 3
204
+ specification_version: 4
167
205
  summary: Cassandra schema management for a multi-environment developer.
168
- test_files:
169
- - spec/cassandra_migrations_spec.rb
170
- - spec/cassandra_migrations/config_spec.rb
171
- - spec/cassandra_migrations/cassandra/queries_spec.rb
172
- - spec/cassandra_migrations/cassandra_spec.rb
206
+ test_files: []
@@ -1,252 +0,0 @@
1
- # encoding : utf-8
2
- require 'spec_helper'
3
-
4
- describe CassandraMigrations::Cassandra::Queries do
5
-
6
- class TestQueryExecutor
7
- extend CassandraMigrations::Cassandra::Queries
8
-
9
- def self.column_type=(column_type)
10
- @column_type = column_type
11
- end
12
-
13
- private
14
-
15
- def self.get_column_type(table, column)
16
- @column_type
17
- end
18
- end
19
-
20
- describe '.write!' do
21
- it 'should insert a record into the specified table' do
22
- TestQueryExecutor.should_receive(:execute).with(
23
- "INSERT INTO people (name, age, height_in_meters, birth_time) VALUES ('John', 24, 1.83, '1989-05-27 08:50:25+0000')"
24
- )
25
-
26
- TestQueryExecutor.write!('people',
27
- :name => 'John',
28
- :age => 24,
29
- :height_in_meters => 1.83,
30
- :birth_time => Time.new(1989, 05, 27, 8, 50, 25, 0)
31
- )
32
- end
33
-
34
- it 'should set record TTL' do
35
- TestQueryExecutor.should_receive(:execute).with(
36
- "INSERT INTO people (name) VALUES ('John') USING TTL 3600"
37
- )
38
-
39
- TestQueryExecutor.write!('people', {:name => 'John'}, :ttl => 3600)
40
- end
41
-
42
- context 'when dealing with collections' do
43
-
44
- it 'should handle setting a set collection column value' do
45
- TestQueryExecutor.column_type = :set
46
-
47
- TestQueryExecutor.should_receive(:execute).with(
48
- "INSERT INTO people (friends) VALUES ({'John', 'Ringo', 'Paul', 'George'})"
49
- )
50
-
51
- TestQueryExecutor.write!('people', {friends: ['John', 'Ringo', 'Paul', 'George']})
52
- end
53
-
54
- it 'should handle setting a list collection column value' do
55
- TestQueryExecutor.column_type = :list
56
-
57
- TestQueryExecutor.should_receive(:execute).with(
58
- "INSERT INTO people (friends) VALUES (['John', 'Ringo', 'Paul', 'George'])"
59
- )
60
-
61
- TestQueryExecutor.write!('people', {friends: ['John', 'Ringo', 'Paul', 'George']})
62
- end
63
-
64
- it 'should handle setting a map collection column value' do
65
- TestQueryExecutor.column_type = :map
66
-
67
- TestQueryExecutor.should_receive(:execute).with(
68
- "INSERT INTO people (friends) VALUES ({ 'talent': 'John', 'drums': 'Ringo', 'voice': 'Paul', 'rhythm': 'George' })"
69
- )
70
-
71
- TestQueryExecutor.write!('people', {friends: {talent: 'John', drums: 'Ringo', voice: 'Paul', rhythm: 'George'}})
72
- end
73
- end
74
- end
75
-
76
- describe '.update!' do
77
- it 'should update some record values' do
78
- TestQueryExecutor.should_receive(:execute).with(
79
- "UPDATE people SET height_in_meters = 1.93, birth_time = '1989-05-28 08:50:25+0000' WHERE name = 'John'"
80
- )
81
-
82
- TestQueryExecutor.update!('people', "name = 'John'",
83
- :height_in_meters => 1.93,
84
- :birth_time => Time.new(1989, 05, 28, 8, 50, 25, 0)
85
- )
86
- end
87
-
88
- it 'should set record TTL' do
89
- TestQueryExecutor.should_receive(:execute).with(
90
- "UPDATE people USING TTL 3600 SET name = 'Johnny' WHERE name = 'John'"
91
- )
92
-
93
- TestQueryExecutor.update!('people', "name = 'John'", {:name => 'Johnny'}, :ttl => 3600)
94
- end
95
-
96
- context 'when dealing with collections' do
97
-
98
- it 'should handle setting a set collection column' do
99
- TestQueryExecutor.column_type = :set
100
-
101
- TestQueryExecutor.should_receive(:execute).with(
102
- "UPDATE people SET friends = {'John', 'Ringo', 'Paul', 'George'} WHERE name = 'Stuart'"
103
- )
104
-
105
- TestQueryExecutor.update!('people', "name = 'Stuart'", {friends: ['John', 'Ringo', 'Paul', 'George']})
106
- end
107
-
108
- it 'should handle adding elements to a set collection column' do
109
- TestQueryExecutor.column_type = :set
110
-
111
- TestQueryExecutor.should_receive(:execute).with(
112
- "UPDATE people SET friends = friends + {'John', 'Ringo', 'Paul', 'George'} WHERE name = 'Stuart'"
113
- )
114
-
115
- TestQueryExecutor.update!('people', "name = 'Stuart'",
116
- {friends: ['John', 'Ringo', 'Paul', 'George']},
117
- {operations: {friends: :+}})
118
- end
119
-
120
- it 'should handle removing elements from a set collection column' do
121
- TestQueryExecutor.column_type = :set
122
-
123
- TestQueryExecutor.should_receive(:execute).with(
124
- "UPDATE people SET friends = friends - {'John', 'Ringo', 'Paul', 'George'} WHERE name = 'Stuart'"
125
- )
126
-
127
- TestQueryExecutor.update!('people', "name = 'Stuart'",
128
- {friends: ['John', 'Ringo', 'Paul', 'George']},
129
- {operations: {friends: :-}})
130
- end
131
-
132
- it 'should handle setting a list collection column' do
133
- TestQueryExecutor.column_type = :list
134
-
135
- TestQueryExecutor.should_receive(:execute).with(
136
- "UPDATE people SET friends = ['John', 'Ringo', 'Paul', 'George'] WHERE name = 'Stuart'"
137
- )
138
-
139
- TestQueryExecutor.update!('people', "name = 'Stuart'", {friends: ['John', 'Ringo', 'Paul', 'George']})
140
- end
141
-
142
- it 'should handle adding elements to a list collection column' do
143
- TestQueryExecutor.column_type = :list
144
-
145
- TestQueryExecutor.should_receive(:execute).with(
146
- "UPDATE people SET friends = friends + ['John', 'Ringo', 'Paul', 'George'] WHERE name = 'Stuart'"
147
- )
148
-
149
- TestQueryExecutor.update!('people', "name = 'Stuart'",
150
- {friends: ['John', 'Ringo', 'Paul', 'George']},
151
- {operations: {friends: :+}})
152
- end
153
-
154
- it 'should handle removing elements from a list collection column' do
155
- TestQueryExecutor.column_type = :list
156
-
157
- TestQueryExecutor.should_receive(:execute).with(
158
- "UPDATE people SET friends = friends - ['John', 'Ringo', 'Paul', 'George'] WHERE name = 'Stuart'"
159
- )
160
-
161
- TestQueryExecutor.update!('people', "name = 'Stuart'",
162
- {friends: ['John', 'Ringo', 'Paul', 'George']},
163
- {operations: {friends: :-}})
164
- end
165
-
166
- it 'should handle setting a map collection column' do
167
- TestQueryExecutor.column_type = :map
168
-
169
- TestQueryExecutor.should_receive(:execute).with(
170
- "UPDATE people SET friends = { 'talent': 'John', 'drums': 'Ringo', 'voice': 'Paul', 'rhythm': 'George' } WHERE name = 'Stuart'"
171
- )
172
-
173
- TestQueryExecutor.update!('people', "name = 'Stuart'", {friends: {talent: 'John', drums: 'Ringo', voice: 'Paul', rhythm: 'George'}})
174
- end
175
-
176
- it 'should handle adding elements to a map collection column' do
177
- TestQueryExecutor.column_type = :map
178
-
179
- TestQueryExecutor.should_receive(:execute).with(
180
- "UPDATE people SET friends = friends + { 'talent': 'John', 'drums': 'Ringo', 'voice': 'Paul', 'rhythm': 'George' } WHERE name = 'Stuart'"
181
- )
182
-
183
- TestQueryExecutor.update!('people', "name = 'Stuart'",
184
- {friends: {talent: 'John', drums: 'Ringo', voice: 'Paul', rhythm: 'George'}},
185
- {operations: {friends: :+}})
186
- end
187
-
188
- it 'should handle removing elements from a map collection column' do
189
- TestQueryExecutor.column_type = :map
190
-
191
- TestQueryExecutor.should_receive(:execute).with(
192
- "DELETE friends['drums'] FROM people WHERE name = 'Stuart'"
193
- )
194
-
195
- TestQueryExecutor.delete!('people', "name = 'Stuart'", :projection => "friends['drums']")
196
- end
197
- end
198
- end
199
-
200
- describe '.select' do
201
- it 'should make select query with WHERE, ORDER BY and LIMIT' do
202
- TestQueryExecutor.should_receive(:execute).with(
203
- "SELECT * FROM people WHERE name = 'John' ORDER BY birth_time LIMIT 200"
204
- )
205
-
206
- TestQueryExecutor.select('people',
207
- :selection => "name = 'John'",
208
- :order_by => 'birth_time',
209
- :limit => 200
210
- )
211
- end
212
-
213
- it 'should allow to specify projection (columns loaded)' do
214
- TestQueryExecutor.should_receive(:execute).with(
215
- "SELECT age, birth_time FROM people WHERE name = 'John'"
216
- )
217
-
218
- TestQueryExecutor.select('people',
219
- :selection => "name = 'John'",
220
- :projection => 'age, birth_time'
221
- )
222
- end
223
- end
224
-
225
- describe '.delete!' do
226
- it 'should delete rows based in a selection' do
227
- TestQueryExecutor.should_receive(:execute).with(
228
- "DELETE FROM people WHERE name IN ('John', 'Mike')"
229
- )
230
-
231
- TestQueryExecutor.delete!('people', "name IN ('John', 'Mike')")
232
- end
233
-
234
- it 'should delete column based in a selection and projection' do
235
- TestQueryExecutor.should_receive(:execute).with(
236
- "DELETE age FROM people WHERE name IN ('John', 'Mike')"
237
- )
238
-
239
- TestQueryExecutor.delete!('people', "name IN ('John', 'Mike')", :projection => :age)
240
- end
241
- end
242
-
243
- describe '.truncate!' do
244
- it 'should clear table' do
245
- TestQueryExecutor.should_receive(:execute).with(
246
- "TRUNCATE people"
247
- )
248
-
249
- TestQueryExecutor.truncate!('people')
250
- end
251
- end
252
- end
@@ -1,92 +0,0 @@
1
- # encoding : utf-8
2
- require 'spec_helper'
3
-
4
- describe CassandraMigrations::Cassandra do
5
-
6
- before do
7
- Rails.stub(:root).and_return Pathname.new("spec/fixtures")
8
- Rails.stub(:env).and_return ActiveSupport::StringInquirer.new("development")
9
- end
10
-
11
- after do
12
- CassandraMigrations::Cassandra.client = nil
13
- CassandraMigrations::Config.config = nil
14
- end
15
-
16
- describe '.execute' do
17
- it 'should connect to cassandra using host and port configured' do
18
- cql_client_mock = mock('cql_client')
19
- Cql::Client.should_receive(:connect).with(:host => '127.0.0.1', :port => 9042).and_return(cql_client_mock)
20
- cql_client_mock.should_receive(:execute).with('anything').and_return(nil)
21
-
22
- CassandraMigrations::Cassandra.execute('anything').should be_nil
23
- end
24
-
25
- it 'raise exception if there is something wrong with the connection' do
26
- Cql::Client.should_receive(:connect).and_raise(Cql::Io::ConnectionError)
27
-
28
- expect {
29
- CassandraMigrations::Cassandra.execute('anything')
30
- }.to raise_exception CassandraMigrations::Errors::ConnectionError
31
- end
32
-
33
- it 'should return a QueryResult if the query returns something' do
34
- CassandraMigrations::Cassandra.client = mock('cql_client')
35
-
36
- result_mock = mock('result_mock')
37
- CassandraMigrations::Cassandra.client.should_receive(:execute).with('anything').and_return(result_mock)
38
-
39
- result = CassandraMigrations::Cassandra.execute('anything')
40
- result.should_not be_nil
41
- result.should be_a(CassandraMigrations::Cassandra::QueryResult)
42
- end
43
- end
44
-
45
- describe '.use' do
46
- it 'should connect to cassandra using host and port configured' do
47
- cql_client_mock = mock('cql_client')
48
- Cql::Client.should_receive(:connect).with(:host => '127.0.0.1', :port => 9042).and_return(cql_client_mock)
49
- cql_client_mock.should_receive(:use).with('anything').and_return(nil)
50
-
51
- CassandraMigrations::Cassandra.use('anything').should be_nil
52
- end
53
-
54
- it "should raise exception if configured keyspace does not exist" do
55
- expect {
56
- CassandraMigrations::Cassandra.use('anything')
57
- }.to raise_exception CassandraMigrations::Errors::UnexistingKeyspaceError
58
- end
59
- end
60
-
61
- describe ".start!" do
62
- it "should use configured keyspace" do
63
- CassandraMigrations::Cassandra.should_receive(:use).with('cassandra_migrations_development')
64
- CassandraMigrations::Cassandra.start!
65
- end
66
-
67
- it "should log missing configuration file or similar error, but swallow exception" do
68
- Rails.stub(:root).and_return Pathname.new("spec/fake_fixture_path")
69
-
70
- Rails.logger = mock('logger')
71
- Rails.logger.should_receive(:warn).with('There is no config/cassandra.yml. Skipping connection to Cassandra...')
72
- CassandraMigrations::Cassandra.start!
73
- end
74
- end
75
-
76
- describe "query interface" do
77
- it "should respond to query helper methods" do
78
- CassandraMigrations::Cassandra.should respond_to :select
79
- CassandraMigrations::Cassandra.should respond_to :write!
80
- CassandraMigrations::Cassandra.should respond_to :update!
81
- CassandraMigrations::Cassandra.should respond_to :delete!
82
- CassandraMigrations::Cassandra.should respond_to :truncate!
83
- end
84
- end
85
-
86
- describe "keyspace interface" do
87
- it "should respond to keyspace helper methods" do
88
- CassandraMigrations::Cassandra.should respond_to :create_keyspace!
89
- CassandraMigrations::Cassandra.should respond_to :drop_keyspace!
90
- end
91
- end
92
- end
@@ -1,48 +0,0 @@
1
- # encoding : utf-8
2
- require 'spec_helper'
3
-
4
- describe CassandraMigrations::Config do
5
-
6
- before do
7
- CassandraMigrations::Config.config = nil
8
- end
9
-
10
- it 'should fetch values in config for the right environment' do
11
- Rails.stub(:root).and_return Pathname.new("spec/fixtures")
12
- Rails.stub(:env).and_return ActiveSupport::StringInquirer.new("development")
13
-
14
- CassandraMigrations::Config.keyspace.should == 'cassandra_migrations_development'
15
- CassandraMigrations::Config.replication.should == {'class' => "SimpleStrategy", 'replication_factor' => 1 }
16
- end
17
-
18
- it 'should raise exception if there are no configs for environment' do
19
- Rails.stub(:root).and_return Pathname.new("spec/fixtures")
20
- Rails.stub(:env).and_return ActiveSupport::StringInquirer.new("fake_environment")
21
-
22
- expect {
23
- CassandraMigrations::Config.keyspace
24
- }.to raise_exception CassandraMigrations::Errors::MissingConfigurationError
25
- end
26
-
27
- it 'should raise exception if there are no config file' do
28
- Rails.stub(:root).and_return Pathname.new("spec/fake_path")
29
- Rails.stub(:env).and_return ActiveSupport::StringInquirer.new("development")
30
-
31
- expect {
32
- CassandraMigrations::Config.keyspace
33
- }.to raise_exception CassandraMigrations::Errors::MissingConfigurationError
34
- end
35
-
36
- it 'should allow ERB in the config file' do
37
- Rails.stub(:root).and_return Pathname.new("spec/fixtures/with_erb")
38
- Rails.stub(:env).and_return ActiveSupport::StringInquirer.new("test")
39
-
40
- CassandraMigrations::Config.keyspace.should == 'cassandra_migrations_test'
41
-
42
- CassandraMigrations::Config.config = nil
43
- ENV.stub(:[]).with("CI").and_return("true")
44
-
45
- CassandraMigrations::Config.keyspace.should == 'cassandra_migrations_ci'
46
- end
47
- end
48
-
@@ -1,168 +0,0 @@
1
- # encoding : utf-8
2
- require 'spec_helper'
3
-
4
- module CassandraMigrations
5
-
6
- # Temporarily monkey path Migration to allow for testing generated CQL
7
- # and suppress announcements
8
- class Migration
9
- attr_reader :cql
10
-
11
- def execute(cql)
12
- @cql = cql
13
- end
14
-
15
- private
16
- def announce_migration(message); end
17
- def announce_operation(message); end
18
- def announce_suboperation(message); end
19
- end
20
- end
21
-
22
- describe CassandraMigrations do
23
-
24
- it "should define modules" do
25
- defined?(CassandraMigrations).should be_true
26
- defined?(CassandraMigrations::Railtie).should be_true
27
- defined?(CassandraMigrations::Cassandra).should be_true
28
- defined?(CassandraMigrations::Errors).should be_true
29
- defined?(CassandraMigrations::Migration).should be_true
30
- defined?(CassandraMigrations::Migrator).should be_true
31
- defined?(CassandraMigrations::Config).should be_true
32
- end
33
-
34
- context 'a migration' do
35
- before do
36
- require_relative 'fixtures/migrations/migrations'
37
- end
38
-
39
- context 'without a primary key' do
40
- before do
41
- @migration = WithoutAPrimaryKey.new
42
- end
43
-
44
- it 'should be invalid' do
45
- expect { @migration.up }.to raise_error(CassandraMigrations::Errors::MigrationDefinitionError, /No primary key defined./)
46
- end
47
- end
48
-
49
- context 'that is valid' do
50
- before do
51
- @migration = CreateKitchenSink.new
52
- end
53
-
54
- it 'should have a name' do
55
- expect(@migration.send(:name)).to eq('CreateKitchenSink')
56
- end
57
-
58
- it 'should produce a valid CQL create statement' do
59
- @migration.up
60
- expected_cql = "CREATE TABLE kitchen_sink (id uuid, a_string varchar, a_timestamp timestamp, a_float float, a_list_of_strings list<varchar>, PRIMARY KEY(id))"
61
- expect(@migration.cql).to eq(expected_cql)
62
- end
63
- end
64
-
65
- context 'with a list collection column declaration' do
66
- before do
67
- @migration = CollectionsListMigration.new
68
- end
69
-
70
- it 'should produce a valid CQL create statement' do
71
- @migration.up
72
- expected_cql = "CREATE TABLE collection_lists (id uuid, list_1 list<varchar>, PRIMARY KEY(id))"
73
- expect(@migration.cql).to eq(expected_cql)
74
- end
75
-
76
- context 'using invalid types' do
77
- before do
78
- @migration = BadCollectionsListMigration.new
79
- end
80
-
81
- it 'should be invalid' do
82
- expect { @migration.up }.to raise_error(CassandraMigrations::Errors::MigrationDefinitionError, /Type 'chupacabra' is not valid for cassandra migration./)
83
- end
84
- end
85
- end
86
-
87
- context 'with a set collection column declaration' do
88
- before do
89
- @migration = CollectionsSetMigration.new
90
- end
91
-
92
- it 'should produce a valid CQL create statement' do
93
- @migration.up
94
- expected_cql = "CREATE TABLE collection_lists (id uuid, set_2 set<float>, PRIMARY KEY(id))"
95
- expect(@migration.cql).to eq(expected_cql)
96
- end
97
-
98
- context 'using invalid types' do
99
- before do
100
- @migration = BadCollectionsSetMigration.new
101
- end
102
-
103
- it 'should be invalid' do
104
- expect { @migration.up }.to raise_error(CassandraMigrations::Errors::MigrationDefinitionError, /Type 'narwhal' is not valid for cassandra migration./)
105
- end
106
- end
107
- end
108
-
109
- context 'with a map collection column declaration' do
110
- before do
111
- @migration = CollectionsMapMigration.new
112
- end
113
-
114
- it 'should produce a valid CQL create statement' do
115
- @migration.up
116
- expected_cql = "CREATE TABLE collection_lists (id uuid, map_1 map<varchar,float>, PRIMARY KEY(id))"
117
- expect(@migration.cql).to eq(expected_cql)
118
- end
119
-
120
- context 'using invalid types' do
121
- before do
122
- @migration = BadCollectionsMapMigration.new
123
- end
124
-
125
- it 'should be invalid' do
126
- expect { @migration.up }.to raise_error(CassandraMigrations::Errors::MigrationDefinitionError, /Type 'unicorns' is not valid for cassandra migration./)
127
- end
128
- end
129
- end
130
-
131
- context 'with an secondary index definition' do
132
- before do
133
- @migration = MigrationWithSecondaryIndex.new
134
- end
135
-
136
- it 'should produce a valid CQL create statement' do
137
- @migration.up
138
- expected_cql = "CREATE INDEX ON with_indexes (a_string)"
139
- expect(@migration.cql).to eq(expected_cql)
140
- end
141
-
142
- it 'should produce a valid CQL drop statement' do
143
- @migration.down
144
- expected_cql = "DROP INDEX with_indexes_a_string_idx"
145
- expect(@migration.cql).to eq(expected_cql)
146
- end
147
- end
148
-
149
- context 'with a named secondary index definition' do
150
- before do
151
- @migration = MigrationWithANamedSecondaryIndex.new
152
- end
153
-
154
- it 'should produce a valid CQL create statement' do
155
- @migration.up
156
- expected_cql = "CREATE INDEX by_another_string ON with_indexes (another_string)"
157
- expect(@migration.cql).to eq(expected_cql)
158
- end
159
-
160
- it 'should produce a valid CQL drop statement' do
161
- @migration.down
162
- expected_cql = "DROP INDEX by_another_string"
163
- expect(@migration.cql).to eq(expected_cql)
164
- end
165
- end
166
-
167
- end
168
- end