Skip to content

Commit 944d2be

Browse files
committed
use instance_exec, should work as instance_eval and may fix in jruby
1 parent 7a56410 commit 944d2be

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/active_scaffold/finder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ def apply_conditions(relation, *conditions)
756756
def sort_collection_by_column(collection, column, order)
757757
sorter = column.sort[:method]
758758
collection = collection.sort_by do |record|
759-
value = sorter.is_a?(Proc) ? record.instance_eval(&sorter) : record.instance_eval(sorter.to_s)
759+
value = sorter.is_a?(Proc) ? record.instance_exec(record, &sorter) : record.instance_eval(sorter.to_s)
760760
value = '' if value.nil?
761761
value
762762
end

test/misc/finder_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_create_conditions_for_columns
3333

3434
def test_method_sorting
3535
column = ActiveScaffold::DataStructures::Column.new('a', ModelStub)
36-
column.sort_by method: proc { itself }
36+
column.sort_by method: proc { |r| self }
3737

3838
collection = [16_000, 2853, 98_765, 6188, 4]
3939
assert_equal collection.sort, @klass.send(:sort_collection_by_column, collection, column, 'asc')
@@ -43,7 +43,7 @@ def test_method_sorting
4343
result = @klass.send(:sort_collection_by_column, collection, column, 'asc')
4444
assert_equal [nil, 'a', 'b'], result
4545

46-
column.sort_by method: 'itself'
46+
column.sort_by method: 'self'
4747
collection = [3, 1, 2]
4848
assert_equal collection.sort, @klass.send(:sort_collection_by_column, collection, column, 'asc')
4949
end

0 commit comments

Comments
 (0)