<commit_before>require 'rails_helper'

feature "The admin panel" do
  let(:admin) { FactoryGirl.create(:admin) }
  let(:chapter) { FactoryGirl.create(:chapter) }
  let(:event) { FactoryGirl.create(:event) }

  let(:event_title) { Faker::Lorem.words(4).join(" ") }
  let(:event_description) { Faker::Lorem.paragraph }
  let(:event_starts_at) { 1.week.from_now.beginning_of_hour }
  let(:event_ends_at) { (1.week.from_now + 2.hours).beginning_of_hour }

  before { login(admin) }

  context "Events" do
    it "Allows an admin to create an event" do
      visit admin_chapter_path(chapter)
      fill_in_event_form(event_title, event_description, event_starts_at, event_ends_at)

      expect { click_button "Create new event" }.to change { Event.count }.by 1
      expect(page).to have_content event_title
      expect(page).to have_content event_description

      new_event = Event.last
      expect(new_event.starts_at).to eq event_starts_at
      expect(new_event.ends_at).to eq event_ends_at
    end

    it "Creates unpublished events by default" do
      visit admin_chapter_path(chapter)
      fill_in_event_form(event_title, event_description, event_starts_at, event_ends_at)
      click_button "Create new event"

      expect(Event.last.published?).to be false
    end

    it "Allows an admin to publish an unpublished event" do
      event = FactoryGirl.create(:unpublished_event)
      visit admin_chapter_event_path(event.chapter, event)
      click_button "Publish"
      event.reload
      expect(event.published?).to be true
    end

    it "Allows an admin to unpublish a published event" do
      visit admin_chapter_event_path(event.chapter, event)
      click_button "Unpublish"
      event.reload
      expect(event.published?).to be false
    end

    it "Allows an admin to edit an event"
    it "Allows an admin to see potential attendees"
    it "Allows an admin to send an attendee an invite"
  end
end

def fill_in_event_form(title, description, starts_at, ends_at)
  fill_in :event_title, with: title
  fill_in :event_description, with: description
  datetime_select(:event_starts_at, starts_at)
  datetime_select(:event_ends_at, ends_at)
end

<commit_msg>A test for committing an event.<commit_after>require 'rails_helper'

feature "The admin panel" do
  let(:admin) { FactoryGirl.create(:admin) }
  let(:chapter) { FactoryGirl.create(:chapter) }
  let(:event) { FactoryGirl.create(:event) }

  let(:event_title) { Faker::Lorem.words(4).join(" ") }
  let(:event_description) { Faker::Lorem.paragraph }
  let(:event_starts_at) { 1.week.from_now.beginning_of_hour }
  let(:event_ends_at) { (1.week.from_now + 2.hours).beginning_of_hour }

  before { login(admin) }

  context "Events" do
    it "Allows an admin to create an event" do
      visit admin_chapter_path(chapter)
      fill_in_event_form(event_title, event_description, event_starts_at, event_ends_at)

      expect { click_button "Create new event" }.to change { Event.count }.by 1
      expect(page).to have_content event_title
      expect(page).to have_content event_description

      new_event = Event.last
      expect(new_event.starts_at).to eq event_starts_at
      expect(new_event.ends_at).to eq event_ends_at
    end

    it "Creates unpublished events by default" do
      visit admin_chapter_path(chapter)
      fill_in_event_form(event_title, event_description, event_starts_at, event_ends_at)
      click_button "Create new event"

      expect(Event.last.published?).to be false
    end

    it "Allows an admin to publish an unpublished event" do
      event = FactoryGirl.create(:unpublished_event)
      visit admin_chapter_event_path(event.chapter, event)
      click_button "Publish"
      event.reload
      expect(event.published?).to be true
    end

    it "Allows an admin to unpublish a published event" do
      visit admin_chapter_event_path(event.chapter, event)
      click_button "Unpublish"
      event.reload
      expect(event.published?).to be false
    end

    it "Allows an admin to edit an event" do
      new_title = Faker::Lorem.sentence
      new_start_time = (event.starts_at - 1.hour).beginning_of_hour

      visit edit_admin_chapter_event_path(event.chapter, event)
      fill_in :event_title, with: new_title
      datetime_select :event_starts_at, new_start_time
      click_button "Save changes"

      # Flash message should be a success, not an error
      expect(page).not_to have_selector ".alert-danger"
      expect(page).to have_selector ".alert-info"

      # Event should have been updated
      event.reload
      expect(event.title).to eq new_title
      expect(event.starts_at).to eq new_start_time
    end

    it "Allows an admin to see potential attendees"
    it "Allows an admin to send an attendee an invite"
  end
end

def fill_in_event_form(title, description, starts_at, ends_at)
  fill_in :event_title, with: title
  fill_in :event_description, with: description
  datetime_select(:event_starts_at, starts_at)
  datetime_select(:event_ends_at, ends_at)
end


{'fraction_non_alphanumeric': 0.08623780123481378, 'fraction_numerical': 0.00219079864568811, 'mean_word_length': 3.782857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1179080', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1573, 'n_words': 404}