Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/railsbridge/bridge_troll
Browse files Browse the repository at this point in the history
…into issue-325-disable-event-food-options
  • Loading branch information
JasonEb committed Feb 12, 2017
2 parents 369d1f2 + fd601f1 commit e345e5b
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 123 deletions.
8 changes: 4 additions & 4 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ def event_special_permissions_text(event, user_event_role)
"You are #{role_text} this event!"
end

def event_form_section(label:, form:)
def event_form_section(label:, form:, force_expanded: false)
id = "section-#{label}".parameterize

results = []

toggler_classes = ['form-section-header']
section_classes = ['collapse']
if form.object.published?
toggler_classes << 'collapsed'
else
if form.object.published? || force_expanded
section_classes << 'in'
else
toggler_classes << 'collapsed'
end

results << content_tag('a', class: toggler_classes, data: {toggle: 'collapse', target: "##{id}"}) do
Expand Down
38 changes: 21 additions & 17 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Event < ActiveRecord::Base
serialize :allowed_operating_system_ids, JSON
serialize :imported_event_data, JSON
enum current_state: [ :draft, :pending_approval, :published ]
validates :current_state, inclusion: { in: Event.current_states.keys }

after_initialize :set_defaults
before_validation :normalize_allowed_operating_system_ids
Expand All @@ -24,7 +23,6 @@ class Event < ActiveRecord::Base
belongs_to :chapter, counter_cache: true
has_one :organization, through: :chapter

extend ActiveHash::Associations::ActiveRecordExtensions
belongs_to :course

has_one :region, through: :location
Expand Down Expand Up @@ -68,31 +66,37 @@ class Event < ActiveRecord::Base

has_many :event_sessions, -> { order('ends_at ASC') }, dependent: :destroy, inverse_of: :event
accepts_nested_attributes_for :event_sessions, allow_destroy: true
validates :event_sessions, length: { minimum: 1 }

with_options(through: :rsvps, source: :survey) do
has_many :surveys
has_many :student_surveys, -> { where('rsvps.role_id = ?', Role::STUDENT.id) }
has_many :volunteer_surveys, -> { where('rsvps.role_id = ?', Role::VOLUNTEER.id) }
end

validates_presence_of :title
validates_presence_of :time_zone
validates_presence_of :chapter
validates :title, presence: true
validates :chapter, presence: true
validates :food_provided, inclusion: { in: [true, false] }
validates_inclusion_of :time_zone, in: ActiveSupport::TimeZone.all.map(&:name), allow_blank: true
validates :allowed_operating_system_ids, array_of_ids: OperatingSystem.all.map(&:id), if: :restrict_operating_systems?
validates_presence_of :target_audience, unless: :historical?, if: [:allow_student_rsvp?, :target_audience_required?]

with_options(unless: :historical?) do |normal_event|
normal_event.with_options(if: :allow_student_rsvp?) do |workshop_event|
workshop_event.validates_numericality_of :student_rsvp_limit, greater_than: 0
workshop_event.validate :validate_student_rsvp_limit
validates :time_zone, inclusion: { in: ActiveSupport::TimeZone.all.map(&:name), allow_blank: true }, presence: true
validates :current_state, inclusion: { in: Event.current_states.keys }
validates :event_sessions, length: { minimum: 1 }

with_options(if: :restrict_operating_systems?) do
validates :allowed_operating_system_ids, array_of_ids: OperatingSystem.all.map(&:id)
end

with_options(unless: :historical?) do
with_options(if: :allow_student_rsvp?) do
validates_numericality_of :student_rsvp_limit, greater_than: 0
validate :validate_student_rsvp_limit
end

with_options(if: [:allow_student_rsvp?, :target_audience_required?]) do
validates_presence_of :target_audience
end

with_options(if: :has_volunteer_limit?) do |workshop_event|
workshop_event.validates_numericality_of :volunteer_rsvp_limit, greater_than: 0
workshop_event.validate :validate_volunteer_rsvp_limit
with_options(if: :has_volunteer_limit?) do
validates_numericality_of :volunteer_rsvp_limit, greater_than: 0
validate :validate_volunteer_rsvp_limit
end
end

