diff --git a/.rubocop.yml b/.rubocop.yml index 188fe0af..70dd4a63 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -101,6 +101,8 @@ Rails/LexicallyScopedActionFilter: Enabled: false Rails/FilePath: EnforcedStyle: arguments +RSpec/ImplicitExpect: + EnforcedStyle: should AllCops: TargetRubyVersion: 3.1.2 NewCops: enable diff --git a/spec/controllers/contests_controller_spec.rb b/spec/controllers/contests_controller_spec.rb new file mode 100644 index 00000000..ed2af780 --- /dev/null +++ b/spec/controllers/contests_controller_spec.rb @@ -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