<commit_before>describe AnsiblePlaybookController do
  before do
    EvmSpecHelper.create_guid_miq_server_zone
    login_as FactoryGirl.create(:user_admin)
  end

  describe "#show" do
    let(:playbook) { FactoryGirl.create(:embedded_playbook) }
    subject { get :show, :params => {:id => playbook.id} }
    render_views

    it "returns status 200" do
      is_expected.to have_http_status 200
    end

    it "renders correct template" do
      is_expected.to render_template(:partial => "layouts/_textual_groups_generic")
    end

    it "displays tags" do
      get :show, :params => {:id => playbook.id}
      expect(response.body).to include("Smart Management")
    end
  end

  describe "#show_list" do
    subject { get :show_list }
    render_views

    it "returns status 200" do
      is_expected.to have_http_status 200
    end

    it "renders correct template" do
      is_expected.to render_template(:partial => "layouts/_gtl")
    end

    it 'renders the correct toolbar' do
      expect(ApplicationHelper::Toolbar::AnsiblePlaybooksCenter).to receive(:definition).and_call_original
      post :show_list
    end
  end

  describe "#button" do
    before do
      controller.instance_variable_set(:@_params, params)
    end

    context 'tagging one or more playbooks' do
      let(:params) { {:pressed => "embedded_configuration_script_payload_tag"} }

      it 'calls tag method' do
        expect(controller).to receive(:tag).with(controller.class.model)
        controller.send(:button)
      end
    end
  end
end
<commit_msg>Add spec test for toolbar method in ansible playbook controller<commit_after>describe AnsiblePlaybookController do
  before do
    EvmSpecHelper.create_guid_miq_server_zone
    login_as FactoryGirl.create(:user_admin)
  end

  describe "#show" do
    let(:playbook) { FactoryGirl.create(:embedded_playbook) }
    subject { get :show, :params => {:id => playbook.id} }
    render_views

    it "returns status 200" do
      is_expected.to have_http_status 200
    end

    it "renders correct template" do
      is_expected.to render_template(:partial => "layouts/_textual_groups_generic")
    end

    it "displays tags" do
      get :show, :params => {:id => playbook.id}
      expect(response.body).to include("Smart Management")
    end
  end

  describe "#show_list" do
    subject { get :show_list }
    render_views

    it "returns status 200" do
      is_expected.to have_http_status 200
    end

    it "renders correct template" do
      is_expected.to render_template(:partial => "layouts/_gtl")
    end

    it 'renders the correct toolbar' do
      expect(ApplicationHelper::Toolbar::AnsiblePlaybooksCenter).to receive(:definition).and_call_original
      post :show_list
    end
  end

  describe "#button" do
    before do
      controller.instance_variable_set(:@_params, params)
    end

    context 'tagging one or more playbooks' do
      let(:params) { {:pressed => "embedded_configuration_script_payload_tag"} }

      it 'calls tag method' do
        expect(controller).to receive(:tag).with(controller.class.model)
        controller.send(:button)
      end
    end
  end

  describe '#toolbar' do
    let(:action) { 'show' }
    subject { controller.send(:toolbar) }

    before do
      controller.instance_variable_set(:@lastaction, action)
    end

    context 'displaying list of playbooks' do
      let(:action) { 'show_list' }

      it 'returns proper toolbar filename' do
        expect(subject).to eq('ansible_playbooks_center')
      end
    end

    context 'displaying summary screen of a playbook' do
      it 'returns proper toolbar filename' do
        expect(subject).to eq('ansible_playbook_center')
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09010220548682087, 'fraction_numerical': 0.006455083378160301, 'mean_word_length': 3.188063063063063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '2763027', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1087, 'n_words': 298}