@@ -36,4 +36,8 @@ FactoryBot.define do
|
||||
duration { "2:00" }
|
||||
ranking_mode { "actual" }
|
||||
end
|
||||
|
||||
trait :offline do
|
||||
offline_form { true }
|
||||
end
|
||||
end
|
||||
|
||||
145
spec/features/offline_spec.rb
Normal file
145
spec/features/offline_spec.rb
Normal file
@@ -0,0 +1,145 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.feature "Users", type: :feature do
|
||||
context "when the contest doesn't allow offline participation" do
|
||||
let!(:contest) { create(:contest, user: create(:user)) }
|
||||
|
||||
it "shouldn't be possible to load the offline participation form" do
|
||||
visit offline_form_path(contest)
|
||||
|
||||
expect(page).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
|
||||
context "when the contest allows offline participation" do
|
||||
let!(:contest) { create(:contest, :offline, user: create(:user)) }
|
||||
|
||||
it "should be possible to load the offline participation form" do
|
||||
visit offline_form_path(contest)
|
||||
|
||||
expect(page).to have_http_status(200)
|
||||
expect(page).to have_content(contest.name)
|
||||
end
|
||||
|
||||
it "shouldn't be possible to validate the form without a pseudo" do
|
||||
visit offline_form_path(contest)
|
||||
|
||||
fill_in I18n.t("activerecord.attributes.offline.name"), with: ""
|
||||
click_button I18n.t("helpers.buttons.start")
|
||||
|
||||
expect(page).to have_http_status(422)
|
||||
expect(page).to have_content(I18n.t("activerecord.errors.models.offline.attributes.name.blank"))
|
||||
end
|
||||
|
||||
it "shouldn't be possible to validate the form without an image" do
|
||||
visit offline_form_path(contest)
|
||||
|
||||
fill_in I18n.t("activerecord.attributes.offline.name"), with: "my_name"
|
||||
|
||||
expect { click_button I18n.t("helpers.buttons.start") }.not_to change { contest.reload.offlines.size }
|
||||
expect(page).to have_http_status(422)
|
||||
expect(page).to have_content(I18n.t("activerecord.errors.models.offline.attributes.start_image.blank"))
|
||||
end
|
||||
|
||||
it "should be possible to start the offline participation with a valid name and start image" do
|
||||
start_image_file = Tempfile.new('start_image')
|
||||
begin
|
||||
visit offline_form_path(contest)
|
||||
|
||||
fill_in I18n.t("activerecord.attributes.offline.name"), with: "my_name"
|
||||
attach_file("offline[images]", start_image_file.path)
|
||||
|
||||
expect { click_button I18n.t("helpers.buttons.start") }.to change { contest.reload.offlines.size }.to(1)
|
||||
expect(page).to have_http_status(200)
|
||||
expect(page).to have_current_path(offline_form_edit_path(contest, contest.offlines[0]))
|
||||
ensure
|
||||
start_image_file.close
|
||||
start_image_file.unlink
|
||||
end
|
||||
end
|
||||
|
||||
it "shouldn't be possible to complete the offline participation without an end image" do
|
||||
start_image_file = Tempfile.new('start_image')
|
||||
begin
|
||||
visit offline_form_path(contest)
|
||||
|
||||
fill_in I18n.t("activerecord.attributes.offline.name"), with: "my_name"
|
||||
attach_file("offline[images]", start_image_file.path)
|
||||
click_button I18n.t("helpers.buttons.start")
|
||||
|
||||
expect { click_button I18n.t("helpers.buttons.end") }.not_to change { contest.offlines[0].images.size }
|
||||
expect(page).to have_http_status(422)
|
||||
expect(page).to have_content(I18n.t("activerecord.errors.models.offline.attributes.end_image.blank"))
|
||||
ensure
|
||||
start_image_file.close
|
||||
start_image_file.unlink
|
||||
end
|
||||
end
|
||||
|
||||
it "shouldn't be possible to complete the offline participation without remaining pieces count when the puzzle isn't completed" do
|
||||
start_image_file = Tempfile.new('start_image')
|
||||
begin
|
||||
visit offline_form_path(contest)
|
||||
|
||||
fill_in I18n.t("activerecord.attributes.offline.name"), with: "my_name"
|
||||
attach_file("offline[images]", start_image_file.path)
|
||||
click_button I18n.t("helpers.buttons.start")
|
||||
|
||||
expect { click_button I18n.t("helpers.buttons.end") }.not_to change { contest.offlines[0].images.size }
|
||||
expect(page).to have_http_status(422)
|
||||
expect(page).to have_content(I18n.t("activerecord.errors.models.offline.attributes.remaining_pieces.blank"))
|
||||
ensure
|
||||
start_image_file.close
|
||||
start_image_file.unlink
|
||||
end
|
||||
end
|
||||
|
||||
it "should be possible to complete the offline participation with the end image and remaining pieces count when the puzzle isn't completed" do
|
||||
start_image_file = Tempfile.new('start_image')
|
||||
end_image_file = Tempfile.new('end_image')
|
||||
begin
|
||||
visit offline_form_path(contest)
|
||||
|
||||
fill_in I18n.t("activerecord.attributes.offline.name"), with: "my_name"
|
||||
attach_file("offline[images]", start_image_file.path)
|
||||
click_button I18n.t("helpers.buttons.start")
|
||||
|
||||
fill_in I18n.t("activerecord.attributes.offline.remaining_pieces"), with: "10"
|
||||
attach_file("offline[end_image]", end_image_file.path)
|
||||
|
||||
expect { click_button I18n.t("helpers.buttons.end") }.to change { contest.offlines[0].images.size }.to(2)
|
||||
expect(page).to have_http_status(200)
|
||||
expect(page).to have_current_path(offline_form_completed_path(contest, contest.offlines[0]))
|
||||
ensure
|
||||
start_image_file.close
|
||||
start_image_file.unlink
|
||||
end_image_file.close
|
||||
end_image_file.unlink
|
||||
end
|
||||
end
|
||||
|
||||
it "should be possible to complete the offline participation with the end image solely when the puzzle is completed" do
|
||||
start_image_file = Tempfile.new('start_image')
|
||||
end_image_file = Tempfile.new('end_image')
|
||||
begin
|
||||
visit offline_form_path(contest)
|
||||
|
||||
fill_in I18n.t("activerecord.attributes.offline.name"), with: "my_name"
|
||||
attach_file("offline[images]", start_image_file.path)
|
||||
click_button I18n.t("helpers.buttons.start")
|
||||
|
||||
check I18n.t("activerecord.attributes.offline.completed")
|
||||
attach_file("offline[end_image]", end_image_file.path)
|
||||
|
||||
expect { click_button I18n.t("helpers.buttons.end") }.to change { contest.offlines[0].images.size }.to(2)
|
||||
expect(page).to have_http_status(200)
|
||||
expect(page).to have_current_path(offline_form_completed_path(contest, contest.offlines[0]))
|
||||
ensure
|
||||
start_image_file.close
|
||||
start_image_file.unlink
|
||||
end_image_file.close
|
||||
end_image_file.unlink
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user