rom-cassandra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +9 -0
  4. data/.metrics +9 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +2 -0
  7. data/.travis.yml +26 -0
  8. data/.yardopts +3 -0
  9. data/CHANGELOG.md +3 -0
  10. data/Gemfile +7 -0
  11. data/Guardfile +14 -0
  12. data/LICENSE +21 -0
  13. data/README.md +83 -0
  14. data/Rakefile +34 -0
  15. data/config/metrics/STYLEGUIDE +230 -0
  16. data/config/metrics/cane.yml +5 -0
  17. data/config/metrics/churn.yml +6 -0
  18. data/config/metrics/flay.yml +2 -0
  19. data/config/metrics/metric_fu.yml +14 -0
  20. data/config/metrics/reek.yml +1 -0
  21. data/config/metrics/roodi.yml +24 -0
  22. data/config/metrics/rubocop.yml +84 -0
  23. data/config/metrics/saikuro.yml +3 -0
  24. data/config/metrics/simplecov.yml +6 -0
  25. data/config/metrics/yardstick.yml +37 -0
  26. data/lib/rom-cassandra.rb +3 -0
  27. data/lib/rom/cassandra.rb +33 -0
  28. data/lib/rom/cassandra/commands.rb +53 -0
  29. data/lib/rom/cassandra/commands/batch.rb +54 -0
  30. data/lib/rom/cassandra/commands/create.rb +38 -0
  31. data/lib/rom/cassandra/commands/delete.rb +38 -0
  32. data/lib/rom/cassandra/commands/update.rb +38 -0
  33. data/lib/rom/cassandra/dataset.rb +102 -0
  34. data/lib/rom/cassandra/gateway.rb +115 -0
  35. data/lib/rom/cassandra/migrations.rb +30 -0
  36. data/lib/rom/cassandra/migrations/generator.rb +68 -0
  37. data/lib/rom/cassandra/migrations/generator/migration.erb +32 -0
  38. data/lib/rom/cassandra/migrations/logger.rb +28 -0
  39. data/lib/rom/cassandra/migrations/migration.rb +107 -0
  40. data/lib/rom/cassandra/migrations/migrator.rb +103 -0
  41. data/lib/rom/cassandra/migrations/runner.rb +119 -0
  42. data/lib/rom/cassandra/migrations/runner_down.rb +49 -0
  43. data/lib/rom/cassandra/migrations/runner_up.rb +50 -0
  44. data/lib/rom/cassandra/query.rb +43 -0
  45. data/lib/rom/cassandra/relation.rb +88 -0
  46. data/lib/rom/cassandra/session.rb +50 -0
  47. data/lib/rom/cassandra/tasks.rb +6 -0
  48. data/lib/rom/cassandra/version.rb +15 -0
  49. data/lib/tasks/db.rake +16 -0
  50. data/rom-cassandra.gemspec +33 -0
  51. data/spec/config/reset_cluster.rb +28 -0
  52. data/spec/config/rom.rb +3 -0
  53. data/spec/config/test_module.rb +7 -0
  54. data/spec/integration/batch_spec.rb +36 -0
  55. data/spec/integration/create_spec.rb +33 -0
  56. data/spec/integration/delete_spec.rb +33 -0
  57. data/spec/integration/migrate/20150825142003_create_users.rb +24 -0
  58. data/spec/integration/migrate/20150825142024_create_logs.rb +17 -0
  59. data/spec/integration/migrate_spec.rb +47 -0
  60. data/spec/integration/relation_spec.rb +27 -0
  61. data/spec/integration/update_spec.rb +33 -0
  62. data/spec/shared/fake_migrate_folder.rb +21 -0
  63. data/spec/shared/users.rb +20 -0
  64. data/spec/spec_helper.rb +17 -0
  65. data/spec/unit/commands/batch_spec.rb +86 -0
  66. data/spec/unit/commands/create_spec.rb +77 -0
  67. data/spec/unit/commands/delete_spec.rb +77 -0
  68. data/spec/unit/commands/update_spec.rb +77 -0
  69. data/spec/unit/dataset_spec.rb +130 -0
  70. data/spec/unit/gateway_spec.rb +140 -0
  71. data/spec/unit/migrations/generator_spec.rb +31 -0
  72. data/spec/unit/migrations/logger_spec.rb +21 -0
  73. data/spec/unit/migrations/migration_spec.rb +59 -0
  74. data/spec/unit/migrations/migrator_spec.rb +120 -0
  75. data/spec/unit/migrations/runner_down_spec.rb +65 -0
  76. data/spec/unit/migrations/runner_spec.rb +142 -0
  77. data/spec/unit/migrations/runner_up_spec.rb +67 -0
  78. data/spec/unit/query_spec.rb +21 -0
  79. data/spec/unit/relation_spec.rb +142 -0
  80. data/spec/unit/session_spec.rb +55 -0
  81. data/spec/unit/tasks/create_migration_spec.rb +41 -0
  82. metadata +242 -0
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ shared_examples :users do
4
+
5
+ let(:setup) { ROM.setup(:cassandra, hosts: ["127.0.0.1"], port: 9042) }
6
+ let(:gateway) { setup[:default] }
7
+ let(:rom) { setup.finalize }
8
+ let(:select) { rom.relation(:users) }
9
+
10
+ before do
11
+ setup.relation(:users) do
12
+ dataset "auth.users"
13
+
14
+ def by_id(id)
15
+ where(id: id)
16
+ end
17
+ end
18
+ end
19
+
20
+ end # shared examples
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ begin
4
+ require "hexx-suit"
5
+ Hexx::Suit.load_metrics_for(self)
6
+ rescue LoadError
7
+ require "hexx-rspec"
8
+ Hexx::RSpec.load_metrics_for(self)
9
+ end
10
+
11
+ # Loads the code under test
12
+ require "rom-cassandra"
13
+
14
+ # Configures RSpec
15
+ require "config/reset_cluster"
16
+ require "config/rom"
17
+ require "config/test_module"
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+
3
+ describe ROM::Cassandra::Commands::Batch do
4
+
5
+ let(:command) { described_class.new relation }
6
+ let(:relation) { double :relation, batch_query: batch }
7
+ let(:batch) { double :batch, foo: :updated_relation }
8
+
9
+ describe ".new" do
10
+ subject { command }
11
+
12
+ it { is_expected.to be_kind_of ROM::Command }
13
+ end # describe .new
14
+
15
+ describe "#relation" do
16
+ subject { command.relation }
17
+
18
+ it "restricts dataset by UPDATE statements" do
19
+ expect(subject).to eql batch
20
+ end
21
+ end # describe #relation
22
+
23
+ describe "#method_missing" do
24
+ subject { command.foo :bar }
25
+
26
+ it "returns a command" do
27
+ expect(subject).to be_kind_of described_class
28
+ end
29
+
30
+ it "updates the relation" do
31
+ expect(batch).to receive(:foo).with(:bar)
32
+ expect(subject.relation).to eql :updated_relation
33
+ end
34
+ end # describe #method_missing
35
+
36
+ describe "#respond_to_missing?" do
37
+ subject { command.respond_to? name }
38
+
39
+ context "method of #relation" do
40
+ let(:name) { :foo }
41
+
42
+ it { is_expected.to eql true }
43
+ end
44
+
45
+ context "method not defined for #relation" do
46
+ let(:name) { :bar }
47
+
48
+ it { is_expected.to eql false }
49
+ end
50
+ end # describe #respond_to_missing?
51
+
52
+ describe "#execute" do
53
+ let(:updated) { double :updated, to_a: result }
54
+ let(:result) { double :result }
55
+
56
+ context "without a block" do
57
+ subject { command.execute(1) }
58
+
59
+ it "applies #to_a" do
60
+ allow(command).to receive(:to_a) { result }
61
+
62
+ expect(subject).to eql(result)
63
+ end
64
+ end
65
+
66
+ context "with a block" do
67
+ subject { command.execute { foo } }
68
+
69
+ it "updates and finalizes the command" do
70
+ allow(command).to receive(:foo) { updated }
71
+
72
+ expect(subject).to eql(result)
73
+ end
74
+ end
75
+ end # describe #execute
76
+
77
+ describe "#keyspace" do
78
+ subject { command.keyspace(:foo) }
79
+
80
+ it "returns query" do
81
+ expect(subject).to be_kind_of ROM::Cassandra::Query
82
+ expect(subject.use.to_s).to eql "USE foo;"
83
+ end
84
+ end # describe #keyspace
85
+
86
+ end # describe ROM::Cassandra::Commands::Batch
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ describe ROM::Cassandra::Commands::Create do
4
+
5
+ let(:command) { described_class.new relation }
6
+ let(:relation) { double :relation, insert_query: insert }
7
+ let(:insert) { double :insert, foo: :updated_relation }
8
+
9
+ describe ".new" do
10
+ subject { command }
11
+
12
+ it { is_expected.to be_kind_of ROM::Commands::Create }
13
+ end # describe .new
14
+
15
+ describe "#relation" do
16
+ subject { command.relation }
17
+
18
+ it "restricts dataset by INSERT statements" do
19
+ expect(subject).to eql insert
20
+ end
21
+ end # describe #relation
22
+
23
+ describe "#method_missing" do
24
+ subject { command.foo :bar }
25
+
26
+ it "returns a command" do
27
+ expect(subject).to be_kind_of described_class
28
+ end
29
+
30
+ it "updates the relation" do
31
+ expect(insert).to receive(:foo).with(:bar)
32
+ expect(subject.relation).to eql :updated_relation
33
+ end
34
+ end # describe #method_missing
35
+
36
+ describe "#respond_to_missing?" do
37
+ subject { command.respond_to? name }
38
+
39
+ context "method of #relation" do
40
+ let(:name) { :foo }
41
+
42
+ it { is_expected.to eql true }
43
+ end
44
+
45
+ context "method not defined for #relation" do
46
+ let(:name) { :bar }
47
+
48
+ it { is_expected.to eql false }
49
+ end
50
+ end # describe #respond_to_missing?
51
+
52
+ describe "#execute" do
53
+ let(:updated) { double :updated, to_a: result }
54
+ let(:result) { double :result }
55
+
56
+ context "without a block" do
57
+ subject { command.execute(1) }
58
+
59
+ it "applies #to_a" do
60
+ allow(command).to receive(:to_a) { result }
61
+
62
+ expect(subject).to eql(result)
63
+ end
64
+ end
65
+
66
+ context "with a block" do
67
+ subject { command.execute { foo } }
68
+
69
+ it "updates and finalizes the command" do
70
+ allow(command).to receive(:foo) { updated }
71
+
72
+ expect(subject).to eql(result)
73
+ end
74
+ end
75
+ end # describe #execute
76
+
77
+ end # describe ROM::Cassandra::Commands::Create
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ describe ROM::Cassandra::Commands::Delete do
4
+
5
+ let(:command) { described_class.new relation }
6
+ let(:relation) { double :relation, delete_query: delete }
7
+ let(:delete) { double :delete, foo: :updated_relation }
8
+
9
+ describe ".new" do
10
+ subject { command }
11
+
12
+ it { is_expected.to be_kind_of ROM::Commands::Delete }
13
+ end # describe .new
14
+
15
+ describe "#relation" do
16
+ subject { command.relation }
17
+
18
+ it "restricts dataset by DELETE statements" do
19
+ expect(subject).to eql delete
20
+ end
21
+ end # describe #relation
22
+
23
+ describe "#method_missing" do
24
+ subject { command.foo :bar }
25
+
26
+ it "returns a command" do
27
+ expect(subject).to be_kind_of described_class
28
+ end
29
+
30
+ it "updates the relation" do
31
+ expect(delete).to receive(:foo).with(:bar)
32
+ expect(subject.relation).to eql :updated_relation
33
+ end
34
+ end # describe #method_missing
35
+
36
+ describe "#respond_to_missing?" do
37
+ subject { command.respond_to? name }
38
+
39
+ context "method of #relation" do
40
+ let(:name) { :foo }
41
+
42
+ it { is_expected.to eql true }
43
+ end
44
+
45
+ context "method not defined for #relation" do
46
+ let(:name) { :bar }
47
+
48
+ it { is_expected.to eql false }
49
+ end
50
+ end # describe #respond_to_missing?
51
+
52
+ describe "#execute" do
53
+ let(:updated) { double :updated, to_a: result }
54
+ let(:result) { double :result }
55
+
56
+ context "without a block" do
57
+ subject { command.execute(1) }
58
+
59
+ it "applies #to_a" do
60
+ allow(command).to receive(:to_a) { result }
61
+
62
+ expect(subject).to eql(result)
63
+ end
64
+ end
65
+
66
+ context "with a block" do
67
+ subject { command.execute { foo } }
68
+
69
+ it "updates and finalizes the command" do
70
+ allow(command).to receive(:foo) { updated }
71
+
72
+ expect(subject).to eql(result)
73
+ end
74
+ end
75
+ end # describe #execute
76
+
77
+ end # describe ROM::Cassandra::Commands::Delete
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ describe ROM::Cassandra::Commands::Update do
4
+
5
+ let(:command) { described_class.new relation }
6
+ let(:relation) { double :relation, update_query: update }
7
+ let(:update) { double :update, foo: :updated_relation }
8
+
9
+ describe ".new" do
10
+ subject { command }
11
+
12
+ it { is_expected.to be_kind_of ROM::Commands::Update }
13
+ end # describe .new
14
+
15
+ describe "#relation" do
16
+ subject { command.relation }
17
+
18
+ it "restricts dataset by UPDATE statements" do
19
+ expect(subject).to eql update
20
+ end
21
+ end # describe #relation
22
+
23
+ describe "#method_missing" do
24
+ subject { command.foo :bar }
25
+
26
+ it "returns a command" do
27
+ expect(subject).to be_kind_of described_class
28
+ end
29
+
30
+ it "updates the relation" do
31
+ expect(update).to receive(:foo).with(:bar)
32
+ expect(subject.relation).to eql :updated_relation
33
+ end
34
+ end # describe #method_missing
35
+
36
+ describe "#respond_to_missing?" do
37
+ subject { command.respond_to? name }
38
+
39
+ context "method of #relation" do
40
+ let(:name) { :foo }
41
+
42
+ it { is_expected.to eql true }
43
+ end
44
+
45
+ context "method not defined for #relation" do
46
+ let(:name) { :bar }
47
+
48
+ it { is_expected.to eql false }
49
+ end
50
+ end # describe #respond_to_missing?
51
+
52
+ describe "#execute" do
53
+ let(:updated) { double :updated, to_a: result }
54
+ let(:result) { double :result }
55
+
56
+ context "without a block" do
57
+ subject { command.execute(1) }
58
+
59
+ it "applies #to_a" do
60
+ allow(command).to receive(:to_a) { result }
61
+
62
+ expect(subject).to eql(result)
63
+ end
64
+ end
65
+
66
+ context "with a block" do
67
+ subject { command.execute { foo } }
68
+
69
+ it "updates and finalizes the command" do
70
+ allow(command).to receive(:foo) { updated }
71
+
72
+ expect(subject).to eql(result)
73
+ end
74
+ end
75
+ end # describe #execute
76
+
77
+ end # describe ROM::Cassandra::Commands::Update
@@ -0,0 +1,130 @@
1
+ # encoding: utf-8
2
+
3
+ describe ROM::Cassandra::Dataset do
4
+
5
+ let(:dataset) { described_class.new(session, keyspace, table, query) }
6
+
7
+ let(:session) { double :session }
8
+ let(:keyspace) { "foo" }
9
+ let(:table) { "bar" }
10
+ let(:query) { double :query }
11
+
12
+ describe "#session" do
13
+ subject { dataset.session }
14
+
15
+ it { is_expected.to eql session }
16
+ end # describe #session
17
+
18
+ describe "#keyspace" do
19
+ subject { dataset.keyspace }
20
+
21
+ it { is_expected.to eql :foo }
22
+ end # describe #keyspace
23
+
24
+ describe "#table" do
25
+ subject { dataset.table }
26
+
27
+ it { is_expected.to eql :bar }
28
+ end # describe #table
29
+
30
+ describe "#query" do
31
+ subject { dataset.query }
32
+
33
+ context "when it is set" do
34
+ it { is_expected.to eql query }
35
+ end
36
+
37
+ context "when it isn't set" do
38
+ let(:dataset) { described_class.new(session, keyspace, table) }
39
+
40
+ it "returns the context of table" do
41
+ expect(subject.select.to_s).to eql "SELECT * FROM foo.bar;"
42
+ end
43
+ end
44
+ end # describe #query
45
+
46
+ describe "#get" do
47
+ subject { dataset.get(:bar, :baz) }
48
+
49
+ let(:select) { double :select }
50
+ before { allow(query).to receive(:select).and_return(select) }
51
+
52
+ it "forwards calls to the #query" do
53
+ expect(query).to receive(:select).with(:bar, :baz)
54
+ subject
55
+ end
56
+
57
+ it "returns the dataset with updated query" do
58
+ expect(subject)
59
+ .to eql described_class.new(session, keyspace, table, select)
60
+ end
61
+ end # describe #get
62
+
63
+ describe "#batch" do
64
+ subject { dataset.batch }
65
+
66
+ let(:batch) { double :batch }
67
+ let(:builder) { double :builder, batch: batch }
68
+ before { allow(ROM::Cassandra::Query).to receive(:new) { builder } }
69
+
70
+ it "returns the dataset with updated query" do
71
+ expect(subject)
72
+ .to eql described_class.new(session, nil, nil, batch)
73
+ end
74
+ end # describe #batch
75
+
76
+ describe "#each" do
77
+ let(:result) { [:foo, :bar] }
78
+ before { allow(session).to receive(:call) { result } }
79
+
80
+ context "with a block" do
81
+ subject { dataset.map { |item| item } }
82
+
83
+ it "sends #query to #session and iterates through the result" do
84
+ expect(session).to receive(:call).with(query)
85
+ expect(subject).to eql result
86
+ end
87
+ end
88
+
89
+ context "without a block" do
90
+ subject { dataset.each }
91
+
92
+ it "sends #query to #session and returns #result's enumerator" do
93
+ expect(subject).to be_kind_of Enumerator
94
+ expect(subject.to_a).to eql result
95
+ end
96
+ end
97
+ end # describe #each
98
+
99
+ describe "#respond_to?" do
100
+ subject { dataset.respond_to? :foo }
101
+
102
+ context "method defined for #query" do
103
+ before { allow(query).to receive(:foo) }
104
+
105
+ it { is_expected.to eql true }
106
+ end
107
+
108
+ context "method missing for #query" do
109
+ it { is_expected.to eql false }
110
+ end
111
+ end # describe #respond_to?
112
+
113
+ describe "#method_missing" do
114
+ subject { dataset.foo(:bar) }
115
+
116
+ let(:updated_query) { double :updated_query }
117
+ before { allow(query).to receive(:foo) { updated_query } }
118
+
119
+ it "forwards calls to the #query" do
120
+ expect(query).to receive(:foo).with(:bar)
121
+ subject
122
+ end
123
+
124
+ it "returns the dataset with updated query" do
125
+ expect(subject)
126
+ .to eql described_class.new(session, keyspace, table, updated_query)
127
+ end
128
+ end # describe #method_missing
129
+
130
+ end # describe ROM::Cassandra::Dataset