TEST: core/models legacybrwosseruseragents optioncache specs

This commit is contained in:
Jake Webster
2026-01-22 17:38:58 +10:00
parent 32af09b248
commit 6377b02c4f
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
RSpec.describe BeEF::Core::Models::LegacyBrowserUserAgents do
describe '.user_agents' do
it 'returns an array' do
expect(described_class.user_agents).to be_a(Array)
end
it 'returns an array that can be iterated' do
result = described_class.user_agents.map { |ua| ua }
expect(result).to be_a(Array)
end
end
end

View File

@@ -0,0 +1,54 @@
RSpec.describe BeEF::Core::Models::OptionCache do
describe '.first_or_create' do
it 'creates a new option cache with a name' do
name = 'test_option'
option = described_class.first_or_create(name: name)
expect(option).to be_persisted
expect(option.name).to eq(name)
expect(option.value).to be_nil
end
it 'returns existing option cache if it already exists' do
name = 'existing_option'
existing = described_class.create!(name: name, value: 'existing_value')
option = described_class.first_or_create(name: name)
expect(option.id).to eq(existing.id)
expect(option.name).to eq(name)
expect(option.value).to eq('existing_value')
end
end
describe '.where' do
it 'finds option cache by name' do
name = 'findable_option'
described_class.create!(name: name, value: 'test_value')
option = described_class.where(name: name).first
expect(option).not_to be_nil
expect(option.name).to eq(name)
expect(option.value).to eq('test_value')
end
it 'returns nil when option cache does not exist' do
option = described_class.where(name: 'non_existent').first
expect(option).to be_nil
end
end
describe 'attributes' do
it 'can set and retrieve name' do
option = described_class.new(name: 'test_name')
expect(option.name).to eq('test_name')
end
it 'can set and retrieve value' do
option = described_class.new(value: 'test_value')
expect(option.value).to eq('test_value')
end
end
end