Skip to content

Commit

Permalink
Add contest controller unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
  • Loading branch information
kostyanf14 committed Sep 2, 2023
1 parent 6d6ad56 commit 91de341
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ Rails/LexicallyScopedActionFilter:
Enabled: false
Rails/FilePath:
EnforcedStyle: arguments
RSpec/ImplicitExpect:
EnforcedStyle: should
AllCops:
TargetRubyVersion: 3.1.2
NewCops: enable
Expand Down
48 changes: 48 additions & 0 deletions spec/controllers/contests_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'rails_helper'

RSpec.describe ContestsController do
describe '#contest' do
context 'when variable assigned' do
before { controller.instance_variable_set :@contest, :contest }

its(:contest) { should eq :contest }
end

context 'when created' do
let(:contest) { create :contest }

before do
allow(controller).to receive(:params).and_return(id: contest.id.to_s)
end

its(:contest) { should eq contest }
end
end

describe '#collection' do
context 'when variable assigned' do
before { controller.instance_variable_set :@collection, :collection }

its(:collection) { should eq :collection }
end

context 'without active contest' do
let(:contest) { create :contest, archived: true }

before do
create :contest, archived: false, upload_open: false, registration_open: false
end

its(:collection) { should eq [contest] }
end

context 'with active contest' do
before do
create :contest, archived: true
create :contest, archived: false, upload_open: true, registration_open: true
end

its(:collection) { should be_empty }
end
end
end

0 comments on commit 91de341

Please sign in to comment.