Adds functional tests for MembersController.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7990 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-11-29 20:29:50 +00:00
parent b0fe7415d1
commit 1e7c4488b9
1 changed files with 30 additions and 29 deletions

View File

@ -49,38 +49,22 @@ class MembersControllerTest < ActionController::TestCase
assert User.find(7).member_of?(Project.find(1)) assert User.find(7).member_of?(Project.find(1))
end end
context "post :new in JS format" do def test_xhr_create
context "with successful saves" do assert_difference 'Member.count', 3 do
should "add membership for each user" do post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
assert User.find(7).member_of?(Project.find(1))
assert User.find(8).member_of?(Project.find(1))
assert User.find(9).member_of?(Project.find(1))
end
should "replace the tab with RJS" do
post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
assert_select_rjs :replace_html, 'tab-content-members'
end
end end
assert_select_rjs :replace_html, 'tab-content-members'
assert User.find(7).member_of?(Project.find(1))
assert User.find(8).member_of?(Project.find(1))
assert User.find(9).member_of?(Project.find(1))
end
context "with a failed save" do def test_xhr_create_with_failure
should "not replace the tab with RJS" do assert_no_difference 'Member.count' do
post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]} post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]}
assert_select '#tab-content-members', 0
end
should "open an error message" do
post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]}
assert @response.body.match(/alert/i), "Alert message not sent"
end
end end
assert_select '#tab-content-members', 0
assert @response.body.match(/alert/i), "Alert message not sent"
end end
def test_edit def test_edit
@ -90,6 +74,16 @@ class MembersControllerTest < ActionController::TestCase
assert_redirected_to '/projects/ecookbook/settings/members' assert_redirected_to '/projects/ecookbook/settings/members'
end end
def test_xhr_edit
assert_no_difference 'Member.count' do
xhr :post, :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3}
end
assert_select_rjs :replace_html, 'tab-content-members'
member = Member.find(2)
assert_equal [1], member.role_ids
assert_equal 3, member.user_id
end
def test_destroy def test_destroy
assert_difference 'Member.count', -1 do assert_difference 'Member.count', -1 do
post :destroy, :id => 2 post :destroy, :id => 2
@ -98,6 +92,13 @@ class MembersControllerTest < ActionController::TestCase
assert !User.find(3).member_of?(Project.find(1)) assert !User.find(3).member_of?(Project.find(1))
end end
def test_xhr_destroy
assert_difference 'Member.count', -1 do
xhr :post, :destroy, :id => 2
end
assert_select_rjs :replace_html, 'tab-content-members'
end
def test_autocomplete_for_member def test_autocomplete_for_member
get :autocomplete_for_member, :id => 1, :q => 'mis' get :autocomplete_for_member, :id => 1, :q => 'mis'
assert_response :success assert_response :success