Expand Down
22 changes: 18 additions & 4 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,33 @@
<%= render 'shared/model_error_messages', model: @event %>

<div class="form-section-header-expander">
<a href=""><i class='fa fa-arrows-alt'></i> Expand All</a>
<%= content_tag(:a, href: '', class: "expand-all #{@event.persisted? ? 'hidden' : ''}") do %>
<i class='fa fa-expand'></i> Expand All
<% end %>
<%= content_tag(:a, href: '', class: "collapse-all") do %>
<i class='fa fa-compress'></i> Collapse All
<% end %>
</div>
<script>
window.whenReady(function () {
$('.form-section-header-expander').on('click', function (event) {
function setCollapseVisibility () {
var allCollapsables = $('section.collapse, section.collapsing').length;
var openCollapsables = $('section.collapse.in').length;
$('.form-section-header-expander .collapse-all').toggleClass('hidden', openCollapsables === 0);
$('.form-section-header-expander .expand-all').toggleClass('hidden', openCollapsables === allCollapsables);
}
$('section.collapse').on('shown.bs.collapse hidden.bs.collapse', setCollapseVisibility);
$('.form-section-header-expander a').on('click', function (event) {
event.stopPropagation();
$('section.collapse').collapse('show');
var action = $(event.currentTarget).hasClass('expand-all') ? 'show' : 'hide';
$('section.collapse').collapse(action);
return false;
});
setTimeout(setCollapseVisibility);
});
</script>

<%= event_form_section form: f, label: 'Organizer Information' do %>
<%= event_form_section form: f, label: 'Organizer Information', force_expanded: true do %>
<div class="field">
<%= f.input :public_email, label: 'What email address should users contact you at with questions?' %>
</div>
Expand Down
18 changes: 17 additions & 1 deletion spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,23 @@
survey_greeting "Test greeting"

factory :event do
before(:create) do |event, evaluator|
trait :imported do
imported_event_data(
{
type: 'meetup',
student_event: {
id: 901,
url: 'http://example.com/901'
},
volunteer_event: {
id: 902,
url: 'http://example.com/901'
}
}
)
end

after(:build) do |event, evaluator|
event.event_sessions << build(:event_session, event: event, starts_at: event.starts_at, ends_at: event.ends_at)
end
end
Expand Down
4 changes: 1 addition & 3 deletions spec/features/events/event_detail_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,9 @@

visit edit_event_path(@event)

page.find('.form-section-header', text: 'Event Description').click
expect(page).to have_css('.remove-session')
page.all('.remove-session')[-1].click
page.all('.remove-session').last.click

page.find('.form-section-header', text: 'Event Description').click
expect(page).to have_css('.event-sessions .fields', count: 1)

expect(@event.event_sessions.count).to eq(1)
Expand Down
2 changes: 2 additions & 0 deletions spec/features/events/event_listing_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
description: "This is a Front End workshop. The focus will be on designing web apps with HTML and CSS."))
visit events_path
click_link "Organize Event"
expand_all_event_sections
end

it "can create a new event" do
Expand Down Expand Up @@ -211,6 +212,7 @@
it "should display frontend content for frontend events" do
visit events_path
click_link "Organize Event"
expand_all_event_sections

fill_in "Title", with: "March Event"
fill_in "event_target_audience", with: "women"
Expand Down
57 changes: 30 additions & 27 deletions spec/features/events/new_event_request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

describe "New Event" do
describe "New Event", js: true do
let(:fill_in_good_location_details) do
find('#location_region_id').find(:xpath, 'option[2]').select_option
fill_in "Name", with: "UChicago"
Expand All @@ -19,32 +19,33 @@
end

it "should pre-fill the event details textarea" do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

expect(page.find_field('event_details')[:value]).to match(/Workshop Description/)
end

it "should have a public organizer email field" do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

label = "What email address should users contact you at with questions?"
expect(page).to have_field(label)
expect(page.field_labeled(label)[:value]).to eq("organizer@mail.com")
end

it "should have the code of conduct checkbox checked" do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

expect(page).to have_unchecked_field("coc")
end

