Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/splits-io. a speedrunning data store and analysis engine splits.io
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300require 'rails_helper'
describe RunsController do describe '#index' do let(:response) { get(:index) }
it 'returns a 200' do expect(response).to have_http_status(200) end end
describe '#new' do let(:response) { get(:new) }
it 'returns a 200' do expect(response).to have_http_status(200) end end
describe '#create' do end
describe '#show' do let(:response) { get(:show, params: {run: id}) }
context 'for a nonexisting run' do let(:id) { 'z' }
it 'returns a 404' do expect(response).to have_http_status(404) end end
context 'for an existing run' do let(:run) { FactoryBot.create(:run, :nicked) }
context 'by id' do let(:id) { run.id36 }
it 'returns a 200' do expect(response).to have_http_status(200) end
it 'renders the template' do expect(response).to render_template('runs/show') end end
context 'by nick' do let(:id) { run.nick }
it 'returns a 302' do expect(response).to have_http_status(302) end
it 'redirects to the modern URL' do expect(response).to redirect_to(run_path(run)) end end end end
describe '#edit' do let(:response) { get(:edit, params: {run: run.id36}) }
context 'for an unowned run' do let(:run) { FactoryBot.create(:run, :unowned) }
context 'by a logged-in user' do before { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:user)) }
it 'returns a 403' do expect(response).to have_http_status(403) end end
context 'by a logged-out user' do before { allow(controller).to receive(:current_user).and_return(nil) }
it 'returns a 403' do expect(response).to have_http_status(403) end end end
context 'for an owned run' do let(:run) { FactoryBot.create(:run, :owned) }
context "by a user who doesn't own the run" do context "because they're not logged in" do before { allow(controller).to receive(:current_user).and_return(nil) }
it 'returns a 403' do expect(response).to have_http_status(403) end end
context "because they're a different user" do before { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:user)) }
it 'returns a 403' do expect(response).to have_http_status(403) end end end
context 'by the user who owns the run' do before { allow(controller).to receive(:current_user).and_return(run.user) }
it 'returns a 200' do expect(response).to have_http_status(200) end end end end
describe '#update' do context 'category' do let(:response) do put(:update, params: { 'run' => run.id36, "#{run.id36}[category]" => FactoryBot.create(:category).id }) end
context 'for an unowned run' do let(:run) { FactoryBot.create(:run, :unowned) }
context 'by a logged-in user' do before { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:user)) }
it 'returns a 403' do expect(response).to have_http_status(403) end end
context 'by a logged-out user' do before { allow(controller).to receive(:current_user).and_return(nil) }
it 'returns a 403' do expect(response).to have_http_status(403) end end end
context 'for an owned run' do let(:run) { FactoryBot.create(:run, :owned) }
context "by a user who doesn't own the run" do context "because they're not logged in" do before { allow(controller).to receive(:current_user).and_return(nil) }
it 'returns a 403' do expect(response).to have_http_status(403) end end
context "because they're a different user" do before { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:user)) }
it 'returns a 403' do expect(response).to have_http_status(403) end end end
context 'by the user who owns the run' do before { allow(controller).to receive(:current_user).and_return(run.user) }
it 'returns a 302' do expect(response).to have_http_status(302) end
it 'redirects to the run edit page' do expect(response).to redirect_to(edit_run_path(run)) end end end end end
describe '#destroy' do let(:response) { delete(:destroy, params: {run: run.id36}) }
context 'for an unowned run' do let(:run) { FactoryBot.create(:run, :unowned) }
context 'by a logged-in user' do before { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:user)) }
it 'returns a 403' do expect(response).to have_http_status(403) end end
context 'by a logged-out user' do before { allow(controller).to receive(:current_user).and_return(nil) }
it 'returns a 403' do expect(response).to have_http_status(403) end end end
context 'for an owned run' do let(:run) { FactoryBot.create(:run, :owned) }
context "by a user who doesn't own the run" do context "because they're not logged in" do before { allow(controller).to receive(:current_user).and_return(nil) }
it 'returns a 403' do expect(response).to have_http_status(403) end end
context "because they're a different user" do before { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:user)) }
it 'returns a 403' do expect(response).to have_http_status(403) end end end
context 'by the user who owns the run' do before { allow(controller).to receive(:current_user).and_return(run.user) }
it 'returns a 302' do expect(response).to have_http_status(302) end
it 'redirects to the frontpage' do expect(response).to redirect_to(root_path) end end end end
describe '#compare' do let(:run) { FactoryBot.create(:run, :parsed) } let(:comparison_run) { FactoryBot.create(:run, :parsed) }
let(:response) { get(:compare, params: {run: run.id36, comparison_run: comparison_run.id36}) }
context 'by a logged-in user' do before { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:user)) }
it 'returns a 200' do expect(response).to have_http_status(200) end end end
describe '#download' do let(:run) { FactoryBot.create(:run, :parsed) } let(:response) { get(:download, params: {run: run.id36, timer: timer}) }
context 'as Urn' do let(:timer) { 'urn' }
it 'returns a 200' do expect(response).to have_http_status(200) end end
context 'as LiveSplit' do let(:timer) { 'livesplit' }
it 'returns a 302' do expect(response).to have_http_status(302) end end
context 'as SplitterZ' do let(:timer) { 'splitterz' }
it 'returns a 200' do expect(response).to have_http_status(200) end end
context 'as Time Split Tracker' do let(:timer) { 'splitterz' }
it 'returns a 200' do expect(response).to have_http_status(200) end end
context 'as WSplit' do let(:timer) { 'wsplit' }
it 'returns a 200' do expect(response).to have_http_status(200) end end endend