superstore 2.4.4 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +4 -6
  3. data/Gemfile +2 -3
  4. data/{Gemfile-rails4.2 → Gemfile.rails6} +2 -3
  5. data/README.md +4 -34
  6. data/lib/superstore.rb +17 -18
  7. data/lib/superstore/adapters/abstract_adapter.rb +1 -27
  8. data/lib/superstore/adapters/jsonb_adapter.rb +4 -132
  9. data/lib/superstore/associations.rb +6 -1
  10. data/lib/superstore/associations/association.rb +6 -0
  11. data/lib/superstore/associations/association_scope.rb +20 -0
  12. data/lib/superstore/associations/belongs_to.rb +3 -1
  13. data/lib/superstore/associations/has_many.rb +15 -2
  14. data/lib/superstore/associations/reflection.rb +8 -2
  15. data/lib/superstore/attribute_assignment.rb +7 -0
  16. data/lib/superstore/attribute_methods.rb +1 -109
  17. data/lib/superstore/attribute_methods/primary_key.rb +20 -11
  18. data/lib/superstore/attributes.rb +13 -0
  19. data/lib/superstore/base.rb +8 -33
  20. data/lib/superstore/core.rb +7 -65
  21. data/lib/superstore/model_schema.rb +35 -0
  22. data/lib/superstore/persistence.rb +31 -115
  23. data/lib/superstore/railtie.rb +3 -11
  24. data/lib/superstore/relation/scrolling.rb +48 -0
  25. data/lib/superstore/timestamp.rb +13 -0
  26. data/lib/superstore/types.rb +11 -9
  27. data/lib/superstore/types/array_type.rb +3 -7
  28. data/lib/superstore/types/boolean_type.rb +7 -12
  29. data/lib/superstore/types/date_range_type.rb +7 -0
  30. data/lib/superstore/types/date_type.rb +7 -10
  31. data/lib/superstore/types/float_type.rb +3 -11
  32. data/lib/superstore/types/geo_point_type.rb +30 -0
  33. data/lib/superstore/types/integer_range_type.rb +19 -0
  34. data/lib/superstore/types/integer_type.rb +8 -14
  35. data/lib/superstore/types/json_type.rb +1 -1
  36. data/lib/superstore/types/range_type.rb +51 -0
  37. data/lib/superstore/types/string_type.rb +4 -4
  38. data/lib/superstore/types/time_type.rb +10 -8
  39. data/superstore.gemspec +4 -3
  40. data/test/support/jsonb.rb +3 -1
  41. data/test/support/models.rb +8 -5
  42. data/test/test_helper.rb +6 -2
  43. data/test/unit/adapters/adapter_test.rb +1 -3
  44. data/test/unit/associations/belongs_to_test.rb +1 -1
  45. data/test/unit/associations/has_many_test.rb +10 -2
  46. data/test/unit/attribute_methods/dirty_test.rb +8 -19
  47. data/test/unit/attribute_methods/primary_key_test.rb +1 -1
  48. data/test/unit/attribute_methods_test.rb +10 -22
  49. data/test/unit/{attribute_methods/typecasting_test.rb → attributes_test.rb} +13 -39
  50. data/test/unit/base_test.rb +4 -0
  51. data/test/unit/caching_test.rb +1 -1
  52. data/test/unit/callbacks_test.rb +4 -4
  53. data/test/unit/core_test.rb +9 -19
  54. data/test/unit/persistence_test.rb +17 -54
  55. data/test/unit/{scope/batches_test.rb → relation/scrolling_test.rb} +9 -5
  56. data/test/unit/serialization_test.rb +10 -2
  57. data/test/unit/{timestamps_test.rb → timestamp_test.rb} +5 -5
  58. data/test/unit/types/array_type_test.rb +3 -18
  59. data/test/unit/types/boolean_type_test.rb +7 -21
  60. data/test/unit/types/date_range_type_test.rb +28 -0
  61. data/test/unit/types/date_type_test.rb +15 -6
  62. data/test/unit/types/float_type_test.rb +4 -19
  63. data/test/unit/types/geo_point_type_test.rb +24 -0
  64. data/test/unit/types/integer_range_type_test.rb +28 -0
  65. data/test/unit/types/integer_type_test.rb +7 -16
  66. data/test/unit/types/string_type_test.rb +9 -13
  67. data/test/unit/types/time_type_test.rb +17 -11
  68. data/test/unit/validations_test.rb +2 -2
  69. metadata +39 -39
  70. data/lib/superstore/attribute_methods/definition.rb +0 -17
  71. data/lib/superstore/attribute_methods/dirty.rb +0 -52
  72. data/lib/superstore/attribute_methods/typecasting.rb +0 -53
  73. data/lib/superstore/caching.rb +0 -13
  74. data/lib/superstore/callbacks.rb +0 -29
  75. data/lib/superstore/connection.rb +0 -24
  76. data/lib/superstore/errors.rb +0 -10
  77. data/lib/superstore/inspect.rb +0 -25
  78. data/lib/superstore/model.rb +0 -38
  79. data/lib/superstore/schema.rb +0 -20
  80. data/lib/superstore/scope.rb +0 -73
  81. data/lib/superstore/scope/batches.rb +0 -27
  82. data/lib/superstore/scope/finder_methods.rb +0 -51
  83. data/lib/superstore/scope/query_methods.rb +0 -52
  84. data/lib/superstore/scoping.rb +0 -30
  85. data/lib/superstore/timestamps.rb +0 -19
  86. data/lib/superstore/type.rb +0 -16
  87. data/lib/superstore/types/base_type.rb +0 -23
  88. data/lib/superstore/validations.rb +0 -44
  89. data/test/unit/attribute_methods/definition_test.rb +0 -16
  90. data/test/unit/inspect_test.rb +0 -26
  91. data/test/unit/schema_test.rb +0 -15
  92. data/test/unit/scope/finder_methods_test.rb +0 -62
  93. data/test/unit/scope/query_methods_test.rb +0 -37
  94. data/test/unit/scoping_test.rb +0 -7
  95. data/test/unit/types/base_type_test.rb +0 -11
