mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
Unify how we sort SQM Categories
This commit is contained in:
parent
934d0bda0e
commit
882fa84de9
8 changed files with 57 additions and 4 deletions
|
|
@ -7,7 +7,7 @@ class DashboardController < SqmApplicationController
|
|||
.sort
|
||||
.reverse
|
||||
|
||||
@category_presenters = SqmCategory.all.map { |sqm_category| CategoryPresenter.new(category: sqm_category) }
|
||||
@category_presenters = SqmCategory.sorted.map { |sqm_category| CategoryPresenter.new(category: sqm_category) }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ class HomeController < ActionController::Base
|
|||
@districts = District.all.order(:name)
|
||||
@schools = School.all
|
||||
|
||||
@categories = SqmCategory.all.order(:sort_index).map { |category| CategoryPresenter.new(category: category) }
|
||||
@categories = SqmCategory.sorted.map { |category| CategoryPresenter.new(category: category) }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class SqmCategoriesController < SqmApplicationController
|
||||
|
||||
def show
|
||||
@categories = SqmCategory.all.order(:sort_index).map { |category| CategoryPresenter.new(category: category) }
|
||||
@categories = SqmCategory.sorted.map { |category| CategoryPresenter.new(category: category) }
|
||||
|
||||
@category = CategoryPresenter.new(category: SqmCategory.find_by_slug(params[:id]))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
class SqmCategory < ActiveRecord::Base
|
||||
include FriendlyId
|
||||
|
||||
friendly_id :name, use: [:slugged]
|
||||
|
||||
scope :sorted, ->() { order(:sort_index) }
|
||||
|
||||
has_many :subcategories
|
||||
end
|
||||
|
|
|
|||
16
spec/controllers/dashboard_controller_spec.rb
Normal file
16
spec/controllers/dashboard_controller_spec.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe DashboardController, type: :controller do
|
||||
include BasicAuthHelper
|
||||
let(:school) { create(:school) }
|
||||
let(:district) { create(:district) }
|
||||
let!(:categories) {
|
||||
[create(:sqm_category, name: 'Second', sort_index: 2), create(:sqm_category, name: 'First', sort_index: 1)]
|
||||
}
|
||||
|
||||
it 'fetches categories sorted by sort_index' do
|
||||
login_as district
|
||||
get :index, params: { school_id: school.to_param, district_id: district.to_param }
|
||||
expect(assigns(:category_presenters).map(&:name)).to eql ['First', 'Second']
|
||||
end
|
||||
end
|
||||
12
spec/controllers/home_controller_spec.rb
Normal file
12
spec/controllers/home_controller_spec.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe HomeController, type: :controller do
|
||||
let!(:categories) {
|
||||
[create(:sqm_category, name: 'Second', sort_index: 2), create(:sqm_category, name: 'First', sort_index: 1)]
|
||||
}
|
||||
|
||||
it 'fetches categories sorted by sort_index' do
|
||||
get :index
|
||||
expect(assigns(:categories).map(&:name)).to eql ['First', 'Second']
|
||||
end
|
||||
end
|
||||
17
spec/controllers/sqm_categories_controller_spec.rb
Normal file
17
spec/controllers/sqm_categories_controller_spec.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe SqmCategoriesController, type: :controller do
|
||||
include BasicAuthHelper
|
||||
let(:school) { create(:school) }
|
||||
let(:district) { create(:district) }
|
||||
let!(:categories) {
|
||||
[create(:sqm_category, name: 'Second', sort_index: 2), create(:sqm_category, name: 'First', sort_index: 1)]
|
||||
}
|
||||
|
||||
it 'fetches categories sorted by sort_index' do
|
||||
login_as district
|
||||
category = categories.first
|
||||
get :show, params: { id: category.to_param, school_id: school.to_param, district_id: district.to_param }
|
||||
expect(assigns(:categories).map(&:name)).to eql ['First', 'Second']
|
||||
end
|
||||
end
|
||||
7
spec/support/basic_auth_helper.rb
Normal file
7
spec/support/basic_auth_helper.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
module BasicAuthHelper
|
||||
def login_as(district)
|
||||
user = district.name.downcase
|
||||
pw = "#{district.name.downcase}!"
|
||||
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user, pw)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue