Permalink
Browse files

Prevent `respond_to?` from failing on Rails console loading or when t…

…able doesn't exist
  • Loading branch information...
1 parent 7242447 commit dbc70bb968da53388caec136e4e5958225ef9ea4 @samleb committed Jan 16, 2013
Showing with 4 additions and 4 deletions.
  1. +3 −3 lib/sexy_scopes/active_record/dynamic_methods.rb
  2. +1 −1 spec/active_record_spec.rb
@@ -58,11 +58,11 @@ def self.#{name} # def self.username
end
def sexy_scopes_has_attribute?(attribute_name)
- if self != ::ActiveRecord::Base && !abstract_class? && table_exists?
+ if equal?(::ActiveRecord::Base) || abstract_class? || !table_exists?
+ false
+ else
column_names.include?(attribute_name.to_s)
end
- rescue ::ActiveRecord::StatementInvalid
- false
end
end
end
@@ -69,7 +69,7 @@ class ::TempUser < ActiveRecord::Base; end
end
it "should not raise error when table doesn't exist" do
- TempUser.should_receive(:column_names).any_number_of_times.and_raise ActiveRecord::StatementInvalid
+ TempUser.table_name = "inexistent_users"
lambda { TempUser.respond_to?(:username) }.should_not raise_error
end
end

0 comments on commit dbc70bb

Please sign in to comment.