it 'changes the code of conduct URL if the chapter-org has a custom one', js: true do
visit "/events/new"
it 'changes the code of conduct URL if the chapter-org has a custom one' do
visit_new_events_form_and_expand_all_sections

custom_coc_org = create(:organization, name: 'CustomCoc', code_of_conduct_url: 'http://example.com/coc')
create(:chapter, name: 'CustomCocChapter', organization: custom_coc_org)

visit "/events/new"
visit_new_events_form_and_expand_all_sections

expect(page.find('label[for=coc] a')['href']).to eq(Event::DEFAULT_CODE_OF_CONDUCT_URL)
check("coc")

Expand All @@ -56,27 +57,27 @@
end

it "should have appropriate locations available" do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

live_location = create(:location)
archived_location = create(:location)
archived_location.archive!

visit "/events/new"
visit_new_events_form_and_expand_all_sections
expect(page).to have_select('event_location_id', options: [
"Please select",
live_location.name_with_region
])
end

it "should have a food options toggle" do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

expect(page).to have_checked_field('event_food_provided_true')
end

it 'allows organizers to specify a whitelist of allowed OSes', js: true do
visit "/events/new"
it 'allows organizers to specify a whitelist of allowed OSes' do
visit_new_events_form_and_expand_all_sections

fill_in_good_event_details

Expand All @@ -93,16 +94,16 @@
end

it 'allows organizer to choose when to send their announcement email' do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

expect(page.find('#event_email_on_approval_true')[:checked]).to eq('checked')
expect(page.find('#event_email_on_approval_true')[:checked]).to be true
choose('event_email_on_approval_true')
choose('event_email_on_approval_false')
end

describe "the location form modal", js: true do
describe "the location form modal" do
it "should show errors if a location form is invalid" do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

click_link "add it"
click_button "Create Location"
Expand All @@ -112,7 +113,7 @@

it "should accept and add a valid location" do
@region = create(:region)
visit "/events/new"
visit_new_events_form_and_expand_all_sections

click_link "add it"
fill_in_good_location_details
Expand All @@ -126,7 +127,7 @@
end
end

describe "autodetecting time zone based on location", js: true do
describe "autodetecting time zone based on location" do
let!(:pacific_location) do
create(
:location,
Expand All @@ -153,7 +154,7 @@
end

it 'changes the time zone dropdown when the location is changed' do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

select pacific_location.name_with_region, from: "event_location_id"
expect(find_field('event_time_zone').value).to match(/Pacific/)
Expand All @@ -163,9 +164,10 @@
end
end

context 'after clicking "Add another session"', js: true do
context 'after clicking "Add another session"' do
before do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

click_on 'Add another session'
end

Expand All @@ -179,12 +181,12 @@
end
end

describe 'session location assignment', js: true do
describe 'session location assignment' do
let!(:event_location) { create(:location) }
let!(:session_location) { create(:location) }

it 'can set a different location for certain sessions' do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

fill_in_good_event_details
select event_location.name_with_region, from: "event_location_id"
Expand All @@ -209,9 +211,9 @@
end
end

context 'submit form', js: true do
context 'submit form' do
it 'requires code of conduct to be checked, and preserves checked-ness on error' do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

expect(page).to have_button 'Submit Event For Approval', disabled: true
expect(page).to have_unchecked_field('coc')
Expand All @@ -224,13 +226,14 @@
end

it 'allows a draft to be saved' do
visit "/events/new"
visit_new_events_form_and_expand_all_sections

fill_in_good_event_details
choose('event_email_on_approval_false')
expect(page).to have_button 'Save Draft'
click_on 'Save Draft'

expand_all_event_sections
expect(page).to have_content('Draft saved')
expect(page.current_path).to eq '/events'
expect(page).to have_button 'Save Draft'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
before do
create(:course)
sign_in_as(user_organizer)
visit "/events/new"
visit_new_events_form_and_expand_all_sections
fill_in_good_event_details
fill_in 'What population is this workshop reaching out to?', with: "a population"
check("coc")
Expand Down
Loading

0 comments on commit e345e5b

Please sign in to comment.