<commit_before>require 'rails_helper'

describe 'Configuration of a site' do
  describe 'when the config is valid' do
    before(:each) do
      configs = [
        ['admin.title', 'TrustyCms CMS'],
        ['admin.subtitle', 'Publishing for Small Teams'],
        ['defaults.page.parts', 'body, extended'],
        ['defaults.page.status', 'Draft'],
        ['defaults.page.filter', nil],
        ['defaults.page.fields', 'Keywords, Description'],
        ['defaults.snippet.filter', nil],
        ['session_timeout', '1209600'], # 2.weeks.to_s ????
        ['default_locale', 'en'],
      ]
      configs.each do |key, value|
        c = TrustyCms::Config.find_or_initialize_by_key(key)
        c.value = value
        c.save
      end
    end

    it 'shows a login page' do
      visit '/'
      expect(page).to have_field 'Username or E-mail Address'
      expect(page).to have_field 'Password'
      expect(page).to have_button 'Login'
    end

    context 'after login' do
      before(:each) do
        User.create name: '<NAME>', login: 'user', password: 'password', password_confirmation: 'password', admin: true

        visit '/'
        fill_in 'username_or_email', with: 'user'
        fill_in 'password', with: 'password'
        click_on 'Login'
      end

      it 'shows the admin interface' do
        expect(User.all.count).to equal 1
        expect(page).to have_content "Logged in as"
      end

      it 'has correct links in header' do
        expect(page).to have_link 'Test User', href: '/admin/preferences/edit'
        expect(page).to have_link 'Logout', href: '/admin/logout'
        expect(page).to have_link 'View Site', href: '/'<commit_msg>Take the config part out of this test since it isn't necessary<commit_after>require 'rails_helper'

describe 'Admin Login' do
  describe 'a valid Admin User' do
    before(:each) do
      @admin_username = 'user'
      @admin_password = 'password'
      User.create name: 'Test User', login: @admin_username, password: <PASSWORD>, password_confirmation: <PASSWORD>, admin: true
    end

    it 'shows a login page' do
      visit '/'
      expect(page).to have_field 'Username or E-mail Address'
      expect(page).to have_field 'Password'
      expect(page).to have_button 'Login'
    end

    context 'after login' do
      before(:each) do
        User.create name: 'Test User', login: 'user', password: 'password', password_confirmation: 'password', admin: true

        visit '/'
        fill_in 'username_or_email', with: 'user'
        fill_in 'password', with: 'password'
        click_on 'Login'
      end

      it 'shows the admin interface' do
        expect(page).to have_content "Logged in as"
      end

      it 'has correct links in header' do
        expect(page).to have_link 'Test User', href: '/admin/preferences/edit'
        expect(page).to have_link 'Logout', href: '/admin/logout'
        expect(page).to have_link 'View Site', href: '/'
{'fraction_non_alphanumeric': 0.12538330494037478, 'fraction_numerical': 0.0030664395229982964, 'mean_word_length': 2.707070707070707, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '4131504', 'n_tokens_mistral': 902, 'n_tokens_neox': 875, 'n_words': 268}