@@ -1,23 +0,0 @@
1
- module Superstore
2
- module Types
3
- class BaseType
4
- attr_accessor :model, :options
5
- def initialize(model, options = {})
6
- @model = model
7
- @options = options
8
- end
9
-
10
- def encode(value)
11
- value
12
- end
13
-
14
- def decode(str)
15
- str
16
- end
17
-
18
- def typecast(value)
19
- value
20
- end
21
- end
22
- end
23
- end
@@ -1,44 +0,0 @@
1
- module Superstore
2
- class RecordInvalid < StandardError
3
- attr_reader :record
4
- def initialize(record)
5
- @record = record
6
- super("Invalid record: #{@record.errors.full_messages.to_sentence}")
7
- end
8
- end
9
-
10
- module Validations
11
- extend ActiveSupport::Concern
12
- include ActiveModel::Validations
13
-
14
- included do
15
- define_callbacks :validate, scope: :name
16
- end
17
-
18
- module ClassMethods
19
- def create!(attributes = {})
20
- new(attributes).tap do |object|
21
- object.save!
22
- end
23
- end
24
- end
25
-
26
- def save(options={})
27
- if perform_validations(options)
28
- super
29
- true
30
- else
31
- false
32
- end
33
- end
34
-
35
- def save!
36
- save || raise(RecordInvalid.new(self))
37
- end
38
-
39
- protected
40
- def perform_validations(options={})
41
- (options[:validate] != false) ? valid? : true
42
- end
43
- end
44
- end
@@ -1,16 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Superstore::AttributeMethods::DefinitionTest < Superstore::TestCase
4
- class TestType < Superstore::Types::BaseType
5
- def typecast(v)
6
- "#{v}-foo"
7
- end
8
- end
9
-
10
- test 'initialize' do
11
- definition = Superstore::AttributeMethods::Definition.new(Issue, :foo, TestType, {})
12
-
13
- assert_equal 'foo', definition.name
14
- assert_kind_of TestType, definition.type
15
- end
16
- end
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Superstore::InspectTest < Superstore::TestCase
4
- test 'attribute_for_inspect' do
5
- object = temp_object do
6
- string :long_string
7
- time :the_time
8
- integer :other
9
- end
10
-
11
- assert_equal "#{'x' * 51}...".inspect, object.new.attribute_for_inspect('x' * 100)
12
- assert_equal "2012-02-14 12:01:02".inspect, object.new.attribute_for_inspect(Time.new(2012, 02, 14, 12, 01, 02))
13
- assert_equal "\"foo\"", object.new.attribute_for_inspect('foo')
14
- end
15
-
16
- test 'inspect' do
17
- object = temp_object do
18
- string :description
19
- integer :price
20
- end.new(description: "yeah buddy", price: nil)
21
-
22
- assert_match(/id/, object.inspect)
23
- assert_match(/description/, object.inspect)
24
- assert_no_match(/price/, object.inspect)
25
- end
26
- end
@@ -1,15 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Superstore::SchemaTest < Superstore::TestCase
4
- # SELECT columnfamily_name FROM System.schema_columnfamilies WHERE keyspace_name='myKeyspaceName';
5
- # test "create_table" do
6
- # Superstore::Schema.create_table 'TestRecords'
7
- #
8
- # begin
9
- # Superstore::Schema.create_table 'TestRecords'
10
- # assert false, 'TestRecords should already exist'
11
- # rescue Exception => e
12
- # end
13
- # end
14
-
15
- end
@@ -1,62 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Superstore::FinderMethodsTest < Superstore::TestCase
4
- test 'find' do
5
- Issue.create.tap do |issue|
6
- assert_equal issue, Issue.find(issue.id)
7
- end
8
-
9
- begin
10
- Issue.find(nil)
11
- assert false
12
- rescue => e
13
- assert_equal "Couldn't find Issue with key nil", e.message
14
- end
15
-
16
- assert_raise Superstore::RecordNotFound do
17
- Issue.find('what')
18
- end
19
- end
20
-
21
- test 'find with ids' do
22
- first_issue = Issue.create
23
- second_issue = Issue.create
24
- Issue.create
25
-
26
- assert_equal [], Issue.find([])
27
- assert_equal [first_issue, second_issue], Issue.find([first_issue.id, second_issue.id])
28
- end
29
-
30
- test 'find with nil ids' do
31
- Issue.create
32
- assert_equal [], Issue.find([nil])
33
- end
34
-
35
- test 'find_by_id' do
36
- Issue.create.tap do |issue|
37
- assert_equal issue, Issue.find_by_id(issue.id)
38
- end
39
-
40
- assert_nil Issue.find_by_id('what')
41
- end
42
-
43
- test 'all' do
44
- first_issue = Issue.create
45
- second_issue = Issue.create
46
-
47
- assert_equal [first_issue, second_issue].to_set, Issue.all.to_set
48
- end
49
-
50
- test 'first' do
51
- first_issue = Issue.create
52
- second_issue = Issue.create
53
-
54
- assert [first_issue, second_issue].include?(Issue.first)
55
- end
56
-
57
- test 'to_ids' do
58
- first_issue = Issue.create title: 'Sup!'
59
-
60
- assert_equal [first_issue.id], Issue.to_ids
61
- end
62
- end
@@ -1,37 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Superstore::Scope::QueryMethodsTest < Superstore::TestCase
4
- test "select" do
5
- original_issue = Issue.create title: "foo", comments: [{"text" => "cool"}], description: 'bar'
6
- found_issue = Issue.select(:title, :comments).find(original_issue.id)
7
-
8
- assert_equal 'foo', found_issue.title
9
- assert_equal [{"text" => "cool"}], found_issue.comments
10
- assert_equal original_issue.id, found_issue.id
11
- assert_nil found_issue.description
12
- end
13
-
14
- test "where" do
15
- foo_issue = Issue.create title: 'foo'
16
- bar_issue = Issue.create title: 'bar'
17
- nil_issue = Issue.create title: nil
18
-
19
- assert_equal [foo_issue], Issue.where(title: 'foo').to_a
20
- assert_equal [foo_issue, bar_issue], Issue.where(title: ['foo', 'bar']).to_a
21
- assert_equal [nil_issue], Issue.where(title: nil).to_a
22
- end
23
-
24
- test "select with block" do
25
- foo_issue = Issue.create title: 'foo'
26
- Issue.create title: 'bar'
27
-
28
- assert_equal [foo_issue], Issue.select { |issue| issue.title == 'foo' }
29
- end
30
-
31
- test "chaining where with scope" do
32
- issue = Issue.create title: 'abc', description: 'def'
33
- query = Issue.select(:title).for_key(issue.id)
34
-
35
- assert_equal [:title], query.select_values
36
- end
37
- end
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Superstore::ScopingTest < Superstore::TestCase
4
- test "scope" do
5
- assert_kind_of Superstore::Scope, Issue.scope
6
- end
7
- end
@@ -1,11 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Superstore::Types::BaseTypeTest < Superstore::Types::TestCase
4
- test 'encode' do
5
- assert_equal 'x', type.encode('x')
6
- end
7
-
8
- test 'decode' do
9
- assert_equal 'abc', type.decode('abc')
10
- end
11
- end