tabletop-companion/test/test_helper.rb

32 lines
867 B
Ruby
Raw Normal View History

2024-05-26 10:45:10 +00:00
# frozen_string_literal: true
2024-04-13 10:22:40 +00:00
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
module ActiveSupport
class TestCase
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
2024-04-14 10:10:10 +00:00
def assert_must_exist(record, field)
assert record.valid?
record.attributes = { "#{field}": nil }
assert_not record.valid?
assert_includes record.errors[field.to_sym], "can't be blank"
assert_raises { record.save(validate: false) }
end
2024-04-21 12:23:37 +00:00
def attr_name(klass, attr)
klass.human_attribute_name(attr)
end
2024-05-26 09:34:09 +00:00
def sign_in(user, password: "password")
post sessions_path, params: { username: user.username, password: password }
end
2024-04-13 10:22:40 +00:00
end
end