Use system specs instead of feature specs

We get rid of database cleaner, and JavaScript tests are faster because
between tests we now rollback transactions instead of truncating the
database.
This commit is contained in:
Javi Martín
2019-04-29 12:26:17 +02:00
parent 12774c7484
commit 9427f01442
190 changed files with 14 additions and 54 deletions

View File

@@ -0,0 +1,90 @@
require "rails_helper"
describe "Imports" do
let(:base_files_path) { %w[spec fixtures files local_census_records import] }
before do
admin = create(:administrator)
login_as(admin.user)
end
describe "New" do
scenario "Should show import form" do
visit new_admin_local_census_records_import_path
expect(page).to have_field("local_census_records_import_file", type: "file")
end
end
describe "Create" do
before { visit new_admin_local_census_records_import_path }
scenario "Should show success notice after successful import" do
within "form#new_local_census_records_import" do
path = base_files_path << "valid.csv"
file = File.join(Rails.root, *path)
attach_file("local_census_records_import_file", file)
click_button "Save"
end
expect(page).to have_content "Local census records import process executed successfully!"
end
scenario "Should show alert when file is not present" do
within "form#new_local_census_records_import" do
click_button "Save"
end
expect(page).to have_content "can't be blank"
end
scenario "Should show alert when file is not supported" do
within "form#new_local_census_records_import" do
path = ["spec", "fixtures", "files", "clippy.jpg"]
file = File.join(Rails.root, *path)
attach_file("local_census_records_import_file", file)
click_button "Save"
end
expect(page).to have_content "Given file format is wrong. The allowed file format is: csv."
end
scenario "Should show successfully created local census records at created group" do
within "form#new_local_census_records_import" do
path = base_files_path << "valid.csv"
file = File.join(Rails.root, *path)
attach_file("local_census_records_import_file", file)
click_button "Save"
end
expect(page).to have_content "Created records (4)"
expect(page).to have_selector("#created-local-census-records tbody tr", count: 4)
end
scenario "Should show invalid local census records at errored group" do
within "form#new_local_census_records_import" do
path = base_files_path << "invalid.csv"
file = File.join(Rails.root, *path)
attach_file("local_census_records_import_file", file)
click_button "Save"
end
expect(page).to have_content "Errored rows (5)"
expect(page).to have_selector("#invalid-local-census-records tbody tr", count: 5)
end
scenario "Should show error messages inside cells at errored group" do
within "form#new_local_census_records_import" do
path = base_files_path << "invalid.csv"
file = File.join(Rails.root, *path)
attach_file("local_census_records_import_file", file)
click_button "Save"
end
rows = all("#invalid-local-census-records tbody tr")
expect(rows[0]).to have_content("can't be blank")
expect(rows[1]).to have_content("can't be blank")
expect(rows[2]).to have_content("can't be blank")
expect(rows[3]).to have_content("can't be blank")
end
end
end