coupler 0.0.1-java

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 (258) hide show
  1. data/.document +5 -0
  2. data/.gitmodules +3 -0
  3. data/.rvmrc +1 -0
  4. data/.vimrc +40 -0
  5. data/Gemfile +27 -0
  6. data/Gemfile.lock +71 -0
  7. data/LICENSE +20 -0
  8. data/NOTES +6 -0
  9. data/README.rdoc +18 -0
  10. data/Rakefile +42 -0
  11. data/TODO +11 -0
  12. data/VERSION +1 -0
  13. data/bin/coupler +7 -0
  14. data/db/.gitignore +6 -0
  15. data/db/migrate/001_initial_schema.rb +166 -0
  16. data/db/migrate/002_stub.rb +4 -0
  17. data/db/migrate/003_stub.rb +4 -0
  18. data/db/migrate/004_create_comparisons.rb +28 -0
  19. data/db/migrate/005_move_database_name.rb +19 -0
  20. data/db/migrate/006_upgrade_comparisons.rb +34 -0
  21. data/db/migrate/007_add_which_to_comparisons.rb +23 -0
  22. data/db/migrate/008_add_result_field_to_transformations.rb +33 -0
  23. data/db/migrate/009_add_generated_flag_to_fields.rb +13 -0
  24. data/db/migrate/010_create_imports.rb +24 -0
  25. data/db/migrate/011_add_primary_key_type.rb +13 -0
  26. data/db/migrate/012_add_transformed_with_to_resources.rb +13 -0
  27. data/db/migrate/013_add_run_count_to_scenarios.rb +13 -0
  28. data/db/migrate/014_add_last_accessed_at_to_some_tables.rb +13 -0
  29. data/db/migrate/015_add_run_number_to_results.rb +15 -0
  30. data/db/migrate/016_fix_scenario_run_count.rb +27 -0
  31. data/db/migrate/017_rename_comparison_columns.rb +14 -0
  32. data/db/migrate/018_fix_scenario_linkage_type.rb +8 -0
  33. data/db/migrate/019_add_columns_to_imports.rb +24 -0
  34. data/db/migrate/020_rename_import_columns.rb +12 -0
  35. data/db/migrate/021_add_fields_to_connections.rb +15 -0
  36. data/db/migrate/022_remove_database_name_from_resources.rb +11 -0
  37. data/features/connections.feature +28 -0
  38. data/features/matchers.feature +35 -0
  39. data/features/projects.feature +11 -0
  40. data/features/resources.feature +62 -0
  41. data/features/scenarios.feature +45 -0
  42. data/features/step_definitions/coupler_steps.rb +145 -0
  43. data/features/step_definitions/matchers_steps.rb +26 -0
  44. data/features/step_definitions/resources_steps.rb +12 -0
  45. data/features/step_definitions/scenarios_steps.rb +7 -0
  46. data/features/step_definitions/transformations_steps.rb +3 -0
  47. data/features/support/env.rb +128 -0
  48. data/features/transformations.feature +22 -0
  49. data/features/wizard.feature +10 -0
  50. data/gfx/coupler-header.svg +213 -0
  51. data/gfx/coupler-sidebar.svg +656 -0
  52. data/gfx/coupler.svg +184 -0
  53. data/gfx/icon.svg +75 -0
  54. data/lib/coupler/base.rb +63 -0
  55. data/lib/coupler/config.rb +128 -0
  56. data/lib/coupler/data_uploader.rb +20 -0
  57. data/lib/coupler/database.rb +31 -0
  58. data/lib/coupler/extensions/connections.rb +57 -0
  59. data/lib/coupler/extensions/exceptions.rb +58 -0
  60. data/lib/coupler/extensions/imports.rb +43 -0
  61. data/lib/coupler/extensions/jobs.rb +21 -0
  62. data/lib/coupler/extensions/matchers.rb +64 -0
  63. data/lib/coupler/extensions/projects.rb +62 -0
  64. data/lib/coupler/extensions/resources.rb +89 -0
  65. data/lib/coupler/extensions/results.rb +100 -0
  66. data/lib/coupler/extensions/scenarios.rb +50 -0
  67. data/lib/coupler/extensions/transformations.rb +70 -0
  68. data/lib/coupler/extensions/transformers.rb +58 -0
  69. data/lib/coupler/extensions.rb +16 -0
  70. data/lib/coupler/helpers.rb +121 -0
  71. data/lib/coupler/import_buffer.rb +48 -0
  72. data/lib/coupler/logger.rb +16 -0
  73. data/lib/coupler/models/common_model.rb +104 -0
  74. data/lib/coupler/models/comparison.rb +166 -0
  75. data/lib/coupler/models/connection.rb +59 -0
  76. data/lib/coupler/models/field.rb +55 -0
  77. data/lib/coupler/models/import.rb +238 -0
  78. data/lib/coupler/models/job.rb +42 -0
  79. data/lib/coupler/models/jobify.rb +17 -0
  80. data/lib/coupler/models/matcher.rb +36 -0
  81. data/lib/coupler/models/project.rb +40 -0
  82. data/lib/coupler/models/resource.rb +287 -0
  83. data/lib/coupler/models/result.rb +92 -0
  84. data/lib/coupler/models/scenario/runner.rb +357 -0
  85. data/lib/coupler/models/scenario.rb +115 -0
  86. data/lib/coupler/models/transformation.rb +117 -0
  87. data/lib/coupler/models/transformer/runner.rb +28 -0
  88. data/lib/coupler/models/transformer.rb +110 -0
  89. data/lib/coupler/models.rb +30 -0
  90. data/lib/coupler/runner.rb +76 -0
  91. data/lib/coupler/scheduler.rb +56 -0
  92. data/lib/coupler.rb +34 -0
  93. data/log/.gitignore +1 -0
  94. data/misc/README +5 -0
  95. data/misc/jruby-json.license +57 -0
  96. data/misc/rack-flash.license +22 -0
  97. data/script/dbconsole.rb +5 -0
  98. data/src/edu/vanderbilt/coupler/Main.java +116 -0
  99. data/src/edu/vanderbilt/coupler/jruby.properties +1 -0
  100. data/tasks/annotations.rake +84 -0
  101. data/tasks/db.rake +120 -0
  102. data/tasks/environment.rake +12 -0
  103. data/tasks/jeweler.rake +43 -0
  104. data/tasks/package.rake +58 -0
  105. data/tasks/rdoc.rake +13 -0
  106. data/tasks/test.rake +63 -0
  107. data/tasks/vendor.rake +43 -0
  108. data/test/README.txt +6 -0
  109. data/test/config.yml +9 -0
  110. data/test/coupler/models/test_import.rb +221 -0
  111. data/test/factories.rb +91 -0
  112. data/test/fixtures/duplicate-keys.csv +5 -0
  113. data/test/fixtures/no-headers.csv +50 -0
  114. data/test/fixtures/people.csv +51 -0
  115. data/test/fixtures/varying-row-size.csv +4 -0
  116. data/test/helper.rb +156 -0
  117. data/test/integration/extensions/test_connections.rb +80 -0
  118. data/test/integration/extensions/test_imports.rb +94 -0
  119. data/test/integration/extensions/test_jobs.rb +52 -0
  120. data/test/integration/extensions/test_matchers.rb +134 -0
  121. data/test/integration/extensions/test_projects.rb +82 -0
  122. data/test/integration/extensions/test_resources.rb +150 -0
  123. data/test/integration/extensions/test_results.rb +89 -0
  124. data/test/integration/extensions/test_scenarios.rb +88 -0
  125. data/test/integration/extensions/test_transformations.rb +113 -0
  126. data/test/integration/extensions/test_transformers.rb +80 -0
  127. data/test/integration/test_field.rb +45 -0
  128. data/test/integration/test_import.rb +78 -0
  129. data/test/integration/test_running_scenarios.rb +379 -0
  130. data/test/integration/test_transformation.rb +56 -0
  131. data/test/integration/test_transforming.rb +154 -0
  132. data/test/table_sets.rb +76 -0
  133. data/test/unit/models/test_common_model.rb +130 -0
  134. data/test/unit/models/test_comparison.rb +619 -0
  135. data/test/unit/models/test_connection.rb +115 -0
  136. data/test/unit/models/test_field.rb +99 -0
  137. data/test/unit/models/test_import.rb +130 -0
  138. data/test/unit/models/test_job.rb +115 -0
  139. data/test/unit/models/test_matcher.rb +82 -0
  140. data/test/unit/models/test_project.rb +102 -0
  141. data/test/unit/models/test_resource.rb +564 -0
  142. data/test/unit/models/test_result.rb +90 -0
  143. data/test/unit/models/test_scenario.rb +199 -0
  144. data/test/unit/models/test_transformation.rb +193 -0
  145. data/test/unit/models/test_transformer.rb +188 -0
  146. data/test/unit/test_base.rb +60 -0
  147. data/test/unit/test_data_uploader.rb +27 -0
  148. data/test/unit/test_database.rb +23 -0
  149. data/test/unit/test_helpers.rb +58 -0
  150. data/test/unit/test_logger.rb +10 -0
  151. data/test/unit/test_models.rb +12 -0
  152. data/test/unit/test_runner.rb +76 -0
  153. data/test/unit/test_scheduler.rb +66 -0
  154. data/uploads/.gitignore +2 -0
  155. data/vendor/java/.gitignore +5 -0
  156. data/webroot/public/css/960.css +1 -0
  157. data/webroot/public/css/dataTables.css +1057 -0
  158. data/webroot/public/css/jquery-ui.css +572 -0
  159. data/webroot/public/css/jquery.treeview.css +68 -0
  160. data/webroot/public/css/reset.css +1 -0
  161. data/webroot/public/css/style.css +504 -0
  162. data/webroot/public/css/text.css +1 -0
  163. data/webroot/public/favicon.ico +0 -0
  164. data/webroot/public/images/12_col.gif +0 -0
  165. data/webroot/public/images/16_col.gif +0 -0
  166. data/webroot/public/images/add.png +0 -0
  167. data/webroot/public/images/ajax-loader.gif +0 -0
  168. data/webroot/public/images/cog.png +0 -0
  169. data/webroot/public/images/coupler.png +0 -0
  170. data/webroot/public/images/foo.png +0 -0
  171. data/webroot/public/images/hammer.png +0 -0
  172. data/webroot/public/images/header.png +0 -0
  173. data/webroot/public/images/home.gif +0 -0
  174. data/webroot/public/images/jobs.gif +0 -0
  175. data/webroot/public/images/sidebar-bottom.png +0 -0
  176. data/webroot/public/images/sidebar.png +0 -0
  177. data/webroot/public/images/treeview-default-line.gif +0 -0
  178. data/webroot/public/images/treeview-default.gif +0 -0
  179. data/webroot/public/images/ui-anim_basic_16x16.gif +0 -0
  180. data/webroot/public/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  181. data/webroot/public/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  182. data/webroot/public/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  183. data/webroot/public/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  184. data/webroot/public/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  185. data/webroot/public/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  186. data/webroot/public/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  187. data/webroot/public/images/ui-bg_highlight-hard_30_565356_1x100.png +0 -0
  188. data/webroot/public/images/ui-bg_highlight-hard_75_888588_1x100.png +0 -0
  189. data/webroot/public/images/ui-bg_highlight-soft_30_6e3b3a_1x100.png +0 -0
  190. data/webroot/public/images/ui-bg_highlight-soft_35_8e8b8e_1x100.png +0 -0
  191. data/webroot/public/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  192. data/webroot/public/images/ui-icons_222222_256x240.png +0 -0
  193. data/webroot/public/images/ui-icons_2e83ff_256x240.png +0 -0
  194. data/webroot/public/images/ui-icons_454545_256x240.png +0 -0
  195. data/webroot/public/images/ui-icons_888888_256x240.png +0 -0
  196. data/webroot/public/images/ui-icons_cd0a0a_256x240.png +0 -0
  197. data/webroot/public/images/ui-icons_ffffff_256x240.png +0 -0
  198. data/webroot/public/js/ajaxupload.js +673 -0
  199. data/webroot/public/js/application.js +40 -0
  200. data/webroot/public/js/jquery-ui.combobox.js +98 -0
  201. data/webroot/public/js/jquery-ui.js +9867 -0
  202. data/webroot/public/js/jquery-ui.min.js +559 -0
  203. data/webroot/public/js/jquery.dataTables.min.js +587 -0
  204. data/webroot/public/js/jquery.min.js +154 -0
  205. data/webroot/public/js/jquery.timeago.js +140 -0
  206. data/webroot/public/js/jquery.tooltip.min.js +19 -0
  207. data/webroot/public/js/jquery.treeview.min.js +15 -0
  208. data/webroot/public/js/resource.js +11 -0
  209. data/webroot/public/js/results.js +56 -0
  210. data/webroot/public/js/transformations.js +95 -0
  211. data/webroot/views/connections/index.erb +5 -0
  212. data/webroot/views/connections/list.erb +34 -0
  213. data/webroot/views/connections/new.erb +55 -0
  214. data/webroot/views/connections/show.erb +36 -0
  215. data/webroot/views/imports/edit.erb +60 -0
  216. data/webroot/views/imports/form.erb +81 -0
  217. data/webroot/views/imports/new.erb +89 -0
  218. data/webroot/views/index.erb +12 -0
  219. data/webroot/views/jobs/index.erb +7 -0
  220. data/webroot/views/jobs/list.erb +24 -0
  221. data/webroot/views/layout.erb +38 -0
  222. data/webroot/views/matchers/form.erb +250 -0
  223. data/webroot/views/matchers/list.erb +32 -0
  224. data/webroot/views/projects/form.erb +14 -0
  225. data/webroot/views/projects/index.erb +96 -0
  226. data/webroot/views/projects/show.erb +24 -0
  227. data/webroot/views/resources/edit.erb +88 -0
  228. data/webroot/views/resources/index.erb +5 -0
  229. data/webroot/views/resources/list.erb +27 -0
  230. data/webroot/views/resources/new.erb +121 -0
  231. data/webroot/views/resources/show.erb +86 -0
  232. data/webroot/views/resources/transform.erb +2 -0
  233. data/webroot/views/results/csv.erb +12 -0
  234. data/webroot/views/results/details.erb +15 -0
  235. data/webroot/views/results/index.erb +2 -0
  236. data/webroot/views/results/list.erb +22 -0
  237. data/webroot/views/results/record.erb +24 -0
  238. data/webroot/views/results/show.erb +68 -0
  239. data/webroot/views/scenarios/index.erb +5 -0
  240. data/webroot/views/scenarios/list.erb +20 -0
  241. data/webroot/views/scenarios/new.erb +99 -0
  242. data/webroot/views/scenarios/run.erb +2 -0
  243. data/webroot/views/scenarios/show.erb +50 -0
  244. data/webroot/views/sidebar.erb +106 -0
  245. data/webroot/views/transformations/create.erb +115 -0
  246. data/webroot/views/transformations/for.erb +16 -0
  247. data/webroot/views/transformations/index.erb +2 -0
  248. data/webroot/views/transformations/list.erb +29 -0
  249. data/webroot/views/transformations/new.erb +126 -0
  250. data/webroot/views/transformations/preview.erb +46 -0
  251. data/webroot/views/transformers/edit.erb +6 -0
  252. data/webroot/views/transformers/form.erb +58 -0
  253. data/webroot/views/transformers/index.erb +2 -0
  254. data/webroot/views/transformers/list.erb +25 -0
  255. data/webroot/views/transformers/new.erb +5 -0
  256. data/webroot/views/transformers/preview.erb +23 -0
  257. data/webroot/views/transformers/show.erb +0 -0
  258. metadata +558 -0
