coupler 0.0.4-java → 0.0.6-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/Gemfile +7 -8
  2. data/Gemfile.lock +43 -24
  3. data/VERSION +1 -1
  4. data/coupler.gemspec +27 -31
  5. data/features/wizard.feature +2 -1
  6. data/lib/coupler.rb +2 -2
  7. data/lib/coupler/base.rb +4 -0
  8. data/lib/coupler/extensions/connections.rb +2 -12
  9. data/lib/coupler/extensions/jobs.rb +4 -2
  10. data/lib/coupler/extensions/projects.rb +1 -1
  11. data/lib/coupler/helpers.rb +9 -1
  12. data/lib/coupler/models.rb +8 -0
  13. data/lib/coupler/models/comparison.rb +5 -4
  14. data/lib/coupler/models/connection.rb +10 -1
  15. data/lib/coupler/models/import.rb +3 -7
  16. data/lib/coupler/models/transformer.rb +1 -1
  17. data/lib/coupler/runner.rb +1 -1
  18. data/lib/coupler/scheduler.rb +1 -1
  19. data/tasks/test.rake +8 -0
  20. data/test/functional/test_base.rb +17 -0
  21. data/test/functional/test_connections.rb +81 -0
  22. data/test/functional/test_imports.rb +76 -0
  23. data/test/{integration/extensions → functional}/test_jobs.rb +21 -12
  24. data/test/functional/test_matchers.rb +108 -0
  25. data/test/functional/test_projects.rb +67 -0
  26. data/test/functional/test_resources.rb +126 -0
  27. data/test/{integration/extensions → functional}/test_results.rb +20 -29
  28. data/test/functional/test_scenarios.rb +92 -0
  29. data/test/functional/test_transformations.rb +106 -0
  30. data/test/functional/test_transformers.rb +68 -0
  31. data/test/helper.rb +30 -20
  32. data/test/integration/test_transformation.rb +6 -1
  33. data/test/unit/models/test_common_model.rb +2 -2
  34. data/test/unit/models/test_comparison.rb +8 -8
  35. data/test/unit/models/test_connection.rb +2 -2
  36. data/test/unit/models/test_field.rb +2 -2
  37. data/test/unit/models/test_import.rb +9 -4
  38. data/test/unit/models/test_job.rb +2 -2
  39. data/test/unit/models/test_matcher.rb +2 -2
  40. data/test/unit/models/test_project.rb +2 -2
  41. data/test/unit/models/test_resource.rb +2 -2
  42. data/test/unit/models/test_result.rb +2 -2
  43. data/test/unit/models/test_scenario.rb +2 -2
  44. data/test/unit/models/test_transformation.rb +2 -2
  45. data/test/unit/models/test_transformer.rb +12 -2
  46. data/test/unit/test_base.rb +1 -14
  47. data/test/unit/test_data_uploader.rb +1 -1
  48. data/test/unit/test_database.rb +1 -1
  49. data/test/unit/test_helpers.rb +2 -2
  50. data/test/unit/test_import_buffer.rb +40 -38
  51. data/test/unit/test_logger.rb +1 -1
  52. data/test/unit/test_models.rb +1 -1
  53. data/test/unit/test_runner.rb +1 -1
  54. data/test/unit/test_scheduler.rb +1 -1
  55. data/webroot/public/css/style.css +7 -5
  56. data/webroot/public/js/jquery.dataTables.min.js +130 -574
  57. data/webroot/views/connections/new.erb +41 -3
  58. data/webroot/views/imports/new.erb +2 -0
  59. data/webroot/views/jobs/list.erb +25 -21
  60. data/webroot/views/projects/index.erb +23 -15
  61. data/webroot/views/resources/list.erb +1 -2
  62. data/webroot/views/resources/new.erb +2 -2
  63. data/webroot/views/resources/show.erb +5 -2
  64. data/webroot/views/scenarios/new.erb +1 -1
  65. data/webroot/views/transformations/new.erb +1 -1
  66. metadata +30 -44
  67. data/lib/coupler/config.rb +0 -128
  68. data/test/coupler/models/test_import.rb +0 -221
  69. data/test/factories.rb +0 -91
  70. data/test/integration/extensions/test_connections.rb +0 -80
  71. data/test/integration/extensions/test_imports.rb +0 -94
  72. data/test/integration/extensions/test_matchers.rb +0 -134
  73. data/test/integration/extensions/test_projects.rb +0 -82
  74. data/test/integration/extensions/test_resources.rb +0 -150
  75. data/test/integration/extensions/test_scenarios.rb +0 -88
  76. data/test/integration/extensions/test_transformations.rb +0 -113
  77. data/test/integration/extensions/test_transformers.rb +0 -80
  78. data/vendor/h2-1.3.154.jar +0 -0
