Skip to content

Commit 5929cc0

Browse files
authored
Merge pull request #310 from Quimbee/add-custom-method-model-option
Allow 'method_model' to be provided as an option to `filter`
2 parents 06dad84 + d1591c7 commit 5929cc0

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/activeadmin_addons/support/input_helpers/input_methods.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def association_name
2323
end
2424

2525
def method_model
26-
object_class.reflect_on_association(association_name).try(:klass) ||
26+
@options[:method_model] ||
27+
object_class.reflect_on_association(association_name).try(:klass) ||
2728
association_name.classify.constantize
2829
end
2930

spec/lib/support/input_methods_spec.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
Class.new do
66
include ActiveAdminAddons::InputMethods
77

8-
attr_reader :method
8+
attr_reader :method, :options
99

10-
def initialize(object, method)
10+
def initialize(object, method, options = {})
1111
@object = object
1212
@method = method
13+
@options = options
1314
end
1415
end
1516
end
@@ -21,7 +22,8 @@ def initialize(object, method)
2122
end
2223

2324
let(:method) { :category_id }
24-
let(:instance) { dummy_class.new(object, method) }
25+
let(:options) { {} }
26+
let(:instance) { dummy_class.new(object, method, options) }
2527

2628
def self.check_invalid_method(method_name)
2729
context "with nil method" do
@@ -68,6 +70,14 @@ def self.check_invalid_object(method_name)
6870
expect(instance.method_model).to be(Store::Manufacturer)
6971
end
7072
end
73+
74+
context "when a :method_model option is provided" do
75+
let(:options) { { method_model: Store::Car } }
76+
77+
it "returns provided class" do
78+
expect(instance.method_model).to be(Store::Car)
79+
end
80+
end
7181
end
7282

7383
describe "#tableize_method" do

0 commit comments

Comments
 (0)