dbagile 0.0.1

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 (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/test/restful.spec ADDED
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'dbagile/restful/server'
3
+ require 'dbagile/restful/client'
4
+ dbagile_load_all_subspecs(__FILE__)
5
+
6
+ describe "DbAgile::Restful feature" do
7
+
8
+ let(:environment){ DbAgile::Fixtures::environment }
9
+ let(:database_name){ :sqlite }
10
+ let(:database) { environment.repository.database(database_name) }
11
+ let(:server) { DbAgile::Restful::Server.new(environment) }
12
+ let(:client) { DbAgile::Restful::Client.new(server.uri) }
13
+ before(:all) { server.start }
14
+ after(:all) { server.stop }
15
+
16
+ def basic_values_uri(extension = "")
17
+ "#{database_name}/basic_values#{extension}"
18
+ end
19
+
20
+ describe "the GET interface" do
21
+ it_should_behave_like "The Restful GET interface"
22
+ end
23
+
24
+ describe "the POST interface" do
25
+ it_should_behave_like "The Restful POST interface"
26
+ end
27
+
28
+ describe "the DELETE interface" do
29
+ it_should_behave_like "The Restful DELETE interface"
30
+ end
31
+
32
+ end
@@ -0,0 +1,51 @@
1
+ $silent = (ARGV[0] == "--silent")
2
+ begin
3
+ require 'rubygems'
4
+ require 'highline'
5
+ $highline = HighLine.new
6
+ rescue LoadError
7
+ puts "Better test suite summary with highline. Try 'gem install highline'"
8
+ end
9
+
10
+ # Say something
11
+ def color(message, color)
12
+ if $highline
13
+ $highline.color(message, color)
14
+ else
15
+ message
16
+ end
17
+ end
18
+
19
+ # Test suite in order
20
+ tests = [ :assumptions, :unit, :contract, :commands, :restful ]
21
+
22
+ # Will contain interesting lines
23
+ summary = []
24
+
25
+ # Let's go
26
+ tests.each do |kind|
27
+ file = File.expand_path("../#{kind}.spec", __FILE__)
28
+
29
+ puts "Running #{kind} (#{kind}.spec)"
30
+ summary << "\nSummary for #{kind}_test (#{kind}.spec)\n"
31
+
32
+ # Executes it in a subprocess
33
+ IO.popen("ruby #{file} 2>&1"){|io|
34
+ while l = io.gets
35
+ puts l unless $silent
36
+ unless l =~ /^\s*\.*\s*$|\(in /
37
+ if l =~ /0 failures/
38
+ summary << " " << color(l, :green)
39
+ elsif l =~ /failures/
40
+ summary << " " << color(l, :red)
41
+ elsif l =~ /Finished/
42
+ summary << " " << color(l, :blue)
43
+ else
44
+ summary << " " << l
45
+ end
46
+ end
47
+ end
48
+ }
49
+ end
50
+
51
+ puts summary.join("")
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../', __FILE__))
2
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
3
+
4
+ require 'dbagile'
5
+ require 'rubygems'
6
+ require 'fixtures'
7
+ require 'spec'
8
+ require 'spec/autorun'
9
+ require 'fileutils'
10
+
11
+ def dbagile_load_all_subfiles(requester_file, match)
12
+ Dir[File.expand_path("../#{match}", requester_file)].each{|f| load(f)}
13
+ end
14
+
15
+ def dbagile_load_all_subspecs(requester_file, name = File.basename(requester_file, ".spec"))
16
+ dbagile_load_all_subfiles(requester_file, "#{name}/**/*.spec")
17
+ end
18
+
19
+ def dbagile_install_examples(requester_file, requester)
20
+ match = "../#{File.basename(requester_file, '.spec')}/**/*.ex"
21
+ Dir[File.expand_path(match, requester_file)].each do |file|
22
+ requester.instance_eval File.read(file)
23
+ end
24
+ end
25
+
26
+ dbagile_load_all_subfiles(__FILE__, "support/*.rb")
@@ -0,0 +1,19 @@
1
+ Spec::Matchers.define :be_a_valid_json_string do
2
+ match do |actual|
3
+ begin
4
+ JSON::parse(actual)
5
+ true
6
+ rescue JSON::JSONError
7
+ false
8
+ end
9
+ end
10
+ failure_message_for_should do |actual|
11
+ "expected that #{actual.inspect} would be a valid JSON string"
12
+ end
13
+ failure_message_for_should_not do |actual|
14
+ "expected that #{actual.inspect} would not be a valid JSON string"
15
+ end
16
+ description do
17
+ "a valid JSON string"
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ Spec::Matchers.define :be_a_valid_yaml_string do
2
+ match do |actual|
3
+ begin
4
+ !YAML::load(actual).nil?
5
+ rescue StandardError
6
+ false
7
+ end
8
+ end
9
+ failure_message_for_should do |actual|
10
+ "expected that #{actual.inspect} would be a valid YAML string"
11
+ end
12
+ failure_message_for_should_not do |actual|
13
+ "expected that #{actual.inspect} would not be a valid YAML string"
14
+ end
15
+ description do
16
+ "a valid YAML string"
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../../fixtures', __FILE__)
2
+ describe "::DbAgile::Adapter.factor" do
3
+
4
+ let(:options){ Hash.new }
5
+ subject{ ::DbAgile::Adapter.factor(uri, options) }
6
+
7
+ describe "when called with sqlite scheme" do
8
+ let(:uri){ "sqlite://test.db" }
9
+ it{ should be_kind_of(::DbAgile::SequelAdapter) }
10
+ end
11
+
12
+
13
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../../../fixtures', __FILE__)
2
+ describe "::DbAgile::SequelAdapter.new" do
3
+
4
+ context "when called without options at all" do
5
+ subject{ DbAgile::SequelAdapter.new("sqlite://test.db") }
6
+ it{ should be_kind_of(DbAgile::SequelAdapter) }
7
+ end
8
+
9
+ context "when called without options but no tracing" do
10
+ subject{ DbAgile::SequelAdapter.new("sqlite://test.db", :trace_sql => false) }
11
+ it{ should be_kind_of(DbAgile::SequelAdapter) }
12
+ end
13
+
14
+ context "when called without options but no tracing" do
15
+ subject{ DbAgile::SequelAdapter.new("sqlite://test.db", :trace_sql => true) }
16
+ it{ should be_kind_of(DbAgile::SequelAdapter::SequelTracer) }
17
+ end
18
+
19
+ end
@@ -0,0 +1,12 @@
1
+ describe "::DbAgile::Command::API" do
2
+
3
+ let(:api){ ::DbAgile::Command::API.new(DbAgile::default_environment) }
4
+
5
+ it "should have instance methods for each command" do
6
+ ::DbAgile::Command::each_subclass do |subclass|
7
+ command_name = DbAgile::Command::ruby_method_for(subclass)
8
+ api.should respond_to(command_name)
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../../fixtures', __FILE__)
2
+ describe "::DbAgile::Command::command_for /" do
3
+
4
+ subject{ ::DbAgile::Command::command_for(arg, nil) }
5
+
6
+ describe "when called with a class" do
7
+ let(:arg){ ::DbAgile::Command::Db::List }
8
+ it{ should be_kind_of(::DbAgile::Command::Db::List) }
9
+ end
10
+
11
+ describe "when called with a string on a root command" do
12
+ let(:arg){ "help" }
13
+ it{ should be_kind_of(::DbAgile::Command::Help) }
14
+ end
15
+
16
+ describe "when called with a string on a non root command" do
17
+ let(:arg){ "sql:heading" }
18
+ it{ should be_kind_of(::DbAgile::Command::SQL::Heading) }
19
+ end
20
+
21
+ describe "when called with a symbol on a root command" do
22
+ let(:arg){ :help }
23
+ it{ should be_kind_of(::DbAgile::Command::Help) }
24
+ end
25
+
26
+ describe "when called with a symbol on a non root command" do
27
+ let(:arg){ :sql_heading }
28
+ it{ should be_kind_of(::DbAgile::Command::SQL::Heading) }
29
+ end
30
+
31
+ describe "when called with a symbol on a non root command" do
32
+ let(:arg){ :schema_sql_script }
33
+ it{ should be_kind_of(::DbAgile::Command::Schema::SqlScript) }
34
+ end
35
+
36
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../../fixtures', __FILE__)
2
+ describe "::DbAgile::Command::command_name_of /" do
3
+
4
+ subject{ ::DbAgile::Command::command_name_of(command) }
5
+
6
+ describe "when called on a root command" do
7
+ let(:command){ DbAgile::Command::Help }
8
+ it{ should == "help" }
9
+ end
10
+
11
+ describe "when called on a non root command" do
12
+ let(:command){ DbAgile::Command::SQL::Heading }
13
+ it{ should == "sql:heading" }
14
+ end
15
+
16
+ describe "when called on a complex name command" do
17
+ let(:command){ DbAgile::Command::Schema::SqlScript }
18
+ it{ should == "schema:sql-script" }
19
+ end
20
+
21
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../../fixtures', __FILE__)
2
+ describe "::DbAgile::Command::ruby_method_for /" do
3
+
4
+ subject{ ::DbAgile::Command::ruby_method_for(command) }
5
+
6
+ describe "when called on a root command" do
7
+ let(:command){ DbAgile::Command::Help }
8
+ it{ should == :help }
9
+ end
10
+
11
+ describe "when called on a non root command" do
12
+ let(:command){ DbAgile::Command::SQL::Heading }
13
+ it{ should == :sql_heading }
14
+ end
15
+
16
+ describe "when called on a complex name command" do
17
+ let(:command){ DbAgile::Command::Schema::SqlScript }
18
+ it{ should == :schema_sql_script }
19
+ end
20
+
21
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path('../../fixtures', __FILE__)
2
+ describe "command sanity /" do
3
+
4
+ DbAgile::Command::each_subclass{|cmd|
5
+ describe "#{cmd.command_name}" do
6
+
7
+ it "should have a summary" do
8
+ cmd.summary.should_not be_nil
9
+ cmd.summary.strip.should_not be_empty
10
+ end
11
+
12
+ it "should have a category" do
13
+ cmd.category.should_not be_nil
14
+ cmd.category.should be_kind_of(Symbol)
15
+ end
16
+
17
+ unless cmd.command_name == "dba"
18
+
19
+ it "should have a usage" do
20
+ cmd.usage.should =~ /^Usage: dba #{cmd.command_name}/
21
+ end
22
+
23
+ else
24
+
25
+ it "should have the description" do
26
+ cmd.description.should =~ /blambeau.github.com/
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ }
33
+
34
+ end
@@ -0,0 +1,23 @@
1
+ describe "::DbAgile::Contract::Utils::Delegate" do
2
+
3
+ describe "methods should correctly be installed" do
4
+ subject{ Object.new.extend(::DbAgile::Contract::Utils::Delegate) }
5
+ it{ should respond_to(:dataset) }
6
+ end
7
+
8
+ describe "method should pass parameters correctly" do
9
+ subject{
10
+ subject = Object.new.extend(::DbAgile::Contract::Utils::Delegate)
11
+ def subject.delegate
12
+ o = Object.new
13
+ def o.dataset(name)
14
+ "Hello #{name}"
15
+ end
16
+ o
17
+ end
18
+ subject
19
+ }
20
+ specify { subject.dataset(:world).should == "Hello world" }
21
+ end
22
+
23
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path('../../../fixtures', __FILE__)
2
+ describe "DbAgile::Core::Chain" do
3
+
4
+ context "When created with only one instance member" do
5
+ let(:chain){ DbAgile::Core::Chain.new(DbAgile::Fixtures::SayHello.new) }
6
+ specify{ chain.say_hello("dbagile").should == "dbagile" }
7
+ end
8
+
9
+ context "When created with only one class member" do
10
+ let(:chain){ DbAgile::Core::Chain.new(DbAgile::Fixtures::SayHello) }
11
+ specify{ chain.say_hello("dbagile").should == "dbagile" }
12
+ end
13
+
14
+ context "When created with only two members" do
15
+ let(:chain){ DbAgile::Core::Chain.new(DbAgile::Fixtures::Capitalize.new, DbAgile::Fixtures::SayHello.new) }
16
+ specify{ chain.say_hello("dbagile").should == "Dbagile" }
17
+ end
18
+
19
+ context "When creaed with two members as classes" do
20
+ let(:chain){ DbAgile::Core::Chain.new(DbAgile::Fixtures::Capitalize, DbAgile::Fixtures::SayHello) }
21
+ specify{ chain.say_hello("dbagile").should == "Dbagile" }
22
+ end
23
+
24
+ context "When created with two members with options as classes" do
25
+ let(:chain){ DbAgile::Core::Chain.new(DbAgile::Fixtures::Capitalize, :upcase, DbAgile::Fixtures::SayHello) }
26
+ specify{ chain.say_hello("dbagile").should == "DBAGILE" }
27
+ end
28
+
29
+ context "When created with two members through shortcut" do
30
+ let(:chain){ DbAgile::Core::Chain[DbAgile::Fixtures::Capitalize, :upcase, DbAgile::Fixtures::SayHello] }
31
+ specify{ chain.say_hello("dbagile").should == "DBAGILE" }
32
+ end
33
+
34
+ context "When plugged with only one instance member" do
35
+ let(:chain){ DbAgile::Core::Chain.new }
36
+ specify{
37
+ chain.plug(DbAgile::Fixtures::SayHello.new)
38
+ chain.say_hello("dbagile").should == "dbagile"
39
+ }
40
+ end
41
+
42
+ context "When plugged different way" do
43
+ let(:chain){ DbAgile::Core::Chain.new(DbAgile::Fixtures::SayHello) }
44
+ specify{
45
+ chain.plug(DbAgile::Fixtures::Capitalize, :upcase)
46
+ chain.say_hello("dbagile").should == "DBAGILE"
47
+ }
48
+ end
49
+
50
+ context "When blocks are used" do
51
+ let(:chain){ DbAgile::Core::Chain.new(DbAgile::Fixtures::SayHello.new) }
52
+ specify{
53
+ chain.del_to_block{ "hello" }.should == "hello"
54
+ }
55
+ end
56
+
57
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path('../../../fixtures', __FILE__)
2
+ describe "DbAgile::Core::Chain#connect" do
3
+
4
+ subject{ chain.connect(DbAgile::Fixtures::SayHello) }
5
+
6
+ context("when reverse then capitalize") do
7
+ let(:chain){ DbAgile::Core::Chain[DbAgile::Fixtures::Reverse, DbAgile::Fixtures::Capitalize] }
8
+ specify{
9
+ subject.should be_kind_of(DbAgile::Core::Chain)
10
+ subject.say_hello("dbagile").should == "Eligabd"
11
+ }
12
+ end
13
+
14
+ context("when capitalize then reverse") do
15
+ let(:chain){ DbAgile::Core::Chain[DbAgile::Fixtures::Capitalize, DbAgile::Fixtures::Reverse] }
16
+ specify{
17
+ subject.should be_kind_of(DbAgile::Core::Chain)
18
+ subject.say_hello("dbagile").should == "eligabD"
19
+ }
20
+ end
21
+
22
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../../../fixtures', __FILE__)
2
+ describe "DbAgile::Core::Chain#delegate_chain" do
3
+
4
+ subject{ chain.delegate_chain }
5
+
6
+ context "when called on an emtpy chain" do
7
+ let(:chain){ DbAgile::Core::Chain.new }
8
+ it{ should == [] }
9
+ end
10
+
11
+ context "when called on a non emtpy chain" do
12
+ let(:chain){ DbAgile::Core::Chain.new("hello") }
13
+ it{ should == ["hello"] }
14
+ end
15
+
16
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../../../fixtures', __FILE__)
2
+ describe "DbAgile::Core::Chain#initialize" do
3
+
4
+ context "when called with no args" do
5
+ let(:chain){ DbAgile::Core::Chain.new }
6
+ specify{ chain.delegate_chain.should == [] }
7
+ end
8
+
9
+ context "when called one argument" do
10
+ let(:chain){ DbAgile::Core::Chain.new("hello") }
11
+ specify{ chain.delegate_chain.should == ["hello"] }
12
+ end
13
+
14
+ context "when called many arguments" do
15
+ let(:chain){ DbAgile::Core::Chain.new("hello 1", "hello 2") }
16
+ specify{ chain.delegate_chain.should == ["hello 1", "hello 2"] }
17
+ end
18
+
19
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../../../fixtures', __FILE__)
2
+ describe "DbAgile::Core::Chain#plug" do
3
+
4
+ context "when called on an empty chain" do
5
+ let(:chain){ DbAgile::Core::Chain.new }
6
+ subject{ chain.plug("hello") }
7
+ specify{
8
+ subject.should == chain
9
+ chain.delegate_chain.should == ["hello"]
10
+ }
11
+ end
12
+
13
+ context "when called on a non empty chain" do
14
+ let(:chain){ DbAgile::Core::Chain.new("hello 1") }
15
+ subject{ chain.plug("hello 2") }
16
+ specify{
17
+ subject.should == chain
18
+ chain.delegate_chain.should == ["hello 2", "hello 1"]
19
+ }
20
+ end
21
+
22
+ context "when called with multiple arguments" do
23
+ let(:chain){ DbAgile::Core::Chain.new() }
24
+ subject{ chain.plug("hello 1", "hello 2") }
25
+ specify{
26
+ subject.should == chain
27
+ chain.delegate_chain.should == ["hello 1", "hello 2"]
28
+ }
29
+ end
30
+
31
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../../../fixtures', __FILE__)
2
+ describe "DbAgile::Core::IO::DSL's scope" do
3
+
4
+ it "should resolve File correctly" do
5
+ DbAgile::Core::IO::DSL.instance_eval{ File }.should == ::File
6
+ DbAgile::Core::IO::DSL.new.instance_eval{ File }.should == ::File
7
+ end
8
+
9
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../fixtures', __FILE__)
2
+ describe "DbAgile::Core::Repository::create! /" do
3
+
4
+ describe "on an unexisting folder" do
5
+ before{ FileUtils.rm_rf(path) }
6
+ after { FileUtils.rm_rf(path) }
7
+ let(:path){ DbAgile::Fixtures::Core::Repository::repository_path(:unexisting) }
8
+
9
+ it "should not raise any error" do
10
+ lambda{ DbAgile::Core::Repository::create!(path) }.should_not raise_error
11
+ end
12
+
13
+ it "should return a repository instance with correct version number" do
14
+ repo = DbAgile::Core::Repository::create!(path)
15
+ repo.should be_kind_of(DbAgile::Core::Repository)
16
+ repo.version.should == DbAgile::VERSION
17
+ end
18
+
19
+ it "should create a reloadable repository with correct version number" do
20
+ created = DbAgile::Core::Repository::create!(path)
21
+ created.send(:version=, "0.99.0")
22
+ created.save!
23
+ reloaded = DbAgile::Core::Repository::load(path)
24
+ reloaded.version.should == "0.99.0"
25
+ end
26
+
27
+ end
28
+
29
+
30
+
31
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../fixtures', __FILE__)
2
+ describe "DbAgile::Core::Repository#current?" do
3
+
4
+ let(:database){ DbAgile::Fixtures::Core::Repository::repository(:test_and_prod) }
5
+
6
+ describe("When called with an existing but not current database (name)") do
7
+ subject{ database.current?(:test) }
8
+ it{ should == false }
9
+ end
10
+
11
+ describe("When called with an existing and current database (name)") do
12
+ subject{ database.current?(:production) }
13
+ it{ should == true }
14
+ end
15
+
16
+ describe("When called with an existing but not current database (instance)") do
17
+ subject{ database.current?(database.database(:test)) }
18
+ it{ should == false }
19
+ end
20
+
21
+ describe("When called with an existing and current database (instance)") do
22
+ subject{ database.current?(database.database(:production)) }
23
+ it{ should == true }
24
+ end
25
+
26
+ describe("When called with an missing database (name)") do
27
+ subject{ database.current?(:nosuchone) }
28
+ it{ should be_nil }
29
+ end
30
+
31
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path('../fixtures', __FILE__)
2
+ describe "DbAgile::Core::Repository#database" do
3
+
4
+ let(:repository){ DbAgile::Fixtures::Core::Repository::repository(:test_and_prod) }
5
+
6
+ describe("When called with an unexisting database name") do
7
+ subject{ repository.database(:test) }
8
+ specify{
9
+ subject.should be_kind_of(::DbAgile::Core::Database)
10
+ subject.name.should == :test
11
+ subject.uri.should == "test.db"
12
+ }
13
+ end
14
+
15
+ describe("When called with an unexisting database instance") do
16
+ subject{ repository.database(repository.database(:test)) }
17
+ specify{
18
+ subject.should be_kind_of(::DbAgile::Core::Database)
19
+ subject.name.should == :test
20
+ subject.uri.should == "test.db"
21
+ }
22
+ end
23
+
24
+ describe("When called with a String for uri") do
25
+ subject{ repository.database("test.db") }
26
+ specify{
27
+ subject.should be_kind_of(::DbAgile::Core::Database)
28
+ subject.name.should == :test
29
+ subject.uri.should == "test.db"
30
+ }
31
+ end
32
+
33
+ describe("When called with a Regexp for uri") do
34
+ subject{ repository.database(/postgres/) }
35
+ specify{
36
+ subject.should be_kind_of(::DbAgile::Core::Database)
37
+ subject.name.should == :production
38
+ subject.uri.should == "postgres://postgres@localhost/test"
39
+ }
40
+ end
41
+
42
+ describe("When called with an missing database") do
43
+ subject{ repository.database(:nosuchone) }
44
+ it{ should be_nil }
45
+ end
46
+
47
+ end
@@ -0,0 +1,21 @@
1
+ ---
2
+ version: 0.0.1
3
+ databases:
4
+ production:
5
+ uri: postgres://postgres@localhost/test
6
+ announced_schema:
7
+ - schema.yaml
8
+ effective_schema:
9
+ - production.yaml
10
+ test:
11
+ uri: test.db
12
+ announced_schema:
13
+ - schema.yaml
14
+ effective_schema:
15
+ - effective.yaml
16
+ - unsupported.yaml
17
+ robust:
18
+ uri: robust.db
19
+ plugins:
20
+ - DbAgile::Contract::Robust::Optimistic
21
+ current: production
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../../../fixtures', __FILE__)
2
+ module DbAgile
3
+ module Fixtures
4
+ module Core
5
+ module Repository
6
+ include Fixtures::Utils
7
+
8
+ def repository_path(name_or_file)
9
+ find_file(name_or_file, __FILE__)
10
+ end
11
+
12
+ def each_repository_path(&block)
13
+ each_dir(__FILE__, &block)
14
+ end
15
+
16
+ # Returns a Schema instance for a given name
17
+ def repository(name_or_file)
18
+ DbAgile::Core::Repository::load(repository_path(name_or_file))
19
+ end
20
+
21
+ extend(Repository)
22
+ end
23
+ end # module Core
24
+ end # module Fixtures
25
+ end # module DbAgile