Add check for pinning when the answer is already pinned
This commit is contained in:
parent
04303c667e
commit
baea942975
|
@ -8,6 +8,7 @@ module UseCase
|
|||
|
||||
def call
|
||||
check_ownership!
|
||||
check_unpinned!
|
||||
|
||||
answer.pinned_at = Time.now.utc
|
||||
answer.save!
|
||||
|
@ -23,6 +24,10 @@ module UseCase
|
|||
def check_ownership!
|
||||
raise ::Errors::NotAuthorized unless answer.user == user
|
||||
end
|
||||
|
||||
def check_unpinned!
|
||||
raise ::Errors::BadRequest if answer.pinned_at.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,6 +18,17 @@ describe UseCase::Answer::Pin do
|
|||
expect { subject }.to change { answer.pinned_at }.from(nil).to(Time.at(1603290950).utc)
|
||||
end
|
||||
end
|
||||
|
||||
context "answer is already pinned" do
|
||||
before do
|
||||
answer.update!(pinned_at: Time.at(1603290950).utc)
|
||||
end
|
||||
|
||||
it "raises an error" do
|
||||
expect { subject }.to raise_error(Errors::BadRequest)
|
||||
expect(answer.reload.pinned_at).to eq(Time.at(1603290950).utc)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "as other user" do
|
||||
|
|
Loading…
Reference in New Issue