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

WIP: Upload test #275

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions spec/factories/task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :task do
display_name { '1st USA olympiad task number 1' }
file_names { ['task1.md'] }
end
end
42 changes: 42 additions & 0 deletions spec/features/upload_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'rails_helper'

RSpec.describe 'Upload', ui: true do

Check notice

Code scanning / Rubocop

Use consistent metadata style. Note test

RSpec/MetadataStyle: Use symbol style for metadata.
let(:upload_path) { "/contests/#{contest.id}/upload/new" }
let(:file_path) { "/contests/#{contest.id}/upload" }

let(:contest) { create(:contest) }

Check notice

Code scanning / Rubocop

Use parentheses for method calls with arguments. Note test

Style/MethodCallWithArgsParentheses: Omit parentheses for method calls with arguments.
let!(:task) { create(:task, contest:) }

Check notice

Code scanning / Rubocop

Use parentheses for method calls with arguments. Note test

Style/MethodCallWithArgsParentheses: Omit parentheses for method calls with arguments.
let(:user) { create(:user, contest:) }

Check notice

Code scanning / Rubocop

Use parentheses for method calls with arguments. Note test

Style/MethodCallWithArgsParentheses: Omit parentheses for method calls with arguments.

before { visit upload_path }

describe 'solution for task' do
before do
fill_inputs 'upload', user.slice(:secret)
click_button 'commit'
end

context 'with valid file' do
before do
# TODO: FIX upload[solutions_attributes][0][file]
attach_file 'upload[solutions_attributes][0][file]', 'spec/support/fixtures/tasks_solutions/task1_ok/task1.md'
click_button 'commit'
end

it { expect(page).to have_content "#{task.display_name}: успішно завантажений на сервер" }
end

context 'with empty file' do
before do
# TODO: FIX upload[solutions_attributes][0][file]
attach_file 'upload[solutions_attributes][0][file]', 'spec/support/fixtures/tasks_solutions/task1_empty/task1.md'
click_button 'commit'
end

it {
expect(page).to have_content \
"#{task.display_name}: Помилка! Файл не може бути порожнім (0 байт). Можливо, файл відкрито у програмі MS Office."
}
end
end
end
Empty file.
1 change: 1 addition & 0 deletions spec/support/fixtures/tasks_solutions/task1_ok/task1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Some task solution