superstore 1.2.0 → 2.0.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.
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,15 +1,8 @@
1
1
  module Superstore
2
2
  module Types
3
3
  class ArrayType < BaseType
4
- def encode(array)
5
- raise ArgumentError.new("#{array.inspect} is not an Array") unless array.kind_of?(Array)
6
- array.to_a.to_json
7
- end
8
-
9
- def decode(str)
10
- return nil if str.blank?
11
-
12
- ActiveSupport::JSON.decode(str)
4
+ def decode(val)
5
+ val unless val.blank?
13
6
  end
14
7
 
15
8
  def typecast(value)
@@ -1,17 +1,14 @@
1
1
  module Superstore
2
2
  module Types
3
3
  class BaseType
4
- attr_accessor :options
5
- def initialize(options = {})
4
+ attr_accessor :model, :options
5
+ def initialize(model, options = {})
6
+ @model = model
6
7
  @options = options
7
8
  end
8
9
 
9
- def default
10
- options[:default].duplicable? ? options[:default].dup : options[:default]
11
- end
12
-
13
10
  def encode(value)
14
- value.to_s
11
+ value
15
12
  end
16
13
 
17
14
  def decode(str)
@@ -9,7 +9,8 @@ module Superstore
9
9
  unless VALID_VALS.include?(bool)
10
10
  raise ArgumentError.new("#{bool.inspect} is not a Boolean")
11
11
  end
12
- TRUE_VALS.include?(bool) ? '1' : '0'
12
+
13
+ TRUE_VALS.include?(bool)
13
14
  end
14
15
 
15
16
  def decode(str)
@@ -1,15 +1,16 @@
1
1
  module Superstore
2
2
  module Types
3
3
  class FloatType < BaseType
4
- REGEX = /\A[-+]?\d+(\.\d+)?\Z/
5
4
  def encode(float)
6
- raise ArgumentError.new("#{float.inspect} is not a Float") unless float.kind_of?(Float)
7
- float.to_s
5
+ float
8
6
  end
9
7
 
10
8
  def decode(str)
11
- return nil if str.empty?
12
- str.to_f
9
+ str.to_f unless str.empty?
10
+ end
11
+
12
+ def typecast(value)
13
+ value.to_f
13
14
  end
14
15
  end
15
16
  end
@@ -4,12 +4,12 @@ module Superstore
4
4
  REGEX = /\A[-+]?\d+\Z/
5
5
  def encode(int)
6
6
  raise ArgumentError.new("#{int.inspect} is not an Integer.") unless int.kind_of?(Integer)
7
- int.to_s
7
+
8
+ int
8
9
  end
9
10
 
10
11
  def decode(str)
11
- return nil if str.empty?
12
- str.to_i
12
+ str.to_i unless str.empty?
13
13
  end
14
14
 
15
15
  def typecast(value)
@@ -1,27 +1,6 @@
1
1
  module Superstore
2
2
  module Types
3
3
  class JsonType < BaseType
4
- def encode(data)
5
- ActiveSupport::JSON.encode(data)
6
- end
7
-
8
- def decode(str)
9
- ActiveSupport::JSON.decode(str)
10
- end
11
-
12
- def typecast(data)
13
- return data if ActiveSupport.parse_json_times
14
-
15
- if data.acts_like?(:time) || data.acts_like?(:date)
16
- data.as_json
17
- elsif data.is_a?(Array)
18
- data.map { |d| typecast(d) }
19
- elsif data.is_a?(Hash)
20
- data.each_with_object({}) { |(key, value), hash| hash[key] = typecast(value) }
21
- else
22
- data
23
- end
24
- end
25
4
  end
26
5
  end
27
6
  end
data/lib/superstore.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'active_support/all'
2
2
  require 'active_model'
3
3
  require 'global_id/identification'
4
+ require 'oj'
4
5
  require 'superstore/errors'
5
6
 
6
7
  module Superstore
@@ -8,7 +9,7 @@ module Superstore
8
9
 
9
10
  autoload :AttributeMethods
10
11
  autoload :Base
11
- autoload :BelongsTo
12
+ autoload :Associations
12
13
  autoload :Caching
13
14
  autoload :Callbacks
14
15
  autoload :Connection
@@ -21,7 +22,6 @@ module Superstore
21
22
  autoload :CassandraSchema
22
23
  autoload :Scope
23
24
  autoload :Scoping
