diff options
131 files changed, 1738 insertions, 1212 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b917c645ff8..ff8aa351226 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,6 +18,7 @@ variables: SIMPLECOV: "true" USE_DB: "true" USE_BUNDLE_INSTALL: "true" + GIT_DEPTH: "20" before_script: - source ./scripts/prepare_build.sh diff --git a/CHANGELOG b/CHANGELOG index f0e4cbcdda0..5c735bd1420 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,10 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.10.0 (unreleased) + - Fix commit builds API, return all builds for all pipelines for given commit. !4849 - Replace Haml with Hamlit to make view rendering faster. !3666 - Wrap code blocks on Activies and Todos page. !4783 (winniehell) + - Display last commit of deleted branch in push events !4699 (winniehell) - Add Sidekiq queue duration to transaction metrics. - Let Workhorse serve format-patch diffs - Make images fit to the size of the viewport !4810 @@ -12,10 +14,20 @@ v 8.10.0 (unreleased) - Exclude email check from the standard health check - Fix changing issue state columns in milestone view - Fix user creation with stronger minimum password requirements !4054 (nathan-pmt) + - Check for conflicts with existing Project's wiki path when creating a new project. + - Remove unused front-end variable -> default_issues_tracker - Add API endpoint for a group issues !4520 (mahcsig) - Allow [ci skip] to be in any case and allow [skip ci]. !4785 (simon_w) + - Add basic system information like memory and disk usage to the admin panel + +v 8.9.3 (unreleased) + - Decreased min width of screen to 1280px for pinned sidebar + - Fix encrypted data backwards compatibility after upgrading attr_encrypted gem + - Update mobile button icons to be more inline with typical UI paradigms v 8.9.2 + - Fix visibility of snippets when searching. + - Fix an information disclosure when requesting access to a group containing private projects. - Update omniauth-saml to 1.6.0 !4951 v 8.9.1 @@ -62,6 +74,8 @@ v 8.9.1 - Remove duplicate 'New Page' button on edit wiki page v 8.9.0 +v 8.9.0 (unreleased) + - Fix group visibility form layout in application settings - Fix builds API response not including commit data - Fix error when CI job variables key specified but not defined - Fix pipeline status when there are no builds in pipeline @@ -157,6 +171,7 @@ v 8.9.0 - Add Application Setting to configure Container Registry token expire delay (default 5min) - Cache assigned issue and merge request counts in sidebar nav - Use Knapsack only in CI environment + - Updated project creation page to match new UI #2542 - Cache project build count in sidebar nav - Add milestone expire date to the right sidebar - Manually mark a issue or merge request as a todo @@ -212,6 +227,10 @@ v 8.9.0 - Add tooltip to pin/unpin navbar - Add new sub nav style to Wiki and Graphs sub navigation +v 8.8.6 + - Fix visibility of snippets when searching. + - Update omniauth-saml to 1.6.0 !4951 + v 8.8.5 - Import GitHub repositories respecting the API rate limit !4166 - Fix todos page throwing errors when you have a project pending deletion !4300 @@ -342,6 +361,10 @@ v 8.8.0 - When creating a .gitignore file a dropdown with templates will be provided - Shows the issue/MR list search/filter form and corrects the mobile styling for guest users. #17562 +v 8.7.8 + - Fix visibility of snippets when searching. + - Update omniauth-saml to 1.6.0 !4951 + v 8.7.7 - Fix import by `Any Git URL` broken if the URL contains a space - Prevent unauthorized access to other projects build traces @@ -346,3 +346,6 @@ gem "paranoia", "~> 2.0" # Health check gem 'health_check', '~> 1.5.1' + +# System information +gem 'vmstat', '~> 2.1.0' diff --git a/Gemfile.lock b/Gemfile.lock index 66660f546e7..c1d2f1fdf5a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -780,6 +780,7 @@ GEM coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) equalizer (~> 0.0, >= 0.0.9) + vmstat (2.1.0) warden (1.2.6) rack (>= 1.0) web-console (2.3.0) @@ -984,6 +985,7 @@ DEPENDENCIES unicorn-worker-killer (~> 0.4.2) version_sorter (~> 2.0.0) virtus (~> 1.0.1) + vmstat (~> 2.1.0) web-console (~> 2.0) webmock (~> 1.21.0) wikicloth (= 0.8.1) diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 5c5a4ca7670..b6dbf2d0cc1 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -199,7 +199,6 @@ $ -> $('.header-content .header-logo').toggle() $('.header-content .navbar-collapse').toggle() $('.navbar-toggle').toggleClass('active') - $('.navbar-toggle i').toggleClass("fa-angle-right fa-angle-left") # Show/hide comments on diff $body.on "click", ".js-toggle-diff-comments", (e) -> @@ -261,7 +260,7 @@ $ -> new Aside() # Sidenav pinning - if $window.width() < 1440 and $.cookie('pin_nav') is 'true' + if $window.width() < 1280 and $.cookie('pin_nav') is 'true' $.cookie('pin_nav', 'false', { path: '/' }) $('.page-with-sidebar') .toggleClass('page-sidebar-collapsed page-sidebar-expanded') diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index 703128fecb3..1b0d9f0b1ae 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -186,6 +186,8 @@ class GitLabDropdown @fullData = data @parseData @fullData + + @filter.input.trigger('keyup') if @options.filterable and @filter and @filter.input } # Init filterable diff --git a/app/assets/stylesheets/framework/nav.scss b/app/assets/stylesheets/framework/nav.scss index 6211bc04597..6e5f216c894 100644 --- a/app/assets/stylesheets/framework/nav.scss +++ b/app/assets/stylesheets/framework/nav.scss @@ -21,9 +21,8 @@ .fa { position: relative; - top: 3px; - font-size: 13px; - color: $btn-placeholder-gray; + top: 5px; + font-size: 18px; } } diff --git a/app/assets/stylesheets/framework/sidebar.scss b/app/assets/stylesheets/framework/sidebar.scss index 98f917ce69b..e8d6a7f2775 100644 --- a/app/assets/stylesheets/framework/sidebar.scss +++ b/app/assets/stylesheets/framework/sidebar.scss @@ -1,5 +1,6 @@ .page-with-sidebar { padding-top: $header-height; + padding-bottom: 25px; transition: padding $sidebar-transition-duration; .sidebar-wrapper { diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index c37574ca7a1..87f8a17659f 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -7,7 +7,7 @@ $gutter_collapsed_width: 62px; $gutter_width: 290px; $gutter_inner_width: 258px; $sidebar-transition-duration: .15s; -$sidebar-breakpoint: 1440px; +$sidebar-breakpoint: 1280px; /* * UI elements diff --git a/app/assets/stylesheets/pages/projects.scss b/app/assets/stylesheets/pages/projects.scss index d3e59d7fdb9..89ce1b2df20 100644 --- a/app/assets/stylesheets/pages/projects.scss +++ b/app/assets/stylesheets/pages/projects.scss @@ -13,10 +13,53 @@ .new_project, .edit-project { - fieldset.features { - .control-label { + fieldset { + &.features .control-label { font-weight: normal; } + .form-group { + margin-bottom: 5px; + } + &> .form-group { + padding-left: 0; + } + } + .help-block { + margin-bottom: 10px; + } + .project-path { + padding-right: 0; + .form-control { + border-radius: $border-radius-base; + } + } + .input-group > div { + &:last-child { + padding-right: 0; + } + } + @media (max-width: $screen-xs-max) { + .input-group > div { + margin-bottom: 14px; + &:last-child { + margin-bottom: 0; + } + } + fieldset > .form-group:first-child { + padding-right: 0; + } + } + + .input-group-addon { + &.static-namespace { + height: 35px; + border-radius: 3px; + border: 1px solid #e5e5e5; + } + &+ .select2 a { + border-top-left-radius: 0; + border-bottom-left-radius: 0; + } } } @@ -365,10 +408,28 @@ a.deploy-project-label { } } -.project-import .btn { - float: left; - margin-bottom: 10px; - margin-right: 10px; +.project-import { + .form-group { + margin-bottom: 0; + } + .import-buttons { + padding-left: 0; + display: -webkit-flex; + display: flex; + -webkit-flex-wrap: wrap; + flex-wrap: wrap; + .btn { + margin-right: 10px; + padding: 8px 12px; + } + &> div { + margin-bottom: 14px; + padding-left: 0; + &:last-child { + margin-bottom: 0; + } + } + } } .project-stats { diff --git a/app/controllers/admin/system_info_controller.rb b/app/controllers/admin/system_info_controller.rb new file mode 100644 index 00000000000..3c67370b667 --- /dev/null +++ b/app/controllers/admin/system_info_controller.rb @@ -0,0 +1,13 @@ +class Admin::SystemInfoController < Admin::ApplicationController + def show + system_info = Vmstat.snapshot + + @cpus = system_info.cpus.length + + @mem_used = system_info.memory.active_bytes + @mem_total = system_info.memory.total_bytes + + @disk_used = system_info.disks[0].used_bytes + @disk_total = system_info.disks[0].total_bytes + end +end diff --git a/app/controllers/dashboard/groups_controller.rb b/app/controllers/dashboard/groups_controller.rb index 71ba6153021..de6bc689bb7 100644 --- a/app/controllers/dashboard/groups_controller.rb +++ b/app/controllers/dashboard/groups_controller.rb @@ -1,5 +1,5 @@ class Dashboard::GroupsController < Dashboard::ApplicationController def index - @group_members = current_user.group_members.page(params[:page]) + @group_members = current_user.group_members.includes(:source).page(params[:page]) end end diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 6751737d15e..d162a5a3165 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -18,9 +18,16 @@ class Projects::CommitController < Projects::ApplicationController apply_diff_view_cookie! @grouped_diff_notes = commit.notes.grouped_diff_notes + @notes = commit.notes.non_diff_notes.fresh + + Banzai::NoteRenderer.render( + @grouped_diff_notes.values.flatten + @notes, + @project, + current_user, + ) @note = @project.build_commit_note(commit) - @notes = commit.notes.non_diff_notes.fresh + @noteable = @commit @comments_target = { noteable_type: 'Commit', diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 4b4bc3d4276..428a42266d0 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -1,10 +1,10 @@ module BlobHelper - def highlighter(blob_name, blob_content, nowrap: false) - Gitlab::Highlight.new(blob_name, blob_content, nowrap: nowrap) + def highlighter(blob_name, blob_content, repository: nil, nowrap: false) + Gitlab::Highlight.new(blob_name, blob_content, nowrap: nowrap, repository: repository) end - def highlight(blob_name, blob_content, nowrap: false, plain: false) - Gitlab::Highlight.highlight(blob_name, blob_content, nowrap: nowrap, plain: plain) + def highlight(blob_name, blob_content, repository: nil, nowrap: false, plain: false) + Gitlab::Highlight.highlight(blob_name, blob_content, nowrap: nowrap, plain: plain, repository: repository) end def no_highlight_files diff --git a/app/models/ci/variable.rb b/app/models/ci/variable.rb index f8d5d4486fd..c9c47ec7419 100644 --- a/app/models/ci/variable.rb +++ b/app/models/ci/variable.rb @@ -13,6 +13,7 @@ module Ci attr_encrypted :value, mode: :per_attribute_iv_and_salt, + insecure_mode: true, key: Gitlab::Application.secrets.db_key_base, algorithm: 'aes-256-cbc' end diff --git a/app/models/event.rb b/app/models/event.rb index 716039fb54b..d7d23c7ae6d 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -315,7 +315,7 @@ class Event < ActiveRecord::Base def body? if push? - push_with_commits? + push_with_commits? || rm_ref? elsif note? true else diff --git a/app/models/group.rb b/app/models/group.rb index e66e04371b2..c70c719e338 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -11,7 +11,7 @@ class Group < Namespace has_many :users, -> { where(members: { requested_at: nil }) }, through: :group_members has_many :owners, - -> { where(members: { access_level: Gitlab::Access::OWNER }) }, + -> { where(members: { requested_at: nil, access_level: Gitlab::Access::OWNER }) }, through: :group_members, source: :user diff --git a/app/models/project.rb b/app/models/project.rb index ca3bc04e2dd..96837364423 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -163,6 +163,7 @@ class Project < ActiveRecord::Base validates :avatar, file_size: { maximum: 200.kilobytes.to_i } validate :visibility_level_allowed_by_group validate :visibility_level_allowed_as_fork + validate :check_wiki_path_conflict add_authentication_token_field :runners_token before_save :ensure_runners_token @@ -539,6 +540,16 @@ class Project < ActiveRecord::Base self.errors.add(:visibility_level, "#{level_name} is not allowed since the fork source project has lower visibility.") end + def check_wiki_path_conflict + return if path.blank? + + path_to_check = path.ends_with?('.wiki') ? path.chomp('.wiki') : "#{path}.wiki" + + if Project.where(namespace_id: namespace_id, path: path_to_check).exists? + errors.add(:name, 'has already been taken') + end + end + def to_param path end diff --git a/app/models/project_import_data.rb b/app/models/project_import_data.rb index ca8a9b4217b..331123a5a5b 100644 --- a/app/models/project_import_data.rb +++ b/app/models/project_import_data.rb @@ -7,6 +7,7 @@ class ProjectImportData < ActiveRecord::Base marshal: true, encode: true, mode: :per_attribute_iv_and_salt, + insecure_mode: true, algorithm: 'aes-256-cbc' serialize :data, JSON diff --git a/app/models/repository.rb b/app/models/repository.rb index acc720ccfa3..2a6a3b086c2 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -978,6 +978,10 @@ class Repository raw_repository.ls_files(actual_ref) end + def gitattribute(path, name) + raw_repository.attributes(path)[name] + end + def copy_gitattributes(ref) actual_ref = ref || root_ref begin diff --git a/app/models/snippet.rb b/app/models/snippet.rb index f8034cb5e6b..5ec933601ac 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -20,6 +20,7 @@ class Snippet < ActiveRecord::Base length: { within: 0..255 }, format: { with: Gitlab::Regex.file_name_regex, message: Gitlab::Regex.file_name_regex_message } + validates :content, presence: true validates :visibility_level, inclusion: { in: Gitlab::VisibilityLevel.values } @@ -81,6 +82,11 @@ class Snippet < ActiveRecord::Base 0 end + # alias for compatibility with blobs and highlighting + def path + file_name + end + def name file_name end @@ -135,7 +141,16 @@ class Snippet < ActiveRecord::Base end def accessible_to(user) - where('visibility_level IN (?) OR author_id = ?', [Snippet::INTERNAL, Snippet::PUBLIC], user) + return are_public unless user.present? + return all if user.admin? + + where( + 'visibility_level IN (:visibility_levels) + OR author_id = :author_id + OR project_id IN (:project_ids)', + visibility_levels: [Snippet::PUBLIC, Snippet::INTERNAL], + author_id: user.id, + project_ids: user.authorized_projects.select(:id)) end end end diff --git a/app/models/user.rb b/app/models/user.rb index 04b220ee13c..767d6366c79 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -25,6 +25,7 @@ class User < ActiveRecord::Base attr_encrypted :otp_secret, key: Gitlab::Application.config.secret_key_base, mode: :per_attribute_iv_and_salt, + insecure_mode: true, algorithm: 'aes-256-cbc' devise :two_factor_authenticatable, @@ -57,7 +58,7 @@ class User < ActiveRecord::Base # Groups has_many :members, dependent: :destroy - has_many :group_members, dependent: :destroy, source: 'GroupMember' + has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, source: 'GroupMember' has_many :groups, through: :group_members has_many :owned_groups, -> { where members: { access_level: Gitlab::Access::OWNER } }, through: :group_members, source: :group has_many :masters_groups, -> { where members: { access_level: Gitlab::Access::MASTER } }, through: :group_members, source: :group @@ -65,7 +66,7 @@ class User < ActiveRecord::Base # Projects has_many :groups_projects, through: :groups, source: :projects has_many :personal_projects, through: :namespace, source: :projects - has_many :project_members, dependent: :destroy, class_name: 'ProjectMember' + has_many :project_members, -> { where(requested_at: nil) }, dependent: :destroy, class_name: 'ProjectMember' has_many :projects, through: :project_members has_many :created_projects, foreign_key: :creator_id, class_name: 'Project' has_many :users_star_projects, dependent: :destroy diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index c883e8f97da..30ab0717164 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -15,7 +15,7 @@ = f.label :default_snippet_visibility, class: 'control-label col-sm-2' .col-sm-10 = render('shared/visibility_radios', model_method: :default_snippet_visibility, form: f, selected_level: @application_setting.default_snippet_visibility, form_model: ProjectSnippet.new) - .form-group.group-visibility-level-holder + .form-group.project-visibility-level-holder = f.label :default_group_visibility, class: 'control-label col-sm-2' .col-sm-10 = render('shared/visibility_radios', model_method: :default_group_visibility, form: f, selected_level: @application_setting.default_group_visibility, form_model: Group.new) diff --git a/app/views/admin/background_jobs/_head.html.haml b/app/views/admin/background_jobs/_head.html.haml index d78682532ed..9d722bd7382 100644 --- a/app/views/admin/background_jobs/_head.html.haml +++ b/app/views/admin/background_jobs/_head.html.haml @@ -1,5 +1,9 @@ .nav-links.sub-nav %ul{ class: (container_class) } + = nav_link(controller: :system_info) do + = link_to admin_system_info_path, title: 'System Info' do + %span + System Info = nav_link(controller: :background_jobs) do = link_to admin_background_jobs_path, title: 'Background Jobs' do %span diff --git a/app/views/admin/system_info/show.html.haml b/app/views/admin/system_info/show.html.haml new file mode 100644 index 00000000000..3ef2f20b589 --- /dev/null +++ b/app/views/admin/system_info/show.html.haml @@ -0,0 +1,22 @@ +- @no_container = true +- page_title "System Info" += render 'admin/background_jobs/head' + +%div{ class: (container_class) } + .prepend-top-default + .row + .col-sm-4 + .light-well + %h4 CPU + .data + %h1= "#{@cpus} cores" + .col-sm-4 + .light-well + %h4 Memory + .data + %h1= "#{number_to_human_size(@mem_used)} / #{number_to_human_size(@mem_total)}" + .col-sm-4 + .light-well + %h4 Disk + .data + %h1= "#{number_to_human_size(@disk_used)} / #{number_to_human_size(@disk_total)}" diff --git a/app/views/admin/users/groups.html.haml b/app/views/admin/users/groups.html.haml index b0a709a568a..8f6d13b881a 100644 --- a/app/views/admin/users/groups.html.haml +++ b/app/views/admin/users/groups.html.haml @@ -1,11 +1,12 @@ - page_title "Groups", @user.name, "Users" = render 'admin/users/head' -- if @user.group_members.present? +- group_members = @user.group_members.includes(:source) +- if group_members.any? .panel.panel-default .panel-heading Groups: %ul.well-list - - @user.group_members.each do |group_member| + - group_members.each do |group_member| - group = group_member.group %li.group_member %span{class: ("list-item-name" unless group_member.owner?)} diff --git a/app/views/events/event/_push.html.haml b/app/views/events/event/_push.html.haml index dc4ff17e31a..ea54ef226ec 100644 --- a/app/views/events/event/_push.html.haml +++ b/app/views/events/event/_push.html.haml @@ -1,3 +1,5 @@ +- project = event.project + .event-title %span.author_name= link_to_author event %span.event_label.pushed #{event.action_name} #{event.ref_type} @@ -5,19 +7,18 @@ %strong= event.ref_name - else %strong - = link_to event.ref_name, namespace_project_commits_path(event.project.namespace, event.project, event.ref_name), title: h(event.target_title) + = link_to event.ref_name, namespace_project_commits_path(project.namespace, project, event.ref_name), title: h(event.target_title) at - = link_to_project event.project + = link_to_project project - if event.push_with_commits? - - project = event.project .event-body %ul.well-list.event_commits - few_commits = event.commits[0...2] - few_commits.each do |commit| = render "events/commit", commit: commit, project: project, event: event - - create_mr = event.new_ref? && create_mr_button?(event.project.default_branch, event.ref_name, event.project) + - create_mr = event.new_ref? && create_mr_button?(project.default_branch, event.ref_name, project) - if event.commits_count > 1 %li.commits-stat - if event.commits_count > 2 @@ -27,18 +28,26 @@ - from = event.commit_from - from_label = truncate_sha(from) - else - - from = event.project.default_branch + - from = project.default_branch - from_label = from - = link_to namespace_project_compare_path(event.project.namespace, event.project, from: from, to: event.commit_to) do + = link_to namespace_project_compare_path(project.namespace, project, from: from, to: event.commit_to) do Compare #{from_label}...#{truncate_sha(event.commit_to)} - if create_mr %span{"data-user-is" => event.author_id, "data-display" => "inline"} or - = link_to create_mr_path(event.project.default_branch, event.ref_name, event.project) do + = link_to create_mr_path(project.default_branch, event.ref_name, project) do create a merge request - elsif create_mr %li.commits-stat{"data-user-is" => event.author_id} - = link_to create_mr_path(event.project.default_branch, event.ref_name, event.project) do + = link_to create_mr_path(project.default_branch, event.ref_name, project) do Create Merge Request +- elsif event.rm_ref? + - repository = project.repository + - last_commit = repository.commit(event.commit_from) + - if last_commit + .event-body + %ul.well-list.event_commits + = render "events/commit", commit: last_commit, project: project, event: event + diff --git a/app/views/layouts/header/_default.html.haml b/app/views/layouts/header/_default.html.haml index 40a2c81eebd..1a39572ac3c 100644 --- a/app/views/layouts/header/_default.html.haml +++ b/app/views/layouts/header/_default.html.haml @@ -6,7 +6,7 @@ = icon('bars') %button.navbar-toggle{type: 'button'} %span.sr-only Toggle navigation - = icon('angle-left') + = icon('ellipsis-v') .navbar-collapse.collapse %ul.nav.navbar-nav diff --git a/app/views/layouts/nav/_admin.html.haml b/app/views/layouts/nav/_admin.html.haml index 0f264cd2e06..5ee8772882e 100644 --- a/app/views/layouts/nav/_admin.html.haml +++ b/app/views/layouts/nav/_admin.html.haml @@ -1,16 +1,16 @@ .scrolling-tabs-container{ class: nav_control_class } = render 'layouts/nav/admin_settings' .fade-left - = icon('arrow-left') + = icon('angle-left') .fade-right - = icon('arrow-right') + = icon('angle-right') %ul.nav-links.scrolling-tabs = nav_link(controller: %w(dashboard admin projects users groups builds runners), html_options: {class: 'home'}) do = link_to admin_root_path, title: 'Overview', class: 'shortcuts-tree' do %span Overview - = nav_link(controller: %w(background_jobs logs health_check)) do - = link_to admin_background_jobs_path, title: 'Monitoring' do + = nav_link(controller: %w(system_info background_jobs logs health_check)) do + = link_to admin_system_info_path, title: 'Monitoring' do %span Monitoring = nav_link(controller: :broadcast_messages) do diff --git a/app/views/layouts/nav/_group.html.haml b/app/views/layouts/nav/_group.html.haml index 5d657a9ac84..d7d36c84b6c 100644 --- a/app/views/layouts/nav/_group.html.haml +++ b/app/views/layouts/nav/_group.html.haml @@ -1,9 +1,9 @@ .scrolling-tabs-container{ class: nav_control_class } = render 'layouts/nav/group_settings' .fade-left - = icon('arrow-left') + = icon('angle-left') .fade-right - = icon('arrow-right') + = icon('angle-right') %ul.nav-links.scrolling-tabs = nav_link(path: 'groups#show', html_options: {class: 'home'}) do = link_to group_path(@group), title: 'Home' do diff --git a/app/views/layouts/nav/_profile.html.haml b/app/views/layouts/nav/_profile.html.haml index f37f9b0f5a3..96fe62c39c3 100644 --- a/app/views/layouts/nav/_profile.html.haml +++ b/app/views/layouts/nav/_profile.html.haml @@ -1,8 +1,8 @@ .scrolling-tabs-container .fade-left - = icon('arrow-left') + = icon('angle-left') .fade-right - = icon('arrow-right') + = icon('angle-right') %ul.nav-links.scrolling-tabs = nav_link(path: 'profiles#show', html_options: {class: 'home'}) do = link_to profile_path, title: 'Profile Settings' do diff --git a/app/views/layouts/nav/_project.html.haml b/app/views/layouts/nav/_project.html.haml index a4bb56aa56f..dcef427cda3 100644 --- a/app/views/layouts/nav/_project.html.haml +++ b/app/views/layouts/nav/_project.html.haml @@ -26,9 +26,9 @@ .scrolling-tabs-container{ class: nav_control_class } .fade-left - = icon('arrow-left') + = icon('angle-left') .fade-right - = icon('arrow-right') + = icon('angle-right') %ul.nav-links.scrolling-tabs = nav_link(path: 'projects#show', html_options: {class: 'home'}) do = link_to project_path(@project), title: 'Project', class: 'shortcuts-project' do diff --git a/app/views/projects/blob/_text.html.haml b/app/views/projects/blob/_text.html.haml index b1769759dce..58524418a67 100644 --- a/app/views/projects/blob/_text.html.haml +++ b/app/views/projects/blob/_text.html.haml @@ -16,4 +16,4 @@ .file-content.code .nothing-here-block Empty file - else - = render 'shared/file_highlight', blob: blob + = render 'shared/file_highlight', blob: blob, repository: @repository diff --git a/app/views/projects/commits/_head.html.haml b/app/views/projects/commits/_head.html.haml index b11b6c24ccd..61152649907 100644 --- a/app/views/projects/commits/_head.html.haml +++ b/app/views/projects/commits/_head.html.haml @@ -1,8 +1,8 @@ .scrolling-tabs-container.sub-nav-scroll .fade-left - = icon('arrow-left') + = icon('angle-left') .fade-right - = icon('arrow-right') + = icon('angle-right') .nav-links.sub-nav.scrolling-tabs %ul{ class: (container_class) } = nav_link(controller: %w(tree blob blame edit_tree new_tree find_file)) do diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index 3c1c6060504..8a73b077357 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -1,110 +1,121 @@ - page_title 'New Project' - header_title "Projects", dashboard_projects_path -%h3.page-title - New Project -%hr - .project-edit-container .project-edit-errors = render 'projects/errors' - .project-edit-content - - = form_for @project, html: { class: 'new_project form-horizontal js-requires-input' } do |f| - .form-group - = f.label :path, class: 'control-label' do - Project owner - .col-sm-10 - = f.select :namespace_id, namespaces_options(:current_user), {}, {class: 'select2 js-select-namespace', tabindex: 1} - - - if current_user.can_create_group? - .help-block - Want to house several dependent projects under the same namespace? - = link_to "Create a group", new_group_path - - .form-group - = f.label :path, class: 'control-label' do - Project name - .col-sm-10 - = f.text_field :path, placeholder: "my-awesome-project", class: "form-control", tabindex: 2, autofocus: true, required: true - - - if import_sources_enabled? - .project-import.js-toggle-container - .form-group - %label.control-label Import project from - .col-sm-10 - - if github_import_enabled? - - if github_import_configured? - = link_to status_import_github_path, class: 'btn import_github' do - %i.fa.fa-github - GitHub - - else - = link_to '#', class: 'how_to_import_link btn import_github' do - %i.fa.fa-github - GitHub - = render 'github_import_modal' - - - if bitbucket_import_enabled? - - if bitbucket_import_configured? - = link_to status_import_bitbucket_path, class: 'btn import_bitbucket', "data-no-turbolink" => "true" do - %i.fa.fa-bitbucket - Bitbucket - - else - = link_to status_import_bitbucket_path, class: 'how_to_import_link btn import_bitbucket', "data-no-turbolink" => "true" do - %i.fa.fa-bitbucket - Bitbucket - = render 'bitbucket_import_modal' - - - if gitlab_import_enabled? - - if gitlab_import_configured? - = link_to status_import_gitlab_path, class: 'btn import_gitlab' do - %i.fa.fa-heart - GitLab.com + .row.prepend-top-default + .col-lg-3.profile-settings-sidebar + %h4.prepend-top-0 + New project + %p + Create or Import your project from popular Git services + .col-lg-9 + = form_for @project, html: { class: 'new_project' } do |f| + %fieldset.append-bottom-0 + .form-group.col-xs-12.col-sm-6 + = f.label :namespace_id, class: 'label-light' do + %span + Project path + .form-group + .input-group + - if current_user.can_select_namespace? + .input-group-addon + = root_url + = f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user, display_path: true), {}, {class: 'select2 js-select-namespace', tabindex: 1} - else - = link_to status_import_gitlab_path, class: 'how_to_import_link btn import_gitlab' do - %i.fa.fa-heart - GitLab.com - = render 'gitlab_import_modal' - - - if gitorious_import_enabled? - = link_to new_import_gitorious_path, class: 'btn import_gitorious' do - %i.icon-gitorious.icon-gitorious-small - Gitorious.org - - - if google_code_import_enabled? - = link_to new_import_google_code_path, class: 'btn import_google_code' do - %i.fa.fa-google - Google Code - - - if fogbugz_import_enabled? - = link_to new_import_fogbugz_path, class: 'btn import_fogbugz' do - %i.fa.fa-bug - Fogbugz - - - if git_import_enabled? - = link_to "#", class: 'btn js-toggle-button import_git' do - %i.fa.fa-git - %span Repo by URL - - - if gitlab_project_import_enabled? - = link_to new_import_gitlab_project_path, class: 'btn import_gitlab_project project-submit' do - %i.fa.fa-gitlab - %span GitLab export - - .js-toggle-content.hide - = render "shared/import_form", f: f - - .prepend-botton-10 - - .form-group - = f.label :description, class: 'control-label' do - Description - %span.light (optional) - .col-sm-10 - = f.text_area :description, class: "form-control", rows: 3, maxlength: 250, tabindex: 3 - = render 'shared/visibility_level', f: f, visibility_level: default_project_visibility, can_change_visibility_level: true, form_model: @project + .input-group-addon.static-namespace + #{root_url}#{current_user.username}/ + .form-group.col-xs-12.col-sm-6.project-path + = f.label :namespace_id, class: 'label-light' do + %span + Project name + = f.text_field :path, placeholder: "my-awesome-project", class: "form-control", tabindex: 2, autofocus: true, required: true + - if current_user.can_create_group? + .help-block + Want to house several dependent projects under the same namespace? + = link_to "Create a group", new_group_path + + - if import_sources_enabled? + .project-import.js-toggle-container + .form-group.clearfix + = f.label :visibility_level, class: 'label-light' do + Import project from + .col-sm-12.import-buttons + %div + - if github_import_enabled? + - if github_import_configured? + = link_to status_import_github_path, class: 'btn import_github' do + %i.fa.fa-github + GitHub + - else + = link_to '#', class: 'how_to_import_link btn import_github' do + %i.fa.fa-github + GitHub + = render 'github_import_modal' + %div + - if bitbucket_import_enabled? + - if bitbucket_import_configured? + = link_to status_import_bitbucket_path, class: 'btn import_bitbucket', "data-no-turbolink" => "true" do + %i.fa.fa-bitbucket + Bitbucket + - else + = link_to status_import_bitbucket_path, class: 'how_to_import_link btn import_bitbucket', "data-no-turbolink" => "true" do + %i.fa.fa-bitbucket + Bitbucket + = render 'bitbucket_import_modal' + %div + - if gitlab_import_enabled? + - if gitlab_import_configured? + = link_to status_import_gitlab_path, class: 'btn import_gitlab' do + %i.fa.fa-heart + GitLab.com + - else + = link_to status_import_gitlab_path, class: 'how_to_import_link btn import_gitlab' do + %i.fa.fa-heart + GitLab.com + = render 'gitlab_import_modal' + %div + - if gitorious_import_enabled? + = link_to new_import_gitorious_path, class: 'btn import_gitorious' do + %i.icon-gitorious.icon-gitorious-small + Gitorious.org + %div + - if google_code_import_enabled? + = link_to new_import_google_code_path, class: 'btn import_google_code' do + %i.fa.fa-google + Google Code + %div + - if fogbugz_import_enabled? + = link_to new_import_fogbugz_path, class: 'btn import_fogbugz' do + %i.fa.fa-bug + Fogbugz + %div + - if git_import_enabled? + = link_to "#", class: 'btn js-toggle-button import_git' do + %i.fa.fa-git + %span Repo by URL + %div + - if gitlab_project_import_enabled? + = link_to new_import_gitlab_project_path, class: 'btn import_gitlab_project project-submit' do + %i.fa.fa-gitlab + %span GitLab export + + .js-toggle-content.hide + = render "shared/import_form", f: f + + .form-group + = f.label :description, class: 'label-light' do + Project description + %span.light (optional) + = f.text_area :description, placeholder: 'Description format', class: "form-control", rows: 3, maxlength: 250 + + .form-group.project-visibility-level-holder + = f.label :visibility_level, class: 'label-light' do + Visibility Level + = link_to "(?)", help_page_path("public_access", "public_access") + = render('shared/visibility_radios', model_method: :visibility_level, form: f, selected_level: @project.visibility_level, form_model: @project) - .form-actions = f.submit 'Create project', class: "btn btn-create project-submit", tabindex: 4 = link_to 'Cancel', dashboard_projects_path, class: 'btn btn-cancel' diff --git a/app/views/shared/_file_highlight.html.haml b/app/views/shared/_file_highlight.html.haml index ad944a19ca1..e26693bf5b9 100644 --- a/app/views/shared/_file_highlight.html.haml +++ b/app/views/shared/_file_highlight.html.haml @@ -1,3 +1,5 @@ +- repository = nil unless local_assigns.key?(:repository) + .file-content.code.js-syntax-highlight .line-numbers - if blob.data.present? @@ -11,4 +13,4 @@ = link_icon = i .blob-content{data: {blob_id: blob.id}} - = highlight(blob.name, blob.data, plain: blob.no_highlighting?) + = highlight(blob.path, blob.data, repository: repository, plain: blob.no_highlighting?) diff --git a/config/routes.rb b/config/routes.rb index e45293cdf7f..bdfb16a66bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -280,6 +280,7 @@ Rails.application.routes.draw do resource :logs, only: [:show] resource :health_check, controller: 'health_check', only: [:show] resource :background_jobs, controller: 'background_jobs', only: [:show] + resource :system_info, controller: 'system_info', only: [:show] resources :namespaces, path: '/projects', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do root to: 'projects#index', as: :projects diff --git a/doc/api/builds.md b/doc/api/builds.md index de998944352..2adea11247e 100644 --- a/doc/api/builds.md +++ b/doc/api/builds.md @@ -107,6 +107,11 @@ Example of response Get a list of builds for specific commit in a project. +This endpoint will return all builds, from all pipelines for a given commit. +If the commit SHA is not found, it will respond with 404, otherwise it will +return an array of builds (an empty array if there are no builds for this +particular commit). + ``` GET /projects/:id/repository/commits/:sha/builds ``` diff --git a/doc/api/settings.md b/doc/api/settings.md index 43a0fe35e42..b5152311f28 100644 --- a/doc/api/settings.md +++ b/doc/api/settings.md @@ -56,7 +56,7 @@ PUT /application/settings | `gravatar_enabled` | boolean | no | Enable Gravatar | | `sign_in_text` | string | no | Text on login page | | `home_page_url` | string | no | Redirect to this URL when not logged in | -| `default_branch_protection` | integer | no | Determine if developers can push to master. Can take `0` _(not protected, both developers and masters can push new commits, force push or delete the branch)_, `1` _(partially protected, developers can push new commits, but cannot force push or delete the branch, masters can do anything)_ or `2` _(fully protected, developers cannot push new commits, force push or delete the branch, masters can do anything)_ as a parameter. Default is `1`. | +| `default_branch_protection` | integer | no | Determine if developers can push to master. Can take `0` _(not protected, both developers and masters can push new commits, force push or delete the branch)_, `1` _(partially protected, developers can push new commits, but cannot force push or delete the branch, masters can do anything)_ or `2` _(fully protected, developers cannot push new commits, force push or delete the branch, masters can do anything)_ as a parameter. Default is `2`. | | `restricted_visibility_levels` | array of integers | no | Selected levels cannot be used by non-admin users for projects or snippets. Can take `0` _(Private)_, `1` _(Internal)_ and `2` _(Public)_ as a parameter. Default is null which means there is no restriction. | | `max_attachment_size` | integer | no | Limit attachment size in MB | | `session_expire_delay` | integer | no | Session duration in minutes. GitLab restart is required to apply changes | diff --git a/doc/development/architecture.md b/doc/development/architecture.md index 12e33406cb6..33fd50f4c11 100644 --- a/doc/development/architecture.md +++ b/doc/development/architecture.md @@ -52,7 +52,9 @@ To serve repositories over SSH there's an add-on application called gitlab-shell ### Components -![GitLab Diagram Overview](gitlab_diagram_overview.png) +![GitLab Diagram Overview](gitlab_architecture_diagram.png) + +_[edit diagram (for GitLab team members only)](https://docs.google.com/drawings/d/1fBzAyklyveF-i-2q-OHUIqDkYfjjxC4mq5shwKSZHLs/edit)_ A typical install of GitLab will be on GNU/Linux. It uses Nginx or Apache as a web front end to proxypass the Unicorn web server. By default, communication between Unicorn and the front end is via a Unix domain socket but forwarding requests via TCP is also supported. The web front end accesses `/home/git/gitlab/public` bypassing the Unicorn server to serve static pages, uploads (e.g. avatar images or attachments), and precompiled assets. GitLab serves web pages and a [GitLab API](https://gitlab.com/gitlab-org/gitlab-ce/tree/master/doc/api) using the Unicorn web server. It uses Sidekiq as a job queue which, in turn, uses redis as a non-persistent database backend for job information, meta data, and incoming jobs. diff --git a/doc/development/gitlab_architecture_diagram.png b/doc/development/gitlab_architecture_diagram.png Binary files differnew file mode 100644 index 00000000000..9ab7ffd3c7b --- /dev/null +++ b/doc/development/gitlab_architecture_diagram.png diff --git a/doc/development/gitlab_diagram_overview.png b/doc/development/gitlab_diagram_overview.png Binary files differdeleted file mode 100644 index d9b9eed3d8f..00000000000 --- a/doc/development/gitlab_diagram_overview.png +++ /dev/null diff --git a/doc/update/8.8-to-8.9.md b/doc/update/8.8-to-8.9.md index f14046bb4be..423140a92c7 100644 --- a/doc/update/8.8-to-8.9.md +++ b/doc/update/8.8-to-8.9.md @@ -122,6 +122,19 @@ via [/etc/default/gitlab]. [Apache templates]: https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/web-server/apache [/etc/default/gitlab]: https://gitlab.com/gitlab-org/gitlab-ce/blob/8-9-stable/lib/support/init.d/gitlab.default.example#L37 +#### SMTP configuration + +If you're installing from source and use SMTP to deliver mail, you will need to add the following line +to config/initializers/smtp_settings.rb: + +```ruby +ActionMailer::Base.delivery_method = :smtp +``` + +See [smtp_settings.rb.sample] as an example. + +[smtp_settings.rb.sample]: https://gitlab.com/gitlab-org/gitlab-ce/blob/v8.9.0/config/initializers/smtp_settings.rb.sample#L13 + #### Init script Ensure you're still up-to-date with the latest init script changes: diff --git a/doc/user/project/highlighting.md b/doc/user/project/highlighting.md new file mode 100644 index 00000000000..73a2d176b54 --- /dev/null +++ b/doc/user/project/highlighting.md @@ -0,0 +1,31 @@ +[Rouge]: https://rubygems.org/gems/rouge + +# Syntax Highlighting + +GitLab provides syntax highlighting on all files and snippets through the [Rouge][] rubygem. It will try to guess what language to use based on the file extension, which most of the time is sufficient. + +If GitLab is guessing wrong, you can override its choice of language using the `gitlab-language` attribute in `.gitattributes`. For example, if you are working in a Prolog project and using the `.pl` file extension (which would normally be highlighted as Perl), you can add the following to your `.gitattributes` file: + +``` conf +*.pl gitlab-language=prolog +``` + +When you check in and push that change, all `*.pl` files in your project will be highlighted as Prolog. + +The paths here are simply git's builtin [`.gitattributes` interface](https://git-scm.com/docs/gitattributes). So, if you were to invent a file format called a `Nicefile` at the root of your project that used ruby syntax, all you need is: + +``` conf +/Nicefile gitlab-language=ruby +``` + +To disable highlighting entirely, use `gitlab-language=text`. Lots more fun shenanigans are available through CGI options, such as: + +``` conf +# json with erb in it +/my-cool-file gitlab-language=erb?parent=json + +# an entire file of highlighting errors! +/other-file gitlab-language=text?token=Error +``` + +Please note that these configurations will only take effect when the `.gitattributes` file is in your default branch (usually `master`). diff --git a/features/steps/dashboard/new_project.rb b/features/steps/dashboard/new_project.rb index 29e6b9f1a01..31f8924c38c 100644 --- a/features/steps/dashboard/new_project.rb +++ b/features/steps/dashboard/new_project.rb @@ -10,7 +10,7 @@ class Spinach::Features::NewProject < Spinach::FeatureSteps end step 'I see "New Project" page' do - expect(page).to have_content('Project owner') + expect(page).to have_content('Project path') expect(page).to have_content('Project name') end diff --git a/lib/api/api.rb b/lib/api/api.rb index f8f680a6311..c3fff8b2f8f 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -39,7 +39,7 @@ module API mount ::API::Issues mount ::API::Keys mount ::API::Labels - mount ::API::Licenses + mount ::API::LicenseTemplates mount ::API::MergeRequests mount ::API::Milestones mount ::API::Namespaces diff --git a/lib/api/builds.rb b/lib/api/builds.rb index 979328efe0e..086d8511e8f 100644 --- a/lib/api/builds.rb +++ b/lib/api/builds.rb @@ -33,10 +33,10 @@ module API get ':id/repository/commits/:sha/builds' do authorize_read_builds! - commit = user_project.pipelines.find_by_sha(params[:sha]) - return not_found! unless commit + return not_found! unless user_project.commit(params[:sha]) - builds = commit.builds.order('id DESC') + pipelines = user_project.pipelines.where(sha: params[:sha]) + builds = user_project.builds.where(pipeline: pipelines).order('id DESC') builds = filter_builds(builds, params[:scope]) present paginate(builds), with: Entities::Build, diff --git a/lib/api/licenses.rb b/lib/api/license_templates.rb index be0e113fbcb..d0552299ed0 100644 --- a/lib/api/licenses.rb +++ b/lib/api/license_templates.rb @@ -1,6 +1,6 @@ module API - # Licenses API - class Licenses < Grape::API + # License Templates API + class LicenseTemplates < Grape::API PROJECT_TEMPLATE_REGEX = /[\<\{\[] (project|description| diff --git a/lib/gitlab/blame.rb b/lib/gitlab/blame.rb index 997a22779a0..d62bc50ce78 100644 --- a/lib/gitlab/blame.rb +++ b/lib/gitlab/blame.rb @@ -41,7 +41,8 @@ module Gitlab def highlighted_lines @blob.load_all_data!(repository) - @highlighted_lines ||= Gitlab::Highlight.highlight(@blob.name, @blob.data).lines + @highlighted_lines ||= + Gitlab::Highlight.highlight(@blob.path, @blob.data, repository: repository).lines end def project diff --git a/lib/gitlab/gon_helper.rb b/lib/gitlab/gon_helper.rb index f751a3a12fd..d4f12cb1df9 100644 --- a/lib/gitlab/gon_helper.rb +++ b/lib/gitlab/gon_helper.rb @@ -3,7 +3,6 @@ module Gitlab def add_gon_variables gon.api_version = API::API.version gon.default_avatar_url = URI::join(Gitlab.config.gitlab.url, ActionController::Base.helpers.image_path('no_avatar.png')).to_s - gon.default_issues_tracker = Project.new.default_issue_tracker.to_param gon.max_file_size = current_application_settings.max_attachment_size gon.relative_url_root = Gitlab.config.gitlab.relative_url_root gon.shortcuts_path = help_shortcuts_path diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index 280120b0f9e..41296415e35 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -1,7 +1,7 @@ module Gitlab class Highlight - def self.highlight(blob_name, blob_content, nowrap: true, plain: false) - new(blob_name, blob_content, nowrap: nowrap). + def self.highlight(blob_name, blob_content, repository: nil, nowrap: true, plain: false) + new(blob_name, blob_content, nowrap: nowrap, repository: repository). highlight(blob_content, continue: false, plain: plain) end @@ -10,12 +10,21 @@ module Gitlab return [] unless blob blob.load_all_data!(repository) - highlight(file_name, blob.data).lines.map!(&:html_safe) + highlight(file_name, blob.data, repository: repository).lines.map!(&:html_safe) end - def initialize(blob_name, blob_content, nowrap: true) + attr_reader :lexer + def initialize(blob_name, blob_content, repository: nil, nowrap: true) + @blob_name = blob_name + @blob_content = blob_content + @repository = repository @formatter = rouge_formatter(nowrap: nowrap) - @lexer = Rouge::Lexer.guess(filename: blob_name, source: blob_content).new rescue Rouge::Lexers::PlainText + + @lexer = custom_language || begin + Rouge::Lexer.guess(filename: blob_name, source: blob_content).new + rescue Rouge::Lexer::AmbiguousGuess => e + e.alternatives.sort_by(&:tag).first + end end def highlight(text, continue: true, plain: false) @@ -30,6 +39,14 @@ module Gitlab private + def custom_language + language_name = @repository && @repository.gitattribute(@blob_name, 'gitlab-language') + + return nil unless language_name + + Rouge::Lexer.find_fancy(language_name) + end + def rouge_formatter(options = {}) options = options.reverse_merge( nowrap: true, diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index faf0d9b6318..c048fe20ba7 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -18,12 +18,12 @@ module Gitlab # Measures the real and CPU execution time of the supplied block. def measure - start_real = Time.now + start_real = System.monotonic_time start_cpu = System.cpu_time retval = yield - @real_time += (Time.now - start_real) * 1000.0 - @cpu_time += System.cpu_time.to_f - start_cpu + @real_time += System.monotonic_time - start_real + @cpu_time += System.cpu_time - start_cpu @call_count += 1 retval diff --git a/lib/gitlab/metrics/metric.rb b/lib/gitlab/metrics/metric.rb index 1cd1ca30f70..f23d67e1e38 100644 --- a/lib/gitlab/metrics/metric.rb +++ b/lib/gitlab/metrics/metric.rb @@ -4,16 +4,15 @@ module Gitlab class Metric JITTER_RANGE = 0.000001..0.001 - attr_reader :series, :values, :tags, :created_at + attr_reader :series, :values, :tags # series - The name of the series (as a String) to store the metric in. # values - A Hash containing the values to store. # tags - A Hash containing extra tags to add to the metrics. def initialize(series, values, tags = {}) - @values = values - @series = series - @tags = tags - @created_at = Time.now.utc + @values = values + @series = series + @tags = tags end # Returns a Hash in a format that can be directly written to InfluxDB. @@ -27,20 +26,20 @@ module Gitlab # # Due to the way InfluxDB is set up there's no solution to this problem, # all we can do is lower the amount of collisions. We do this by using - # Time#to_f which returns the seconds as a Float providing greater - # accuracy. We then add a small random value that is large enough to - # distinguish most timestamps but small enough to not alter the amount - # of seconds. + # System.real_time which returns the nanoseconds as a Float providing + # greater accuracy. We then add a small random value that is large + # enough to distinguish most timestamps but small enough to not alter + # the timestamp significantly. # # See https://gitlab.com/gitlab-com/operations/issues/175 for more # information. - time = @created_at.to_f + rand(JITTER_RANGE) + time = System.real_time(:nanosecond) + rand(JITTER_RANGE) { series: @series, tags: @tags, values: @values, - timestamp: (time * 1_000_000_000).to_i + timestamp: time.to_i } end end diff --git a/lib/gitlab/metrics/system.rb b/lib/gitlab/metrics/system.rb index a7d183b2f94..82c18bb108b 100644 --- a/lib/gitlab/metrics/system.rb +++ b/lib/gitlab/metrics/system.rb @@ -34,13 +34,29 @@ module Gitlab # THREAD_CPUTIME is not supported on OS X if Process.const_defined?(:CLOCK_THREAD_CPUTIME_ID) def self.cpu_time - Process.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :millisecond) + Process. + clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :millisecond).to_f end else def self.cpu_time - Process.clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :millisecond) + Process. + clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :millisecond).to_f end end + + # Returns the current real time in a given precision. + # + # Returns the time as a Float. + def self.real_time(precision = :millisecond) + Process.clock_gettime(Process::CLOCK_REALTIME, precision).to_f + end + + # Returns the current monotonic clock time in a given precision. + # + # Returns the time as a Float. + def self.monotonic_time(precision = :millisecond) + Process.clock_gettime(Process::CLOCK_MONOTONIC, precision).to_f + end end end end diff --git a/lib/gitlab/metrics/transaction.rb b/lib/gitlab/metrics/transaction.rb index 4bc5081aa03..bded245da43 100644 --- a/lib/gitlab/metrics/transaction.rb +++ b/lib/gitlab/metrics/transaction.rb @@ -30,7 +30,7 @@ module Gitlab end def duration - @finished_at ? (@finished_at - @started_at) * 1000.0 : 0.0 + @finished_at ? (@finished_at - @started_at) : 0.0 end def allocated_memory @@ -41,12 +41,12 @@ module Gitlab Thread.current[THREAD_KEY] = self @memory_before = System.memory_usage - @started_at = Time.now + @started_at = System.monotonic_time yield ensure @memory_after = System.memory_usage - @finished_at = Time.now + @finished_at = System.monotonic_time Thread.current[THREAD_KEY] = nil end diff --git a/spec/controllers/admin/impersonations_controller_spec.rb b/spec/controllers/admin/impersonations_controller_spec.rb index eb82476b179..d5f0b289b5b 100644 --- a/spec/controllers/admin/impersonations_controller_spec.rb +++ b/spec/controllers/admin/impersonations_controller_spec.rb @@ -22,7 +22,7 @@ describe Admin::ImpersonationsController do it "responds with status 404" do delete :destroy - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "doesn't sign us in" do @@ -46,7 +46,7 @@ describe Admin::ImpersonationsController do it "responds with status 404" do delete :destroy - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "doesn't sign us in as the impersonator" do @@ -65,7 +65,7 @@ describe Admin::ImpersonationsController do it "responds with status 404" do delete :destroy - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "doesn't sign us in as the impersonator" do diff --git a/spec/controllers/admin/spam_logs_controller_spec.rb b/spec/controllers/admin/spam_logs_controller_spec.rb index b51b303a714..520a4f6f9c5 100644 --- a/spec/controllers/admin/spam_logs_controller_spec.rb +++ b/spec/controllers/admin/spam_logs_controller_spec.rb @@ -14,7 +14,7 @@ describe Admin::SpamLogsController do it 'lists all spam logs' do get :index - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -22,14 +22,14 @@ describe Admin::SpamLogsController do it 'removes only the spam log when removing log' do expect { delete :destroy, id: first_spam.id }.to change { SpamLog.count }.by(-1) expect(User.find(user.id)).to be_truthy - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'removes user and his spam logs when removing the user' do delete :destroy, id: first_spam.id, remove_user: true expect(flash[:notice]).to eq "User #{user.username} was successfully removed." - expect(response.status).to eq(302) + expect(response).to have_http_status(302) expect(SpamLog.count).to eq(0) expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound) end diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 6caf37ddc2c..ab9aa65f7b9 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -17,7 +17,7 @@ describe Admin::UsersController do it 'deletes user' do delete :destroy, id: user.username, format: :json - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect { User.find(user.id) }.to raise_exception(ActiveRecord::RecordNotFound) end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index ff5b3916273..10824c20c87 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -44,7 +44,7 @@ describe ApplicationController do context "when the 'private_token' param is populated with the private token" do it "logs the user in" do get :index, private_token: user.private_token - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response.body).to eq("authenticated") end end @@ -54,7 +54,7 @@ describe ApplicationController do it "logs the user in" do @request.headers['PRIVATE-TOKEN'] = user.private_token get :index - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response.body).to eq("authenticated") end end @@ -80,7 +80,7 @@ describe ApplicationController do context "when the 'personal_access_token' param is populated with the personal access token" do it "logs the user in" do get :index, private_token: personal_access_token.token - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response.body).to eq('authenticated') end end @@ -89,7 +89,7 @@ describe ApplicationController do it "logs the user in" do @request.headers["PRIVATE-TOKEN"] = personal_access_token.token get :index - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response.body).to eq('authenticated') end end diff --git a/spec/controllers/autocomplete_controller_spec.rb b/spec/controllers/autocomplete_controller_spec.rb index 28cf804c1b2..60c654f622d 100644 --- a/spec/controllers/autocomplete_controller_spec.rb +++ b/spec/controllers/autocomplete_controller_spec.rb @@ -29,7 +29,7 @@ describe AutocompleteController do get(:users, project_id: 'unknown') end - it { expect(response.status).to eq(404) } + it { expect(response).to have_http_status(404) } end end @@ -58,7 +58,7 @@ describe AutocompleteController do get(:users, group_id: 'unknown') end - it { expect(response.status).to eq(404) } + it { expect(response).to have_http_status(404) } end end @@ -114,7 +114,7 @@ describe AutocompleteController do get(:users, project_id: project.id) end - it { expect(response.status).to eq(404) } + it { expect(response).to have_http_status(404) } end describe 'GET #users with unknown project' do @@ -122,7 +122,7 @@ describe AutocompleteController do get(:users, project_id: 'unknown') end - it { expect(response.status).to eq(404) } + it { expect(response).to have_http_status(404) } end describe 'GET #users with inaccessible group' do @@ -131,7 +131,7 @@ describe AutocompleteController do get(:users, group_id: user.namespace.id) end - it { expect(response.status).to eq(404) } + it { expect(response).to have_http_status(404) } end describe 'GET #users with no project' do diff --git a/spec/controllers/commit_controller_spec.rb b/spec/controllers/commit_controller_spec.rb index cf5c606c723..a3a3309e15e 100644 --- a/spec/controllers/commit_controller_spec.rb +++ b/spec/controllers/commit_controller_spec.rb @@ -155,7 +155,7 @@ describe Projects::CommitController do id: commit.id) expect(response).not_to be_success - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -204,7 +204,7 @@ describe Projects::CommitController do id: master_pickable_commit.id) expect(response).not_to be_success - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end diff --git a/spec/controllers/groups/group_members_controller_spec.rb b/spec/controllers/groups/group_members_controller_spec.rb index c8601341d54..ddc54108a7b 100644 --- a/spec/controllers/groups/group_members_controller_spec.rb +++ b/spec/controllers/groups/group_members_controller_spec.rb @@ -13,7 +13,7 @@ describe Groups::GroupMembersController do it 'renders index with group members' do get :index, group_id: group - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response).to render_template(:index) end end @@ -26,7 +26,7 @@ describe Groups::GroupMembersController do delete :destroy, group_id: group, id: 42 - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -48,7 +48,7 @@ describe Groups::GroupMembersController do delete :destroy, group_id: group, id: member - expect(response.status).to eq(403) + expect(response).to have_http_status(403) expect(group.users).to include group_user end end @@ -89,7 +89,7 @@ describe Groups::GroupMembersController do it 'returns 403' do delete :leave, group_id: group - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -118,7 +118,7 @@ describe Groups::GroupMembersController do it 'cannot removes himself from the group' do delete :leave, group_id: group - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -166,7 +166,7 @@ describe Groups::GroupMembersController do post :approve_access_request, group_id: group, id: 42 - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -188,7 +188,7 @@ describe Groups::GroupMembersController do post :approve_access_request, group_id: group, id: member - expect(response.status).to eq(403) + expect(response).to have_http_status(403) expect(group.users).not_to include group_requester end end diff --git a/spec/controllers/health_check_controller_spec.rb b/spec/controllers/health_check_controller_spec.rb index 0d8a68bb51a..56ecf2bb644 100644 --- a/spec/controllers/health_check_controller_spec.rb +++ b/spec/controllers/health_check_controller_spec.rb @@ -65,21 +65,21 @@ describe HealthCheckController do it 'supports passing the token in the header' do request.headers['TOKEN'] = token get :index - expect(response.status).to eq(500) + expect(response).to have_http_status(500) expect(response.content_type).to eq 'text/plain' expect(response.body).to include('The server is on fire') end it 'supports failure plaintest response' do get :index, token: token - expect(response.status).to eq(500) + expect(response).to have_http_status(500) expect(response.content_type).to eq 'text/plain' expect(response.body).to include('The server is on fire') end it 'supports failure json response' do get :index, token: token, format: :json - expect(response.status).to eq(500) + expect(response).to have_http_status(500) expect(response.content_type).to eq 'application/json' expect(json_response['healthy']).to be false expect(json_response['message']).to include('The server is on fire') @@ -87,7 +87,7 @@ describe HealthCheckController do it 'supports failure xml response' do get :index, token: token, format: :xml - expect(response.status).to eq(500) + expect(response).to have_http_status(500) expect(response.content_type).to eq 'application/xml' expect(xml_response['healthy']).to be false expect(xml_response['message']).to include('The server is on fire') @@ -95,7 +95,7 @@ describe HealthCheckController do it 'supports failure responses for specific checks' do get :index, token: token, checks: 'email', format: :json - expect(response.status).to eq(500) + expect(response).to have_http_status(500) expect(response.content_type).to eq 'application/json' expect(json_response['healthy']).to be false expect(json_response['message']).to include('Email is on fire') diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb index 3c6e54839b5..e478a253b3f 100644 --- a/spec/controllers/invites_controller_spec.rb +++ b/spec/controllers/invites_controller_spec.rb @@ -15,7 +15,7 @@ describe InvitesController do get :accept, id: token member.reload - expect(response.status).to eq(302) + expect(response).to have_http_status(302) expect(member.user).to eq(user) expect(flash[:notice]).to include 'You have been granted' end @@ -26,7 +26,7 @@ describe InvitesController do get :decline, id: token expect{member.reload}.to raise_error ActiveRecord::RecordNotFound - expect(response.status).to eq(302) + expect(response).to have_http_status(302) expect(flash[:notice]).to include 'You have declined the invitation to join' end end diff --git a/spec/controllers/namespaces_controller_spec.rb b/spec/controllers/namespaces_controller_spec.rb index 27e9afe582e..2b334ed1172 100644 --- a/spec/controllers/namespaces_controller_spec.rb +++ b/spec/controllers/namespaces_controller_spec.rb @@ -86,7 +86,7 @@ describe NamespacesController do it "responds with status 404" do get :show, id: group.path - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -102,7 +102,7 @@ describe NamespacesController do it "responds with status 404" do get :show, id: "doesntexist" - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end diff --git a/spec/controllers/notification_settings_controller_spec.rb b/spec/controllers/notification_settings_controller_spec.rb index 15d155833b4..6be9489edb2 100644 --- a/spec/controllers/notification_settings_controller_spec.rb +++ b/spec/controllers/notification_settings_controller_spec.rb @@ -60,7 +60,7 @@ describe NotificationSettingsController do project: { id: private_project.id }, notification_setting: { level: :participating } - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -118,7 +118,7 @@ describe NotificationSettingsController do id: notification_setting, notification_setting: { level: :participating } - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/controllers/oauth/applications_controller_spec.rb b/spec/controllers/oauth/applications_controller_spec.rb index af378304893..552899eb36c 100644 --- a/spec/controllers/oauth/applications_controller_spec.rb +++ b/spec/controllers/oauth/applications_controller_spec.rb @@ -12,7 +12,7 @@ describe Oauth::ApplicationsController do it 'shows list of applications' do get :index - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'redirects back to profile page if OAuth applications are disabled' do @@ -21,7 +21,7 @@ describe Oauth::ApplicationsController do get :index - expect(response.status).to eq(302) + expect(response).to have_http_status(302) expect(response).to redirect_to(profile_path) end end diff --git a/spec/controllers/profiles/accounts_controller_spec.rb b/spec/controllers/profiles/accounts_controller_spec.rb index 4eafc11abaa..2dc9adfd60c 100644 --- a/spec/controllers/profiles/accounts_controller_spec.rb +++ b/spec/controllers/profiles/accounts_controller_spec.rb @@ -13,7 +13,7 @@ describe Profiles::AccountsController do delete :unlink, provider: 'saml' updated_user = User.find(user.id) - expect(response.status).to eq(302) + expect(response).to have_http_status(302) expect(updated_user.identities.size).to eq(1) expect(updated_user.identities).to include(identity) end diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index c4b4a888b4e..f59d4937157 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -103,7 +103,7 @@ describe Projects::BranchesController do namespace_id: project.namespace.to_param, project_id: project.to_param - expect(response.status).to eq(303) + expect(response).to have_http_status(303) end end @@ -121,24 +121,24 @@ describe Projects::BranchesController do context "valid branch name, valid source" do let(:branch) { "feature" } - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(200) } end context "valid branch name with unencoded slashes" do let(:branch) { "improve/awesome" } - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(200) } end context "valid branch name with encoded slashes" do let(:branch) { "improve%2Fawesome" } - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(200) } end context "invalid branch name, valid ref" do let(:branch) { "no-branch" } - it { expect(response.status).to eq(404) } + it { expect(response).to have_http_status(404) } end end end diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index cbaa3e0b7b2..7cf09fa4a4a 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -14,7 +14,7 @@ describe Projects::IssuesController do it "returns index" do get :index, namespace_id: project.namespace.path, project_id: project.path - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "return 301 if request path doesn't match project path" do @@ -28,7 +28,7 @@ describe Projects::IssuesController do project.save get :index, namespace_id: project.namespace.path, project_id: project.path - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "returns 404 when external issue tracker is enabled" do @@ -36,7 +36,7 @@ describe Projects::IssuesController do allow(project).to receive(:default_issues_tracker?).and_return(false) get :index, namespace_id: project.namespace.path, project_id: project.path - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -248,7 +248,7 @@ describe Projects::IssuesController do before { sign_in(user) } it "rejects a developer to destroy an issue" do delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: issue.iid - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -262,7 +262,7 @@ describe Projects::IssuesController do it "deletes the issue" do delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: issue.iid - expect(response.status).to eq(302) + expect(response).to have_http_status(302) expect(controller).to set_flash[:notice].to(/The issue was successfully deleted\./).now end end @@ -280,7 +280,7 @@ describe Projects::IssuesController do project_id: project.path, id: issue.iid, name: "thumbsup") end.to change { issue.award_emoji.count }.by(1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 64eefd71918..74c050f48f1 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -272,7 +272,7 @@ describe Projects::MergeRequestsController do it "denies access to users unless they're admin or project owner" do delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: merge_request.iid - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end context "when the user is owner" do @@ -285,7 +285,7 @@ describe Projects::MergeRequestsController do it "deletes the merge request" do delete :destroy, namespace_id: project.namespace.path, project_id: project.path, id: merge_request.iid - expect(response.status).to eq(302) + expect(response).to have_http_status(302) expect(controller).to set_flash[:notice].to(/The merge request was successfully deleted\./).now end end diff --git a/spec/controllers/projects/notes_controller_spec.rb b/spec/controllers/projects/notes_controller_spec.rb index 00bc38b6071..75590c1ed4f 100644 --- a/spec/controllers/projects/notes_controller_spec.rb +++ b/spec/controllers/projects/notes_controller_spec.rb @@ -18,7 +18,7 @@ describe Projects::NotesController do project_id: project.path, id: note.id, name: "thumbsup") end.to change { note.award_emoji.count }.by(1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "removes the already awarded emoji" do @@ -30,7 +30,7 @@ describe Projects::NotesController do project_id: project.path, id: note.id, name: "thumbsup") end.to change { AwardEmoji.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end diff --git a/spec/controllers/projects/project_members_controller_spec.rb b/spec/controllers/projects/project_members_controller_spec.rb index e5e750c855f..29aaceb2302 100644 --- a/spec/controllers/projects/project_members_controller_spec.rb +++ b/spec/controllers/projects/project_members_controller_spec.rb @@ -58,7 +58,7 @@ describe Projects::ProjectMembersController do get :index, namespace_id: project.namespace, project_id: project end - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(200) } end end @@ -71,7 +71,7 @@ describe Projects::ProjectMembersController do project_id: project, id: 42 - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -94,7 +94,7 @@ describe Projects::ProjectMembersController do project_id: project, id: member - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(project.users).to include team_user end end @@ -139,7 +139,7 @@ describe Projects::ProjectMembersController do delete :leave, namespace_id: project.namespace, project_id: project - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -171,7 +171,7 @@ describe Projects::ProjectMembersController do delete :leave, namespace_id: project.namespace, project_id: project - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -224,7 +224,7 @@ describe Projects::ProjectMembersController do project_id: project, id: 42 - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -247,7 +247,7 @@ describe Projects::ProjectMembersController do project_id: project, id: member - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(project.users).not_to include team_requester end end diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb index 33c35161da3..48f799d8ca1 100644 --- a/spec/controllers/projects/raw_controller_spec.rb +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -13,7 +13,7 @@ describe Projects::RawController do project_id: public_project.to_param, id: id) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8') expect(response.header['Content-Disposition']). to eq("inline") @@ -30,7 +30,7 @@ describe Projects::RawController do project_id: public_project.to_param, id: id) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response.header['Content-Type']).to eq('image/jpeg') expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-blob:") end @@ -54,7 +54,7 @@ describe Projects::RawController do project_id: public_project.to_param, id: id) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -65,7 +65,7 @@ describe Projects::RawController do project_id: public_project.to_param, id: id) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/controllers/projects/repositories_controller_spec.rb b/spec/controllers/projects/repositories_controller_spec.rb index aad62cf20e3..ee905d11fb2 100644 --- a/spec/controllers/projects/repositories_controller_spec.rb +++ b/spec/controllers/projects/repositories_controller_spec.rb @@ -36,7 +36,7 @@ describe Projects::RepositoriesController do it "renders Not Found" do get :archive, namespace_id: project.namespace.path, project_id: project.path, ref: "master", format: "zip" - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/controllers/projects/snippets_controller_spec.rb b/spec/controllers/projects/snippets_controller_spec.rb index 0f32a30f18b..b8a28f43707 100644 --- a/spec/controllers/projects/snippets_controller_spec.rb +++ b/spec/controllers/projects/snippets_controller_spec.rb @@ -19,7 +19,7 @@ describe Projects::SnippetsController do get :index, namespace_id: project.namespace.path, project_id: project.path expect(assigns(:snippets)).not_to include(project_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -30,7 +30,7 @@ describe Projects::SnippetsController do get :index, namespace_id: project.namespace.path, project_id: project.path expect(assigns(:snippets)).to include(project_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -41,7 +41,7 @@ describe Projects::SnippetsController do get :index, namespace_id: project.namespace.path, project_id: project.path expect(assigns(:snippets)).to include(project_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -56,7 +56,7 @@ describe Projects::SnippetsController do it 'responds with status 404' do get action, namespace_id: project.namespace.path, project_id: project.path, id: project_snippet.to_param - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -67,7 +67,7 @@ describe Projects::SnippetsController do get action, namespace_id: project.namespace.path, project_id: project.path, id: project_snippet.to_param expect(assigns(:snippet)).to eq(project_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -78,7 +78,7 @@ describe Projects::SnippetsController do get action, namespace_id: project.namespace.path, project_id: project.path, id: project_snippet.to_param expect(assigns(:snippet)).to eq(project_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -88,7 +88,7 @@ describe Projects::SnippetsController do it 'responds with status 404' do get action, namespace_id: project.namespace.path, project_id: project.path, id: 42 - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -98,7 +98,7 @@ describe Projects::SnippetsController do it 'responds with status 404' do get action, namespace_id: project.namespace.path, project_id: project.path, id: 42 - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/controllers/projects/todo_controller_spec.rb b/spec/controllers/projects/todo_controller_spec.rb index 40a3403b660..5a8bba28594 100644 --- a/spec/controllers/projects/todo_controller_spec.rb +++ b/spec/controllers/projects/todo_controller_spec.rb @@ -22,7 +22,7 @@ describe Projects::TodosController do issuable_type: 'issue') end.to change { user.todos.count }.by(1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -36,7 +36,7 @@ describe Projects::TodosController do issuable_type: 'issue') end.to change { user.todos.count }.by(0) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should not create todo for issue when user not logged in' do @@ -47,7 +47,7 @@ describe Projects::TodosController do issuable_type: 'issue') end.to change { user.todos.count }.by(0) - expect(response.status).to eq(302) + expect(response).to have_http_status(302) end end end @@ -69,7 +69,7 @@ describe Projects::TodosController do issuable_type: 'merge_request') end.to change { user.todos.count }.by(1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -83,7 +83,7 @@ describe Projects::TodosController do issuable_type: 'merge_request') end.to change { user.todos.count }.by(0) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should not create todo for merge request user has no access to' do @@ -94,7 +94,7 @@ describe Projects::TodosController do issuable_type: 'merge_request') end.to change { user.todos.count }.by(0) - expect(response.status).to eq(302) + expect(response).to have_http_status(302) end end end diff --git a/spec/controllers/projects/tree_controller_spec.rb b/spec/controllers/projects/tree_controller_spec.rb index e74731c9ed8..4e3a2bdb19e 100644 --- a/spec/controllers/projects/tree_controller_spec.rb +++ b/spec/controllers/projects/tree_controller_spec.rb @@ -64,7 +64,7 @@ describe Projects::TreeController do context "valid SHA commit ID with path" do let(:id) { '6d39438/.gitignore' } - it { expect(response.status).to eq(302) } + it { expect(response).to have_http_status(302) } end end diff --git a/spec/controllers/projects/uploads_controller_spec.rb b/spec/controllers/projects/uploads_controller_spec.rb index 93c4494c660..0893ee89f6a 100644 --- a/spec/controllers/projects/uploads_controller_spec.rb +++ b/spec/controllers/projects/uploads_controller_spec.rb @@ -18,7 +18,7 @@ describe Projects::UploadsController do namespace_id: project.namespace.to_param, project_id: project.to_param, format: :json - expect(response.status).to eq(422) + expect(response).to have_http_status(422) end end @@ -79,7 +79,7 @@ describe Projects::UploadsController do it "responds with status 200" do go - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -87,7 +87,7 @@ describe Projects::UploadsController do it "responds with status 404" do go - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -106,7 +106,7 @@ describe Projects::UploadsController do it "responds with status 200" do go - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -114,7 +114,7 @@ describe Projects::UploadsController do it "responds with status 404" do go - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -140,7 +140,7 @@ describe Projects::UploadsController do it "responds with status 200" do go - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -192,7 +192,7 @@ describe Projects::UploadsController do it "responds with status 200" do go - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -224,7 +224,7 @@ describe Projects::UploadsController do it "responds with status 200" do go - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -232,7 +232,7 @@ describe Projects::UploadsController do it "responds with status 404" do go - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -253,7 +253,7 @@ describe Projects::UploadsController do it "responds with status 200" do go - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -261,7 +261,7 @@ describe Projects::UploadsController do it "responds with status 404" do go - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -270,7 +270,7 @@ describe Projects::UploadsController do it "responds with status 404" do go - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 146b2c2e131..d60579030c0 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -77,7 +77,7 @@ describe ProjectsController do get :show, namespace_id: public_project.namespace.path, id: public_project.path expect(assigns(:project)).to eq(public_project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -101,7 +101,7 @@ describe ProjectsController do get :show, namespace_id: public_project.namespace.path, id: public_project.path.upcase expect(assigns(:project)).to eq(other_project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -146,7 +146,7 @@ describe ProjectsController do expect(project.repository.path).to include(new_path) expect(assigns(:repository).path).to eq(project.repository.path) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -161,7 +161,7 @@ describe ProjectsController do delete :destroy, namespace_id: project.namespace.path, id: project.path expect { Project.find(orig_id) }.to raise_error(ActiveRecord::RecordNotFound) - expect(response.status).to eq(302) + expect(response).to have_http_status(302) expect(response).to redirect_to(dashboard_projects_path) end end @@ -234,7 +234,7 @@ describe ProjectsController do delete(:remove_fork, namespace_id: project.namespace.to_param, id: project.to_param, format: :js) - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end diff --git a/spec/controllers/snippets_controller_spec.rb b/spec/controllers/snippets_controller_spec.rb index b3dcb52c500..2a89159c070 100644 --- a/spec/controllers/snippets_controller_spec.rb +++ b/spec/controllers/snippets_controller_spec.rb @@ -19,7 +19,7 @@ describe SnippetsController do it 'responds with status 404' do get :show, id: other_personal_snippet.to_param - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -28,7 +28,7 @@ describe SnippetsController do get :show, id: personal_snippet.to_param expect(assigns(:snippet)).to eq(personal_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -54,7 +54,7 @@ describe SnippetsController do get :show, id: personal_snippet.to_param expect(assigns(:snippet)).to eq(personal_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -79,7 +79,7 @@ describe SnippetsController do get :show, id: personal_snippet.to_param expect(assigns(:snippet)).to eq(personal_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -88,7 +88,7 @@ describe SnippetsController do get :show, id: personal_snippet.to_param expect(assigns(:snippet)).to eq(personal_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -102,7 +102,7 @@ describe SnippetsController do it 'responds with status 404' do get :show, id: 'doesntexist' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -110,7 +110,7 @@ describe SnippetsController do it 'responds with status 404' do get :show, id: 'doesntexist' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -134,7 +134,7 @@ describe SnippetsController do it 'responds with status 404' do get :raw, id: other_personal_snippet.to_param - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -143,7 +143,7 @@ describe SnippetsController do get :raw, id: personal_snippet.to_param expect(assigns(:snippet)).to eq(personal_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -169,7 +169,7 @@ describe SnippetsController do get :raw, id: personal_snippet.to_param expect(assigns(:snippet)).to eq(personal_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -194,7 +194,7 @@ describe SnippetsController do get :raw, id: personal_snippet.to_param expect(assigns(:snippet)).to eq(personal_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -203,7 +203,7 @@ describe SnippetsController do get :raw, id: personal_snippet.to_param expect(assigns(:snippet)).to eq(personal_snippet) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -217,7 +217,7 @@ describe SnippetsController do it 'responds with status 404' do get :raw, id: 'doesntexist' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -225,7 +225,7 @@ describe SnippetsController do it 'responds with status 404' do get :raw, id: 'doesntexist' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb index 73858e6f063..69124ab06bf 100644 --- a/spec/controllers/uploads_controller_spec.rb +++ b/spec/controllers/uploads_controller_spec.rb @@ -26,7 +26,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "user", mounted_as: "avatar", id: user.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -35,7 +35,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "user", mounted_as: "avatar", id: user.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -52,7 +52,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -64,7 +64,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -109,7 +109,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -118,7 +118,7 @@ describe UploadsController do it "responds with status 404" do get :show, model: "project", mounted_as: "avatar", id: project.id, filename: "image.png" - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -133,7 +133,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -145,7 +145,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -181,7 +181,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -190,7 +190,7 @@ describe UploadsController do it "responds with status 404" do get :show, model: "group", mounted_as: "avatar", id: group.id, filename: "image.png" - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -210,7 +210,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -222,7 +222,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -267,7 +267,7 @@ describe UploadsController do it "responds with status 200" do get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -276,7 +276,7 @@ describe UploadsController do it "responds with status 404" do get :show, model: "note", mounted_as: "attachment", id: note.id, filename: "image.png" - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index c61ec174665..8d6f486efdd 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -33,7 +33,7 @@ describe UsersController do it 'renders the show template' do get :show, username: user.username - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response).to render_template('show') end end @@ -47,7 +47,7 @@ describe UsersController do context 'when logged out' do it 'renders 404' do get :show, username: user.username - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -56,7 +56,7 @@ describe UsersController do it 'renders show' do get :show, username: user.username - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response).to render_template('show') end end @@ -121,7 +121,7 @@ describe UsersController do context 'format html' do it 'renders snippets page' do get :snippets, username: user.username - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response).to render_template('show') end end @@ -129,7 +129,7 @@ describe UsersController do context 'format json' do it 'response with snippets json data' do get :snippets, username: user.username, format: :json - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(JSON.parse(response.body)).to have_key('html') end end diff --git a/spec/features/admin/admin_system_info_spec.rb b/spec/features/admin/admin_system_info_spec.rb new file mode 100644 index 00000000000..dbc1d829b67 --- /dev/null +++ b/spec/features/admin/admin_system_info_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe 'Admin System Info' do + before do + login_as :admin + end + + describe 'GET /admin/system_info' do + it 'shows system info page' do + visit admin_system_info_path + + expect(page).to have_content 'CPU' + expect(page).to have_content 'Memory' + expect(page).to have_content 'Disk' + end + end +end diff --git a/spec/features/groups/members/user_requests_access_spec.rb b/spec/features/groups/members/user_requests_access_spec.rb index 1ea607cbca0..4944301c938 100644 --- a/spec/features/groups/members/user_requests_access_spec.rb +++ b/spec/features/groups/members/user_requests_access_spec.rb @@ -4,6 +4,7 @@ feature 'Groups > Members > User requests access', feature: true do let(:user) { create(:user) } let(:owner) { create(:user) } let(:group) { create(:group, :public) } + let!(:project) { create(:project, :private, namespace: group) } background do group.add_owner(owner) @@ -24,6 +25,20 @@ feature 'Groups > Members > User requests access', feature: true do expect(page).not_to have_content 'Leave Group' end + scenario 'user does not see private projects' do + perform_enqueued_jobs { click_link 'Request Access' } + + expect(page).not_to have_content project.name + end + + scenario 'user does not see group in the Dashboard > Groups page' do + perform_enqueued_jobs { click_link 'Request Access' } + + visit dashboard_groups_path + + expect(page).not_to have_content group.name + end + scenario 'user is not listed in the group members page' do click_link 'Request Access' diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb index 1620eb6c60a..364532e94e3 100644 --- a/spec/lib/gitlab/highlight_spec.rb +++ b/spec/lib/gitlab/highlight_spec.rb @@ -4,6 +4,7 @@ describe Gitlab::Highlight, lib: true do include RepoHelpers let(:project) { create(:project) } + let(:repository) { project.repository } let(:commit) { project.commit(sample_commit.id) } describe '.highlight_lines' do @@ -18,4 +19,30 @@ describe Gitlab::Highlight, lib: true do end end + describe 'custom highlighting from .gitattributes' do + let(:branch) { 'gitattributes' } + let(:blob) { repository.blob_at_branch(branch, path) } + + let(:highlighter) do + Gitlab::Highlight.new(blob.path, blob.data, repository: repository) + end + + before { project.change_head('gitattributes') } + + describe 'basic language selection' do + let(:path) { 'custom-highlighting/test.gitlab-custom' } + it 'highlights as ruby' do + expect(highlighter.lexer.tag).to eq 'ruby' + end + end + + describe 'cgi options' do + let(:path) { 'custom-highlighting/test.gitlab-cgi' } + + it 'highlights as json with erb' do + expect(highlighter.lexer.tag).to eq 'erb' + expect(highlighter.lexer.parent.tag).to eq 'json' + end + end + end end diff --git a/spec/lib/gitlab/metrics/system_spec.rb b/spec/lib/gitlab/metrics/system_spec.rb index d6ae54e25e8..cf0e282c2fb 100644 --- a/spec/lib/gitlab/metrics/system_spec.rb +++ b/spec/lib/gitlab/metrics/system_spec.rb @@ -28,8 +28,20 @@ describe Gitlab::Metrics::System do end describe '.cpu_time' do - it 'returns a Fixnum' do - expect(described_class.cpu_time).to be_an_instance_of(Fixnum) + it 'returns a Float' do + expect(described_class.cpu_time).to be_an_instance_of(Float) + end + end + + describe '.real_time' do + it 'returns a Float' do + expect(described_class.real_time).to be_an_instance_of(Float) + end + end + + describe '.monotonic_time' do + it 'returns a Float' do + expect(described_class.monotonic_time).to be_an_instance_of(Float) end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 53c8408633c..d305cd9ff1e 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -63,6 +63,27 @@ describe Project, models: true do expect(project2).not_to be_valid expect(project2.errors[:limit_reached].first).to match(/Personal project creation is not allowed/) end + + describe 'wiki path conflict' do + context "when the new path has been used by the wiki of other Project" do + it 'should have an error on the name attribute' do + new_project = build_stubbed(:project, namespace_id: project.namespace_id, path: "#{project.path}.wiki") + + expect(new_project).not_to be_valid + expect(new_project.errors[:name].first).to eq('has already been taken') + end + end + + context "when the new wiki path has been used by the path of other Project" do + it 'should have an error on the name attribute' do + project_with_wiki_suffix = create(:project, path: 'foo.wiki') + new_project = build_stubbed(:project, namespace_id: project_with_wiki_suffix.namespace_id, path: 'foo') + + expect(new_project).not_to be_valid + expect(new_project.errors[:name].first).to eq('has already been taken') + end + end + end end describe 'default_scope' do diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index 789816bf2c7..0621c6a06ce 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -72,7 +72,7 @@ describe Snippet, models: true do end end - describe '#search_code' do + describe '.search_code' do let(:snippet) { create(:snippet, content: 'class Foo; end') } it 'returns snippets with matching content' do @@ -88,6 +88,46 @@ describe Snippet, models: true do end end + describe '.accessible_to' do + let(:author) { create(:author) } + let(:project) { create(:empty_project) } + + let!(:public_snippet) { create(:snippet, :public) } + let!(:internal_snippet) { create(:snippet, :internal) } + let!(:private_snippet) { create(:snippet, :private, author: author) } + + let!(:project_public_snippet) { create(:snippet, :public, project: project) } + let!(:project_internal_snippet) { create(:snippet, :internal, project: project) } + let!(:project_private_snippet) { create(:snippet, :private, project: project) } + + it 'returns only public snippets when user is blank' do + expect(described_class.accessible_to(nil)).to match_array [public_snippet, project_public_snippet] + end + + it 'returns only public, and internal snippets for regular users' do + user = create(:user) + + expect(described_class.accessible_to(user)).to match_array [public_snippet, internal_snippet, project_public_snippet, project_internal_snippet] + end + + it 'returns public, internal snippets and project private snippets for project members' do + member = create(:user) + project.team << [member, :developer] + + expect(described_class.accessible_to(member)).to match_array [public_snippet, internal_snippet, project_public_snippet, project_internal_snippet, project_private_snippet] + end + + it 'returns private snippets where the user is the author' do + expect(described_class.accessible_to(author)).to match_array [public_snippet, internal_snippet, private_snippet, project_public_snippet, project_internal_snippet] + end + + it 'returns all snippets when for admins' do + admin = create(:admin) + + expect(described_class.accessible_to(admin)).to match_array [public_snippet, internal_snippet, private_snippet, project_public_snippet, project_internal_snippet, project_private_snippet] + end + end + describe '#participants' do let(:project) { create(:project, :public) } let(:snippet) { create(:snippet, content: 'foo', project: project) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 73bee535fe3..328254ed56b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -31,6 +31,26 @@ describe User, models: true do it { is_expected.to have_many(:spam_logs).dependent(:destroy) } it { is_expected.to have_many(:todos).dependent(:destroy) } it { is_expected.to have_many(:award_emoji).dependent(:destroy) } + + describe '#group_members' do + it 'does not include group memberships for which user is a requester' do + user = create(:user) + group = create(:group, :public) + group.request_access(user) + + expect(user.group_members).to be_empty + end + end + + describe '#project_members' do + it 'does not include project memberships for which user is a requester' do + user = create(:user) + project = create(:project, :public) + project.request_access(user) + + expect(user.project_members).to be_empty + end + end end describe 'validations' do diff --git a/spec/requests/api/award_emoji_spec.rb b/spec/requests/api/award_emoji_spec.rb index 2e65e7f1920..ed78d582bd0 100644 --- a/spec/requests/api/award_emoji_spec.rb +++ b/spec/requests/api/award_emoji_spec.rb @@ -17,7 +17,7 @@ describe API::API, api: true do it "returns an array of award_emoji" do get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['name']).to eq(award_emoji.name) end @@ -25,7 +25,7 @@ describe API::API, api: true do it "should return a 404 error when issue id not found" do get api("/projects/#{project.id}/issues/12345/award_emoji", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -33,7 +33,7 @@ describe API::API, api: true do it "returns an array of award_emoji" do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['name']).to eq(downvote.name) end @@ -45,7 +45,7 @@ describe API::API, api: true do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji", user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -56,7 +56,7 @@ describe API::API, api: true do it 'returns an array of award emoji' do get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['name']).to eq(rocket.name) end @@ -68,7 +68,7 @@ describe API::API, api: true do it "returns the award emoji" do get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/#{award_emoji.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(award_emoji.name) expect(json_response['awardable_id']).to eq(issue.id) expect(json_response['awardable_type']).to eq("Issue") @@ -77,7 +77,7 @@ describe API::API, api: true do it "returns a 404 error if the award is not found" do get api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/12345", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -85,7 +85,7 @@ describe API::API, api: true do it 'returns the award emoji' do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji/#{downvote.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(downvote.name) expect(json_response['awardable_id']).to eq(merge_request.id) expect(json_response['awardable_type']).to eq("MergeRequest") @@ -98,7 +98,7 @@ describe API::API, api: true do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji/#{downvote.id}", user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -109,7 +109,7 @@ describe API::API, api: true do it 'returns an award emoji' do get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji/#{rocket.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).not_to be_an Array expect(json_response['name']).to eq(rocket.name) end @@ -120,7 +120,7 @@ describe API::API, api: true do it "creates a new award emoji" do post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user), name: 'blowfish' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['name']).to eq('blowfish') expect(json_response['user']['username']).to eq(user.username) end @@ -128,13 +128,13 @@ describe API::API, api: true do it "should return a 400 bad request error if the name is not given" do post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 401 unauthorized error if the user is not authenticated" do post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji"), name: 'thumbsup' - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -145,7 +145,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user), name: 'rocket' end.to change { note.award_emoji.count }.from(0).to(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['user']['username']).to eq(user.username) end end @@ -157,13 +157,13 @@ describe API::API, api: true do delete api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/#{award_emoji.id}", user) end.to change { issue.award_emoji.count }.from(1).to(0) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'returns a 404 error when the award emoji can not be found' do delete api("/projects/#{project.id}/issues/#{issue.id}/award_emoji/12345", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -173,13 +173,13 @@ describe API::API, api: true do delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/award_emoji/#{downvote.id}", user) end.to change { merge_request.award_emoji.count }.from(1).to(0) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'returns a 404 error when note id not found' do delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes/12345", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -192,7 +192,7 @@ describe API::API, api: true do delete api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji/#{rocket.id}", user) end.to change { note.award_emoji.count }.from(1).to(0) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index 55582aa53d2..b11ca26ee68 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -17,7 +17,7 @@ describe API::API, api: true do project.repository.expire_cache get api("/projects/#{project.id}/repository/branches", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array branch_names = json_response.map { |x| x['name'] } expect(branch_names).to match_array(project.repository.branch_names) @@ -27,7 +27,7 @@ describe API::API, api: true do describe "GET /projects/:id/repository/branches/:branch" do it "should return the branch information for a single branch" do get api("/projects/#{project.id}/repository/branches/#{branch_name}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(branch_name) expect(json_response['commit']['id']).to eq(branch_sha) @@ -36,19 +36,19 @@ describe API::API, api: true do it "should return a 403 error if guest" do get api("/projects/#{project.id}/repository/branches", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it "should return a 404 error if branch is not available" do get api("/projects/#{project.id}/repository/branches/unknown", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end describe "PUT /projects/:id/repository/branches/:branch/protect" do it "should protect a single branch" do put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(branch_name) expect(json_response['commit']['id']).to eq(branch_sha) @@ -57,25 +57,25 @@ describe API::API, api: true do it "should return a 404 error if branch not found" do put api("/projects/#{project.id}/repository/branches/unknown/protect", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return a 403 error if guest" do put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it "should return success when protect branch again" do put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end describe "PUT /projects/:id/repository/branches/:branch/unprotect" do it "should unprotect a single branch" do put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(branch_name) expect(json_response['commit']['id']).to eq(branch_sha) @@ -84,13 +84,13 @@ describe API::API, api: true do it "should return success when unprotect branch" do put api("/projects/#{project.id}/repository/branches/unknown/unprotect", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return success when unprotect branch again" do put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user) put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -100,7 +100,7 @@ describe API::API, api: true do branch_name: 'feature1', ref: branch_sha - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['name']).to eq('feature1') expect(json_response['commit']['id']).to eq(branch_sha) @@ -110,14 +110,14 @@ describe API::API, api: true do post api("/projects/#{project.id}/repository/branches", user2), branch_name: branch_name, ref: branch_sha - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it 'should return 400 if branch name is invalid' do post api("/projects/#{project.id}/repository/branches", user), branch_name: 'new design', ref: branch_sha - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('Branch name is invalid') end @@ -125,12 +125,12 @@ describe API::API, api: true do post api("/projects/#{project.id}/repository/branches", user), branch_name: 'new_design1', ref: branch_sha - expect(response.status).to eq(201) + expect(response).to have_http_status(201) post api("/projects/#{project.id}/repository/branches", user), branch_name: 'new_design1', ref: branch_sha - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('Branch already exists') end @@ -138,7 +138,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/repository/branches", user), branch_name: 'new_design3', ref: 'foo' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('Invalid reference name') end end @@ -150,25 +150,25 @@ describe API::API, api: true do it "should remove branch" do delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['branch_name']).to eq(branch_name) end it 'should return 404 if branch not exists' do delete api("/projects/#{project.id}/repository/branches/foobar", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should remove protected branch" do project.protected_branches.create(name: branch_name) delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user) - expect(response.status).to eq(405) + expect(response).to have_http_status(405) expect(json_response['message']).to eq('Protected branch cant be removed') end it "should not remove HEAD branch" do delete api("/projects/#{project.id}/repository/branches/master", user) - expect(response.status).to eq(405) + expect(response).to have_http_status(405) expect(json_response['message']).to eq('Cannot remove HEAD branch') end end diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb index 47e9253a10c..f5b39c3d698 100644 --- a/spec/requests/api/builds_spec.rb +++ b/spec/requests/api/builds_spec.rb @@ -19,7 +19,7 @@ describe API::API, api: true do context 'authorized user' do it 'should return project builds' do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array end @@ -32,7 +32,7 @@ describe API::API, api: true do let(:query) { 'scope=pending' } it do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array end end @@ -41,7 +41,7 @@ describe API::API, api: true do let(:query) { 'scope[0]=pending&scope[1]=running' } it do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array end end @@ -49,7 +49,7 @@ describe API::API, api: true do context 'respond 400 when scope contains invalid state' do let(:query) { 'scope[0]=pending&scope[1]=unknown_status' } - it { expect(response.status).to eq(400) } + it { expect(response).to have_http_status(400) } end end @@ -57,29 +57,66 @@ describe API::API, api: true do let(:api_user) { nil } it 'should not return project builds' do - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end describe 'GET /projects/:id/repository/commits/:sha/builds' do - before do - project.ensure_pipeline(pipeline.sha, 'master') - get api("/projects/#{project.id}/repository/commits/#{pipeline.sha}/builds", api_user) - end + context 'when commit does not exist in repository' do + before do + get api("/projects/#{project.id}/repository/commits/1a271fd1/builds", api_user) + end - context 'authorized user' do - it 'should return project builds for specific commit' do - expect(response.status).to eq(200) - expect(json_response).to be_an Array + it 'responds with 404' do + expect(response).to have_http_status(404) end end - context 'unauthorized user' do - let(:api_user) { nil } + context 'when commit exists in repository' do + context 'when user is authorized' do + context 'when pipeline has builds' do + before do + create(:ci_pipeline, project: project, sha: project.commit.id) + create(:ci_build, pipeline: pipeline) + create(:ci_build) + + get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", api_user) + end + + it 'should return project builds for specific commit' do + expect(response).to have_http_status(200) + expect(json_response).to be_an Array + expect(json_response.size).to eq 2 + end + end - it 'should not return project builds' do - expect(response.status).to eq(401) + context 'when pipeline has no builds' do + before do + branch_head = project.commit('feature').id + get api("/projects/#{project.id}/repository/commits/#{branch_head}/builds", api_user) + end + + it 'returns an empty array' do + expect(response).to have_http_status(200) + expect(json_response).to be_an Array + expect(json_response).to be_empty + end + end + end + + context 'when user is not authorized' do + before do + create(:ci_pipeline, project: project, sha: project.commit.id) + create(:ci_build, pipeline: pipeline) + + get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", nil) + end + + it 'should not return project builds' do + expect(response).to have_http_status(401) + expect(json_response.except('message')).to be_empty + end end end end @@ -89,7 +126,7 @@ describe API::API, api: true do context 'authorized user' do it 'should return specific build data' do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq('test') end end @@ -98,7 +135,7 @@ describe API::API, api: true do let(:api_user) { nil } it 'should not return specific build data' do - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -116,7 +153,7 @@ describe API::API, api: true do end it 'should return specific build artifacts' do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response.headers).to include(download_headers) end end @@ -125,13 +162,13 @@ describe API::API, api: true do let(:api_user) { nil } it 'should not return specific build artifacts' do - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end it 'should not return build artifacts if not uploaded' do - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -142,7 +179,7 @@ describe API::API, api: true do context 'authorized user' do it 'should return specific build trace' do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response.body).to eq(build.trace) end end @@ -151,7 +188,7 @@ describe API::API, api: true do let(:api_user) { nil } it 'should not return specific build trace' do - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -162,7 +199,7 @@ describe API::API, api: true do context 'authorized user' do context 'user with :update_build persmission' do it 'should cancel running or pending build' do - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(project.builds.first.status).to eq('canceled') end end @@ -171,7 +208,7 @@ describe API::API, api: true do let(:api_user) { user2 } it 'should not cancel build' do - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end end @@ -180,7 +217,7 @@ describe API::API, api: true do let(:api_user) { nil } it 'should not cancel build' do - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -193,7 +230,7 @@ describe API::API, api: true do context 'authorized user' do context 'user with :update_build permission' do it 'should retry non-running build' do - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(project.builds.first.status).to eq('canceled') expect(json_response['status']).to eq('pending') end @@ -203,7 +240,7 @@ describe API::API, api: true do let(:api_user) { user2 } it 'should not retry build' do - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end end @@ -212,7 +249,7 @@ describe API::API, api: true do let(:api_user) { nil } it 'should not retry build' do - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end diff --git a/spec/requests/api/commit_statuses_spec.rb b/spec/requests/api/commit_statuses_spec.rb index 298cdbad329..6668f3543f6 100644 --- a/spec/requests/api/commit_statuses_spec.rb +++ b/spec/requests/api/commit_statuses_spec.rb @@ -41,7 +41,7 @@ describe API::CommitStatuses, api: true do before { get api(get_url, reporter) } it 'returns latest commit statuses' do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(statuses_id).to contain_exactly(status3.id, status4.id, status5.id, status6.id) @@ -54,7 +54,7 @@ describe API::CommitStatuses, api: true do before { get api(get_url, reporter), all: 1 } it 'returns all commit statuses' do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(statuses_id).to contain_exactly(status1.id, status2.id, @@ -67,7 +67,7 @@ describe API::CommitStatuses, api: true do before { get api(get_url, reporter), ref: 'develop' } it 'returns latest commit statuses for specific ref' do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(statuses_id).to contain_exactly(status3.id, status5.id) @@ -78,7 +78,7 @@ describe API::CommitStatuses, api: true do before { get api(get_url, reporter), name: 'coverage' } it 'return latest commit statuses for specific name' do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(statuses_id).to contain_exactly(status4.id, status5.id) @@ -101,7 +101,7 @@ describe API::CommitStatuses, api: true do before { get api(get_url, guest) } it "should not return project commits" do - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -109,7 +109,7 @@ describe API::CommitStatuses, api: true do before { get api(get_url) } it "should not return project commits" do - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -122,7 +122,7 @@ describe API::CommitStatuses, api: true do before { post api(post_url, developer), state: 'success' } it 'creates commit status' do - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['sha']).to eq(commit.id) expect(json_response['status']).to eq('success') expect(json_response['name']).to eq('default') @@ -141,7 +141,7 @@ describe API::CommitStatuses, api: true do end it 'creates commit status' do - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['sha']).to eq(commit.id) expect(json_response['status']).to eq('success') expect(json_response['name']).to eq('coverage') @@ -155,7 +155,7 @@ describe API::CommitStatuses, api: true do before { post api(post_url, developer), state: 'invalid' } it 'does not create commit status' do - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -163,7 +163,7 @@ describe API::CommitStatuses, api: true do before { post api(post_url, developer) } it 'does not create commit status' do - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -172,7 +172,7 @@ describe API::CommitStatuses, api: true do before { post api(post_url, developer), state: 'running' } it 'returns not found error' do - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -181,7 +181,7 @@ describe API::CommitStatuses, api: true do before { post api(post_url, reporter) } it 'should not create commit status' do - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -189,7 +189,7 @@ describe API::CommitStatuses, api: true do before { post api(post_url, guest) } it 'should not create commit status' do - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -197,7 +197,7 @@ describe API::CommitStatuses, api: true do before { post api(post_url) } it 'should not create commit status' do - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index 6fc38f537d3..5219c808791 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -19,7 +19,7 @@ describe API::API, api: true do it "should return project commits" do get api("/projects/#{project.id}/repository/commits", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['id']).to eq(project.repository.commit.id) @@ -29,7 +29,7 @@ describe API::API, api: true do context "unauthorized user" do it "should not return project commits" do get api("/projects/#{project.id}/repository/commits") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -63,7 +63,7 @@ describe API::API, api: true do it "should return an invalid parameter error message" do get api("/projects/#{project.id}/repository/commits?since=invalid-date", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to include "\"since\" must be a timestamp in ISO 8601 format" end end @@ -73,26 +73,26 @@ describe API::API, api: true do context "authorized user" do it "should return a commit by sha" do get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['id']).to eq(project.repository.commit.id) expect(json_response['title']).to eq(project.repository.commit.title) end it "should return a 404 error if not found" do get api("/projects/#{project.id}/repository/commits/invalid_sha", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return nil for commit without CI" do get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['status']).to be_nil end it "should return status for CI" do pipeline = project.ensure_pipeline(project.repository.commit.sha, 'master') get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['status']).to eq(pipeline.status) end end @@ -100,7 +100,7 @@ describe API::API, api: true do context "unauthorized user" do it "should not return the selected commit" do get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -111,7 +111,7 @@ describe API::API, api: true do it "should return the diff of the selected commit" do get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to be >= 1 @@ -120,14 +120,14 @@ describe API::API, api: true do it "should return a 404 error if invalid commit" do get api("/projects/#{project.id}/repository/commits/invalid_sha/diff", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end context "unauthorized user" do it "should not return the diff of the selected commit" do get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -136,7 +136,7 @@ describe API::API, api: true do context 'authorized user' do it 'should return merge_request comments' do get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) expect(json_response.first['note']).to eq('a comment on a commit') @@ -145,14 +145,14 @@ describe API::API, api: true do it 'should return a 404 error if merge_request_id not found' do get api("/projects/#{project.id}/repository/commits/1234ab/comments", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end context 'unauthorized user' do it 'should not return the diff of the selected commit' do get api("/projects/#{project.id}/repository/commits/1234ab/comments") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -161,7 +161,7 @@ describe API::API, api: true do context 'authorized user' do it 'should return comment' do post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['note']).to eq('My comment') expect(json_response['path']).to be_nil expect(json_response['line']).to be_nil @@ -170,7 +170,7 @@ describe API::API, api: true do it 'should return the inline comment' do post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment', path: project.repository.commit.diffs.first.new_path, line: 7, line_type: 'new' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['note']).to eq('My comment') expect(json_response['path']).to eq(project.repository.commit.diffs.first.new_path) expect(json_response['line']).to eq(7) @@ -179,19 +179,19 @@ describe API::API, api: true do it 'should return 400 if note is missing' do post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return 404 if note is attached to non existent commit' do post api("/projects/#{project.id}/repository/commits/1234ab/comments", user), note: 'My comment' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end context 'unauthorized user' do it 'should not return the diff of the selected commit' do post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end diff --git a/spec/requests/api/doorkeeper_access_spec.rb b/spec/requests/api/doorkeeper_access_spec.rb index 0afc3e79339..881b818b5e9 100644 --- a/spec/requests/api/doorkeeper_access_spec.rb +++ b/spec/requests/api/doorkeeper_access_spec.rb @@ -11,21 +11,21 @@ describe API::API, api: true do describe "when unauthenticated" do it "returns authentication success" do get api("/user"), access_token: token.token - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end describe "when token invalid" do it "returns authentication error" do get api("/user"), access_token: "123a" - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end describe "authorization by private token" do it "returns authentication success" do get api("/user", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index 8efa09f75fd..2e5448143d5 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -16,7 +16,7 @@ describe API::API, api: true do } get api("/projects/#{project.id}/repository/files", user), params - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['file_path']).to eq(file_path) expect(json_response['file_name']).to eq('popen.rb') expect(json_response['last_commit_id']).to eq('570e7b2abdd848b95f2f578043fc23bd6f6fd24d') @@ -25,7 +25,7 @@ describe API::API, api: true do it "should return a 400 bad request if no params given" do get api("/projects/#{project.id}/repository/files", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 404 if such file does not exist" do @@ -35,7 +35,7 @@ describe API::API, api: true do } get api("/projects/#{project.id}/repository/files", user), params - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -51,13 +51,13 @@ describe API::API, api: true do it "should create a new file in project repo" do post api("/projects/#{project.id}/repository/files", user), valid_params - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['file_path']).to eq('newfile.rb') end it "should return a 400 bad request if no params given" do post api("/projects/#{project.id}/repository/files", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 400 if editor fails to create file" do @@ -65,7 +65,7 @@ describe API::API, api: true do and_return(false) post api("/projects/#{project.id}/repository/files", user), valid_params - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -81,13 +81,13 @@ describe API::API, api: true do it "should update existing file in project repo" do put api("/projects/#{project.id}/repository/files", user), valid_params - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['file_path']).to eq(file_path) end it "should return a 400 bad request if no params given" do put api("/projects/#{project.id}/repository/files", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -102,20 +102,20 @@ describe API::API, api: true do it "should delete existing file in project repo" do delete api("/projects/#{project.id}/repository/files", user), valid_params - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['file_path']).to eq(file_path) end it "should return a 400 bad request if no params given" do delete api("/projects/#{project.id}/repository/files", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 400 if fails to create file" do allow_any_instance_of(Repository).to receive(:remove_file).and_return(false) delete api("/projects/#{project.id}/repository/files", user), valid_params - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -143,7 +143,7 @@ describe API::API, api: true do it "remains unchanged" do get api("/projects/#{project.id}/repository/files", user), get_params - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['file_path']).to eq(file_path) expect(json_response['file_name']).to eq(file_path) expect(json_response['content']).to eq(put_params[:content]) diff --git a/spec/requests/api/fork_spec.rb b/spec/requests/api/fork_spec.rb index fa94e03ec32..a9f5aa924b7 100644 --- a/spec/requests/api/fork_spec.rb +++ b/spec/requests/api/fork_spec.rb @@ -22,7 +22,7 @@ describe API::API, api: true do context 'when authenticated' do it 'should fork if user has sufficient access to project' do post api("/projects/fork/#{project.id}", user2) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['name']).to eq(project.name) expect(json_response['path']).to eq(project.path) expect(json_response['owner']['id']).to eq(user2.id) @@ -32,7 +32,7 @@ describe API::API, api: true do it 'should fork if user is admin' do post api("/projects/fork/#{project.id}", admin) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['name']).to eq(project.name) expect(json_response['path']).to eq(project.path) expect(json_response['owner']['id']).to eq(admin.id) @@ -42,20 +42,20 @@ describe API::API, api: true do it 'should fail on missing project access for the project to fork' do post api("/projects/fork/#{project.id}", user3) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Project Not Found') end it 'should fail if forked project exists in the user namespace' do post api("/projects/fork/#{project.id}", user) - expect(response.status).to eq(409) + expect(response).to have_http_status(409) expect(json_response['message']['name']).to eq(['has already been taken']) expect(json_response['message']['path']).to eq(['has already been taken']) end it 'should fail if project to fork from does not exist' do post api('/projects/fork/424242', user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Project Not Found') end end @@ -63,7 +63,7 @@ describe API::API, api: true do context 'when unauthenticated' do it 'should return authentication error' do post api("/projects/fork/#{project.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) expect(json_response['message']).to eq('401 Unauthorized') end end diff --git a/spec/requests/api/group_members_spec.rb b/spec/requests/api/group_members_spec.rb index 02553d0f8e2..52f9e7d4681 100644 --- a/spec/requests/api/group_members_spec.rb +++ b/spec/requests/api/group_members_spec.rb @@ -31,7 +31,7 @@ describe API::API, api: true do it "each user: should return an array of members groups of group3" do [owner, master, developer, reporter, guest].each do |user| get api("/groups/#{group_with_members.id}/members", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to eq(5) expect(json_response.find { |e| e['id'] == owner.id }['access_level']).to eq(GroupMember::OWNER) @@ -45,7 +45,7 @@ describe API::API, api: true do it 'users not part of the group should get access error' do get api("/groups/#{group_with_members.id}/members", stranger) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -54,7 +54,7 @@ describe API::API, api: true do context "when not a member of the group" do it "should not add guest as member of group_no_members when adding being done by person outside the group" do post api("/groups/#{group_no_members.id}/members", reporter), user_id: guest.id, access_level: GroupMember::MASTER - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -66,7 +66,7 @@ describe API::API, api: true do post api("/groups/#{group_no_members.id}/members", owner), user_id: new_user.id, access_level: GroupMember::MASTER end.to change { group_no_members.members.count }.by(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['name']).to eq(new_user.name) expect(json_response['access_level']).to eq(GroupMember::MASTER) end @@ -78,27 +78,27 @@ describe API::API, api: true do post api("/groups/#{group_with_members.id}/members", guest), user_id: new_user.id, access_level: GroupMember::MASTER end.not_to change { group_with_members.members.count } - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it "should return error if member already exists" do post api("/groups/#{group_with_members.id}/members", owner), user_id: master.id, access_level: GroupMember::MASTER - expect(response.status).to eq(409) + expect(response).to have_http_status(409) end it "should return a 400 error when user id is not given" do post api("/groups/#{group_no_members.id}/members", owner), access_level: GroupMember::MASTER - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 400 error when access level is not given" do post api("/groups/#{group_no_members.id}/members", owner), user_id: master.id - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 422 error when access level is not known" do post api("/groups/#{group_no_members.id}/members", owner), user_id: master.id, access_level: 1234 - expect(response.status).to eq(422) + expect(response).to have_http_status(422) end end end @@ -110,7 +110,7 @@ describe API::API, api: true do api("/groups/#{group_no_members.id}/members/#{developer.id}", owner), access_level: GroupMember::MASTER ) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -122,7 +122,7 @@ describe API::API, api: true do access_level: GroupMember::MASTER ) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) get api("/groups/#{group_with_members.id}/members", owner) json_reporter = json_response.find do |e| @@ -139,7 +139,7 @@ describe API::API, api: true do access_level: GroupMember::MASTER ) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) get api("/groups/#{group_with_members.id}/members", owner) json_developer = json_response.find do |e| @@ -153,7 +153,7 @@ describe API::API, api: true do put( api("/groups/#{group_with_members.id}/members/#{master.id}", owner) ) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return a 422 error when access level is not known' do @@ -161,7 +161,7 @@ describe API::API, api: true do api("/groups/#{group_with_members.id}/members/#{master.id}", owner), access_level: 1234 ) - expect(response.status).to eq(422) + expect(response).to have_http_status(422) end end end @@ -172,7 +172,7 @@ describe API::API, api: true do random_user = create(:user) delete api("/groups/#{group_with_members.id}/members/#{owner.id}", random_user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -182,17 +182,17 @@ describe API::API, api: true do delete api("/groups/#{group_with_members.id}/members/#{guest.id}", owner) end.to change { group_with_members.members.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return a 404 error when user id is not known" do delete api("/groups/#{group_with_members.id}/members/1328", owner) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should not allow guest to modify group members" do delete api("/groups/#{group_with_members.id}/members/#{master.id}", guest) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end end diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index 7ecefce80d6..04141a45031 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -23,14 +23,14 @@ describe API::API, api: true do context "when unauthenticated" do it "should return authentication error" do get api("/groups") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context "when authenticated as user" do it "normal user: should return an array of groups of user1" do get api("/groups", user1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['name']).to eq(group1.name) @@ -40,7 +40,7 @@ describe API::API, api: true do context "when authenticated as admin" do it "admin: should return an array of all groups" do get api("/groups", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) end @@ -51,51 +51,51 @@ describe API::API, api: true do context "when authenticated as user" do it "should return one of user1's groups" do get api("/groups/#{group1.id}", user1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) json_response['name'] == group1.name end it "should not return a non existing group" do get api("/groups/1328", user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should not return a group not attached to user1" do get api("/groups/#{group2.id}", user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end context "when authenticated as admin" do it "should return any existing group" do get api("/groups/#{group2.id}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(group2.name) end it "should not return a non existing group" do get api("/groups/1328", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end context 'when using group path in URL' do it 'should return any existing group' do get api("/groups/#{group1.path}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(group1.name) end it 'should not return a non existing group' do get api('/groups/unknown', admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should not return a group not attached to user1' do get api("/groups/#{group2.path}", user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -107,14 +107,14 @@ describe API::API, api: true do it 'updates the group' do put api("/groups/#{group1.id}", user1), name: new_group_name - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(new_group_name) end it 'returns 404 for a non existing group' do put api('/groups/1328', user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -122,7 +122,7 @@ describe API::API, api: true do it 'updates the group' do put api("/groups/#{group1.id}", admin), name: new_group_name - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(new_group_name) end end @@ -131,7 +131,7 @@ describe API::API, api: true do it 'does not updates the group' do put api("/groups/#{group1.id}", user2), name: new_group_name - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -139,7 +139,7 @@ describe API::API, api: true do it 'returns 404 when trying to update the group' do put api("/groups/#{group2.id}", user1), name: new_group_name - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -149,7 +149,7 @@ describe API::API, api: true do it "should return the group's projects" do get api("/groups/#{group1.id}/projects", user1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response.length).to eq(2) project_names = json_response.map { |proj| proj['name' ] } expect(project_names).to match_array([project1.name, project3.name]) @@ -157,13 +157,13 @@ describe API::API, api: true do it "should not return a non existing group" do get api("/groups/1328/projects", user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should not return a group not attached to user1" do get api("/groups/#{group2.id}/projects", user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should only return projects to which user has access" do @@ -171,7 +171,7 @@ describe API::API, api: true do get api("/groups/#{group1.id}/projects", user3) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response.length).to eq(1) expect(json_response.first['name']).to eq(project3.name) end @@ -180,14 +180,14 @@ describe API::API, api: true do context "when authenticated as admin" do it "should return any existing group" do get api("/groups/#{group2.id}/projects", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response.length).to eq(1) expect(json_response.first['name']).to eq(project2.name) end it "should not return a non existing group" do get api("/groups/1328/projects", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -195,20 +195,20 @@ describe API::API, api: true do it 'should return any existing group' do get api("/groups/#{group1.path}/projects", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) project_names = json_response.map { |proj| proj['name' ] } expect(project_names).to match_array([project1.name, project3.name]) end it 'should not return a non existing group' do get api('/groups/unknown/projects', admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should not return a group not attached to user1' do get api("/groups/#{group2.path}/projects", user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -217,30 +217,30 @@ describe API::API, api: true do context "when authenticated as user without group permissions" do it "should not create group" do post api("/groups", user1), attributes_for(:group) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end context "when authenticated as user with group permissions" do it "should create group" do post api("/groups", user3), attributes_for(:group) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end it "should not create group, duplicate" do post api("/groups", user3), { name: 'Duplicate Test', path: group2.path } - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(response.message).to eq("Bad Request") end it "should return 400 bad request error if name not given" do post api("/groups", user3), { path: group2.path } - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return 400 bad request error if path not given" do post api("/groups", user3), { name: 'test' } - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end end @@ -249,37 +249,37 @@ describe API::API, api: true do context "when authenticated as user" do it "should remove group" do delete api("/groups/#{group1.id}", user1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should not remove a group if not an owner" do user4 = create(:user) group1.add_master(user4) delete api("/groups/#{group1.id}", user3) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it "should not remove a non existing group" do delete api("/groups/1328", user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should not remove a group not attached to user1" do delete api("/groups/#{group2.id}", user1) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end context "when authenticated as admin" do it "should remove any existing group" do delete api("/groups/#{group2.id}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should not remove a non existing group" do delete api("/groups/1328", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -295,14 +295,14 @@ describe API::API, api: true do context "when authenticated as user" do it "should not transfer project to group" do post api("/groups/#{group1.id}/projects/#{project.id}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end context "when authenticated as admin" do it "should transfer project to group" do post api("/groups/#{group1.id}/projects/#{project.id}", admin) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end end end diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index 22802dd0e05..437c89c3577 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -11,7 +11,7 @@ describe API::API, api: true do it do get api("/internal/check"), secret_token: secret_token - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['api_version']).to eq(API::API.version) end end @@ -23,7 +23,7 @@ describe API::API, api: true do it do get api("/internal/broadcast_message"), secret_token: secret_token - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["message"]).to eq(broadcast_message.message) end end @@ -32,7 +32,7 @@ describe API::API, api: true do it do get api("/internal/broadcast_message"), secret_token: secret_token - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_empty end end @@ -42,7 +42,7 @@ describe API::API, api: true do it do get(api("/internal/discover"), key_id: key.id, secret_token: secret_token) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(user.name) end @@ -61,7 +61,7 @@ describe API::API, api: true do push(key, project_wiki) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_truthy end end @@ -70,7 +70,7 @@ describe API::API, api: true do it do pull(key, project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_truthy end end @@ -79,7 +79,7 @@ describe API::API, api: true do it do push(key, project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_truthy end end @@ -94,7 +94,7 @@ describe API::API, api: true do it do pull(key, project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_falsey end end @@ -103,7 +103,7 @@ describe API::API, api: true do it do push(key, project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_falsey end end @@ -120,7 +120,7 @@ describe API::API, api: true do it do pull(key, personal_project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_falsey end end @@ -129,7 +129,7 @@ describe API::API, api: true do it do push(key, personal_project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_falsey end end @@ -147,7 +147,7 @@ describe API::API, api: true do it do pull(key, project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_truthy end end @@ -156,7 +156,7 @@ describe API::API, api: true do it do push(key, project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_falsey end end @@ -173,7 +173,7 @@ describe API::API, api: true do it do archive(key, project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_truthy end end @@ -182,7 +182,7 @@ describe API::API, api: true do it do archive(key, project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_falsey end end @@ -192,7 +192,7 @@ describe API::API, api: true do it do pull(key, OpenStruct.new(path_with_namespace: 'gitlab/notexists')) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_falsey end end @@ -201,7 +201,7 @@ describe API::API, api: true do it do pull(OpenStruct.new(id: 0), project) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["status"]).to be_falsey end end diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index edec53dad89..2cf130df328 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -51,14 +51,14 @@ describe API::API, api: true do context "when unauthenticated" do it "should return authentication error" do get api("/issues") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context "when authenticated" do it "should return an array of issues" do get api("/issues", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['title']).to eq(issue.title) end @@ -72,7 +72,7 @@ describe API::API, api: true do it 'should return an array of closed issues' do get api('/issues?state=closed', user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(closed_issue.id) @@ -80,7 +80,7 @@ describe API::API, api: true do it 'should return an array of opened issues' do get api('/issues?state=opened', user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(issue.id) @@ -88,7 +88,7 @@ describe API::API, api: true do it 'should return an array of all issues' do get api('/issues?state=all', user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) expect(json_response.first['id']).to eq(issue.id) @@ -97,7 +97,7 @@ describe API::API, api: true do it 'should return an array of labeled issues' do get api("/issues?labels=#{label.title}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['labels']).to eq([label.title]) @@ -105,7 +105,7 @@ describe API::API, api: true do it 'should return an array of labeled issues when at least one label matches' do get api("/issues?labels=#{label.title},foo,bar", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['labels']).to eq([label.title]) @@ -113,14 +113,14 @@ describe API::API, api: true do it 'should return an empty array if no issue matches labels' do get api('/issues?labels=foo,bar', user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(0) end it 'should return an array of labeled issues matching given state' do get api("/issues?labels=#{label.title}&state=opened", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['labels']).to eq([label.title]) @@ -129,7 +129,7 @@ describe API::API, api: true do it 'should return an empty array if no issue matches labels and state filters' do get api("/issues?labels=#{label.title}&state=closed", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(0) end @@ -179,7 +179,7 @@ describe API::API, api: true do it 'returns group issues without confidential issues for non project members' do get api(base_url, non_member) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['title']).to eq(group_issue.title) @@ -188,7 +188,7 @@ describe API::API, api: true do it 'returns group confidential issues for author' do get api(base_url, author) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) end @@ -196,7 +196,7 @@ describe API::API, api: true do it 'returns group confidential issues for assignee' do get api(base_url, assignee) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) end @@ -204,7 +204,7 @@ describe API::API, api: true do it 'returns group issues with confidential issues for project members' do get api(base_url, user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) end @@ -212,7 +212,7 @@ describe API::API, api: true do it 'returns group confidential issues for admin' do get api(base_url, admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) end @@ -220,7 +220,7 @@ describe API::API, api: true do it 'returns an array of labeled group issues' do get api("#{base_url}?labels=#{group_label.title}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['labels']).to eq([group_label.title]) @@ -229,7 +229,7 @@ describe API::API, api: true do it 'returns an array of labeled group issues where all labels match' do get api("#{base_url}?labels=#{group_label.title},foo,bar", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(0) end @@ -237,7 +237,7 @@ describe API::API, api: true do it 'returns an empty array if no group issue matches labels' do get api("#{base_url}?labels=foo,bar", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(0) end @@ -245,7 +245,7 @@ describe API::API, api: true do it 'returns an empty array if no issue matches milestone' do get api("#{base_url}?milestone=#{group_empty_milestone.title}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(0) end @@ -253,7 +253,7 @@ describe API::API, api: true do it 'returns an empty array if milestone does not exist' do get api("#{base_url}?milestone=foo", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(0) end @@ -261,7 +261,7 @@ describe API::API, api: true do it 'returns an array of issues in given milestone' do get api("#{base_url}?milestone=#{group_milestone.title}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(group_issue.id) @@ -271,7 +271,7 @@ describe API::API, api: true do get api("#{base_url}?milestone=#{group_milestone.title}"\ '&state=closed', user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(group_closed_issue.id) @@ -284,7 +284,7 @@ describe API::API, api: true do it 'should return project issues without confidential issues for non project members' do get api("#{base_url}/issues", non_member) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) expect(json_response.first['title']).to eq(issue.title) @@ -292,7 +292,7 @@ describe API::API, api: true do it 'should return project issues without confidential issues for project members with guest role' do get api("#{base_url}/issues", guest) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) expect(json_response.first['title']).to eq(issue.title) @@ -300,7 +300,7 @@ describe API::API, api: true do it 'should return project confidential issues for author' do get api("#{base_url}/issues", author) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(3) expect(json_response.first['title']).to eq(issue.title) @@ -308,7 +308,7 @@ describe API::API, api: true do it 'should return project confidential issues for assignee' do get api("#{base_url}/issues", assignee) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(3) expect(json_response.first['title']).to eq(issue.title) @@ -316,7 +316,7 @@ describe API::API, api: true do it 'should return project issues with confidential issues for project members' do get api("#{base_url}/issues", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(3) expect(json_response.first['title']).to eq(issue.title) @@ -324,7 +324,7 @@ describe API::API, api: true do it 'should return project confidential issues for admin' do get api("#{base_url}/issues", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(3) expect(json_response.first['title']).to eq(issue.title) @@ -332,7 +332,7 @@ describe API::API, api: true do it 'should return an array of labeled project issues' do get api("#{base_url}/issues?labels=#{label.title}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['labels']).to eq([label.title]) @@ -340,7 +340,7 @@ describe API::API, api: true do it 'should return an array of labeled project issues when at least one label matches' do get api("#{base_url}/issues?labels=#{label.title},foo,bar", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['labels']).to eq([label.title]) @@ -348,28 +348,28 @@ describe API::API, api: true do it 'should return an empty array if no project issue matches labels' do get api("#{base_url}/issues?labels=foo,bar", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(0) end it 'should return an empty array if no issue matches milestone' do get api("#{base_url}/issues?milestone=#{empty_milestone.title}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(0) end it 'should return an empty array if milestone does not exist' do get api("#{base_url}/issues?milestone=foo", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(0) end it 'should return an array of issues in given milestone' do get api("#{base_url}/issues?milestone=#{title}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) expect(json_response.first['id']).to eq(issue.id) @@ -379,7 +379,7 @@ describe API::API, api: true do it 'should return an array of issues matching state in milestone' do get api("#{base_url}/issues?milestone=#{milestone.title}"\ '&state=closed', user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(closed_issue.id) @@ -390,7 +390,7 @@ describe API::API, api: true do it 'exposes known attributes' do get api("/projects/#{project.id}/issues/#{issue.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['id']).to eq(issue.id) expect(json_response['iid']).to eq(issue.iid) expect(json_response['project_id']).to eq(issue.project.id) @@ -408,7 +408,7 @@ describe API::API, api: true do it "should return a project issue by id" do get api("/projects/#{project.id}/issues/#{issue.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq(issue.title) expect(json_response['iid']).to eq(issue.iid) end @@ -423,44 +423,44 @@ describe API::API, api: true do it "should return 404 if issue id not found" do get api("/projects/#{project.id}/issues/54321", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end context 'confidential issues' do it "should return 404 for non project members" do get api("/projects/#{project.id}/issues/#{confidential_issue.id}", non_member) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return 404 for project members with guest role" do get api("/projects/#{project.id}/issues/#{confidential_issue.id}", guest) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return confidential issue for project members" do get api("/projects/#{project.id}/issues/#{confidential_issue.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq(confidential_issue.title) expect(json_response['iid']).to eq(confidential_issue.iid) end it "should return confidential issue for author" do get api("/projects/#{project.id}/issues/#{confidential_issue.id}", author) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq(confidential_issue.title) expect(json_response['iid']).to eq(confidential_issue.iid) end it "should return confidential issue for assignee" do get api("/projects/#{project.id}/issues/#{confidential_issue.id}", assignee) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq(confidential_issue.title) expect(json_response['iid']).to eq(confidential_issue.iid) end it "should return confidential issue for admin" do get api("/projects/#{project.id}/issues/#{confidential_issue.id}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq(confidential_issue.title) expect(json_response['iid']).to eq(confidential_issue.iid) end @@ -471,7 +471,7 @@ describe API::API, api: true do it "should create a new project issue" do post api("/projects/#{project.id}/issues", user), title: 'new issue', labels: 'label, label2' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['title']).to eq('new issue') expect(json_response['description']).to be_nil expect(json_response['labels']).to eq(['label', 'label2']) @@ -479,21 +479,21 @@ describe API::API, api: true do it "should return a 400 bad request if title not given" do post api("/projects/#{project.id}/issues", user), labels: 'label, label2' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return 400 on invalid label names' do post api("/projects/#{project.id}/issues", user), title: 'new issue', labels: 'label, ?' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['labels']['?']['title']).to eq(['is invalid']) end it 'should return 400 if title is too long' do post api("/projects/#{project.id}/issues", user), title: 'g' * 256 - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['title']).to eq([ 'is too long (maximum is 255 characters)' ]) @@ -505,7 +505,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/issues", user), title: 'new issue', labels: 'label, label2', created_at: creation_time - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time) end end @@ -529,7 +529,7 @@ describe API::API, api: true do it "should not create a new project issue" do expect { post api("/projects/#{project.id}/issues", user), params }.not_to change(Issue, :count) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq({ "error" => "Spam detected" }) spam_logs = SpamLog.all @@ -546,7 +546,7 @@ describe API::API, api: true do it "should update a project issue" do put api("/projects/#{project.id}/issues/#{issue.id}", user), title: 'updated title' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq('updated title') end @@ -554,14 +554,14 @@ describe API::API, api: true do it "should return 404 error if issue id not found" do put api("/projects/#{project.id}/issues/44444", user), title: 'updated title' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should return 400 on invalid label names' do put api("/projects/#{project.id}/issues/#{issue.id}", user), title: 'updated title', labels: 'label, ?' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['labels']['?']['title']).to eq(['is invalid']) end @@ -569,33 +569,33 @@ describe API::API, api: true do it "should return 403 for non project members" do put api("/projects/#{project.id}/issues/#{confidential_issue.id}", non_member), title: 'updated title' - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it "should return 403 for project members with guest role" do put api("/projects/#{project.id}/issues/#{confidential_issue.id}", guest), title: 'updated title' - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it "should update a confidential issue for project members" do put api("/projects/#{project.id}/issues/#{confidential_issue.id}", user), title: 'updated title' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq('updated title') end it "should update a confidential issue for author" do put api("/projects/#{project.id}/issues/#{confidential_issue.id}", author), title: 'updated title' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq('updated title') end it "should update a confidential issue for admin" do put api("/projects/#{project.id}/issues/#{confidential_issue.id}", admin), title: 'updated title' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq('updated title') end end @@ -608,21 +608,21 @@ describe API::API, api: true do it 'should not update labels if not present' do put api("/projects/#{project.id}/issues/#{issue.id}", user), title: 'updated title' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['labels']).to eq([label.title]) end it 'should remove all labels' do put api("/projects/#{project.id}/issues/#{issue.id}", user), labels: '' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['labels']).to eq([]) end it 'should update labels' do put api("/projects/#{project.id}/issues/#{issue.id}", user), labels: 'foo,bar' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['labels']).to include 'foo' expect(json_response['labels']).to include 'bar' end @@ -630,14 +630,14 @@ describe API::API, api: true do it 'should return 400 on invalid label names' do put api("/projects/#{project.id}/issues/#{issue.id}", user), labels: 'label, ?' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['labels']['?']['title']).to eq(['is invalid']) end it 'should allow special label names' do put api("/projects/#{project.id}/issues/#{issue.id}", user), labels: 'label:foo, label-bar,label_bar,label/bar' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['labels']).to include 'label:foo' expect(json_response['labels']).to include 'label-bar' expect(json_response['labels']).to include 'label_bar' @@ -647,7 +647,7 @@ describe API::API, api: true do it 'should return 400 if title is too long' do put api("/projects/#{project.id}/issues/#{issue.id}", user), title: 'g' * 256 - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['title']).to eq([ 'is too long (maximum is 255 characters)' ]) @@ -658,7 +658,7 @@ describe API::API, api: true do it "should update a project issue" do put api("/projects/#{project.id}/issues/#{issue.id}", user), labels: 'label2', state_event: "close" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['labels']).to include 'label2' expect(json_response['state']).to eq "closed" @@ -669,7 +669,7 @@ describe API::API, api: true do update_time = 2.weeks.ago put api("/projects/#{project.id}/issues/#{issue.id}", user), labels: 'label3', state_event: 'close', updated_at: update_time - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['labels']).to include 'label3' expect(Time.parse(json_response['updated_at'])).to be_within(1.second).of(update_time) @@ -680,12 +680,12 @@ describe API::API, api: true do describe "DELETE /projects/:id/issues/:issue_id" do it "rejects a non member from deleting an issue" do delete api("/projects/#{project.id}/issues/#{issue.id}", non_member) - expect(response.status).to be(403) + expect(response).to have_http_status(403) end it "rejects a developer from deleting an issue" do delete api("/projects/#{project.id}/issues/#{issue.id}", author) - expect(response.status).to be(403) + expect(response).to have_http_status(403) end context "when the user is project owner" do @@ -694,7 +694,7 @@ describe API::API, api: true do it "deletes the issue if an admin requests it" do delete api("/projects/#{project.id}/issues/#{issue.id}", owner) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['state']).to eq 'opened' end end @@ -708,7 +708,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/issues/#{issue.id}/move", user), to_project_id: target_project.id - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['project_id']).to eq(target_project.id) end @@ -717,7 +717,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/issues/#{issue.id}/move", user), to_project_id: project.id - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('Cannot move issue to project it originates from!') end end @@ -727,7 +727,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/issues/#{issue.id}/move", user), to_project_id: target_project2.id - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('Cannot move issue due to insufficient permissions!') end end @@ -736,7 +736,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/issues/#{issue.id}/move", admin), to_project_id: target_project2.id - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['project_id']).to eq(target_project2.id) end @@ -745,7 +745,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/issues/123/move", user), to_project_id: target_project.id - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -754,7 +754,7 @@ describe API::API, api: true do post api("/projects/123/issues/#{issue.id}/move", user), to_project_id: target_project.id - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -763,7 +763,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/issues/#{issue.id}/move", user), to_project_id: 123 - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -772,26 +772,26 @@ describe API::API, api: true do it 'subscribes to an issue' do post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['subscribed']).to eq(true) end it 'returns 304 if already subscribed' do post api("/projects/#{project.id}/issues/#{issue.id}/subscription", user) - expect(response.status).to eq(304) + expect(response).to have_http_status(304) end it 'returns 404 if the issue is not found' do post api("/projects/#{project.id}/issues/123/subscription", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'returns 404 if the issue is confidential' do post api("/projects/#{project.id}/issues/#{confidential_issue.id}/subscription", non_member) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -799,26 +799,26 @@ describe API::API, api: true do it 'unsubscribes from an issue' do delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['subscribed']).to eq(false) end it 'returns 304 if not subscribed' do delete api("/projects/#{project.id}/issues/#{issue.id}/subscription", user2) - expect(response.status).to eq(304) + expect(response).to have_http_status(304) end it 'returns 404 if the issue is not found' do delete api("/projects/#{project.id}/issues/123/subscription", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'returns 404 if the issue is confidential' do delete api("/projects/#{project.id}/issues/#{confidential_issue.id}/subscription", non_member) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/requests/api/keys_spec.rb b/spec/requests/api/keys_spec.rb index d2b87f88712..1861882d59e 100644 --- a/spec/requests/api/keys_spec.rb +++ b/spec/requests/api/keys_spec.rb @@ -14,14 +14,14 @@ describe API::API, api: true do context 'when unauthenticated' do it 'should return authentication error' do get api("/keys/#{key.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context 'when authenticated' do it 'should return 404 for non-existing key' do get api('/keys/999999', admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Not found') end @@ -29,7 +29,7 @@ describe API::API, api: true do user.keys << key user.save get api("/keys/#{key.id}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq(key.title) expect(json_response['user']['id']).to eq(user.id) expect(json_response['user']['username']).to eq(user.username) diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb index b2c7f8d9acb..39736779986 100644 --- a/spec/requests/api/labels_spec.rb +++ b/spec/requests/api/labels_spec.rb @@ -15,7 +15,7 @@ describe API::API, api: true do describe 'GET /projects/:id/labels' do it 'should return project labels' do get api("/projects/#{project.id}/labels", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to eq(1) expect(json_response.first['name']).to eq(label1.name) @@ -28,7 +28,7 @@ describe API::API, api: true do name: 'Foo', color: '#FFAABB', description: 'test' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['name']).to eq('Foo') expect(json_response['color']).to eq('#FFAABB') expect(json_response['description']).to eq('test') @@ -38,7 +38,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/labels", user), name: 'Foo', color: '#FFAABB' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['name']).to eq('Foo') expect(json_response['color']).to eq('#FFAABB') expect(json_response['description']).to be_nil @@ -46,19 +46,19 @@ describe API::API, api: true do it 'should return a 400 bad request if name not given' do post api("/projects/#{project.id}/labels", user), color: '#FFAABB' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return a 400 bad request if color not given' do post api("/projects/#{project.id}/labels", user), name: 'Foobar' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return 400 for invalid color' do post api("/projects/#{project.id}/labels", user), name: 'Foo', color: '#FFAA' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['color']).to eq(['must be a valid color code']) end @@ -66,7 +66,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/labels", user), name: 'Foo', color: '#FFAAFFFF' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['color']).to eq(['must be a valid color code']) end @@ -74,7 +74,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/labels", user), name: '?', color: '#FFAABB' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['title']).to eq(['is invalid']) end @@ -82,7 +82,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/labels", user), name: 'label1', color: '#FFAABB' - expect(response.status).to eq(409) + expect(response).to have_http_status(409) expect(json_response['message']).to eq('Label already exists') end end @@ -90,18 +90,18 @@ describe API::API, api: true do describe 'DELETE /projects/:id/labels' do it 'should return 200 for existing label' do delete api("/projects/#{project.id}/labels", user), name: 'label1' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should return 404 for non existing label' do delete api("/projects/#{project.id}/labels", user), name: 'label2' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Label Not Found') end it 'should return 400 for wrong parameters' do delete api("/projects/#{project.id}/labels", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -112,7 +112,7 @@ describe API::API, api: true do new_name: 'New Label', color: '#FFFFFF', description: 'test' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq('New Label') expect(json_response['color']).to eq('#FFFFFF') expect(json_response['description']).to eq('test') @@ -122,7 +122,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/labels", user), name: 'label1', new_name: 'New Label' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq('New Label') expect(json_response['color']).to eq(label1.color) end @@ -131,7 +131,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/labels", user), name: 'label1', color: '#FFFFFF' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(label1.name) expect(json_response['color']).to eq('#FFFFFF') end @@ -140,7 +140,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/labels", user), name: 'label1', description: 'test' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(label1.name) expect(json_response['description']).to eq('test') end @@ -149,18 +149,18 @@ describe API::API, api: true do put api("/projects/#{project.id}/labels", user), name: 'label2', new_name: 'label3' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should return 400 if no label name given' do put api("/projects/#{project.id}/labels", user), new_name: 'label2' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('400 (Bad request) "name" not given') end it 'should return 400 if no new parameters given' do put api("/projects/#{project.id}/labels", user), name: 'label1' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('Required parameters '\ '"new_name" or "color" missing') end @@ -170,7 +170,7 @@ describe API::API, api: true do name: 'label1', new_name: '?', color: '#FFFFFF' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['title']).to eq(['is invalid']) end @@ -178,7 +178,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/labels", user), name: 'label1', color: '#FF' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['color']).to eq(['must be a valid color code']) end @@ -186,7 +186,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/labels", user), name: 'Foo', color: '#FFAAFFFF' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['color']).to eq(['must be a valid color code']) end end @@ -196,7 +196,7 @@ describe API::API, api: true do it "should subscribe to the label" do post api("/projects/#{project.id}/labels/#{label1.title}/subscription", user) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response["name"]).to eq(label1.title) expect(json_response["subscribed"]).to be_truthy end @@ -206,7 +206,7 @@ describe API::API, api: true do it "should subscribe to the label" do post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response["name"]).to eq(label1.title) expect(json_response["subscribed"]).to be_truthy end @@ -218,7 +218,7 @@ describe API::API, api: true do it "should return 304" do post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) - expect(response.status).to eq(304) + expect(response).to have_http_status(304) end end @@ -226,7 +226,7 @@ describe API::API, api: true do it "should a return 404 error" do post api("/projects/#{project.id}/labels/1234/subscription", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -238,7 +238,7 @@ describe API::API, api: true do it "should unsubscribe from the label" do delete api("/projects/#{project.id}/labels/#{label1.title}/subscription", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["name"]).to eq(label1.title) expect(json_response["subscribed"]).to be_falsey end @@ -248,7 +248,7 @@ describe API::API, api: true do it "should unsubscribe from the label" do delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["name"]).to eq(label1.title) expect(json_response["subscribed"]).to be_falsey end @@ -260,7 +260,7 @@ describe API::API, api: true do it "should return 304" do delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) - expect(response.status).to eq(304) + expect(response).to have_http_status(304) end end @@ -268,7 +268,7 @@ describe API::API, api: true do it "should a return 404 error" do delete api("/projects/#{project.id}/labels/1234/subscription", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/requests/api/licenses_spec.rb b/spec/requests/api/license_templates_spec.rb index 3726b2f5688..9a1894d63a2 100644 --- a/spec/requests/api/licenses_spec.rb +++ b/spec/requests/api/license_templates_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe API::Licenses, api: true do +describe API::API, api: true do include ApiHelpers describe 'Entity' do @@ -23,7 +23,7 @@ describe API::Licenses, api: true do it 'returns a list of available license templates' do get api('/licenses') - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to eq(15) expect(json_response.map { |l| l['key'] }).to include('agpl-3.0') @@ -34,7 +34,7 @@ describe API::Licenses, api: true do it 'returns a list of available popular license templates' do get api('/licenses?popular=1') - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to eq(3) expect(json_response.map { |l| l['key'] }).to include('apache-2.0') @@ -116,7 +116,7 @@ describe API::Licenses, api: true do let(:license_type) { 'muth-over9000' } it 'returns a 404' do - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 5896b93603f..61e897edf87 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -22,14 +22,14 @@ describe API::API, api: true do context "when unauthenticated" do it "should return authentication error" do get api("/projects/#{project.id}/merge_requests") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context "when authenticated" do it "should return an array of all merge_requests" do get api("/projects/#{project.id}/merge_requests", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(3) expect(json_response.last['title']).to eq(merge_request.title) @@ -37,7 +37,7 @@ describe API::API, api: true do it "should return an array of all merge_requests" do get api("/projects/#{project.id}/merge_requests?state", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(3) expect(json_response.last['title']).to eq(merge_request.title) @@ -45,7 +45,7 @@ describe API::API, api: true do it "should return an array of open merge_requests" do get api("/projects/#{project.id}/merge_requests?state=opened", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.last['title']).to eq(merge_request.title) @@ -53,7 +53,7 @@ describe API::API, api: true do it "should return an array of closed merge_requests" do get api("/projects/#{project.id}/merge_requests?state=closed", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['title']).to eq(merge_request_closed.title) @@ -61,7 +61,7 @@ describe API::API, api: true do it "should return an array of merged merge_requests" do get api("/projects/#{project.id}/merge_requests?state=merged", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['title']).to eq(merge_request_merged.title) @@ -75,7 +75,7 @@ describe API::API, api: true do it "should return an array of merge_requests in ascending order" do get api("/projects/#{project.id}/merge_requests?sort=asc", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(3) response_dates = json_response.map{ |merge_request| merge_request['created_at'] } @@ -84,7 +84,7 @@ describe API::API, api: true do it "should return an array of merge_requests in descending order" do get api("/projects/#{project.id}/merge_requests?sort=desc", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(3) response_dates = json_response.map{ |merge_request| merge_request['created_at'] } @@ -93,7 +93,7 @@ describe API::API, api: true do it "should return an array of merge_requests ordered by updated_at" do get api("/projects/#{project.id}/merge_requests?order_by=updated_at", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(3) response_dates = json_response.map{ |merge_request| merge_request['updated_at'] } @@ -102,7 +102,7 @@ describe API::API, api: true do it "should return an array of merge_requests ordered by created_at" do get api("/projects/#{project.id}/merge_requests?order_by=created_at&sort=asc", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(3) response_dates = json_response.map{ |merge_request| merge_request['created_at'] } @@ -116,7 +116,7 @@ describe API::API, api: true do it 'exposes known attributes' do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['id']).to eq(merge_request.id) expect(json_response['iid']).to eq(merge_request.iid) expect(json_response['project_id']).to eq(merge_request.project.id) @@ -142,7 +142,7 @@ describe API::API, api: true do it "should return merge_request" do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq(merge_request.title) expect(json_response['iid']).to eq(merge_request.iid) expect(json_response['work_in_progress']).to eq(false) @@ -159,7 +159,7 @@ describe API::API, api: true do it "should return a 404 error if merge_request_id not found" do get api("/projects/#{project.id}/merge_requests/999", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end context 'Work in Progress' do @@ -167,7 +167,7 @@ describe API::API, api: true do it "should return merge_request" do get api("/projects/#{project.id}/merge_requests/#{merge_request_wip.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['work_in_progress']).to eq(true) end end @@ -186,7 +186,7 @@ describe API::API, api: true do it 'returns a 404 when merge_request_id not found' do get api("/projects/#{project.id}/merge_requests/999/commits", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -199,7 +199,7 @@ describe API::API, api: true do it 'returns a 404 when merge_request_id not found' do get api("/projects/#{project.id}/merge_requests/999/changes", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -213,7 +213,7 @@ describe API::API, api: true do author: user, labels: 'label, label2', milestone_id: milestone.id - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['title']).to eq('Test merge_request') expect(json_response['labels']).to eq(['label', 'label2']) expect(json_response['milestone']['id']).to eq(milestone.id) @@ -222,25 +222,25 @@ describe API::API, api: true do it "should return 422 when source_branch equals target_branch" do post api("/projects/#{project.id}/merge_requests", user), title: "Test merge_request", source_branch: "master", target_branch: "master", author: user - expect(response.status).to eq(422) + expect(response).to have_http_status(422) end it "should return 400 when source_branch is missing" do post api("/projects/#{project.id}/merge_requests", user), title: "Test merge_request", target_branch: "master", author: user - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return 400 when target_branch is missing" do post api("/projects/#{project.id}/merge_requests", user), title: "Test merge_request", source_branch: "markdown", author: user - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return 400 when title is missing" do post api("/projects/#{project.id}/merge_requests", user), target_branch: 'master', source_branch: 'markdown' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return 400 on invalid label names' do @@ -250,7 +250,7 @@ describe API::API, api: true do target_branch: 'master', author: user, labels: 'label, ?' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['labels']['?']['title']).to eq( ['is invalid'] ) @@ -274,7 +274,7 @@ describe API::API, api: true do target_branch: 'master', author: user end.to change { MergeRequest.count }.by(0) - expect(response.status).to eq(409) + expect(response).to have_http_status(409) end end end @@ -292,7 +292,7 @@ describe API::API, api: true do post api("/projects/#{fork_project.id}/merge_requests", user2), title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master", author: user2, target_project_id: project.id, description: 'Test description for Test merge_request' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['title']).to eq('Test merge_request') expect(json_response['description']).to eq('Test description for Test merge_request') end @@ -303,26 +303,26 @@ describe API::API, api: true do expect(fork_project.forked_from_project).to eq(project) post api("/projects/#{fork_project.id}/merge_requests", user2), title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['title']).to eq('Test merge_request') end it "should return 400 when source_branch is missing" do post api("/projects/#{fork_project.id}/merge_requests", user2), title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return 400 when target_branch is missing" do post api("/projects/#{fork_project.id}/merge_requests", user2), title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return 400 when title is missing" do post api("/projects/#{fork_project.id}/merge_requests", user2), target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end context 'when target_branch is specified' do @@ -333,7 +333,7 @@ describe API::API, api: true do source_branch: 'markdown', author: user, target_project_id: fork_project.id - expect(response.status).to eq(422) + expect(response).to have_http_status(422) end it 'should return 422 if targeting a different fork' do @@ -343,14 +343,14 @@ describe API::API, api: true do source_branch: 'markdown', author: user2, target_project_id: unrelated_project.id - expect(response.status).to eq(422) + expect(response).to have_http_status(422) end end it "should return 201 when target_branch is specified and for the same project" do post api("/projects/#{fork_project.id}/merge_requests", user2), title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end end end @@ -365,7 +365,7 @@ describe API::API, api: true do it "denies the deletion of the merge request" do delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}", developer) - expect(response.status).to be(403) + expect(response).to have_http_status(403) end end @@ -373,7 +373,7 @@ describe API::API, api: true do it "destroys the merge request owners can destroy" do delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -381,7 +381,7 @@ describe API::API, api: true do describe "PUT /projects/:id/merge_requests/:merge_request_id to close MR" do it "should return merge_request" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), state_event: "close" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['state']).to eq('closed') end end @@ -392,7 +392,7 @@ describe API::API, api: true do it "should return merge_request in case of success" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return 406 if branch can't be merged" do @@ -401,21 +401,21 @@ describe API::API, api: true do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) - expect(response.status).to eq(406) + expect(response).to have_http_status(406) expect(json_response['message']).to eq('Branch cannot be merged') end it "should return 405 if merge_request is not open" do merge_request.close put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) - expect(response.status).to eq(405) + expect(response).to have_http_status(405) expect(json_response['message']).to eq('405 Method Not Allowed') end it "should return 405 if merge_request is a work in progress" do merge_request.update_attribute(:title, "WIP: #{merge_request.title}") put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) - expect(response.status).to eq(405) + expect(response).to have_http_status(405) expect(json_response['message']).to eq('405 Method Not Allowed') end @@ -424,7 +424,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user) - expect(response.status).to eq(405) + expect(response).to have_http_status(405) expect(json_response['message']).to eq('405 Method Not Allowed') end @@ -432,21 +432,21 @@ describe API::API, api: true do user2 = create(:user) project.team << [user2, :reporter] put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user2) - expect(response.status).to eq(401) + expect(response).to have_http_status(401) expect(json_response['message']).to eq('401 Unauthorized') end it "returns 409 if the SHA parameter doesn't match" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), sha: merge_request.source_sha.succ - expect(response.status).to eq(409) + expect(response).to have_http_status(409) expect(json_response['message']).to start_with('SHA does not match HEAD of source branch') end it "succeeds if the SHA parameter matches" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), sha: merge_request.source_sha - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "enables merge when build succeeds if the ci is active" do @@ -455,7 +455,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/merge", user), merge_when_build_succeeds: true - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq('Test') expect(json_response['merge_when_build_succeeds']).to eq(true) end @@ -464,31 +464,31 @@ describe API::API, api: true do describe "PUT /projects/:id/merge_requests/:merge_request_id" do it "updates title and returns merge_request" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), title: "New title" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq('New title') end it "updates description and returns merge_request" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), description: "New description" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['description']).to eq('New description') end it "updates milestone_id and returns merge_request" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), milestone_id: milestone.id - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['milestone']['id']).to eq(milestone.id) end it "should return 400 when source_branch is specified" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), source_branch: "master", target_branch: "master" - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return merge_request with renamed target_branch" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), target_branch: "wiki" - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['target_branch']).to eq('wiki') end @@ -497,7 +497,7 @@ describe API::API, api: true do user), title: 'new issue', labels: 'label, ?' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['labels']['?']['title']).to eq(['is invalid']) end end @@ -507,7 +507,7 @@ describe API::API, api: true do original_count = merge_request.notes.size post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user), note: "My comment" - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['note']).to eq('My comment') expect(json_response['author']['name']).to eq(user.name) expect(json_response['author']['username']).to eq(user.username) @@ -516,20 +516,20 @@ describe API::API, api: true do it "should return 400 if note is missing" do post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return 404 if note is attached to non existent merge request" do post api("/projects/#{project.id}/merge_requests/404/comments", user), note: 'My comment' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end describe "GET :id/merge_requests/:merge_request_id/comments" do it "should return merge_request comments ordered by created_at" do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/comments", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(2) expect(json_response.first['note']).to eq("a comment on a MR") @@ -539,7 +539,7 @@ describe API::API, api: true do it "should return a 404 error if merge_request_id not found" do get api("/projects/#{project.id}/merge_requests/999/comments", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -551,7 +551,7 @@ describe API::API, api: true do end get api("/projects/#{project.id}/merge_requests/#{mr.id}/closes_issues", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(issue.id) @@ -559,7 +559,7 @@ describe API::API, api: true do it 'returns an empty array when there are no issues to be closed' do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(0) end @@ -572,7 +572,7 @@ describe API::API, api: true do get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.id}/closes_issues", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['title']).to eq(issue.title) @@ -584,20 +584,20 @@ describe API::API, api: true do it 'subscribes to a merge request' do post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", admin) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['subscribed']).to eq(true) end it 'returns 304 if already subscribed' do post api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", user) - expect(response.status).to eq(304) + expect(response).to have_http_status(304) end it 'returns 404 if the merge request is not found' do post api("/projects/#{project.id}/merge_requests/123/subscription", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -605,20 +605,20 @@ describe API::API, api: true do it 'unsubscribes from a merge request' do delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['subscribed']).to eq(false) end it 'returns 304 if not subscribed' do delete api("/projects/#{project.id}/merge_requests/#{merge_request.id}/subscription", admin) - expect(response.status).to eq(304) + expect(response).to have_http_status(304) end it 'returns 404 if the merge request is not found' do post api("/projects/#{project.id}/merge_requests/123/subscription", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb index 0154d1c62cc..0f4e38b2475 100644 --- a/spec/requests/api/milestones_spec.rb +++ b/spec/requests/api/milestones_spec.rb @@ -12,20 +12,20 @@ describe API::API, api: true do describe 'GET /projects/:id/milestones' do it 'should return project milestones' do get api("/projects/#{project.id}/milestones", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['title']).to eq(milestone.title) end it 'should return a 401 error if user not authenticated' do get api("/projects/#{project.id}/milestones") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end it 'returns an array of active milestones' do get api("/projects/#{project.id}/milestones?state=active", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(milestone.id) @@ -34,7 +34,7 @@ describe API::API, api: true do it 'returns an array of closed milestones' do get api("/projects/#{project.id}/milestones?state=closed", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(closed_milestone.id) @@ -44,7 +44,7 @@ describe API::API, api: true do describe 'GET /projects/:id/milestones/:milestone_id' do it 'should return a project milestone by id' do get api("/projects/#{project.id}/milestones/#{milestone.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq(milestone.title) expect(json_response['iid']).to eq(milestone.iid) end @@ -60,19 +60,19 @@ describe API::API, api: true do it 'should return 401 error if user not authenticated' do get api("/projects/#{project.id}/milestones/#{milestone.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end it 'should return a 404 error if milestone id not found' do get api("/projects/#{project.id}/milestones/1234", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end describe 'POST /projects/:id/milestones' do it 'should create a new project milestone' do post api("/projects/#{project.id}/milestones", user), title: 'new milestone' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['title']).to eq('new milestone') expect(json_response['description']).to be_nil end @@ -80,14 +80,14 @@ describe API::API, api: true do it 'should create a new project milestone with description and due date' do post api("/projects/#{project.id}/milestones", user), title: 'new milestone', description: 'release', due_date: '2013-03-02' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['description']).to eq('release') expect(json_response['due_date']).to eq('2013-03-02') end it 'should return a 400 error if title is missing' do post api("/projects/#{project.id}/milestones", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -95,14 +95,14 @@ describe API::API, api: true do it 'should update a project milestone' do put api("/projects/#{project.id}/milestones/#{milestone.id}", user), title: 'updated title' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq('updated title') end it 'should return a 404 error if milestone id not found' do put api("/projects/#{project.id}/milestones/1234", user), title: 'updated title' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -110,7 +110,7 @@ describe API::API, api: true do it 'should update a project milestone' do put api("/projects/#{project.id}/milestones/#{milestone.id}", user), state_event: 'close' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['state']).to eq('closed') end @@ -131,14 +131,14 @@ describe API::API, api: true do end it 'should return project issues for a particular milestone' do get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['milestone']['title']).to eq(milestone.title) end it 'should return a 401 error if user not authenticated' do get api("/projects/#{project.id}/milestones/#{milestone.id}/issues") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end describe 'confidential issues' do @@ -155,7 +155,7 @@ describe API::API, api: true do it 'returns confidential issues to team members' do get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to eq(2) expect(json_response.map { |issue| issue['id'] }).to include(issue.id, confidential_issue.id) @@ -167,7 +167,7 @@ describe API::API, api: true do get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", member) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to eq(1) expect(json_response.map { |issue| issue['id'] }).to include(issue.id) @@ -176,7 +176,7 @@ describe API::API, api: true do it 'does not return confidential issues to regular users' do get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", create(:user)) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to eq(1) expect(json_response.map { |issue| issue['id'] }).to include(issue.id) diff --git a/spec/requests/api/namespaces_spec.rb b/spec/requests/api/namespaces_spec.rb index 21787fdd895..237b4b17eb5 100644 --- a/spec/requests/api/namespaces_spec.rb +++ b/spec/requests/api/namespaces_spec.rb @@ -11,14 +11,14 @@ describe API::API, api: true do context "when unauthenticated" do it "should return authentication error" do get api("/namespaces") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context "when authenticated as admin" do it "admin: should return an array of all namespaces" do get api("/namespaces", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(Namespace.count) @@ -26,7 +26,7 @@ describe API::API, api: true do it "admin: should return an array of matched namespaces" do get api("/namespaces?search=#{group1.name}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) @@ -36,7 +36,7 @@ describe API::API, api: true do context "when authenticated as a regular user" do it "user: should return an array of namespaces" do get api("/namespaces", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) @@ -44,7 +44,7 @@ describe API::API, api: true do it "admin: should return an array of matched namespaces" do get api("/namespaces?search=#{user.username}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index beb29a68692..bacd01f8e74 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -40,7 +40,7 @@ describe API::API, api: true do it "should return an array of issue notes" do get api("/projects/#{project.id}/issues/#{issue.id}/notes", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['body']).to eq(issue_note.note) end @@ -48,14 +48,14 @@ describe API::API, api: true do it "should return a 404 error when issue id not found" do get api("/projects/#{project.id}/issues/12345/notes", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end context "and current user cannot view the notes" do it "should return an empty array" do get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response).to be_empty end @@ -66,7 +66,7 @@ describe API::API, api: true do it "returns 404" do get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -74,7 +74,7 @@ describe API::API, api: true do it "should return an empty array" do get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", private_user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['body']).to eq(cross_reference_note.note) end @@ -86,7 +86,7 @@ describe API::API, api: true do it "should return an array of snippet notes" do get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['body']).to eq(snippet_note.note) end @@ -94,13 +94,13 @@ describe API::API, api: true do it "should return a 404 error when snippet id not found" do get api("/projects/#{project.id}/snippets/42/notes", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "returns 404 when not authorized" do get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", private_user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -108,7 +108,7 @@ describe API::API, api: true do it "should return an array of merge_requests notes" do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['body']).to eq(merge_request_note.note) end @@ -116,13 +116,13 @@ describe API::API, api: true do it "should return a 404 error if merge request id not found" do get api("/projects/#{project.id}/merge_requests/4444/notes", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "returns 404 when not authorized" do get api("/projects/#{project.id}/merge_requests/4444/notes", private_user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -132,21 +132,21 @@ describe API::API, api: true do it "should return an issue note by id" do get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['body']).to eq(issue_note.note) end it "should return a 404 error if issue note not found" do get api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end context "and current user cannot view the note" do it "should return a 404 error" do get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end context "when issue is confidential" do @@ -155,7 +155,7 @@ describe API::API, api: true do it "returns 404" do get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", private_user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -164,7 +164,7 @@ describe API::API, api: true do it "should return an issue note by id" do get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", private_user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['body']).to eq(cross_reference_note.note) end end @@ -175,14 +175,14 @@ describe API::API, api: true do it "should return a snippet note by id" do get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['body']).to eq(snippet_note.note) end it "should return a 404 error if snippet note not found" do get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/12345", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -192,7 +192,7 @@ describe API::API, api: true do it "should create a new issue note" do post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['body']).to eq('hi!') expect(json_response['author']['username']).to eq(user.username) end @@ -200,13 +200,13 @@ describe API::API, api: true do it "should return a 400 bad request error if body not given" do post api("/projects/#{project.id}/issues/#{issue.id}/notes", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 401 unauthorized error if user not authenticated" do post api("/projects/#{project.id}/issues/#{issue.id}/notes"), body: 'hi!' - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end context 'when an admin or owner makes the request' do @@ -215,7 +215,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!', created_at: creation_time - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['body']).to eq('hi!') expect(json_response['author']['username']).to eq(user.username) expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time) @@ -228,7 +228,7 @@ describe API::API, api: true do it "should create a new snippet note" do post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user), body: 'hi!' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['body']).to eq('hi!') expect(json_response['author']['username']).to eq(user.username) end @@ -236,13 +236,13 @@ describe API::API, api: true do it "should return a 400 bad request error if body not given" do post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 401 unauthorized error if user not authenticated" do post api("/projects/#{project.id}/snippets/#{snippet.id}/notes"), body: 'hi!' - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -282,7 +282,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/issues/#{issue.id}/"\ "notes/#{issue_note.id}", user), body: 'Hello!' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['body']).to eq('Hello!') end @@ -290,14 +290,14 @@ describe API::API, api: true do put api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user), body: 'Hello!' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should return a 400 bad request error if body not given' do put api("/projects/#{project.id}/issues/#{issue.id}/"\ "notes/#{issue_note.id}", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -306,7 +306,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/snippets/#{snippet.id}/"\ "notes/#{snippet_note.id}", user), body: 'Hello!' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['body']).to eq('Hello!') end @@ -314,7 +314,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/snippets/#{snippet.id}/"\ "notes/12345", user), body: "Hello!" - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -323,7 +323,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\ "notes/#{merge_request_note.id}", user), body: 'Hello!' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['body']).to eq('Hello!') end @@ -331,7 +331,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\ "notes/12345", user), body: "Hello!" - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -342,17 +342,17 @@ describe API::API, api: true do delete api("/projects/#{project.id}/issues/#{issue.id}/"\ "notes/#{issue_note.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) # Check if note is really deleted delete api("/projects/#{project.id}/issues/#{issue.id}/"\ "notes/#{issue_note.id}", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'returns a 404 error when note id not found' do delete api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -361,18 +361,18 @@ describe API::API, api: true do delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ "notes/#{snippet_note.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) # Check if note is really deleted delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ "notes/#{snippet_note.id}", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'returns a 404 error when note id not found' do delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ "notes/12345", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -381,18 +381,18 @@ describe API::API, api: true do delete api("/projects/#{project.id}/merge_requests/"\ "#{merge_request.id}/notes/#{merge_request_note.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) # Check if note is really deleted delete api("/projects/#{project.id}/merge_requests/"\ "#{merge_request.id}/notes/#{merge_request_note.id}", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'returns a 404 error when note id not found' do delete api("/projects/#{project.id}/merge_requests/"\ "#{merge_request.id}/notes/12345", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/requests/api/project_hooks_spec.rb b/spec/requests/api/project_hooks_spec.rb index ffb93bbb120..fd1fffa6223 100644 --- a/spec/requests/api/project_hooks_spec.rb +++ b/spec/requests/api/project_hooks_spec.rb @@ -22,7 +22,7 @@ describe API::API, 'ProjectHooks', api: true do context "authorized user" do it "should return project hooks" do get api("/projects/#{project.id}/hooks", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.count).to eq(1) @@ -40,7 +40,7 @@ describe API::API, 'ProjectHooks', api: true do context "unauthorized user" do it "should not access project hooks" do get api("/projects/#{project.id}/hooks", user3) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end end @@ -49,7 +49,7 @@ describe API::API, 'ProjectHooks', api: true do context "authorized user" do it "should return a project hook" do get api("/projects/#{project.id}/hooks/#{hook.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['url']).to eq(hook.url) expect(json_response['issues_events']).to eq(hook.issues_events) expect(json_response['push_events']).to eq(hook.push_events) @@ -61,20 +61,20 @@ describe API::API, 'ProjectHooks', api: true do it "should return a 404 error if hook id is not available" do get api("/projects/#{project.id}/hooks/1234", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end context "unauthorized user" do it "should not access an existing hook" do get api("/projects/#{project.id}/hooks/#{hook.id}", user3) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end it "should return a 404 error if hook id is not available" do get api("/projects/#{project.id}/hooks/1234", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -83,7 +83,7 @@ describe API::API, 'ProjectHooks', api: true do expect do post api("/projects/#{project.id}/hooks", user), url: "http://example.com", issues_events: true end.to change {project.hooks.count}.by(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['url']).to eq('http://example.com') expect(json_response['issues_events']).to eq(true) expect(json_response['push_events']).to eq(true) @@ -96,12 +96,12 @@ describe API::API, 'ProjectHooks', api: true do it "should return a 400 error if url not given" do post api("/projects/#{project.id}/hooks", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 422 error if url not valid" do post api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com" - expect(response.status).to eq(422) + expect(response).to have_http_status(422) end end @@ -109,7 +109,7 @@ describe API::API, 'ProjectHooks', api: true do it "should update an existing project hook" do put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'http://example.org', push_events: false - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['url']).to eq('http://example.org') expect(json_response['issues_events']).to eq(hook.issues_events) expect(json_response['push_events']).to eq(false) @@ -121,17 +121,17 @@ describe API::API, 'ProjectHooks', api: true do it "should return 404 error if hook id not found" do put api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org' - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return 400 error if url is not given" do put api("/projects/#{project.id}/hooks/#{hook.id}", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 422 error if url is not valid" do put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com' - expect(response.status).to eq(422) + expect(response).to have_http_status(422) end end @@ -140,22 +140,22 @@ describe API::API, 'ProjectHooks', api: true do expect do delete api("/projects/#{project.id}/hooks/#{hook.id}", user) end.to change {project.hooks.count}.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return success when deleting hook" do delete api("/projects/#{project.id}/hooks/#{hook.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return a 404 error when deleting non existent hook" do delete api("/projects/#{project.id}/hooks/42", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return a 405 error if hook id not given" do delete api("/projects/#{project.id}/hooks", user) - expect(response.status).to eq(405) + expect(response).to have_http_status(405) end it "shold return a 404 if a user attempts to delete project hooks he/she does not own" do @@ -164,7 +164,7 @@ describe API::API, 'ProjectHooks', api: true do other_project.team << [test_user, :master] delete api("/projects/#{other_project.id}/hooks/#{hook.id}", test_user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(WebHook.exists?(hook.id)).to be_truthy end end diff --git a/spec/requests/api/project_members_spec.rb b/spec/requests/api/project_members_spec.rb index 44b532b10e1..9a7c1da4401 100644 --- a/spec/requests/api/project_members_spec.rb +++ b/spec/requests/api/project_members_spec.rb @@ -15,7 +15,7 @@ describe API::API, api: true do it "should return project team members" do get api("/projects/#{project.id}/members", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.count).to eq(2) expect(json_response.map { |u| u['username'] }).to include user.username @@ -23,7 +23,7 @@ describe API::API, api: true do it "finds team members with query string" do get api("/projects/#{project.id}/members", user), query: user.username - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.count).to eq(1) expect(json_response.first['username']).to eq(user.username) @@ -31,7 +31,7 @@ describe API::API, api: true do it "should return a 404 error if id not found" do get api("/projects/9999/members", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -40,14 +40,14 @@ describe API::API, api: true do it "should return project team member" do get api("/projects/#{project.id}/members/#{user.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['username']).to eq(user.username) expect(json_response['access_level']).to eq(ProjectMember::MASTER) end it "should return a 404 error if user id not found" do get api("/projects/#{project.id}/members/1234", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -57,7 +57,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: ProjectMember::DEVELOPER end.to change { ProjectMember.count }.by(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['username']).to eq(user2.username) expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER) end @@ -70,24 +70,24 @@ describe API::API, api: true do post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: ProjectMember::DEVELOPER end.not_to change { ProjectMember.count } - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['username']).to eq(user2.username) expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER) end it "should return a 400 error when user id is not given" do post api("/projects/#{project.id}/members", user), access_level: ProjectMember::MASTER - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 400 error when access level is not given" do post api("/projects/#{project.id}/members", user), user_id: user2.id - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 422 error when access level is not known" do post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: 1234 - expect(response.status).to eq(422) + expect(response).to have_http_status(422) end end @@ -96,24 +96,24 @@ describe API::API, api: true do it "should update project team member" do put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: ProjectMember::MASTER - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['username']).to eq(user3.username) expect(json_response['access_level']).to eq(ProjectMember::MASTER) end it "should return a 404 error if user_id is not found" do put api("/projects/#{project.id}/members/1234", user), access_level: ProjectMember::MASTER - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return a 400 error when access level is not given" do put api("/projects/#{project.id}/members/#{user3.id}", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should return a 422 error when access level is not known" do put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: 123 - expect(response.status).to eq(422) + expect(response).to have_http_status(422) end end @@ -134,20 +134,20 @@ describe API::API, api: true do expect do delete api("/projects/#{project.id}/members/#{user3.id}", user) end.not_to change { ProjectMember.count } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return 200 if team member already removed" do delete api("/projects/#{project.id}/members/#{user3.id}", user) delete api("/projects/#{project.id}/members/#{user3.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return 200 OK when the user was not member" do expect do delete api("/projects/#{project.id}/members/1000000", user) end.to change { ProjectMember.count }.by(0) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['id']).to eq(1000000) expect(json_response['message']).to eq('Access revoked') end @@ -158,7 +158,7 @@ describe API::API, api: true do delete api("/projects/#{project.id}/members/#{user3.id}", user3) end.to change { ProjectMember.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['id']).to eq(project_member2.id) end end diff --git a/spec/requests/api/project_snippets_spec.rb b/spec/requests/api/project_snippets_spec.rb index 9706d060cfa..4ebde201941 100644 --- a/spec/requests/api/project_snippets_spec.rb +++ b/spec/requests/api/project_snippets_spec.rb @@ -27,7 +27,7 @@ describe API::API, api: true do get api("/projects/#{project.id}/snippets/", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response.size).to eq(3) expect(json_response.map{ |snippet| snippet['id']} ).to include(public_snippet.id, internal_snippet.id, private_snippet.id) end @@ -38,7 +38,7 @@ describe API::API, api: true do create(:project_snippet, :private, project: project) get api("/projects/#{project.id}/snippets/", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response.size).to eq(0) end end @@ -56,7 +56,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/snippets/", admin), params - expect(response.status).to eq(201) + expect(response).to have_http_status(201) snippet = ProjectSnippet.find(json_response['id']) expect(snippet.content).to eq(params[:code]) expect(snippet.title).to eq(params[:title]) @@ -73,7 +73,7 @@ describe API::API, api: true do put api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin), code: new_content - expect(response.status).to eq(200) + expect(response).to have_http_status(200) snippet.reload expect(snippet.content).to eq(new_content) end @@ -86,7 +86,7 @@ describe API::API, api: true do delete api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -97,7 +97,7 @@ describe API::API, api: true do get api("/projects/#{snippet.project.id}/snippets/#{snippet.id}/raw", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response.content_type).to eq 'text/plain' expect(response.body).to eq(snippet.content) end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 01eb4b44b83..41b5ed9bc33 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -45,14 +45,14 @@ describe API::API, api: true do context 'when unauthenticated' do it 'should return authentication error' do get api('/projects') - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context 'when authenticated' do it 'should return an array of projects' do get api('/projects', user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['name']).to eq(project.name) expect(json_response.first['owner']['username']).to eq(user.username) @@ -84,7 +84,7 @@ describe API::API, api: true do context 'and using search' do it 'should return searched project' do get api('/projects', user), { search: project.name } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) end @@ -93,21 +93,21 @@ describe API::API, api: true do context 'and using the visibility filter' do it 'should filter based on private visibility param' do get api('/projects', user), { visibility: 'private' } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(user.namespace.projects.where(visibility_level: Gitlab::VisibilityLevel::PRIVATE).count) end it 'should filter based on internal visibility param' do get api('/projects', user), { visibility: 'internal' } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(user.namespace.projects.where(visibility_level: Gitlab::VisibilityLevel::INTERNAL).count) end it 'should filter based on public visibility param' do get api('/projects', user), { visibility: 'public' } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.length).to eq(user.namespace.projects.where(visibility_level: Gitlab::VisibilityLevel::PUBLIC).count) end @@ -121,7 +121,7 @@ describe API::API, api: true do it 'should return the correct order when sorted by id' do get api('/projects', user), { order_by: 'id', sort: 'desc' } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['id']).to eq(project3.id) end @@ -135,21 +135,21 @@ describe API::API, api: true do context 'when unauthenticated' do it 'should return authentication error' do get api('/projects/all') - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context 'when authenticated as regular user' do it 'should return authentication error' do get api('/projects/all', user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end context 'when authenticated as admin' do it 'should return an array of all projects' do get api('/projects/all', admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response).to satisfy do |response| @@ -173,7 +173,7 @@ describe API::API, api: true do it 'should return the starred projects viewable by the user' do get api('/projects/starred', user3) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.map { |project| project['id'] }).to contain_exactly(project.id, public_project.id) end @@ -185,25 +185,25 @@ describe API::API, api: true do allow_any_instance_of(User).to receive(:projects_limit_left).and_return(0) expect { post api('/projects', user2), name: 'foo' }. to change {Project.count}.by(0) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end it 'should create new project without path and return 201' do expect { post api('/projects', user), name: 'foo' }. to change { Project.count }.by(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end it 'should create last project before reaching project limit' do allow_any_instance_of(User).to receive(:projects_limit_left).and_return(1) post api('/projects', user2), name: 'foo' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end it 'should not create new project without name and return 400' do expect { post api('/projects', user) }.not_to change { Project.count } - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should assign attributes to project" do @@ -273,7 +273,7 @@ describe API::API, api: true do it 'should not allow a non-admin to use a restricted visibility level' do post api('/projects', user), @project - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['visibility_level'].first).to( match('restricted by your GitLab administrator') ) @@ -295,14 +295,14 @@ describe API::API, api: true do it 'should create new project without path and return 201' do expect { post api("/projects/user/#{user.id}", admin), name: 'foo' }.to change {Project.count}.by(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end it 'should respond with 400 on failure and not project' do expect { post api("/projects/user/#{user.id}", admin) }. not_to change { Project.count } - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['name']).to eq([ 'can\'t be blank', 'is too short (minimum is 0 characters)', @@ -380,7 +380,7 @@ describe API::API, api: true do it "uploads the file and returns its info" do post api("/projects/#{project.id}/uploads", user), file: fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png") - expect(response.status).to be(201) + expect(response).to have_http_status(201) expect(json_response['alt']).to eq("dk") expect(json_response['url']).to start_with("/uploads/") expect(json_response['url']).to end_with("/dk.png") @@ -394,27 +394,27 @@ describe API::API, api: true do it 'should return a project by id' do get api("/projects/#{project.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(project.name) expect(json_response['owner']['username']).to eq(user.username) end it 'should return a project by path name' do get api("/projects/#{project.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(project.name) end it 'should return a 404 error if not found' do get api('/projects/42', user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Project Not Found') end it 'should return a 404 error if user is not a member' do other_user = create(:user) get api("/projects/#{project.id}", other_user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should handle users with dots' do @@ -422,7 +422,7 @@ describe API::API, api: true do project = create(:project, creator_id: dot_user.id, namespace: dot_user.namespace) get api("/projects/#{dot_user.namespace.name}%2F#{project.path}", dot_user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(project.name) end @@ -433,7 +433,7 @@ describe API::API, api: true do it 'contains permission information' do get api("/projects", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response.first['permissions']['project_access']['access_level']). to eq(Gitlab::Access::MASTER) expect(json_response.first['permissions']['group_access']).to be_nil @@ -445,7 +445,7 @@ describe API::API, api: true do project.team << [user, :master] get api("/projects/#{project.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['permissions']['project_access']['access_level']). to eq(Gitlab::Access::MASTER) expect(json_response['permissions']['group_access']).to be_nil @@ -460,7 +460,7 @@ describe API::API, api: true do it 'should set the owner and return 200' do get api("/projects/#{project2.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['permissions']['project_access']).to be_nil expect(json_response['permissions']['group_access']['access_level']). to eq(Gitlab::Access::OWNER) @@ -479,7 +479,7 @@ describe API::API, api: true do get api("/projects/#{project.id}/events", user) end - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(200) } context 'joined event' do let(:json_event) { json_response[1] } @@ -500,14 +500,14 @@ describe API::API, api: true do it 'should return a 404 error if not found' do get api('/projects/42/events', user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Project Not Found') end it 'should return a 404 error if user is not a member' do other_user = create(:user) get api("/projects/#{project.id}/events", other_user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -516,7 +516,7 @@ describe API::API, api: true do it 'should return an array of project snippets' do get api("/projects/#{project.id}/snippets", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['title']).to eq(snippet.title) end @@ -525,13 +525,13 @@ describe API::API, api: true do describe 'GET /projects/:id/snippets/:snippet_id' do it 'should return a project snippet' do get api("/projects/#{project.id}/snippets/#{snippet.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq(snippet.title) end it 'should return a 404 error if snippet id not found' do get api("/projects/#{project.id}/snippets/1234", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -540,7 +540,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/snippets", user), title: 'api test', file_name: 'sample.rb', code: 'test', visibility_level: '0' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['title']).to eq('api test') end @@ -554,7 +554,7 @@ describe API::API, api: true do it 'should update an existing project snippet' do put api("/projects/#{project.id}/snippets/#{snippet.id}", user), code: 'updated code' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq('example') expect(snippet.reload.content).to eq('updated code') end @@ -562,7 +562,7 @@ describe API::API, api: true do it 'should update an existing project snippet with new title' do put api("/projects/#{project.id}/snippets/#{snippet.id}", user), title: 'other api test' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq('other api test') end end @@ -574,24 +574,24 @@ describe API::API, api: true do expect do delete api("/projects/#{project.id}/snippets/#{snippet.id}", user) end.to change { Snippet.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should return 404 when deleting unknown snippet id' do delete api("/projects/#{project.id}/snippets/1234", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end describe 'GET /projects/:id/snippets/:snippet_id/raw' do it 'should get a raw project snippet' do get api("/projects/#{project.id}/snippets/#{snippet.id}/raw", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should return a 404 error if raw project snippet not found' do get api("/projects/#{project.id}/snippets/5555/raw", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -604,7 +604,7 @@ describe API::API, api: true do it 'should return array of ssh keys' do get api("/projects/#{project.id}/keys", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['title']).to eq(deploy_key.title) end @@ -613,20 +613,20 @@ describe API::API, api: true do describe 'GET /projects/:id/keys/:key_id' do it 'should return a single key' do get api("/projects/#{project.id}/keys/#{deploy_key.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['title']).to eq(deploy_key.title) end it 'should return 404 Not Found with invalid ID' do get api("/projects/#{project.id}/keys/404", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end describe 'POST /projects/:id/keys' do it 'should not create an invalid ssh key' do post api("/projects/#{project.id}/keys", user), { title: 'invalid key' } - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['key']).to eq([ 'can\'t be blank', 'is too short (minimum is 0 characters)', @@ -636,7 +636,7 @@ describe API::API, api: true do it 'should not create a key without title' do post api("/projects/#{project.id}/keys", user), key: 'some key' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['title']).to eq([ 'can\'t be blank', 'is too short (minimum is 0 characters)' @@ -662,7 +662,7 @@ describe API::API, api: true do it 'should return 404 Not Found with invalid ID' do delete api("/projects/#{project.id}/keys/404", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -676,13 +676,13 @@ describe API::API, api: true do it "shouldn't available for non admin users" do post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it 'should allow project to be forked from an existing project' do expect(project_fork_target.forked?).not_to be_truthy post api("/projects/#{project_fork_target.id}/fork/#{project_fork_source.id}", admin) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) project_fork_target.reload expect(project_fork_target.forked_from_project.id).to eq(project_fork_source.id) expect(project_fork_target.forked_project_link).not_to be_nil @@ -691,7 +691,7 @@ describe API::API, api: true do it 'should fail if forked_from project which does not exist' do post api("/projects/#{project_fork_target.id}/fork/9999", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should fail with 409 if already forked' do @@ -699,7 +699,7 @@ describe API::API, api: true do project_fork_target.reload expect(project_fork_target.forked_from_project.id).to eq(project_fork_source.id) post api("/projects/#{project_fork_target.id}/fork/#{new_project_fork_source.id}", admin) - expect(response.status).to eq(409) + expect(response).to have_http_status(409) project_fork_target.reload expect(project_fork_target.forked_from_project.id).to eq(project_fork_source.id) expect(project_fork_target.forked?).to be_truthy @@ -710,7 +710,7 @@ describe API::API, api: true do it "shouldn't be visible to users outside group" do delete api("/projects/#{project_fork_target.id}/fork", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end context 'when users belong to project group' do @@ -723,7 +723,7 @@ describe API::API, api: true do it 'should be forbidden to non-owner users' do delete api("/projects/#{project_fork_target.id}/fork", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it 'should make forked project unforked' do @@ -732,7 +732,7 @@ describe API::API, api: true do expect(project_fork_target.forked_from_project).not_to be_nil expect(project_fork_target.forked?).to be_truthy delete api("/projects/#{project_fork_target.id}/fork", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) project_fork_target.reload expect(project_fork_target.forked_from_project).to be_nil expect(project_fork_target.forked?).not_to be_truthy @@ -741,7 +741,7 @@ describe API::API, api: true do it 'should be idempotent if not forked' do expect(project_fork_target.forked_from_project).to be_nil delete api("/projects/#{project_fork_target.id}/fork", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(project_fork_target.reload.forked_from_project).to be_nil end end @@ -799,14 +799,14 @@ describe API::API, api: true do context 'when unauthenticated' do it 'should return authentication error' do get api("/projects/search/#{query}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context 'when authenticated' do it 'should return an array of projects' do get api("/projects/search/#{query}",user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to eq(6) json_response.each {|project| expect(project['name']).to match(/.*query.*/)} @@ -816,7 +816,7 @@ describe API::API, api: true do context 'when authenticated as a different user' do it 'should return matching public projects' do get api("/projects/search/#{query}", user2) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to eq(2) json_response.each {|project| expect(project['name']).to match(/(internal|public) query/)} @@ -838,7 +838,7 @@ describe API::API, api: true do it 'should return authentication error' do project_param = { name: 'bar' } put api("/projects/#{project.id}"), project_param - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -846,7 +846,7 @@ describe API::API, api: true do it 'should update name' do project_param = { name: 'bar' } put api("/projects/#{project.id}", user), project_param - expect(response.status).to eq(200) + expect(response).to have_http_status(200) project_param.each_pair do |k, v| expect(json_response[k.to_s]).to eq(v) end @@ -855,7 +855,7 @@ describe API::API, api: true do it 'should update visibility_level' do project_param = { visibility_level: 20 } put api("/projects/#{project3.id}", user), project_param - expect(response.status).to eq(200) + expect(response).to have_http_status(200) project_param.each_pair do |k, v| expect(json_response[k.to_s]).to eq(v) end @@ -866,7 +866,7 @@ describe API::API, api: true do project_param = { public: false } put api("/projects/#{project3.id}", user), project_param - expect(response.status).to eq(200) + expect(response).to have_http_status(200) project_param.each_pair do |k, v| expect(json_response[k.to_s]).to eq(v) end @@ -876,14 +876,14 @@ describe API::API, api: true do it 'should not update name to existing name' do project_param = { name: project3.name } put api("/projects/#{project.id}", user), project_param - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['name']).to eq(['has already been taken']) end it 'should update path & name to existing path & name in different namespace' do project_param = { path: project4.path, name: project4.name } put api("/projects/#{project3.id}", user), project_param - expect(response.status).to eq(200) + expect(response).to have_http_status(200) project_param.each_pair do |k, v| expect(json_response[k.to_s]).to eq(v) end @@ -894,7 +894,7 @@ describe API::API, api: true do it 'should update path' do project_param = { path: 'bar' } put api("/projects/#{project3.id}", user4), project_param - expect(response.status).to eq(200) + expect(response).to have_http_status(200) project_param.each_pair do |k, v| expect(json_response[k.to_s]).to eq(v) end @@ -908,7 +908,7 @@ describe API::API, api: true do description: 'new description' } put api("/projects/#{project3.id}", user4), project_param - expect(response.status).to eq(200) + expect(response).to have_http_status(200) project_param.each_pair do |k, v| expect(json_response[k.to_s]).to eq(v) end @@ -917,20 +917,20 @@ describe API::API, api: true do it 'should not update path to existing path' do project_param = { path: project.path } put api("/projects/#{project3.id}", user4), project_param - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['path']).to eq(['has already been taken']) end it 'should not update name' do project_param = { name: 'bar' } put api("/projects/#{project3.id}", user4), project_param - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it 'should not update visibility_level' do project_param = { visibility_level: 20 } put api("/projects/#{project3.id}", user4), project_param - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -943,7 +943,7 @@ describe API::API, api: true do merge_requests_enabled: true, description: 'new description' } put api("/projects/#{project.id}", user3), project_param - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end end @@ -953,7 +953,7 @@ describe API::API, api: true do it 'archives the project' do post api("/projects/#{project.id}/archive", user) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['archived']).to be_truthy end end @@ -966,7 +966,7 @@ describe API::API, api: true do it 'remains archived' do post api("/projects/#{project.id}/archive", user) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['archived']).to be_truthy end end @@ -979,7 +979,7 @@ describe API::API, api: true do it 'rejects the action' do post api("/projects/#{project.id}/archive", user3) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end end @@ -989,7 +989,7 @@ describe API::API, api: true do it 'remains unarchived' do post api("/projects/#{project.id}/unarchive", user) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['archived']).to be_falsey end end @@ -1002,7 +1002,7 @@ describe API::API, api: true do it 'unarchives the project' do post api("/projects/#{project.id}/unarchive", user) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['archived']).to be_falsey end end @@ -1015,7 +1015,7 @@ describe API::API, api: true do it 'rejects the action' do post api("/projects/#{project.id}/unarchive", user3) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end end @@ -1025,7 +1025,7 @@ describe API::API, api: true do it 'stars the project' do expect { post api("/projects/#{project.id}/star", user) }.to change { project.reload.star_count }.by(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['star_count']).to eq(1) end end @@ -1039,7 +1039,7 @@ describe API::API, api: true do it 'does not modify the star count' do expect { post api("/projects/#{project.id}/star", user) }.not_to change { project.reload.star_count } - expect(response.status).to eq(304) + expect(response).to have_http_status(304) end end end @@ -1054,7 +1054,7 @@ describe API::API, api: true do it 'unstars the project' do expect { delete api("/projects/#{project.id}/star", user) }.to change { project.reload.star_count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['star_count']).to eq(0) end end @@ -1063,7 +1063,7 @@ describe API::API, api: true do it 'does not modify the star count' do expect { delete api("/projects/#{project.id}/star", user) }.not_to change { project.reload.star_count } - expect(response.status).to eq(304) + expect(response).to have_http_status(304) end end end @@ -1072,36 +1072,36 @@ describe API::API, api: true do context 'when authenticated as user' do it 'should remove project' do delete api("/projects/#{project.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should not remove a project if not an owner' do user3 = create(:user) project.team << [user3, :developer] delete api("/projects/#{project.id}", user3) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it 'should not remove a non existing project' do delete api('/projects/1328', user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should not remove a project not attached to user' do delete api("/projects/#{project.id}", user2) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end context 'when authenticated as admin' do it 'should remove any existing project' do delete api("/projects/#{project.id}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should not remove a non existing project' do delete api('/projects/1328', admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index 7cf4a01d76b..5890e9c9d3d 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -18,7 +18,7 @@ describe API::API, api: true do it "should return project commits" do get api("/projects/#{project.id}/repository/tree", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['name']).to eq('encoding') @@ -28,7 +28,7 @@ describe API::API, api: true do it 'should return a 404 for unknown ref' do get api("/projects/#{project.id}/repository/tree?ref_name=foo", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response).to be_an Object json_response['message'] == '404 Tree Not Found' @@ -38,7 +38,7 @@ describe API::API, api: true do context "unauthorized user" do it "should not return project commits" do get api("/projects/#{project.id}/repository/tree") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -46,41 +46,41 @@ describe API::API, api: true do describe "GET /projects/:id/repository/blobs/:sha" do it "should get the raw file contents" do get api("/projects/#{project.id}/repository/blobs/master?filepath=README.md", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return 404 for invalid branch_name" do get api("/projects/#{project.id}/repository/blobs/invalid_branch_name?filepath=README.md", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return 404 for invalid file" do get api("/projects/#{project.id}/repository/blobs/master?filepath=README.invalid", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return a 400 error if filepath is missing" do get api("/projects/#{project.id}/repository/blobs/master", user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end describe "GET /projects/:id/repository/commits/:sha/blob" do it "should get the raw file contents" do get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end describe "GET /projects/:id/repository/raw_blobs/:sha" do it "should get the raw file contents" do get api("/projects/#{project.id}/repository/raw_blobs/#{sample_blob.oid}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should return a 404 for unknown blob' do get api("/projects/#{project.id}/repository/raw_blobs/123456", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response).to be_an Object json_response['message'] == '404 Blob Not Found' @@ -91,7 +91,7 @@ describe API::API, api: true do it "should get the archive" do get api("/projects/#{project.id}/repository/archive", user) repo_name = project.repository.name.gsub("\.git", "") - expect(response.status).to eq(200) + expect(response).to have_http_status(200) type, params = workhorse_send_data expect(type).to eq('git-archive') expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.gz/) @@ -100,7 +100,7 @@ describe API::API, api: true do it "should get the archive.zip" do get api("/projects/#{project.id}/repository/archive.zip", user) repo_name = project.repository.name.gsub("\.git", "") - expect(response.status).to eq(200) + expect(response).to have_http_status(200) type, params = workhorse_send_data expect(type).to eq('git-archive') expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/) @@ -109,7 +109,7 @@ describe API::API, api: true do it "should get the archive.tar.bz2" do get api("/projects/#{project.id}/repository/archive.tar.bz2", user) repo_name = project.repository.name.gsub("\.git", "") - expect(response.status).to eq(200) + expect(response).to have_http_status(200) type, params = workhorse_send_data expect(type).to eq('git-archive') expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.bz2/) @@ -117,28 +117,28 @@ describe API::API, api: true do it "should return 404 for invalid sha" do get api("/projects/#{project.id}/repository/archive/?sha=xxx", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end describe 'GET /projects/:id/repository/compare' do it "should compare branches" do get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'feature' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['commits']).to be_present expect(json_response['diffs']).to be_present end it "should compare tags" do get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.0', to: 'v1.1.0' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['commits']).to be_present expect(json_response['diffs']).to be_present end it "should compare commits" do get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.id, to: sample_commit.parent_id - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['commits']).to be_empty expect(json_response['diffs']).to be_empty expect(json_response['compare_same_ref']).to be_falsey @@ -146,14 +146,14 @@ describe API::API, api: true do it "should compare commits in reverse order" do get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.parent_id, to: sample_commit.id - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['commits']).to be_present expect(json_response['diffs']).to be_present end it "should compare same refs" do get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'master' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['commits']).to be_empty expect(json_response['diffs']).to be_empty expect(json_response['compare_same_ref']).to be_truthy @@ -163,7 +163,7 @@ describe API::API, api: true do describe 'GET /projects/:id/repository/contributors' do it 'should return valid data' do get api("/projects/#{project.id}/repository/contributors", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array contributor = json_response.first expect(contributor['email']).to eq('dmitriy.zaporozhets@gmail.com') diff --git a/spec/requests/api/runners_spec.rb b/spec/requests/api/runners_spec.rb index b4c826522a5..00a3c917b6a 100644 --- a/spec/requests/api/runners_spec.rb +++ b/spec/requests/api/runners_spec.rb @@ -39,7 +39,7 @@ describe API::Runners, api: true do get api('/runners', user) shared = json_response.any?{ |r| r['is_shared'] } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(shared).to be_falsey end @@ -48,14 +48,14 @@ describe API::Runners, api: true do get api('/runners?scope=active', user) shared = json_response.any?{ |r| r['is_shared'] } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(shared).to be_falsey end it 'should avoid filtering if scope is invalid' do get api('/runners?scope=unknown', user) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -63,7 +63,7 @@ describe API::Runners, api: true do it 'should not return runners' do get api('/runners') - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -75,7 +75,7 @@ describe API::Runners, api: true do get api('/runners/all', admin) shared = json_response.any?{ |r| r['is_shared'] } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(shared).to be_truthy end @@ -85,7 +85,7 @@ describe API::Runners, api: true do it 'should not return runners list' do get api('/runners/all', user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -93,14 +93,14 @@ describe API::Runners, api: true do get api('/runners/all?scope=specific', admin) shared = json_response.any?{ |r| r['is_shared'] } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(shared).to be_falsey end it 'should avoid filtering if scope is invalid' do get api('/runners?scope=unknown', admin) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -108,7 +108,7 @@ describe API::Runners, api: true do it 'should not return runners' do get api('/runners') - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -119,7 +119,7 @@ describe API::Runners, api: true do it "should return runner's details" do get api("/runners/#{shared_runner.id}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['description']).to eq(shared_runner.description) end end @@ -128,7 +128,7 @@ describe API::Runners, api: true do it "should return runner's details" do get api("/runners/#{specific_runner.id}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['description']).to eq(specific_runner.description) end end @@ -136,7 +136,7 @@ describe API::Runners, api: true do it 'should return 404 if runner does not exists' do get api('/runners/9999', admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -145,7 +145,7 @@ describe API::Runners, api: true do it "should return runner's details" do get api("/runners/#{specific_runner.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['description']).to eq(specific_runner.description) end end @@ -154,7 +154,7 @@ describe API::Runners, api: true do it "should return runner's details" do get api("/runners/#{shared_runner.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['description']).to eq(shared_runner.description) end end @@ -164,7 +164,7 @@ describe API::Runners, api: true do it "should not return runner's details" do get api("/runners/#{specific_runner.id}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -172,7 +172,7 @@ describe API::Runners, api: true do it "should not return runner's details" do get api("/runners/#{specific_runner.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -191,7 +191,7 @@ describe API::Runners, api: true do locked: 'true') shared_runner.reload - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(shared_runner.description).to eq("#{description}_updated") expect(shared_runner.active).to eq(!active) expect(shared_runner.tag_list).to include('ruby2.1', 'pgsql', 'mysql') @@ -206,7 +206,7 @@ describe API::Runners, api: true do update_runner(specific_runner.id, admin, description: 'test') specific_runner.reload - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(specific_runner.description).to eq('test') expect(specific_runner.description).not_to eq(description) end @@ -215,7 +215,7 @@ describe API::Runners, api: true do it 'should return 404 if runner does not exists' do update_runner(9999, admin, description: 'test') - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end def update_runner(id, user, args) @@ -228,7 +228,7 @@ describe API::Runners, api: true do it 'should not update runner' do put api("/runners/#{shared_runner.id}", user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -236,7 +236,7 @@ describe API::Runners, api: true do it 'should not update runner without access to it' do put api("/runners/#{specific_runner.id}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it 'should update runner with access to it' do @@ -244,7 +244,7 @@ describe API::Runners, api: true do put api("/runners/#{specific_runner.id}", admin), description: 'test' specific_runner.reload - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(specific_runner.description).to eq('test') expect(specific_runner.description).not_to eq(description) end @@ -255,7 +255,7 @@ describe API::Runners, api: true do it 'should not delete runner' do put api("/runners/#{specific_runner.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -267,7 +267,7 @@ describe API::Runners, api: true do expect do delete api("/runners/#{shared_runner.id}", admin) end.to change{ Ci::Runner.shared.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -276,21 +276,21 @@ describe API::Runners, api: true do expect do delete api("/runners/#{unused_specific_runner.id}", admin) end.to change{ Ci::Runner.specific.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should delete used runner' do expect do delete api("/runners/#{specific_runner.id}", admin) end.to change{ Ci::Runner.specific.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end it 'should return 404 if runner does not exists' do delete api('/runners/9999', admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -298,26 +298,26 @@ describe API::Runners, api: true do context 'when runner is shared' do it 'should not delete runner' do delete api("/runners/#{shared_runner.id}", user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end context 'when runner is not shared' do it 'should not delete runner without access to it' do delete api("/runners/#{specific_runner.id}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it 'should not delete runner with more than one associated project' do delete api("/runners/#{two_projects_runner.id}", user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it 'should delete runner for one owned project' do expect do delete api("/runners/#{specific_runner.id}", user) end.to change{ Ci::Runner.specific.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -326,7 +326,7 @@ describe API::Runners, api: true do it 'should not delete runner' do delete api("/runners/#{specific_runner.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -337,7 +337,7 @@ describe API::Runners, api: true do get api("/projects/#{project.id}/runners", user) shared = json_response.any?{ |r| r['is_shared'] } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(shared).to be_truthy end @@ -347,7 +347,7 @@ describe API::Runners, api: true do it "should not return project's runners" do get api("/projects/#{project.id}/runners", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -355,7 +355,7 @@ describe API::Runners, api: true do it "should not return project's runners" do get api("/projects/#{project.id}/runners") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -372,14 +372,14 @@ describe API::Runners, api: true do expect do post api("/projects/#{project.id}/runners", user), runner_id: specific_runner2.id end.to change{ project.runners.count }.by(+1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end it 'should avoid changes when enabling already enabled runner' do expect do post api("/projects/#{project.id}/runners", user), runner_id: specific_runner.id end.to change{ project.runners.count }.by(0) - expect(response.status).to eq(409) + expect(response).to have_http_status(409) end it 'should not enable locked runner' do @@ -389,13 +389,13 @@ describe API::Runners, api: true do post api("/projects/#{project.id}/runners", user), runner_id: specific_runner2.id end.to change{ project.runners.count }.by(0) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it 'should not enable shared runner' do post api("/projects/#{project.id}/runners", user), runner_id: shared_runner.id - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end context 'user is admin' do @@ -403,7 +403,7 @@ describe API::Runners, api: true do expect do post api("/projects/#{project.id}/runners", admin), runner_id: unused_specific_runner.id end.to change{ project.runners.count }.by(+1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end end @@ -411,14 +411,14 @@ describe API::Runners, api: true do it 'should not enable runner without access to' do post api("/projects/#{project.id}/runners", user), runner_id: unused_specific_runner.id - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end it 'should raise an error when no runner_id param is provided' do post api("/projects/#{project.id}/runners", admin) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -426,7 +426,7 @@ describe API::Runners, api: true do it 'should not enable runner' do post api("/projects/#{project.id}/runners", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -434,7 +434,7 @@ describe API::Runners, api: true do it 'should not enable runner' do post api("/projects/#{project.id}/runners") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -446,7 +446,7 @@ describe API::Runners, api: true do expect do delete api("/projects/#{project.id}/runners/#{two_projects_runner.id}", user) end.to change{ project.runners.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -455,14 +455,14 @@ describe API::Runners, api: true do expect do delete api("/projects/#{project.id}/runners/#{specific_runner.id}", user) end.to change{ project.runners.count }.by(0) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end it 'should return 404 is runner is not found' do delete api("/projects/#{project.id}/runners/9999", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -470,7 +470,7 @@ describe API::Runners, api: true do it "should not disable project's runner" do delete api("/projects/#{project.id}/runners/#{specific_runner.id}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -478,7 +478,7 @@ describe API::Runners, api: true do it "should not disable project's runner" do delete api("/projects/#{project.id}/runners/#{specific_runner.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index fed9ae1949b..bf7eaaaaaed 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -14,7 +14,7 @@ describe API::API, api: true do it "should update #{service} settings" do put api("/projects/#{project.id}/services/#{dashed_service}", user), service_attrs - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return if required fields missing" do @@ -45,7 +45,7 @@ describe API::API, api: true do it "should delete #{service}" do delete api("/projects/#{project.id}/services/#{dashed_service}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) project.send(service_method).reload expect(project.send(service_method).activated?).to be_falsey end @@ -64,20 +64,20 @@ describe API::API, api: true do it 'should return authentication error when unauthenticated' do get api("/projects/#{project.id}/services/#{dashed_service}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end it "should return all properties of service #{service} when authenticated as admin" do get api("/projects/#{project.id}/services/#{dashed_service}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list.map) end it "should return properties of service #{service} other than passwords when authenticated as project owner" do get api("/projects/#{project.id}/services/#{dashed_service}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['properties'].keys.map(&:to_sym)).to match_array(service_attrs_list_without_passwords) end @@ -85,7 +85,7 @@ describe API::API, api: true do project.team << [user2, :developer] get api("/projects/#{project.id}/services/#{dashed_service}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end diff --git a/spec/requests/api/session_spec.rb b/spec/requests/api/session_spec.rb index fbd57b34a58..c15b7ff9792 100644 --- a/spec/requests/api/session_spec.rb +++ b/spec/requests/api/session_spec.rb @@ -9,7 +9,7 @@ describe API::API, api: true do context "when valid password" do it "should return private token" do post api("/session"), email: user.email, password: '12345678' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['email']).to eq(user.email) expect(json_response['private_token']).to eq(user.private_token) @@ -48,7 +48,7 @@ describe API::API, api: true do context "when invalid password" do it "should return authentication error" do post api("/session"), email: user.email, password: '123' - expect(response.status).to eq(401) + expect(response).to have_http_status(401) expect(json_response['email']).to be_nil expect(json_response['private_token']).to be_nil @@ -58,7 +58,7 @@ describe API::API, api: true do context "when empty password" do it "should return authentication error" do post api("/session"), email: user.email - expect(response.status).to eq(401) + expect(response).to have_http_status(401) expect(json_response['email']).to be_nil expect(json_response['private_token']).to be_nil @@ -68,7 +68,7 @@ describe API::API, api: true do context "when empty name" do it "should return authentication error" do post api("/session"), password: user.password - expect(response.status).to eq(401) + expect(response).to have_http_status(401) expect(json_response['email']).to be_nil expect(json_response['private_token']).to be_nil diff --git a/spec/requests/api/settings_spec.rb b/spec/requests/api/settings_spec.rb index c815a8e1d73..f756101c514 100644 --- a/spec/requests/api/settings_spec.rb +++ b/spec/requests/api/settings_spec.rb @@ -10,7 +10,7 @@ describe API::API, 'Settings', api: true do describe "GET /application/settings" do it "should return application settings" do get api("/application/settings", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Hash expect(json_response['default_projects_limit']).to eq(42) expect(json_response['signin_enabled']).to be_truthy @@ -21,7 +21,7 @@ describe API::API, 'Settings', api: true do it "should update application settings" do put api("/application/settings", admin), default_projects_limit: 3, signin_enabled: false - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['default_projects_limit']).to eq(3) expect(json_response['signin_enabled']).to be_falsey end diff --git a/spec/requests/api/sidekiq_metrics_spec.rb b/spec/requests/api/sidekiq_metrics_spec.rb index 41cbf0c6669..28067f8ca88 100644 --- a/spec/requests/api/sidekiq_metrics_spec.rb +++ b/spec/requests/api/sidekiq_metrics_spec.rb @@ -9,28 +9,28 @@ describe API::SidekiqMetrics, api: true do it 'defines the `queue_metrics` endpoint' do get api('/sidekiq/queue_metrics', admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_a Hash end it 'defines the `process_metrics` endpoint' do get api('/sidekiq/process_metrics', admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['processes']).to be_an Array end it 'defines the `job_stats` endpoint' do get api('/sidekiq/job_stats', admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_a Hash end it 'defines the `compound_metrics` endpoint' do get api('/sidekiq/compound_metrics', admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_a Hash expect(json_response['queues']).to be_a Hash expect(json_response['processes']).to be_an Array diff --git a/spec/requests/api/system_hooks_spec.rb b/spec/requests/api/system_hooks_spec.rb index 94eebc48ec8..cf66f261ade 100644 --- a/spec/requests/api/system_hooks_spec.rb +++ b/spec/requests/api/system_hooks_spec.rb @@ -13,21 +13,21 @@ describe API::API, api: true do context "when no user" do it "should return authentication error" do get api("/hooks") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context "when not an admin" do it "should return forbidden error" do get api("/hooks", user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end context "when authenticated as admin" do it "should return an array of hooks" do get api("/hooks", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['url']).to eq(hook.url) end @@ -43,7 +43,7 @@ describe API::API, api: true do it "should respond with 400 if url not given" do post api("/hooks", admin) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it "should not create new hook without url" do @@ -56,13 +56,13 @@ describe API::API, api: true do describe "GET /hooks/:id" do it "should return hook by id" do get api("/hooks/#{hook.id}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['event_name']).to eq('project_create') end it "should return 404 on failure" do get api("/hooks/404", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -75,7 +75,7 @@ describe API::API, api: true do it "should return success if hook id not found" do delete api("/hooks/12345", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb index 12e170b232f..fa700ab7343 100644 --- a/spec/requests/api/tags_spec.rb +++ b/spec/requests/api/tags_spec.rb @@ -18,7 +18,7 @@ describe API::API, api: true do context 'without releases' do it "should return an array of project tags" do get api("/projects/#{project.id}/repository/tags", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['name']).to eq(tag_name) end @@ -33,7 +33,7 @@ describe API::API, api: true do it "should return an array of project tags with release info" do get api("/projects/#{project.id}/repository/tags", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['name']).to eq(tag_name) expect(json_response.first['message']).to eq('Version 1.1.0') @@ -48,14 +48,14 @@ describe API::API, api: true do it 'returns a specific tag' do get api("/projects/#{project.id}/repository/tags/#{tag_name}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['name']).to eq(tag_name) end it 'returns 404 for an invalid tag name' do get api("/projects/#{project.id}/repository/tags/foobar", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -66,7 +66,7 @@ describe API::API, api: true do tag_name: 'v7.0.1', ref: 'master' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['name']).to eq('v7.0.1') end end @@ -78,7 +78,7 @@ describe API::API, api: true do ref: 'master', release_description: 'Wow' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['name']).to eq('v7.0.1') expect(json_response['release']['description']).to eq('Wow') end @@ -94,13 +94,13 @@ describe API::API, api: true do context 'delete tag' do it 'should delete an existing tag' do delete api("/projects/#{project.id}/repository/tags/#{tag_name}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['tag_name']).to eq(tag_name) end it 'should raise 404 if the tag does not exist' do delete api("/projects/#{project.id}/repository/tags/foobar", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -117,7 +117,7 @@ describe API::API, api: true do ref: 'master', message: 'Release 7.1.0' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['name']).to eq('v7.1.0') expect(json_response['message']).to eq('Release 7.1.0') end @@ -127,14 +127,14 @@ describe API::API, api: true do post api("/projects/#{project.id}/repository/tags", user2), tag_name: 'v1.9.0', ref: '621491c677087aa243f165eab467bfdfbee00be1' - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it 'should return 400 if tag name is invalid' do post api("/projects/#{project.id}/repository/tags", user), tag_name: 'v 1.0.0', ref: 'master' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('Tag name invalid') end @@ -142,11 +142,11 @@ describe API::API, api: true do post api("/projects/#{project.id}/repository/tags", user), tag_name: 'v8.0.0', ref: 'master' - expect(response.status).to eq(201) + expect(response).to have_http_status(201) post api("/projects/#{project.id}/repository/tags", user), tag_name: 'v8.0.0', ref: 'master' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('Tag v8.0.0 already exists') end @@ -154,7 +154,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/repository/tags", user), tag_name: 'mytag', ref: 'foo' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('Target foo is invalid') end end @@ -167,7 +167,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user), description: description - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['tag_name']).to eq(tag_name) expect(json_response['description']).to eq(description) end @@ -176,7 +176,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/repository/tags/foobar/release", user), description: description - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('Tag does not exist') end @@ -190,7 +190,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user), description: description - expect(response.status).to eq(409) + expect(response).to have_http_status(409) expect(json_response['message']).to eq('Release already exists') end end @@ -211,7 +211,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user), description: new_description - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['tag_name']).to eq(tag_name) expect(json_response['description']).to eq(new_description) end @@ -221,7 +221,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/repository/tags/foobar/release", user), description: new_description - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('Tag does not exist') end @@ -229,7 +229,7 @@ describe API::API, api: true do put api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user), description: new_description - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('Release does not exist') end end diff --git a/spec/requests/api/templates_spec.rb b/spec/requests/api/templates_spec.rb index a6d5ade3013..68d0f41b489 100644 --- a/spec/requests/api/templates_spec.rb +++ b/spec/requests/api/templates_spec.rb @@ -22,7 +22,7 @@ describe API::Templates, api: true do it 'returns a list of available gitignore templates' do get api('/gitignores') - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.size).to be > 15 end @@ -34,7 +34,7 @@ describe API::Templates, api: true do it 'returns a list of available gitlab_ci_ymls' do get api('/gitlab_ci_ymls') - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['name']).not_to be_nil end @@ -45,7 +45,7 @@ describe API::Templates, api: true do it 'adds a disclaimer on the top' do get api('/gitlab_ci_ymls/Ruby') - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['content']).to start_with("# This file is a template,") end end diff --git a/spec/requests/api/triggers_spec.rb b/spec/requests/api/triggers_spec.rb index fdd4ec6d761..8992996c30a 100644 --- a/spec/requests/api/triggers_spec.rb +++ b/spec/requests/api/triggers_spec.rb @@ -29,17 +29,17 @@ describe API::API do context 'Handles errors' do it 'should return bad request if token is missing' do post api("/projects/#{project.id}/trigger/builds"), ref: 'master' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return not found if project is not found' do post api('/projects/0/trigger/builds'), options.merge(ref: 'master') - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should return unauthorized if token is for different project' do post api("/projects/#{project2.id}/trigger/builds"), options.merge(ref: 'master') - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -48,14 +48,14 @@ describe API::API do it 'should create builds' do post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'master') - expect(response.status).to eq(201) + expect(response).to have_http_status(201) pipeline.builds.reload expect(pipeline.builds.size).to eq(2) end it 'should return bad request with no builds created if there\'s no commit for that ref' do post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'other-branch') - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('No builds created') end @@ -66,19 +66,19 @@ describe API::API do it 'should validate variables to be a hash' do post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: 'value', ref: 'master') - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('variables needs to be a hash') end it 'should validate variables needs to be a map of key-valued strings' do post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: { key: %w(1 2) }, ref: 'master') - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('variables needs to be a map of key-valued strings') end it 'create trigger request with variables' do post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: variables, ref: 'master') - expect(response.status).to eq(201) + expect(response).to have_http_status(201) pipeline.builds.reload expect(pipeline.builds.first.trigger_request.variables).to eq(variables) end @@ -91,7 +91,7 @@ describe API::API do it 'should return list of triggers' do get api("/projects/#{project.id}/triggers", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_a(Array) expect(json_response[0]).to have_key('token') end @@ -101,7 +101,7 @@ describe API::API do it 'should not return triggers list' do get api("/projects/#{project.id}/triggers", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -109,7 +109,7 @@ describe API::API do it 'should not return triggers list' do get api("/projects/#{project.id}/triggers") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -119,14 +119,14 @@ describe API::API do it 'should return trigger details' do get api("/projects/#{project.id}/triggers/#{trigger.token}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_a(Hash) end it 'should respond with 404 Not Found if requesting non-existing trigger' do get api("/projects/#{project.id}/triggers/abcdef012345", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -134,7 +134,7 @@ describe API::API do it 'should not return triggers list' do get api("/projects/#{project.id}/triggers/#{trigger.token}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -142,7 +142,7 @@ describe API::API do it 'should not return triggers list' do get api("/projects/#{project.id}/triggers/#{trigger.token}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -154,7 +154,7 @@ describe API::API do post api("/projects/#{project.id}/triggers", user) end.to change{project.triggers.count}.by(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response).to be_a(Hash) end end @@ -163,7 +163,7 @@ describe API::API do it 'should not create trigger' do post api("/projects/#{project.id}/triggers", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -171,7 +171,7 @@ describe API::API do it 'should not create trigger' do post api("/projects/#{project.id}/triggers") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -182,13 +182,13 @@ describe API::API do expect do delete api("/projects/#{project.id}/triggers/#{trigger.token}", user) end.to change{project.triggers.count}.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should respond with 404 Not Found if requesting non-existing trigger' do delete api("/projects/#{project.id}/triggers/abcdef012345", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -196,7 +196,7 @@ describe API::API do it 'should not delete trigger' do delete api("/projects/#{project.id}/triggers/#{trigger.token}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -204,7 +204,7 @@ describe API::API do it 'should not delete trigger' do delete api("/projects/#{project.id}/triggers/#{trigger.token}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index a7690f430c4..056256a29f5 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -15,7 +15,7 @@ describe API::API, api: true do context "when unauthenticated" do it "should return authentication error" do get api("/users") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -29,18 +29,18 @@ describe API::API, api: true do it "renders 403" do get api("/users") - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it "renders 404" do get api("/users/#{user.id}") - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end it "should return an array of users" do get api("/users", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array username = user.username expect(json_response.detect do |user| @@ -50,7 +50,7 @@ describe API::API, api: true do it "should return one user" do get api("/users?username=#{omniauth_user.username}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['username']).to eq(omniauth_user.username) end @@ -59,7 +59,7 @@ describe API::API, api: true do context "when admin" do it "should return an array of users" do get api("/users", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first.keys).to include 'email' expect(json_response.first.keys).to include 'identities' @@ -74,24 +74,24 @@ describe API::API, api: true do describe "GET /users/:id" do it "should return a user by id" do get api("/users/#{user.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['username']).to eq(user.username) end it "should return a 401 if unauthenticated" do get api("/users/9998") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end it "should return a 404 error if user id not found" do get api("/users/9999", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Not found') end it "should return a 404 if invalid ID" do get api("/users/1ASDF", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -106,7 +106,7 @@ describe API::API, api: true do it "should create user with correct attributes" do post api('/users', admin), attributes_for(:user, admin: true, can_create_group: true) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) user_id = json_response['id'] new_user = User.find(user_id) expect(new_user).not_to eq(nil) @@ -116,7 +116,7 @@ describe API::API, api: true do it "should create non-admin user" do post api('/users', admin), attributes_for(:user, admin: false, can_create_group: false) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) user_id = json_response['id'] new_user = User.find(user_id) expect(new_user).not_to eq(nil) @@ -126,7 +126,7 @@ describe API::API, api: true do it "should create non-admin users by default" do post api('/users', admin), attributes_for(:user) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) user_id = json_response['id'] new_user = User.find(user_id) expect(new_user).not_to eq(nil) @@ -135,12 +135,12 @@ describe API::API, api: true do it "should return 201 Created on success" do post api("/users", admin), attributes_for(:user, projects_limit: 3) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end it 'creates non-external users by default' do post api("/users", admin), attributes_for(:user) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) user_id = json_response['id'] new_user = User.find(user_id) @@ -150,7 +150,7 @@ describe API::API, api: true do it 'should allow an external user to be created' do post api("/users", admin), attributes_for(:user, external: true) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) user_id = json_response['id'] new_user = User.find(user_id) @@ -163,27 +163,27 @@ describe API::API, api: true do email: 'invalid email', password: 'password', name: 'test' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return 400 error if name not given' do post api('/users', admin), attributes_for(:user).except(:name) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return 400 error if password not given' do post api('/users', admin), attributes_for(:user).except(:password) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return 400 error if email not given' do post api('/users', admin), attributes_for(:user).except(:email) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return 400 error if username not given' do post api('/users', admin), attributes_for(:user).except(:username) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return 400 error if user does not validate' do @@ -194,7 +194,7 @@ describe API::API, api: true do name: 'test', bio: 'g' * 256, projects_limit: -1 - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['password']). to eq(['is too short (minimum is 8 characters)']) expect(json_response['message']['bio']). @@ -207,7 +207,7 @@ describe API::API, api: true do it "shouldn't available for non admin users" do post api("/users", user), attributes_for(:user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end context 'with existing user' do @@ -227,7 +227,7 @@ describe API::API, api: true do password: 'password', username: 'foo' end.to change { User.count }.by(0) - expect(response.status).to eq(409) + expect(response).to have_http_status(409) expect(json_response['message']).to eq('Email has already been taken') end @@ -239,7 +239,7 @@ describe API::API, api: true do password: 'password', username: 'test' end.to change { User.count }.by(0) - expect(response.status).to eq(409) + expect(response).to have_http_status(409) expect(json_response['message']).to eq('Username has already been taken') end end @@ -249,7 +249,7 @@ describe API::API, api: true do it "should redirect to sign in page" do get "/users/sign_up" - expect(response.status).to eq(302) + expect(response).to have_http_status(302) expect(response).to redirect_to(new_user_session_path) end end @@ -261,41 +261,41 @@ describe API::API, api: true do it "should update user with new bio" do put api("/users/#{user.id}", admin), { bio: 'new test bio' } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['bio']).to eq('new test bio') expect(user.reload.bio).to eq('new test bio') end it 'should update user with his own email' do put api("/users/#{user.id}", admin), email: user.email - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['email']).to eq(user.email) expect(user.reload.email).to eq(user.email) end it 'should update user with his own username' do put api("/users/#{user.id}", admin), username: user.username - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['username']).to eq(user.username) expect(user.reload.username).to eq(user.username) end it "should update user's existing identity" do put api("/users/#{omniauth_user.id}", admin), provider: 'ldapmain', extern_uid: '654321' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(omniauth_user.reload.identities.first.extern_uid).to eq('654321') end it 'should update user with new identity' do put api("/users/#{user.id}", admin), provider: 'github', extern_uid: '67890' - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(user.reload.identities.first.extern_uid).to eq('67890') expect(user.reload.identities.first.provider).to eq('github') end it "should update admin status" do put api("/users/#{user.id}", admin), { admin: true } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['is_admin']).to eq(true) expect(user.reload.admin).to eq(true) end @@ -309,7 +309,7 @@ describe API::API, api: true do it "should not update admin status" do put api("/users/#{admin_user.id}", admin), { can_create_group: false } - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['is_admin']).to eq(true) expect(admin_user.reload.admin).to eq(true) expect(admin_user.can_create_group).to eq(false) @@ -317,18 +317,18 @@ describe API::API, api: true do it "should not allow invalid update" do put api("/users/#{user.id}", admin), { email: 'invalid email' } - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(user.reload.email).not_to eq('invalid email') end it "shouldn't available for non admin users" do put api("/users/#{user.id}", user), attributes_for(:user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it "should return 404 for non-existing user" do put api("/users/999999", admin), { bio: 'update should fail' } - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Not found') end @@ -344,7 +344,7 @@ describe API::API, api: true do name: 'test', bio: 'g' * 256, projects_limit: -1 - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']['password']). to eq(['is too short (minimum is 8 characters)']) expect(json_response['message']['bio']). @@ -364,14 +364,14 @@ describe API::API, api: true do it 'should return 409 conflict error if email address exists' do put api("/users/#{@user.id}", admin), email: 'test@example.com' - expect(response.status).to eq(409) + expect(response).to have_http_status(409) expect(@user.reload.email).to eq(@user.email) end it 'should return 409 conflict error if username taken' do @user_id = User.all.last.id put api("/users/#{@user.id}", admin), username: 'test' - expect(response.status).to eq(409) + expect(response).to have_http_status(409) expect(@user.reload.username).to eq(@user.username) end end @@ -382,13 +382,13 @@ describe API::API, api: true do it "should not create invalid ssh key" do post api("/users/#{user.id}/keys", admin), { title: "invalid key" } - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('400 (Bad request) "key" not given') end it 'should not create key without title' do post api("/users/#{user.id}/keys", admin), key: 'some key' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('400 (Bad request) "title" not given') end @@ -401,7 +401,7 @@ describe API::API, api: true do it "should return 405 for invalid ID" do post api("/users/ASDF/keys", admin) - expect(response.status).to eq(405) + expect(response).to have_http_status(405) end end @@ -411,14 +411,14 @@ describe API::API, api: true do context 'when unauthenticated' do it 'should return authentication error' do get api("/users/#{user.id}/keys") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context 'when authenticated' do it 'should return 404 for non-existing user' do get api('/users/999999/keys', admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 User Not Found') end @@ -426,14 +426,14 @@ describe API::API, api: true do user.keys << key user.save get api("/users/#{user.id}/keys", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['title']).to eq(key.title) end it "should return 405 for invalid ID" do get api("/users/ASDF/keys", admin) - expect(response.status).to eq(405) + expect(response).to have_http_status(405) end end end @@ -444,7 +444,7 @@ describe API::API, api: true do context 'when unauthenticated' do it 'should return authentication error' do delete api("/users/#{user.id}/keys/42") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -455,20 +455,20 @@ describe API::API, api: true do expect do delete api("/users/#{user.id}/keys/#{key.id}", admin) end.to change { user.keys.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should return 404 error if user not found' do user.keys << key user.save delete api("/users/999999/keys/#{key.id}", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 User Not Found') end it 'should return 404 error if key not foud' do delete api("/users/#{user.id}/keys/42", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Key Not Found') end end @@ -479,7 +479,7 @@ describe API::API, api: true do it "should not create invalid email" do post api("/users/#{user.id}/emails", admin), {} - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('400 (Bad request) "email" not given') end @@ -492,7 +492,7 @@ describe API::API, api: true do it "should raise error for invalid ID" do post api("/users/ASDF/emails", admin) - expect(response.status).to eq(405) + expect(response).to have_http_status(405) end end @@ -502,14 +502,14 @@ describe API::API, api: true do context 'when unauthenticated' do it 'should return authentication error' do get api("/users/#{user.id}/emails") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end context 'when authenticated' do it 'should return 404 for non-existing user' do get api('/users/999999/emails', admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 User Not Found') end @@ -517,14 +517,14 @@ describe API::API, api: true do user.emails << email user.save get api("/users/#{user.id}/emails", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first['email']).to eq(email.email) end it "should raise error for invalid ID" do put api("/users/ASDF/emails", admin) - expect(response.status).to eq(405) + expect(response).to have_http_status(405) end end end @@ -535,7 +535,7 @@ describe API::API, api: true do context 'when unauthenticated' do it 'should return authentication error' do delete api("/users/#{user.id}/emails/42") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -546,20 +546,20 @@ describe API::API, api: true do expect do delete api("/users/#{user.id}/emails/#{email.id}", admin) end.to change { user.emails.count }.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should return 404 error if user not found' do user.emails << email user.save delete api("/users/999999/emails/#{email.id}", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 User Not Found') end it 'should return 404 error if email not foud' do delete api("/users/#{user.id}/emails/42", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Email Not Found') end @@ -574,24 +574,24 @@ describe API::API, api: true do it "should delete user" do delete api("/users/#{user.id}", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound expect(json_response['email']).to eq(user.email) end it "should not delete for unauthenticated user" do delete api("/users/#{user.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end it "shouldn't available for non admin users" do delete api("/users/#{user.id}", user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end it "should return 404 for non-existing user" do delete api("/users/999999", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 User Not Found') end @@ -603,7 +603,7 @@ describe API::API, api: true do describe "GET /user" do it "should return current user" do get api("/user", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['email']).to eq(user.email) expect(json_response['is_admin']).to eq(user.is_admin?) expect(json_response['can_create_project']).to eq(user.can_create_project?) @@ -613,7 +613,7 @@ describe API::API, api: true do it "should return 401 error if user is unauthenticated" do get api("/user") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -621,7 +621,7 @@ describe API::API, api: true do context "when unauthenticated" do it "should return authentication error" do get api("/user/keys") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -630,7 +630,7 @@ describe API::API, api: true do user.keys << key user.save get api("/user/keys", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first["title"]).to eq(key.title) end @@ -642,13 +642,13 @@ describe API::API, api: true do user.keys << key user.save get api("/user/keys/#{key.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["title"]).to eq(key.title) end it "should return 404 Not Found within invalid ID" do get api("/user/keys/42", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Not found') end @@ -657,13 +657,13 @@ describe API::API, api: true do user.save admin get api("/user/keys/#{key.id}", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Not found') end it "should return 404 for invalid ID" do get api("/users/keys/ASDF", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -673,29 +673,29 @@ describe API::API, api: true do expect do post api("/user/keys", user), key_attrs end.to change{ user.keys.count }.by(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end it "should return a 401 error if unauthorized" do post api("/user/keys"), title: 'some title', key: 'some key' - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end it "should not create ssh key without key" do post api("/user/keys", user), title: 'title' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('400 (Bad request) "key" not given') end it 'should not create ssh key without title' do post api('/user/keys', user), key: 'some key' - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('400 (Bad request) "title" not given') end it "should not create ssh key without title" do post api("/user/keys", user), key: "somekey" - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -706,19 +706,19 @@ describe API::API, api: true do expect do delete api("/user/keys/#{key.id}", user) end.to change{user.keys.count}.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return success if key ID not found" do delete api("/user/keys/42", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return 401 error if unauthorized" do user.keys << key user.save delete api("/user/keys/#{key.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end it "should raise error for invalid ID" do @@ -730,7 +730,7 @@ describe API::API, api: true do context "when unauthenticated" do it "should return authentication error" do get api("/user/emails") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -739,7 +739,7 @@ describe API::API, api: true do user.emails << email user.save get api("/user/emails", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_an Array expect(json_response.first["email"]).to eq(email.email) end @@ -751,13 +751,13 @@ describe API::API, api: true do user.emails << email user.save get api("/user/emails/#{email.id}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["email"]).to eq(email.email) end it "should return 404 Not Found within invalid ID" do get api("/user/emails/42", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Not found') end @@ -766,13 +766,13 @@ describe API::API, api: true do user.save admin get api("/user/emails/#{email.id}", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 Not found') end it "should return 404 for invalid ID" do get api("/users/emails/ASDF", admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -782,17 +782,17 @@ describe API::API, api: true do expect do post api("/user/emails", user), email_attrs end.to change{ user.emails.count }.by(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) end it "should return a 401 error if unauthorized" do post api("/user/emails"), email: 'some email' - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end it "should not create email with invalid email" do post api("/user/emails", user), {} - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('400 (Bad request) "email" not given') end end @@ -804,19 +804,19 @@ describe API::API, api: true do expect do delete api("/user/emails/#{email.id}", user) end.to change{user.emails.count}.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return success if email ID not found" do delete api("/user/emails/42", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "should return 401 error if unauthorized" do user.emails << email user.save delete api("/user/emails/#{email.id}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end it "should raise error for invalid ID" do @@ -828,25 +828,25 @@ describe API::API, api: true do before { admin } it 'should block existing user' do put api("/users/#{user.id}/block", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(user.reload.state).to eq('blocked') end it 'should not re-block ldap blocked users' do put api("/users/#{ldap_blocked_user.id}/block", admin) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) expect(ldap_blocked_user.reload.state).to eq('ldap_blocked') end it 'should not be available for non admin users' do put api("/users/#{user.id}/block", user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) expect(user.reload.state).to eq('active') end it 'should return a 404 error if user id not found' do put api('/users/9999/block', admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 User Not Found') end end @@ -857,31 +857,31 @@ describe API::API, api: true do it 'should unblock existing user' do put api("/users/#{user.id}/unblock", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(user.reload.state).to eq('active') end it 'should unblock a blocked user' do put api("/users/#{blocked_user.id}/unblock", admin) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(blocked_user.reload.state).to eq('active') end it 'should not unblock ldap blocked users' do put api("/users/#{ldap_blocked_user.id}/unblock", admin) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) expect(ldap_blocked_user.reload.state).to eq('ldap_blocked') end it 'should not be available for non admin users' do put api("/users/#{user.id}/unblock", user) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) expect(user.reload.state).to eq('active') end it 'should return a 404 error if user id not found' do put api('/users/9999/block', admin) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) expect(json_response['message']).to eq('404 User Not Found') end diff --git a/spec/requests/api/variables_spec.rb b/spec/requests/api/variables_spec.rb index b1e1053d037..ddba18245f8 100644 --- a/spec/requests/api/variables_spec.rb +++ b/spec/requests/api/variables_spec.rb @@ -15,7 +15,7 @@ describe API::API, api: true do it 'should return project variables' do get api("/projects/#{project.id}/variables", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response).to be_a(Array) end end @@ -24,7 +24,7 @@ describe API::API, api: true do it 'should not return project variables' do get api("/projects/#{project.id}/variables", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -32,7 +32,7 @@ describe API::API, api: true do it 'should not return project variables' do get api("/projects/#{project.id}/variables") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -42,14 +42,14 @@ describe API::API, api: true do it 'should return project variable details' do get api("/projects/#{project.id}/variables/#{variable.key}", user) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response['value']).to eq(variable.value) end it 'should respond with 404 Not Found if requesting non-existing variable' do get api("/projects/#{project.id}/variables/non_existing_variable", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -57,7 +57,7 @@ describe API::API, api: true do it 'should not return project variable details' do get api("/projects/#{project.id}/variables/#{variable.key}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -65,7 +65,7 @@ describe API::API, api: true do it 'should not return project variable details' do get api("/projects/#{project.id}/variables/#{variable.key}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -77,7 +77,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/variables", user), key: 'TEST_VARIABLE_2', value: 'VALUE_2' end.to change{project.variables.count}.by(1) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['key']).to eq('TEST_VARIABLE_2') expect(json_response['value']).to eq('VALUE_2') end @@ -87,7 +87,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/variables", user), key: variable.key, value: 'VALUE_2' end.to change{project.variables.count}.by(0) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -95,7 +95,7 @@ describe API::API, api: true do it 'should not create variable' do post api("/projects/#{project.id}/variables", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -103,7 +103,7 @@ describe API::API, api: true do it 'should not create variable' do post api("/projects/#{project.id}/variables") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -118,7 +118,7 @@ describe API::API, api: true do updated_variable = project.variables.first - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(value_before).to eq(variable.value) expect(updated_variable.value).to eq('VALUE_1_UP') end @@ -126,7 +126,7 @@ describe API::API, api: true do it 'should responde with 404 Not Found if requesting non-existing variable' do put api("/projects/#{project.id}/variables/non_existing_variable", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -134,7 +134,7 @@ describe API::API, api: true do it 'should not update variable' do put api("/projects/#{project.id}/variables/#{variable.key}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -142,7 +142,7 @@ describe API::API, api: true do it 'should not update variable' do put api("/projects/#{project.id}/variables/#{variable.key}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -153,13 +153,13 @@ describe API::API, api: true do expect do delete api("/projects/#{project.id}/variables/#{variable.key}", user) end.to change{project.variables.count}.by(-1) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should responde with 404 Not Found if requesting non-existing variable' do delete api("/projects/#{project.id}/variables/non_existing_variable", user) - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end @@ -167,7 +167,7 @@ describe API::API, api: true do it 'should not delete variable' do delete api("/projects/#{project.id}/variables/#{variable.key}", user2) - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end @@ -175,7 +175,7 @@ describe API::API, api: true do it 'should not delete variable' do delete api("/projects/#{project.id}/variables/#{variable.key}") - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end diff --git a/spec/requests/ci/api/builds_spec.rb b/spec/requests/ci/api/builds_spec.rb index 7e50bea90d1..1bc51783c3a 100644 --- a/spec/requests/ci/api/builds_spec.rb +++ b/spec/requests/ci/api/builds_spec.rb @@ -26,7 +26,7 @@ describe Ci::API::API do post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['sha']).to eq(build.sha) expect(runner.reload.platform).to eq("darwin") end @@ -34,7 +34,7 @@ describe Ci::API::API do it "should return 404 error if no pending build found" do post ci_api("/builds/register"), token: runner.token - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return 404 error if no builds for specific runner" do @@ -43,7 +43,7 @@ describe Ci::API::API do post ci_api("/builds/register"), token: runner.token - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "should return 404 error if no builds for shared runner" do @@ -52,7 +52,7 @@ describe Ci::API::API do post ci_api("/builds/register"), token: shared_runner.token - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it "returns options" do @@ -61,7 +61,7 @@ describe Ci::API::API do post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response["options"]).to eq({ "image" => "ruby:2.1", "services" => ["postgres"] }) end @@ -72,7 +72,7 @@ describe Ci::API::API do post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response["variables"]).to eq([ { "key" => "CI_BUILD_NAME", "value" => "spinach", "public" => true }, { "key" => "CI_BUILD_STAGE", "value" => "test", "public" => true }, @@ -91,7 +91,7 @@ describe Ci::API::API do post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response["variables"]).to eq([ { "key" => "CI_BUILD_NAME", "value" => "spinach", "public" => true }, { "key" => "CI_BUILD_STAGE", "value" => "test", "public" => true }, @@ -109,7 +109,7 @@ describe Ci::API::API do post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin } - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response["depends_on_builds"].count).to eq(2) expect(json_response["depends_on_builds"][0]["name"]).to eq("rspec") end @@ -122,7 +122,7 @@ describe Ci::API::API do it do post ci_api("/builds/register"), token: runner.token, info: { param => value } - expect(response.status).to eq(404) + expect(response).to have_http_status(404) runner.reload is_expected.to eq(value) end @@ -172,7 +172,7 @@ describe Ci::API::API do end it "should update a running build" do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it 'should not override trace information when no trace is given' do @@ -252,13 +252,13 @@ describe Ci::API::API do context "should authorize posting artifact to running build" do it "using token as parameter" do post authorize_url, { token: build.token }, headers - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["TempPath"]).not_to be_nil end it "using token as header" do post authorize_url, {}, headers_with_token - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_response["TempPath"]).not_to be_nil end end @@ -267,13 +267,13 @@ describe Ci::API::API do it "using token as parameter" do stub_application_setting(max_artifacts_size: 0) post authorize_url, { token: build.token, filesize: 100 }, headers - expect(response.status).to eq(413) + expect(response).to have_http_status(413) end it "using token as header" do stub_application_setting(max_artifacts_size: 0) post authorize_url, { filesize: 100 }, headers_with_token - expect(response.status).to eq(413) + expect(response).to have_http_status(413) end end @@ -281,7 +281,7 @@ describe Ci::API::API do before { post authorize_url, { token: 'invalid', filesize: 100 } } it 'should respond with forbidden' do - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end end @@ -305,20 +305,20 @@ describe Ci::API::API do context "should post artifact to running build" do it "uses regual file post" do upload_artifacts(file_upload, headers_with_token, false) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response["artifacts_file"]["filename"]).to eq(file_upload.original_filename) end it "uses accelerated file post" do upload_artifacts(file_upload, headers_with_token, true) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response["artifacts_file"]["filename"]).to eq(file_upload.original_filename) end it "updates artifact" do upload_artifacts(file_upload, headers_with_token) upload_artifacts(file_upload2, headers_with_token) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response["artifacts_file"]["filename"]).to eq(file_upload2.original_filename) end end @@ -343,7 +343,7 @@ describe Ci::API::API do end it 'stores artifacts and artifacts metadata' do - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename) expect(stored_metadata_file.original_filename).to eq(metadata.original_filename) end @@ -355,7 +355,7 @@ describe Ci::API::API do end it 'is expected to respond with bad request' do - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'does not store metadata' do @@ -382,7 +382,7 @@ describe Ci::API::API do it 'updates when specified' do build.reload - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['artifacts_expire_at']).not_to be_empty expect(build.artifacts_expire_at).to be_within(5.minutes).of(Time.now + 7.days) end @@ -393,7 +393,7 @@ describe Ci::API::API do it 'ignores if not specified' do build.reload - expect(response.status).to eq(201) + expect(response).to have_http_status(201) expect(json_response['artifacts_expire_at']).to be_nil expect(build.artifacts_expire_at).to be_nil end @@ -404,21 +404,21 @@ describe Ci::API::API do it "should fail to post too large artifact" do stub_application_setting(max_artifacts_size: 0) upload_artifacts(file_upload, headers_with_token) - expect(response.status).to eq(413) + expect(response).to have_http_status(413) end end context "artifacts post request does not contain file" do it "should fail to post artifacts without file" do post post_url, {}, headers_with_token - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end context 'GitLab Workhorse is not configured' do it "should fail to post artifacts without GitLab-Workhorse" do post post_url, { token: build.token }, {} - expect(response.status).to eq(403) + expect(response).to have_http_status(403) end end end @@ -437,7 +437,7 @@ describe Ci::API::API do it "should fail to post artifacts for outside of tmp path" do upload_artifacts(file_upload, headers_with_token) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end end @@ -458,7 +458,7 @@ describe Ci::API::API do before { delete delete_url, token: build.token } it 'should remove build artifacts' do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(build.artifacts_file.exists?).to be_falsy expect(build.artifacts_metadata.exists?).to be_falsy end @@ -475,14 +475,14 @@ describe Ci::API::API do end it 'should download artifact' do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(response.headers).to include download_headers end end context 'build does not has artifacts' do it 'should respond with not found' do - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/requests/ci/api/triggers_spec.rb b/spec/requests/ci/api/triggers_spec.rb index 72f6a3c981d..f12678e5a8e 100644 --- a/spec/requests/ci/api/triggers_spec.rb +++ b/spec/requests/ci/api/triggers_spec.rb @@ -21,17 +21,17 @@ describe Ci::API::API do context 'Handles errors' do it 'should return bad request if token is missing' do post ci_api("/projects/#{project.ci_id}/refs/master/trigger") - expect(response.status).to eq(400) + expect(response).to have_http_status(400) end it 'should return not found if project is not found' do post ci_api('/projects/0/refs/master/trigger'), options - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end it 'should return unauthorized if token is for different project' do post ci_api("/projects/#{project2.ci_id}/refs/master/trigger"), options - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -40,14 +40,14 @@ describe Ci::API::API do it 'should create builds' do post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options - expect(response.status).to eq(201) + expect(response).to have_http_status(201) pipeline.builds.reload expect(pipeline.builds.size).to eq(2) end it 'should return bad request with no builds created if there\'s no commit for that ref' do post ci_api("/projects/#{project.ci_id}/refs/other-branch/trigger"), options - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('No builds created') end @@ -58,19 +58,19 @@ describe Ci::API::API do it 'should validate variables to be a hash' do post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: 'value') - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('variables needs to be a hash') end it 'should validate variables needs to be a map of key-valued strings' do post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: { key: %w(1 2) }) - expect(response.status).to eq(400) + expect(response).to have_http_status(400) expect(json_response['message']).to eq('variables needs to be a map of key-valued strings') end it 'create trigger request with variables' do post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options.merge(variables: variables) - expect(response.status).to eq(201) + expect(response).to have_http_status(201) pipeline.builds.reload expect(pipeline.builds.first.trigger_request.variables).to eq(variables) end diff --git a/spec/requests/git_http_spec.rb b/spec/requests/git_http_spec.rb index fd26ca97818..bae56334be4 100644 --- a/spec/requests/git_http_spec.rb +++ b/spec/requests/git_http_spec.rb @@ -14,7 +14,7 @@ describe 'Git HTTP requests', lib: true do context "when no authentication is provided" do it "responds with status 401 (no project existence information leak)" do download('doesnt/exist.git') do |response| - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -23,7 +23,7 @@ describe 'Git HTTP requests', lib: true do context "when authentication fails" do it "responds with status 401" do download('doesnt/exist.git', user: user.username, password: "nope") do |response| - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -31,7 +31,7 @@ describe 'Git HTTP requests', lib: true do context "when authentication succeeds" do it "responds with status 404" do download('/doesnt/exist.git', user: user.username, password: user.password) do |response| - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -46,7 +46,7 @@ describe 'Git HTTP requests', lib: true do download("/#{wiki.repository.path_with_namespace}.git") do |response| json_body = ActiveSupport::JSON.decode(response.body) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) expect(json_body['RepoPath']).to include(wiki.repository.path_with_namespace) end end @@ -62,13 +62,13 @@ describe 'Git HTTP requests', lib: true do it "downloads get status 200" do download(path, {}) do |response| - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end it "uploads get status 401" do upload(path, {}) do |response| - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -77,7 +77,7 @@ describe 'Git HTTP requests', lib: true do it "uploads get status 200 (because Git hooks do the real check)" do upload(path, env) do |response| - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -86,7 +86,7 @@ describe 'Git HTTP requests', lib: true do allow(Gitlab.config.gitlab_shell).to receive(:receive_pack).and_return(false) upload(path, env) do |response| - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -97,7 +97,7 @@ describe 'Git HTTP requests', lib: true do allow(Gitlab.config.gitlab_shell).to receive(:upload_pack).and_return(false) download(path, {}) do |response| - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -111,13 +111,13 @@ describe 'Git HTTP requests', lib: true do context "when no authentication is provided" do it "responds with status 401 to downloads" do download(path, {}) do |response| - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end it "responds with status 401 to uploads" do upload(path, {}) do |response| - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -128,7 +128,7 @@ describe 'Git HTTP requests', lib: true do context "when authentication fails" do it "responds with status 401" do download(path, env) do |response| - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -139,7 +139,7 @@ describe 'Git HTTP requests', lib: true do clone_get(path, env) - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -158,7 +158,7 @@ describe 'Git HTTP requests', lib: true do project.team << [user, :master] download(path, env) do |response| - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end @@ -169,12 +169,12 @@ describe 'Git HTTP requests', lib: true do clone_get(path, env) - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "uploads get status 200" do upload(path, env) do |response| - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -188,13 +188,13 @@ describe 'Git HTTP requests', lib: true do it "downloads get status 200" do clone_get "#{project.path_with_namespace}.git", user: 'oauth2', password: @token.token - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "uploads get status 401 (no project existence information leak)" do push_get "#{project.path_with_namespace}.git", user: 'oauth2', password: @token.token - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end @@ -232,13 +232,13 @@ describe 'Git HTTP requests', lib: true do context "when the user doesn't have access to the project" do it "downloads get status 404" do download(path, user: user.username, password: user.password) do |response| - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end it "uploads get status 200 (because Git hooks do the real check)" do upload(path, user: user.username, password: user.password) do |response| - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end end @@ -256,13 +256,13 @@ describe 'Git HTTP requests', lib: true do it "downloads get status 200" do clone_get "#{project.path_with_namespace}.git", user: 'gitlab-ci-token', password: token - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end it "uploads get status 401 (no project existence information leak)" do push_get "#{project.path_with_namespace}.git", user: 'gitlab-ci-token', password: token - expect(response.status).to eq(401) + expect(response).to have_http_status(401) end end end @@ -336,7 +336,7 @@ describe 'Git HTTP requests', lib: true do end it "returns the file" do - expect(response.status).to eq(200) + expect(response).to have_http_status(200) end end @@ -344,7 +344,7 @@ describe 'Git HTTP requests', lib: true do before { get "/#{project.path_with_namespace}/blob/master/info/refs" } it "returns not found" do - expect(response.status).to eq(404) + expect(response).to have_http_status(404) end end end diff --git a/spec/requests/jwt_controller_spec.rb b/spec/requests/jwt_controller_spec.rb index d2d4a9eca18..c6172b9cc7d 100644 --- a/spec/requests/jwt_controller_spec.rb +++ b/spec/requests/jwt_controller_spec.rb @@ -11,12 +11,12 @@ describe JwtController do context 'existing service' do subject! { get '/jwt/auth', parameters } - it { expect(response.status).to eq(200) } + it { expect(response).to have_http_status(200) } context 'returning custom http code' do let(:service) { double(execute: { http_status: 505 }) } - it { expect(response.status).to eq(505) } + it { expect(response).to have_http_status(505) } end end @@ -36,7 +36,7 @@ describe JwtController do context 'project with disabled CI' do let(:builds_enabled) { false } - it { expect(response.status).to eq(403) } + it { expect(response).to have_http_status(403) } end end @@ -56,14 +56,14 @@ describe JwtController do subject! { get '/jwt/auth', parameters, headers } - it { expect(response.status).to eq(403) } + it { expect(response).to have_http_status(403) } end end context 'unknown service' do subject! { get '/jwt/auth', service: 'unknown' } - it { expect(response.status).to eq(404) } + it { expect(response).to have_http_status(404) } end def credentials(login, password) diff --git a/spec/services/search/snippet_service_spec.rb b/spec/services/search/snippet_service_spec.rb new file mode 100644 index 00000000000..14f3301d9f4 --- /dev/null +++ b/spec/services/search/snippet_service_spec.rb @@ -0,0 +1,59 @@ +require 'spec_helper' + +describe Search::SnippetService, services: true do + let(:author) { create(:author) } + let(:project) { create(:empty_project) } + + let!(:public_snippet) { create(:snippet, :public, content: 'password: XXX') } + let!(:internal_snippet) { create(:snippet, :internal, content: 'password: XXX') } + let!(:private_snippet) { create(:snippet, :private, content: 'password: XXX', author: author) } + + let!(:project_public_snippet) { create(:snippet, :public, project: project, content: 'password: XXX') } + let!(:project_internal_snippet) { create(:snippet, :internal, project: project, content: 'password: XXX') } + let!(:project_private_snippet) { create(:snippet, :private, project: project, content: 'password: XXX') } + + describe '#execute' do + context 'unauthenticated' do + it 'returns public snippets only' do + search = described_class.new(nil, search: 'password') + results = search.execute + + expect(results.objects('snippet_blobs')).to match_array [public_snippet, project_public_snippet] + end + end + + context 'authenticated' do + it 'returns only public & internal snippets for regular users' do + user = create(:user) + search = described_class.new(user, search: 'password') + results = search.execute + + expect(results.objects('snippet_blobs')).to match_array [public_snippet, internal_snippet, project_public_snippet, project_internal_snippet] + end + + it 'returns public, internal snippets and project private snippets for project members' do + member = create(:user) + project.team << [member, :developer] + search = described_class.new(member, search: 'password') + results = search.execute + + expect(results.objects('snippet_blobs')).to match_array [public_snippet, internal_snippet, project_public_snippet, project_internal_snippet, project_private_snippet] + end + + it 'returns public, internal and private snippets where user is the author' do + search = described_class.new(author, search: 'password') + results = search.execute + + expect(results.objects('snippet_blobs')).to match_array [public_snippet, internal_snippet, private_snippet, project_public_snippet, project_internal_snippet] + end + + it 'returns all snippets when user is admin' do + admin = create(:admin) + search = described_class.new(admin, search: 'password') + results = search.execute + + expect(results.objects('snippet_blobs')).to match_array [public_snippet, internal_snippet, private_snippet, project_public_snippet, project_internal_snippet, project_private_snippet] + end + end + end +end diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 498bd4bf800..426bf53f198 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -17,6 +17,7 @@ module TestEnv "'test'" => 'e56497b', 'orphaned-branch' => '45127a9', 'binary-encoding' => '7b1cf43', + 'gitattributes' => '5a62481', } # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily |