superstore 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -13
  3. data/CHANGELOG.md +16 -0
  4. data/Gemfile +0 -5
  5. data/README.md +15 -33
  6. data/lib/superstore/adapters/jsonb_adapter.rb +245 -0
  7. data/lib/superstore/associations/association.rb +38 -0
  8. data/lib/superstore/associations/belongs_to.rb +35 -0
  9. data/lib/superstore/associations/builder/association.rb +38 -0
  10. data/lib/superstore/associations/builder/belongs_to.rb +7 -0
  11. data/lib/superstore/associations/builder/has_many.rb +7 -0
  12. data/lib/superstore/associations/builder/has_one.rb +7 -0
  13. data/lib/superstore/associations/has_many.rb +26 -0
  14. data/lib/superstore/associations/has_one.rb +24 -0
  15. data/lib/superstore/associations/reflection.rb +65 -0
  16. data/lib/superstore/associations.rb +72 -0
  17. data/lib/superstore/attribute_methods/definition.rb +5 -10
  18. data/lib/superstore/attribute_methods/dirty.rb +12 -2
  19. data/lib/superstore/attribute_methods/typecasting.rb +6 -12
  20. data/lib/superstore/base.rb +3 -4
  21. data/lib/superstore/connection.rb +3 -5
  22. data/lib/superstore/core.rb +0 -5
  23. data/lib/superstore/model.rb +32 -33
  24. data/lib/superstore/persistence.rb +4 -10
  25. data/lib/superstore/railtie.rb +2 -20
  26. data/lib/superstore/scope/batches.rb +17 -22
  27. data/lib/superstore/scope/finder_methods.rb +33 -35
  28. data/lib/superstore/scope/query_methods.rb +38 -44
  29. data/lib/superstore/scope.rb +24 -0
  30. data/lib/superstore/type.rb +3 -3
  31. data/lib/superstore/types/array_type.rb +2 -9
  32. data/lib/superstore/types/base_type.rb +4 -7
  33. data/lib/superstore/types/boolean_type.rb +2 -1
  34. data/lib/superstore/types/float_type.rb +6 -5
  35. data/lib/superstore/types/integer_type.rb +3 -3
  36. data/lib/superstore/types/json_type.rb +0 -21
  37. data/lib/superstore.rb +16 -5
  38. data/superstore.gemspec +2 -1
  39. data/test/support/jsonb.rb +8 -0
  40. data/test/support/{issue.rb → models.rb} +9 -0
  41. data/test/support/pg.rb +11 -15
  42. data/test/test_helper.rb +7 -6
  43. data/test/unit/{belongs_to_test.rb → associations/belongs_to_test.rb} +1 -10
  44. data/test/unit/associations/has_many_test.rb +13 -0
  45. data/test/unit/associations/has_one_test.rb +14 -0
  46. data/test/unit/{belongs_to → associations}/reflection_test.rb +2 -2
  47. data/test/unit/attribute_methods/definition_test.rb +6 -3
  48. data/test/unit/attribute_methods/dirty_test.rb +17 -14
  49. data/test/unit/attribute_methods/typecasting_test.rb +0 -14
  50. data/test/unit/base_test.rb +3 -3
  51. data/test/unit/connection_test.rb +0 -4
  52. data/test/unit/persistence_test.rb +4 -4
  53. data/test/unit/schema_test.rb +9 -17
  54. data/test/unit/scope/query_methods_test.rb +10 -1
  55. data/test/unit/types/array_type_test.rb +12 -10
  56. data/test/unit/types/base_type_test.rb +2 -10
  57. data/test/unit/types/boolean_type_test.rb +15 -13
  58. data/test/unit/types/date_type_test.rb +3 -3
  59. data/test/unit/types/float_type_test.rb +14 -7
  60. data/test/unit/types/integer_type_test.rb +11 -9
  61. data/test/unit/types/json_type_test.rb +0 -23
  62. data/test/unit/types/string_type_test.rb +6 -6
  63. data/test/unit/types/time_type_test.rb +7 -7
  64. metadata +35 -26
  65. data/CHANGELOG +0 -0
  66. data/lib/superstore/adapters/cassandra_adapter.rb +0 -203
  67. data/lib/superstore/adapters/hstore_adapter.rb +0 -170
  68. data/lib/superstore/belongs_to/association.rb +0 -65
  69. data/lib/superstore/belongs_to/builder.rb +0 -40
  70. data/lib/superstore/belongs_to/reflection.rb +0 -38
  71. data/lib/superstore/belongs_to.rb +0 -63
  72. data/lib/superstore/cassandra_schema/statements.rb +0 -52
  73. data/lib/superstore/cassandra_schema/tasks.rb +0 -47
  74. data/lib/superstore/cassandra_schema.rb +0 -9
  75. data/lib/superstore/log_subscriber.rb +0 -44
  76. data/lib/superstore/railties/controller_runtime.rb +0 -45
  77. data/lib/superstore/tasks/ks.rake +0 -59
  78. data/test/support/cassandra.rb +0 -46
  79. data/test/support/hstore.rb +0 -24
  80. data/test/support/user.rb +0 -2
  81. data/test/unit/cassandra_schema/statements_test.rb +0 -47
  82. data/test/unit/cassandra_schema/tasks_test.rb +0 -31
  83. data/test/unit/log_subscriber_test.rb +0 -26
  84. data/test/unit/railties/controller_runtime_test.rb +0 -48
