Skip to content

Commit dbf8834

Browse files
authored
Merge branch 'master' into toshifumi/write-warning
2 parents 535b8cc + 9162079 commit dbf8834

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

app/controllers/admin/contests_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def update_from_json
7373
name_en: json[:contest_name] || @contest.name_en
7474
)
7575
@contest.problems.destroy_all
76-
json[:problems].each.with_index(1) do |problem_json, i|
76+
json[:problems].each.with_index do |problem_json, i|
7777
problem = Problem.create(
7878
contest_id: @contest.id,
7979
name_ja: problem_json[:title],
@@ -82,7 +82,7 @@ def update_from_json
8282
description_en: problem_json[:statement],
8383
order: i
8484
)
85-
problem_json[:data_sets].each.with_index(1) do |data_set_json, j|
85+
problem_json[:data_sets].each.with_index do |data_set_json, j|
8686
DataSet.create(
8787
problem_id: problem.id,
8888
label: data_set_json[:label],

app/models/problem.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Problem < ApplicationRecord
22
belongs_to :contest
3-
has_many :data_sets, dependent: :destroy
3+
has_many :data_sets, -> { order(:order) }, dependent: :destroy
44
has_many :submissions, through: :data_sets
55

66
def name

spec/controllers/admin/contests_controller_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@
105105
updated_contest = Contest.find_by(id: contest.id)
106106
expect(response).to redirect_to admin_contest_path(contest)
107107
expect(updated_contest.name_ja).to eq json[:contest_name]
108-
expect(updated_contest.problems.size).to eq 1
109-
expect(updated_contest.problems.first.name_ja).to eq 'A + B'
110-
expect(updated_contest.problems.first.data_sets.size).to eq 1
111-
expect(updated_contest.problems.first.data_sets.first.label).to eq 'Small'
108+
expect(updated_contest.problems.size).to eq json[:problems].size
109+
expect(updated_contest.problems.first.name_ja).to eq json[:problems].first[:title]
110+
expect(updated_contest.problems.first.order).to eq 0
111+
expect(updated_contest.problems.first.data_sets.size).to eq json[:problems].first[:data_sets].size
112+
expect(updated_contest.problems.first.data_sets.first.label).to eq json[:problems].first[:data_sets].first[:label]
112113
end
113114
end
114115

src/contests/Problem.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,9 @@ export default class Problem extends React.Component<ProblemProps, ProblemState>
134134
<textarea
135135
className="problem--answer"
136136
name="answer"
137-
placeholder={`このテキストボックスに解答(作成したプログラムにデータセットを入力して得られた実行結果)を貼り付けて、右下の提出ボタンを押してください。
138-
139-
入力となるデータセットはフォームの右上のリンクからダウンロードできます。
140-
データセットは2種類あるので、SmallもしくはLargeを押して選択してから、ダウンロードしてください。`}
137+
placeholder={`このテキストボックスに解答(作成したプログラムにデータセットを入力して得られた実行結果)を貼り付けて、右下の提出ボタンを押してください。\n\n${
138+
this.props.problem.dataSets.length >= 2 ? `データセットの種類を選択してから、` : ``
139+
}入力となるデータをフォームの右上のリンクからダウンロードしてください。`}
141140
value={this.selectedDataSet().answer}
142141
rows={Math.max(6, Math.min(18, this.selectedDataSet().answer.split('\n').length))}
143142
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>): void => {

0 commit comments

Comments
 (0)