mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-14 04:04:03 +00:00
move subscribe to its own controller, add authorization, test subscribe/unsubscribe
This commit is contained in:
parent
97bf86454e
commit
3be200abcc
7 changed files with 92 additions and 43 deletions
53
spec/controllers/subscriptions_controller_spec.rb
Normal file
53
spec/controllers/subscriptions_controller_spec.rb
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe SubscriptionsController do
|
||||
let(:conference) { create(:conference) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'when user is a guest' do
|
||||
it 'redirects to sign in page' do
|
||||
post :create, conference_id: conference.short_title
|
||||
expect(response).to redirect_to new_user_session_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is signed in' do
|
||||
before(:each) do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
it 'redirects to home page' do
|
||||
post :create, conference_id: conference.short_title
|
||||
expect(response).to redirect_to root_path
|
||||
end
|
||||
|
||||
it 'shows success message in flash notice' do
|
||||
post :create, conference_id: conference.short_title
|
||||
expect(flash[:notice]).to match("You have been subscribed to receive email notifications for #{conference.short_title}")
|
||||
end
|
||||
|
||||
it 'subscribes user to conference' do
|
||||
post :create, conference_id: conference.short_title
|
||||
expect(user.subscriptions.pluck(:conference_id)).to include(conference.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before(:each) do
|
||||
sign_in(user)
|
||||
post :create, conference_id: conference.short_title
|
||||
end
|
||||
|
||||
it 'redirects to home page' do
|
||||
delete :destroy, conference_id: conference.short_title
|
||||
expect(response).to redirect_to root_path
|
||||
end
|
||||
|
||||
it 'shows success message in flash notice' do
|
||||
delete :destroy, conference_id: conference.short_title
|
||||
expect(flash[:notice]).to match("You have been unsubscribed and now you will not be receiving email notifications for #{conference.short_title}.")
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue