activerecord-runivedo 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76c8d1e6bcfaacaf69adb4fb3f9d91f2344a26cd
4
- data.tar.gz: e267f3b3f03cf19a449a901ae8bc878ab73cb7e6
3
+ metadata.gz: b623b91f13fc1a06d1ece4e1f76d99ca2bc20085
4
+ data.tar.gz: 3b9d9b0a5d03235af18aef81736d853b784fa22b
5
5
  SHA512:
6
- metadata.gz: 7368f4cb85245c1f1bc8a423ccebd173e263e46da0058a3c51b3310377ce2abd421f9477ab3a10bd49277915a7aee8a62e6654235e01b40a945ba7c3bbb98a98
7
- data.tar.gz: 7fa4a0405e0ef432532653646c1e6a7969f1c8437de2ab7126d3959dad161ad9fe51ebffc7a153c6c6a129f5979c3ab333917c5c398ea1bc23756b16cee0c6d0
6
+ metadata.gz: 93507d535477833177703278f535b58faf843002a575e441bec93cc0b9ba0e61a15d02d20f5d8d6990bdffb64519542c4b3dd84b8368dd18b1440e38970cb1b8
7
+ data.tar.gz: b908f653d0406fee2e5049f38195d3bd5dc9093bff39205a5bec1ec66266d61f6decdc6be1115d8059f2bcbddafd3551345fea2bb3691b4d2581763210727e12
@@ -0,0 +1,170 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <uts date="2015-02-20 13:32:02 +0000" generator="uspec" version="1.0">
3
+ <specification>
4
+ <tables>
5
+ <table name="BucketRevision" description="" uuid="01808530-0754-4661-9a6c-15737c023ad4">
6
+ <fields>
7
+ <field name="perspective" description="" type="id" uuid="33be27d7-f768-49f3-aaf9-e7c0ff81eb01"/>
8
+ </fields>
9
+ </table>
10
+ <table name="Fields" description="Columns in utoms or tables in the Univedo data model." uuid="76231b4f-0c1a-453f-9cf4-f299bd043436">
11
+ <fields>
12
+ <field name="name" description="" type="char" length="50" uuid="00397067-f1b1-44b7-8637-769e0f86e6fd"/>
13
+ <field name="uuid" description="" type="uuid" uuid="d23f4669-2ab7-42ac-98e2-467ef332b47d"/>
14
+ <field name="type" description="" type="char" length="20" uuid="7dbe9ebb-5178-4aa5-91bb-096fb1ffb894"/>
15
+ <field name="foreign_key" description="" type="id" uuid="cd380935-5915-4b65-ade0-a5fa1144ee2e"/>
16
+ <field name="foreign_table" description="" type="id" uuid="ec74db31-3bc6-409c-ae2e-9a6b8d1f2a6c"/>
17
+ <field name="foreign_inverse" description="" type="bool" uuid="90634fbe-9818-490d-951b-1b81ffe9cf8e"/>
18
+ <field name="description" description="" type="text" uuid="9b1014e1-ec8e-4231-8746-36b0e8c2379f"/>
19
+ </fields>
20
+ </table>
21
+ <table name="Dummy" description="Dummy utom for test purposes.&#13;&#10;&#13;&#10;Apps can use this utom for testing but should not make any assumptions on data." uuid="195f5ecf-7da9-46c7-af09-3e6c0aaaf782">
22
+ <fields>
23
+ <field name="dummy_int8" description="" type="integer" length="1" uuid="43afa38a-28c0-46fc-bd0e-4e302e8583ae"/>
24
+ <field name="dummy_bool" description="" type="bool" uuid="6666c7a8-ae19-470a-88c3-5410f0ef6cbd"/>
25
+ <field name="dummy_blob" description="" type="blob" uuid="9ddabd19-4af4-499a-b579-32e4aa369df5"/>
26
+ <field name="dummy_char" description="" type="char" length="10" uuid="cadd88cc-0d52-46c5-9daf-975085a50b8e"/>
27
+ <field name="dummy_int16" description="" type="integer" length="2" uuid="ca7f8ef6-abbb-49da-9165-e97b6d1062cc"/>
28
+ <field name="dummy_int32" description="" type="integer" length="4" uuid="c9f62a3d-84af-4552-848f-7fc35124021a"/>
29
+ <field name="dummy_int64" description="" type="integer" length="8" uuid="cc69b4db-017e-4a57-837a-9e916ab40728"/>
30
+ <field name="dummy_float" description="" type="float" length="4" uuid="29d3812a-82c2-4022-9e88-4b1edd980432"/>
31
+ <field name="dummy_double" description="" type="float" length="8" uuid="23319e53-4f4e-48ad-b6df-93d4d432ed33"/>
32
+ <field name="dummy_text" description="" type="text" uuid="76df4e6a-785e-4615-b112-19b764e61c05"/>
33
+ <field name="dummy_datetime" description="" type="datetime" uuid="74860bb5-21eb-4eaf-b213-904587839d37"/>
34
+ <field name="dummy_uuid" description="" type="uuid" uuid="8d506bbb-9e41-4f51-a522-3646977d0bb5"/>
35
+ <field name="dummy_id" description="" type="id" uuid="9e593d3f-15fe-42ba-b9f2-6248dc6d16df"/>
36
+ </fields>
37
+ </table>
38
+ </tables>
39
+ <keys>
40
+ <key name="Owner" description="" uuid="f39d26c0-1e62-4133-b08f-10bb3855c223"/>
41
+ </keys>
42
+ <events>
43
+ <event name="inserted" description="" uuid="12b3e063-7aa8-44e7-bc8c-4a1b1a238454"/>
44
+ <event name="deleted" description="" uuid="9507ee43-ea4b-4ba7-88b2-9391ca59dc8a"/>
45
+ <event name="updated" description="" uuid="b2db0a97-001a-454b-9119-48a3c7a42c7f"/>
46
+ </events>
47
+ </specification>
48
+ <apps>
49
+ <app uuid="cefb4ed2-4ce3-4825-8550-b68a3c142f0a" name="Test Perspective" description="Sample perspective used for testing.">
50
+ <tables>
51
+ <table name="dummy" description="" specification="195f5ecf-7da9-46c7-af09-3e6c0aaaf782" selective="true">
52
+ <fields>
53
+ <field name="dummy_int8" description="" specification="43afa38a-28c0-46fc-bd0e-4e302e8583ae"/>
54
+ <field name="dummy_bool" description="" specification="6666c7a8-ae19-470a-88c3-5410f0ef6cbd"/>
55
+ <field name="dummy_blob" description="" specification="9ddabd19-4af4-499a-b579-32e4aa369df5"/>
56
+ <field name="dummy_char" description="" specification="cadd88cc-0d52-46c5-9daf-975085a50b8e"/>
57
+ <field name="dummy_int16" description="" specification="ca7f8ef6-abbb-49da-9165-e97b6d1062cc"/>
58
+ <field name="dummy_int32" description="" specification="c9f62a3d-84af-4552-848f-7fc35124021a"/>
59
+ <field name="dummy_int64" description="" specification="cc69b4db-017e-4a57-837a-9e916ab40728"/>
60
+ <field name="dummy_float" description="" specification="29d3812a-82c2-4022-9e88-4b1edd980432"/>
61
+ <field name="dummy_double" description="" specification="23319e53-4f4e-48ad-b6df-93d4d432ed33"/>
62
+ <field name="dummy_text" description="" specification="76df4e6a-785e-4615-b112-19b764e61c05"/>
63
+ <field name="dummy_datetime" description="" specification="74860bb5-21eb-4eaf-b213-904587839d37"/>
64
+ <field name="dummy_uuid" description="" specification="8d506bbb-9e41-4f51-a522-3646977d0bb5"/>
65
+ <field name="dummy_id" description="" specification="9e593d3f-15fe-42ba-b9f2-6248dc6d16df"/>
66
+ <field name="foreign_key_id" description="" type="foreign_key" foreign_table="dummy" foreign_key="key" foreign_inverse="false"/>
67
+ <field name="id" description="" specification="c36ce2f6-c4f9-4133-841d-3da4f45f62ca"/>
68
+ <field name="created_at" description="" specification="b749da4b-3c27-4e11-8be2-6cc5c9cdc7c7"/>
69
+ <field name="updated_at" description="" specification="b34d7140-9005-4362-aa5d-1e091f5772df"/>
70
+ <field name="human_readable" description="" specification="4cf63bae-c2a9-4958-8809-087d67ff782a"/>
71
+ <field name="card" description="" specification="2a8ea640-4311-498f-9190-db0442f785c3"/>
72
+ <field name="foreign_key1_id" description="" type="foreign_key" foreign_table="dummy" foreign_key="key1" foreign_inverse="false"/>
73
+ <field name="creator_id" specification="8925cce6-3b67-4eff-b30f-a57b90545c51"/>
74
+ <field name="modifier_id" specification="fc152a9b-99bb-4370-87b9-ee162602a1b1"/>
75
+ </fields>
76
+ </table>
77
+ <table name="virt" description="">
78
+ <fields>
79
+ <field name="dummy_id" description="" type="foreign_key" foreign_table="dummy" foreign_key="key" foreign_inverse="false"/>
80
+ <field name="self" description="" type="foreign_key" foreign_table="virt" foreign_key="key" foreign_inverse="false"/>
81
+ <field name="inverse" description="" type="foreign_key" foreign_table="dummy" foreign_key="key" foreign_inverse="true"/>
82
+ <field name="dummy_id1" description="" type="foreign_key" foreign_table="dummy" foreign_key="key" foreign_inverse="false"/>
83
+ <field name="dummy_id2" description="" type="foreign_key" foreign_table="dummy" foreign_key="key1" foreign_inverse="false"/>
84
+ <field name="dummy2_id" description="" type="foreign_key" foreign_table="dummy_2" foreign_key="key1" foreign_inverse="false"/>
85
+ <field name="id" specification="c36ce2f6-c4f9-4133-841d-3da4f45f62ca"/>
86
+ </fields>
87
+ </table>
88
+ <table name="fields_selective" description="" specification="76231b4f-0c1a-453f-9cf4-f299bd043436" selective="true">
89
+ <fields>
90
+ <field name="id" specification="c36ce2f6-c4f9-4133-841d-3da4f45f62ca"/>
91
+ </fields>
92
+ </table>
93
+ <table name="fields_inclusive" description="" specification="76231b4f-0c1a-453f-9cf4-f299bd043436" selective="false">
94
+ <fields>
95
+ <field name="id" description="" specification="c36ce2f6-c4f9-4133-841d-3da4f45f62ca"/>
96
+ </fields>
97
+ </table>
98
+ <table name="dummy_child" description="" parent="dummy" selective="false">
99
+ <fields>
100
+ </fields>
101
+ </table>
102
+ <table name="dummy_2" description="" specification="195f5ecf-7da9-46c7-af09-3e6c0aaaf782" selective="false">
103
+ <fields>
104
+ <field name="id" description="" specification="c36ce2f6-c4f9-4133-841d-3da4f45f62ca"/>
105
+ <field name="dummy_char" specification="cadd88cc-0d52-46c5-9daf-975085a50b8e"/>
106
+ </fields>
107
+ </table>
108
+ <table name="dummy_renamed" description="Dummy with renamed fields." specification="195f5ecf-7da9-46c7-af09-3e6c0aaaf782" selective="false">
109
+ <fields>
110
+ <field name="bool_dummy" specification="6666c7a8-ae19-470a-88c3-5410f0ef6cbd"/>
111
+ </fields>
112
+ </table>
113
+ <table name="bucket_revisions" description="" specification="01808530-0754-4661-9a6c-15737c023ad4" selective="false">
114
+ <fields>
115
+ <field name="perspective" specification="33be27d7-f768-49f3-aaf9-e7c0ff81eb01"/>
116
+ <field name="id" specification="c36ce2f6-c4f9-4133-841d-3da4f45f62ca"/>
117
+ <field name="created_at" specification="b749da4b-3c27-4e11-8be2-6cc5c9cdc7c7"/>
118
+ <field name="creator_id" specification="8925cce6-3b67-4eff-b30f-a57b90545c51"/>
119
+ </fields>
120
+ </table>
121
+ </tables>
122
+ <join_tables>
123
+ <join_table name="test_join" description="" key="key" table_left="dummy" table_right="dummy_2" column_name_left="dummy_id" column_name_right="dummy2_id"/>
124
+ <join_table name="test_join2" description="" key="key1" table_left="dummy" table_right="dummy_2" column_name_left="dummy_id" column_name_right="dummy2_id"/>
125
+ <join_table name="test_virt_join" description="" key="key" table_left="dummy" table_right="virt" column_name_left="dummy_id" column_name_right="virt_id"/>
126
+ <join_table name="test_virt_join2" description="" key="key1" table_left="dummy" table_right="virt" column_name_left="dummy_id" column_name_right="virt_id"/>
127
+ </join_tables>
128
+ <keys>
129
+ <key name="key" description=""/>
130
+ <key name="key1" description=""/>
131
+ <key name="owner" description="" specification="f39d26c0-1e62-4133-b08f-10bb3855c223"/>
132
+ </keys>
133
+ <events>
134
+ <event name="inserted" description="" specification="12b3e063-7aa8-44e7-bc8c-4a1b1a238454"/>
135
+ <event name="deleted" description="" specification="9507ee43-ea4b-4ba7-88b2-9391ca59dc8a"/>
136
+ <event name="updated" description="" specification="b2db0a97-001a-454b-9119-48a3c7a42c7f"/>
137
+ </events>
138
+ <states>
139
+ <state name="dummy" description="">
140
+ <instance name="dummy" table="dummy">
141
+ </instance>
142
+ </state>
143
+ <state name="test_state_1" description="">
144
+ <instance name="dummy_i" table="dummy">
145
+ <instance name="dummy_2_i" table="dummy_2" key="key" join_invert="false" optional="false">
146
+ </instance>
147
+ </instance>
148
+ </state>
149
+ <state name="test_state_2" description="">
150
+ <instance name="dummy_i" table="dummy">
151
+ <instance name="dummy_i_2" table="dummy" key="key" join_invert="false" optional="false">
152
+ </instance>
153
+ <instance name="dummy_2_i" table="dummy_2" key="key" join_invert="false" optional="false">
154
+ </instance>
155
+ </instance>
156
+ </state>
157
+ </states>
158
+ <listeners>
159
+ <listener name="test_listener_1_inserted" description="" persistent="false" state="test_state_1" event="inserted"/>
160
+ <listener name="test_persistent_listener_1_inserted" description="" persistent="true" state="test_state_1" event="inserted"/>
161
+ <listener name="test_listener_1_updated" description="" persistent="false" state="test_state_1" event="updated"/>
162
+ <listener name="test_listener_1_deleted" description="" persistent="false" state="test_state_1" event="deleted"/>
163
+ <listener name="test_listener_2_inserted" description="" persistent="false" state="test_state_2" event="inserted"/>
164
+ <listener name="test_single_inserted" description="" persistent="false" state="dummy" event="inserted"/>
165
+ <listener name="test_single_updated" description="" persistent="false" state="dummy" event="updated"/>
166
+ <listener name="test_single_deleted" description="" persistent="false" state="dummy" event="deleted"/>
167
+ </listeners>
168
+ </app>
169
+ </apps>
170
+ </uts>
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "activerecord-runivedo"
7
- spec.version = "0.5.0"
7
+ spec.version = "0.5.1"
8
8
  spec.authors = ["Lucas Clemente"]