24
- autoload :Serialization
25
25
  autoload :Timestamps
26
26
  autoload :Type
27
27
  autoload :Validations
@@ -41,16 +41,27 @@ module Superstore
41
41
  extend ActiveSupport::Autoload
42
42
 
43
43
  autoload :AbstractAdapter
44
+ autoload :JsonbAdapter
44
45
  autoload :CassandraAdapter
45
- autoload :HstoreAdapter
46
46
  end
47
47
 
48
- module BelongsTo
48
+ module Associations
49
49
  extend ActiveSupport::Autoload
50
50
 
51
51
  autoload :Association
52
- autoload :Builder
53
52
  autoload :Reflection
53
+ autoload :BelongsTo
54
+ autoload :HasMany
55
+ autoload :HasOne
56
+
57
+ module Builder
58
+ extend ActiveSupport::Autoload
59
+
60
+ autoload :Association
61
+ autoload :BelongsTo
62
+ autoload :HasMany
63
+ autoload :HasOne
64
+ end
54
65
  end
55
66
 
56
67
  module Types
data/superstore.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'superstore'
5
- s.version = '1.2.0'
5
+ s.version = '2.0.0'
6
6
  s.description = 'ActiveModel for many attributes'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "gotime"]
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_runtime_dependency('activemodel', '>= 3.0')
21
21
  s.add_runtime_dependency('globalid')
22
+ s.add_runtime_dependency('oj')
22
23
 
23
24
  s.add_development_dependency('bundler')
24
25
  end
@@ -0,0 +1,8 @@
1
+ class JsonbInitializer
2
+ def self.initialize!
3
+ Superstore::Base.adapter.create_table('issues')
4
+ Superstore::Base.adapter.define_jsonb_functions!
5
+ end
6
+ end
7
+
8
+ JsonbInitializer.initialize!
@@ -1,10 +1,19 @@
1
+ class User < ActiveRecord::Base
2
+ end
3
+
4
+ class Label < ActiveRecord::Base
5
+ end
6
+
1
7
  class Issue < Superstore::Base
2
8
  string :description
3
9
  string :title
4
10
 
5
11
  before_create { self.description ||= 'funny' }
6
12
 
13
+ has_many :labels
14
+
7
15
  def self.for_key key
8
16
  where_ids(key)
9
17
  end
10
18
  end
19
+
data/test/support/pg.rb CHANGED
@@ -7,9 +7,7 @@ class PGInitializer
7
7
  'encoding' => 'unicode',
8
8
  'database' => 'superstore_test',
9
9
  'pool' => 5,
10
- 'host' => 'localhost',
11
- 'password' => 'postgres',
12
- 'username' => 'postgres'
10
+ 'host' => 'localhost'
13
11
  }
14
12
 
15
13
  ActiveRecord::Base.configurations = { test: config }
@@ -18,9 +16,17 @@ class PGInitializer
18
16
  ActiveRecord::Tasks::DatabaseTasks.create config
19
17
  ActiveRecord::Base.establish_connection config
20
18
 
19
+ create_labels_table
21
20
  create_users_table
22
21
  end
23
22
 
23
+ def self.create_labels_table
24
+ ActiveRecord::Migration.create_table :labels do |t|
25
+ t.string :issue_id, null: false
26
+ t.string :name, null: false
27
+ end
28
+ end
29
+
24
30
  def self.create_users_table
25
31
  ActiveRecord::Migration.create_table :users do |t|
26
32
  t.string :special_id, null: false
@@ -29,19 +35,9 @@ class PGInitializer
29
35
  end
30
36
 
31
37
  def self.table_names
32
- %w(users)
38
+ %w(labels users)
33
39
  end
34
40
  end
35
41
 
36
42
  PGInitializer.initialize!
37
- ActiveRecord::Migration.verbose = false
38
-
39
- module ActiveSupport
40
- class TestCase
41
- teardown do
42
- PGInitializer.table_names.each do |table_name|
43
- ActiveRecord::Base.connection.execute "TRUNCATE #{table_name}"
44
- end
45
- end
46
- end
47
- end
43
+ ActiveRecord::Migration.verbose = false
data/test/test_helper.rb CHANGED
@@ -3,14 +3,15 @@ Bundler.require(:default, :test)
3
3
 
4
4
  I18n.config.enforce_available_locales = false
5
5
 
