Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1532 Do not allow words that are digits #1583

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a433132
1532 Do not allow words that are digits
tomaszsmy Jul 9, 2022
fed3ea0
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
nya-elimu Jul 11, 2022
1490342
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
nya-elimu Jul 11, 2022
f1d8a6a
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
nya-elimu Jul 11, 2022
e425202
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
nya-elimu Jul 11, 2022
c76e817
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
nya-elimu Jul 12, 2022
3754339
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
nya-elimu Jul 20, 2022
0644d26
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
nya-elimu Jul 20, 2022
e744533
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
tomaszsmy Jul 21, 2022
fcd512d
1532 Do not allow words that are digits
tomaszsmy Jul 21, 2022
297e9f2
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
nya-elimu Jul 22, 2022
f221ee0
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
nya-elimu Jul 22, 2022
9418962
1532 Do not allow words that are digits
tomaszsmy Jul 22, 2022
7600e9b
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
tomaszsmy Jul 24, 2022
8357c9d
1532 Do not allow words that are digits
tomaszsmy Jul 24, 2022
9e81b60
1532 Do not allow words that are digits
tomaszsmy Jul 25, 2022
b97b2ec
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
nya-elimu Aug 5, 2022
8d97ff3
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
tomaszsmy Aug 26, 2022
e5c5774
1532 Do not allow words that are digits
tomaszsmy Aug 26, 2022
bb1e164
Merge remote-tracking branch 'origin/main' into 1532_Do_not_allow_wor…
tomaszsmy Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into 1532_Do_not_allow_words_that_are_digits
# Conflicts:
#	src/main/java/ai/elimu/web/content/word/WordCreateController.java
#	src/test/java/ai/elimu/web/content/word/WordCreateControllerTest.java
  • Loading branch information
tomaszsmy committed Aug 26, 2022
commit 8d97ff3ac87add09e553a4c4e9d2969cbf89dfc2
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,16 @@ public String handleSubmit(
Model model) {
logger.info("handleSubmit");

validateWord(word, result);
Word existingWord = wordDao.readByTextAndType(word.getText(), word.getWordType());
if (existingWord != null) {
result.rejectValue("text", "NonUnique");
}

if (StringUtils.containsAny(word.getText(), " ")) {
result.rejectValue("text", "WordSpace");
}
validateWord(word, result);

if (result.hasErrors()) {
model.addAttribute("word", word);
model.addAttribute("timeStart", request.getParameter("timeStart"));
Expand Down Expand Up @@ -271,7 +279,7 @@ private void autoSelectLetterSoundCorrespondences(Word word) {
}

private void validateWord(Word word, BindingResult result) {
Word existingWord = wordDao.readByText(word.getText());
Word existingWord = wordDao.readByTextAndType(word.getText());

if (existingWord != null) {
result.rejectValue("text", "NonUnique");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package ai.elimu.web.content.word;

import ai.elimu.dao.WordDao;
import ai.elimu.model.content.Word;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -29,12 +35,12 @@ public class WordCreateControllerTest {

@Autowired
private WordCreateController wordCreateController;

private MockMvc mockMvc;

@Autowired
private WordDao wordDao;

@Before
public void setup() {
assertNotNull(wordCreateController);
Expand Down Expand Up @@ -62,6 +68,31 @@ public void testHandleSubmit_emptyText() throws Exception {
// assertEquals("content/word/create", mvcResult.getModelAndView().getViewName());
}

@Test
public void testHandleSubmit_success() throws Exception {
Word wordHello = wordDao.readByText("hello");
assertThat(wordHello, is(nullValue()));

int numberOfWordsBefore = wordDao.readAll().size();

RequestBuilder requestBuilder = MockMvcRequestBuilders
.post("/content/word/create")
.param("timeStart", String.valueOf(System.currentTimeMillis()))
.param("text", "hello")
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
MvcResult mvcResult = mockMvc.perform(requestBuilder).andReturn();

wordHello = wordDao.readByText("hello");
assertThat(wordHello, not(nullValue()));
assertThat(wordHello.getText(), is("hello"));

int numberOfWordsAfter = wordDao.readAll().size();
assertThat(numberOfWordsAfter, is(numberOfWordsBefore + 1));

assertEquals(HttpStatus.MOVED_TEMPORARILY.value(), mvcResult.getResponse().getStatus());
assertEquals("redirect:/content/word/list#" + wordHello.getId(), mvcResult.getModelAndView().getViewName());
}

@Test
public void testValidateDigitsInWord() throws Exception {
assertTrue(containGivenErrorCode(getBindingResult(getRequestWithSpecificText("10")).getAllErrors(), "WordNumbers"));
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.