<commit_before>require 'rails_helper'

describe 'Using time_sheets#new' do
  before :each do
    @hiwi = FactoryGirl.create(:hiwi)
    @wimi = FactoryGirl.create(:wimi).user
    @contract = FactoryGirl.create(:contract, hiwi: @hiwi, responsible: @wimi)
    login_as @hiwi
  end

  it 'is possible to add a new work sheet' do
    visit new_contract_time_sheet_path(@contract)

    fill_in "time_sheet_month", with: Date.today.month
    fill_in "time_sheet_year", with: Date.today.year

    ts_count_before = TimeSheet.count
    find('#hiddensubmit').click
    expect(TimeSheet.count).to eq(ts_count_before+1)
    # No flash error
    expect(page).to_not have_css('div.alert-danger')
  end
end<commit_msg>Test(time_sheet#new): Feature test for time sheets not in contract month. Ref #506<commit_after>require 'rails_helper'

describe 'Using time_sheets#new' do
  before :each do
    @hiwi = FactoryGirl.create(:hiwi)
    @wimi = FactoryGirl.create(:wimi).user
    @contract = FactoryGirl.create(:contract, hiwi: @hiwi, responsible: @wimi)
    login_as @hiwi
    visit new_contract_time_sheet_path(@contract)
  end

  it 'is possible to add a new work sheet for current month' do
    fill_in "time_sheet_month", with: Date.today.month
    fill_in "time_sheet_year", with: Date.today.year

    expect { find('#hiddensubmit').click }.to change { TimeSheet.count }.by(1)
    # No flash error
    expect(page).to_not have_css('div.alert-danger')
  end

  it 'is not possible to add a work sheet for a month after contract end' do
    after_contract_end = (@contract.end_date + 1.month).end_of_month

    fill_in "time_sheet_month", with: after_contract_end.month
    fill_in "time_sheet_year", with: after_contract_end.year
    find('#hiddensubmit').click

    expect(page).to have_css('div.alert-danger')
    expect(page).to have_current_path(new_contract_time_sheet_path(@contract))
  end

  it 'is not possible to add a work sheet for a month before contract start' do
    before_contract_start = (@contract.start_date - 1.month).beginning_of_month

    fill_in "time_sheet_month", with: before_contract_start.month
    fill_in "time_sheet_year", with: before_contract_start.year
    find('#hiddensubmit').click

    expect(page).to have_css('div.alert-danger')
    expect(page).to have_current_path(new_contract_time_sheet_path(@contract))
  end
end
{'fraction_non_alphanumeric': 0.10485933503836317, 'fraction_numerical': 0.0029838022165387893, 'mean_word_length': 4.483644859813084, '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': '5823496', 'n_tokens_mistral': 803, 'n_tokens_neox': 769, 'n_words': 188}