9
9
  spec.email = ["lucas@univedo.com"]
10
10
  spec.summary = "ActiveRecord adapter for Univedo"
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_dependency "runivedo", "~> 0.4.0"
20
- spec.add_dependency "activerecord", "~> 4.0"
20
+ spec.add_dependency "activerecord", "~> 4.2"
21
21
  spec.add_development_dependency 'minitest'
22
22
  spec.add_development_dependency 'minitest-emoji'
23
23
  spec.add_development_dependency "bundler"
@@ -5,6 +5,18 @@ require 'arel/visitors/bind_visitor'
5
5
  require 'runivedo'
6
6
 
7
7
  module ActiveRecord
8
+ module Type
9
+ class UUID < Type::Value
10
+ def type
11
+ :uuid
12
+ end
13
+
14
+ def type_cast_for_database(value)
15
+ value.to_s
16
+ end
17
+ end
18
+ end
19
+
8
20
  module ConnectionHandling # :nodoc:
9
21
  def runivedo_connection(config)
10
22
  raise ArgumentError, "No univedo url specified. Missing argument: server" unless config[:server]
@@ -21,19 +33,7 @@ module ActiveRecord
21
33
 
22
34
  module ConnectionAdapters #:nodoc:
23
35
  class RunivedoAdapter < AbstractAdapter
