require_sudo_mode :create, :update, :destroy
def index
- scope = @project.memberships.active
+ scope = @project.memberships
@offset, @limit = api_offset_and_limit
@member_count = scope.count
@member_pages = Paginator.new @member_count, @limit, params['page']
<% roles = Role.find_all_givable
- members = @project.memberships.active.includes(:member_roles, :roles, :principal).to_a.sort %>
+ members = @project.memberships.includes(:member_roles, :roles, :principal).to_a.sort %>
<p><%= link_to l(:label_member_new), new_project_membership_path(@project), :remote => true, :class => "icon icon-add" %></p>
assert_redirected_to '/projects/ecookbook/settings/members'
end
+ def test_update_locked_member_should_be_allowed
+ User.find(3).lock!
+
+ put :update, :id => 2, :membership => {:role_ids => [1]}
+ assert_response 302
+ member = Member.find(2)
+ assert member.user.locked?
+ assert_equal [1], member.role_ids
+ end
+
def test_update_should_not_add_unmanaged_roles
role = Role.find(1)
role.update! :all_roles_managed => false
assert !User.find(3).member_of?(Project.find(1))
end
+ def test_destroy_locked_member_should_be_allowed
+ assert User.find(3).lock!
+
+ assert_difference 'Member.count', -1 do
+ delete :destroy, :id => 2
+ end
+ end
+
def test_destroy_should_fail_with_unmanaged_roles
role = Role.find(1)
role.update! :all_roles_managed => false
end
end
+ def test_settings_should_show_locked_members
+ user = User.generate!
+ member = User.add_to_project(user, Project.find(1))
+ user.lock!
+ assert user.reload.locked?
+ @request.session[:user_id] = 2
+
+ get :settings, :id => 'ecookbook', :tab => 'members'
+ assert_response :success
+ assert_select "tr#member-#{member.id}"
+ end
+
def test_update
@request.session[:user_id] = 2 # manager
post :update, :id => 1, :project => {:name => 'Test changed name',
assert_response :success
assert_equal 'application/json', @response.content_type
json = ActiveSupport::JSON.decode(response.body)
- assert_equal({
- "memberships" =>
- [{"id"=>1,
- "project" => {"name"=>"eCookbook", "id"=>1},
- "roles" => [{"name"=>"Manager", "id"=>1}],
- "user" => {"name"=>"John Smith", "id"=>2}},
- {"id"=>2,
- "project" => {"name"=>"eCookbook", "id"=>1},
- "roles" => [{"name"=>"Developer", "id"=>2}],
- "user" => {"name"=>"Dave Lopper", "id"=>3}}],
- "limit" => 25,
- "total_count" => 2,
- "offset" => 0},
- json)
+ assert_equal 3, json["total_count"]
+ assert_equal 25, json["limit"]
+ assert_equal 0, json["offset"]
+ assert_include({
+ "id"=>1,
+ "project" => {"name"=>"eCookbook", "id"=>1},
+ "roles" => [{"name"=>"Manager", "id"=>1}],
+ "user" => {"name"=>"John Smith", "id"=>2}
+ },
+ json["memberships"]
+ )
end
test "GET /projects/:project_id/memberships.xml should succeed for closed project" do
assert_response :success
end
+ test "GET /projects/:project_id/memberships.xml should include locked users" do
+ assert User.find(3).lock!
+ get '/projects/ecookbook/memberships.xml', {}, credentials('jsmith')
+ assert_response :success
+ assert_select 'memberships[type=array] membership id', :text => '2' do
+ assert_select '~ user[id="3"][name="Dave Lopper"]'
+ end
+ end
+
test "POST /projects/:project_id/memberships.xml should create the membership" do
assert_difference 'Member.count' do
post '/projects/1/memberships.xml', {:membership => {:user_id => 7, :role_ids => [2,3]}}, credentials('jsmith')