<commit_before>require 'rails_helper'
require 'cancan/matchers'
require 'timecop'

RSpec.describe DashboardController, type: :controller do
  include Devise::TestHelpers

  let(:valid_session) { }
  let(:user) { create :user }

  let(:valid_attributes) {{
    name:'<NAME>',
    description:'<NAME>',
    participant_count: 2000,
    starts_at_date:'2020-08-23',
    ends_at_date:'2020-08-23',
    starts_at_time:'17:00',
    ends_at_time:'23:59',
    is_private: true,
    user_id: user.id,
    rooms: [FactoryGirl.build(:room)]
  }}

  let(:event) { create :event, user_id: user.id, starts_at: Date.today + 5, ends_at: Date.today + 6 }
  let(:other_event) { create :event, user_id: user.id, starts_at: Date.today + 5, ends_at: Date.today + 6 }
  let(:other_user) { create :user }
  let(:past_event) { create :event, name: 'Past Event', user_id: user.id }
  let(:group) { create :group, users: [user] }

  before(:each) do
    @request.env["devise.mapping"] = Devise.mappings[:user]
    sign_in user
  end

  describe "GET index" do
    it "assigns upcoming event to @events" do
      event = Event.create! valid_attributes
      get :index, {}, valid_session
      event_occurrence = EventOccurrence.new({ event: event, starts_occurring_at: event.starts_at, ends_occurring_at: event.ends_at })
      expect(assigns(:event_occurrences).to_s).to eq([event_occurrence].to_s)
    end

    it "assigns max 5 upcoming events as @events" do
      6.times { |i| FactoryGirl.create(:upcoming_event, name: i.to_s, user_id: user.id) }
      get :index, {}, valid_session
      expect(assigns(:event_occurrences).size).to eq(5)
    end
  
    describe "My tasks partial" do
      let!(:task) { create :assigned_task, event_id: event.id, identity: user, status: 'accepted' }
      let!(:other_task) { create :assigned_task, name: 'Other Task', event_id: event.id, identity: other_user }
      let!(:pending_task) { create :assigned_task, name: 'Pending Task', event_id: event.id, identity: user }
      let!(:past_task) { create :assigned_task, name: 'Past Task', event_id: past_event.id, identity: user, status: 'accepted' }
      let!(:another_group) { create :group }
      let!(:group_task) { create :assigned_task, event_id: event.id, identity: group}
      let!(:task_done) { create :assigned_task, event_id: event.id, identity: user, done: true}

      before do
        Timecop.freeze(Date.today + 3)
      end

      after do
        Timecop.return
      end<commit_msg>Fixes dashboard tests, ref #361<commit_after>require 'rails_helper'
require 'cancan/matchers'
require 'timecop'

RSpec.describe DashboardController, type: :controller do
  include Devise::TestHelpers

  let(:valid_session) { }
  let(:user) { create :user }
  let(:other_user) {create(:user)}

  let(:valid_attributes) {{
    name:'<NAME>',
    description:'<NAME>',
    participant_count: 2000,
    starts_at_date:'2020-08-23',
    ends_at_date:'2020-08-23',
    starts_at_time:'17:00',
    ends_at_time:'23:59',
    is_private: true,
    user_id: user.id,
    rooms: [FactoryGirl.build(:room)]
  }}

  let(:valid_attributes_upcoming) {{
    name:'<NAME>',
    description:'Coole Sache',
    participant_count: 2000,
    starts_at_date:'2020-08-23',
    ends_at_date:'2020-08-23',
    starts_at_time:'17:00',
    ends_at_time:'23:59',
    is_private: false,
    user_id: other_user.id,
    rooms: [FactoryGirl.build(:room)]
  }}

  let(:event) { create :event, user_id: user.id, starts_at: Date.today + 5, ends_at: Date.today + 6 }
  let(:other_event) { create :event, user_id: user.id, starts_at: Date.today + 5, ends_at: Date.today + 6 }
  let(:other_user) { create :user }
  let(:past_event) { create :event, name: 'Past Event', user_id: user.id }
  let(:group) { create :group, users: [user] }

  before(:each) do
    @request.env["devise.mapping"] = Devise.mappings[:user]
    sign_in user
  end

  describe "GET index" do

    it "assigns upcoming event to @events" do
      event = Event.create! valid_attributes_upcoming
      get :index, {}, valid_session
      event_occurrence = EventOccurrence.new({ event: event, starts_occurring_at: event.starts_at, ends_occurring_at: event.ends_at })
      expect(assigns(:event_occurrences).to_s).to eq([event_occurrence].to_s)
    end

    it "assigns max 5 upcoming events as @events" do
      6.times { |i| FactoryGirl.create(:upcoming_event, name: i.to_s, user_id: other_user.id, is_private: false) }
      get :index, {}, valid_session
      expect(assigns(:event_occurrences).size).to eq(5)
    end
  
    describe "My tasks partial" do
      let!(:task) { create :assigned_task, event_id: event.id, identity: user, status: 'accepted' }
      let!(:other_task) { create :assigned_task, name: 'Other Task', event_id: event.id, identity: other_user }
      let!(:pending_task) { create :assigned_task, name: 'Pending Task', event_id: event.id, identity: user }
      let!(:past_task) { create :assigned_task, name: 'Past Task', event_id: past_event.id, identity: user, status: 'accepted' }
      let!(:another_group) { create :group }
      let!(:group_task) { create :assigned_task, event_id: event.id, identity: group}
      let!(:task_done) { create :assigned_task, event_id: event.id, identity: user, done: true}

      before do
        Timecop.freeze(Date.today + 3)
      end

      after do
        Timecop.return
      end
{'fraction_non_alphanumeric': 0.13880067252008219, 'fraction_numerical': 0.019241546796189054, 'mean_word_length': 3.85403445149592, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '4883192', 'n_tokens_mistral': 1959, 'n_tokens_neox': 1844, 'n_words': 425}