24
- attr_reader :session, :perspective, :url
25
-
26
- class Version
27
- include Comparable
28
-
29
- def initialize(version_string)
30
- @version = version_string.split('.').map { |v| v.to_i }
31
- end
32
-
33
- def <=>(version_string)
34
- @version <=> version_string.split('.').map { |v| v.to_i }
35
- end
36
- end
36
+ attr_reader :session, :perspective, :url, :bucket
37
37
 
38
38
  class BindSubstitution < Arel::Visitors::SQLite # :nodoc:
39
39
  include Arel::Visitors::BindVisitor
@@ -49,11 +49,9 @@ module ActiveRecord
49
49
  @username = username
50
50
  @result = nil
51
51
 
52
- if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
53
- @visitor = Arel::Visitors::SQLite.new self
54
- else
55
- @visitor = unprepared_visitor
56
- end
52
+ type_map.register_type 'uuid', Type::UUID.new
53
+
54
+ @visitor = Arel::Visitors::SQLite.new self
57
55
 
58
56
  connect
59
57
  end
@@ -100,7 +98,8 @@ module ActiveRecord
100
98
  :time => { :name => "time" },
101
99
  :date => { :name => "date" },
102
100
  :binary => { :name => "blob" },
103
- :boolean => { :name => "boolean" }
101
+ :boolean => { :name => "boolean" },
102
+ :uuid => { :name => "uuid" },
104
103
  }
