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_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/view_helpers/fields_for_spec.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.17.pre spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.16.pre spec/unit/view_helpers/fields_for_spec.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/view_helpers/fields_for_spec.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/view_helpers/fields_for_spec.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.15.pre spec/unit/view_helpers/fields_for_spec.rb
activeadmin-orac-1.0.0.pre4 spec/unit/view_helpers/fields_for_spec.rb
activeadmin-orac-1.0.0 spec/unit/view_helpers/fields_for_spec.rb
activeadmin-orac-1.0.0.pre.orac spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.14.pre spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.13.pre spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.12.pre spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.11.pre spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.10.pre spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.9.pre spec/unit/view_helpers/fields_for_spec.rb
yousty-activeadmin-1.0.8.pre spec/unit/view_helpers/fields_for_spec.rb
activeadmin-1.0.0.pre4 spec/unit/view_helpers/fields_for_spec.rb
activeadmin-1.0.0.pre3 spec/unit/view_helpers/fields_for_spec.rb