Add testing utilities and improve test coverage with FactoryBot integration
- Added `shoulda-matchers` for enhanced RSpec testing capabilities. - Introduced `factory_bot_rails` for easier test data creation. - Created factories for `HttpLogEntry`, `BlobEntry`, and `Domain::Fa::Post` models. - Updated `rails_helper.rb` to include FactoryBot methods and configure Shoulda matchers. - Enhanced `HttpLogEntry` model with a new `response_size` method. - Refactored `justfile` to include parallel test execution. - Improved `Gemfile` and `Gemfile.lock` with new testing gems.
This commit is contained in:
@@ -3,6 +3,7 @@ require "test_helper"
|
||||
class Domain::Fa::UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = TestUtil.build_fa_user
|
||||
@user.registered_at = 1.year.ago
|
||||
@user.save!
|
||||
end
|
||||
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class HttpLogEntryTest < ActiveSupport::TestCase
|
||||
def make_required_params
|
||||
{
|
||||
request_headers_id: TestUtil.create_http_headers.id,
|
||||
response_headers_id: TestUtil.create_http_headers.id,
|
||||
response_sha256: TestUtil.create_blob_entry.sha256,
|
||||
response_time_ms: 125,
|
||||
content_type: "test/text",
|
||||
verb: :get,
|
||||
requested_at: Time.now,
|
||||
uri_scheme: "https",
|
||||
uri_host: "example.com",
|
||||
uri_path: "/foo/bar",
|
||||
status_code: 200,
|
||||
performed_by: "direct"
|
||||
}
|
||||
end
|
||||
|
||||
test "requires required params" do
|
||||
model = ::HttpLogEntry.new(make_required_params)
|
||||
assert model.valid?, model.errors.full_messages
|
||||
|
||||
make_required_params.keys.each do |target_key|
|
||||
params_without_key = make_required_params
|
||||
params_without_key.delete(target_key)
|
||||
refute ::HttpLogEntry.new(params_without_key).valid?
|
||||
end
|
||||
end
|
||||
|
||||
test "uri is correct" do
|
||||
uri_str =
|
||||
"https://www.example.com/big/path/here?and=query&other=query2#smaz"
|
||||
uri = Addressable::URI.parse(uri_str)
|
||||
model = ::HttpLogEntry.new({ uri: uri_str })
|
||||
assert_equal "https", model.uri_scheme
|
||||
assert_equal "www.example.com", model.uri_host
|
||||
assert_equal "/big/path/here", model.uri_path
|
||||
assert_equal "and=query&other=query2", model.uri_query
|
||||
assert_equal "smaz", model.uri_hash
|
||||
assert_equal uri, model.uri
|
||||
assert_equal uri_str, model.uri_str
|
||||
end
|
||||
|
||||
test "model cannot be updated" do
|
||||
model = ::HttpLogEntry.new(make_required_params)
|
||||
model.save!
|
||||
model.verb = :post
|
||||
assert_raises(ActiveRecord::ReadOnlyRecord) { model.save! }
|
||||
model.reload
|
||||
assert_equal "get", model.verb
|
||||
end
|
||||
|
||||
test "model cannot be deleted" do
|
||||
model = ::HttpLogEntry.new(make_required_params)
|
||||
model.save!
|
||||
assert_raises(ActiveRecord::ReadOnlyRecord) { model.destroy }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user