From 690db9693fcee3beedc467b48fd9e4bd42ee936d Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 23 Jan 2013 23:39:47 +0400 Subject: [PATCH] fix tests --- .../admin/teams/members_controller.rb | 7 ++--- app/controllers/teams/members_controller.rb | 11 +++---- app/views/admin/teams/show.html.haml | 6 ++-- app/views/teams/projects/index.html.haml | 2 +- features/admin/teams.feature | 3 -- features/steps/admin/admin_teams.rb | 18 ++++++----- features/steps/userteams/userteams.rb | 30 +++++++++++-------- features/support/env.rb | 2 +- features/teams/team.feature | 1 + spec/routing/admin_routing_spec.rb | 14 ++++----- 10 files changed, 47 insertions(+), 47 deletions(-) diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb index cdcc96c0aef..7fd777dc72f 100644 --- a/app/controllers/admin/teams/members_controller.rb +++ b/app/controllers/admin/teams/members_controller.rb @@ -30,11 +30,8 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController end def destroy - if user_team.remove_member(team_member) - redirect_to admin_team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." - else - redirect_to admin_team_members(user_team), notice: "Something is wrong." - end + user_team.remove_member(team_member) + redirect_to admin_team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." end protected diff --git a/app/controllers/teams/members_controller.rb b/app/controllers/teams/members_controller.rb index 95b8de1861b..56e952a3d40 100644 --- a/app/controllers/teams/members_controller.rb +++ b/app/controllers/teams/members_controller.rb @@ -20,7 +20,7 @@ class Teams::MembersController < Teams::ApplicationController user_team.add_members(user_ids, access, is_admin) end - redirect_to team_path(user_team), notice: 'Members was successfully added into Team of users.' + redirect_to team_members_path(user_team), notice: 'Members was successfully added into Team of users.' end def edit @@ -30,18 +30,15 @@ class Teams::MembersController < Teams::ApplicationController def update options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]} if user_team.update_membership(team_member, options) - redirect_to team_path(user_team), notice: "Membership for #{team_member.name} was successfully updated in Team of users." + redirect_to team_members_path(user_team), notice: "Membership for #{team_member.name} was successfully updated in Team of users." else render :edit end end def destroy - if user_team.remove_member(team_member) - redirect_to team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." - else - redirect_to team_members(user_team), notice: "Something is wrong." - end + user_team.remove_member(team_member) + redirect_to team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." end protected diff --git a/app/views/admin/teams/show.html.haml b/app/views/admin/teams/show.html.haml index a7470c2d6e0..6a1deaff989 100644 --- a/app/views/admin/teams/show.html.haml +++ b/app/views/admin/teams/show.html.haml @@ -52,7 +52,7 @@ %th Team access %th.cred.span3 Danger Zone! - @team.members.each do |member| - %tr.member + %tr.member{ class: "user_#{member.id}"} %td = link_to [:admin, member] do = member.name @@ -62,7 +62,7 @@ %td.bgred = link_to 'Edit', edit_admin_team_member_path(@team, member), class: "btn small"   - = link_to 'Remove', admin_team_member_path(@team, member), confirm: 'Remove member from team. Are you sure?', method: :delete, class: "btn danger small" + = link_to 'Remove', admin_team_member_path(@team, member), confirm: 'Remove member from team. Are you sure?', method: :delete, class: "btn danger small", id: "remove_member_#{member.id}" %fieldset %legend @@ -84,7 +84,7 @@ %td.bgred = link_to 'Edit', edit_admin_team_project_path(@team, project), class: "btn small"   - = link_to 'Relegate', admin_team_project_path(@team, project), confirm: 'Remove project from team. Are you sure?', method: :delete, class: "btn danger small" + = link_to 'Relegate', admin_team_project_path(@team, project), confirm: 'Remove project from team. Are you sure?', method: :delete, class: "btn danger small", id: "relegate_project_#{project.id}" :javascript $(function(){ diff --git a/app/views/teams/projects/index.html.haml b/app/views/teams/projects/index.html.haml index b0a50e594cf..af6ffe5f3a4 100644 --- a/app/views/teams/projects/index.html.haml +++ b/app/views/teams/projects/index.html.haml @@ -13,7 +13,7 @@ %hr -%table +%table.projects-table %thead %tr %th Project name diff --git a/features/admin/teams.feature b/features/admin/teams.feature index 6ca7c4cbe02..b38a71e07b3 100644 --- a/features/admin/teams.feature +++ b/features/admin/teams.feature @@ -1,9 +1,6 @@ Feature: Admin Teams Background: Given I sign in as an admin - #And there are projects in system - #And system has users - #And I have own project And Create gitlab user "John" Scenario: Create a team diff --git a/features/steps/admin/admin_teams.rb b/features/steps/admin/admin_teams.rb index a1221cd1a8c..5c66b24bccf 100644 --- a/features/steps/admin/admin_teams.rb +++ b/features/steps/admin/admin_teams.rb @@ -83,8 +83,7 @@ class AdminTeams < Spinach::FeatureSteps end Then 'I should see empty projects table' do - projects_list = find("#projects_list") - projects_list.has_content?("Relegate").must_equal false + page.has_no_css?("#projects_list").must_equal true end When 'I select project "Shop" with max access "Reporter"' do @@ -177,11 +176,13 @@ class AdminTeams < Spinach::FeatureSteps end And 'I should see "Shop" in projects list' do - + project = Project.find_by_name("Shop") + find_in_list("#projects_list .project", project).must_equal true end When 'I click on remove "Jimm" user link' do - + user = User.find_by_name("Jimm") + click_link "remove_member_#{user.id}" end Then 'I should be redirected to "HardCoders" team admin page' do @@ -189,15 +190,18 @@ class AdminTeams < Spinach::FeatureSteps end And 'I should not to see "Jimm" user in members list' do - + user = User.find_by_name("Jimm") + find_in_list("#members_list .member", user).must_equal false end When 'I click on "Relegate" link on "Shop" project' do - + project = Project.find_by_name("Shop") + click_link "relegate_project_#{project.id}" end Then 'I should see projects liston team page without "Shop" project' do - + project = Project.find_by_name("Shop") + find_in_list("#projects_list .project", project).must_equal false end Then 'I should see "John" user with role "Reporter" in team table' do diff --git a/features/steps/userteams/userteams.rb b/features/steps/userteams/userteams.rb index 59ec3d2de6e..39a2588ec92 100644 --- a/features/steps/userteams/userteams.rb +++ b/features/steps/userteams/userteams.rb @@ -175,7 +175,12 @@ class Userteams < Spinach::FeatureSteps end And 'I select user "John" from list with role "Reporter"' do - pending 'step not implemented' + user = User.find_by_name("John") + within "#team_members" do + select user.name, :from => "user_ids" + select "Reporter", :from => "default_project_access" + end + click_button "Add" end Then 'I should see user "John" in team list' do @@ -185,7 +190,7 @@ class Userteams < Spinach::FeatureSteps end And 'I have my own project without teams' do - project = create :project, creator: current_user + @project = create :project, creator: current_user end And 'I visit my team page' do @@ -197,27 +202,26 @@ class Userteams < Spinach::FeatureSteps click_link "Projects" end + And 'I click link "Assign project to Team"' do + click_link "Assign project to Team" + end + Then 'I should see form with my own project in avaliable projects list' do - project = current_user.projects.first projects_select = find("#project_ids") - projects_select.should have_content(project.name) + projects_select.should have_content(@project.name) end When 'I submit form with selected project and max access' do - project = current_user.projects.first - within "#team_projects" do - select project.name, :from => "project_ids" + within "#assign_projects" do + select @project.name, :from => "project_ids" select "Reporter", :from => "greatest_project_access" end click_button "Add" end Then 'I should see my own project in team projects list' do - project = current_user.projects.first - projects = all("table .project") - projects.each do |project_row| - project_row.should have_content(project.name) - end + projects = find(".projects-table") + projects.should have_content(@project.name) end When 'I click link "New Team Member"' do @@ -227,7 +231,7 @@ class Userteams < Spinach::FeatureSteps protected def current_team - @user_team ||= Team.first + @user_team ||= UserTeam.first end def project diff --git a/features/support/env.rb b/features/support/env.rb index be10ad1b8b9..5651c4a09ba 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -21,7 +21,7 @@ Dir["#{Rails.root}/features/steps/shared/*.rb"].each {|file| require file} include GitoliteStub WebMock.allow_net_connect! - +Spinach.config.save_and_open_page_on_failure = true # # JS driver # diff --git a/features/teams/team.feature b/features/teams/team.feature index d914313efb6..b62d230fd56 100644 --- a/features/teams/team.feature +++ b/features/teams/team.feature @@ -70,6 +70,7 @@ Feature: UserTeams And I have my own project without teams And I visit my team page When I click on link "Projects" + And I click link "Assign project to Team" Then I should see form with my own project in avaliable projects list When I submit form with selected project and max access Then I should see my own project in team projects list diff --git a/spec/routing/admin_routing_spec.rb b/spec/routing/admin_routing_spec.rb index fb26bf98d0f..3e0e4bb3883 100644 --- a/spec/routing/admin_routing_spec.rb +++ b/spec/routing/admin_routing_spec.rb @@ -95,20 +95,20 @@ describe Admin::ProjectsController, "routing" do end end -# edit_admin_team_member GET /admin/team_members/:id/edit(.:format) admin/team_members#edit -# admin_team_member PUT /admin/team_members/:id(.:format) admin/team_members#update -# DELETE /admin/team_members/:id(.:format) admin/team_members#destroy -describe Admin::TeamMembersController, "routing" do +# edit_admin_project_member GET /admin/projects/:project_id/members/:id/edit(.:format) admin/projects/members#edit {:id=>/[^\/]+/, :project_id=>/[^\/]+/} +# admin_project_member PUT /admin/projects/:project_id/members/:id(.:format) admin/projects/members#update {:id=>/[^\/]+/, :project_id=>/[^\/]+/} +# DELETE /admin/projects/:project_id/members/:id(.:format) admin/projects/members#destroy {:id=>/[^\/]+/, :project_id=>/[^\/]+/} +describe Admin::Projects::MembersController, "routing" do it "to #edit" do - get("/admin/team_members/1/edit").should route_to('admin/team_members#edit', id: '1') + get("/admin/projects/test/members/1/edit").should route_to('admin/projects/members#edit', project_id: 'test', id: '1') end it "to #update" do - put("/admin/team_members/1").should route_to('admin/team_members#update', id: '1') + put("/admin/projects/test/members/1").should route_to('admin/projects/members#update', project_id: 'test', id: '1') end it "to #destroy" do - delete("/admin/team_members/1").should route_to('admin/team_members#destroy', id: '1') + delete("/admin/projects/test/members/1").should route_to('admin/projects/members#destroy', project_id: 'test', id: '1') end end