This commit is contained in:
nasia-sam 2017-07-18 10:03:07 +00:00 committed by GitHub
commit 3acb686cd5
23 changed files with 686 additions and 1 deletions

View file

@ -0,0 +1,152 @@
require 'spec_helper'
describe Admin::BoothsController do
let(:admin) { create(:admin) }
let(:conference) { create(:conference) }
let(:booth) { create(:booth, conference: conference) }
let(:admin) { create(:admin) }
context 'not logged in user' do
describe 'GET index' do
it 'does not render admin/booths#index' do
get :index, conference_id: conference.short_title
expect(response).to redirect_to(user_session_path)
end
end
describe 'GET show' do
it 'does not render admin/booths#show' do
get :show, id: booth.id, conference_id: conference.short_title
expect(response).to redirect_to(user_session_path)
end
end
end
context 'user is admin' do
before :each do
sign_in admin
end
describe 'GET index' do
before { get :index, conference_id: conference.short_title }
it 'assigns attributes for booths' do
expect(assigns(:booths)).to eq([booth])
end
it 'renders index template' do
expect(response).to render_template('index')
end
end
describe 'GET new' do
before { get :new, conference_id: conference.short_title }
it 'assigns attributes for booths' do
expect(assigns(:booth)).to be_a_new(Booth)
end
it 'renders new template' do
expect(response).to render_template('new')
end
end
describe 'POST #create' do
# context 'successfully created' do
# it 'creates a new booth' do
# expected = expect do
# post :create, booth: attributes_for(:booth), conference_id: conference.short_title
# end
# expected.to change { Booth.count }.by(1)
# end
#
# it 'redirects to admin booth index' do
# post :create, booth: attributes_for(:booth), conference_id: conference.short_title
# expect(response).to redirect_to(admin_conference_booths_path)
# end
#
# it 'shows success message' do
# post :create, booth: attributes_for(:booth), conference_id: conference.short_title
# expect(flash[:notice]).to match('Booth successfully created.')
# end
# end
context 'create action fails' do
it 'does not create any record' do
expected = expect do
post :create, booth: attributes_for(:booth, title: ''), conference_id: conference.short_title
end
expected.to_not change(Booth, :count)
end
it 'redirects to new' do
post :create, booth: attributes_for(:booth, title: ''), conference_id: conference.short_title
expect(response).to render_template('new')
end
# it 'shows flash message' do
# post :create, booth: attributes_for(:booth, title: ''), conference_id: conference.short_title
#
# expect(flash[:error]).to eq("Title can't be blank")
# end
end
end
describe 'PATCH #update' do
context 'updates suchessfully' do
it 'redirects to admin booth index path' do
patch :update, id: booth.id, booth: attributes_for(:booth, title: 'different'), conference_id: conference.short_title
expect(response).to redirect_to admin_conference_booths_path
end
it 'shows success message' do
patch :update, id: booth.id, booth: attributes_for(:booth, title: 'different'), conference_id: conference.short_title
expect(flash[:notice]).to match"Successfully updated booth."
end
it 'updates booth' do
patch :update, id: booth.id, booth: attributes_for(:booth, title: 'different'), conference_id: conference.short_title
booth.reload
expect(booth.title).to eq('different')
end
end
end
describe 'DELETE #destroy' do
context 'deletes successfully' do
# it 'booth deleted' do
# expected = expect do
# delete :destroy, id: booth.iddelete :destroy, id: booth.id, conference_id: conference.short_title
# end
# expected.to change { Booth.count }.by(-1)
# end
it 'redirects to admin booth index path' do
delete :destroy, id: booth.id, conference_id: conference.short_title
expect(response).to redirect_to(admin_conference_booths_path)
end
it 'show success message' do
delete :destroy, id: booth.id, conference_id: conference.short_title
expect(flash[:notice]).to match('Booth successfully destroyed.')
end
end
end
describe 'GET #edit' do
it 'renders edit template' do
get :edit, id: booth.id, conference_id: conference.short_title
expect(response).to render_template('edit')
end
it 'assigns booth variable' do
get :edit, id: booth.id, conference_id: conference.short_title
expect(assigns(:booth)).to eq booth
end
end
end
end

15
spec/factories/booths.rb Normal file
View file

