diff --git a/spec/controllers/serial_works_controller_spec.rb b/spec/controllers/serial_works_controller_spec.rb new file mode 100644 index 00000000000..0956cc33920 --- /dev/null +++ b/spec/controllers/serial_works_controller_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe SerialWorksController do + include LoginMacros + include RedirectExpectationHelper + let(:user) { create(:user) } + let(:series) { create(:series, pseuds: user.pseuds) } + let!(:first_work) { create(:serial_work, series: series) } + let!(:second_work) { create(:serial_work, series: series) } + + it "will fail if you're not the owner" do + fake_login + delete :destroy, id: first_work.id + it_redirects_to_with_error(series_path(series), "Sorry, you don't have permission to access the page you were trying to reach.") + end + + it "redirects to series when destroying one of many" do + fake_login_known_user(user) + delete :destroy, id: first_work.id + # it doesn't give you any success message - this might be worth improving in future + it_redirects_to(series_path(series)) + end + + it "redirects to user when destroying last one" do + fake_login_known_user(user) + delete :destroy, id: first_work.id + delete :destroy, id: second_work.id + # it doesn't give you any success message - this might be worth improving in future + it_redirects_to(user_path(user)) + end +end