superstore 1.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 (100) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.travis.yml +11 -0
  4. data/CHANGELOG +0 -0
  5. data/Gemfile +19 -0
  6. data/LICENSE +13 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +100 -0
  9. data/Rakefile +12 -0
  10. data/lib/superstore/adapters/abstract_adapter.rb +49 -0
  11. data/lib/superstore/adapters/cassandra_adapter.rb +181 -0
  12. data/lib/superstore/adapters/hstore_adapter.rb +163 -0
  13. data/lib/superstore/attribute_methods/definition.rb +22 -0
  14. data/lib/superstore/attribute_methods/dirty.rb +36 -0
  15. data/lib/superstore/attribute_methods/primary_key.rb +25 -0
  16. data/lib/superstore/attribute_methods/typecasting.rb +59 -0
  17. data/lib/superstore/attribute_methods.rb +96 -0
  18. data/lib/superstore/base.rb +33 -0
  19. data/lib/superstore/belongs_to/association.rb +48 -0
  20. data/lib/superstore/belongs_to/builder.rb +40 -0
  21. data/lib/superstore/belongs_to/reflection.rb +30 -0
  22. data/lib/superstore/belongs_to.rb +63 -0
  23. data/lib/superstore/callbacks.rb +29 -0
  24. data/lib/superstore/cassandra_schema/statements.rb +52 -0
  25. data/lib/superstore/cassandra_schema/tasks.rb +47 -0
  26. data/lib/superstore/cassandra_schema.rb +9 -0
  27. data/lib/superstore/connection.rb +39 -0
  28. data/lib/superstore/core.rb +59 -0
  29. data/lib/superstore/errors.rb +10 -0
  30. data/lib/superstore/identity.rb +26 -0
  31. data/lib/superstore/inspect.rb +25 -0
  32. data/lib/superstore/log_subscriber.rb +44 -0
  33. data/lib/superstore/model.rb +37 -0
  34. data/lib/superstore/persistence.rb +153 -0
  35. data/lib/superstore/railtie.rb +30 -0
  36. data/lib/superstore/railties/controller_runtime.rb +45 -0
  37. data/lib/superstore/schema.rb +20 -0
  38. data/lib/superstore/scope/batches.rb +32 -0
  39. data/lib/superstore/scope/finder_methods.rb +48 -0
  40. data/lib/superstore/scope/query_methods.rb +49 -0
  41. data/lib/superstore/scope.rb +49 -0
  42. data/lib/superstore/scoping.rb +27 -0
  43. data/lib/superstore/tasks/ks.rake +54 -0
  44. data/lib/superstore/timestamps.rb +19 -0
  45. data/lib/superstore/type.rb +16 -0
  46. data/lib/superstore/types/array_type.rb +20 -0
  47. data/lib/superstore/types/base_type.rb +26 -0
  48. data/lib/superstore/types/boolean_type.rb +20 -0
  49. data/lib/superstore/types/date_type.rb +22 -0
  50. data/lib/superstore/types/float_type.rb +16 -0
  51. data/lib/superstore/types/integer_type.rb +20 -0
  52. data/lib/superstore/types/json_type.rb +13 -0
  53. data/lib/superstore/types/string_type.rb +19 -0
  54. data/lib/superstore/types/time_type.rb +16 -0
  55. data/lib/superstore/types.rb +8 -0
  56. data/lib/superstore/validations.rb +44 -0
  57. data/lib/superstore.rb +69 -0
  58. data/superstore.gemspec +23 -0
  59. data/test/support/cassandra.rb +44 -0
  60. data/test/support/hstore.rb +40 -0
  61. data/test/support/issue.rb +10 -0
  62. data/test/test_helper.rb +42 -0
  63. data/test/unit/active_model_test.rb +18 -0
  64. data/test/unit/adapters/adapter_test.rb +6 -0
  65. data/test/unit/attribute_methods/definition_test.rb +13 -0
  66. data/test/unit/attribute_methods/dirty_test.rb +72 -0
  67. data/test/unit/attribute_methods/primary_key_test.rb +26 -0
  68. data/test/unit/attribute_methods/typecasting_test.rb +118 -0
  69. data/test/unit/attribute_methods_test.rb +51 -0
  70. data/test/unit/base_test.rb +20 -0
  71. data/test/unit/belongs_to/reflection_test.rb +12 -0
  72. data/test/unit/belongs_to_test.rb +62 -0
  73. data/test/unit/callbacks_test.rb +46 -0
  74. data/test/unit/cassandra_schema/statements_test.rb +47 -0
  75. data/test/unit/cassandra_schema/tasks_test.rb +31 -0
  76. data/test/unit/connection_test.rb +10 -0
  77. data/test/unit/core_test.rb +55 -0
  78. data/test/unit/identity_test.rb +26 -0
  79. data/test/unit/inspect_test.rb +26 -0
  80. data/test/unit/log_subscriber_test.rb +26 -0
  81. data/test/unit/persistence_test.rb +213 -0
  82. data/test/unit/railties/controller_runtime_test.rb +48 -0
  83. data/test/unit/schema_test.rb +27 -0
  84. data/test/unit/scope/batches_test.rb +30 -0
  85. data/test/unit/scope/finder_methods_test.rb +51 -0
  86. data/test/unit/scope/query_methods_test.rb +27 -0
  87. data/test/unit/scoping_test.rb +7 -0
  88. data/test/unit/serialization_test.rb +10 -0
  89. data/test/unit/timestamps_test.rb +27 -0
  90. data/test/unit/types/array_type_test.rb +21 -0
  91. data/test/unit/types/base_type_test.rb +19 -0
  92. data/test/unit/types/boolean_type_test.rb +24 -0
  93. data/test/unit/types/date_type_test.rb +15 -0
  94. data/test/unit/types/float_type_test.rb +17 -0
  95. data/test/unit/types/integer_type_test.rb +19 -0
  96. data/test/unit/types/json_type_test.rb +23 -0
  97. data/test/unit/types/string_type_test.rb +30 -0
  98. data/test/unit/types/time_type_test.rb +19 -0
  99. data/test/unit/validations_test.rb +27 -0
  100. metadata +170 -0
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::AttributeMethodsTest < Superstore::TestCase
4
+ test 'read and write attributes' do
5
+ issue = Issue.new
6
+ assert_nil issue.read_attribute(:description)
7
+
8
+ issue.write_attribute(:description, nil)
9
+ assert_nil issue.read_attribute(:description)
10
+
11
+ issue.write_attribute(:description, 'foo')
12
+ assert_equal 'foo', issue.read_attribute(:description)
13
+ end
14
+
15
+ test 'hash accessor aliases' do
16
+ issue = Issue.new
17
+
18
+ issue[:description] = 'bar'
19
+
20
+ assert_equal 'bar', issue[:description]
21
+ end
22
+
23
+ test 'attributes setter' do
24
+ issue = Issue.new
25
+
26
+ issue.attributes = {
27
+ description: 'foo'
28
+ }
29
+
30
+ assert_equal 'foo', issue.description
31
+ end
32
+
33
+ class ChildIssue < Issue
34
+ def title=(val)
35
+ self[:title] = val + ' lol'
36
+ end
37
+ end
38
+
39
+ test 'override' do
40
+ issue = ChildIssue.new(title: 'hey')
41
+
42
+ assert_equal 'hey lol', issue.title
43
+ end
44
+
45
+ # test 'attribute_exists' do
46
+ # assert !Issue.new.attribute_exists?(:description)
47
+ # assert Issue.new(description: nil).attribute_exists?(:description)
48
+ # assert Issue.new(description: false).attribute_exists?(:description)
49
+ # assert Issue.new(description: 'hey').attribute_exists?(:description)
50
+ # end
51
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::BaseTest < Superstore::TestCase
4
+ class Son < Superstore::Base
5
+ end
6
+
7
+ class Grandson < Son
8
+ end
9
+
10
+ test 'base_class' do
11
+ assert_equal Superstore::Base, Superstore::Base
12
+ assert_equal Son, Son.base_class
13
+ assert_equal Son, Grandson.base_class
14
+ end
15
+
16
+ test 'column family' do
17
+ assert_equal 'Superstore::BaseTest::Sons', Son.column_family
18
+ assert_equal 'Superstore::BaseTest::Sons', Grandson.column_family
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::BelongsTo::ReflectionTest < Superstore::TestCase
4
+ class ::Status < Superstore::Base; end
5
+ class ::User < Superstore::Base
6
+ belongs_to :status
7
+ end
8
+
9
+ test 'class_name' do
10
+ assert_equal 'Status', User.new.belongs_to_reflections[:status].class_name
11
+ end
12
+ end
@@ -0,0 +1,62 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::BelongsToTest < Superstore::TestCase
4
+ class TestObject < Issue
5
+ string :issue_id
6
+ belongs_to :issue
7
+
8
+ string :widget_id
9
+ belongs_to :widget, class_name: 'Issue'
10
+
11
+ string :target_id
12
+ string :target_type
13
+ belongs_to :target, polymorphic: true
14
+ end
15
+
16
+ test 'belongs_to' do
17
+ issue = Issue.create
18
+
19
+ record = TestObject.create(issue: issue)
20
+
21
+ assert_equal issue, record.issue
22
+ assert_equal issue.id, record.issue_id
23
+
24
+ record = TestObject.find(record.id)
25
+ assert_equal issue, record.issue
26
+ end
27
+
28
+ test 'belongs_to with class_name' do
29
+ issue = Issue.create
30
+
31
+ record = TestObject.create(widget: issue)
32
+
33
+ assert_equal issue, record.widget
34
+ assert_equal issue.id, record.widget_id
35
+
36
+ record = TestObject.find(record.id)
37
+ assert_equal issue, record.widget
38
+ end
39
+
40
+ test 'belongs_to with polymorphic' do
41
+ issue = Issue.create
42
+
43
+ record = TestObject.create(target: issue)
44
+
45
+ assert_equal issue, record.target
46
+ assert_equal issue.id, record.target_id
47
+ assert_equal 'Issue', record.target_type
48
+
49
+ record = TestObject.find(record.id)
50
+ assert_equal issue, record.target
51
+ end
52
+
53
+ test 'belongs_to clear cache after reload' do
54
+ issue = Issue.create
55
+ record = TestObject.create(issue: issue)
56
+ issue.destroy
57
+
58
+ assert_not_nil record.issue
59
+ assert_nil TestObject.find(record.id).issue
60
+ assert_nil record.reload.issue
61
+ end
62
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::CallbacksTest < Superstore::TestCase
4
+ class TestIssue < Superstore::Base
5
+ self.column_family = 'Issues'
6
+ string :description
7
+
8
+ %w(before_validation after_validation after_save after_create after_update after_destroy).each do |method|
9
+ send(method) do
10
+ callback_history << method
11
+ end
12
+ end
13
+
14
+ def reset_callback_history
15
+ @callback_history = []
16
+ end
17
+
18
+ def callback_history
19
+ @callback_history ||= []
20
+ end
21
+ end
22
+
23
+ test 'create' do
24
+ issue = TestIssue.create
25
+
26
+ assert_equal ['before_validation', 'after_validation', 'after_save', 'after_create'], issue.callback_history
27
+ end
28
+
29
+ test 'update' do
30
+ issue = TestIssue.create
31
+ issue.reset_callback_history
32
+
33
+ issue.update_attribute :description, 'foo'
34
+
35
+ assert_equal ['after_save', 'after_update'], issue.callback_history
36
+ end
37
+
38
+ test 'destroy' do
39
+ issue = TestIssue.create
40
+ issue.reset_callback_history
41
+
42
+ issue.destroy
43
+
44
+ assert_equal ['after_destroy'], issue.callback_history
45
+ end
46
+ end
@@ -0,0 +1,47 @@
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
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::ConnectionTest < Superstore::TestCase
4
+ class TestObject < Superstore::Base
5
+ end
6
+
7
+ test "sanitize supports question marks" do
8
+ assert_equal 'hello ?', CassandraCQL::Statement.sanitize('hello ?')
9
+ end
10
+ end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::CoreTest < Superstore::TestCase
4
+ test 'initialiaze' do
5
+ issue = Issue.new
6
+
7
+ assert issue.new_record?
8
+ assert !issue.destroyed?
9
+ end
10
+
11
+ test 'initialize yields self' do
12
+ issue = Issue.new { |i| i.description = 'bar' }
13
+ assert_equal 'bar', issue.description
14
+ end
15
+
16
+ test 'dup' do
17
+ issue = Issue.create description: 'foo'
18
+
19
+ dup_issue = issue.dup
20
+
21
+ assert dup_issue.new_record?
22
+ assert_not_equal issue.id, dup_issue.id
23
+ assert_nil dup_issue.created_at
24
+ assert_nil dup_issue.updated_at
25
+ assert_equal 'foo', issue.description
26
+ end
27
+
28
+ test 'equality of new records' do
29
+ assert_not_equal Issue.new, Issue.new
30
+ end
31
+
32
+ test 'equality' do
33
+ first_issue = Issue.create
34
+ second_issue = Issue.create
35
+
36
+ assert_equal first_issue, first_issue
37
+ assert_equal first_issue, Issue.find(first_issue.id)
38
+ assert_not_equal first_issue, second_issue
39
+ end
40
+
41
+ test 'to_param' do
42
+ issue = Issue.new
43
+ assert_equal issue.id, issue.to_param
44
+ end
45
+
46
+ test 'hash' do
47
+ issue = Issue.create
48
+ assert_equal issue.id.hash, issue.hash
49
+ end
50
+
51
+ test 'inspect' do
52
+ issue = Issue.create
53
+ assert issue.inspect =~ /^#<Issue id: \"\w+\", created_at: \".+\", updated_at: \".+\", description: \".+\">$/
54
+ end
55
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::IdentityTest < Superstore::TestCase
4
+ test 'primary_key' do
5
+ assert_equal 'id', Issue.primary_key
6
+ end
7
+
8
+ test 'default _generate_key' do
9
+ issue = Issue.new
10
+
11
+ assert_not_nil Issue._generate_key(issue)
12
+ end
13
+
14
+ test 'custom key' do
15
+ model = temp_object do
16
+ key do
17
+ "name:#{name}"
18
+ end
19
+ attr_accessor :name
20
+ end
21
+ record = model.new
22
+ record.name = 'bar'
23
+
24
+ assert_equal 'name:bar', model._generate_key(record)
25
+ end
26
+ end
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,213 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'test_helper'
5
+
6
+ class Superstore::PersistenceTest < Superstore::TestCase
7
+ test 'instantiate removes unknowns' do
8
+ assert_nil Issue.instantiate('theid', 'z' => 'nooo').attributes['z']
9
+ end
10
+
11
+ test 'encode_attributes' do
12
+ klass = temp_object do
13
+ string :description
14
+ end
15
+
16
+ assert_equal(
17
+ {},
18
+ klass.encode_attributes({})
19
+ )
20
+
21
+ assert_equal(
22
+ {'description' => nil},
23
+ klass.encode_attributes({'description' => nil})
24
+ )
25
+
26
+ assert_equal(
27
+ {'description' => 'lol'},
28
+ klass.encode_attributes({'description' => 'lol'})
29
+ )
30
+ end
31
+
32
+ test "batch" do
33
+ first_issue = second_issue = nil
34
+
35
+ Issue.batch do
36
+ assert Issue.batching?
37
+
38
+ first_issue = Issue.create
39
+ second_issue = Issue.create
40
+
41
+ assert_raise(Superstore::RecordNotFound) { Issue.find(first_issue.id) }
42
+ assert_raise(Superstore::RecordNotFound) { Issue.find(second_issue.id) }
43
+ end
44
+
45
+ assert !Issue.batching?
46
+ assert_nothing_raised(Superstore::RecordNotFound) { Issue.find(first_issue.id) }
47
+ assert_nothing_raised(Superstore::RecordNotFound) { Issue.find(second_issue.id) }
48
+ end
49
+
50
+ test 'persistance inquiries' do
51
+ issue = Issue.new
52
+ assert issue.new_record?
53
+ assert !issue.persisted?
54
+
55
+ issue.save
56
+ assert issue.persisted?
57
+ assert !issue.new_record?
58
+ end
59
+
60
+ test 'create' do
61
+ issue = Issue.create { |i| i.description = 'foo' }
62
+ assert_equal 'foo', issue.description
63
+ assert_equal 'foo', Issue.find(issue.id).description
64
+ end
65
+
66
+ test 'read and write UTF' do
67
+ utf = "\ucba1\ucba2\ucba3 ƒ´∑ƒ©√åµ≈√ˆअनुच्छेद´µøµø¬≤ 汉语漢語".force_encoding(Encoding::UTF_8)
68
+
69
+ issue = Issue.create { |i| i.description = utf }
70
+ assert_equal utf, issue.description
71
+ reloaded = Issue.find(issue.id).description
72
+ assert_equal utf, reloaded
73
+ end
74
+
75
+ test 'save' do
76
+ issue = Issue.new
77
+ issue.save
78
+
79
+ assert_equal issue, Issue.find(issue.id)
80
+ end
81
+
82
+ test 'save!' do
83
+ klass = temp_object do
84
+ string :description
85
+ validates :description, presence: true
86
+ end
87
+
88
+ record = klass.new(description: 'bad')
89
+ record.save!
90
+
91
+ assert_raise Superstore::RecordInvalid do
92
+ record = klass.new
93
+ record.save!
94
+ end
95
+ end
96
+
97
+ test 'destroy' do
98
+ issue = Issue.create
99
+ issue.destroy
100
+
101
+ assert issue.destroyed?
102
+ assert !issue.persisted?
103
+ assert !issue.new_record?
104
+ end
105
+
106
+ test 'update_attribute' do
107
+ issue = Issue.create
108
+ issue.update_attribute(:description, 'lol')
109
+
110
+ assert !issue.changed?
111
+ assert_equal 'lol', issue.description
112
+ end
113
+
114
+ test 'update_attributes' do
115
+ issue = Issue.create
116
+ issue.update_attributes(description: 'lol')
117
+
118
+ assert !issue.changed?
119
+ assert_equal 'lol', issue.description
120
+ end
121
+
122
+ test 'update_attributes!' do
123
+ begin
124
+ Issue.validates(:description, presence: true)
125
+
126
+ issue = Issue.new(description: 'bad')
127
+ issue.save!
128
+
129
+ assert_raise Superstore::RecordInvalid do
130
+ issue.update_attributes! description: ''
131
+ end
132
+ ensure
133
+ Issue.reset_callbacks(:validate)
134
+ end
135
+ end
136
+
137
+ test 'update nil attributes' do
138
+ issue = Issue.create(title: 'I rule', description: 'lololol')
139
+
140
+ issue.update_attributes title: nil
141
+
142
+ issue = Issue.find issue.id
143
+ assert_nil issue.title
144
+ end
145
+
146
+ test 'becomes' do
147
+ klass = temp_object do
148
+ end
149
+
150
+ assert_kind_of klass, Issue.new.becomes(klass)
151
+ end
152
+
153
+ test 'reload' do
154
+ persisted_issue = Issue.create
155
+ fresh_issue = Issue.find(persisted_issue.id)
156
+ fresh_issue.update_attribute(:description, 'say what')
157
+
158
+ reloaded_issue = persisted_issue.reload
159
+ assert_equal 'say what', persisted_issue.description
160
+ assert_equal persisted_issue, reloaded_issue
161
+ end
162
+
163
+ test 'allow CQL keyword in column name' do
164
+ assert_nothing_raised do
165
+ Issue.string :text
166
+ issue = Issue.create :text => 'hello'
167
+ issue.text = 'world'
168
+ issue.save!
169
+ issue.text = nil
170
+ issue.save!
171
+ end
172
+ end
173
+
174
+ test 'quote_columns' do
175
+ klass = Class.new { include Superstore::Persistence }
176
+ assert_equal %w{'a' 'b'}, klass.__send__(:quote_columns, %w{a b})
177
+ end
178
+
179
+ test 'remove' do
180
+ klass = temp_object do
181
+ string :name
182
+ end
183
+
184
+ record = klass.new(name: 'cool')
185
+ record.save!
186
+
187
+ id = record.id
188
+ assert_equal id, klass.find(id).id
189
+
190
+ klass.remove(id)
191
+
192
+ assert_raise Superstore::RecordNotFound do
193
+ klass.find(id)
194
+ end
195
+ end
196
+
197
+ test 'remove multiple' do
198
+ klass = temp_object do
199
+ string :name
200
+ end
201
+
202
+ ids = []
203
+ (1..10).each do
204
+ record = klass.create!(name: 'cool')
205
+ ids << record.id
206
+ end
207
+
208
+ klass.remove(ids)
209
+
210
+ assert_equal [], klass.find(ids)
211
+ end
212
+
213
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+ require "superstore/railties/controller_runtime"
3
+
4
+ class Superstore::Railties::ControllerRuntimeTest < MiniTest::Unit::TestCase
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