Finish select2-ajax for users. Added Select2Helper for tests
This commit is contained in:
parent
10f14136f5
commit
ef05423f47
11 changed files with 256 additions and 222 deletions
|
@ -19,7 +19,7 @@ $ ->
|
|||
multiple: $('.ajax-users-select').hasClass('multiselect')
|
||||
minimumInputLength: 0
|
||||
ajax: # instead of writing the function to execute the request we use Select2's convenient helper
|
||||
url: "/api/v3/users.json"
|
||||
url: "/api/" + gon.api_version + "/users.json"
|
||||
dataType: "json"
|
||||
data: (term, page) ->
|
||||
search: term # search term
|
||||
|
@ -33,11 +33,11 @@ $ ->
|
|||
initSelection: (element, callback) ->
|
||||
id = $(element).val()
|
||||
if id isnt ""
|
||||
$.ajax("http://api.rottentomatoes.com/api/public/v1.0/users/" + id + ".json",
|
||||
$.ajax(
|
||||
"/api/" + gon.api_version + "/users/" + id + ".json",
|
||||
dataType: "json"
|
||||
data:
|
||||
apikey: "ju6z9mjyajq2djue3gbvv26t"
|
||||
|
||||
dataType: "jsonp"
|
||||
private_token: gon.api_token
|
||||
).done (data) ->
|
||||
callback data
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
@import "gitlab_bootstrap.scss";
|
||||
|
||||
@import "common.scss";
|
||||
@import "ref_select.scss";
|
||||
@import "selects.scss";
|
||||
|
||||
@import "sections/header.scss";
|
||||
@import "sections/nav.scss";
|
||||
|
|
|
@ -555,17 +555,3 @@ img.emoji {
|
|||
display: none;
|
||||
}
|
||||
|
||||
.ajax-users-select {
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
.user-result {
|
||||
.user-image {
|
||||
float: left;
|
||||
}
|
||||
.user-name {
|
||||
}
|
||||
.user-username {
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
.ajax-users-select {
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
.user-result {
|
||||
.user-image {
|
||||
float: left;
|
||||
}
|
||||
.user-name {
|
||||
}
|
||||
.user-username {
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
||||
.select2-no-results {
|
||||
padding: 7px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/** Branch/tag selector **/
|
||||
.project-refs-form {
|
||||
margin: 0;
|
|
@ -152,9 +152,8 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def add_gon_variables
|
||||
gon.default_issues_tracker = Project.issues_tracker.default_value
|
||||
if current_user
|
||||
gon.api_token = current_user.private_token
|
||||
gon.gravatar_url = request.ssl? ? Gitlab.config.gravatar.ssl_url : Gitlab.config.gravatar.plain_url
|
||||
end
|
||||
gon.api_version = Gitlab::API.version
|
||||
gon.api_token = current_user.private_token if current_user
|
||||
gon.gravatar_url = request.ssl? ? Gitlab.config.gravatar.ssl_url : Gitlab.config.gravatar.plain_url
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,6 +11,7 @@ Feature: Project Team management
|
|||
Then I should be able to see myself in team
|
||||
And I should see "Sam" in team list
|
||||
|
||||
@javascript
|
||||
Scenario: Add user to project
|
||||
Given I click link "New Team Member"
|
||||
And I select "Mike" as "Reporter"
|
||||
|
|
|
@ -2,6 +2,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps
|
|||
include SharedAuthentication
|
||||
include SharedProject
|
||||
include SharedPaths
|
||||
include Select2Helper
|
||||
|
||||
Then 'I should be able to see myself in team' do
|
||||
page.should have_content(@user.name)
|
||||
|
@ -20,8 +21,9 @@ class ProjectTeamManagement < Spinach::FeatureSteps
|
|||
|
||||
And 'I select "Mike" as "Reporter"' do
|
||||
user = User.find_by_name("Mike")
|
||||
|
||||
select2(user.id, from: "#user_ids", multiple: true)
|
||||
within "#new_team_member" do
|
||||
select "#{user.name} (#{user.username})", :from => "user_ids"
|
||||
select "Reporter", :from => "project_access"
|
||||
end
|
||||
click_button "Add users"
|
||||
|
|
|
@ -2,238 +2,239 @@ class Userteams < Spinach::FeatureSteps
|
|||
include SharedAuthentication
|
||||
include SharedPaths
|
||||
include SharedProject
|
||||
include Select2Helper
|
||||
|
||||
When 'I do not have teams with me' do
|
||||
UserTeam.with_member(current_user).destroy_all
|
||||
When 'I do not have teams with me' do
|
||||
UserTeam.with_member(current_user).destroy_all
|
||||
end
|
||||
|
||||
Then 'I should see dashboard page without teams info block' do
|
||||
page.has_no_css?(".teams-box").must_equal true
|
||||
end
|
||||
|
||||
When 'I have teams with my membership' do
|
||||
team = create :user_team, owner: current_user
|
||||
team.add_member(current_user, UserTeam.access_roles["Master"], true)
|
||||
end
|
||||
|
||||
Then 'I should see dashboard page with teams information block' do
|
||||
page.should have_css(".teams-box")
|
||||
end
|
||||
|
||||
When 'exist user teams' do
|
||||
team = create :user_team
|
||||
team.add_member(current_user, UserTeam.access_roles["Master"], true)
|
||||
end
|
||||
|
||||
And 'I click on "All teams" link' do
|
||||
click_link("All Teams")
|
||||
end
|
||||
|
||||
Then 'I should see "All teams" page' do
|
||||
current_path.should == teams_path
|
||||
end
|
||||
|
||||
And 'I should see exist teams in teams list' do
|
||||
team = UserTeam.last
|
||||
find_in_list(".teams_list tr", team).must_equal true
|
||||
end
|
||||
|
||||
When 'I click to "New team" link' do
|
||||
click_link("New Team")
|
||||
end
|
||||
|
||||
And 'I submit form with new team info' do
|
||||
fill_in 'name', with: 'gitlab'
|
||||
|
||||
fill_in 'user_team_description', with: 'team description'
|
||||
click_button 'Create team'
|
||||
end
|
||||
|
||||
And 'I should see newly created team' do
|
||||
page.should have_content "gitlab"
|
||||
page.should have_content "team description"
|
||||
end
|
||||
|
||||
Then 'I should be redirected to new team page' do
|
||||
team = UserTeam.last
|
||||
current_path.should == team_path(team)
|
||||
end
|
||||
|
||||
When 'I have teams with projects and members' do
|
||||
team = create :user_team, owner: current_user
|
||||
@project = create :project
|
||||
team.add_member(current_user, UserTeam.access_roles["Master"], true)
|
||||
team.assign_to_project(@project, UserTeam.access_roles["Master"])
|
||||
@event = create(:closed_issue_event, project: @project)
|
||||
end
|
||||
|
||||
When 'I visit team page' do
|
||||
visit team_path(UserTeam.last)
|
||||
end
|
||||
|
||||
Then 'I should see projects list' do
|
||||
page.should have_css(".projects_box")
|
||||
projects_box = find(".projects_box")
|
||||
projects_box.should have_content(@project.name)
|
||||
end
|
||||
|
||||
And 'project from team has issues assigned to me' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
project.issues << create(:issue, assignee: current_user)
|
||||
end
|
||||
end
|
||||
|
||||
Then 'I should see dashboard page without teams info block' do
|
||||
page.has_no_css?(".teams-box").must_equal true
|
||||
end
|
||||
When 'I visit team issues page' do
|
||||
team = UserTeam.last
|
||||
visit issues_team_path(team)
|
||||
end
|
||||
|
||||
When 'I have teams with my membership' do
|
||||
team = create :user_team, owner: current_user
|
||||
team.add_member(current_user, UserTeam.access_roles["Master"], true)
|
||||
end
|
||||
|
||||
Then 'I should see dashboard page with teams information block' do
|
||||
page.should have_css(".teams-box")
|
||||
end
|
||||
|
||||
When 'exist user teams' do
|
||||
team = create :user_team
|
||||
team.add_member(current_user, UserTeam.access_roles["Master"], true)
|
||||
end
|
||||
|
||||
And 'I click on "All teams" link' do
|
||||
click_link("All Teams")
|
||||
end
|
||||
|
||||
Then 'I should see "All teams" page' do
|
||||
current_path.should == teams_path
|
||||
end
|
||||
|
||||
And 'I should see exist teams in teams list' do
|
||||
team = UserTeam.last
|
||||
find_in_list(".teams_list tr", team).must_equal true
|
||||
end
|
||||
|
||||
When 'I click to "New team" link' do
|
||||
click_link("New Team")
|
||||
end
|
||||
|
||||
And 'I submit form with new team info' do
|
||||
fill_in 'name', with: 'gitlab'
|
||||
|
||||
fill_in 'user_team_description', with: 'team description'
|
||||
click_button 'Create team'
|
||||
end
|
||||
|
||||
And 'I should see newly created team' do
|
||||
page.should have_content "gitlab"
|
||||
page.should have_content "team description"
|
||||
end
|
||||
|
||||
Then 'I should be redirected to new team page' do
|
||||
team = UserTeam.last
|
||||
current_path.should == team_path(team)
|
||||
end
|
||||
|
||||
When 'I have teams with projects and members' do
|
||||
team = create :user_team, owner: current_user
|
||||
@project = create :project
|
||||
team.add_member(current_user, UserTeam.access_roles["Master"], true)
|
||||
team.assign_to_project(@project, UserTeam.access_roles["Master"])
|
||||
@event = create(:closed_issue_event, project: @project)
|
||||
end
|
||||
|
||||
When 'I visit team page' do
|
||||
visit team_path(UserTeam.last)
|
||||
end
|
||||
|
||||
Then 'I should see projects list' do
|
||||
page.should have_css(".projects_box")
|
||||
projects_box = find(".projects_box")
|
||||
projects_box.should have_content(@project.name)
|
||||
end
|
||||
|
||||
And 'project from team has issues assigned to me' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
project.issues << create(:issue, assignee: current_user)
|
||||
Then 'I should see issues from this team assigned to me' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
project.issues.assigned(current_user).each do |issue|
|
||||
page.should have_content issue.title
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
When 'I visit team issues page' do
|
||||
team = UserTeam.last
|
||||
visit issues_team_path(team)
|
||||
Given 'I have team with projects and members' do
|
||||
team = create :user_team, owner: current_user
|
||||
project = create :project
|
||||
user = create :user
|
||||
team.add_member(current_user, UserTeam.access_roles["Master"], true)
|
||||
team.add_member(user, UserTeam.access_roles["Developer"], false)
|
||||
team.assign_to_project(project, UserTeam.access_roles["Master"])
|
||||
end
|
||||
|
||||
Given 'project from team has issues assigned to teams members' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
project.issues << create(:issue, assignee: member)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Then 'I should see issues from this team assigned to me' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
project.issues.assigned(current_user).each do |issue|
|
||||
Then 'I should see issues from this team assigned to teams members' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
project.issues.assigned(member).each do |issue|
|
||||
page.should have_content issue.title
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Given 'I have team with projects and members' do
|
||||
team = create :user_team, owner: current_user
|
||||
project = create :project
|
||||
user = create :user
|
||||
team.add_member(current_user, UserTeam.access_roles["Master"], true)
|
||||
team.add_member(user, UserTeam.access_roles["Developer"], false)
|
||||
team.assign_to_project(project, UserTeam.access_roles["Master"])
|
||||
Given 'project from team has merge requests assigned to me' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
3.times { project.merge_requests << create(:merge_request, assignee: member) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Given 'project from team has issues assigned to teams members' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
project.issues << create(:issue, assignee: member)
|
||||
When 'I visit team merge requests page' do
|
||||
team = UserTeam.last
|
||||
visit merge_requests_team_path(team)
|
||||
end
|
||||
|
||||
Then 'I should see merge requests from this team assigned to me' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
project.issues.assigned(member).each do |merge_request|
|
||||
page.should have_content merge_request.title
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Then 'I should see issues from this team assigned to teams members' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
project.issues.assigned(member).each do |issue|
|
||||
page.should have_content issue.title
|
||||
end
|
||||
Given 'project from team has merge requests assigned to team members' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
3.times { project.merge_requests << create(:merge_request, assignee: member) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Then 'I should see merge requests from this team assigned to me' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
project.issues.assigned(member).each do |merge_request|
|
||||
page.should have_content merge_request.title
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Given 'project from team has merge requests assigned to me' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
3.times { project.merge_requests << create(:merge_request, assignee: member) }
|
||||
end
|
||||
end
|
||||
end
|
||||
Given 'I have new user "John"' do
|
||||
create :user, name: "John"
|
||||
end
|
||||
|
||||
When 'I visit team merge requests page' do
|
||||
team = UserTeam.last
|
||||
visit merge_requests_team_path(team)
|
||||
end
|
||||
When 'I visit team people page' do
|
||||
team = UserTeam.last
|
||||
visit team_members_path(team)
|
||||
end
|
||||
|
||||
Then 'I should see merge requests from this team assigned to me' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
project.issues.assigned(member).each do |merge_request|
|
||||
page.should have_content merge_request.title
|
||||
end
|
||||
end
|
||||
end
|
||||
And 'I select user "John" from list with role "Reporter"' do
|
||||
user = User.find_by_name("John")
|
||||
select2(user.id, from: "#user_ids", multiple: true)
|
||||
within "#team_members" do
|
||||
select "Reporter", from: "default_project_access"
|
||||
end
|
||||
click_button "Add"
|
||||
end
|
||||
|
||||
Given 'project from team has merge requests assigned to team members' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
3.times { project.merge_requests << create(:merge_request, assignee: member) }
|
||||
end
|
||||
end
|
||||
end
|
||||
Then 'I should see user "John" in team list' do
|
||||
user = User.find_by_name("John")
|
||||
team_members_list = find(".team-table")
|
||||
team_members_list.should have_content user.name
|
||||
end
|
||||
|
||||
Then 'I should see merge requests from this team assigned to me' do
|
||||
team = UserTeam.last
|
||||
team.projects.each do |project|
|
||||
team.members.each do |member|
|
||||
project.issues.assigned(member).each do |merge_request|
|
||||
page.should have_content merge_request.title
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
And 'I have my own project without teams' do
|
||||
@project = create :project, namespace: current_user.namespace
|
||||
end
|
||||
|
||||
Given 'I have new user "John"' do
|
||||
create :user, name: "John"
|
||||
end
|
||||
And 'I visit my team page' do
|
||||
team = UserTeam.where(owner_id: current_user.id).last
|
||||
visit team_path(team)
|
||||
end
|
||||
|
||||
When 'I visit team people page' do
|
||||
team = UserTeam.last
|
||||
visit team_members_path(team)
|
||||
end
|
||||
When 'I click on link "Projects"' do
|
||||
click_link "Projects"
|
||||
end
|
||||
|
||||
And 'I select user "John" from list with role "Reporter"' do
|
||||
user = User.find_by_name("John")
|
||||
within "#team_members" do
|
||||
select "#{user.name} (#{user.username})", from: "user_ids"
|
||||
select "Reporter", from: "default_project_access"
|
||||
end
|
||||
click_button "Add"
|
||||
end
|
||||
And 'I click link "Assign project to Team"' do
|
||||
click_link "Assign project to Team"
|
||||
end
|
||||
|
||||
Then 'I should see user "John" in team list' do
|
||||
user = User.find_by_name("John")
|
||||
team_members_list = find(".team-table")
|
||||
team_members_list.should have_content user.name
|
||||
end
|
||||
Then 'I should see form with my own project in avaliable projects list' do
|
||||
projects_select = find("#project_ids")
|
||||
projects_select.should have_content(@project.name)
|
||||
end
|
||||
|
||||
And 'I have my own project without teams' do
|
||||
@project = create :project, namespace: current_user.namespace
|
||||
When 'I submit form with selected project and max access' do
|
||||
within "#assign_projects" do
|
||||
select @project.name_with_namespace, from: "project_ids"
|
||||
select "Reporter", from: "greatest_project_access"
|
||||
end
|
||||
click_button "Add"
|
||||
end
|
||||
|
||||
And 'I visit my team page' do
|
||||
team = UserTeam.where(owner_id: current_user.id).last
|
||||
visit team_path(team)
|
||||
end
|
||||
Then 'I should see my own project in team projects list' do
|
||||
projects = find(".projects-table")
|
||||
projects.should have_content(@project.name)
|
||||
end
|
||||
|
||||
When 'I click on link "Projects"' do
|
||||
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
|
||||
projects_select = find("#project_ids")
|
||||
projects_select.should have_content(@project.name)
|
||||
end
|
||||
|
||||
When 'I submit form with selected project and max access' do
|
||||
within "#assign_projects" do
|
||||
select @project.name_with_namespace, 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
|
||||
projects = find(".projects-table")
|
||||
projects.should have_content(@project.name)
|
||||
end
|
||||
|
||||
When 'I click link "New Team Member"' do
|
||||
click_link "New Team Member"
|
||||
end
|
||||
When 'I click link "New Team Member"' do
|
||||
click_link "New Team Member"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
@ -257,5 +258,4 @@ class Userteams < Spinach::FeatureSteps
|
|||
end
|
||||
entered
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ require 'spinach/capybara'
|
|||
require 'sidekiq/testing/inline'
|
||||
|
||||
|
||||
%w(stubbed_repository valid_commit).each do |f|
|
||||
%w(stubbed_repository valid_commit select2_helper).each do |f|
|
||||
require Rails.root.join('spec', 'support', f)
|
||||
end
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ Feature: UserTeams
|
|||
When I visit team merge requests page
|
||||
Then I should see merge requests from this team assigned to me
|
||||
|
||||
@javascript
|
||||
Scenario: I should add user to projects in Team
|
||||
Given I have team with projects and members
|
||||
Given I have new user "John"
|
||||
|
|
25
spec/support/select2_helper.rb
Normal file
25
spec/support/select2_helper.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Select2 ajax programatic helper
|
||||
# It allows you to select value from select2
|
||||
#
|
||||
# Params
|
||||
# value - real value of selected item
|
||||
# opts - options containing css selector
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# select2(2, from: '#user_ids')
|
||||
#
|
||||
|
||||
module Select2Helper
|
||||
def select2(value, options={})
|
||||
raise "Must pass a hash containing 'from'" if not options.is_a?(Hash) or not options.has_key?(:from)
|
||||
|
||||
selector = options[:from]
|
||||
|
||||
if options[:multiple]
|
||||
page.execute_script("$('#{selector}').select2('val', ['#{value}']);")
|
||||
else
|
||||
page.execute_script("$('#{selector}').select2('val', '#{value}');")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue