2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-10-31 22:45:15 +02:00
|
|
|
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
|
2017-07-15 03:02:03 +03:00
|
|
|
expect(flash[:notice]).to match("You have subscribed to receive email notifications for #{conference.title}")
|
2014-10-31 22:45:15 +02:00
|
|
|
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
|
2017-07-15 03:02:03 +03:00
|
|
|
expect(flash[:notice]).to match("You have unsubscribed and you will not be receiving email notifications for #{conference.title}.")
|
2014-10-31 22:45:15 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|