Skip to content
Browse files

User can be edited without name: LIGHTHOUSE #260

  • Loading branch information...
1 parent 9f40590 commit e9d25b326a028cf44dab1c29d48664797bfcaebf Jeff Dettmann committed with Dec 29, 2009
Showing with 20 additions and 73 deletions.
  1. +8 −0 app/models/user.rb
  2. +1 −1 app/views/cms/users/index.html.erb
  3. +11 −72 test/unit/models/user_test.rb
View
8 app/models/user.rb
@@ -80,6 +80,14 @@ def full_name_with_login
"#{full_name} (#{login})"
end
+ def full_name_or_login
+ if full_name.strip.blank?
+ login
+ else
+ full_name
+ end
+ end
+
# This is to show a formated date on the input form. I'm unsure that
# this is the best way to solve this, but it works.
def expires_at_formatted
View
2 app/views/cms/users/index.html.erb
@@ -26,7 +26,7 @@
<% @users.each do |user|%>
<tr>
<td class="first"></td>
- <td><div class="dividers"><%= link_to "#{user.first_name} #{user.last_name}", edit_cms_user_path(user) %></div></td>
+ <td><div class="dividers"><%= link_to "#{user.full_name_or_login}", edit_cms_user_path(user) %></div></td>
<td><div class="dividers"><%= link_to user.email, "mailto:#{user.email}" %></div></td>
<td>
<div class="dividers">
View
83 test/unit/models/user_test.rb
@@ -66,52 +66,18 @@ def test_disable_enable
assert !@user.valid?
end
end
-end
-
-class UserAbleToViewTest < ActiveSupport::TestCase
-
- test "User able_to_view? with String path" do
- non_admin = GroupType.create!(:cms_access=>false)
- group = Factory(:group, :group_type=>non_admin)
- public_user = Factory(:user)
- public_user.groups<< group
- public_user.save!
-
- section = Factory(:section, :path=>"/members", :name=>"Members")
- section.groups << group
- section.save!
-
- assert public_user.able_to_view?("/members")
- end
-
- test "User can't view a nil section" do
- user = User.new
-
- Section.expects(:find_by_path).with("/members").returns(nil)
- user.expects(:able_to_view_without_paths?).never
-
- assert_raise ActiveRecord::RecordNotFound do
- user.able_to_view?("/members")
- end
-
- end
-
- test "Users with cmsaccess?" do
- @non_admin = GroupType.create!(:cms_access=>true)
- @group = Factory(:group, :group_type=>@non_admin)
- @public_user = Factory(:user)
- @public_user.groups<< @group
- @public_user.save!
-
- assert(@public_user.cms_access?, "")
- end
-
- test "cms_access? determines if a user is considered to have cmsadmin privledges or not." do
- user = User.new
- assert(!user.cms_access?, "")
+ test "full name or login" do
+ login = 'robbo'
+ fn = 'Bob'
+ ln = 'Smith'
+ u = User.new(:login => 'robbo')
+ assert_equal login, u.full_name_or_login
+ u.first_name = fn
+ assert_equal fn, u.full_name_or_login
+ u.last_name = ln
+ assert_equal fn + ' ' + ln, u.full_name_or_login
+
end
-
-
end
class UserPermissionsTest < ActiveSupport::TestCase
@@ -268,33 +234,6 @@ def test_guest
assert !@user.able_to?("do anything global")
assert @user.able_to_view?(@public_page)
assert !@user.able_to_view?(@protected_page)
- assert !@user.cms_access?
- end
-
- test "override viewable sections for the guest group" do
- @user.expects(:viewable_sections).returns([@protected_section])
- assert_equal Section, @protected_section.class
- assert(@protected_section.is_a?(Section), "")
- assert @user.able_to_view?(@protected_section)
- end
-
- test "GuestUser can't view a nil section" do
- user = GuestUser.new
-
- Section.expects(:find_by_path).with("/members").returns(nil)
-
- assert_raise ActiveRecord::RecordNotFound do
- user.able_to_view?("/members")
- end
-
end
- test "Guest User able_to_view? with String path" do
- section = Factory(:section, :path=>"/members", :name=>"Members")
- section.groups << @guest_group
- section.save!
-
- assert @user.able_to_view?("/members")
-
- end
end

0 comments on commit e9d25b3

Please sign in to comment.
Something went wrong with that request. Please try again.