Skip to content

Commit

Permalink
月のサイズを10以上にする
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatsumi0000 committed Oct 29, 2023
1 parent dba4bc0 commit d60e24a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions web/backend/app/models/converter/text_to_moon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class TextToMoon
CONVERT_SIZE = 4

attribute :text, :string
attribute :size, :integer, default: 20
attribute :size, :integer, default: 10

validates :text, presence: true
validates :text, length: { minimum: 1, maximum: 20 }
validates :text, length: { minimum: 1, maximum: 10 }
validates :text, format: { with: /\A[ぁ-んァ-ンa-zA-Z0-9ー0-9A-Za-z  ]+\z/, message: '変換できるのは全角半角英数字、ひらがなカタカナのみです。' }
validates :size, numericality: { only_integer: true, greater_than_or_equal_to: 20, less_than_or_equal_to: 100 }

Expand Down
12 changes: 6 additions & 6 deletions web/backend/spec/models/converter/text_to_moon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@

context 'textに半角全角英数字、ひらがなカタカナの文字が含まれているとき' do
it 'ひらがなのみなのでエラーにならないことを確認' do
text_to_moon = Converter::TextToMoon.new(text: 'あいうえお', size: 20)
text_to_moon = Converter::TextToMoon.new(text: 'あいうえお', size: 10)
expect(text_to_moon.valid?).to be true
end

it 'カタカナのみなのでエラーにならないことを確認' do
text_to_moon = Converter::TextToMoon.new(text: 'アイウエオ', size: 20)
text_to_moon = Converter::TextToMoon.new(text: 'アイウエオ', size: 10)
expect(text_to_moon.valid?).to be true
end

it '半角英数字のみなのでエラーにならないことを確認' do
text_to_moon = Converter::TextToMoon.new(text: 'abcde12345', size: 20)
text_to_moon = Converter::TextToMoon.new(text: 'abcde12345', size: 10)
expect(text_to_moon.valid?).to be true
end

it '全角英数字のみなのでエラーにならないことを確認' do
text_to_moon = Converter::TextToMoon.new(text: 'ABCDE12345', size: 20)
text_to_moon = Converter::TextToMoon.new(text: 'ABCDE12345', size: 10)
expect(text_to_moon.valid?).to be true
end

it 'textとsizeに受け取ったパラメータが設定されていることを確認' do
text_to_moon = Converter::TextToMoon.new(text: 'ABCDE12345', size: 20)
text_to_moon = Converter::TextToMoon.new(text: 'ABCDE12345', size: 10)
response = text_to_moon.call
expect(response[:text]).to eq 'ABCDE12345'
expect(response[:size]).to eq 20
expect(response[:size]).to eq 10
end

end
Expand Down
14 changes: 7 additions & 7 deletions web/frontend/src/pages/TopPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { computed } from "vue";
import { ComputedRef } from "vue";
import { reactive } from "vue";
const size = ref<number>(20);
const size = ref<number>(10);
const text = ref<string>("");
const isValid = ref<boolean>(false);
const response = ref<string[]>([]);
Expand All @@ -37,10 +37,10 @@ const inputNumberOnly = (inputValue: string): boolean | string => {
const regex = /^[0-9]+$/;
return regex.test(inputValue) || "数字を入力してください";
};
const inputNumber20to100 = (inputValue: string): boolean | string => {
// 20 ~ 100の数字のみの入力を許可する
const regex = /^[2-9][0-9]$|^100$/;
return regex.test(inputValue) || "20 ~ 100の数字を入力してください";
const inputNumber10to100 = (inputValue: string): boolean | string => {
// 10 ~ 100の数字のみの入力を許可する
const regex = /^[1-9][0-9]$|^100$/;
return regex.test(inputValue) || "10 ~ 100の数字を入力してください";
};
const inputText1to20 = (inputValue: string): boolean | string => {
Expand Down Expand Up @@ -83,9 +83,9 @@ onErrorCaptured((err: Error) => {
<v-form @submit.prevent v-model="isValid">
<v-text-field
v-model="size"
:rules="[inputNumberOnly, inputNumber20to100]"
:rules="[inputNumberOnly, inputNumber10to100]"
label="月のサイズ"
placeholder="20 ~ 100"
placeholder="10 ~ 100"
></v-text-field>

<v-text-field
Expand Down

0 comments on commit d60e24a

Please sign in to comment.