<commit_before>require "stories_helper"

class SitesTest < Test::Unit::TestCase
  story "I should be able to create a new Site to watch" do
    scenario "A user goes to the new site page" do
      visit "/sites/new"

      assert_contain "Setup a New Site to Watch"

      assert_have_selector 'form input[name="site[name]"]'
      assert_have_selector 'form input[name="site[url]"]'
      assert_have_selector 'form textarea[name="site[match_text]"]'
      assert_have_selector 'form input[name="site[threshold]"]'
      assert_have_selector 'form input[name="site[email]"]'
    end

    scenario "A user submits valid site information" do
      visit "/sites/new"
      fill_in "site-name", :with => "Google"
      fill_in "site-url", :with => "http://google.com/search?q=#{rand(9999)}"
      fill_in "site-match_text", :with => "xxxxx"
      fill_in "site-threshold", :with => "5"
      fill_in "site-email", :with => "<EMAIL>"
      click_button "add"

      assert_have_no_selector "form"
      assert_contain "<EMAIL>"
    end

    scenario "A user submits invalid site information" do
      visit "/sites/new"
      fill_in "site-name", :with => "Google"
      fill_in "site-url", :with => ""
      fill_in "site-match_text", :with => "xxxxx"
      fill_in "site-threshold", :with => "5"
      fill_in "site-email", :with => "<EMAIL>"
      click_button "add"

      assert_have_selector 'form input[value="<EMAIL>"]'
    end
  end

  story "I should be able to view details about a site" do
    scenario "A user goes to the site page" do
      site = Site.factory.save
      visit "/sites/#{site.id}"
      assert_contain "feeling lucky"
    end
  end

  story "I should be able to edit details about a site" do
    scenario "A user goes to the site edit page" do
      site = Site.factory.save
      visit "/sites/#{site.id}/edit"
      assert_have_selector 'form textarea[name="site[match_text]"]'
      assert_contain "feeling lucky"
    end

    scenario "A user updates a site record" do
      site = Site.factory.save
      visit "/sites/#{site.id}/edit"
      fill_in "email", :with => "<EMAIL>"
      click_button "save"

      assert_have_no_selector "form"
      assert_contain "<EMAIL>"
      assert_contain "feeling lucky"
    end

    scenario "A user updates a site record with invalid data" do
      site = Site.factory.save
      visit "/sites/#{site.id}/edit"
      fill_in "email", :with => "xxxxx"
      click_button "save"

      assert_not_contain "xxxxx"
      assert_have_selector "form"
    end
  end
  
  story "monit should be able update the satus of a site" do
    scenario "monit hits the API endpoint with a success status" do
      site = Site.factory.save
      
      visit "/sites/#{site.id}/status", :post, {:status => "success"}
      
      site = Site[site.id]
      assert_equal site.status_record.sort(:order => "DESC", :limit => 1).first, "success"
    end
    
    scenario "monit hits the API endpoint with a fail status" do
      site = Site.factory.save
      
      visit "/sites/#{site.id}/status", :post, {:status => "fail"}
      
      site = Site[site.id]
      assert_equal site.status_record.sort(:order => "DESC", :limit => 1).first, "fail"
    end
  end<commit_msg>Fix for monitrc test files sticking around.<commit_after>require "stories_helper"

class SitesTest < Test::Unit::TestCase
  story "I should be able to create a new Site to watch" do
    scenario "A user goes to the new site page" do
      visit "/sites/new"

      assert_contain "Setup a New Site to Watch"

      assert_have_selector 'form input[name="site[name]"]'
      assert_have_selector 'form input[name="site[url]"]'
      assert_have_selector 'form textarea[name="site[match_text]"]'
      assert_have_selector 'form input[name="site[threshold]"]'
      assert_have_selector 'form input[name="site[email]"]'
    end

    scenario "A user submits valid site information" do
      visit "/sites/new"
      fill_in "site-name", :with => "Google"
      fill_in "site-url", :with => "http://google.com/search?q=#{rand(9999)}"
      fill_in "site-match_text", :with => "xxxxx"
      fill_in "site-threshold", :with => "5"
      fill_in "site-email", :with => "<EMAIL>"
      click_button "add"

      assert_have_no_selector "form"
      assert_contain "<EMAIL>"
    end

    scenario "A user submits invalid site information" do
      visit "/sites/new"
      fill_in "site-name", :with => "Google"
      fill_in "site-url", :with => ""
      fill_in "site-match_text", :with => "xxxxx"
      fill_in "site-threshold", :with => "5"
      fill_in "site-email", :with => "<EMAIL>"
      click_button "add"

      assert_have_selector 'form input[value="<EMAIL>"]'
    end
  end

  story "I should be able to view details about a site" do
    scenario "A user goes to the site page" do
      site = Site.factory.save
      visit "/sites/#{site.id}"
      assert_contain "feeling lucky"
    end
  end

  story "I should be able to edit details about a site" do
    scenario "A user goes to the site edit page" do
      site = Site.factory.save
      visit "/sites/#{site.id}/edit"
      assert_have_selector 'form textarea[name="site[match_text]"]'
      assert_contain "feeling lucky"
    end

    scenario "A user updates a site record" do
      site = Site.factory.save
      visit "/sites/#{site.id}/edit"
      fill_in "email", :with => "<EMAIL>"
      click_button "save"

      assert_have_no_selector "form"
      assert_contain "<EMAIL>"
      assert_contain "feeling lucky"
    end

    scenario "A user updates a site record with invalid data" do
      site = Site.factory.save
      visit "/sites/#{site.id}/edit"
      fill_in "email", :with => "xxxxx"
      click_button "save"

      assert_not_contain "xxxxx"
      assert_have_selector "form"
    end
  end
  
  story "monit should be able update the satus of a site" do
    scenario "monit hits the API endpoint with a success status" do
      site = Site.factory.save
      
      visit "/sites/#{site.id}/status", :post, {:status => "success"}
      
      site = Site[site.id]
      assert_equal site.status_record.sort(:order => "DESC", :limit => 1).first, "success"
    end
    
    scenario "monit hits the API endpoint with a fail status" do
      site = Site.factory.save
      
      visit "/sites/#{site.id}/status", :post, {:status => "fail"}
      
      site = Site[site.id]
      assert_equal site.status_record.sort(:order => "DESC", :limit => 1).first, "fail"
    end
  end
  
  teardown do
    FileUtils.rm_f(Dir["monitrc/*.monitrc"])
  end
{'fraction_non_alphanumeric': 0.12374122673176687, 'fraction_numerical': 0.0024412572474824534, 'mean_word_length': 2.8066202090592336, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 51, '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': '2237147', 'n_tokens_mistral': 2122, 'n_tokens_neox': 2069, 'n_words': 627}