superstore 2.4.4 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +4 -6
- data/Gemfile +2 -3
- data/{Gemfile-rails4.2 → Gemfile.rails6} +2 -3
- data/README.md +4 -34
- data/lib/superstore.rb +17 -18
- data/lib/superstore/adapters/abstract_adapter.rb +1 -27
- data/lib/superstore/adapters/jsonb_adapter.rb +4 -132
- data/lib/superstore/associations.rb +6 -1
- data/lib/superstore/associations/association.rb +6 -0
- data/lib/superstore/associations/association_scope.rb +20 -0
- data/lib/superstore/associations/belongs_to.rb +3 -1
- data/lib/superstore/associations/has_many.rb +15 -2
- data/lib/superstore/associations/reflection.rb +8 -2
- data/lib/superstore/attribute_assignment.rb +7 -0
- data/lib/superstore/attribute_methods.rb +1 -109
- data/lib/superstore/attribute_methods/primary_key.rb +20 -11
- data/lib/superstore/attributes.rb +13 -0
- data/lib/superstore/base.rb +8 -33
- data/lib/superstore/core.rb +7 -65
- data/lib/superstore/model_schema.rb +35 -0
- data/lib/superstore/persistence.rb +31 -115
- data/lib/superstore/railtie.rb +3 -11
- data/lib/superstore/relation/scrolling.rb +48 -0
- data/lib/superstore/timestamp.rb +13 -0
- data/lib/superstore/types.rb +11 -9
- data/lib/superstore/types/array_type.rb +3 -7
- data/lib/superstore/types/boolean_type.rb +7 -12
- data/lib/superstore/types/date_range_type.rb +7 -0
- data/lib/superstore/types/date_type.rb +7 -10
- data/lib/superstore/types/float_type.rb +3 -11
- data/lib/superstore/types/geo_point_type.rb +30 -0
- data/lib/superstore/types/integer_range_type.rb +19 -0
- data/lib/superstore/types/integer_type.rb +8 -14
- data/lib/superstore/types/json_type.rb +1 -1
- data/lib/superstore/types/range_type.rb +51 -0
- data/lib/superstore/types/string_type.rb +4 -4
- data/lib/superstore/types/time_type.rb +10 -8
- data/superstore.gemspec +4 -3
- data/test/support/jsonb.rb +3 -1
- data/test/support/models.rb +8 -5
- data/test/test_helper.rb +6 -2
- data/test/unit/adapters/adapter_test.rb +1 -3
- data/test/unit/associations/belongs_to_test.rb +1 -1
- data/test/unit/associations/has_many_test.rb +10 -2
- data/test/unit/attribute_methods/dirty_test.rb +8 -19
- data/test/unit/attribute_methods/primary_key_test.rb +1 -1
- data/test/unit/attribute_methods_test.rb +10 -22
- data/test/unit/{attribute_methods/typecasting_test.rb → attributes_test.rb} +13 -39
- data/test/unit/base_test.rb +4 -0
- data/test/unit/caching_test.rb +1 -1
- data/test/unit/callbacks_test.rb +4 -4
- data/test/unit/core_test.rb +9 -19
- data/test/unit/persistence_test.rb +17 -54
- data/test/unit/{scope/batches_test.rb → relation/scrolling_test.rb} +9 -5
- data/test/unit/serialization_test.rb +10 -2
- data/test/unit/{timestamps_test.rb → timestamp_test.rb} +5 -5
- data/test/unit/types/array_type_test.rb +3 -18
- data/test/unit/types/boolean_type_test.rb +7 -21
- data/test/unit/types/date_range_type_test.rb +28 -0
- data/test/unit/types/date_type_test.rb +15 -6
- data/test/unit/types/float_type_test.rb +4 -19
- data/test/unit/types/geo_point_type_test.rb +24 -0
- data/test/unit/types/integer_range_type_test.rb +28 -0
- data/test/unit/types/integer_type_test.rb +7 -16
- data/test/unit/types/string_type_test.rb +9 -13
- data/test/unit/types/time_type_test.rb +17 -11
- data/test/unit/validations_test.rb +2 -2
- metadata +39 -39
- data/lib/superstore/attribute_methods/definition.rb +0 -17
- data/lib/superstore/attribute_methods/dirty.rb +0 -52
- data/lib/superstore/attribute_methods/typecasting.rb +0 -53
- data/lib/superstore/caching.rb +0 -13
- data/lib/superstore/callbacks.rb +0 -29
- data/lib/superstore/connection.rb +0 -24
- data/lib/superstore/errors.rb +0 -10
- data/lib/superstore/inspect.rb +0 -25
- data/lib/superstore/model.rb +0 -38
- data/lib/superstore/schema.rb +0 -20
- data/lib/superstore/scope.rb +0 -73
- data/lib/superstore/scope/batches.rb +0 -27
- data/lib/superstore/scope/finder_methods.rb +0 -51
- data/lib/superstore/scope/query_methods.rb +0 -52
- data/lib/superstore/scoping.rb +0 -30
- data/lib/superstore/timestamps.rb +0 -19
- data/lib/superstore/type.rb +0 -16
- data/lib/superstore/types/base_type.rb +0 -23
- data/lib/superstore/validations.rb +0 -44
- data/test/unit/attribute_methods/definition_test.rb +0 -16
- data/test/unit/inspect_test.rb +0 -26
- data/test/unit/schema_test.rb +0 -15
- data/test/unit/scope/finder_methods_test.rb +0 -62
- data/test/unit/scope/query_methods_test.rb +0 -37
- data/test/unit/scoping_test.rb +0 -7
- 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
|
data/test/unit/inspect_test.rb
DELETED
@@ -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
|
data/test/unit/schema_test.rb
DELETED
@@ -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
|
data/test/unit/scoping_test.rb
DELETED