/
test_imports.rb
82 lines (66 loc) · 2.72 KB
/
test_imports.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require 'helper'
module CouplerFunctionalTests
class TestImports < Coupler::Test::FunctionalTest
def setup
super
@project = Project.create(:name => 'foo')
end
attribute(:javascript, true)
test "upload" do
visit "/projects/#{@project.id}/resources/new"
find('label[for="resource-type-csv"]').click
attach_file('data', fixture_path('people.csv'))
assert_equal "/projects/#{@project.id}/imports/upload", page.current_path
assert page.has_selector?('input#name')
end
attribute(:javascript, true)
test "upload with no headers" do
visit "/projects/#{@project.id}/resources/new"
find('label[for="resource-type-csv"]').click
attach_file('data', fixture_path('no-headers.csv'))
assert_equal "/projects/#{@project.id}/imports/upload", page.current_path
assert page.has_selector?('input#name')
end
attribute(:javascript, true)
test "create with no issues" do
visit "/projects/#{@project.id}/resources/new"
find('label[for="resource-type-csv"]').click
attach_file('data', fixture_path('people.csv'))
job_count = Job.count
click_button('Begin Importing')
assert_match %r{^/projects/#{@project[:id]}$}, page.current_path
assert_equal job_count + 1, Job.count
end
attribute(:javascript, true)
test "create with invalid import, fix, and continue" do
visit "/projects/#{@project.id}/resources/new"
find('label[for="resource-type-csv"]').click
attach_file('data', fixture_path('people.csv'))
fill_in('name', :with => '')
click_button('Begin Importing')
assert page.has_selector?("div.errors")
fill_in('name', :with => 'Foo Bar')
click_button('Begin Importing')
assert_match %r{^/projects/#{@project[:id]}/resources/\d+$}, page.current_path
end
attribute(:javascript, true)
test "create with duplicate keys redirects to edit" do
visit "/projects/#{@project.id}/resources/new"
find('label[for="resource-type-csv"]').click
attach_file('data', fixture_path('duplicate-keys.csv'))
click_button('Begin Importing')
assert find("h2").has_content?("Duplicate Keys")
assert_match %r{^/projects/#{@project.id}/imports/\d+/edit$}, page.current_path
end
attribute(:javascript, true)
test "update import with duplicate keys" do
visit "/projects/#{@project.id}/resources/new"
find('label[for="resource-type-csv"]').click
attach_file('data', fixture_path('duplicate-keys.csv'))
click_button('Begin Importing')
find('input[name="delete[2][]"][value="1"]').click
click_button('Submit')
assert_match %r{^/projects/#{@project[:id]}/resources/\d+$}, page.current_path
end
end
end