From e09a6ed6d64bdd5b3f4975fd48976a88618a89a1 Mon Sep 17 00:00:00 2001 From: Adrian Gonzalez Date: Mon, 13 May 2013 17:16:13 -0400 Subject: [PATCH] Changed settings to always have a numeric suffix starting with 0. --- .../stash/hook/MirrorRepositoryHook.java | 5 ++--- .../resources/static/mirror-repository-hook.js | 4 +--- .../static/mirror-repository-hook.soy | 2 +- .../stash/hook/MirrorRepositoryHookTest.java | 18 +++++++++--------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java b/src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java index f6d1a4a..7cd9636 100644 --- a/src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java +++ b/src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java @@ -210,10 +210,9 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep ms.mirrorRepoUrl = settings.getString(SETTING_MIRROR_REPO_URL + suffix, ""); ms.username = settings.getString(SETTING_USERNAME + suffix, ""); ms.password = settings.getString(SETTING_PASSWORD + suffix, ""); - ms.suffix = count > 0 ? String.valueOf(count) : ""; - results.add(ms); + ms.suffix = String.valueOf(count++); - count++; + results.add(ms); } } diff --git a/src/main/resources/static/mirror-repository-hook.js b/src/main/resources/static/mirror-repository-hook.js index a75f6cf..8a1126c 100644 --- a/src/main/resources/static/mirror-repository-hook.js +++ b/src/main/resources/static/mirror-repository-hook.js @@ -3,7 +3,7 @@ define('et/hook/mirror', ['jquery', 'exports'], function ($, exports) { exports.init = function (createSubView, createButton) { $('#et-add-button').click(function () { try { - var currIndex, index, name, html; + var currIndex, index = 0, name, html; // Determine the current index from the last password input name = $('div.hook-config-contents input:password').last().attr("name"); @@ -11,8 +11,6 @@ define('et/hook/mirror', ['jquery', 'exports'], function ($, exports) { if (name && name.length >= 8) { currIndex = parseInt(name.substring(8)); index = (isNaN(currIndex) ? 0 : currIndex) + 1; - } else { - index = ''; } // Insert template after last field-group div diff --git a/src/main/resources/static/mirror-repository-hook.soy b/src/main/resources/static/mirror-repository-hook.soy index 8321ba9..6cf1d39 100644 --- a/src/main/resources/static/mirror-repository-hook.soy +++ b/src/main/resources/static/mirror-repository-hook.soy @@ -8,7 +8,7 @@ // Always add one subview {call .subview data="all"} - {param index: '' /} + {param index: 0 /} {/call} // Add additional mirrors, up to 10 total diff --git a/src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java b/src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java index b8f4da8..1a4bdb6 100644 --- a/src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java +++ b/src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java @@ -186,22 +186,22 @@ public class MirrorRepositoryHookTest { Settings settings = mock(Settings.class); Map map = new HashMap(); - map.put(MirrorRepositoryHook.SETTING_MIRROR_REPO_URL, ""); + map.put(MirrorRepositoryHook.SETTING_MIRROR_REPO_URL + "0", ""); when(settings.asMap()).thenReturn(map); - when(settings.getString(eq(MirrorRepositoryHook.SETTING_MIRROR_REPO_URL), eq(""))) + when(settings.getString(eq(MirrorRepositoryHook.SETTING_MIRROR_REPO_URL + "0"), eq(""))) .thenThrow(new RuntimeException("Intentional unit test exception")) .thenReturn("") .thenReturn("invalid uri") .thenReturn("http://should-not:have-user@stash-mirror.englishtown.com/scm/test/test.git") .thenReturn(mirrorRepoUrl); - when(settings.getString(eq(MirrorRepositoryHook.SETTING_USERNAME), eq(""))) + when(settings.getString(eq(MirrorRepositoryHook.SETTING_USERNAME + "0"), eq(""))) .thenReturn("") .thenReturn(username); - when(settings.getString(eq(MirrorRepositoryHook.SETTING_PASSWORD), eq(""))) + when(settings.getString(eq(MirrorRepositoryHook.SETTING_PASSWORD + "0"), eq(""))) .thenReturn("") .thenReturn(password); @@ -215,20 +215,20 @@ public class MirrorRepositoryHookTest { errors = mock(SettingsValidationErrors.class); hook.validate(settings, errors, repo); verify(errors, never()).addFormError(anyString()); - verify(errors).addFieldError(eq(MirrorRepositoryHook.SETTING_MIRROR_REPO_URL), anyString()); - verify(errors).addFieldError(eq(MirrorRepositoryHook.SETTING_USERNAME), anyString()); - verify(errors).addFieldError(eq(MirrorRepositoryHook.SETTING_PASSWORD), anyString()); + verify(errors).addFieldError(eq(MirrorRepositoryHook.SETTING_MIRROR_REPO_URL + "0"), anyString()); + verify(errors).addFieldError(eq(MirrorRepositoryHook.SETTING_USERNAME + "0"), anyString()); + verify(errors).addFieldError(eq(MirrorRepositoryHook.SETTING_PASSWORD + "0"), anyString()); errors = mock(SettingsValidationErrors.class); hook.validate(settings, errors, repo); verify(errors, never()).addFormError(anyString()); - verify(errors).addFieldError(eq(MirrorRepositoryHook.SETTING_MIRROR_REPO_URL), anyString()); + verify(errors).addFieldError(eq(MirrorRepositoryHook.SETTING_MIRROR_REPO_URL + "0"), anyString()); verify(errors).addFieldError(anyString(), anyString()); errors = mock(SettingsValidationErrors.class); hook.validate(settings, errors, repo); verify(errors, never()).addFormError(anyString()); - verify(errors).addFieldError(eq(MirrorRepositoryHook.SETTING_MIRROR_REPO_URL), anyString()); + verify(errors).addFieldError(eq(MirrorRepositoryHook.SETTING_MIRROR_REPO_URL + "0"), anyString()); verify(errors).addFieldError(anyString(), anyString()); when(passwordEncryptor.isEncrypted(anyString())).thenReturn(true);