diff options
author | Matt Jankowski <mjankowski@thoughtbot.com> | 2017-05-22 15:50:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-22 15:50:58 -0400 |
commit | e1b42e9aa01b0c6adab05afb9c5ee0cf9fbb41a9 (patch) | |
tree | 82d1b2b4c6fa8a57829b5f9885251d3ae14766b6 /app/models/account_filter.rb | |
parent | b51398d0ddf4c4b366e104c67366f6a80b69d61b (diff) |
Add coverage for ReportFilter and AccountFilter (#3236)
Diffstat (limited to 'app/models/account_filter.rb')
-rw-r--r-- | app/models/account_filter.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb index 186b38cd7..1a8cc5192 100644 --- a/app/models/account_filter.rb +++ b/app/models/account_filter.rb @@ -18,8 +18,6 @@ class AccountFilter private def scope_for(key, value) - accounts = Account.arel_table - case key.to_s when 'local' Account.local @@ -34,21 +32,26 @@ class AccountFilter when 'suspended' Account.suspended when 'username' - Account.where(accounts[:username].matches("#{value}%")) + Account.matches_username(value) when 'display_name' - Account.where(accounts[:display_name].matches("#{value}%")) + Account.matches_display_name(value) when 'email' - users = User.arel_table - Account.joins(:user).merge(User.where(users[:email].matches("#{value}%"))) + accounts_with_users.merge User.matches_email(value) when 'ip' - return Account.default_scoped unless valid_ip?(value) - matches_ip = User.where(current_sign_in_ip: value).or(User.where(last_sign_in_ip: value)) - Account.joins(:user).merge(matches_ip) + if valid_ip?(value) + accounts_with_users.merge User.with_recent_ip_address(value) + else + Account.default_scoped + end else raise "Unknown filter: #{key}" end end + def accounts_with_users + Account.joins(:user) + end + def valid_ip?(value) IPAddr.new(value) true |