diff --git a/app/models/project.rb b/app/models/project.rb index 1f0e0cefa..4bc05a589 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -21,7 +21,7 @@ class Project < ApplicationRecord has_many :project_interests has_many :keywords, through: :project_interests - has_many :updates, dependent: :destroy + has_many :updates, -> { order 'created_at DESC' }, dependent: :destroy has_many :comments, as: :commentable, dependent: :destroy diff --git a/app/models/user.rb b/app/models/user.rb index e587f7c88..6fae10e34 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,7 +7,7 @@ class User < ApplicationRecord validates_uniqueness_of :email has_many :originated_projects, foreign_key: 'originator_id', class_name: 'Project' - has_many :updates, -> { order 'updated_at DESC' }, foreign_key: 'author_id', dependent: :destroy + has_many :updates, -> { order 'created_at DESC' }, foreign_key: 'author_id', dependent: :destroy has_many :memberships has_many :comments, foreign_key: 'commenter_id' diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index dd0e744e8..3ca766b6a 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -64,6 +64,8 @@ before do @project = FactoryBot.create(:project) @idea = FactoryBot.create(:idea) + # We sort updates by updated_at, make sure it's different from the creation updates + sleep 1 @user = FactoryBot.create(:user) @project.join!(@user) @idea.join!(@user) @@ -78,15 +80,15 @@ end it 'creates an Update object assigned to the user' do - expect(@project.updates.last.author).to eq(@user) + expect(@project.updates.first.author).to eq(@user) end context 'when project has no users (state == idea)' do - it { expect(@idea.updates.last.text).to eq('started') } + it { expect(@idea.updates.first.text).to eq('started') } end context 'when project has a user (state == project)' do - it { expect(@project.updates.last.text).to eq('joined') } + it { expect(@project.updates.first.text).to eq('joined') } end end