<commit_before>describe MiqPolicyController do
  before :each do
    stub_user(:features => :all)
  end
  context "::Policies" do
    context "#policy_edit" do
      render_views

      before :each do
        event = FactoryGirl.create(:miq_event_definition, :name => "host_compliance_check")
        action = FactoryGirl.create(:miq_action, :name => "compliance_failed")
        allow(controller).to receive(:policy_get_node_info)
        allow(controller).to receive(:get_node_info)
      end

      it "Correct active tree node is saved in @sb after Policy is added" do
        new = {}
        new[:mode] = "compliance"
        new[:towhat] = "Host"
        new[:description] = "Test_description"
        new[:expression] =  {">" => {"count" => "Host.advanced_settings", "value" => "1"}}
        controller.instance_variable_set(:@edit, {:new     => new,
                                                  :current => new,
                                                  :typ     => "basic",
                                                  :key     => "policy_edit__new"})
        session[:edit] = assigns(:edit)
        active_node = "xx-compliance_xx-compliance-host"
        allow(controller).to receive(:replace_right_cell)
        controller.instance_variable_set(:@sb, {:trees       => {:policy_tree => {:active_node => active_node}},
                                                :active_tree => :policy_tree})
        controller.instance_variable_set(:@_params, :button => "add")
        controller.policy_edit
        sb = assigns(:sb)
        expect(sb[:trees][sb[:active_tree]][:active_node]).to include("#{active_node}_p-")
        expect(assigns(:flash_array).first[:message]).to include("added")
      end

      it "Renders the control policy creation form correctly" do
        session[:sandboxes] = {"miq_policy" => {:trees       => {:policy_tree => {:active_node => "xx-compliance_xx-compliance-host"}},
                                                :active_tree => :policy_tree,
                                                :folder      => "compliance-host"}}
        session[:edit] = {:new => {:mode => "compliance", :towhat => "Host"}}
        post :x_button, :pressed => "policy_new", :typ => "basic"
        expect(response).to render_template("layouts/exp_atom/_editor")
        expect(response).to render_template("layouts/_exp_editor")
        expect(response).to render_template("miq_policy/_policy_details")
      end
    end
  end
end<commit_msg>Test: policy_edit relies on @sb[:nodeid]<commit_after>describe MiqPolicyController do
  before :each do
    stub_user(:features => :all)
  end
  context "::Policies" do
    context "#policy_edit" do
      render_views

      before :each do
        event = FactoryGirl.create(:miq_event_definition, :name => "host_compliance_check")
        action = FactoryGirl.create(:miq_action, :name => "compliance_failed")
        allow(controller).to receive(:policy_get_node_info)
        allow(controller).to receive(:get_node_info)
      end

      it "Correct active tree node is saved in @sb after Policy is added" do
        new = {}
        new[:mode] = "compliance"
        new[:towhat] = "Host"
        new[:description] = "Test_description"
        new[:expression] =  {">" => {"count" => "Host.advanced_settings", "value" => "1"}}
        controller.instance_variable_set(:@edit, {:new     => new,
                                                  :current => new,
                                                  :typ     => "basic",
                                                  :key     => "policy_edit__new"})
        session[:edit] = assigns(:edit)
        active_node = "xx-compliance_xx-compliance-host"
        allow(controller).to receive(:replace_right_cell)
        controller.instance_variable_set(:@sb, {:trees       => {:policy_tree => {:active_node => active_node}},
                                                :active_tree => :policy_tree})
        controller.instance_variable_set(:@_params, :button => "add")
        controller.policy_edit
        sb = assigns(:sb)
        expect(sb[:trees][sb[:active_tree]][:active_node]).to include("#{active_node}_p-")
        expect(assigns(:flash_array).first[:message]).to include("added")
      end

      it "Renders the control policy creation form correctly" do
        session[:sandboxes] = {"miq_policy" => {:trees       => {:policy_tree => {:active_node => "xx-compliance_xx-compliance-host"}},
                                                :active_tree => :policy_tree,
                                                :folder      => "compliance-host",
                                                :nodeid      => "host"}}
        session[:edit] = {:new => {:mode => "compliance", :towhat => "Host"}}
        post :x_button, :pressed => "policy_new", :typ => "basic"
        expect(response).to render_template("layouts/exp_atom/_editor")
        expect(response).to render_template("layouts/_exp_editor")
        expect(response).to render_template("miq_policy/_policy_details")
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13250639889742075, 'fraction_numerical': 0.00039377830281551486, 'mean_word_length': 2.103237629810629, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5625137', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1312, 'n_words': 269}