Commit 042cf15b authored by Lin Jen-Shin's avatar Lin Jen-Shin

Cache Note#notable for commits and fix tests

parent 4d03873c
...@@ -190,7 +190,7 @@ class Note < ActiveRecord::Base ...@@ -190,7 +190,7 @@ class Note < ActiveRecord::Base
# override to return commits, which are not active record # override to return commits, which are not active record
def noteable def noteable
if for_commit? if for_commit?
project.commit(commit_id) @commit ||= project.commit(commit_id)
else else
super super
end end
......
...@@ -4,14 +4,19 @@ FactoryGirl.define do ...@@ -4,14 +4,19 @@ FactoryGirl.define do
factory :commit do factory :commit do
git_commit RepoHelpers.sample_commit git_commit RepoHelpers.sample_commit
project factory: :empty_project project factory: :empty_project
author { build(:author) }
initialize_with do initialize_with do
new(git_commit, project) new(git_commit, project)
end end
after(:build) do |commit|
allow(commit).to receive(:author).and_return build(:author)
end
trait :without_author do trait :without_author do
author nil after(:build) do |commit|
allow(commit).to receive(:author).and_return nil
end
end end
end end
end end
...@@ -54,7 +54,8 @@ feature 'Member autocomplete', :js do ...@@ -54,7 +54,8 @@ feature 'Member autocomplete', :js do
let(:note) { create(:note_on_commit, project: project, commit_id: project.commit.id) } let(:note) { create(:note_on_commit, project: project, commit_id: project.commit.id) }
before do before do
allow_any_instance_of(Commit).to receive(:author).and_return(author) allow(User).to receive(:find_by_any_email)
.with(noteable.author_email.downcase).and_return(author)
visit project_commit_path(project, noteable) visit project_commit_path(project, noteable)
end end
......
...@@ -383,7 +383,7 @@ describe NotificationService, services: true do ...@@ -383,7 +383,7 @@ describe NotificationService, services: true do
before do before do
build_team(note.project) build_team(note.project)
reset_delivered_emails! reset_delivered_emails!
allow_any_instance_of(Commit).to receive(:author).and_return(@u_committer) allow(note.noteable).to receive(:author).and_return(@u_committer)
update_custom_notification(:new_note, @u_guest_custom, resource: project) update_custom_notification(:new_note, @u_guest_custom, resource: project)
update_custom_notification(:new_note, @u_custom_global) update_custom_notification(:new_note, @u_custom_global)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment