Permalink
Browse files

more misc fixes

  • Loading branch information...
Raekye committed Jul 2, 2018
1 parent 32ca23c commit 60338d3082e348e3b56cff033451ee448a63eb2c
@@ -6,10 +6,10 @@
<% else %>
<%= simple_form_for @server, url: new_server_path do |f| %>
<%= f.input :name, input_html: { size: 32 }, required: true %>
<%= f.input :remote_size_slug, collection: @do_sizes.collect { |x| [x.descriptor, x.slug] }, as: :select, include_blank: false, label: 'Size' %>
<%= f.input :remote_region_slug, collection: @do_regions.collect { |x| [x.name, x.slug] }, as: :select, include_blank: false, label: "Region (#{link_to('higher tier better', 'https://en.wikipedia.org/wiki/Data_center#Data_center_tiers')})".html_safe %>
<%= f.input :remote_size_slug, collection: @do_sizes.collect { |x| [x.descriptor, x.slug] }, as: :select, include_blank: true, label: 'Size' %>
<%= f.input :remote_region_slug, collection: @do_regions.collect { |x| [x.name, x.slug] }, as: :select, include_blank: true, label: "Region (#{link_to('higher tier better', 'https://en.wikipedia.org/wiki/Data_center#Data_center_tiers')})".html_safe %>
<%= f.simple_fields_for :minecraft do |s_f| %>
<%= s_f.input :flavour, collection: Gamocosm::MINECRAFT_FLAVOURS.collect { |k, v| [v[:name], k] }, as: :select, include_blank: false, label: 'Minecraft flavour', required: true %>
<%= s_f.input :flavour, collection: Gamocosm::MINECRAFT_FLAVOURS.collect { |k, v| [v[:name], k] }, as: :select, include_blank: true, label: 'Minecraft flavour', required: true %>
<% end %>
<div>
<%= render partial: 'flavour', collection: Gamocosm::MINECRAFT_FLAVOURS.map { |k, v| [k, v] } %>
@@ -52,7 +52,7 @@ def teardown
sign_in @owner
begin
old_server_count = Server.count
post :create, {
post :create, params: {
server: {
name: 'test2',
remote_region_slug: 'ams3',
@@ -67,20 +67,20 @@ def teardown
assert_redirected_to server_path(s2)
assert_not_nil flash[:success], 'No new server message'
s2.update_columns(remote_id: 1)
delete :destroy, { id: s2.id }
delete :destroy, params: { id: s2.id }
assert_redirected_to servers_path
assert_equal 'Server is deleting', flash[:success], 'Server delete not success'
assert_equal old_server_count, Server.count, 'Server not actually deleted'
ensure
Server.destroy_all(name: 'test2')
Server.where(name: 'test2').destroy_all
end
end

test 'create server bad input' do
mock_do_base(200)
sign_in @owner
begin
post :create, {
post :create, params: {
server: {
name: 'test2',
remote_region_slug: 'ams3',
@@ -94,7 +94,7 @@ def teardown
assert_equal 'Something went wrong. Please try again', flash[:error], 'Should have failed creating server with bad input'
assert_select 'span.help-block', 'Invalid flavour'
ensure
Server.destroy_all(name: 'test2')
Server.where(name: 'test2').destroy_all
end
end

@@ -211,7 +211,7 @@ def teardown
mock_mcsw_exec(@server.minecraft).stub_mcsw_exec(200, 'help')
sign_in @owner
@server.update_columns(remote_id: 1)
post :command, { id: @server.id, command: { data: 'help' } }
post :command, params: { id: @server.id, command: { data: 'help' } }
assert_redirected_to server_path(@server)
assert_equal 'Command sent', flash[:success], 'Minecraft exec command not successful'
end
@@ -247,19 +247,19 @@ def teardown
remote_region_slug: 'nyc3',
remote_size_slug: '1gb',
}
put :update, { id: @server.id, server: {
put :update, params: { id: @server.id, server: {
setup_stage: 0,
remote_size_slug: ' 512mb ',
remote_region_slug: 'nyc3',
} }
assert_redirected_to server_path(@server)
# reset values
view_server @server, {
view_server @server, params: {
setup_stage: 0,
remote_region_slug: 'nyc3',
remote_size_slug: '512mb',
}
put :update, { id: @server.id, server: {
put :update, params: { id: @server.id, server: {
size_slug: ' ',
remote_region_slug: "\n",
} }
@@ -548,7 +548,7 @@ def remove_friend_from_server(server, friend)
}
assert_redirected_to servers_path
assert_match /added ssh public key/i, flash[:success], 'Adding Digital Ocean SSH key not success'
post :destroy_digital_ocean_ssh_key, {
post :destroy_digital_ocean_ssh_key, params: {
id: 1,
}
assert_redirected_to servers_path
@@ -78,7 +78,7 @@ def stop_server(minecraft)
=end
def create_server(name, flavour, remote_region_slug, remote_size_slug)
old_servers_count = Server.count
post servers_path, { server: {
post servers_path, params: { server: {
name: name,
remote_region_slug: remote_region_slug,
remote_size_slug: remote_size_slug,
@@ -3,15 +3,15 @@
class CloudFlareTest < ActiveSupport::TestCase

def setup
@cloudflare = CloudFlare::Client.new(Gamocosm::CLOUDFLARE_EMAIL, Gamocosm::CLOUDFLARE_API_TOKEN, Gamocosm::USER_SERVERS_DOMAIN)
@cloudflare = CloudFlare::Client.new(Gamocosm::CLOUDFLARE_EMAIL, Gamocosm::CLOUDFLARE_API_TOKEN, Gamocosm::USER_SERVERS_DOMAIN, Gamocosm::CLOUDFLARE_ZONE)
end

def teardown
end

test 'error responses' do
mock_cloudflare.stub_cf_dns_list(400, 'success', []).times_only(1)
res = @cloudflare.dns_list
res = @cloudflare.dns_list(nil)
assert res.error?, 'CloudFlare response should have been an error 400'
assert_equal 'CloudFlare API error: HTTP response code 400, {"result"=>"success", "response"=>{"recs"=>{"objs"=>[]}}}', res.msg

@@ -51,13 +51,6 @@ def teardown
assert_equal 'CloudFlare API error: HTTP response code 400, {"result"=>"success", "response"=>{}}', res.msg
end

test 'update dns will add if not found' do
mock_cloudflare.stub_cf_dns_list(200, 'success', []).times_only(1)
mock_cloudflare.stub_cf_dns_add(200, 'success', 'abc', 'localhost').times_only(1)
res = @cloudflare.dns_update('abc', 'localhost')
assert_nil res, 'CloudFlare response should have been nil (no error)'
end

test 'delete non-existing domain ok' do
mock_cloudflare.stub_cf_dns_list(200, 'success', [
{ rec_id: 1, display_name: 'abc', type: 'A' },
@@ -68,7 +61,7 @@ def teardown

test 'http timeout' do
mock_cloudflare.stub_cf_request('rec_load_all', {}).to_timeout
res = @cloudflare.dns_list
res = @cloudflare.dns_list(nil)
assert res.error?, 'CloudFlare response should have been a network exception'
assert_equal 'CloudFlare API network exception: execution expired', res.msg
end

0 comments on commit 60338d3

Please sign in to comment.