forked from External/greenlight
Fixed issue with rooms not correctly ordering (#963)
This commit is contained in:
parent
03266730e8
commit
475374090a
|
@ -103,6 +103,11 @@ class User < ApplicationRecord
|
||||||
order(Arel.sql("#{column} #{direction}"))
|
order(Arel.sql("#{column} #{direction}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a list of rooms ordered by last session
|
||||||
|
def ordered_rooms
|
||||||
|
[main_room] + rooms.where.not(id: main_room.id).order("last_session desc")
|
||||||
|
end
|
||||||
|
|
||||||
# Activates an account and initialize a users main room
|
# Activates an account and initialize a users main room
|
||||||
def activate
|
def activate
|
||||||
update_attributes(email_verified: true, activated_at: Time.zone.now)
|
update_attributes(email_verified: true, activated_at: Time.zone.now)
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="room_block_container" class="row pt-7 pb-5">
|
<div id="room_block_container" class="row pt-7 pb-5">
|
||||||
<% current_user.rooms.each do |room| %>
|
<% current_user.ordered_rooms.each do |room| %>
|
||||||
<div class="col-lg-4 col-md-6 col-sm-12">
|
<div class="col-lg-4 col-md-6 col-sm-12">
|
||||||
<%= link_to room do %>
|
<%= link_to room do %>
|
||||||
<%= render "rooms/components/room_block", room: room %>
|
<%= render "rooms/components/room_block", room: room %>
|
||||||
|
|
|
@ -112,6 +112,28 @@ describe User, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#ordered_rooms' do
|
||||||
|
it 'correctly orders the users rooms' do
|
||||||
|
user = create(:user)
|
||||||
|
room1 = create(:room, owner: user)
|
||||||
|
room2 = create(:room, owner: user)
|
||||||
|
room3 = create(:room, owner: user)
|
||||||
|
room4 = create(:room, owner: user)
|
||||||
|
|
||||||
|
room4.update_attributes(sessions: 1, last_session: "2020-02-24 19:52:57")
|
||||||
|
room3.update_attributes(sessions: 1, last_session: "2020-01-25 19:52:57")
|
||||||
|
room2.update_attributes(sessions: 1, last_session: "2019-09-05 19:52:57")
|
||||||
|
room1.update_attributes(sessions: 1, last_session: "2015-02-24 19:52:57")
|
||||||
|
|
||||||
|
rooms = user.ordered_rooms
|
||||||
|
expect(rooms[0]).to eq(user.main_room)
|
||||||
|
expect(rooms[1]).to eq(room4)
|
||||||
|
expect(rooms[2]).to eq(room3)
|
||||||
|
expect(rooms[3]).to eq(room2)
|
||||||
|
expect(rooms[4]).to eq(room1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'password reset' do
|
context 'password reset' do
|
||||||
it 'creates token and respective reset digest' do
|
it 'creates token and respective reset digest' do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
|
|
Loading…
Reference in New Issue