105
104
  end
106
105
 
@@ -119,6 +118,9 @@ module ActiveRecord
119
118
 
120
119
  def exec_query(sql, name = nil, binds = [])
121
120
  log(sql, name, binds) do
121
+ if without_prepared_statement?(binds)
122
+ binds = []
123
+ end
122
124
  stmt = @connection.prepare(sql)
123
125
  cols = stmt.column_names
124
126
  i = -1
@@ -166,8 +168,8 @@ module ActiveRecord
166
168
  end
167
169
  alias :create :insert_sql
168
170
 
169
- def select_rows(sql, name = nil)
170
- exec_query(sql, name).rows
171
+ def select_rows(sql, name = nil, binds = [])
172
+ exec_query(sql, name, binds).rows
171
173
  end
172
174
 
173
175
  # SCHEMA STATEMENTS ========================================
@@ -181,16 +183,22 @@ module ActiveRecord
181
183
  end
182
184
 
183
185
  def columns(table_name)
184
- @perspective.get_fields_for_table(table_name).map do |name, datatype|
185
- datatype = "integer" if datatype == "pk"
186
- Column.new(name, nil, datatype)
186
+ @perspective.get_fields_for_table(table_name).map do |name, sql_type|
187
+ sql_type = "integer" if sql_type == "pk"
188
+ cast_type = lookup_cast_type(sql_type)
189
+ Column.new(name, nil, cast_type, sql_type)
187
190
  end
