Skip to content

Commit

Permalink
[api] Review#accepted_at now uses the history_element.created_at valu…
Browse files Browse the repository at this point in the history
…e instead of review.updated_at
  • Loading branch information
evanrolfe committed Jan 26, 2017
1 parent 2a60129 commit 8df57e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/api/app/models/review.rb
Expand Up @@ -60,12 +60,16 @@ def state

def accepted_at
if review_assigned_to && review_assigned_to.state == :accepted
review_assigned_to.updated_at
review_assigned_to.accept_history_element.created_at
elsif state == :accepted && !review_assigned_to
updated_at
accept_history_element.created_at
end
end

def accept_history_element
history_elements.find_by(type: 'HistoryElement::ReviewAccepted')
end

def assigned_reviewer
self[:reviewer] || by_user || by_group || by_project || by_package
end
Expand Down
24 changes: 19 additions & 5 deletions src/api/spec/models/review_spec.rb
Expand Up @@ -46,8 +46,15 @@
create(
:review,
by_user: user.login,
state: review_state,
updated_at: Faker::Time.forward(1)
state: review_state
)
end
let!(:history_element_review_accepted) do
create(
:history_element_review_accepted,
review: review,
user: user,
created_at: Faker::Time.forward(1)
)
end

Expand All @@ -57,14 +64,21 @@
:review,
by_user: user.login,
review_id: review.id,
updated_at: Faker::Time.forward(2),
state: :accepted
)
end
let!(:history_element_review_accepted2) do
create(
:history_element_review_accepted,
review: review2,
user: user,
created_at: Faker::Time.forward(2)
)
end

subject { review.accepted_at }

it { is_expected.to eq(review2.updated_at) }
it { is_expected.to eq(history_element_review_accepted2.created_at) }
end

context 'with a review assigned to and assigned to state != accepted' do
Expand All @@ -86,7 +100,7 @@
context 'with no reviewed assigned to and state = accepted' do
subject { review.accepted_at }

it { is_expected.to eq(review.updated_at) }
it { is_expected.to eq(history_element_review_accepted.created_at) }
end

context 'with no reviewed assigned to and state != accepted' do
Expand Down

0 comments on commit 8df57e0

Please sign in to comment.