Skip to content

Commit

Permalink
fixup: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
meltheadorable committed Jun 5, 2024
1 parent d0604f6 commit 3fc5039
Show file tree
Hide file tree
Showing 64 changed files with 84 additions and 118 deletions.
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,8 @@ group :development, :test do
gem "factory_bot_rails", "~> 4.11"
gem "mocha", "~> 1.1"

# Feature specs
# system specs
gem "capybara", "~> 3.30"
gem "capybara-screenshot", "~> 1.0"
gem "launchy", "~> 2.5" # For auto-opening capybara html file
gem "puma", "~> 5.6"
gem "selenium-webdriver", "~> 4.15.0" # TODO: Can't upgrade to 4.17 until Rails 7 + Ruby 3.3
Expand All @@ -175,7 +174,6 @@ group :development, :test do
gem "annotate", "~> 3.1"
gem "assert_difference", "~> 1.0" # Deprecated: Barely used, convert usage to something else.
gem "awesome_print", "~> 1.6"
gem "database_cleaner", "~> 2.0"
gem "db-query-matchers", "~> 0.10"
gem "rubocop", "1.22.3" # Hound supported versions: http://help.houndci.com/en/articles/2461415-supported-linters
gem "rubocop-rails", "~> 2.8"
Expand Down
2 changes: 1 addition & 1 deletion spec/decorators/odk/condition_group_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "rails_helper"

module ODK
describe ConditionGroupDecorator, :odk, :reset_factory_sequences, database_cleaner: :truncate do
describe ConditionGroupDecorator, :odk, :reset_factory_sequences do
include_context "odk rendering"

let(:result) { decorate(condition_group).to_odk }
Expand Down
2 changes: 1 addition & 1 deletion spec/decorators/odk/form_item_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "rails_helper"

module ODK
describe FormItemDecorator, :odk, :reset_factory_sequences, database_cleaner: :truncate do
describe FormItemDecorator, :odk, :reset_factory_sequences do
include_context "odk rendering"

describe "xpath methods" do
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/dedupe_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
)
end

it "should dedupe correctly", database_cleaner: :truncate do
it "should dedupe correctly" do
# Start with two existing dupes, but are clean
described_class.perform_now
expect(Response.all.count).to eq(2)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/sms/decoder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@
end
end

describe "complex hierarchy construction", database_cleaner: :truncate do
describe "complex hierarchy construction" do
it "builds response tree for nested groups with repeat" do
# QingGroup (root)
# QingGroup
Expand Down
23 changes: 12 additions & 11 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require "capybara/rspec"
require "capybara/rails"
require "selenium-webdriver"
require "capybara-screenshot/rspec"
require "cancan/matchers"
require "fileutils"
require "vcr"
Expand All @@ -27,13 +26,6 @@
end
end

Capybara.javascript_driver = :selenium_chrome_headless

# Add support for Headless Chrome screenshots.
Capybara::Screenshot.register_driver(:selenium_chrome_headless) do |driver, path|
driver.browser.save_screenshot(path)
end

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f }
Expand All @@ -53,7 +45,7 @@
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
config.use_transactional_fixtures = true

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
Expand All @@ -72,7 +64,7 @@
config.infer_spec_type_from_file_location!

config.include(AssertDifference)
config.include(FeatureSpecHelpers, type: :feature)
config.include(SystemSpecHelpers, type: :system)
config.include(GeneralSpecHelpers)
config.include(ModelSpecHelpers, type: :model)
config.include(RequestSpecHelpers, type: :request)
Expand All @@ -88,6 +80,15 @@
FileUtils.mkdir_p(Rails.root.join("tmp"))
end

# Set up system tests
config.before(:each, type: :system) do
driven_by(:rack_test)
end

config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome_headless
end

# We have to use around so that this block runs before arounds and befores in actual specs.
config.around(:each) do |example|
# Previous specs might leave locale set to something else, which can cause issues.
Expand All @@ -113,7 +114,7 @@

# Print browser logs to console if they are non-empty.
# You MUST use console.warn or console.error for this to work.
config.after(:each, type: :feature, js: true) do
config.after(:each, type: :system, js: true) do
# logs = page.driver.browser.manage.logs.get(:browser).join("\n")
logs = ""
unless logs.strip.empty?
Expand Down
16 changes: 8 additions & 8 deletions spec/requests/media/odk_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
FileUtils.rm_rf(ResponsesController::TMP_UPLOADS_PATH)
end

