41 lines
1.1 KiB
Ruby
41 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module RequestSpecHelper
|
|
def json_response
|
|
JSON.parse(response.body)
|
|
end
|
|
|
|
def api_key_header(client, api_key = nil)
|
|
api_key ||= [RynDNS::Application::API_KEY_PREFIX, client.name_id, client.description].join('.')
|
|
{ RynDNS::Application::API_KEY_HEADER =>
|
|
api_key }
|
|
end
|
|
|
|
def parse_permission(perm_r, perm_w, perm_x)
|
|
"#{'r' if perm_r}#{'w' if perm_w}#{'x' if perm_x}"
|
|
end
|
|
|
|
def hash_to_query_string(hash)
|
|
result = ''
|
|
hash.each do |k, v|
|
|
# escape value to be uri save
|
|
result += "#{k}=#{CGI.escape(v.to_s)}&"
|
|
end
|
|
result.delete_suffix('&')
|
|
end
|
|
|
|
def list_equals_db?(client_list)
|
|
return false unless Client.count == client_list.count
|
|
|
|
client_list.each do |client|
|
|
db_client = Client.find_by name: client[:name.to_s]
|
|
return false unless db_client.description == client[:description.to_s] &&
|
|
db_client.permission == client[:permission.to_s] &&
|
|
db_client.public_ip == client[:public_ip.to_s] &&
|
|
db_client.ipv4 == client[:ipv4.to_s]
|
|
end
|
|
true
|
|
end
|
|
|
|
end
|