<commit_before>require 'spec_helper'

describe PetitionsHelper do
  let(:browser) { mock }
  before { helper.stub!(:browser).and_return browser }

  describe '#open_graph_for' do
    let(:petition) { create(:petition) }
    let(:member) { create(:member) }
    let(:signer_code) { create(:referral_code, member: member, petition: petition) }
    let(:config) {{
      facebook: {
        site_name: 'My Super Petitions',
        app_id: 12345
      }
    }}

    before(:each) do
      helper.stub!(:spin!)
      helper.stub!(:social_media_config).and_return config
    end

    subject { helper.open_graph_for(petition, signer_code) }
    it { should include('og:type' => 'watchdognet:petition') }
    it { should include('og:title' => petition.title) }
    it { should include('og:description' => strip_tags(petition.description)) }
    it "should have an image drawn from the list of possible Facebook images" do
      Rails.configuration.social_media[:facebook][:images].should include subject['og:image']
    end
    it { should include('og:site_name' => 'My Super Petitions') }
    it { should include('fb:app_id' => 12345) }
  end

  describe '#open_graph_for where alternate title exists' do
    let(:petition) { create(:petition) }
    let(:member) { create(:member) }
    let(:signer_code) { create(:referral_code, member: member, petition: petition) }
    let(:alt_title) { create(:petition_title, petition: petition, title_type: PetitionTitle::TitleType::FACEBOOK)}

    context "member hash is valid" do
      subject { helper.open_graph_for(petition, signer_code) }
      it { should include('og:title' => alt_title.title)}
    end
  end

  describe '#choose_form_based_on_browser' do

    context 'for an ie user' do
      before do
        helper.browser.stub!(:ie?).and_return true
        helper.browser.stub!(:user_agent).and_return 'MSIE'
      end

      specify{ helper.choose_form_based_on_browser.should == 'ie_form' }
    end

    context 'for a regular browser user' do
      before do
        helper.browser.stub!(:ie?).and_return false
        helper.browser.stub!(:user_agent).and_return anything
      end

      specify{ helper.choose_form_based_on_browser.should == 'form' }
    end

    context 'for a fake ie user' do
      before do
        helper.browser.stub!(:ie?).and_return true
        helper.browser.stub!(:user_agent).and_return 'chromeframe'
      end

      specify{ helper.choose_form_based_on_browser.should == 'form' }
    end
  end

  describe '#facebook_sharing_option' do

    context 'for an ie7 user' do
      before { browser.stub!(:ie7?).and_return true }
      specify{ helper.facebook_sharing_option.should == 'facebook_popup' }
    end


    context 'for a regular browser user' do
      let(:exp) { 'facebook sharing options' }
      let(:goal) { :referred_member }
      let(:options) { ['facebook_popup', 'facebook_request', 'facebook_recommendation'] }

      before { browser.stub!(:ie7?).and_return false }

      it 'should spin for an option' do
        helper.should_receive(:spin!).with(exp, goal, options)
        helper.facebook_sharing_option
      end
    end
  end

  describe '#facebook_button' do

    shared_examples 'facebook button hash' do
      before do
        helper.stub(:facebook_sharing_option).and_return option
      end

      subject { helper.facebook_button }

      it{ should include(button_class: button_class) }
      it{ should include(button_text: button_text) }
    end

    context 'when facebook sharing option is blank' do
      let(:option) { '' }
      let(:button_class) { 'fb_popup_btn' }
      let(:button_text) { 'Share on Facebook' }
<commit_msg>fix tests<commit_after>require 'spec_helper'

describe PetitionsHelper do
  let(:browser) { mock }
  before { helper.stub!(:browser).and_return browser }

  describe '#open_graph_for' do
    let(:petition) { create(:petition) }
    let(:member) { create(:member) }
    let(:signer_code) { create(:referral_code, member: member, petition: petition) }
    let(:config) {{
      facebook: {
        site_name: 'My Super Petitions',
        app_id: 12345
      }
    }}

    before(:each) do
      helper.stub!(:spin!)
      helper.stub!(:social_media_config).and_return config
    end

    subject { helper.open_graph_for(petition, signer_code) }
    it { should include('og:type' => 'watchdognet:petition') }
    it { should include('og:title' => petition.title) }
    it { should include('og:description' => strip_tags(petition.description)) }
    it "should have an image drawn from the list of possible Facebook images" do
      Rails.configuration.social_media[:facebook][:images].should include subject['og:image']
    end
    it { should include('og:site_name' => 'My Super Petitions') }
    it { should include('fb:app_id' => 12345) }
  end

  describe '#open_graph_for where alternate title exists' do
    let(:petition) { create(:petition) }
    let(:member) { create(:member) }
    let(:signer_code) { create(:referral_code, member: member, petition: petition) }
    let(:alt_title) { create(:petition_title, petition: petition, title_type: PetitionTitle::TitleType::FACEBOOK)}

    context "member hash is valid" do
      subject { helper.open_graph_for(petition, signer_code) }
      it { should include('og:title' => alt_title.title)}
    end
  end

  describe '#choose_form_based_on_browser' do

    context 'for an ie user' do
      before do
        helper.browser.stub!(:ie?).and_return true
        helper.browser.stub!(:user_agent).and_return 'MSIE'
      end

      specify{ helper.choose_form_based_on_browser.should == 'ie_form' }
    end

    context 'for a regular browser user' do
      before do
        helper.browser.stub!(:ie?).and_return false
        helper.browser.stub!(:user_agent).and_return anything
      end

      specify{ helper.choose_form_based_on_browser.should == 'form' }
    end

    context 'for a fake ie user' do
      before do
        helper.browser.stub!(:ie?).and_return true
        helper.browser.stub!(:user_agent).and_return 'chromeframe'
      end

      specify{ helper.choose_form_based_on_browser.should == 'form' }
    end
  end

  describe '#facebook_sharing_option' do

    context 'for an ie7 user' do
      before { browser.stub!(:ie7?).and_return true }
      specify{ helper.facebook_sharing_option.should == 'facebook_popup' }
    end


    context 'for a regular browser user' do
      let(:exp) { 'facebook sharing options' }
      let(:goal) { :referred_member }
      let(:options) { ['facebook_popup', 'facebook_request', 'facebook_recommendation', 'facebook_dialog'] }

      before { browser.stub!(:ie7?).and_return false }

      it 'should spin for an option' do
        helper.should_receive(:spin!).with(exp, goal, options)
        helper.facebook_sharing_option
      end
    end
  end

  describe '#facebook_button' do

    shared_examples 'facebook button hash' do
      before do
        helper.stub(:facebook_sharing_option).and_return option
      end

      subject { helper.facebook_button }

      it{ should include(button_class: button_class) }
      it{ should include(button_text: button_text) }
    end

    context 'when facebook sharing option is blank' do
      let(:option) { '' }
      let(:button_class) { 'fb_popup_btn' }
      let(:button_text) { 'Share on Facebook' }

{'fraction_non_alphanumeric': 0.11566297965314762, 'fraction_numerical': 0.0035504574627884746, 'mean_word_length': 3.3158515026517383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '509371', 'n_tokens_mistral': 2295, 'n_tokens_neox': 2198, 'n_words': 532}