Skip to content

Commit

Permalink
Read affiliation from user on school user page (pupilfirst#1678)
Browse files Browse the repository at this point in the history
- Fallback to organisation name when user affiliation is empty.
  • Loading branch information
maciej-ka authored Oct 8, 2024
1 parent f1db12a commit 1efffc4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/presenters/schools/users/show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def courses_authored
.order(name: :asc)
end

def organisation_names
@organisation_names ||= user.organisation&.name
def affiliation
@affiliation ||= user.affiliation || user.organisation&.name
end

def current_standing
Expand Down
4 changes: 2 additions & 2 deletions app/views/schools/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
</div>
</div>
<% end %>
<% if @presenter.organisation_names.present? %>
<% if @presenter.affiliation.present? %>
<div class="flex items-center gap-3">
<p class="text-xl text-gray-600"><i class="if i-school-light if-fw" ></i></p>
<div>
<p class="text-sm text-gray-500"><%= t("schools.users.show.affiliation") %></p>
<p class="text-sm font-bold"><%= @presenter.organisation_names %></p>
<p class="text-sm font-bold"><%= @presenter.affiliation %></p>
</div>
</div>
<% end %>
Expand Down
8 changes: 8 additions & 0 deletions spec/system/school/users/users_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
discord_user_id: Faker::Number.number(digits: 10).to_s,
organisation: organisation
end
let(:user_affiliated) { create :user, affiliation: Faker::Company.name }

let(:course_1) { create :course, school: school }
let(:course_2) { create :course, school: school }
Expand Down Expand Up @@ -48,6 +49,13 @@
expect(page).to have_text("The page you were looking for doesn't exist!")
end

scenario "user with affiliation filled" do
sign_in_user school_admin.user, referrer: school_user_path(user_affiliated)

expect(page).not_to have_text(organisation.name)
expect(page).to have_text(user_affiliated.affiliation)
end

scenario "admin access user of same school" do
sign_in_user school_admin.user, referrer: school_user_path(user)

Expand Down

0 comments on commit 1efffc4

Please sign in to comment.