Skip to content

Commit

Permalink
Fix a bug where polymorphic fields could throw an exception (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrani authored and nickcharlton committed Apr 20, 2018
1 parent a921c2e commit acaad1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/administrate/field/polymorphic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def associated_dashboard(klass = data.class)
end

def classes
options.fetch(:classes) || []
options.fetch(:classes, [])
end

private
Expand Down
21 changes: 21 additions & 0 deletions spec/lib/fields/polymorphic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,25 @@ def display_resource(*)
expect(field.selected_global_id).to eq(nil)
end
end

describe "#classes" do
let(:field) { Administrate::Field::Polymorphic.new(:foo, "hello", :show) }

context "not present in options" do
it "returns an empty array" do
allow(field).to receive(:options).and_return({})

expect(field.send(:classes)).to eq([])
end
end

context "present in options" do
it "returns an present value" do
classes = ["one", "two", "three"]
allow(field).to receive(:options).and_return(classes: classes)

expect(field.send(:classes)).to eq(classes)
end
end
end
end

0 comments on commit acaad1e

Please sign in to comment.