@@ -0,0 +1,82 @@
1
+ require 'helper'
2
+
3
+ module TestExtensions
4
+ class TestProjects < Coupler::Test::IntegrationTest
5
+ test "projects" do
6
+ get "/projects"
7
+ assert last_response.ok?
8
+ end
9
+
10
+ test "new project" do
11
+ get "/projects/new"
12
+ assert last_response.ok?
13
+
14
+ doc = Nokogiri::HTML(last_response.body)
15
+ assert_equal 1, doc.css('form[action="/projects"]').length
16
+ %w{name description}.each do |name|
17
+ assert_equal 1, doc.css("input[name='project[#{name}]']").length
18
+ end
19
+ end
20
+
21
+ test "create project" do
22
+ post "/projects", {
23
+ 'project' => {
24
+ 'name' => 'foo', 'description' => 'foo bar',
25
+ }
26
+ }
27
+ assert_equal 1, Project.count
28
+ assert last_response.redirect?, "Wasn't redirected"
29
+ follow_redirect!
30
+
31
+ project = Project.first
32
+ assert_equal "http://example.org/projects/#{project.id}", last_request.url
33
+ assert_match /Project successfully created/, last_response.body
34
+ end
35
+
36
+ test "show project" do
37
+ project = Project.create(:name => 'foo')
38
+ get "/projects/#{project.id}"
39
+ assert last_response.ok?
40
+ assert_match /foo/, last_response.body
41
+ end
42
+
43
+ test "showing invalid project when projects exist" do
44
+ project = Project.create(:name => 'foo')
45
+ get "/projects/8675309"
46
+ assert last_response.redirect?
47
+ assert_equal "http://example.org/projects", last_response['location']
48
+ follow_redirect!
49
+ assert_match /The project you were looking for doesn't exist/, last_response.body
50
+ end
51
+
52
+ test "edit project" do
53
+ project = Project.create(:name => 'foo')
54
+ get "/projects/#{project.id}/edit"
55
+ assert last_response.ok?
56
+ end
57
+
58
+ test "update project" do
59
+ project = Project.create(:name => 'foo')
60
+ put "/projects/#{project.id}", :project => {:name => "Hee haw"}
61
+ assert last_response.redirect?
62
+ assert_equal "http://example.org/projects", last_response['location']
63
+ end
64
+
65
+ test "delete" do
66
+ project = Project.create(:name => 'foo')
67
+ delete "/projects/#{project.id}"
68
+ assert_nil Project[:id => project.id]
69
+ assert last_response.redirect?
70
+ assert_equal "http://example.org/projects", last_response['location']
71
+ end
72
+
73
+ test "delete with versions" do
74
+ project = Project.create(:name => 'foo')
75
+ delete "/projects/#{project.id}", :nuke => "true"
76
+ assert_nil Project[:id => project.id]
77
+ assert_nil Database.instance[:projects_versions][:current_id => project.id]
78
+ assert last_response.redirect?
79
+ assert_equal "http://example.org/projects", last_response['location']
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,150 @@
1
+ require 'helper'
2
+
3
+ module TestExtensions
4
+ class TestResources < Coupler::Test::IntegrationTest
5
+ def self.startup
6
+ super
7
+ conn = new_connection('h2', :name => 'foo')
8
+ conn.database do |db|
9
+ db.create_table!(:foo) do
10
+ primary_key :id
11
+ String :foo
12
+ String :bar
13
+ end
14
+ db[:foo].insert({:foo => 'foo', :bar => 'bar'})
15
+ db[:foo].insert({:foo => 'bar', :bar => 'foo'})
16
+
17
+ db.create_table!(:bar) do
18
+ primary_key :id
19
+ String :baz
20
+ String :quux
21
+ end
22
+ end
23
+ end
24
+
25
+ def setup
26
+ super
27
+ stamp = Time.now - 50
28
+ @project = Project.create(:name => 'foo', :created_at => stamp)
29
+ @connection = new_connection('h2', :name => 'h2 connection', :created_at => stamp).save!
30
+ end
31
+
32
+ test "index" do
33
+ resource = Resource.create(:name => 'foo', :project => @project, :connection => @connection, :table_name => 'foo')
34
+ get "/projects/#{@project.id}/resources"
35
+ assert last_response.ok?
36
+ assert @project.reload.last_accessed_at
37
+ end
38
+
39
+ test "index with non existant project" do
40
+ get "/projects/8675309/resources"
41
+ assert last_response.redirect?
42
+ assert_equal "http://example.org/projects", last_response['location']
43
+ follow_redirect!
44
+ assert_match /The project you were looking for doesn't exist/, last_response.body
45
+ end
46
+
47
+ test "new resource" do
48
+ get "/projects/#{@project.id}/resources/new"
49
+ assert last_response.ok?
50
+
51
+ doc = Nokogiri::HTML(last_response.body)
52
+ assert_equal 1, doc.css("form[action='/projects/#{@project.id}/resources']").length
53
+ %w{name table_name}.each do |name|
54
+ assert_equal 1, doc.css("input[name='resource[#{name}]']").length
55
+ end
56
+ end
57
+
58
+ test "successfully creating resource" do
59
+ attribs = {
60
+ 'connection_id' => @connection.id.to_s,
61
+ 'name' => 'bar',
62
+ 'table_name' => 'bar'
63
+ }
64
+ post "/projects/#{@project.id}/resources", { 'resource' => attribs }
65
+ resource = Resource[:name => 'bar', :project_id => @project.id]
66
+ assert resource
67
+
68
+ assert last_response.redirect?, "Wasn't redirected"
69
+ assert_equal "http://example.org/projects/#{@project.id}/resources/#{resource.id}/edit", last_response['location']
70
+ end
71
+
72
+ test "failing to create resource" do
73
+ attribs = {
74
+ 'connection_id' => @connection.id.to_s,
75
+ 'name' => '',
76
+ 'table_name' => 'bar'
77
+ }
78
+ post "/projects/#{@project.id}/resources", { 'resource' => attribs }
79
+ assert last_response.ok?
80
+ assert_match /Name is not present/, last_response.body
81
+ end
82
+
83
+ test "show resource" do
84
+ resource = Resource.create!(:name => 'foo', :project => @project, :connection => @connection, :table_name => 'foo')
85
+ field = resource.fields_dataset[:name => 'foo']
86
+ transformer = Transformer.create!(:name => 'noop', :code => 'value', :allowed_types => %w{string}, :result_type => 'same')
87
+ transformation = Transformation.create!(:resource => resource, :transformer => transformer, :source_field => field)
88
+
89
+ get "/projects/#{@project[:id]}/resources/#{resource.id}"
90
+ assert last_response.ok?
91
+
92
+ doc = Nokogiri::HTML(last_response.body)
93
+ tables = doc.css('table')
94
+
95
+ # resource table
96
+ rows = tables[0].css('tbody tr')
97
+ assert_equal 3, rows.length
98
+ rows.each_with_index do |row, i|
99
+ cells = row.css('td')
100
+ assert_equal %w{id foo bar}[i], cells[0].inner_html
101
+ end
102
+ end
103
+
104
+ test "schedule transform job" do
105
+ resource = Resource.create!(:name => 'foo', :project => @project, :connection => @connection, :table_name => 'foo')
106
+ get "/projects/#{@project[:id]}/resources/#{resource[:id]}/transform"
107
+ assert last_response.redirect?, "Wasn't redirected"
108
+ assert_equal "http://example.org/projects/#{@project[:id]}/resources/#{resource[:id]}", last_response['location']
109
+ assert Job.filter(:name => 'transform', :resource_id => resource.id, :status => 'scheduled').count == 1
110
+ end
111
+
112
+ #def test_progress
113
+ #resource = Factory(:resource, :project => @project, :completed => 100, :total => 1000)
114
+ #get "/projects/#{@project.id}/resources/#{resource.id}/progress"
115
+ #assert last_response.ok?
116
+ #assert_equal "10", last_response.body
117
+ #end
118
+
119
+ test "edit" do
120
+ resource = Resource.create!(:name => 'foo', :project => @project, :connection => @connection, :table_name => 'foo')
121
+ get "/projects/#{@project[:id]}/resources/#{resource.id}/edit"
122
+ assert last_response.ok?
123
+ end
124
+
125
+ test "update" do
126
+ resource = Resource.create!(:name => 'foo', :project => @project, :connection => @connection, :table_name => 'foo')
127
+ field = resource.fields_dataset[:name => 'foo']
128
+ put "/projects/#{@project[:id]}/resources/#{resource.id}", :resource => {
129
+ :fields_attributes => [{'id' => field.id, 'is_selected' => 0}]
130
+ }
131
+ assert last_response.redirect?
132
+ end
133
+
134
+ test "update with no attributes" do
135
+ resource = Resource.create!(:name => 'foo', :project => @project, :connection => @connection, :table_name => 'foo')
136
+ put "/projects/#{@project[:id]}/resources/#{resource.id}"
137
+ assert last_response.redirect?
138
+ end
139
+
140
+ #def test_delete
141
+ #pend
142
+ #end
143
+
144
+ test "record" do
145
+ resource = Resource.create!(:name => 'foo', :project => @project, :connection => @connection, :table_name => 'foo')
146
+ get "/projects/#{@project.id}/resources/#{resource.id}/record/1"
147
+ assert last_response.ok?
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,89 @@
1
+ require 'helper'
2
+
3
+ module TestExtensions
4
+ class TestResults < Coupler::Test::IntegrationTest
5
+ def self.startup
6
+ super
7
+ conn = new_connection('h2', :name => 'foo')
8
+ conn.database do |db|
9
+ db.create_table!(:foo) do
10
+ primary_key :id
11
+ String :foo
12
+ String :bar
13
+ end
14
+ db[:foo].insert({:foo => 'foo', :bar => 'bar'})
15
+ db[:foo].insert({:foo => 'bar', :bar => 'foo'})
16
+ end
17
+ end
18
+
19
+ def setup
20
+ super
21
+ @project = Project.create!(:name => 'foo')
22
+ @connection = new_connection('h2', :name => 'h2 connection').save!
23
+ @resource = Resource.create!(:name => 'foo', :table_name => 'foo', :project => @project, :connection => @connection)
24
+ @scenario = Scenario.create!(:name => 'foo', :resource_1 => @resource, :project => @project)
25
+ foo = @resource.fields_dataset[:name => 'foo']
26
+ bar = @resource.fields_dataset[:name => 'bar']
27
+ @matcher = Matcher.create!({
28
+ :scenario => @scenario,
29
+ :comparisons_attributes => [{
30
+ 'lhs_type' => 'field', 'raw_lhs_value' => foo.id, 'lhs_which' => 1,
31
+ 'rhs_type' => 'field', 'raw_rhs_value' => bar.id, 'rhs_which' => 2,
32
+ 'operator' => 'equals'
33
+ }]
34
+ })
35
+ @scenario.run!
36
+ @result = @scenario.results_dataset.first
37
+ end
38
+
39
+ test "index" do
40
+ get "/projects/#{@project.id}/scenarios/#{@scenario.id}/results"
41
+ assert last_response.ok?
42
+ end
43
+
44
+ test "index with non existant project" do
45
+ get "/projects/8675309/scenarios/#{@scenario.id}/results"
46
+ assert last_response.redirect?
47
+ assert_equal "http://example.org/projects", last_response['location']
48
+ follow_redirect!
49
+ assert_match /The project you were looking for doesn't exist/, last_response.body
50
+ end
51
+
52
+ test "index with non existant scenario" do
53
+ get "/projects/#{@project.id}/scenarios/8675309/results"
54
+ assert last_response.redirect?
55
+ assert_equal "http://example.org/projects/#{@project.id}/scenarios", last_response['location']
56
+ follow_redirect!
57
+ assert_match /The scenario you were looking for doesn't exist/, last_response.body
58
+ end
59
+
60
+ test "show" do
61
+ get "/projects/#{@project.id}/scenarios/#{@scenario.id}/results/#{@result.id}"
62
+ assert last_response.ok?
63
+ end
64
+
65
+ test "details" do
66
+ group_id = nil
67
+ @result.groups_dataset { |ds| group_id = ds.get(:id) }
68
+ get "/projects/#{@project.id}/scenarios/#{@scenario.id}/results/#{@result.id}/details/#{group_id}"
69
+ assert last_response.ok?
70
+ end
71
+
72
+ test "show sends csv" do
73
+ get "/projects/#{@project.id}/scenarios/#{@scenario.id}/results/#{@result.id}.csv"
74
+ assert_equal %{attachment; filename="#{@scenario.slug}-run-#{@result.created_at.strftime('%Y%m%d-%H%M')}.csv"}, last_response['Content-Disposition']
75
+
76
+ body = last_response.body
77
+ regexp = /id,foo,bar,coupler_group_id/
78
+ assert_match regexp, body
79
+ end
80
+
81
+ test "show with non existant result" do
82
+ get "/projects/#{@project.id}/scenarios/#{@scenario.id}/results/8675309"
83
+ assert last_response.redirect?
84
+ assert_equal "http://example.org/projects/#{@project.id}/scenarios/#{@scenario.id}/results", last_response['location']
85
+ follow_redirect!
86
+ assert_match /The result you were looking for doesn't exist/, last_response.body
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,88 @@
1
+ require 'helper'
2
+
3
+ module TestExtensions
4
+ class TestScenarios < Coupler::Test::IntegrationTest
5
+ def self.startup
6
+ super
7
+ conn = new_connection('h2', :name => 'foo')
8
+ conn.database do |db|
9
+ db.create_table!(:foo) do
10
+ primary_key :id
11
+ String :foo
12
+ String :bar
13
+ end
14
+ db[:foo].insert({:foo => 'foo', :bar => 'bar'})
15
+ db[:foo].insert({:foo => 'bar', :bar => 'foo'})
16
+ end
17
+ end
18
+
19
+ def setup
20
+ super
21
+ @project = Project.create(:name => 'foo')
22
+ @connection = new_connection('h2', :name => 'h2 connection').save!
23
+ @resource = Resource.create(:name => 'foo', :project => @project, :connection => @connection, :table_name => 'foo')
24
+ end
25
+
26
+ test "index" do
27
+ scenario = Scenario.create(:name => 'foo', :resource_1 => @resource, :project => @project)
28
+ get "/projects/#{@project.id}/scenarios"
29
+ assert last_response.ok?
30
+ end
31
+
32
+ test "index of non existant project" do
33
+ get "/projects/8675309/scenarios"
34
+ assert last_response.redirect?
35
+ assert_equal "http://example.org/projects", last_response['location']
36
+ follow_redirect!
37
+ assert_match /The project you were looking for doesn't exist/, last_response.body
38
+ end
39
+
40
+ test "show" do
41
+ scenario = Scenario.create(:name => 'foo', :resource_1 => @resource, :project => @project)
42
+ get "/projects/#{@project.id}/scenarios/#{scenario.id}"
43
+ assert last_response.ok?
44
+ end
45
+
46
+ test "new" do
47
+ get "/projects/#{@project.id}/scenarios/new"
48
+ assert last_response.ok?
49
+ end
50
+
51
+ test "successfully creating scenario" do
52
+ attribs = {
53
+ 'name' => 'foo',
54
+ 'resource_ids' => [@resource.id.to_s]
55
+ }
56
+ post "/projects/#{@project.id}/scenarios", { 'scenario' => attribs }
57
+ scenario = Scenario[:name => 'foo', :project_id => @project.id]
58
+ assert scenario
59
+ assert_equal [@resource], scenario.resources
60
+
61
+ assert last_response.redirect?, "Wasn't redirected"
62
+ assert_equal "http://example.org/projects/#{@project.id}/scenarios/#{scenario.id}", last_response['location']
63
+ end
64
+
65
+ test "failing to create scenario" do
66
+ post "/projects/#{@project.id}/scenarios", {
67
+ 'scenario' => { 'name' => nil, 'resource_ids' => [@resource.id.to_s] }
68
+ }
69
+ assert last_response.ok?
70
+ assert_match /Name is not present/, last_response.body
71
+ end
72
+
73
+ test "run scenario" do
74
+ scenario = Scenario.create(:name => 'foo', :resource_1 => @resource, :project => @project)
75
+ get "/projects/#{@project.id}/scenarios/#{scenario.id}/run"
76
+ assert last_response.redirect?, "Wasn't redirected"
77
+ assert_equal "http://example.org/projects/#{@project[:id]}/scenarios/#{scenario[:id]}", last_response['location']
78
+ assert Job.filter(:name => 'run_scenario', :scenario_id => scenario.id, :status => 'scheduled').count == 1
79
+ end
80
+
81
+ #def test_progress
82
+ #scenario = Factory(:scenario, :project => @project, :completed => 100, :total => 1000)
83
+ #get "/projects/#{@project.id}/scenarios/#{scenario.id}/progress"
84
+ #assert last_response.ok?
85
+ #assert_equal "10", last_response.body
86
+ #end
87
+ end
88
+ end
@@ -0,0 +1,113 @@
1
+ require 'helper'
2
+
3
+ module TestExtensions
4
+ class TestTransformations < Coupler::Test::IntegrationTest
5
+ def self.startup
6
+ super
7
+ conn = new_connection('h2', :name => 'foo')
8
+ conn.database do |db|
9
+ db.create_table!(:foo) do
10
+ primary_key :id
11
+ String :foo
12
+ String :bar
13
+ end
14
+ db[:foo].insert({:foo => 'foo', :bar => 'bar'})
15
+ db[:foo].insert({:foo => 'bar', :bar => 'foo'})
16
+ end
17
+ end
18
+
19
+ def setup
20
+ super
21
+ @project = Project.create(:name => 'foo')
22
+ @connection = new_connection('h2', :name => 'h2 connection').save!
23
+ @resource = Resource.create(:name => 'foo', :project => @project, :connection => @connection, :table_name => 'foo')
24
+ @transformer = Transformer.create(:name => 'noop', :code => 'value', :allowed_types => %w{string integer datetime}, :result_type => 'same')
25
+ end
26
+
27
+ test "new" do
28
+ get "/projects/#{@project.id}/resources/#{@resource.id}/transformations/new"
29
+ assert last_response.ok?
30
+ end
31
+
32
+ test "new with non existant project" do
33
+ get "/projects/8675309/resources/#{@resource.id}/transformations/new"
34
+ assert last_response.redirect?
35
+ assert_equal "http://example.org/projects", last_response['location']
36
+ follow_redirect!
37
+ assert_match /The project you were looking for doesn't exist/, last_response.body
38
+ end
39
+
40
+ test "new with non existant resource" do
41
+ get "/projects/#{@project.id}/resources/8675309/transformations/new"
42
+ assert last_response.redirect?
43
+ assert_equal "http://example.org/projects/#{@project.id}/resources", last_response['location']
44
+ follow_redirect!
45
+ assert_match /The resource you were looking for doesn't exist/, last_response.body
46
+ end
47
+
48
+ test "successfully creating transformation" do
49
+ field = @resource.fields_dataset[:name => 'foo']
50
+ attribs = {
51
+ :transformer_id => @transformer.id.to_s,
52
+ :source_field_id => field.id.to_s
53
+ }
54
+ post("/projects/#{@project.id}/resources/#{@resource.id}/transformations", { 'transformation' => attribs })
55
+ transformation = @resource.transformations_dataset.first
56
+ assert transformation
57
+
58
+ assert last_response.redirect?, "Wasn't redirected"
59
+ assert_equal "http://example.org/projects/#{@project.id}/resources/#{@resource.id}", last_response['location']
60
+ end
61
+
62
+ test "delete" do
63
+ field = @resource.fields_dataset[:name => 'foo']
64
+ transformation = Transformation.create!(:resource => @resource, :transformer => @transformer, :source_field => field)
65
+ delete "/projects/#{@project.id}/resources/#{@resource.id}/transformations/#{transformation.id}"
66
+ assert_equal 0, Transformation.filter(:id => transformation.id).count
67
+
68
+ assert last_response.redirect?, "Wasn't redirected"
69
+ assert_equal "http://example.org/projects/#{@project.id}/resources/#{@resource.id}", last_response['location']
70
+ end
71
+
72
+ test "delete with non existant transformation" do
73
+ delete "/projects/#{@project.id}/resources/#{@resource.id}/transformations/8675309"
74
+ assert last_response.redirect?
75
+ assert_equal "http://example.org/projects/#{@project.id}/resources/#{@resource.id}/transformations", last_response['location']
76
+ follow_redirect!
77
+ assert_match /The transformation you were looking for doesn't exist/, last_response.body
78
+ end
79
+
80
+ test "for" do
81
+ field = @resource.fields_dataset[:name => 'foo']
82
+ t12n = Transformation.create!(:resource => @resource, :source_field => field, :transformer => @transformer)
83
+
84
+ get "/projects/#{@project.id}/resources/#{@resource.id}/transformations/for/foo"
85
+ assert_match /noop/, last_response.body
86
+ end
87
+
88
+ test "for with non existant field" do
89
+ get "/projects/#{@project.id}/resources/#{@resource.id}/transformations/for/gobbledegook"
90
+ assert last_response.ok?
91
+ assert_equal '', last_response.body
92
+ end
93
+
94
+ test "index" do
95
+ field = @resource.fields_dataset[:name => 'foo']
96
+ t12n = Transformation.create!(:resource => @resource, :source_field => field, :transformer => @transformer)
97
+
98
+ get "/projects/#{@project.id}/resources/#{@resource.id}/transformations"
99
+ assert last_response.ok?
100
+ end
101
+
102
+ test "preview" do
103
+ field = @resource.fields_dataset[:name => 'foo']
104
+ params = {
105
+ :transformer_id => @transformer.id.to_s,
106
+ :source_field_id => field.id.to_s,
107
+ :result_field_id => field.id.to_s
108
+ }
109
+ post "/projects/#{@project.id}/resources/#{@resource.id}/transformations/preview", :transformation => params
110
+ assert last_response.ok?, last_response.body
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,80 @@
1
+ require 'helper'
2
+
3
+ module TestExtensions
4
+ class TestTransformers < Coupler::Test::IntegrationTest
5
+ test "index" do
6
+ get '/transformers'
7
+ assert last_response.ok?
8
+ end
9
+
10
+ test "new" do
11
+ get '/transformers/new'
12
+ assert last_response.ok?
13
+ end
14
+
15
+ test "successful create" do
16
+ count = Transformer.count
17
+ attribs = {
18
+ :name => 'noop',
19
+ :code => 'value',
20
+ :allowed_types => %w{string},
21
+ :result_type => 'string'
22
+ }
23
+ post '/transformers', 'transformer' => attribs
24
+ assert_equal count + 1, Transformer.count
25
+ assert last_response.redirect?
26
+ assert_equal "http://example.org/transformers", last_response['location']
27
+ end
28
+
29
+ test "failed create" do
30
+ count = Transformer.count
31
+ attribs = {
32
+ :name => '',
33
+ :code => 'value',
34
+ :allowed_types => %w{string},
35
+ :result_type => 'string'
36
+ }
37
+ post '/transformers', 'transformer' => attribs
38
+ assert_equal count, Transformer.count
39
+ assert last_response.ok?
40
+ end
41
+
42
+ test "edit" do
43
+ xformer = Transformer.create(:name => 'noop', :code => 'value', :allowed_types => %w{string}, :result_type => 'string')
44
+ get "/transformers/#{xformer.id}/edit"
45
+ assert last_response.ok?
46
+ end
47
+
48
+ test "successful update" do
49
+ xformer = Transformer.create(:name => 'noop', :code => 'value', :allowed_types => %w{string}, :result_type => 'string')
50
+ put "/transformers/#{xformer.id}", :transformer => { 'code' => 'value' }
51
+ assert last_response.redirect?, last_response.inspect
52
+ assert_equal "http://example.org/transformers", last_response['location']
53
+ end
54
+
55
+ test "failed update" do
56
+ xformer = Transformer.create(:name => 'noop', :code => 'value', :allowed_types => %w{string}, :result_type => 'string')
57
+ put "/transformers/#{xformer.id}", :transformer => { 'code' => 'foo(' }
58
+ assert last_response.ok?
59
+ end
60
+
61
+ test "preview" do
62
+ post "/transformers/preview", :transformer => { 'code' => 'value.downcase', 'allowed_types' => %w{string}, 'result_type' => 'string' }
63
+ assert last_response.ok?
64
+ end
65
+
66
+ test "delete" do
67
+ xformer = Transformer.create(:name => 'noop', :code => 'value', :allowed_types => %w{string}, :result_type => 'string')
68
+ delete "/transformers/#{xformer.id}"
69
+ assert_equal 0, Transformer.filter(:id => xformer.id).count
70
+ assert last_response.redirect?, last_response.inspect
71
+ assert_equal "http://example.org/transformers", last_response['location']
72
+ end
73
+
74
+ test "show" do
75
+ xformer = Transformer.create(:name => 'noop', :code => 'value', :allowed_types => %w{string}, :result_type => 'string')
76
+ get "/transformers/#{xformer.id}"
77
+ assert last_response.ok?
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+
3
+ class TestField < Coupler::Test::IntegrationTest
4
+ def self.startup
5
+ super
6
+ Connection.delete
7
+ each_adapter do |adapter, config|
8
+ data = Array.new(50) { [Forgery(:name).first_name, Forgery(:name).last_name] }
9
+ conn = new_connection(adapter, :name => "#{adapter} connection").save!
10
+ conn.database do |db|
11
+ db.create_table!(:test_data) do
12
+ primary_key :id
13
+ String :first_name
14
+ String :last_name
15
+ end
16
+ db[:test_data].import([:first_name, :last_name], data)
17
+ end
18
+ end
19
+ end
20
+
21
+ each_adapter do |adapter, _|
22
+ adapter_test(adapter, "scenarios_dataset") do
23
+ connection = new_connection(adapter, :name => "#{adapter} connection").save!
24
+ project = Project.create(:name => "foo")
25
+ resource = Resource.create({
26
+ :name => "Test resource", :table_name => 'test_data',
27
+ :project => project, :connection => connection
28
+ })
29
+ scenario = Scenario.create({
30
+ :name => "Test scenario",
31
+ :resource_1 => resource, :project => project
32
+ })
33
+ first_name = resource.fields_dataset[:name => 'first_name']
34
+ matcher = Matcher.create({
35
+ :scenario => scenario,
36
+ :comparisons_attributes => [
37
+ {:lhs_type => 'field', :raw_lhs_value => first_name.id, :lhs_which => 1, :rhs_type => 'field', :raw_rhs_value => first_name.id, :rhs_which => 2, :operator => 'equals'},
38
+ ],
39
+ })
40
+
41
+ ds = first_name.scenarios_dataset
42
+ assert_equal scenario.id, ds.get(:scenarios__id)
43
+ end
44
+ end
45
+ end