Skip to content

Commit

Permalink
Updates are never updated!
Browse files Browse the repository at this point in the history
  • Loading branch information
hennevogel committed Feb 11, 2020
1 parent bb03be6 commit 0efc385
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 5 additions & 3 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 0efc385

Please sign in to comment.