6
+ require 'active_record'
6
7
  require 'rails/test_help'
7
8
  require 'mocha/setup'
8
9
 
10
+ ActiveSupport::TestCase.test_order = :random
11
+
9
12
  require 'support/pg'
10
- require 'support/hstore'
11
- # require 'support/cassandra'
12
- require 'support/issue'
13
- require 'support/user'
13
+ require 'support/jsonb'
14
+ require 'support/models'
14
15
 
15
16
  def MiniTest.filter_backtrace(bt)
16
17
  bt
@@ -35,9 +36,9 @@ module Superstore
35
36
 
36
37
  module Types
37
38
  class TestCase < Superstore::TestCase
38
- attr_accessor :coder
39
+ attr_accessor :type
39
40
  setup do
40
- @coder = self.class.name.sub(/Test$/, '').constantize.new
41
+ @type = self.class.name.sub(/Test$/, '').constantize.new(Issue)
41
42
  end
42
43
  end
43
44
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class Superstore::BelongsToTest < Superstore::TestCase
3
+ class Superstore::Associations::BelongsTest < Superstore::TestCase
4
4
  class TestObject < Issue
5
5
  string :issue_id
6
6
  belongs_to :issue
@@ -70,15 +70,6 @@ class Superstore::BelongsToTest < Superstore::TestCase
70
70
  assert_equal user, record.user
71
71
  end
72
72
 
73
- test 'belongs_to with primary_key raises an error for non-ActiveRecord' do
74
- issue = Issue.create title: 'title'
75
-
76
- record = TestObject.new
77
- record.title_issue_id = issue.title
78
- assert_raises(ArgumentError) { record.title_issue }
79
- assert_raises(ArgumentError) { record.title_issue = issue }
80
- end
81
-
82
73
  test 'belongs_to with polymorphic' do
83
74
  issue = Issue.create
84
75
 
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::Associations::HasManyTest < Superstore::TestCase
4
+ class TestObject < Issue
5
+ end
6
+
7
+ test 'has_many' do
8
+ issue = TestObject.create!
9
+ label = Label.create! name: 'important', issue_id: issue.id
10
+
11
+ assert_equal [label], issue.labels
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::Associations::HasOneTest < Superstore::TestCase
4
+ class TestObject < Issue
5
+ has_one :favorite_label, class_name: 'Label', foreign_key: 'issue_id'
6
+ end
7
+
8
+ test 'has_many' do
9
+ issue = TestObject.create!
10
+ label = Label.create! name: 'important', issue_id: issue.id
11
+
12
+ assert_equal label, issue.favorite_label
13
+ end
14
+ end
@@ -1,12 +1,12 @@
1
1
  require 'test_helper'
2
2
 
3
- class Superstore::BelongsTo::ReflectionTest < Superstore::TestCase
3
+ class Superstore::Associations::ReflectionTest < Superstore::TestCase
4
4
  class ::Status < Superstore::Base; end
5
5
  class ::Job < Superstore::Base
6
6
  belongs_to :status
7
7
  end
8
8
 
9
9
  test 'class_name' do
10
- assert_equal 'Status', Job.new.belongs_to_reflections[:status].class_name
10
+ assert_equal 'Status', Job.new.association_reflections[:status].class_name
11
11
  end
12
12
  end
@@ -2,12 +2,15 @@ require 'test_helper'
2
2
 
3
3
  class Superstore::AttributeMethods::DefinitionTest < Superstore::TestCase
4
4
  class TestType < Superstore::Types::BaseType
5
+ def typecast(v)
6
+ "#{v}-foo"
7
+ end
5
8
  end
6
9
 
7
- test 'typecast' do
8
- definition = Superstore::AttributeMethods::Definition.new(:foo, TestType, {a: :b})
10
+ test 'initialize' do
11
+ definition = Superstore::AttributeMethods::Definition.new(Issue, :foo, TestType, {})
9
12
 
10
13
  assert_equal 'foo', definition.name
11
- assert_kind_of TestType, definition.coder
14
+ assert_kind_of TestType, definition.type
12
15
  end
13
16
  end
@@ -51,20 +51,6 @@ class Superstore::AttributeMethods::DirtyTest < Superstore::TestCase
51
51
  assert record.changed?
52
52
  end
53
53
 
