<commit_before>
require 'rails_helper'

include Warden::Test::Helpers
Warden.test_mode!

describe 'Profile edit' do
  before :each do
    user = FactoryGirl.create(:user)
    login_as(user)
  end

  it 'uploads and deletes image' do
    visit edit_user_registration_path
    page.attach_file('user_image', Rails.root + 'spec/fixtures/mikki.png')
    fill_in('Etunimi', with:'Pekka')
    fill_in('Sukunimi', with:'Pekkanen')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')

    expect(page.html).to include 'cloudinary.com'
    expect(page).not_to have_content 'esti käyttäjän tallentamisen'

    visit edit_user_registration_path
    check('user_remove_image')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')

    expect(page.html).not_to include 'cloudinary.com'
    expect(page).not_to have_content 'esti käyttäjän tallentamisen'
  end

  it 'rejects zip-file' do
    visit edit_user_registration_path
    page.attach_file('user_image', Rails.root + 'spec/fixtures/zip.zip')
    fill_in('Etunimi', with:'Pekka')
    fill_in('Sukunimi', with:'Pekkanen')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')

    expect(page).to have_content 'Profiilikuva ei ole sallittua tiedostotyyppiä'
  end

  # it 'rejects too big file' do
  #   visit edit_user_registration_path
  #   page.attach_file('user_image', Rails.root + 'spec/fixtures/tetris.jpg')
  #   fill_in('Etunimi', with:'Pekka')
  #   fill_in('Sukunimi', with:'Pekkanen')
  #   fill_in('Nykyinen salasana', with:'ihanmitavaan')
  #
  #   click_button('Päivitä')
  #
  #   expect(page).to have_content 'Profiilikuva ei ole sallittua tiedostotyyppiä'
  # end

  it 'edits name' do
    visit edit_user_registration_path
    fill_in('Etunimi', with:'Pekka')
    fill_in('Sukunimi', with:'Pekkanen')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')

    expect(page).to have_content 'Pekka Pekkanen'
    expect(page).not_to have_content 'esti käyttäjän tallentamisen'
  end

  it 'edits address' do
    visit edit_user_registration_path
    fill_in('Osoite', with:'Siilitie 4')
    fill_in('Postinumero', with:'00100')
    fill_in('Kaupunki', with:'Vantaa')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')<commit_msg>Tiedostokoon testaus<commit_after>
require 'rails_helper'

include Warden::Test::Helpers
Warden.test_mode!

describe 'Profile edit' do
  before :each do
    user = FactoryGirl.create(:user)
    login_as(user)
  end

  it 'uploads and deletes image' do
    visit edit_user_registration_path
    page.attach_file('user_image', Rails.root + 'spec/fixtures/mikki.png')
    fill_in('Etunimi', with:'Pekka')
    fill_in('Sukunimi', with:'Pekkanen')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')

    expect(page.html).to include 'cloudinary.com'
    expect(page).not_to have_content 'esti käyttäjän tallentamisen'

    visit edit_user_registration_path
    check('user_remove_image')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')

    expect(page.html).not_to include 'cloudinary.com'
    expect(page).not_to have_content 'esti käyttäjän tallentamisen'
  end

  it 'rejects zip-file' do
    visit edit_user_registration_path
    page.attach_file('user_image', Rails.root + 'spec/fixtures/zip.zip')
    fill_in('Etunimi', with:'Pekka')
    fill_in('Sukunimi', with:'Pekkanen')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')

    expect(page).to have_content 'Profiilikuva ei ole sallittua tiedostotyyppiä'
  end

  it 'rejects too big file' do
    visit edit_user_registration_path
    page.attach_file('user_image', Rails.root + 'spec/fixtures/tetris.jpg')
    fill_in('Etunimi', with:'Pekka')
    fill_in('Sukunimi', with:'Pekkanen')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')

    expect(page).to have_content 'Profiilikuva on liian suuri'
  end

  it 'edits name' do
    visit edit_user_registration_path
    fill_in('Etunimi', with:'Pekka')
    fill_in('Sukunimi', with:'Pekkanen')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')

    expect(page).to have_content 'P<NAME>'
    expect(page).not_to have_content 'esti käyttäjän tallentamisen'
  end

  it 'edits address' do
    visit edit_user_registration_path
    fill_in('Osoite', with:'Siilitie 4')
    fill_in('Postinumero', with:'00100')
    fill_in('Kaupunki', with:'Vantaa')
    fill_in('Nykyinen salasana', with:'ihanmitavaan')

    click_button('Päivitä')
{'fraction_non_alphanumeric': 0.1231665228645384, 'fraction_numerical': 0.0025884383088869713, 'mean_word_length': 4.717632552404439, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '5094090', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1720, 'n_words': 304}