@ -0,0 +1,15 @@
FactoryGirl.define do
factory :booth do
title { Faker::Hipster.sentence }
description { Faker::Lorem.paragraph }
reasoning { Faker::Lorem.paragraph }
website_url { Faker::Internet.url }
submitter_relationship { Faker::Lorem.paragraph }
conference
after(:build) do |booth|
booth.responsibles << create(:user)
end
end
end

View file

@ -249,6 +249,16 @@ feature 'Has correct abilities' do
visit admin_conference_roles_path(conference.short_title)
expect(current_path).to eq(admin_conference_roles_path(conference.short_title))
visit admin_conference_booths_path(conference.short_title)
expect(current_path).to eq(admin_conference_booths_path(conference.short_title))
visit new_admin_conference_booth_path(conference.short_title)
expect(current_path).to eq(new_admin_conference_booth_path(conference.short_title))
create(:booth, conference: conference)
visit edit_admin_conference_booth_path(conference.short_title, conference.booths.first)
expect(current_path).to eq(edit_admin_conference_booth_path(conference.short_title, conference.booths.first))
visit admin_conference_resources_path(conference.short_title)
expect(current_path).to eq(admin_conference_resources_path(conference.short_title))

View file

@ -237,6 +237,16 @@ feature 'Has correct abilities' do
visit edit_admin_conference_target_path(conference.short_title, conference.targets.first)
expect(current_path).to eq(edit_admin_conference_target_path(conference.short_title, conference.targets.first))
visit admin_conference_booths_path(conference.short_title)
expect(current_path).to eq(admin_conference_booths_path(conference.short_title))
visit new_admin_conference_booth_path(conference.short_title)
expect(current_path).to eq(new_admin_conference_booth_path(conference.short_title))
create(:booth, conference: conference)
visit edit_admin_conference_booth_path(conference.short_title, conference.booths.first)
expect(current_path).to eq(edit_admin_conference_booth_path(conference.short_title, conference.booths.first))
visit admin_conference_program_tracks_path(conference.short_title)
expect(current_path).to eq(admin_conference_program_tracks_path(conference.short_title))

54
spec/models/booth_spec.rb Normal file
View file

@ -0,0 +1,54 @@
require 'spec_helper'
describe 'Booth' do
subject { create(:booth) }
let!(:conference) { create(:conference) }
describe 'validation' do
it 'has a valid factory' do
expect(build(:booth)).to be_valid
end
it { is_expected.to validate_presence_of(:reasoning) }
it { is_expected.to validate_presence_of(:description) }
it { is_expected.to validate_presence_of(:responsibles) }
it { is_expected.to validate_presence_of(:submitter_relationship) }
it { is_expected.to validate_presence_of(:website_url) }
it 'is not valid without a title' do
is_expected.to validate_presence_of(:title)
end
end
describe 'association' do
it { is_expected.to belong_to(:conference) }
it { is_expected.to have_many(:booth_requests) }
end
describe '#transition_possible?(transition)' do
shared_examples 'transition_possible?(transition)' do |state, transition, expected|
it "returns #{expected} for #{transition} transition, when the booth is #{state}}" do
my_booth = create(:booth, state: state)
expect(my_booth.transition_possible?(transition.to_sym)).to eq expected
end
end
states = [:new, :withdrawn, :to_accept, :accepted, :to_reject, :rejected, :canceled]
transitions = [:restart, :withdraw, :accept, :reject, :to_accept, :to_reject, :cancel]
states_transitions = { new: { restart: false, withdraw: true, accept: true, to_accept: true, to_reject: true, reject: true, cancel: false },
withdrawn: { restart: true, withdraw: false, accept: false, to_accept: false, to_reject: false, reject: false, cancel: false },
to_accept: { restart: true, withdraw: true, accept: true, to_accept: false, to_reject: true, reject: false, cancel: true },
to_reject: { restart: true, withdraw: true, accept: false, to_accept: true, to_reject: false, reject: true, cancel: true },
accepted: { restart: false, withdraw: true, accept: false, to_accept: false, to_reject: false, reject: false, cancel: true },
rejected: { restart: false, withdraw: true, accept: false, to_accept: false, to_reject: false, reject: false, cancel: true },
canceled: { restart: true, withdraw: false, accept: false, to_accept: false, to_reject: false, reject: false, cancel: false } }
states.each do |state|
transitions.each do |transition|
it_behaves_like 'transition_possible?(transition)', state, transition, states_transitions[state.to_sym][transition.to_sym]
end
end
end
end