54
- test 'typecast json with times' do
55
- record = temp_object do
56
- json :stuff
57
- end.create(stuff: {'time' => Time.new(2004, 12, 24, 6, 42, 21)})
58
-
59
- record.reload
60
-
61
- record.stuff = {'time' => Time.new(2004, 12, 24, 6, 42, 21)}
62
- assert !record.changed?
63
-
64
- record.stuff = {'time' => Time.new(2004, 12, 24, 6, 42, 22)}
65
- assert record.changed?
66
- end
67
-
68
54
  test 'unapplied_changes' do
69
55
  record = temp_object do
70
56
  float :price
@@ -94,4 +80,21 @@ class Superstore::AttributeMethods::DirtyTest < Superstore::TestCase
94
80
  assert_equal expected, record.changes
95
81
  end
96
82
  end
83
+
84
+ test 'dirty and restore to original value' do
85
+ object = temp_object do
86
+ string :name
87
+ end
88
+
89
+ record = object.create(name: 'foo')
90
+
91
+ assert_equal({}, record.changes)
92
+
93
+ record.name = 'bar'
94
+ expected = {'name'=>[nil, 'foo']}
95
+ assert_equal({'name' => ['foo', 'bar']}, record.changes)
96
+
97
+ record.name = 'foo'
98
+ assert_equal({}, record.changes)
99
+ end
97
100
  end
@@ -1,16 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Superstore::AttributeMethods::TypecastingTest < Superstore::TestCase
4
- class CustomType
5
- end
6
-
7
- class CustomCoder < Superstore::Types::BaseType
8
- end
9
-
10
4
  class TestIssue < Superstore::Base
11
5
  self.table_name = 'Issues'
12
6
 
13
- attribute :custom_column, type: CustomType, coder: CustomCoder
14
7
  boolean :enabled
15
8
  float :rating
16
9
  integer :price
@@ -28,13 +21,6 @@ class Superstore::AttributeMethods::TypecastingTest < Superstore::TestCase
28
21
  assert_nothing_raised { TestChildIssue.new.description }
29
22
  end
30
23
 
31
- test 'custom attribute definer' do
32
- model_attribute = TestIssue.attribute_definitions['custom_column']
33
-
34
- assert_kind_of CustomCoder, model_attribute.coder
35
- assert_equal 'custom_column', model_attribute.name
36
- end
37
-
38
24
  test 'typecast_attribute' do
39
25
  assert_equal 1, TestIssue.typecast_attribute('price', 1)
40
26
  assert_equal 1, TestIssue.typecast_attribute(:price, 1)
@@ -13,8 +13,8 @@ class Superstore::BaseTest < Superstore::TestCase
13
13
  assert_equal Son, Grandson.base_class
14
14
  end
15
15
 
16
- test 'column family' do
17
- assert_equal 'Superstore::BaseTest::Sons', Son.table_name
18
- assert_equal 'Superstore::BaseTest::Sons', Grandson.table_name
16
+ test 'table_name' do
17
+ assert_equal 'superstore_base_test_sons', Son.table_name
18
+ assert_equal 'superstore_base_test_sons', Grandson.table_name
19
19
  end
20
20
  end
@@ -3,8 +3,4 @@ require 'test_helper'
3
3
  class Superstore::ConnectionTest < Superstore::TestCase
4
4
  class TestObject < Superstore::Base
5
5
  end
6
-
7
- test "sanitize supports question marks" do
8
- assert_equal 'hello ?', CassandraCQL::Statement.sanitize('hello ?')
9
- end
10
6
  end
@@ -176,7 +176,7 @@ class Superstore::PersistenceTest < Superstore::TestCase
176
176
  assert_equal %w{'a' 'b'}, klass.__send__(:quote_columns, %w{a b})
177
177
  end
178
178
 
179
- test 'remove' do
179
+ test 'delete' do
180
180
  klass = temp_object do
181
181
  string :name
182
182
  end
@@ -187,14 +187,14 @@ class Superstore::PersistenceTest < Superstore::TestCase
187
187
  id = record.id
188
188
  assert_equal id, klass.find(id).id
189
189
 
190
- klass.remove(id)
190
+ klass.delete(id)
191
191
 
192
192
  assert_raise Superstore::RecordNotFound do
193
193
  klass.find(id)
194
194
  end
195
195
  end
196
196
 
197
- test 'remove multiple' do
197
+ test 'delete multiple' do
198
198
  klass = temp_object do
199
199
  string :name