it "should successfully process the submission and clean up", database_cleaner: :truncate do
it "should successfully process the submission and clean up" do
image = Rack::Test::UploadedFile.new(image_fixture("the_swing.jpg"), "image/jpeg")
submission_file = prepare_and_upload_submission_file("single_part_media.xml")

Expand All @@ -46,7 +46,7 @@
expect(FileUtils.rm(tmp_files)).to be_empty
end

it "should safely ignore simple duplicates", database_cleaner: :truncate do
it "should safely ignore simple duplicates" do
# Original
submission_file = prepare_and_upload_submission_file("single_question.xml")
post submission_path, params: {xml_submission_file: submission_file}, headers: auth_header
Expand Down Expand Up @@ -99,7 +99,7 @@
context "with multiple parts" do
let(:form) { create(:form, :live, question_types: %w[text image sketch]) }

it "should successfully process the submission", database_cleaner: :truncate do
it "should successfully process the submission" do
image = Rack::Test::UploadedFile.new(image_fixture("the_swing.jpg"), "image/jpeg")
image2 = Rack::Test::UploadedFile.new(image_fixture("sassafras.jpg"), "image/jpeg")
submission_file = prepare_and_upload_submission_file("multiple_part_media.xml")
Expand All @@ -117,7 +117,7 @@
context "with multiple parts, duplicate submissions for first part" do
let(:form) { create(:form, :live, question_types: %w[text image sketch]) }

it "should ignore the second submission", database_cleaner: :truncate do
it "should ignore the second submission" do
image = Rack::Test::UploadedFile.new(image_fixture("the_swing.jpg"), "image/jpeg")
image2 = Rack::Test::UploadedFile.new(image_fixture("sassafras.jpg"), "image/jpeg")
submission_file = prepare_and_upload_submission_file("multiple_part_media.xml")
Expand All @@ -140,7 +140,7 @@
context "with multiple parts, duplicate submissions for second part" do
let(:form) { create(:form, :live, question_types: %w[text image sketch]) }

it "should ignore the third submission as it is a duplicate", database_cleaner: :truncate do
it "should ignore the third submission as it is a duplicate" do
image = Rack::Test::UploadedFile.new(image_fixture("the_swing.jpg"), "image/jpeg")
image2 = Rack::Test::UploadedFile.new(image_fixture("sassafras.jpg"), "image/jpeg")
submission_file = prepare_and_upload_submission_file("multiple_part_media.xml")
Expand All @@ -163,7 +163,7 @@
context "with multiple parts, duplicate first submission at the end" do
let(:form) { create(:form, :live, question_types: %w[text image sketch]) }

it "should successfully process the submission", database_cleaner: :truncate do
it "should successfully process the submission" do
image = Rack::Test::UploadedFile.new(image_fixture("the_swing.jpg"), "image/jpeg")
image2 = Rack::Test::UploadedFile.new(image_fixture("sassafras.jpg"), "image/jpeg")
submission_file = prepare_and_upload_submission_file("multiple_part_media.xml")
Expand All @@ -186,7 +186,7 @@
context "with multiple parts, duplicate xml/image and no response" do
let(:form) { create(:form, :live, question_types: %w[text image sketch]) }

it "should successfully process the submission", database_cleaner: :truncate do
it "should successfully process the submission" do
image = Rack::Test::UploadedFile.new(image_fixture("the_swing.jpg"), "image/jpeg")
submission_file = prepare_and_upload_submission_file("multiple_part_media.xml")
submission_file2 = prepare_and_upload_submission_file("multiple_part_media.xml")
Expand All @@ -207,7 +207,7 @@
context "multiple media attachments in multiple responses" do
let(:form) { create(:form, :live, question_types: %w[text image sketch image]) }

it "should successfully process the submission", database_cleaner: :truncate do
it "should successfully process the submission" do
image = Rack::Test::UploadedFile.new(image_fixture("the_swing.jpg"), "image/jpeg")
image2 = Rack::Test::UploadedFile.new(image_fixture("sassafras.jpg"), "image/jpeg")
image3 = Rack::Test::UploadedFile.new(image_fixture("sassafras2.jpg"), "image/jpeg")
Expand Down
8 changes: 4 additions & 4 deletions spec/requests/odk/submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
end