@@ -1,24 +0,0 @@
1
- Bundler.require :hstore
2
- Superstore::Base.config = {'adapter' => 'hstore'}
3
-
4
- class HstoreInitializer
5
- def self.initialize!
6
- Superstore::Base.adapter.create_table('issues')
7
- end
8
-
9
- def self.table_names
10
- %w(issues)
11
- end
12
- end
13
-
14
- HstoreInitializer.initialize!
15
-
16
- module ActiveSupport
17
- class TestCase
18
- teardown do
19
- HstoreInitializer.table_names.each do |table_name|
20
- ActiveRecord::Base.connection.execute "TRUNCATE #{table_name}"
21
- end
22
- end
23
- end
24
- end
data/test/support/user.rb DELETED
@@ -1,2 +0,0 @@
1
- class User < ActiveRecord::Base
2
- end
@@ -1,47 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Superstore::CassandraSchema::StatementsTest < Superstore::TestCase
4
- if Superstore::Base.adapter.is_a?(Superstore::Adapters::CassandraAdapter)
5
- test "create_keyspace" do
6
- Superstore::CassandraSchema.create_keyspace 'Blah'
7
-
8
- existing_keyspace = false
9
- begin
10
- Superstore::CassandraSchema.create_keyspace 'Blah'
11
- rescue Exception => e
12
- existing_keyspace = true
13
- ensure
14
- Superstore::CassandraSchema.drop_keyspace 'Blah'
15
- end
16
-
17
- assert existing_keyspace
18
- end
19
-
20
- test "add_index" do
21
- begin
22
- Superstore::CassandraSchema.create_table 'TestIndexed'
23
- Superstore::CassandraSchema.alter_column_family 'TestIndexed', "ADD id_value varchar"
24
- Superstore::CassandraSchema.add_index 'TestIndexed', 'id_value'
25
- ensure
26
- Superstore::CassandraSchema.drop_table 'TestIndexed'
27
- end
28
- end
29
-
30
- test "drop_index" do
31
- begin
32
- Superstore::CassandraSchema.create_table 'TestDropIndexes'
33
-
34
- Superstore::CassandraSchema.alter_column_family 'TestDropIndexes', "ADD id_value1 varchar"
35
- Superstore::CassandraSchema.alter_column_family 'TestDropIndexes', "ADD id_value2 varchar"
36
-
37
- Superstore::CassandraSchema.add_index 'TestDropIndexes', 'id_value1'
38
- Superstore::CassandraSchema.add_index 'TestDropIndexes', 'id_value2', 'special_name'
39
-
40
- Superstore::CassandraSchema.drop_index 'TestDropIndexes_id_value1_idx'
41
- Superstore::CassandraSchema.drop_index 'special_name'
42
- ensure
43
- Superstore::CassandraSchema.drop_table 'TestDropIndexes'
44
- end
45
- end
46
- end
47
- end
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Superstore::CassandraSchema::TasksTest < Superstore::TestCase
4
- if Superstore::Base.adapter.is_a?(Superstore::Adapters::CassandraAdapter)
5
- test "table_names" do
6
- assert_equal ['Issues'], Superstore::CassandraSchema.table_names
7
- end
8
-
9
- test "dump" do
10
- io = StringIO.new
11
-
12
- Superstore::CassandraSchema.dump(io)
13
- io.rewind
14
-
15
- assert_match /Issues/, io.read
16
- end
17
-
18
- test "load" do
19
- Superstore::CassandraSchema.expects(:keyspace_execute).with("DO STUFF;")
20
- Superstore::CassandraSchema.expects(:keyspace_execute).with("AND MORE;")
21
-
22
- Superstore::CassandraSchema.load StringIO.new(
23
- "DO\n" +
24
- " STUFF;\n" +
25
- "\n" +
26
- "AND\n" +
27
- " MORE;\n"
28
- )
29
- end
30
- end
31
- end
@@ -1,26 +0,0 @@
1
- require "test_helper"
2
- require "active_support/log_subscriber/test_helper"
3
- require "superstore/log_subscriber"
4
-
5
- class Superstore::LogSubscriberTest < Superstore::TestCase
6
- include ActiveSupport::LogSubscriber::TestHelper
7
-
8
- def setup
9
- super
10
-
11
- Superstore::LogSubscriber.attach_to :cassandra_object
12
- end
13
-
14
- def test_cql_notification
15
- Issue.adapter.execute "SELECT * FROM Issues"
16
-
17
- wait
18
-
19
- assert_equal 1, @logger.logged(:debug).size
20
- assert_match "SELECT * FROM Issues", @logger.logged(:debug)[0]
21
- end
22
-
23
- def test_initializes_runtime
24
- Thread.new { assert_equal 0, Superstore::LogSubscriber.runtime }.join
25
- end
26
- end
@@ -1,48 +0,0 @@
1
- require 'test_helper'
2
- require "superstore/railties/controller_runtime"
3
-
4
- class Superstore::Railties::ControllerRuntimeTest < MiniTest::Test
5
- class TestRuntime
6
- def self.log_process_action(payload)
7
- ['sweet']
8
- end
9
-
10
- def cleanup_view_runtime
11
- 12
12
- end
13
-
14
- def append_info_to_payload(payload)
15
- payload[:foo] = 42
16
- end
17
- end
18
-
19
- class CassandraRuntime < TestRuntime
20
- include Superstore::Railties::ControllerRuntime
21
- end
22
-
23
- def test_cleanup_view_runtime
24
- runtime = CassandraRuntime.new
25
- Superstore::LogSubscriber.runtime = 10
26
-
27
- runtime.cleanup_view_runtime
28
-
29
- assert_equal 0, Superstore::LogSubscriber.runtime
30
- end
31
-
32
- def test_append_info_to_payload
33
- runtime = CassandraRuntime.new
34
- payload = {}
35
- runtime.append_info_to_payload(payload)
36
-
37
- assert_equal 42, payload[:foo]
38
- assert payload.key?(:cassandra_object_runtime)
39
- end
40
-
41
- def test_log_process_action
42
- payload = {cassandra_object_runtime: 12.3}
43
- messages = CassandraRuntime.log_process_action(payload)
44
-
45
- assert_equal 2, messages.size
46
- assert_equal "Superstore: 12.3ms", messages.last
47
- end
48
- end