200
200
  end
@@ -205,7 +205,7 @@ class Superstore::PersistenceTest < Superstore::TestCase
205
205
  ids << record.id
206
206
  end
207
207
 
208
- klass.remove(ids)
208
+ klass.delete(ids)
209
209
 
210
210
  assert_equal [], klass.find(ids)
211
211
  end
@@ -2,22 +2,14 @@ require 'test_helper'
2
2
 
3
3
  class Superstore::SchemaTest < Superstore::TestCase
4
4
  # SELECT columnfamily_name FROM System.schema_columnfamilies WHERE keyspace_name='myKeyspaceName';
5
- test "create and drop_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
-
14
- Superstore::Schema.drop_table 'TestRecords'
15
-
16
- begin
17
- Superstore::Schema.drop_table 'TestRecords'
18
- assert false, 'TestRecords should not exist'
19
- rescue Exception => e
20
- end
21
- end
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
22
14
 
23
15
  end
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  class Superstore::Scope::QueryMethodsTest < Superstore::TestCase
4
4
  test "select" do
5
5
  original_issue = Issue.create title: 'foo', description: 'bar'
6
-
7
6
  found_issue = Issue.select(:title).find(original_issue.id)
8
7
 
9
8
  assert_equal 'foo', found_issue.title
@@ -11,6 +10,16 @@ class Superstore::Scope::QueryMethodsTest < Superstore::TestCase
11
10
  assert_nil found_issue.description
12
11
  end
13
12
 
13
+ test "where" do
14
+ foo_issue = Issue.create title: 'foo'
15
+ bar_issue = Issue.create title: 'bar'
16
+ nil_issue = Issue.create title: nil
17
+
18
+ assert_equal [foo_issue], Issue.where(title: 'foo').to_a
19
+ assert_equal [foo_issue, bar_issue], Issue.where(title: ['foo', 'bar']).to_a
20
+ assert_equal [nil_issue], Issue.where(title: nil).to_a
21
+ end
22
+
14
23
  test "select with block" do
15
24
  foo_issue = Issue.create title: 'foo'
16
25
  bar_issue = Issue.create title: 'bar'
@@ -1,21 +1,23 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Superstore::Types::ArrayTypeTest < Superstore::Types::TestCase
4
- test 'encode' do
5
- assert_equal ['1', '2'].to_json, coder.encode(['1', '2'])
4
+ if Superstore::Base.adapter.class.name == 'Superstore::Adapters::CassandraAdapter'
5
+ test 'encode' do
6
+ assert_equal ['1', '2'].to_json, type.encode(['1', '2'])
6
7
 
7
- assert_raise ArgumentError do
8
- coder.encode('wtf')
8
+ assert_raise ArgumentError do
9
+ type.encode('wtf')
10
+ end
9
11
  end
10
- end
11
12
 
12
- test 'decode' do
13
- assert_equal ['1', '2'], coder.decode(['1', '2'].to_json)
14
- assert_equal nil, coder.decode(nil)
15
- assert_equal nil, coder.decode('')
13
+ test 'decode' do
14
+ assert_equal ['1', '2'], type.decode(['1', '2'].to_json)
15
+ assert_equal nil, type.decode(nil)
16
+ assert_equal nil, type.decode('')
17
+ end
16
18
  end
17
19
 
18
20
  test 'typecast' do
19
- assert_equal ['x', 'y'], coder.typecast(['x', 'y'].to_set)
21
+ assert_equal ['x', 'y'], type.typecast(['x', 'y'].to_set)
20
22
  end
21
23
  end
@@ -1,19 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Superstore::Types::BaseTypeTest < Superstore::Types::TestCase
4
- test 'default' do
5
- assert_equal nil, coder.default
6
- assert_equal '5', Superstore::Types::BaseType.new(default: '5').default
7
- assert_equal 5.object_id, Superstore::Types::BaseType.new(default: 5).default.object_id
8
- end
9
-
10
4
  test 'encode' do
11
- assert_equal '1', coder.encode(1)
12
- assert_equal '', coder.encode(nil)
13
- assert_equal '1', coder.encode('1')
5
+ assert_equal 'x', type.encode('x')
14
6
  end
15
7
 
16
8
  test 'decode' do
17
- assert_equal 'abc', coder.decode('abc')
9
+ assert_equal 'abc', type.decode('abc')
18
10
  end
19
11
  end