Sha256: 68f1043c5f39c05d6107fe57b5d5445371acfaaa1198e73f3996cf3c4de1e5fb

Contents?: true

Size: 1.6 KB

Versions: 25

Compression:

Stored size: 1.6 KB

Contents

require 'active_admin/view_helpers/fields_for'

describe ActiveAdmin::ViewHelpers::FormHelper, ".fields_for" do
  include ActiveAdmin::ViewHelpers::FormHelper

  it "should skip :action, :controller and :commit" do
    expect(fields_for_params(
      scope: "All", action: "index", controller: "PostController", commit: "Filter", utf8: "Yes!")).
      to eq [ { scope: "All" } ]
  end

  it "should skip the except" do
    expect(fields_for_params({scope: "All", name: "Greg"}, except: :name)).
      to eq [ { scope: "All" } ]
  end

  it "should allow an array for the except" do
    expect(fields_for_params({scope: "All", name: "Greg", age: "12"}, except: [:name, :age])).
      to eq [ { scope: "All" } ]
  end

  it "should work with hashes" do
    params = fields_for_params(filters: { name: "John", age: "12" })

    expect(params.size).to eq 2
    expect(params).to include({"filters[name]" => "John" })
    expect(params).to include({ "filters[age]" => "12" })
  end

  it "should work with nested hashes" do
    expect(fields_for_params(filters: { user: { name: "John" }})).
      to eq [ { "filters[user][name]" => "John" } ]
  end

  it "should work with arrays" do
    expect(fields_for_params(people: ["greg", "emily", "philippe"])).
      to eq [ { "people[]" => "greg" },
                  { "people[]" => "emily" },
                  { "people[]" => "philippe" } ]
  end

  it "should work with symbols" do
    expect(fields_for_params(filter: :id)).
      to eq [ { filter: "id" } ]
  end

  it "should work with booleans" do
    expect(fields_for_params(booleantest: false)).to eq [ { booleantest: false } ]
  end
end

Version data entries

25 entries across 25 versions & 4 rubygems

Version Path
activeadmin-1.0.0.pre2 spec/unit/view_helpers/fields_for_spec.rb
activeadmin-1.0.0.pre1 spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.7.pre spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.6.pre spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.5.pre spec/unit/view_helpers/fields_for_spec.rb