Introduce Booths for admin

This commit is contained in:
nasia 2017-05-17 13:31:27 +03:00 committed by Stella Rouzi
parent 29aee82a14
commit f7c0b64eb5
22 changed files with 534 additions and 1 deletions

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: false },
to_reject: { restart: true, withdraw: true, accept: false, to_accept: true, to_reject: false, reject: true, cancel: false },
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