extendi-cassandra_object 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.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.travis.yml +23 -0
- data/CHANGELOG +0 -0
- data/Gemfile +17 -0
- data/LICENSE +13 -0
- data/MIT-LICENSE +20 -0
- data/README.md +177 -0
- data/Rakefile +12 -0
- data/extendi-cassandra_object.gemspec +26 -0
- data/lib/cassandra_object.rb +73 -0
- data/lib/cassandra_object/adapters/abstract_adapter.rb +61 -0
- data/lib/cassandra_object/adapters/cassandra_adapter.rb +269 -0
- data/lib/cassandra_object/adapters/cassandra_schemaless_adapter.rb +306 -0
- data/lib/cassandra_object/attribute_methods.rb +96 -0
- data/lib/cassandra_object/attribute_methods/definition.rb +22 -0
- data/lib/cassandra_object/attribute_methods/dirty.rb +36 -0
- data/lib/cassandra_object/attribute_methods/primary_key.rb +25 -0
- data/lib/cassandra_object/attribute_methods/typecasting.rb +59 -0
- data/lib/cassandra_object/base.rb +33 -0
- data/lib/cassandra_object/base_schema.rb +11 -0
- data/lib/cassandra_object/base_schemaless.rb +11 -0
- data/lib/cassandra_object/base_schemaless_dynamic.rb +11 -0
- data/lib/cassandra_object/belongs_to.rb +63 -0
- data/lib/cassandra_object/belongs_to/association.rb +49 -0
- data/lib/cassandra_object/belongs_to/builder.rb +40 -0
- data/lib/cassandra_object/belongs_to/reflection.rb +30 -0
- data/lib/cassandra_object/callbacks.rb +29 -0
- data/lib/cassandra_object/core.rb +63 -0
- data/lib/cassandra_object/errors.rb +10 -0
- data/lib/cassandra_object/identity.rb +26 -0
- data/lib/cassandra_object/inspect.rb +25 -0
- data/lib/cassandra_object/log_subscriber.rb +44 -0
- data/lib/cassandra_object/model.rb +60 -0
- data/lib/cassandra_object/persistence.rb +203 -0
- data/lib/cassandra_object/railtie.rb +33 -0
- data/lib/cassandra_object/railties/controller_runtime.rb +45 -0
- data/lib/cassandra_object/schema.rb +83 -0
- data/lib/cassandra_object/schemaless.rb +83 -0
- data/lib/cassandra_object/scope.rb +86 -0
- data/lib/cassandra_object/scope/finder_methods.rb +54 -0
- data/lib/cassandra_object/scope/query_methods.rb +69 -0
- data/lib/cassandra_object/scoping.rb +27 -0
- data/lib/cassandra_object/serialization.rb +6 -0
- data/lib/cassandra_object/tasks/ks.rake +54 -0
- data/lib/cassandra_object/timestamps.rb +19 -0
- data/lib/cassandra_object/type.rb +16 -0
- data/lib/cassandra_object/types.rb +8 -0
- data/lib/cassandra_object/types/array_type.rb +16 -0
- data/lib/cassandra_object/types/base_type.rb +26 -0
- data/lib/cassandra_object/types/boolean_type.rb +20 -0
- data/lib/cassandra_object/types/date_type.rb +22 -0
- data/lib/cassandra_object/types/float_type.rb +16 -0
- data/lib/cassandra_object/types/integer_type.rb +20 -0
- data/lib/cassandra_object/types/json_type.rb +13 -0
- data/lib/cassandra_object/types/string_type.rb +19 -0
- data/lib/cassandra_object/types/time_type.rb +16 -0
- data/lib/cassandra_object/types/type_helper.rb +39 -0
- data/lib/cassandra_object/validations.rb +44 -0
- data/test/support/cassandra.rb +63 -0
- data/test/support/issue.rb +12 -0
- data/test/support/issue_dynamic.rb +12 -0
- data/test/support/issue_schema.rb +17 -0
- data/test/support/issue_schema_child.rb +17 -0
- data/test/support/issue_schema_father.rb +13 -0
- data/test/test_helper.rb +41 -0
- data/test/unit/active_model_test.rb +18 -0
- data/test/unit/adapters/adapter_test.rb +6 -0
- data/test/unit/attribute_methods/definition_test.rb +13 -0
- data/test/unit/attribute_methods/dirty_test.rb +72 -0
- data/test/unit/attribute_methods/primary_key_test.rb +26 -0
- data/test/unit/attribute_methods/typecasting_test.rb +119 -0
- data/test/unit/attribute_methods_test.rb +51 -0
- data/test/unit/base_test.rb +20 -0
- data/test/unit/belongs_to/reflection_test.rb +12 -0
- data/test/unit/belongs_to_test.rb +63 -0
- data/test/unit/callbacks_test.rb +46 -0
- data/test/unit/connection_test.rb +6 -0
- data/test/unit/connections/connections_test.rb +55 -0
- data/test/unit/core_test.rb +55 -0
- data/test/unit/identity_test.rb +26 -0
- data/test/unit/inspect_test.rb +26 -0
- data/test/unit/log_subscriber_test.rb +25 -0
- data/test/unit/persistence_schema_test.rb +156 -0
- data/test/unit/persistence_test.rb +266 -0
- data/test/unit/railties/controller_runtime_test.rb +48 -0
- data/test/unit/schema/tasks_test.rb +32 -0
- data/test/unit/schema_test.rb +115 -0
- data/test/unit/schemaless_test.rb +100 -0
- data/test/unit/scope/finder_methods_test.rb +117 -0
- data/test/unit/scope/query_methods_test.rb +32 -0
- data/test/unit/scoping_test.rb +7 -0
- data/test/unit/timestamps_test.rb +27 -0
- data/test/unit/types/array_type_test.rb +17 -0
- data/test/unit/types/base_type_test.rb +19 -0
- data/test/unit/types/boolean_type_test.rb +24 -0
- data/test/unit/types/date_type_test.rb +15 -0
- data/test/unit/types/float_type_test.rb +17 -0
- data/test/unit/types/integer_type_test.rb +19 -0
- data/test/unit/types/json_type_test.rb +23 -0
- data/test/unit/types/string_type_test.rb +25 -0
- data/test/unit/types/time_type_test.rb +14 -0
- data/test/unit/validations_test.rb +27 -0
- metadata +202 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CassandraObject::BelongsTo::ReflectionTest < CassandraObject::TestCase
|
4
|
+
class ::Status < CassandraObject::Base; end
|
5
|
+
class ::User < CassandraObject::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,63 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CassandraObject::BelongsToTest < CassandraObject::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
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'belongs_to' do
|
18
|
+
issue = Issue.create
|
19
|
+
|
20
|
+
record = TestObject.create(issue: issue)
|
21
|
+
|
22
|
+
assert_equal issue, record.issue
|
23
|
+
assert_equal issue.id, record.issue_id
|
24
|
+
|
25
|
+
record = TestObject.find(record.id)
|
26
|
+
assert_equal issue, record.issue
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'belongs_to with class_name' do
|
30
|
+
issue = Issue.create
|
31
|
+
|
32
|
+
record = TestObject.create(widget: issue)
|
33
|
+
|
34
|
+
assert_equal issue, record.widget
|
35
|
+
assert_equal issue.id, record.widget_id
|
36
|
+
|
37
|
+
record = TestObject.find(record.id)
|
38
|
+
assert_equal issue, record.widget
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'belongs_to with polymorphic' do
|
42
|
+
issue = Issue.create
|
43
|
+
|
44
|
+
record = TestObject.create(target: issue)
|
45
|
+
|
46
|
+
assert_equal issue, record.target
|
47
|
+
assert_equal issue.id, record.target_id
|
48
|
+
assert_equal 'Issue', record.target_type
|
49
|
+
|
50
|
+
record = TestObject.find(record.id)
|
51
|
+
assert_equal issue, record.target
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'belongs_to clear cache after reload' do
|
55
|
+
issue = Issue.create
|
56
|
+
record = TestObject.create(issue: issue)
|
57
|
+
issue.destroy
|
58
|
+
|
59
|
+
assert_not_nil record.issue
|
60
|
+
assert_nil TestObject.find(record.id).issue
|
61
|
+
assert_nil record.reload.issue
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CassandraObject::CallbacksTest < CassandraObject::TestCase
|
4
|
+
class TestIssue < CassandraObject::BaseSchemaless
|
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,55 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class CassandraObject::ConnectionsTest < CassandraObject::TestCase
|
7
|
+
|
8
|
+
test 'test connections' do
|
9
|
+
IssueSchema.delete_all
|
10
|
+
ids = []
|
11
|
+
(1..10000).each do
|
12
|
+
i = IssueSchema.create(title: "fadjfjkadhsfkjldsa")
|
13
|
+
ids << i.id
|
14
|
+
end
|
15
|
+
|
16
|
+
threads = []
|
17
|
+
|
18
|
+
(0..10).collect do |i|
|
19
|
+
|
20
|
+
# puts "spawn thread #{i}"
|
21
|
+
thr = Thread.new do
|
22
|
+
begin
|
23
|
+
IssueSchema.find(ids)
|
24
|
+
rescue Exception => e
|
25
|
+
puts("\n\n\n\n" + e.message)
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
threads << thr
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
# test 'test create' do
|
35
|
+
#
|
36
|
+
# values = []
|
37
|
+
# threads = []
|
38
|
+
# (0..100).collect do |i|
|
39
|
+
#
|
40
|
+
#
|
41
|
+
# puts "spawn thread #{i}"
|
42
|
+
# thr = Thread.new do
|
43
|
+
# begin
|
44
|
+
# values << Issue.new(title: 'title', description: 'desc').search.results.size
|
45
|
+
# rescue Exception => e
|
46
|
+
# puts("\n\n\n\n" + e.message)
|
47
|
+
# retry
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
# threads << thr
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CassandraObject::CoreTest < CassandraObject::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 CassandraObject::IdentityTest < CassandraObject::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 CassandraObject::InspectTest < CassandraObject::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,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'active_support/log_subscriber/test_helper'
|
3
|
+
require 'cassandra_object/log_subscriber'
|
4
|
+
|
5
|
+
class CassandraObject::LogSubscriberTest < CassandraObject::TestCase
|
6
|
+
include ActiveSupport::LogSubscriber::TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
|
11
|
+
CassandraObject::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_match 'SELECT * FROM Issues', @logger.logged(:debug)[0]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_initializes_runtime
|
23
|
+
Thread.new { assert_equal 0, CassandraObject::LogSubscriber.runtime }.join
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class CassandraObject::PersistenceSchemaTest < CassandraObject::TestCase
|
7
|
+
|
8
|
+
test 'instantiate removes unknowns' do
|
9
|
+
assert_nil IssueSchema.instantiate('theid', 'z' => 'nooo').attributes['z']
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'create' do
|
13
|
+
issue = IssueSchema.create title: 'tit', description: 'foo'
|
14
|
+
assert_equal 'foo', issue.description
|
15
|
+
assert_equal 'foo', IssueSchema.find(issue.id).description
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'save' do
|
19
|
+
issue = IssueSchema.new
|
20
|
+
issue.title = 'tit'
|
21
|
+
issue.save
|
22
|
+
|
23
|
+
assert_equal issue, IssueSchema.find(issue.id)
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'save!' do
|
27
|
+
record = IssueSchema.new(title: 'tit', description: 'bad')
|
28
|
+
record.save!
|
29
|
+
|
30
|
+
assert_raise CassandraObject::RecordInvalid do
|
31
|
+
record = IssueSchema.new(description: 'lololol')
|
32
|
+
record.save!
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'destroy' do
|
38
|
+
issue = IssueSchema.create(title: 'I rule', description: 'lololol')
|
39
|
+
issue.destroy
|
40
|
+
|
41
|
+
assert issue.destroyed?
|
42
|
+
assert !issue.persisted?
|
43
|
+
assert !issue.new_record?
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'update_attribute' do
|
47
|
+
issue = IssueSchema.create(title: 'I rule', description: 'lololol')
|
48
|
+
issue.update_attribute(:description, 'lol')
|
49
|
+
|
50
|
+
assert !issue.changed?
|
51
|
+
assert_equal 'lol', issue.description
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'update_attributes' do
|
55
|
+
issue = IssueSchema.create(title: 'I rule', description: 'lololol')
|
56
|
+
issue.update_attributes(title: 'lollete', description: 'lol')
|
57
|
+
|
58
|
+
assert !issue.changed?
|
59
|
+
assert_equal 'lol', issue.description
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'update_attributes!' do
|
63
|
+
issue = IssueSchema.new(description: 'bad')
|
64
|
+
issue.title = 'titttt'
|
65
|
+
issue.save!
|
66
|
+
|
67
|
+
assert_raise CassandraObject::RecordInvalid do
|
68
|
+
issue.update_attributes! title: ''
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'update nil attributes' do
|
73
|
+
issue = IssueSchema.create(title: 'I rule', description: 'lololol')
|
74
|
+
|
75
|
+
issue.update_attributes description: nil
|
76
|
+
|
77
|
+
issue = IssueSchema.find issue.id
|
78
|
+
assert_nil issue.description
|
79
|
+
end
|
80
|
+
|
81
|
+
test 'becomes' do
|
82
|
+
klass = temp_object do
|
83
|
+
end
|
84
|
+
|
85
|
+
assert_kind_of klass, IssueSchema.new.becomes(klass)
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'reload' do
|
89
|
+
persisted_issue = IssueSchema.create(title: 'I rule', description: 'lololol')
|
90
|
+
fresh_issue = IssueSchema.find(persisted_issue.id)
|
91
|
+
fresh_issue.update_attribute(:description, 'say what')
|
92
|
+
|
93
|
+
reloaded_issue = persisted_issue.reload
|
94
|
+
assert_equal 'say what', persisted_issue.description
|
95
|
+
assert_equal persisted_issue, reloaded_issue
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'remove' do
|
99
|
+
issue = IssueSchema.create(title: 'I rule', description: 'lololol')
|
100
|
+
id = issue.id
|
101
|
+
assert_equal id, IssueSchema.find(id).id
|
102
|
+
IssueSchema.remove(id)
|
103
|
+
assert_raise CassandraObject::RecordNotFound do
|
104
|
+
IssueSchema.find(id)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
test 'remove multiple' do
|
109
|
+
ids = []
|
110
|
+
(1..10).each do
|
111
|
+
issue = IssueSchema.create(title: 'I rule', description: 'lololol')
|
112
|
+
ids << issue.id
|
113
|
+
end
|
114
|
+
|
115
|
+
IssueSchema.remove(ids)
|
116
|
+
|
117
|
+
assert_equal [], IssueSchema.find(ids)
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'ttl' do
|
121
|
+
issue = IssueSchema.create(title: 'I rule', description: 'lololol', ttl: 1)
|
122
|
+
assert_nothing_raised do
|
123
|
+
IssueSchema.find(issue.id)
|
124
|
+
end
|
125
|
+
|
126
|
+
sleep 2
|
127
|
+
|
128
|
+
assert_raise CassandraObject::RecordNotFound do
|
129
|
+
IssueSchema.find(issue.id)
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
test 'type tests' do
|
135
|
+
issue = IssueSchema.create(title: 'title', description: 'desc', field: 1.5, intero: 10)
|
136
|
+
assert_nothing_raised do
|
137
|
+
IssueSchema.find(issue.id)
|
138
|
+
end
|
139
|
+
|
140
|
+
from_db = IssueSchema.find(issue.id)
|
141
|
+
assert_equal Float, from_db.field.class
|
142
|
+
assert_equal Fixnum, from_db.intero.class
|
143
|
+
# TODO add other types
|
144
|
+
# byebug
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
test 'belongs_to schema' do
|
149
|
+
father = IssueSchemaFather.create title: 'father'
|
150
|
+
child = IssueSchemaChild.create title: 'child', issue_schema_father: father
|
151
|
+
child.save
|
152
|
+
assert_equal father, IssueSchemaChild.find(child.id).issue_schema_father
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
end
|