@@ -12,6 +12,8 @@ require 'mocha'
12
12
  require 'rack/test'
13
13
  require 'rack/flash'
14
14
  require 'rack/flash/test'
15
+ require 'capybara'
16
+ require 'capybara/dsl'
15
17
  require 'nokogiri'
16
18
  require 'timecop'
17
19
  require 'tempfile'
@@ -21,11 +23,9 @@ require 'table_maker'
21
23
  require 'sequel'
22
24
  require 'sequel/extensions/schema_dumper'
23
25
  require 'forgery'
24
- require 'ruby-debug'
25
26
 
26
27
  dir = File.dirname(__FILE__)
27
28
  $LOAD_PATH.unshift(dir)
28
- require 'table_sets'
29
29
 
30
30
  # set here and in the rake environment task
31
31
  ENV['COUPLER_ENV'] = 'test'
@@ -38,16 +38,19 @@ Coupler::Base.set(:sessions, false) # workaround
38
38
  Coupler::Base.set(:environment, :test)
39
39
  Coupler::Database.instance.migrate!
40
40
 
41
+ #Capybara.register_driver :selenium_chrome do |app|
42
+ #Capybara::Driver::Selenium.new(app, :browser => :chrome)
43
+ #end
44
+ Capybara.javascript_driver = :selenium
45
+ Capybara.app = Coupler::Base
46
+
41
47
  module Coupler
42
48
  module Test
43
49
  class Base < ::Test::Unit::TestCase
44
- include Rack::Test::Methods
50
+ include Coupler
51
+ include Coupler::Models
45
52
  @@test_config = YAML.load(ERB.new(File.read(File.join(File.dirname(__FILE__), 'config.yml'))).result(binding))
46
53
 
47
- def app
48
- Coupler::Base
49
- end
50
-
51
54
  def setup
52
55
  #@_original_connection_count = connection_count
53
56
  @_database = Coupler::Database.instance
@@ -57,13 +60,6 @@ module Coupler
57
60
  end
58
61
  end
59
62
 
60
- #def run(*args, &block)
61
- #Sequel::Model.db.transaction do
62
- #super
63
- #raise Sequel::Error::Rollback
64
- #end
65
- #end
66
-
67
63
  def teardown
68
64
  if @_tmpdirs
69
65
  @_tmpdirs.each { |t| FileUtils.rm_rf(t) }
@@ -124,10 +120,27 @@ module Coupler
124
120
  end
125
121
 
126
122
  class UnitTest < Base; end
123
+ class IntegrationTest < Base; end
127
124
 
128
- class IntegrationTest < Base
129
- include Coupler
130
- include Coupler::Models
125
+ class FunctionalTest < Base
126
+ include Capybara::DSL
127
+
128
+ def app
129
+ Coupler::Base
130
+ end
131
+
132
+ def teardown
133
+ super
134
+ Capybara.reset_sessions!
135
+ Capybara.use_default_driver
136
+ end
137
+
138
+ def setup
139
+ if self.class.get_attribute(@method_name, :javascript)
140
+ Capybara.current_driver = Capybara.javascript_driver
141
+ end
142
+ super
143
+ end
131
144
  end
132
145
  end
133
146
  end
@@ -154,6 +167,3 @@ class Array
154
167
  end
155
168
  end
156
169
  end
157
-
158
- require 'factory_girl'
159
- Factory.find_definitions
@@ -37,7 +37,12 @@ class TestTransformation < Coupler::Test::IntegrationTest
37
37
 
