Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add admin? method to user

  • Loading branch information...
commit c0f0cc299781e3327f9f4086596b9d3e8ea564f0 1 parent 2dbe0eb
@pbm authored
View
6 app/models/user.rb
@@ -12,7 +12,7 @@ class User < ActiveRecord::Base
# :private should be number one, so we can set default.
ROLES = [:private, :admin, :editor].freeze
# attr_accessible :avatar
-
+
belongs_to :membership
validates_presence_of :membership
@@ -53,6 +53,10 @@ def is?(role)
roles.include?(role.to_sym)
end
+ def admin?
+ roles.include?(:admin)
+ end
+
def recent_flights(days_ago=30)
BilledFlight.last_n_days(days_ago).pilot(self)
end
View
2  app/views/layouts/application.html.erb
@@ -20,7 +20,7 @@
<li><%= link_to 'Events', events_path %></li>
<% if current_user %>
<li><%= link_to 'Members', users_path %></li>
- <% if current_user && current_user.is?(:admin) %>
+ <% if current_user && current_user.admin? %>
<li><%= link_to 'Admin', admin_path %></li>
<% end %>
<% end %>
View
3  test/unit/user_test.rb
@@ -12,7 +12,8 @@ class UserTest < ActiveSupport::TestCase
test "default values" do
u = User.new
- assert_equal false, u.is?(:admin), "default admin"
+ assert_equal false, u.is?(:admin), "default admin A"
+ assert_equal false, u.admin?, "default admin B"
assert_equal false, u.is?(:editor), "default editor"
end
Please sign in to comment.
Something went wrong with that request. Please try again.