Skip to content

Commit

Permalink
Extend HistoryElement factories
Browse files Browse the repository at this point in the history
Add more types of history elements.
Add missing attributes to the factories.
  • Loading branch information
saraycp committed Feb 24, 2023
1 parent 6732b13 commit 8425e7c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/api/spec/factories/history_elements.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,65 @@
FactoryBot.define do
# Inheriting from HistoryElement::Review

factory :history_element_review_assigned, class: 'HistoryElement::ReviewAssigned' do
user { create(:user) }
type { 'HistoryElement::ReviewAssigned' }
end

factory :history_element_review_accepted, class: 'HistoryElement::ReviewAccepted' do
user { create(:user) }
type { 'HistoryElement::ReviewAccepted' }
end

factory :history_element_review_declined, class: 'HistoryElement::ReviewDeclined' do
user { create(:user) }
type { 'HistoryElement::ReviewDeclined' }
end

# Inheriting from HistoryElement::Request

factory :history_element_request_accepted, class: 'HistoryElement::RequestAccepted' do
user { create(:user) }
op_object_id { create(:bs_request_with_submit_action).id }
type { 'HistoryElement::RequestAccepted' }
end

factory :history_element_request_revoked, class: 'HistoryElement::RequestRevoked' do
user { create(:user) }
op_object_id { create(:bs_request_with_submit_action).id }
type { 'HistoryElement::RequestRevoked' }
end

factory :history_element_request_review_added_with_review, class: 'HistoryElement::RequestReviewAdded' do
user { create(:user) }
type { 'HistoryElement::RequestReviewAdded' }

before(:create) do |history_element|
bs_request = create(:bs_request_with_submit_action, review_by_user: create(:confirmed_user))
history_element.update(description_extension: bs_request.reviews.first.id.to_s, op_object_id: bs_request.id)
end
end

factory :history_element_request_review_added_without_review, class: 'HistoryElement::RequestReviewAdded' do
user { create(:user) }
type { 'HistoryElement::RequestReviewAdded' }
description_extension { nil }

before(:create) do |history_element|
bs_request = create(:bs_request_with_submit_action, review_by_user: create(:confirmed_user))
history_element.update(op_object_id: bs_request.id)
end
end

factory :history_element_request_superseded, class: 'HistoryElement::RequestSuperseded' do
user { create(:user) }
type { 'HistoryElement::RequestSuperseded' }

before(:create) do |history_element|
superseding_bs_request = create(:bs_request_with_submit_action)
superseded_bs_request = create(:superseded_bs_request, superseded_by_request: superseding_bs_request)

history_element.update(description_extension: superseded_bs_request.superseded_by.to_s, op_object_id: superseded_bs_request.id)
end
end
end

0 comments on commit 8425e7c

Please sign in to comment.