Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Merge branch 'teams-dropdown-improvements'
Browse files Browse the repository at this point in the history
Original Pull Request: #941

Co-authored-by: Simran Singhal <[email protected]>
Co-authored-by: Arushi Singhal <[email protected]>
  • Loading branch information
3 people committed Jun 3, 2018
2 parents 9890b71 + 97dab44 commit 06ef0be
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def set_activities
end

def teams
Team.in_current_season.accepted.order(:name)
@teams ||= Team.accepted.in_nearest_season.order(:name)
end
helper_method :teams

Expand Down
2 changes: 2 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class Team < ApplicationRecord
scope :accepted, -> { full_time.or(part_time) }
scope :visible, -> { where.not(invisible: true).or(accepted) }
scope :in_current_season, -> { where(season: Season.current) }
scope :in_previous_season, -> { by_season(Date.today.year - 1) }
scope :by_season, ->(year) { joins(:season).where(seasons: { name: year }) }
scope :in_nearest_season, -> { in_current_season.presence || in_previous_season }

class << self
def ordered(sort = {})
Expand Down
3 changes: 1 addition & 2 deletions app/views/activities/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ div.row
= radio_button_tag :kind, kind == 'all' ? '' : kind, params[:kind] == kind
= " " + kind == 'feed_entry' ? 'Blog Post' : kind.titleize
label.team_filter
' Team:
= select_tag :team_id, options_for_select(teams.map { |t| [t.display_name, t.id] }, params[:team_id]), include_blank: true, class: 'form-control'
= select_tag :team_id, options_for_select(teams.map { |t| [t.display_name, t.id] }, params[:team_id]), include_blank: 'Teams', class: 'form-control'

p.pagination-info
= page_entries_info @activities
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180602225032_index_teams_on_kind.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class IndexTeamsOnKind < ActiveRecord::Migration[5.1]
def change
add_index :teams, :kind
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180524190818) do
ActiveRecord::Schema.define(version: 20180602225032) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -271,6 +271,7 @@
t.string "project_name"
t.bigint "project_id"
t.index ["applications_count"], name: "index_teams_on_applications_count"
t.index ["kind"], name: "index_teams_on_kind"
t.index ["project_id"], name: "index_teams_on_project_id"
t.index ["season_id"], name: "index_teams_on_season_id"
end
Expand Down
23 changes: 23 additions & 0 deletions spec/models/team_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,29 @@
end
end

describe '.in_nearest_season' do
let(:current_season) { create(:season, name: Date.today.year) }
let!(:current_teams) { create_list(:team, 2, season: current_season) }
let(:prev_season) { create(:season, name: Date.today.year - 1) }
let!(:prev_teams) { create_list(:team, 2, season: prev_season) }

subject(:returned_teams) { described_class.in_nearest_season }

context 'when current season has teams' do
it 'returns those teams' do
expect(returned_teams).to match_array(current_teams)
end
end

context 'when current season has no teams' do
before { current_teams.each(&:destroy) }

it 'returns last season\'s teams' do
expect(returned_teams).to match_array(prev_teams)
end
end
end

describe '.without_recent_log_update' do
let(:team_without) { create :team }

Expand Down

0 comments on commit 06ef0be

Please sign in to comment.