-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_helper.rb
76 lines (65 loc) · 2.1 KB
/
test_helper.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
# frozen_string_literal: true
require "simplecov"
# require "minitest/pride"
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
# Set up ActiveSupport tests.
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical
# order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
# Set up ActionDispatch tests.
class ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
def login(user)
sign_in_as(user, "1234567890")
end
def sign_in_as(user, password)
user.update password: password, password_confirmation: password
post new_user_session_url, params: {
user: { email: user.email, password: password }
}
follow_redirect!
user
end
end
module Rack
module Test
# Allow files to be uploaded in tests.
class UploadedFile
attr_reader :tempfile
end
end
end
# Add helper method to login user.
class ActionDispatch::SystemTestCase
def visit_login(user, screenshot_name = nil)
password = "PASSword2"
user.update(password: password, password_confirmation: password)
visit new_user_session_url
screenshot(screenshot_name) if screenshot_name.present?
fill_in "user[email]", with: user.email
fill_in "user[password]", with: user.password
click_form_submit
end
end
# Discarding files stored during integration tests.
module ActionDispatch
class IntegrationTest
def remove_uploaded_files
FileUtils.rm_rf(Rails.root.join("tmp", "storage"))
FileUtils.rm_rf(Rails.root.join("test", "storage", "carrierwave", "uploads"))
FileUtils.rm_rf(Rails.root.join("test", "storage", "carrierwave", "documents", "980190963"))
FileUtils.rm_rf(Rails.root.join("test", "storage", "carrierwave", "documents", "980190964"))
FileUtils.rm_rf(Rails.root.join("test", "storage", "carrierwave", "documents", "980190965"))
FileUtils.rm_rf(Rails.root.join("test", "storage", "carrierwave", "documents", "980190966"))
end
def after_teardown
super
remove_uploaded_files
end
end
end