Skip to content

Commit dbf3857

Browse files
committed
/series/add: use slug instead of id in <select>.
Unbreak integration tests that failed because country was disappearing after series creation.
1 parent e32f397 commit dbf3857

File tree

5 files changed

+6
-50
lines changed

5 files changed

+6
-50
lines changed

src/main/java/ru/mystamps/web/controller/SeriesController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ public Iterable<SelectEntityDto> getCategories(Locale userLocale) {
113113
}
114114

115115
@ModelAttribute("countries")
116-
public Iterable<SelectEntityDto> getCountries(Locale userLocale) {
116+
public Iterable<LinkEntityDto> getCountries(Locale userLocale) {
117117
String lang = LocaleUtils.getLanguageOrNull(userLocale);
118-
return countryService.findAllAsSelectEntities(lang);
118+
return countryService.findAllAsLinkEntities(lang);
119119
}
120120

121121
@RequestMapping(Url.ADD_SERIES_PAGE)

src/main/java/ru/mystamps/web/service/CountryService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121

2222
import ru.mystamps.web.service.dto.AddCountryDto;
2323
import ru.mystamps.web.service.dto.LinkEntityDto;
24-
import ru.mystamps.web.service.dto.SelectEntityDto;
2524
import ru.mystamps.web.service.dto.UrlEntityDto;
2625

2726
public interface CountryService {
2827
UrlEntityDto add(AddCountryDto dto, Integer userId);
29-
Iterable<SelectEntityDto> findAllAsSelectEntities(String lang);
3028
Iterable<LinkEntityDto> findAllAsLinkEntities(String lang);
3129
LinkEntityDto findOneAsLinkEntity(String slug, String lang);
3230
long countAll();

src/main/java/ru/mystamps/web/service/CountryServiceImpl.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import ru.mystamps.web.dao.dto.AddCountryDbDto;
3737
import ru.mystamps.web.service.dto.AddCountryDto;
3838
import ru.mystamps.web.service.dto.LinkEntityDto;
39-
import ru.mystamps.web.service.dto.SelectEntityDto;
4039
import ru.mystamps.web.service.dto.UrlEntityDto;
4140
import ru.mystamps.web.util.SlugUtils;
4241

@@ -80,12 +79,6 @@ public UrlEntityDto add(AddCountryDto dto, Integer userId) {
8079
return new UrlEntityDto(id, slug);
8180
}
8281

83-
@Override
84-
@Transactional(readOnly = true)
85-
public Iterable<SelectEntityDto> findAllAsSelectEntities(String lang) {
86-
return countryDao.findAllAsSelectEntities(lang);
87-
}
88-
8982
@Override
9083
@Transactional(readOnly = true)
9184
public Iterable<LinkEntityDto> findAllAsLinkEntities(String lang) {

src/main/webapp/WEB-INF/views/series/add.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ <h3 th:text="${#strings.capitalize(add_series)}">
153153
<select id="country" class="form-control" th:field="*{country}">
154154
<option value="" th:text="#{t_not_chosen}">Not chosen</option>
155155
<!--/*/
156-
<option th:each="country : ${countries}" th:value="${country.id}" th:text="${country.name}"></option>
156+
<option th:each="country : ${countries}" th:value="${country.slug}" th:text="${country.name}"></option>
157157
/*/-->
158158
<!--/*-->
159-
<option value="1">Russia</option>
160-
<option value="2">Canada</option>
161-
<option value="3">Italy</option>
159+
<option value="russia">Russia</option>
160+
<option value="canada">Canada</option>
161+
<option value="italy">Italy</option>
162162
<!--*/-->
163163
</select>
164164
<small sec:authorize="hasAuthority('CREATE_COUNTRY')">

src/test/groovy/ru/mystamps/web/service/CountryServiceImplTest.groovy

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import ru.mystamps.web.dao.JdbcCountryDao
2424
import ru.mystamps.web.dao.dto.AddCountryDbDto
2525
import ru.mystamps.web.model.AddCountryForm
2626
import ru.mystamps.web.service.dto.LinkEntityDto
27-
import ru.mystamps.web.service.dto.SelectEntityDto
2827
import ru.mystamps.web.service.dto.UrlEntityDto
2928
import ru.mystamps.web.tests.DateUtils
3029
import ru.mystamps.web.util.SlugUtils
@@ -191,40 +190,6 @@ class CountryServiceImplTest extends Specification {
191190
}) >> 80
192191
}
193192

194-
//
195-
// Tests for findAllAsSelectEntities(String)
196-
//
197-
198-
def "findAllAsSelectEntities(String) should call dao"() {
199-
given:
200-
SelectEntityDto country1 = new SelectEntityDto(1, 'First Country')
201-
and:
202-
SelectEntityDto country2 = new SelectEntityDto(2, 'Second Country')
203-
and:
204-
List<SelectEntityDto> expectedCountries = [ country1, country2 ]
205-
and:
206-
countryDao.findAllAsSelectEntities(_ as String) >> expectedCountries
207-
when:
208-
Iterable<SelectEntityDto> resultCountries = service.findAllAsSelectEntities('de')
209-
then:
210-
resultCountries == expectedCountries
211-
}
212-
213-
@Unroll
214-
def "findAllAsSelectEntities(String) should pass language '#expectedLanguage' to dao"(String expectedLanguage) {
215-
when:
216-
service.findAllAsSelectEntities(expectedLanguage)
217-
then:
218-
1 * countryDao.findAllAsSelectEntities({ String language ->
219-
assert language == expectedLanguage
220-
return true
221-
})
222-
where:
223-
expectedLanguage | _
224-
'ru' | _
225-
null | _
226-
}
227-
228193
//
229194
// Tests for findAllAsLinkEntities(String)
230195
//

0 commit comments

Comments
 (0)