38
38
  adapter_test(adapter, "accepts nested attributes for result field") do
39
39
  adapter_setup(adapter)
40
- transformer = Factory(:transformer, :code => %{value}, :result_type => 'same')
40
+ transformer = Transformer.create({
41
+ :name => "noop",
42
+ :code => %{value},
43
+ :allowed_types => %w{string integer datetime},
44
+ :result_type => 'same'
45
+ })
41
46
  field = @resource.fields_dataset[:name => 'first_name']
42
47
  transformation = Transformation.create({
43
48
  :transformer => transformer,
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestCommonModel < Coupler::Test::UnitTest
6
6
  def self.startup
7
7
  super
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestComparison < Coupler::Test::UnitTest
6
6
  def sequel_expr(*args)
7
7
  if args.length == 1
@@ -559,7 +559,7 @@ module Coupler
559
559
 
560
560
  test "blocking?" do
561
561
  field = stub("field", :name => 'first_name') {
562
- stubs(:[]).with(:type).returns('string')
562
+ stubs(:[]).with(:final_type).returns('string')
563
563
  }
564
564
  Field.stubs(:[]).with(:id => 1).returns(field)
565
565
  comparison = new_comparison({
@@ -572,11 +572,11 @@ module Coupler
572
572
 
573
573
  test "cross_match?" do
574
574
  field_1 = stub("field 1", :id => 1, :name => 'ssn_1', :resource_id => 1) {
575
- stubs(:[]).with(:type).returns('string')
575
+ stubs(:[]).with(:final_type).returns('string')
576
576
  }
577
577
  Field.stubs(:[]).with(:id => 1).returns(field_1)
578
578
  field_2 = stub("field 2", :id => 2, :name => 'ssn_2', :resource_id => 1) {
579
- stubs(:[]).with(:type).returns('string')
579
+ stubs(:[]).with(:final_type).returns('string')
580
580
  }
581
581
  Field.stubs(:[]).with(:id => 2).returns(field_2)
582
582
  comparison = new_comparison({
@@ -589,11 +589,11 @@ module Coupler
589
589
 
590
590
  test "does not allow two fields of different types" do
591
591
  field_1 = stub("field 1", :name => 'first_name') {
592
- stubs(:[]).with(:type).returns('string')
592
+ stubs(:[]).with(:final_type).returns('string')
593
593
  }
594
594
  Field.stubs(:[]).with(:id => 1).returns(field_1)
595
595
  field_2 = stub("field 2", :name => 'age') {
596
- stubs(:[]).with(:type).returns('integer')
596
+ stubs(:[]).with(:final_type).returns('integer')
597
597
  }
598
598
  Field.stubs(:[]).with(:id => 2).returns(field_2)
599
599
  comparison = new_comparison({
@@ -605,7 +605,7 @@ module Coupler
605
605
  end
606
606
 
607
607
  test "does not allow non-equality comparisons for fields" do
608
- field = stub("field", :name => 'first_name') { stubs(:[]).with(:type).returns('string') }
608
+ field = stub("field", :name => 'first_name') { stubs(:[]).with(:final_type).returns('string') }
609
609
  Field.stubs(:[]).with(:id => 1).returns(field)
610
610
  comparison = new_comparison({
611
611
  :lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestConnection < Coupler::Test::UnitTest
6
6
  test "sequel model" do
7
7
  assert_equal ::Sequel::Model, Connection.superclass
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestField < Coupler::Test::UnitTest
6
6
  def new_field(attrs = {})
7
7
  f = Field.new({
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestImport < Coupler::Test::UnitTest
6
6
  def new_import(attribs = {})
7
7
  values = {
@@ -67,6 +67,11 @@ module Coupler
67
67
  assert !import.has_headers
68
68
  end
69
69
 
70
+ test "requires name" do
71
+ import = new_import(:name => nil)
72
+ assert !import.valid?
73
+ end
74
+
70
75
  test "requires field names" do
71
76
  import = new_import(:data => fixture_file_upload('no-headers.csv'))
72
77
  assert_nil import.field_names
@@ -97,8 +102,8 @@ module Coupler
97
102
 
98
103
  test "requires unused resource name" do
99
104
  import = new_import
100
- @project.resources_dataset.stubs(:count).returns(1)
101
- assert !import.valid?
105
+ import.expects(:validates_unique).with([:project_id, :name]).returns(false)
106
+ import.valid?
102
107
  end
103
108
 
104
109
  test "dataset" do
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestJob < Coupler::Test::UnitTest
6
6
  def new_job(attribs = {})
7
7
  j = Job.new(attribs)
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestMatcher < Coupler::Test::UnitTest
6
6
  def new_matcher(attribs = {})
7
7
  values = {
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestProject < Coupler::Test::UnitTest
6
6
  test "sequel model" do
7
7
  assert_equal ::Sequel::Model, Project.superclass
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestResource < Coupler::Test::UnitTest
6
6
  def setup
7
7
  super
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestResult < Coupler::Test::UnitTest
6
6
  def new_result(attribs = {})
7
7
  values = {
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestScenario < Coupler::Test::UnitTest
6
6
  def setup
7
7
  super
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestTransformation < Coupler::Test::UnitTest
6
6
  def new_transformation(attribs = {})
7
7
  values = {
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
4
- module Models
3
+ module CouplerUnitTests
4
+ module ModelTests
5
5
  class TestTransformer < Coupler::Test::UnitTest
6
6
  def new_transformer(attribs = {})
7
7
  values = {
@@ -183,6 +183,16 @@ module Coupler
183
183
  #def test_should_handle_empty_values
184
184
  #pend
185
185
  #end
186
+
187
+ test "doesn't escape backslashes too much" do
188
+ code = %{value =~ /\d/ ? "YES" : "NO"}
189
+ transformer = new_transformer({
190
+ :allowed_types => %w{string},
191
+ :result_type => 'string', :code => code
192
+ }).save!
193
+ t = Transformer[:id => transformer.id]
194
+ assert_equal code, t.code
195
+ end
186
196
  end
187
197
  end
188
198
  end
@@ -1,24 +1,11 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
3
+ module CouplerUnitTests
4
4
  class TestBase < Coupler::Test::UnitTest
5
5
  def test_subclasses_sinatra_base
6
6
  assert_equal Sinatra::Base, Coupler::Base.superclass
7
7
  end
8
8
 
9
- def test_index_when_no_projects
10
- get "/"
11
- assert last_response.ok?
12
- assert_match /Getting Started/, last_response.body
13
- end
14
-
15
- def test_redirect_when_projects_exist
16
- project = Factory(:project)
17
- get "/"
18
- assert last_response.redirect?
19
- assert_equal "http://example.org/projects", last_response['location']
20
- end
21
-
22
9
  def test_db_path
23
10
  env = Base.settings.environment
24
11
  begin
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
3
+ module CouplerUnitTests
4
4
  class TestDataUploader < Coupler::Test::UnitTest
5
5
  def test_carrierwave_subclass
6
6
  assert_equal CarrierWave::Uploader::Base, DataUploader.superclass
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
3
+ module CouplerUnitTests
4
4
  class TestDatabase < Coupler::Test::UnitTest
5
5
  def setup
6
6
  super
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- module Coupler
3
+ module CouplerUnitTests
4
4
  class TestHelpers < Coupler::Test::UnitTest
5
5
  include ::Coupler::Helpers
6
6
 
@@ -50,7 +50,7 @@ module Coupler
50
50
  result = form_tag_for(obj, :base_url => "/projects")
51
51
  assert_equal %{<form action="/projects" method="post">}, result
52
52
 
53
- obj = Factory(:project)
53
+ obj = Project.create(:name => 'foo')
54
54
  result = form_tag_for(obj, :base_url => "/projects")
55
55
  assert_equal %{<form action="/projects/#{obj.id}" method="post"><div style="display: none;"><input type="hidden" name="_method" value="put" /></div>}, result
56
56
  end
@@ -1,47 +1,49 @@
1
1
  require 'helper'
2
2
 
3
- class TestImportBuffer < Coupler::Test::UnitTest
4
- include Coupler
3
+ module CouplerUnitTests
4
+ class TestImportBuffer < Coupler::Test::UnitTest
5
+ include Coupler
5
6
 
6
- def setup
7
- super
8
- @database = stub('database', :run => nil)
9
- @dataset = stub('dataset', {
10
- :insert_sql => "INSERT INTO \"FOO\" (\"BAR\") VALUES",
11
- :db => @database,
12
- :first_source_alias => :foo
13
- })
14
- end
7
+ def setup
8
+ super
9
+ @database = stub('database', :run => nil)
10
+ @dataset = stub('dataset', {
11
+ :insert_sql => "INSERT INTO \"FOO\" (\"BAR\") VALUES",
12
+ :db => @database,
13
+ :first_source_alias => :foo
14
+ })
15
+ end
15
16
 
16
- test "single insert" do
17
- @dataset.expects(:insert_sql).with([:bar], Sequel::LiteralString.new("VALUES")).returns("INSERT INTO \"FOO\" (\"BAR\") VALUES")
18
- @dataset.expects(:literal).with([123]).returns("(123)")
19
- @database.expects(:run).with("INSERT INTO \"FOO\" (\"BAR\") VALUES (123)")
20
- buffer = ImportBuffer.new([:bar], @dataset)
21
- buffer.add({:bar => 123})
22
- buffer.flush
23
- end
17
+ test "single insert" do
18
+ @dataset.expects(:insert_sql).with([:bar], Sequel::LiteralString.new("VALUES")).returns("INSERT INTO \"FOO\" (\"BAR\") VALUES")
19
+ @dataset.expects(:literal).with([123]).returns("(123)")
20
+ @database.expects(:run).with("INSERT INTO \"FOO\" (\"BAR\") VALUES (123)")
21
+ buffer = ImportBuffer.new([:bar], @dataset)
22
+ buffer.add({:bar => 123})
23
+ buffer.flush
24
+ end
24
25
 
25
- test "multiple insert" do
26
- @dataset.expects(:literal).with([123]).returns("(123)")
27
- @dataset.expects(:literal).with([456]).returns("(456)")
28
- @database.expects(:run).with("INSERT INTO \"FOO\" (\"BAR\") VALUES (123), (456)")
29
- buffer = ImportBuffer.new([:bar], @dataset)
30
- buffer.add({:bar => 123})
31
- buffer.add({:bar => 456})
32
- buffer.flush
33
- end
26
+ test "multiple insert" do
27
+ @dataset.expects(:literal).with([123]).returns("(123)")
28
+ @dataset.expects(:literal).with([456]).returns("(456)")
29
+ @database.expects(:run).with("INSERT INTO \"FOO\" (\"BAR\") VALUES (123), (456)")
30
+ buffer = ImportBuffer.new([:bar], @dataset)
31
+ buffer.add({:bar => 123})
32
+ buffer.add({:bar => 456})
33
+ buffer.flush
34
+ end
34
35
 
35
- test "max query size / auto-flush" do
36
- size = ImportBuffer::MAX_QUERY_SIZE - 50
37
- str = "x" * size
36
+ test "max query size / auto-flush" do
37
+ size = ImportBuffer::MAX_QUERY_SIZE - 50
38
+ str = "x" * size
38
39
 
39
- # bar is a string this time
40
- @dataset.expects(:literal).twice.with([str]).returns("(#{str})")
41
- @database.expects(:run).twice
42
- buffer = ImportBuffer.new([:bar], @dataset)
43
- buffer.add({:bar => str})
44
- buffer.add({:bar => str})
45
- buffer.flush
40
+ # bar is a string this time
41
+ @dataset.expects(:literal).twice.with([str]).returns("(#{str})")
42
+ @database.expects(:run).twice
43
+ buffer = ImportBuffer.new([:bar], @dataset)
44
+ buffer.add({:bar => str})
45
+ buffer.add({:bar => str})
46
+ buffer.flush
47
+ end
46
48
  end
47
49
  end