context "normal submission" do
it "should work and have mission set to current mission", database_cleaner: :truncate do
it "should work and have mission set to current mission" do
post(submission_path, params: request_params, headers: auth_header)
expect(response).to have_http_status(:created)
expect(nemo_response.mission).to eq(mission)
expect(nemo_response.device_id).to eq(nil)
end

it "should save device ID if present", database_cleaner: :truncate do
it "should save device ID if present" do
post("#{submission_path}?deviceID=test", params: request_params, headers: auth_header)
expect(response).to have_http_status(:created)
expect(nemo_response.device_id).to eq("test")
Expand Down Expand Up @@ -139,7 +139,7 @@
form.c[1].update!(required: true)
end

it "should still accept response", database_cleaner: :truncate do
it "should still accept response" do
post(submission_path, params: request_params, headers: auth_header)
expect(response).to have_http_status(:created)
expect(nemo_response.children.size).to eq(1)
Expand All @@ -163,7 +163,7 @@
end
let!(:question_types) { %w[text text text text] }

it "should return created", database_cleaner: :truncate do
it "should return created" do
prepare_odk_response_fixture("simple_response", form1, values: xml_values, formver: "202211")
r1
r1_original_path = Rails.root.join("tmp/odk/responses/simple_response/simple_response.xml")
Expand Down
33 changes: 0 additions & 33 deletions spec/support/configs/database_cleaner.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module FeatureSpecHelpers
module SystemSpecHelpers
ALERT_CLASSES = {
notice: "alert-info",
success: "alert-success",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "broadcasts", :sms, js: true do
describe "broadcasts", :sms, js: true do
include_context "search"
let(:max_user_dropdown_results) { BroadcastsController::USERS_OR_GROUPS_PER_PAGE * 2 }
let!(:user) { create(:user, role_name: "staffer") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "dashboard", js: true do
describe "dashboard", js: true do
let(:dashboard_path) { mission_root_path(mission_name: get_mission.compact_name, locale: "en") }

before do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Tests the hint popovers in regular forms and modal forms.
require "rails_helper"

feature "form hints", js: true do
describe "form hints", js: true do
let(:form) { create(:form, question_types: %w[integer image image]) }
let(:mission_name) { get_mission.compact_name }
let(:user) { create(:user, role_name: "coordinator") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "fileutils"
require "zip"

feature "form export" do
describe "form export" do
context "single form" do
let(:user) { create(:user, role_name: "coordinator") }
let(:form) { create(:form, :live, question_types: %w[text]) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "form status and version display and changes", js: true do
describe "form status and version display and changes", js: true do
let!(:form) { create(:form, :draft, name: "Myform") }
let(:user) { create(:user, role_name: "coordinator") }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "forms", js: true do
describe "forms", js: true do
INDENT = 40

let!(:user) { create(:user) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "forms", js: true do
describe "forms", js: true do
let(:user) { create(:user) }
let(:form) do
create(:form, name: "Foo", question_types: %w[integer multilevel_select_one select_one integer])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "constraints form fields", js: true do
describe "constraints form fields", js: true do
let!(:user) { create(:admin) }
let(:standard) { false }
let(:traits) { standard ? [:standard] : [] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "display logic form fields", js: true do
describe "display logic form fields", js: true do
let!(:user) { create(:admin) }
let(:standard) { false }
let(:traits) { standard ? [:standard] : [] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "adding and editing qing group on form", js: true do
describe "adding and editing qing group on form", js: true do
let!(:user) { create(:user) }
let!(:form) do
create(:form, name: "Foo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "skip logic form fields", js: true do
describe "skip logic form fields", js: true do
let!(:user) { create(:admin) }
let(:standard) { false }
let(:traits) { standard ? [:standard] : [] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "option set" do
describe "option set" do
let(:user) { create(:user, role_name: "coordinator") }

before do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "question index", js: true do
describe "question index", js: true do
let(:admin) { create(:admin) }
let(:mission) { get_mission }
let!(:questions) { create_list(:question, 3, canonical_name: "duplicated", mission: mission) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

feature "question tags" do
describe "question tags" do
include_context "search"

let!(:mission) { get_mission }
Expand Down
Loading

0 comments on commit 3fc5039

Please sign in to comment.