Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Regression on project name sorting for materials collections #1241

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rails/app/controllers/materials_collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def find_and_authorize_material_collection
end

def load_projects
@projects = policy_scope(Admin::Project)
@projects = policy_scope(Admin::Project).order(:name)
end

end
19 changes: 17 additions & 2 deletions rails/spec/controllers/materials_collections_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
login_admin
end

let(:materials_collection) { FactoryBot.create(:materials_collection) }
let(:project) { FactoryBot.create(:project) }
let(:project) { FactoryBot.create(:project, name: "z project") }
let(:project2) { FactoryBot.create(:project, name: "a project") }
let(:materials_collection) { FactoryBot.create(:materials_collection, project_id: project.id) }
let(:valid_attributes) { { name: "Some name", description: "Some description", project_id: project.id } }

describe "GET index" do
Expand All @@ -37,6 +38,20 @@
get :index
expect(assigns(:materials_collections).to_a).to eq([materials_collection])
end

it "assigns all sorted projects as @projects" do
project # create "z project" first
project2 # create "a project" second
materials_collection
get :index
# make sure project was created before project2
expect(project.id).to be < project2.id
# make sure the projects are sorted by name
ids = assigns(:projects).map {|p| p.id}
names = assigns(:projects).map {|p| p.name}
expect(ids).to eq([project2.id, project.id])
expect(names).to eq(["a project", "z project"])
end
end

describe "GET show" do
Expand Down
Loading