dbagile 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (305) hide show
  1. data/LICENCE.textile +12 -0
  2. data/README.textile +89 -0
  3. data/bin/dba +22 -0
  4. data/lib/dbagile/adapter/sequel/class_methods.rb +18 -0
  5. data/lib/dbagile/adapter/sequel/connection.rb +38 -0
  6. data/lib/dbagile/adapter/sequel/data/table_driven.rb +30 -0
  7. data/lib/dbagile/adapter/sequel/data/transaction_driven.rb +43 -0
  8. data/lib/dbagile/adapter/sequel/schema/concrete_script.rb +135 -0
  9. data/lib/dbagile/adapter/sequel/schema/physical_dump.rb +106 -0
  10. data/lib/dbagile/adapter/sequel/schema/schema2sequel_args.rb +71 -0
  11. data/lib/dbagile/adapter/sequel/schema/table_driven.rb +52 -0
  12. data/lib/dbagile/adapter/sequel/schema/transaction_driven.rb +46 -0
  13. data/lib/dbagile/adapter/sequel/sequel_tracer.rb +144 -0
  14. data/lib/dbagile/adapter/sequel.rb +46 -0
  15. data/lib/dbagile/adapter.rb +15 -0
  16. data/lib/dbagile/command/api.rb +49 -0
  17. data/lib/dbagile/command/bulk/commons.rb +130 -0
  18. data/lib/dbagile/command/bulk/export.rb +99 -0
  19. data/lib/dbagile/command/bulk/import.rb +147 -0
  20. data/lib/dbagile/command/bulk.rb +3 -0
  21. data/lib/dbagile/command/class_methods.rb +103 -0
  22. data/lib/dbagile/command/db/add.rb +94 -0
  23. data/lib/dbagile/command/db/list.rb +40 -0
  24. data/lib/dbagile/command/db/ping.rb +49 -0
  25. data/lib/dbagile/command/db/rm.rb +52 -0
  26. data/lib/dbagile/command/db/stage.rb +81 -0
  27. data/lib/dbagile/command/db/use.rb +48 -0
  28. data/lib/dbagile/command/db.rb +6 -0
  29. data/lib/dbagile/command/dba.rb +121 -0
  30. data/lib/dbagile/command/help.rb +50 -0
  31. data/lib/dbagile/command/repo/create.rb +54 -0
  32. data/lib/dbagile/command/repo.rb +1 -0
  33. data/lib/dbagile/command/robust.rb +86 -0
  34. data/lib/dbagile/command/schema/check.rb +59 -0
  35. data/lib/dbagile/command/schema/commons.rb +118 -0
  36. data/lib/dbagile/command/schema/diff.rb +101 -0
  37. data/lib/dbagile/command/schema/dump.rb +48 -0
  38. data/lib/dbagile/command/schema/merge.rb +55 -0
  39. data/lib/dbagile/command/schema/sql_script.rb +124 -0
  40. data/lib/dbagile/command/schema.rb +6 -0
  41. data/lib/dbagile/command/sql/drop.rb +40 -0
  42. data/lib/dbagile/command/sql/heading.rb +34 -0
  43. data/lib/dbagile/command/sql/send.rb +67 -0
  44. data/lib/dbagile/command/sql/show.rb +42 -0
  45. data/lib/dbagile/command/sql.rb +4 -0
  46. data/lib/dbagile/command/web/tools.rb +23 -0
  47. data/lib/dbagile/command/web.rb +1 -0
  48. data/lib/dbagile/command.rb +158 -0
  49. data/lib/dbagile/contract/connection.rb +66 -0
  50. data/lib/dbagile/contract/data/dataset.rb +69 -0
  51. data/lib/dbagile/contract/data/table_driven.rb +49 -0
  52. data/lib/dbagile/contract/data/transaction_driven.rb +74 -0
  53. data/lib/dbagile/contract/data.rb +3 -0
  54. data/lib/dbagile/contract/robust/helpers.rb +19 -0
  55. data/lib/dbagile/contract/robust/optimistic/data/table_driven.rb +31 -0
  56. data/lib/dbagile/contract/robust/optimistic/data/transaction_driven.rb +45 -0
  57. data/lib/dbagile/contract/robust/optimistic/schema/table_driven.rb +53 -0
  58. data/lib/dbagile/contract/robust/optimistic/schema/transaction_driven.rb +45 -0
  59. data/lib/dbagile/contract/robust/optimistic.rb +18 -0
  60. data/lib/dbagile/contract/robust.rb +20 -0
  61. data/lib/dbagile/contract/schema/table_driven.rb +89 -0
  62. data/lib/dbagile/contract/schema/transaction_driven.rb +68 -0
  63. data/lib/dbagile/contract/schema.rb +2 -0
  64. data/lib/dbagile/contract/utils/delegate.rb +17 -0
  65. data/lib/dbagile/contract/utils/full.rb +13 -0
  66. data/lib/dbagile/contract/utils.rb +2 -0
  67. data/lib/dbagile/contract.rb +5 -0
  68. data/lib/dbagile/core/chain.rb +92 -0
  69. data/lib/dbagile/core/connection.rb +51 -0
  70. data/lib/dbagile/core/database.rb +221 -0
  71. data/lib/dbagile/core/io/dsl.rb +95 -0
  72. data/lib/dbagile/core/io/robustness.rb +82 -0
  73. data/lib/dbagile/core/io.rb +2 -0
  74. data/lib/dbagile/core/repository/builder.rb +67 -0
  75. data/lib/dbagile/core/repository/yaml_methods.rb +82 -0
  76. data/lib/dbagile/core/repository.rb +211 -0
  77. data/lib/dbagile/core/schema/builder/coercion.rb +210 -0
  78. data/lib/dbagile/core/schema/builder/concept_factory.rb +61 -0
  79. data/lib/dbagile/core/schema/builder.rb +187 -0
  80. data/lib/dbagile/core/schema/composite.rb +239 -0
  81. data/lib/dbagile/core/schema/computations/filter.rb +40 -0
  82. data/lib/dbagile/core/schema/computations/merge.rb +55 -0
  83. data/lib/dbagile/core/schema/computations/minus.rb +44 -0
  84. data/lib/dbagile/core/schema/computations/split.rb +37 -0
  85. data/lib/dbagile/core/schema/computations.rb +4 -0
  86. data/lib/dbagile/core/schema/database_schema.rb +129 -0
  87. data/lib/dbagile/core/schema/errors.rb +173 -0
  88. data/lib/dbagile/core/schema/logical/attribute.rb +68 -0
  89. data/lib/dbagile/core/schema/logical/constraint/candidate_key.rb +70 -0
  90. data/lib/dbagile/core/schema/logical/constraint/foreign_key.rb +121 -0
  91. data/lib/dbagile/core/schema/logical/constraint.rb +58 -0
  92. data/lib/dbagile/core/schema/logical/constraints.rb +28 -0
  93. data/lib/dbagile/core/schema/logical/heading.rb +47 -0
  94. data/lib/dbagile/core/schema/logical/relvar.rb +81 -0
  95. data/lib/dbagile/core/schema/logical.rb +24 -0
  96. data/lib/dbagile/core/schema/migrate/abstract_script.rb +35 -0
  97. data/lib/dbagile/core/schema/migrate/collapse_table.rb +15 -0
  98. data/lib/dbagile/core/schema/migrate/create_table.rb +15 -0
  99. data/lib/dbagile/core/schema/migrate/drop_table.rb +15 -0
  100. data/lib/dbagile/core/schema/migrate/expand_table.rb +15 -0
  101. data/lib/dbagile/core/schema/migrate/operation.rb +141 -0
  102. data/lib/dbagile/core/schema/migrate/stager.rb +282 -0
  103. data/lib/dbagile/core/schema/migrate.rb +2 -0
  104. data/lib/dbagile/core/schema/part.rb +114 -0
  105. data/lib/dbagile/core/schema/physical/index.rb +64 -0
  106. data/lib/dbagile/core/schema/physical/indexes.rb +12 -0
  107. data/lib/dbagile/core/schema/physical.rb +26 -0
  108. data/lib/dbagile/core/schema/robustness.rb +39 -0
  109. data/lib/dbagile/core/schema/schema_object.rb +94 -0
  110. data/lib/dbagile/core/schema.rb +254 -0
  111. data/lib/dbagile/core/transaction.rb +74 -0
  112. data/lib/dbagile/core.rb +7 -0
  113. data/lib/dbagile/environment/buffering.rb +45 -0
  114. data/lib/dbagile/environment/delegator.rb +59 -0
  115. data/lib/dbagile/environment/interactions.rb +208 -0
  116. data/lib/dbagile/environment/on_error.rb +47 -0
  117. data/lib/dbagile/environment/repository.rb +161 -0
  118. data/lib/dbagile/environment/robustness.rb +7 -0
  119. data/lib/dbagile/environment/testing.rb +23 -0
  120. data/lib/dbagile/environment.rb +122 -0
  121. data/lib/dbagile/errors.rb +30 -0
  122. data/lib/dbagile/io/csv.rb +99 -0
  123. data/lib/dbagile/io/json.rb +41 -0
  124. data/lib/dbagile/io/pretty_table.rb +128 -0
  125. data/lib/dbagile/io/ruby.rb +62 -0
  126. data/lib/dbagile/io/text.rb +18 -0
  127. data/lib/dbagile/io/type_safe.rb +65 -0
  128. data/lib/dbagile/io/xml.rb +35 -0
  129. data/lib/dbagile/io/yaml.rb +30 -0
  130. data/lib/dbagile/io.rb +94 -0
  131. data/lib/dbagile/loader.rb +16 -0
  132. data/lib/dbagile/plugin.rb +29 -0
  133. data/lib/dbagile/restful/client/delete.rb +22 -0
  134. data/lib/dbagile/restful/client/get.rb +24 -0
  135. data/lib/dbagile/restful/client/post.rb +22 -0
  136. data/lib/dbagile/restful/client/utils.rb +16 -0
  137. data/lib/dbagile/restful/client.rb +41 -0
  138. data/lib/dbagile/restful/middleware/delete.rb +22 -0
  139. data/lib/dbagile/restful/middleware/get.rb +27 -0
  140. data/lib/dbagile/restful/middleware/one_database.rb +82 -0
  141. data/lib/dbagile/restful/middleware/post.rb +23 -0
  142. data/lib/dbagile/restful/middleware/utils.rb +65 -0
  143. data/lib/dbagile/restful/middleware.rb +54 -0
  144. data/lib/dbagile/restful/server.rb +65 -0
  145. data/lib/dbagile/restful.rb +9 -0
  146. data/lib/dbagile/robustness/dependencies.rb +36 -0
  147. data/lib/dbagile/robustness/file_system.rb +53 -0
  148. data/lib/dbagile/robustness.rb +14 -0
  149. data/lib/dbagile/tools/file_system.rb +24 -0
  150. data/lib/dbagile/tools/math.rb +11 -0
  151. data/lib/dbagile/tools/ordered_hash.rb +39 -0
  152. data/lib/dbagile/tools/ruby.rb +78 -0
  153. data/lib/dbagile/tools/string.rb +6 -0
  154. data/lib/dbagile/tools/tuple.rb +49 -0
  155. data/lib/dbagile/tools.rb +6 -0
  156. data/lib/dbagile.rb +66 -0
  157. data/test/assumptions/equality.spec +11 -0
  158. data/test/assumptions/fixtures.rb +39 -0
  159. data/test/assumptions/inheritance.spec +17 -0
  160. data/test/assumptions/sequel/autonumber.spec +19 -0
  161. data/test/assumptions/sequel/connect.spec +29 -0
  162. data/test/assumptions/sequel/test.db +0 -0
  163. data/test/assumptions/stdlib/pathname.spec +13 -0
  164. data/test/assumptions/yaml/fixtures.rb +25 -0
  165. data/test/assumptions/yaml/to_yaml.spec +10 -0
  166. data/test/assumptions.spec +2 -0
  167. data/test/commands/bulk/export.spec +100 -0
  168. data/test/commands/bulk/import.spec +49 -0
  169. data/test/commands/db/add.spec +31 -0
  170. data/test/commands/db/list.spec +29 -0
  171. data/test/commands/db/ping.spec +21 -0
  172. data/test/commands/db/rm.spec +18 -0
  173. data/test/commands/db/use.spec +18 -0
  174. data/test/commands/dba.spec +54 -0
  175. data/test/commands/repo/create.spec +30 -0
  176. data/test/commands/schema/check.spec +25 -0
  177. data/test/commands/schema/diff.spec +30 -0
  178. data/test/commands/schema/dump.spec +23 -0
  179. data/test/commands/schema/fixtures/add_constraint.yaml +30 -0
  180. data/test/commands/schema/fixtures/announced.yaml +28 -0
  181. data/test/commands/schema/fixtures/effective.yaml +20 -0
  182. data/test/commands/schema/fixtures/invalid.yaml +6 -0
  183. data/test/commands/schema/sql_script.spec +56 -0
  184. data/test/commands/sql/drop.spec +25 -0
  185. data/test/commands/sql/heading.spec +7 -0
  186. data/test/commands/sql/scripts/delete.sql +1 -0
  187. data/test/commands/sql/scripts/insert.sql +2 -0
  188. data/test/commands/sql/send.spec +29 -0
  189. data/test/commands/sql/show.spec +17 -0
  190. data/test/commands.spec +138 -0
  191. data/test/contract/connection/transaction.ex +11 -0
  192. data/test/contract/connection.spec +9 -0
  193. data/test/contract/data/dataset/columns.ex +5 -0
  194. data/test/contract/data/dataset/count.ex +5 -0
  195. data/test/contract/data/dataset.spec +9 -0
  196. data/test/contract/data/table_driven/dataset.ex +31 -0
  197. data/test/contract/data/table_driven/exists_q.ex +27 -0
  198. data/test/contract/data/table_driven.spec +9 -0
  199. data/test/contract/data/transaction_driven/delete.ex +29 -0
  200. data/test/contract/data/transaction_driven/direct_sql.ex +19 -0
  201. data/test/contract/data/transaction_driven/insert.ex +8 -0
  202. data/test/contract/data/transaction_driven/update.ex +19 -0
  203. data/test/contract/data/transaction_driven.spec +18 -0
  204. data/test/contract/robust/data/table_driven.spec +15 -0
  205. data/test/contract/robust/data/transaction_driven.spec +21 -0
  206. data/test/contract/robust/schema/table_driven.spec +21 -0
  207. data/test/contract/robust/schema/transaction_driven.spec +19 -0
  208. data/test/contract/schema/table_driven/column_names.ex +5 -0
  209. data/test/contract/schema/table_driven/has_column_q.ex +13 -0
  210. data/test/contract/schema/table_driven/has_table_q.ex +11 -0
  211. data/test/contract/schema/table_driven/heading.ex +5 -0
  212. data/test/contract/schema/table_driven.spec +9 -0
  213. data/test/contract/schema/transaction_driven/create_table.ex +10 -0
  214. data/test/contract/schema/transaction_driven/drop_table.ex +10 -0
  215. data/test/contract/schema/transaction_driven.spec +18 -0
  216. data/test/contract.spec +66 -0
  217. data/test/fixtures/basics/data/basic_values.rb +13 -0
  218. data/test/fixtures/basics/data/empty_table.rb +3 -0
  219. data/test/fixtures/basics/data/non_empty_table.rb +4 -0
  220. data/test/fixtures/basics/data/parts.rb +8 -0
  221. data/test/fixtures/basics/data/suppliers.rb +7 -0
  222. data/test/fixtures/basics/data/supplies.rb +14 -0
  223. data/test/fixtures/basics/dbagile.idx +20 -0
  224. data/test/fixtures/basics/fixtures.yaml +28 -0
  225. data/test/fixtures/basics/robust.db +0 -0
  226. data/test/fixtures/basics/suppliers.yaml +30 -0
  227. data/test/fixtures/basics/test.db +0 -0
  228. data/test/fixtures/empty/dbagile.idx +5 -0
  229. data/test/fixtures.rb +152 -0
  230. data/test/restful/delete/no_format.ex +32 -0
  231. data/test/restful/delete.spec +8 -0
  232. data/test/restful/get/csv_format.ex +12 -0
  233. data/test/restful/get/json_format.ex +19 -0
  234. data/test/restful/get/query_string.ex +11 -0
  235. data/test/restful/get/text_format.ex +12 -0
  236. data/test/restful/get/yaml_format.ex +14 -0
  237. data/test/restful/get.spec +5 -0
  238. data/test/restful/post/no_format.ex +22 -0
  239. data/test/restful/post.spec +8 -0
  240. data/test/restful.spec +32 -0
  241. data/test/run_all_suite.rb +51 -0
  242. data/test/spec_helper.rb +26 -0
  243. data/test/support/be_a_valid_json_string.rb +19 -0
  244. data/test/support/be_a_valid_yaml_string.rb +18 -0
  245. data/test/unit/adapter/factor.spec +13 -0
  246. data/test/unit/adapter/sequel/new.spec +19 -0
  247. data/test/unit/command/api.spec +12 -0
  248. data/test/unit/command/command_for.spec +36 -0
  249. data/test/unit/command/command_name_of.spec +21 -0
  250. data/test/unit/command/ruby_method_for.spec +21 -0
  251. data/test/unit/command/sanity.spec +34 -0
  252. data/test/unit/contract/utils/delegate/delegate.spec +23 -0
  253. data/test/unit/core/chain/chain.spec +57 -0
  254. data/test/unit/core/chain/connect.spec +22 -0
  255. data/test/unit/core/chain/delegate_chain.spec +16 -0
  256. data/test/unit/core/chain/initialize.spec +19 -0
  257. data/test/unit/core/chain/plug.spec +31 -0
  258. data/test/unit/core/io/dsl/scope.spec +9 -0
  259. data/test/unit/core/repository/create_bang.spec +31 -0
  260. data/test/unit/core/repository/current.spec +31 -0
  261. data/test/unit/core/repository/database.spec +47 -0
  262. data/test/unit/core/repository/fixtures/corrupted/dbagile.idx +1 -0
  263. data/test/unit/core/repository/fixtures/test_and_prod/dbagile.idx +21 -0
  264. data/test/unit/core/repository/fixtures.rb +25 -0
  265. data/test/unit/core/repository/has_database_q.spec +16 -0
  266. data/test/unit/core/repository/load.spec +51 -0
  267. data/test/unit/core/repository/to_yaml.spec +17 -0
  268. data/test/unit/core/schema/check.spec +32 -0
  269. data/test/unit/core/schema/empty_q.spec +18 -0
  270. data/test/unit/core/schema/filter.spec +42 -0
  271. data/test/unit/core/schema/fixtures/dbagile.yaml +7 -0
  272. data/test/unit/core/schema/fixtures/empty.yaml +11 -0
  273. data/test/unit/core/schema/fixtures/invalid.yaml +54 -0
  274. data/test/unit/core/schema/fixtures/left.yaml +46 -0
  275. data/test/unit/core/schema/fixtures/left_minus_right.yaml +31 -0
  276. data/test/unit/core/schema/fixtures/right.yaml +46 -0
  277. data/test/unit/core/schema/fixtures/right_minus_left.yaml +31 -0
  278. data/test/unit/core/schema/fixtures/suppliers_and_parts.yaml +30 -0
  279. data/test/unit/core/schema/fixtures.rb +32 -0
  280. data/test/unit/core/schema/merge.spec +72 -0
  281. data/test/unit/core/schema/minus.spec +26 -0
  282. data/test/unit/core/schema/sanity.spec +39 -0
  283. data/test/unit/core/schema/split.spec +58 -0
  284. data/test/unit/core/schema/stage_script.spec +26 -0
  285. data/test/unit/core/schema/to_yaml.spec +13 -0
  286. data/test/unit/core/schema/yaml_display.spec +14 -0
  287. data/test/unit/core/schema/yaml_load.spec +20 -0
  288. data/test/unit/core/transaction/transaction.spec +10 -0
  289. data/test/unit/fixtures.rb +67 -0
  290. data/test/unit/io/to_xxx.spec +52 -0
  291. data/test/unit/plugin/options.spec +21 -0
  292. data/test/unit/plugin/tuple_heading.spec +11 -0
  293. data/test/unit/plugin/with_options.spec +12 -0
  294. data/test/unit/tools/ruby/class_unqualified_name.spec +26 -0
  295. data/test/unit/tools/ruby/extract_file_rdoc.spec +10 -0
  296. data/test/unit/tools/ruby/fixtures/rdoc.txt +12 -0
  297. data/test/unit/tools/ruby/fixtures.rb +19 -0
  298. data/test/unit/tools/ruby/optional_args_block_call.spec +35 -0
  299. data/test/unit/tools/ruby/parent_module.spec +21 -0
  300. data/test/unit/tools/ruby/rdoc_file_paragraphs.spec +13 -0
  301. data/test/unit/tools/tuple/tuple_heading.spec +11 -0
  302. data/test/unit/tools/tuple/tuple_key.spec +27 -0
  303. data/test/unit/tools/tuple/tuple_project.spec +23 -0
  304. data/test/unit.spec +3 -0
  305. metadata +422 -0
