<commit_before>require 'spec_helper'

module TestHelper #FIXME: merge with unit test_helper.rb
  def self.create_valid_poll(title = '2b|!2b?', category = Poll::CATEGORIES.first)
    Poll.create(:title => title, :category => category)
  end

  def self.new_valid_poll(title = '2b|!2b?', category = Poll::CATEGORIES.first)
    Poll.new(:title => title, :category => category)
  end

  def self.create_and_save_poll
    poll = create_valid_poll
    poll.save
    poll
  end
  
  def self.create_close_and_save_poll
    poll = create_valid_poll
    poll.close
    poll.save
    poll
  end
end

describe "Poll administration" do
  describe "GET / polls" do
    it "should initially have no active and closed polls" do
      visit polls_path
      page.should have_content('Found no active polls.')
      page.should have_content('Found no closed polls.')
    end
  
    it "should open create poll page" do
      visit polls_path
      click_link 'Create poll'
      page.should have_content('New question')
    end
  
    it "should have one active and one closed poll" do
      TestHelper.create_and_save_poll
      TestHelper.create_close_and_save_poll
      visit polls_path
      page.should_not have_content('Found no active polls.')
      page.should_not have_content('Found no closed polls.')
    end
  
    #FIXME: how to test Cancel close?
    it "should close poll" do
      TestHelper.create_and_save_poll
      visit polls_path
      click_button 'Close poll'
      page.should have_content('Found no active polls.')
      page.should_not have_content('Found no closed polls.')
    end
  
    #FIXME: how to test Cancel delete?
    it "should delete poll" do
      TestHelper.create_close_and_save_poll
      visit polls_path
      click_button 'Delete poll'
      page.should have_content('Found no closed polls.')
    end
  end
  
  describe "GET/PUT/POST new poll" do
    it "should have only a single question at first" do
      visit new_poll_path
      page.should have_content('Question 1')
      page.should_not have_content('Question 2')
    end
  
    it "should fail to add new question and not append question when empty" do
      visit new_poll_path
      click_button 'Add question'
      page.should have_content("Text can't be blank")
      page.should have_content('Question 1')
      page.should have_xpath("//span[@class='field_with_errors']")
      page.should_not have_content('Question 2')<commit_msg>add: test cancel add poll<commit_after>require 'spec_helper'

module TestHelper #FIXME: merge with unit test_helper.rb
  def self.create_valid_poll(title = '2b|!2b?', category = Poll::CATEGORIES.first)
    Poll.create(:title => title, :category => category)
  end

  def self.new_valid_poll(title = '2b|!2b?', category = Poll::CATEGORIES.first)
    Poll.new(:title => title, :category => category)
  end

  def self.create_and_save_poll
    poll = create_valid_poll
    poll.save
    poll
  end
  
  def self.create_close_and_save_poll
    poll = create_valid_poll
    poll.close
    poll.save
    poll
  end
end

describe "Poll administration" do
  describe "GET / polls" do
    it "should initially have no active and closed polls" do
      visit polls_path
      page.should have_content('Found no active polls.')
      page.should have_content('Found no closed polls.')
    end
  
    it "should open create poll page" do
      visit polls_path
      click_link 'Create poll'
      page.should have_content('New question')
    end
  
    it "should have one active and one closed poll" do
      TestHelper.create_and_save_poll
      TestHelper.create_close_and_save_poll
      visit polls_path
      page.should_not have_content('Found no active polls.')
      page.should_not have_content('Found no closed polls.')
    end
  
    #FIXME: how to test Cancel close?
    it "should close poll" do
      TestHelper.create_and_save_poll
      visit polls_path
      click_button 'Close poll'
      page.should have_content('Found no active polls.')
      page.should_not have_content('Found no closed polls.')
    end
  
    #FIXME: how to test Cancel delete?
    it "should delete poll" do
      TestHelper.create_close_and_save_poll
      visit polls_path
      click_button 'Delete poll'
      page.should have_content('Found no closed polls.')
    end
  end
  
  describe "GET/PUT/POST new poll" do
    it "should initially have only a single question" do
      visit new_poll_path
      page.should have_content('Question 1')
      page.should_not have_content('Question 2')
    end
    
    it "should cancel new poll" do
      visit new_poll_path
      click_button 'Cancel'
      page.should have_content('Active polls')
    end
  
    it "should fail to add new question and not append question when empty" do
      visit new_poll_path
      click_button 'Add question'
      page.should have_content("Text can't be blank")
      page.should have_content('Question 1')
      page.should have_xpath("//span[@class='field_with_errors']")
      page.should_not have_content('Question 2')
{'fraction_non_alphanumeric': 0.07762738853503184, 'fraction_numerical': 0.0031847133757961785, 'mean_word_length': 3.0589660743134086, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5096694', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1521, 'n_words': 466}