<commit_before># encoding: utf-8

require "spec_helper"

describe FoundationRailsHelper::FlashHelper do
  include ActionView::Context if defined?(ActionView::Context)
  include ActionView::Helpers::UrlHelper
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::TextHelper
  include FoundationRailsHelper::FlashHelper

  FoundationRailsHelper::FlashHelper::DEFAULT_KEY_MATCHING.each do |message_type, foundation_type|
    it "displays flash message with #{foundation_type} class for #{message_type} message" do
      allow(self).to receive(:flash).and_return({message_type => "Flash message"})
      node = Capybara.string display_flash_messages
      expect(node).
        to  have_css("div.alert-box.#{foundation_type}", :text => "Flash message").
        and have_css("div.alert-box a.close", :text => "×")
    end
  end

  it "displays multiple flash messages" do
    allow(self).to receive(:flash).and_return({ success: "Yay it worked", error: "But this other thing failed" })
    node = Capybara.string display_flash_messages
    expect(node).
      to  have_css("div.alert-box.success", :text => "Yay it worked").
      and have_css("div.alert-box.alert",   :text => "But this other thing failed")
  end

  it "displays flash message with overridden key matching" do
    allow(self).to receive(:flash).and_return({:notice => "Flash message"})
    node = Capybara.string display_flash_messages({:notice => :alert})
    expect(node).to have_css("div.alert-box.alert", :text => "Flash message")
  end

  it "displays flash message with custom key matching" do
    allow(self).to receive(:flash).and_return({:custom_type => "Flash message"})
    node = Capybara.string display_flash_messages({:custom_type => :custom_class})
    expect(node).to have_css("div.alert-box.custom_class", :text => "Flash message")
  end

  it "displays flash message with standard class if key doesn't match" do
    allow(self).to receive(:flash).and_return({:custom_type => "Flash message"})
    node = Capybara.string display_flash_messages
    expect(node).to have_css("div.alert-box.standard", :text => "Flash message")
  end
  
  it "shouldn't die when flash hash contains devise internal data" do
    allow(self).to receive(:flash).and_return({:timedout => true})
    node = Capybara.string display_flash_messages
    expect(node).to have_css("div.alert-box.standard")
  end
end<commit_msg>Change specs to use string keys: this is what we actually get when looping through the FlashHash<commit_after># encoding: utf-8

require "spec_helper"

describe FoundationRailsHelper::FlashHelper do
  include ActionView::Context if defined?(ActionView::Context)
  include ActionView::Helpers::UrlHelper
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::TextHelper
  include FoundationRailsHelper::FlashHelper

  FoundationRailsHelper::FlashHelper::DEFAULT_KEY_MATCHING.each do |message_type, foundation_type|
    it "displays flash message with #{foundation_type} class for #{message_type} message" do
      allow(self).to receive(:flash).and_return({message_type.to_s => "Flash message"})
      node = Capybara.string display_flash_messages
      expect(node).
        to  have_css("div.alert-box.#{foundation_type}", :text => "Flash message").
        and have_css("div.alert-box a.close", :text => "×")
    end
  end

  it "handles symbol keys" do
    allow(self).to receive(:flash).and_return({ "success" => "Flash message" })
    node = Capybara.string display_flash_messages
    expect(node).to have_css("div.alert-box.success", :text => "Flash message")
  end

  it "handles string keys" do
    allow(self).to receive(:flash).and_return({ "success" => "Flash message" })
    node = Capybara.string display_flash_messages
    expect(node).to have_css("div.alert-box.success", :text => "Flash message")
  end

  it "displays multiple flash messages" do
    allow(self).to receive(:flash).and_return({ "success" => "Yay it worked", "error" => "But this other thing failed" })
    node = Capybara.string display_flash_messages
    expect(node).
      to  have_css("div.alert-box.success", :text => "Yay it worked").
      and have_css("div.alert-box.alert",   :text => "But this other thing failed")
  end

  it "displays flash message with overridden key matching" do
    allow(self).to receive(:flash).and_return({ "notice" => "Flash message" })
    node = Capybara.string display_flash_messages({:notice => :alert})
    expect(node).to have_css("div.alert-box.alert", :text => "Flash message")
  end

  it "displays flash message with custom key matching" do
    allow(self).to receive(:flash).and_return({ "custom_type" => "Flash message" })
    node = Capybara.string display_flash_messages({:custom_type => :custom_class})
    expect(node).to have_css("div.alert-box.custom_class", :text => "Flash message")
  end

  it "displays flash message with standard class if key doesn't match" do
    allow(self).to receive(:flash).and_return({ "custom_type" => "Flash message" })
    node = Capybara.string display_flash_messages
    expect(node).to have_css("div.alert-box.standard", :text => "Flash message")
  end
  
  it "shouldn't die when flash hash contains devise internal data" do
    allow(self).to receive(:flash).and_return({:timedout => true})
    node = Capybara.string display_flash_messages
    expect(node).to have_css("div.alert-box.standard")
  end
end
{'fraction_non_alphanumeric': 0.1285475792988314, 'fraction_numerical': 0.0003709886848451122, 'mean_word_length': 4.640167364016737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '6809314', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1601, 'n_words': 424}