Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/modern_searchlogic/column_conditions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def respond_to_missing?(method, *)
end

def valid_searchlogic_scope?(method)
return false if method =~ /^define_method_/
return false if connection.tables.empty? || method =~ /^define_method_/ || abstract_class?

searchlogic_scope_dynamically_defined?(method) ||
!!searchlogic_column_condition_method_block(method.to_s) ||
Expand Down Expand Up @@ -191,6 +191,7 @@ def column_names_regexp
end

def method_missing(method, *args, &block)
return super if connection.tables.empty? || abstract_class?
return super unless dynamically_define_searchlogic_method(method)

__send__(method, *args, &block)
Expand Down
24 changes: 24 additions & 0 deletions spec/lib/modern_searchlogic/column_conditions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,28 @@
User.not_active.all.should == [inactive]
end
end

context 'abstract class' do
it 'should not try to add searchlogic methods' do
class MyApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

MyApplicationRecord.should_not respond_to :id_eq
end

context 'extended by a non-abstract class' do
it 'should add searchlogic methods' do
class MyApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

class ScopedUser < MyApplicationRecord
self.table_name = 'users'
end

ScopedUser.should respond_to :id_eq
end
end
end
end