data/lib/dbagile.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'dbagile/loader'
2
+ module DbAgile
3
+
4
+ # Version of the DbAgile interface
5
+ VERSION = "0.0.1".freeze
6
+
7
+ # Domains recognized as valid domains inside a SQL database
8
+ RECOGNIZED_DOMAINS = [
9
+ ::SByC::TypeSystem::Ruby::Boolean,
10
+ TrueClass, FalseClass,
11
+ String,
12
+ Fixnum, Bignum, Integer,
13
+ Float,
14
+ Time,
15
+ Date
16
+ ]
17
+
18
+ #
19
+ # Builds a DbAgile::Command::API instance and yields the block with the
20
+ # api instance.
21
+ #
22
+ # A fresh new default environement is created if no one is given.
23
+ #
24
+ # Example
25
+ # DbAgile::dba do |dba|
26
+ # # Override environment default values (~/.dbagile, ...)
27
+ # dba.repository_path = ... # your application own repository
28
+ # dba.output_buffer = ... # keep messages in any object supporting :<< (STDOUT by default)
29
+ #
30
+ # # Start using dbagile commands
31
+ # dba.bulk_export %w{--csv --type-safe contacts} # each line pushed in buffer
32
+ # dba.bulk_export %w{--ruby contacts} # each record pushed as a Hash in buffer
33
+ # end
34
+ #
35
+ def dba(environment = nil)
36
+ environment ||= default_environment
37
+ dba = DbAgile::Command::API.new(environment)
38
+ if block_given?
39
+ yield(dba)
40
+ else
41
+ dba
42
+ end
43
+ end
44
+ module_function :dba
45
+
46
+ #
47
+ # Builds a default environment instance.
48
+ #
49
+ # @see DbAgile::Core::Repository.default
50
+ #
51
+ def default_environment
52
+ DbAgile::Environment.default
53
+ end
54
+ module_function :default_environment
55
+
56
+ end # module DbAgile
57
+ require 'dbagile/robustness'
58
+ require 'dbagile/errors'
59
+ require 'dbagile/environment'
60
+ require 'dbagile/contract'
61
+ require 'dbagile/tools'
62
+ require 'dbagile/io'
63
+ require 'dbagile/core'
64
+ require 'dbagile/adapter'
65
+ require 'dbagile/plugin'
66
+ require 'dbagile/command'
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../fixtures.rb', __FILE__)
2
+ describe "The way comparison work" do
3
+
4
+ it "should not override ==" do
5
+ foo1 = DbAgile::Fixtures::Assumptions::FooComparable.new(1)
6
+ foo2 = DbAgile::Fixtures::Assumptions::FooComparable.new(1)
7
+ (foo1 <=> foo2).should == 0
8
+ (foo1 == foo2).should == false
9
+ end
10
+
11
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path('../../spec_helper.rb', __FILE__)
2
+ module DbAgile
3
+ module Fixtures
4
+ module Assumptions
5
+
6
+ module SafeModule
7
+
8
+ def safe_method
9
+ SafeModule
10
+ end
11
+
12
+ end
13
+
14
+ class UnsafeClass
15
+
16
+ def safe_method
17
+ UnsafeClass
18
+ end
19
+
20
+ include SafeModule
21
+ end
22
+
23
+ class FooComparable
24
+
25
+ attr_reader :int
26
+
27
+ def initialize(int)
28
+ @int = int
29
+ end
30
+
31
+ def <=>(other)
32
+ @int <=> other.int
33
+ end
34
+
35
+ end
36
+
37
+ end # module Assumptions
38
+ end # module Fixtures
39
+ end # module DbAgile
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../fixtures.rb', __FILE__)
2
+ describe "The way inheritance works with modules" do
3
+
4
+ let(:namespace){ DbAgile::Fixtures::Assumptions }
5
+ let(:safe_class){ namespace::UnsafeClass.new.extend(namespace::SafeModule) }
6
+
7
+ describe "The way modules are included" do
8
+ subject{ safe_class }
9
+ it{ should be_kind_of(namespace::SafeModule) }
10
+ end
11
+
12
+ describe "The way methods are overriden" do
13
+ subject{ safe_class.safe_method }
14
+ it { should == namespace::UnsafeClass }
15
+ end
16
+
17
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../../fixtures', __FILE__)
2
+ describe "auto number on sequel /" do
3
+
4
+ let(:db_file){ File.expand_path('../test.db', __FILE__) }
5
+ let(:db){ Sequel::connect("sqlite://#{db_file}") }
6
+ before{
7
+ if db.table_exists?(:test)
8
+ db.drop_table(:test)
9
+ end
10
+ }
11
+
12
+ it "should be supported at primary key time" do
13
+ db.create_table(:test){
14
+ column :id, :integer
15
+ primary_key :id, :auto_increment => true
16
+ }
17
+ end
18
+
19
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../../fixtures', __FILE__)
2
+ describe "Sequel::connect /" do
3
+
4
+ let(:uris){[
5
+ 'postgres://nosuchuser@localhost/nosuch_database',
6
+ 'sqlite://tmp/test.db',
7
+ 'mysql://nosuchuser@localhost/nosuch_database',
8
+ 'dbi-frontbase://nosuchuser@localhost/nosuch_database',
9
+ 'dbi-mysql://nosuchuser@localhost/nosuch_database',
10
+ 'dbi-oracle://nosuchuser@localhost/nosuch_database',
11
+ 'dbi-msql://nosuchuser@localhost/nosuch_database',
12
+ ]}
13
+
14
+ it "allows connecting and using SQL tools on unexisting databases" do
15
+ uris.each{|uri|
16
+ lambda{
17
+ db = Sequel::connect(uri)
18
+ gen = Sequel::Schema::Generator.new(db){
19
+ column :id, Integer
20
+ column :name, String
21
+ primary_key [:id]
22
+ }
23
+ res = db.send(:create_table_sql, :mytable, gen, {})
24
+ res.should =~ /CREATE TABLE/
25
+ }.should_not raise_error
26
+ }
27
+ end
28
+
29
+ end
Binary file
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../../fixtures.rb', __FILE__)
2
+ require 'pathname'
3
+ describe "Pathname utility" do
4
+
5
+ it "should be able to relativize files" do
6
+ child = Pathname.new(__FILE__)
7
+ parent = Pathname.new(File.dirname(File.dirname(__FILE__)))
8
+ rel = child.relative_path_from(parent)
9
+ rel.should be_relative
10
+ rel.to_s.should == "stdlib/pathname.spec"
11
+ end
12
+
13
+ end
@@ -0,0 +1,25 @@
1
+ require 'yaml'
2
+ require File.expand_path('../../fixtures', __FILE__)
3
+ module DbAgile
4
+ module Fixtures
5
+ class YAMLDumpable
6
+
7
+ attr_reader :name
8
+
9
+ def initialize(name)
10
+ @name = name
11
+ end
12
+
13
+ def to_yaml(opts = {})
14
+ YAML::quick_emit(self, opts) do |out|
15
+ out.map("tag:yaml.org,2002:map", :inline ) do |map|
16
+ map.add('class', self.class.to_s)
17
+ map.add('name', self.name)
18
+ end
19
+ end
20
+ { 'test' => true }.to_yaml(opts)
21
+ end
22
+
23
+ end # class YAMLDumpable
24
+ end # module Fixtures
25
+ end # module DbAgile
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../fixtures', __FILE__)
2
+ describe "to_yaml understanding /" do
3
+
4
+ describe "about user-defined to_yaml method" do
5
+ let(:dumpable){ DbAgile::Fixtures::YAMLDumpable.new("hello") }
6
+ subject{ lambda{ dumpable.to_yaml } }
7
+ it{ should_not raise_error }
8
+ end
9
+
10
+ end
@@ -0,0 +1,2 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ dbagile_load_all_subspecs(__FILE__)
@@ -0,0 +1,100 @@
1
+ shared_examples_for("The bulk:export command") do
2
+
3
+ it "should return the output buffer" do
4
+ dba.bulk_export(%w{suppliers}).should == dba.output_buffer
5
+ end
6
+
7
+ it "should support a --select option" do
8
+ dba.bulk_export(%w{--csv --select id,name basic_values})
9
+ dba.output_buffer.string.should =~ /^1,Standard values/
10
+ end
11
+
12
+ it "should support a --allbut option" do
13
+ dba.bulk_export(%w{--csv --allbut name basic_values})
14
+ dba.output_buffer.string.should_not =~ /Standard values/
15
+ end
16
+
17
+ ### --csv
18
+
19
+ describe "When used with --csv option" do
20
+
21
+ it "should support a --headers option" do
22
+ dba.bulk_export(%w{--csv --headers --select id,name basic_values})
23
+ dba.output_buffer.string.should =~ /^id,name/
24
+ end
25
+
26
+ it "should support a --seperator option" do
27
+ dba.bulk_export(%w{--csv --separator=; --select id,name basic_values})
28
+ dba.output_buffer.string.should =~ /^1;Standard values/
29
+ end
30
+
31
+ it "should support --force-quotes --quote options" do
32
+ dba.bulk_export(%w{--csv --quote=' --force-quotes --select id,name basic_values})
33
+ dba.output_buffer.string.strip.should == "'1','Standard values'"
34
+ end
35
+
36
+ end
37
+
38
+ ### --json
39
+
40
+ describe "When used with --json option" do
41
+
42
+ it "should return a valid JSON string" do
43
+ result = dba.bulk_export(%w{--json basic_values}).string
44
+ result.should be_a_valid_json_string
45
+ back_tuple = JSON::parse(result)[0]
46
+ DbAgile::Fixtures::basic_values[0].each_pair{|k,v|
47
+ next if v.kind_of?(Time) or v.kind_of?(Date) # not supported by json
48
+ back_tuple[k.to_s].should == v
49
+ }
50
+ end
51
+
52
+ it "should support a --no-pretty option" do
53
+ result = dba.bulk_export(%w{--json --no-pretty --select id,name basic_values}).string
54
+ result.strip.should_not =~ /\n/
55
+ result.should be_a_valid_json_string
56
+ end
57
+
58
+ it "should support a --pretty option" do
59
+ result = dba.bulk_export(%w{--json --pretty --select id,name basic_values}).string
60
+ result.strip.should =~ /\n/
61
+ result.should be_a_valid_json_string
62
+ end
63
+
64
+ it "should support a --type-sage option" do
65
+ result = dba.bulk_export(%w{--json --type-safe basic_values}).string
66
+ result.should be_a_valid_json_string
67
+ end
68
+
69
+ end
70
+
71
+ ### --yaml
72
+
73
+ describe "When used with --yaml option" do
74
+
75
+ it "should return yaml valid string" do
76
+ result = dba.bulk_export(%w{--yaml basic_values}).string
77
+ result.should be_a_valid_yaml_string
78
+ YAML::load(result).should == DbAgile::Fixtures::basic_values
79
+ end
80
+
81
+ it "should return yaml valid string with --type-safe" do
82
+ result = dba.bulk_export(%w{--yaml --type-safe basic_values}).string
83
+ result.should be_a_valid_yaml_string
84
+ end
85
+
86
+ end
87
+
88
+ ### --ruby
89
+
90
+ describe "When used with --ruby option" do
91
+
92
+ it "should support a valid ruby string" do
93
+ dba.bulk_export %w{--ruby basic_values}
94
+ back = Kernel.eval(dba.output_buffer.string)
95
+ back.should == DbAgile::Fixtures::basic_values
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -0,0 +1,49 @@
1
+ shared_examples_for("The bulk:import command") do
2
+
3
+ # --ruby
4
+
5
+ describe "When used with a --ruby option" do
6
+
7
+ it "should work on input buffer by default" do
8
+ File.open(DbAgile::Fixtures::basic_values_path, "r"){|io|
9
+ dba.input_buffer = io
10
+ dba.bulk_import %w{--ruby --drop-table basic_values_copy}
11
+ dba.sql_send "UPDATE basic_values_copy SET ruby_nil = null"
12
+ }
13
+ dba.dataset(:basic_values_copy).to_a.should == DbAgile::Fixtures::basic_values
14
+ end
15
+
16
+ it "should accept a --input option" do
17
+ dba.bulk_import ['--input', DbAgile::Fixtures::basic_values_path] + %w{--ruby --drop-table basic_values_copy}
18
+ dba.sql_send "UPDATE basic_values_copy SET ruby_nil = null"
19
+ dba.dataset(:basic_values_copy).to_a.should == DbAgile::Fixtures::basic_values
20
+ end
21
+
22
+ it "should support an export/import piping through StringIO" do
23
+ dba.bulk_export %w{--ruby basic_values}
24
+ dba.input_buffer = StringIO.new(dba.output_buffer.string)
25
+ dba.output_buffer = StringIO.new
26
+ dba.bulk_import %w{--ruby --create-table basic_values_copy}
27
+ dba.dataset(:basic_values_copy).to_a.should == DbAgile::Fixtures::basic_values
28
+ end
29
+
30
+ end # --ruby
31
+
32
+ # --format=x --type-safe
33
+ [:csv, :json, :yaml, :ruby].each do |format|
34
+
35
+ describe "When piping import/export with --type-safe in #{format}" do
36
+
37
+ it "should be type safe" do
38
+ dba.bulk_export "--format", format, "--type-safe", "basic_values"
39
+ dba.input_buffer = StringIO.new(dba.output_buffer.string)
40
+ dba.output_buffer = StringIO.new
41
+ dba.bulk_import "--drop-table", "--format", format, "--type-safe", "basic_values_copy"
42
+ dba.dataset(:basic_values_copy).to_a.should == DbAgile::Fixtures::basic_values
43
+ end
44
+
45
+ end
46
+
47
+ end # --format=x --type-safe
48
+
49
+ end
@@ -0,0 +1,31 @@
1
+ shared_examples_for("The db:add command") do
2
+
3
+ it "should return the new database" do
4
+ dba.db_add(%w{test test.db}).should be_kind_of(DbAgile::Core::Database)
5
+ end
6
+
7
+ it "should accept an absolute database" do
8
+ dba.db_add(%w{test postgres://dbagile@localhost/unexisting}).should be_kind_of(DbAgile::Core::Database)
9
+ end
10
+
11
+ it "should raise an error when the name is already in use" do
12
+ dba.db_add(%w{test test.db})
13
+ lambda{ dba.db_add(%w{test test.db}) }.should raise_error(DbAgile::DatabaseNameConflictError)
14
+ end
15
+
16
+ it "should save the repository" do
17
+ dba.db_add(%w{test test.db})
18
+ dba.dup.repository.has_database?(:test).should be_true
19
+ end
20
+
21
+ it "should set the database as the current one by default" do
22
+ dba.db_add(%w{test test.db})
23
+ dba.dup.repository.current?(:test).should be_true
24
+ end
25
+
26
+ it "should not set the database as the current one with --no-current" do
27
+ dba.db_add(%w{--no-current test test.db})
28
+ dba.dup.repository.current?(:test).should be_false
29
+ end
30
+
31
+ end
@@ -0,0 +1,29 @@
1
+ shared_examples_for("The db:list command") do
2
+
3
+ describe "/ on a non empty repository /" do
4
+
5
+ it "should return the repository instance" do
6
+ dba.db_list.should be_kind_of(DbAgile::Core::Repository)
7
+ end
8
+
9
+ it "should print the databases" do
10
+ dba.output_buffer = StringIO.new
11
+ dba.db_list
12
+ dba.output_buffer.string.should =~ /Available databases/
13
+ end
14
+
15
+ end
16
+
17
+ describe "/ on an empty repository /" do
18
+
19
+ before{ dba.repository_path = DbAgile::Fixtures::ensure_empty_repository! }
20
+
21
+ it "should print a friendly error message when no database" do
22
+ dba.message_buffer = StringIO.new
23
+ dba.db_list
24
+ dba.message_buffer.string.should =~ /No database found/
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,21 @@
1
+ shared_examples_for("The db:ping command") do
2
+
3
+ it "should return the pinged database" do
4
+ dba.db_ping(%w{sqlite}).should be_kind_of(::DbAgile::Core::Database)
5
+ end
6
+
7
+ it "should return the error if ping failed" do
8
+ dba.db_ping(%w{unexisting}).should be_kind_of(StandardError)
9
+ end
10
+
11
+ it "should print a friendly message on success" do
12
+ dba.db_ping(%w{sqlite})
13
+ dba.output_buffer.string.should =~ /ok/
14
+ end
15
+
16
+ it "should print a friendly message on failure" do
17
+ dba.db_ping(%w{unexisting})
18
+ dba.output_buffer.string.should =~ /KO/
19
+ end
20
+
21
+ end
@@ -0,0 +1,18 @@
1
+ shared_examples_for("The db:rm command") do
2
+
3
+ it "should return the repository" do
4
+ dba.db_add(%w{test test.db})
5
+ dba.db_rm(%w{test}).should be_kind_of(::DbAgile::Core::Repository)
6
+ end
7
+
8
+ it "should raise an error when the name is unknown" do
9
+ lambda{ dba.db_rm(%w{test}) }.should raise_error(DbAgile::NoSuchDatabaseError)
10
+ end
11
+
12
+ it "should save the repository" do
13
+ dba.db_add(%w{test test.db})
14
+ dba.db_rm(%w{test})
15
+ dba.dup.repository.has_database?(:test).should be_false
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ shared_examples_for("The db:use command") do
2
+
3
+ it "should return the current database" do
4
+ dba.db_add(%w{test test.db})
5
+ dba.db_use(%w{test}).should be_kind_of(::DbAgile::Core::Database)
6
+ end
7
+
8
+ it "should raise an error if the database is unknown" do
9
+ lambda{ dba.db_use(%w{test}) }.should raise_error(DbAgile::NoSuchDatabaseError)
10
+ end
11
+
12
+ it "should save the repository" do
13
+ dba.db_add(%w{--no-current test test.db})
14
+ dba.db_use(%w{test})
15
+ dba.dup.repository.current?(:test).should be_true
16
+ end
17
+
18
+ end
@@ -0,0 +1,54 @@
1
+ shared_examples_for("The dba command") do
2
+
3
+ let(:env){ DbAgile::default_environment.with_testing_methods! }
4
+ let(:dba){ DbAgile::Command::Dba.new(env) }
5
+ subject{ dba.run(__FILE__, args); env }
6
+
7
+ describe "when called on an existing repository /" do
8
+
9
+ before{ env.repository_path = DbAgile::Fixtures::repository_path(:basics) }
10
+
11
+ describe "with no args" do
12
+ let(:args){ [] }
13
+ it{ should have_flushed(/Usage:/) }
14
+ end
15
+
16
+ describe "with --help" do
17
+ let(:args){ ['--help'] }
18
+ it{ should have_flushed(/Usage:/) }
19
+ end
20
+
21
+ describe "with --version" do
22
+ let(:args){ ['--version'] }
23
+ it{ should have_flushed(/(c)/) }
24
+ end
25
+
26
+ describe "with --interactive" do
27
+ let(:args){ ['--interactive'] }
28
+ it{ should be_interactive }
29
+ end
30
+
31
+ describe "with --no-interactive" do
32
+ let(:args){ ['--no-interactive'] }
33
+ it{ should_not be_interactive }
34
+ end
35
+
36
+ describe "with --backtrace" do
37
+ let(:args){ ['--backtrace'] }
38
+ it{ should be_show_backtrace }
39
+ end
40
+
41
+ describe "with --no-backtrace" do
42
+ let(:args){ ['--no-backtrace'] }
43
+ it{ should_not be_show_backtrace }
44
+ end
45
+
46
+ describe "with help" do
47
+ let(:args){ ['help', 'help'] }
48
+ it{ should have_flushed(/Usage:/) }
49
+ it{ should have_flushed(/Description:/) }
50
+ end
51
+
52
+ end # on an existing repository
53
+
54
+ end
@@ -0,0 +1,30 @@
1
+ shared_examples_for("The repo:create command") do
2
+
3
+ let(:empty_path){ DbAgile::Fixtures::repository_path(:empty) }
4
+
5
+ describe "when the repository already exists" do
6
+
7
+ before { dba.repository_path = DbAgile::Fixtures::ensure_empty_repository! }
8
+
9
+ it "should raise an error without --force" do
10
+ lambda{ dba.repo_create [ dba.repository_path ] }.should raise_error(IOError)
11
+ end
12
+
13
+ it "should not raise an error with --force" do
14
+ lambda{ dba.repo_create [ "--force", dba.repository_path ] }.should_not raise_error(IOError)
15
+ end
16
+
17
+ end
18
+
19
+ describe "when the repository does not exist" do
20
+
21
+ before { FileUtils.rm_rf(empty_path) }
22
+
23
+ it "should create the repo without --force" do
24
+ dba.repo_create [ dba.repository_path ]
25
+ dba.repository.should be_kind_of(DbAgile::Core::Repository)
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,25 @@
1
+ shared_examples_for("The schema:check command") do
2
+
3
+ describe "when the shema is valid" do
4
+
5
+ it "should return a Schema and Errors" do
6
+ schema, errors = dba.schema_check
7
+ schema.should be_kind_of(DbAgile::Core::Schema::DatabaseSchema)
8
+ errors.should be_kind_of(DbAgile::SchemaSemanticsError)
9
+ errors.should be_empty
10
+ end
11
+
12
+ end
13
+
14
+ describe "when the shema is invalid" do
15
+
16
+ it "should return a Schema and Errors" do
17
+ schema, errors = dba.schema_check [ File.expand_path('../fixtures/invalid.yaml', __FILE__) ]
18
+ schema.should be_kind_of(DbAgile::Core::Schema::DatabaseSchema)
19
+ errors.should be_kind_of(DbAgile::SchemaSemanticsError)
20
+ errors.should_not be_empty
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,30 @@
1
+ shared_examples_for("The schema:diff command") do
2
+
3
+ let(:invalid){ File.expand_path('../fixtures/invalid.yaml', __FILE__) }
4
+ let(:announced){ File.expand_path('../fixtures/announced.yaml', __FILE__) }
5
+ let(:effective){ File.expand_path('../fixtures/effective.yaml', __FILE__) }
6
+
7
+ it "should return merged schema" do
8
+ dba.message_buffer = StringIO.new
9
+ dba.schema_diff([announced, effective]).should be_kind_of(DbAgile::Core::Schema::DatabaseSchema)
10
+ end
11
+
12
+ it "should show all differences without -u" do
13
+ dba.message_buffer = StringIO.new
14
+ dba.schema_diff([effective, announced]).should be_kind_of(DbAgile::Core::Schema::DatabaseSchema)
15
+ s = dba.message_buffer.string
16
+ s.should =~ /PARTS/
17
+ s.should =~ /SUPPLIERS/
18
+ s.should =~ /SUPPLIES/
19
+ end
20
+
21
+ it "should not show all differences with -u" do
22
+ dba.message_buffer = StringIO.new
23
+ dba.schema_diff(['-u', effective, announced]).should be_kind_of(DbAgile::Core::Schema::DatabaseSchema)
24
+ s = dba.message_buffer.string
25
+ s.should =~ /SUPPLIES/
26
+ s.should_not =~ /SUPPLIERS/
27
+ s.should_not =~ /PARTS/
28
+ end
29
+
30
+ end