<commit_before>require 'rails_helper'
require "rspec/mocks/standalone"

describe ActiveAdmin::FormBuilder do

  # Setup an ActionView::Base object which can be used for
  # generating the form for.
  let(:helpers) do
    view = action_view
    def view.posts_path
      "/posts"
    end

    def view.protect_against_forgery?
      false
    end

    def view.url_for(*args)
      if args.first == {action: "index"}
        posts_path
      else
        super
      end
    end

    def view.a_helper_method
      "A Helper Method"
    end

    view
  end

  def build_form(options = {}, form_object = Post.new, &block)
    options = {url: helpers.posts_path}.merge(options)

    form = render_arbre_component({form_object: form_object, form_options: options, form_block: block}, helpers) do
      active_admin_form_for(assigns[:form_object], assigns[:form_options], &assigns[:form_block])
    end.to_s

    Capybara.string(form)
  end

  context "in general" do
    context "it without custom settings" do
      let :body do
        build_form do |f|
          f.inputs do
            f.input :title
            f.input :body
          end
        end
      end

      it "should generate a fieldset with a inputs class" do
        expect(body).to have_tag("fieldset", attributes: { class: "inputs" })
      end
    end

    context "it with custom settings" do
      let :body do
        build_form do |f|
          f.inputs class: "custom_class" do
            f.input :title
            f.input :body
          end
        end
      end

      it "should generate a fieldset with a inputs and custom class" do
        expect(body).to have_tag("fieldset", attributes: { class: "inputs custom_class" })
      end
    end
  end

  context "in general with actions" do
    let :body do
      build_form do |f|
        f.inputs do
          f.input :title
          f.input :body
        end
        f.actions do<commit_msg>don't use have_selector in form builder spec<commit_after>require 'rails_helper'
require "rspec/mocks/standalone"

describe ActiveAdmin::FormBuilder do

  # Setup an ActionView::Base object which can be used for
  # generating the form for.
  let(:helpers) do
    view = action_view
    def view.posts_path
      "/posts"
    end

    def view.protect_against_forgery?
      false
    end

    def view.url_for(*args)
      if args.first == {action: "index"}
        posts_path
      else
        super
      end
    end

    def view.a_helper_method
      "A Helper Method"
    end

    view
  end

  def build_form(options = {}, form_object = Post.new, &block)
    options = {url: helpers.posts_path}.merge(options)

    form = render_arbre_component({form_object: form_object, form_options: options, form_block: block}, helpers) do
      active_admin_form_for(assigns[:form_object], assigns[:form_options], &assigns[:form_block])
    end.to_s

    Capybara.string(form)
  end

  context "in general" do
    context "it without custom settings" do
      let :body do
        build_form do |f|
          f.inputs do
            f.input :title
            f.input :body
          end
        end
      end

      it "should generate a fieldset with a inputs class" do
        expect(body).to have_selector("fieldset.inputs")
      end
    end

    context "it with custom settings" do
      let :body do
        build_form do |f|
          f.inputs class: "custom_class" do
            f.input :title
            f.input :body
          end
        end
      end

      it "should generate a fieldset with a inputs and custom class" do
        expect(body).to have_selector("fieldset.inputs.custom_class")
      end
    end
  end

  context "in general with actions" do
    let :body do
      build_form do |f|
        f.inputs do
          f.input :title
          f.input :body
        end
        f.actions do
{'fraction_non_alphanumeric': 0.078748370273794, 'fraction_numerical': 0.0, 'mean_word_length': 2.101050929668553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2738065', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1142, 'n_words': 360}