Browse Source

Changed settings to always have a numeric suffix starting with 0.

pull/7/head
Adrian Gonzalez 12 years ago
parent
commit
e09a6ed6d6
  1. 5
      src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java
  2. 4
      src/main/resources/static/mirror-repository-hook.js
  3. 2
      src/main/resources/static/mirror-repository-hook.soy
  4. 18
      src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java

5
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);
}
}

4
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

2
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

18
src/test/java/com/englishtown/stash/hook/MirrorRepositoryHookTest.java

@ -186,22 +186,22 @@ public class MirrorRepositoryHookTest {
Settings settings = mock(Settings.class);
Map<String, Object> map = new HashMap<String, Object>();
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);

Loading…
Cancel
Save