coupler 0.0.4-java → 0.0.6-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.
- data/Gemfile +7 -8
- data/Gemfile.lock +43 -24
- data/VERSION +1 -1
- data/coupler.gemspec +27 -31
- data/features/wizard.feature +2 -1
- data/lib/coupler.rb +2 -2
- data/lib/coupler/base.rb +4 -0
- data/lib/coupler/extensions/connections.rb +2 -12
- data/lib/coupler/extensions/jobs.rb +4 -2
- data/lib/coupler/extensions/projects.rb +1 -1
- data/lib/coupler/helpers.rb +9 -1
- data/lib/coupler/models.rb +8 -0
- data/lib/coupler/models/comparison.rb +5 -4
- data/lib/coupler/models/connection.rb +10 -1
- data/lib/coupler/models/import.rb +3 -7
- data/lib/coupler/models/transformer.rb +1 -1
- data/lib/coupler/runner.rb +1 -1
- data/lib/coupler/scheduler.rb +1 -1
- data/tasks/test.rake +8 -0
- data/test/functional/test_base.rb +17 -0
- data/test/functional/test_connections.rb +81 -0
- data/test/functional/test_imports.rb +76 -0
- data/test/{integration/extensions → functional}/test_jobs.rb +21 -12
- data/test/functional/test_matchers.rb +108 -0
- data/test/functional/test_projects.rb +67 -0
- data/test/functional/test_resources.rb +126 -0
- data/test/{integration/extensions → functional}/test_results.rb +20 -29
- data/test/functional/test_scenarios.rb +92 -0
- data/test/functional/test_transformations.rb +106 -0
- data/test/functional/test_transformers.rb +68 -0
- data/test/helper.rb +30 -20
- data/test/integration/test_transformation.rb +6 -1
- data/test/unit/models/test_common_model.rb +2 -2
- data/test/unit/models/test_comparison.rb +8 -8
- data/test/unit/models/test_connection.rb +2 -2
- data/test/unit/models/test_field.rb +2 -2
- data/test/unit/models/test_import.rb +9 -4
- data/test/unit/models/test_job.rb +2 -2
- data/test/unit/models/test_matcher.rb +2 -2
- data/test/unit/models/test_project.rb +2 -2
- data/test/unit/models/test_resource.rb +2 -2
- data/test/unit/models/test_result.rb +2 -2
- data/test/unit/models/test_scenario.rb +2 -2
- data/test/unit/models/test_transformation.rb +2 -2
- data/test/unit/models/test_transformer.rb +12 -2
- data/test/unit/test_base.rb +1 -14
- data/test/unit/test_data_uploader.rb +1 -1
- data/test/unit/test_database.rb +1 -1
- data/test/unit/test_helpers.rb +2 -2
- data/test/unit/test_import_buffer.rb +40 -38
- data/test/unit/test_logger.rb +1 -1
- data/test/unit/test_models.rb +1 -1
- data/test/unit/test_runner.rb +1 -1
- data/test/unit/test_scheduler.rb +1 -1
- data/webroot/public/css/style.css +7 -5
- data/webroot/public/js/jquery.dataTables.min.js +130 -574
- data/webroot/views/connections/new.erb +41 -3
- data/webroot/views/imports/new.erb +2 -0
- data/webroot/views/jobs/list.erb +25 -21
- data/webroot/views/projects/index.erb +23 -15
- data/webroot/views/resources/list.erb +1 -2
- data/webroot/views/resources/new.erb +2 -2
- data/webroot/views/resources/show.erb +5 -2
- data/webroot/views/scenarios/new.erb +1 -1
- data/webroot/views/transformations/new.erb +1 -1
- metadata +30 -44
- data/lib/coupler/config.rb +0 -128
- data/test/coupler/models/test_import.rb +0 -221
- data/test/factories.rb +0 -91
- data/test/integration/extensions/test_connections.rb +0 -80
- data/test/integration/extensions/test_imports.rb +0 -94
- data/test/integration/extensions/test_matchers.rb +0 -134
- data/test/integration/extensions/test_projects.rb +0 -82
- data/test/integration/extensions/test_resources.rb +0 -150
- data/test/integration/extensions/test_scenarios.rb +0 -88
- data/test/integration/extensions/test_transformations.rb +0 -113
- data/test/integration/extensions/test_transformers.rb +0 -80
- data/vendor/h2-1.3.154.jar +0 -0
data/test/helper.rb
CHANGED
@@ -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
|
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
|
129
|
-
include
|
130
|
-
|
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 =
|
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
|
4
|
-
module
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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
|
4
|
-
module
|
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
|
-
|
101
|
-
|
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
|
4
|
-
module
|
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
|
data/test/unit/test_base.rb
CHANGED
@@ -1,24 +1,11 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
module
|
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
|
data/test/unit/test_database.rb
CHANGED
data/test/unit/test_helpers.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
module
|
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 =
|
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
|
-
|
4
|
-
|
3
|
+
module CouplerUnitTests
|
4
|
+
class TestImportBuffer < Coupler::Test::UnitTest
|
5
|
+
include Coupler
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
36
|
+
test "max query size / auto-flush" do
|
37
|
+
size = ImportBuffer::MAX_QUERY_SIZE - 50
|
38
|
+
str = "x" * size
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|