Update pinning tests to match new Turbo Stream behaviour

This commit is contained in:
Karina Kwiatek 2023-02-12 21:04:35 +01:00
parent 520f7eb9ef
commit 793fec7da1

View file

@ -43,7 +43,7 @@ describe AnswerController, type: :controller do
end end
describe "#pin" do describe "#pin" do
subject { post :pin, params: { username: user.screen_name, id: answer.id } } subject { post :pin, params: { username: user.screen_name, id: answer.id }, format: :turbo_stream }
context "user signed in" do context "user signed in" do
before(:each) { sign_in user } before(:each) { sign_in user }
@ -51,7 +51,7 @@ describe AnswerController, type: :controller do
it "pins the answer" do it "pins the answer" do
travel_to(Time.at(1603290950).utc) do travel_to(Time.at(1603290950).utc) do
expect { subject }.to change { answer.reload.pinned_at }.from(nil).to(Time.at(1603290950).utc) expect { subject }.to change { answer.reload.pinned_at }.from(nil).to(Time.at(1603290950).utc)
expect(response).to redirect_to(user_path(user)) expect(response.body).to include("turbo-stream action=\"update\" target=\"ab-pin-#{answer.id}\"")
end end
end end
end end
@ -63,15 +63,14 @@ describe AnswerController, type: :controller do
it "does not pin the answer" do it "does not pin the answer" do
travel_to(Time.at(1603290950).utc) do travel_to(Time.at(1603290950).utc) do
expect { subject }.to raise_error(Errors::NotAuthorized) expect { subject }.not_to(change { answer.reload.pinned_at })
expect(answer.reload.pinned_at).to eq(nil)
end end
end end
end end
end end
describe "#unpin" do describe "#unpin" do
subject { delete :unpin, params: { username: user.screen_name, id: answer.id } } subject { delete :unpin, params: { username: user.screen_name, id: answer.id }, format: :turbo_stream }
context "user signed in" do context "user signed in" do
before(:each) do before(:each) do
@ -81,7 +80,7 @@ describe AnswerController, type: :controller do
it "unpins the answer" do it "unpins the answer" do
expect { subject }.to change { answer.reload.pinned_at }.from(Time.at(1603290950).utc).to(nil) expect { subject }.to change { answer.reload.pinned_at }.from(Time.at(1603290950).utc).to(nil)
expect(response).to redirect_to(user_path(user)) expect(response.body).to include("turbo-stream action=\"update\" target=\"ab-pin-#{answer.id}\"")
end end
end end
@ -94,8 +93,7 @@ describe AnswerController, type: :controller do
end end
it "does not unpin the answer" do it "does not unpin the answer" do
expect { subject }.to raise_error(Errors::NotAuthorized) expect { subject }.not_to(change { answer.reload.pinned_at })
expect(answer.reload.pinned_at).to eq(Time.at(1603290950).utc)
end end
end end
end end