188
191
  end
189
192
 
190
193
  protected
191
194
 
192
- def select(sql, name = nil, binds = []) #:nodoc:
193
- exec_query(sql, name, binds)
195
+ def _type_cast(value)
196
+ case value
197
+ when UUIDTools::UUID
198
+ value.to_s
199
+ else
200
+ value
201
+ end
194
202
  end
195
203
  end
196
204
  end
data/test/setup_test.rb CHANGED
@@ -3,19 +3,31 @@ require "test_helper"
3
3
  ActiveRecord::Base.establish_connection(
4
4
  adapter: "runivedo",
5
5
  server: TEST_URL,
6
- bucket: "01a9e003-0783-475a-b698-485a5450a9d4",
7
- app: "6e5a3a08-9bb0-4d92-ad04-7c6fed3874fa",
6
+ bucket: UUIDTools::UUID.random_create.to_s,
7
+ app: "cefb4ed2-4ce3-4825-8550-b68a3c142f0a",
8
8
  username: "marvin",
9
+ uts: "Test Perspective.xml",
9
10
  )
10
11
 
11
- class Table < ActiveRecord::Base; end
12
+ class Dummy < ActiveRecord::Base
13
+ self.table_name = "dummy"
14
+
15
+ validates :dummy_uuid, uniqueness: true
16
+ end
12
17
 
13
18
  class SetupTest < MiniTest::Test
14
19
  def test_count
15
- assert Table.count > 10
20
+ assert Dummy.count >= 0
16
21
  end
17
22
 
18
23
  def test_queries
19
- assert_equal "tables", Table.where(id: 1).first.name
24
+ Dummy.create dummy_char: "foo"
25
+ assert_equal "foo", Dummy.all.last.dummy_char
26
+ end
27
+
28
+ def test_queries_uuid
29
+ uuid = UUIDTools::UUID.random_create
30
+ Dummy.create dummy_uuid: uuid
31
+ assert_equal uuid, Dummy.all.last.dummy_uuid
20
32
  end
21
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-runivedo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Clemente
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-09 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: runivedo
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.0'
33
+ version: '4.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.0'
40
+ version: '4.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -106,6 +106,7 @@ files:
106
106
  - LICENSE.txt
107
107
  - README.md
108
108
  - Rakefile
109
+ - Test Perspective.xml
109
110
  - activerecord-runivedo.gemspec
110
111
  - lib/active_record/connection_adapters/runivedo_adapter.rb
111
112
  - lib/activerecord-runivedo.rb