diff options
author | Gareth Rees <gareth@mysociety.org> | 2015-02-18 13:27:19 +0000 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2015-02-24 13:23:17 +0000 |
commit | ae648fc4ff414eb33ef17744d4434a0e4a43e606 (patch) | |
tree | 8753c498c676e84e57660c836cb0e7305006d032 | |
parent | f7974a3c5243279f9a739a7d84174af953b38434 (diff) |
Add User#banned?
- Redefined User#public_banned? to User#banned?
- Add specs for User#banned?
- Deprecate User#public_banned?
- Replace use of User#public_banned? with User#banned?
-rw-r--r-- | app/models/user.rb | 12 | ||||
-rw-r--r-- | app/views/user/show.html.erb | 2 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 18 |
3 files changed, 29 insertions, 3 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index c953e52f2..920c0da46 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -207,7 +207,7 @@ class User < ActiveRecord::Base if not name.nil? name.strip! end - if public_banned? + if banned? # Use interpolation to return a string rather than a SafeBuffer so that # gsub can be called on it until we upgrade to Rails 3.2. The name returned # is not marked as HTML safe so will be escaped automatically in views. We @@ -294,10 +294,18 @@ class User < ActiveRecord::Base def admin_page_links? super? end + # Is it public that they are banned? + def banned? + !ban_text.empty? + end + def public_banned? - !ban_text.empty? + warn %q([DEPRECATION] User#public_banned? will be replaced with + User#banned? as of 0.22).squish + banned? end + # Various ways the user can be banned, and text to describe it if failed def can_file_requests? ban_text.empty? && !exceeded_limit? diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb index 7c8d52568..78b513d6a 100644 --- a/app/views/user/show.html.erb +++ b/app/views/user/show.html.erb @@ -78,7 +78,7 @@ <% end %> </p> - <% if @display_user.public_banned? %> + <% if @display_user.banned? %> <div id="user_public_banned"> <p> <strong> diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 7dcd3ab8a..2245a024f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -369,3 +369,21 @@ describe User, "when calculating if a user has exceeded the request limit" do end + +describe User do + + describe :banned? do + + it 'is banned if the user has ban_text' do + user = FactoryGirl.build(:user, :ban_text => 'banned') + expect(user).to be_banned + end + + it 'is not banned if the user has no ban_text' do + user = FactoryGirl.build(:user, :ban_text => '') + expect(user).to_not be_banned + end + + end + +end |