comparison test/unit/role_test.rb @ 1526:404aa68d4227

Merge from live branch
author Chris Cannam
date Thu, 11 Sep 2014 12:46:20 +0100
parents e248c7af89ec
children
comparison
equal deleted inserted replaced
1493:a5f2bdf3b486 1526:404aa68d4227
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
89 89
90 def test_find_all_givable 90 def test_find_all_givable
91 assert_equal Role.all.reject(&:builtin?).sort, Role.find_all_givable 91 assert_equal Role.all.reject(&:builtin?).sort, Role.find_all_givable
92 end 92 end
93 93
94 context "#anonymous" do 94 def test_anonymous_should_return_the_anonymous_role
95 should "return the anonymous role" do 95 assert_no_difference('Role.count') do
96 role = Role.anonymous 96 role = Role.anonymous
97 assert role.builtin? 97 assert role.builtin?
98 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin 98 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
99 end 99 end
100 end
100 101
101 context "with a missing anonymous role" do 102 def test_anonymous_with_a_missing_anonymous_role_should_return_the_anonymous_role
102 setup do 103 Role.where(:builtin => Role::BUILTIN_ANONYMOUS).delete_all
103 Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}")
104 end
105 104
106 should "create a new anonymous role" do 105 assert_difference('Role.count') do
107 assert_difference('Role.count') do 106 role = Role.anonymous
108 Role.anonymous 107 assert role.builtin?
109 end 108 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
110 end
111
112 should "return the anonymous role" do
113 role = Role.anonymous
114 assert role.builtin?
115 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
116 end
117 end 109 end
118 end 110 end
119 111
120 context "#non_member" do 112 def test_non_member_should_return_the_non_member_role
121 should "return the non-member role" do 113 assert_no_difference('Role.count') do
122 role = Role.non_member 114 role = Role.non_member
123 assert role.builtin? 115 assert role.builtin?
124 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin 116 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
125 end 117 end
118 end
126 119
127 context "with a missing non-member role" do 120 def test_non_member_with_a_missing_non_member_role_should_return_the_non_member_role
128 setup do 121 Role.where(:builtin => Role::BUILTIN_NON_MEMBER).delete_all
129 Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}")
130 end
131 122
132 should "create a new non-member role" do 123 assert_difference('Role.count') do
133 assert_difference('Role.count') do 124 role = Role.non_member
134 Role.non_member 125 assert role.builtin?
135 end 126 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
136 end
137
138 should "return the non-member role" do
139 role = Role.non_member
140 assert role.builtin?
141 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
142 end
143 end 127 end
144 end 128 end
145 end 129 end