summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/ability_spec.rb96
-rw-r--r--spec/models/abuse_report_spec.rb22
-rw-r--r--spec/models/active_session_spec.rb122
-rw-r--r--spec/models/appearance_spec.rb50
-rw-r--r--spec/models/application_record_spec.rb16
-rw-r--r--spec/models/application_setting/term_spec.rb18
-rw-r--r--spec/models/application_setting_spec.rb314
-rw-r--r--spec/models/award_emoji_spec.rb38
-rw-r--r--spec/models/badge_spec.rb56
-rw-r--r--spec/models/badges/group_badge_spec.rb6
-rw-r--r--spec/models/badges/project_badge_spec.rb26
-rw-r--r--spec/models/blob_spec.rb271
-rw-r--r--spec/models/blob_viewer/base_spec.rb100
-rw-r--r--spec/models/blob_viewer/changelog_spec.rb14
-rw-r--r--spec/models/blob_viewer/composer_json_spec.rb10
-rw-r--r--spec/models/blob_viewer/gemspec_spec.rb10
-rw-r--r--spec/models/blob_viewer/gitlab_ci_yml_spec.rb22
-rw-r--r--spec/models/blob_viewer/license_spec.rb18
-rw-r--r--spec/models/blob_viewer/package_json_spec.rb38
-rw-r--r--spec/models/blob_viewer/podspec_json_spec.rb10
-rw-r--r--spec/models/blob_viewer/podspec_spec.rb10
-rw-r--r--spec/models/blob_viewer/readme_spec.rb26
-rw-r--r--spec/models/blob_viewer/route_map_spec.rb20
-rw-r--r--spec/models/blob_viewer/server_side_spec.rb16
-rw-r--r--spec/models/board_group_recent_visit_spec.rb26
-rw-r--r--spec/models/board_project_recent_visit_spec.rb26
-rw-r--r--spec/models/board_spec.rb6
-rw-r--r--spec/models/broadcast_message_spec.rb56
-rw-r--r--spec/models/chat_name_spec.rb8
-rw-r--r--spec/models/chat_team_spec.rb2
-rw-r--r--spec/models/ci/artifact_blob_spec.rb56
-rw-r--r--spec/models/ci/bridge_spec.rb10
-rw-r--r--spec/models/ci/build_metadata_spec.rb28
-rw-r--r--spec/models/ci/build_runner_session_spec.rb22
-rw-r--r--spec/models/ci/build_spec.rb1721
-rw-r--r--spec/models/ci/build_trace_chunk_spec.rb324
-rw-r--r--spec/models/ci/build_trace_chunks/database_spec.rb56
-rw-r--r--spec/models/ci/build_trace_chunks/fog_spec.rb72
-rw-r--r--spec/models/ci/build_trace_chunks/redis_spec.rb60
-rw-r--r--spec/models/ci/build_trace_section_name_spec.rb2
-rw-r--r--spec/models/ci/build_trace_section_spec.rb2
-rw-r--r--spec/models/ci/group_spec.rb50
-rw-r--r--spec/models/ci/group_variable_spec.rb12
-rw-r--r--spec/models/ci/job_artifact_spec.rb126
-rw-r--r--spec/models/ci/legacy_stage_spec.rb142
-rw-r--r--spec/models/ci/pipeline_schedule_spec.rb50
-rw-r--r--spec/models/ci/pipeline_schedule_variable_spec.rb2
-rw-r--r--spec/models/ci/pipeline_spec.rb1383
-rw-r--r--spec/models/ci/pipeline_variable_spec.rb8
-rw-r--r--spec/models/ci/runner_spec.rb332
-rw-r--r--spec/models/ci/stage_spec.rb140
-rw-r--r--spec/models/ci/trigger_request_spec.rb10
-rw-r--r--spec/models/ci/trigger_spec.rb38
-rw-r--r--spec/models/ci/variable_spec.rb14
-rw-r--r--spec/models/clusters/applications/cert_manager_spec.rb50
-rw-r--r--spec/models/clusters/applications/helm_spec.rb24
-rw-r--r--spec/models/clusters/applications/ingress_spec.rb68
-rw-r--r--spec/models/clusters/applications/jupyter_spec.rb62
-rw-r--r--spec/models/clusters/applications/knative_spec.rb80
-rw-r--r--spec/models/clusters/applications/prometheus_spec.rb132
-rw-r--r--spec/models/clusters/applications/runner_spec.rb76
-rw-r--r--spec/models/clusters/cluster_spec.rb262
-rw-r--r--spec/models/clusters/group_spec.rb2
-rw-r--r--spec/models/clusters/kubernetes_namespace_spec.rb66
-rw-r--r--spec/models/clusters/platforms/kubernetes_spec.rb220
-rw-r--r--spec/models/clusters/project_spec.rb2
-rw-r--r--spec/models/clusters/providers/gcp_spec.rb88
-rw-r--r--spec/models/commit_collection_spec.rb44
-rw-r--r--spec/models/commit_range_spec.rb80
-rw-r--r--spec/models/commit_spec.rb310
-rw-r--r--spec/models/commit_status_spec.rb314
-rw-r--r--spec/models/compare_spec.rb54
-rw-r--r--spec/models/concerns/access_requestable_spec.rb14
-rw-r--r--spec/models/concerns/avatarable_spec.rb36
-rw-r--r--spec/models/concerns/awardable_spec.rb12
-rw-r--r--spec/models/concerns/batch_destroy_dependent_associations_spec.rb16
-rw-r--r--spec/models/concerns/blob_language_from_git_attributes_spec.rb14
-rw-r--r--spec/models/concerns/blocks_json_serialization_spec.rb10
-rw-r--r--spec/models/concerns/cache_markdown_field_spec.rb106
-rw-r--r--spec/models/concerns/cacheable_attributes_spec.rb108
-rw-r--r--spec/models/concerns/case_sensitivity_spec.rb38
-rw-r--r--spec/models/concerns/chronic_duration_attribute_spec.rb66
-rw-r--r--spec/models/concerns/deployable_spec.rb43
-rw-r--r--spec/models/concerns/deployment_platform_spec.rb58
-rw-r--r--spec/models/concerns/discussion_on_diff_spec.rb30
-rw-r--r--spec/models/concerns/each_batch_spec.rb26
-rw-r--r--spec/models/concerns/editable_spec.rb4
-rw-r--r--spec/models/concerns/expirable_spec.rb12
-rw-r--r--spec/models/concerns/faster_cache_keys_spec.rb8
-rw-r--r--spec/models/concerns/feature_gate_spec.rb10
-rw-r--r--spec/models/concerns/from_union_spec.rb14
-rw-r--r--spec/models/concerns/group_descendant_spec.rb80
-rw-r--r--spec/models/concerns/has_ref_spec.rb26
-rw-r--r--spec/models/concerns/has_status_spec.rb184
-rw-r--r--spec/models/concerns/has_variable_spec.rb44
-rw-r--r--spec/models/concerns/ignorable_column_spec.rb22
-rw-r--r--spec/models/concerns/issuable_spec.rb254
-rw-r--r--spec/models/concerns/loaded_in_group_list_spec.rb20
-rw-r--r--spec/models/concerns/manual_inverse_association_spec.rb22
-rw-r--r--spec/models/concerns/maskable_spec.rb50
-rw-r--r--spec/models/concerns/mentionable_spec.rb80
-rw-r--r--spec/models/concerns/milestoneish_spec.rb96
-rw-r--r--spec/models/concerns/noteable_spec.rb22
-rw-r--r--spec/models/concerns/optionally_search_spec.rb30
-rw-r--r--spec/models/concerns/participable_spec.rb20
-rw-r--r--spec/models/concerns/presentable_spec.rb10
-rw-r--r--spec/models/concerns/project_features_compatibility_spec.rb4
-rw-r--r--spec/models/concerns/prometheus_adapter_spec.rb32
-rw-r--r--spec/models/concerns/protected_ref_access_spec.rb10
-rw-r--r--spec/models/concerns/reactive_caching_spec.rb52
-rw-r--r--spec/models/concerns/redactable_spec.rb40
-rw-r--r--spec/models/concerns/redis_cacheable_spec.rb38
-rw-r--r--spec/models/concerns/relative_positioning_spec.rb74
-rw-r--r--spec/models/concerns/resolvable_discussion_spec.rb2
-rw-r--r--spec/models/concerns/resolvable_note_spec.rb42
-rw-r--r--spec/models/concerns/routable_spec.rb88
-rw-r--r--spec/models/concerns/sha_attribute_spec.rb34
-rw-r--r--spec/models/concerns/sortable_spec.rb88
-rw-r--r--spec/models/concerns/spammable_spec.rb24
-rw-r--r--spec/models/concerns/strip_attribute_spec.rb6
-rw-r--r--spec/models/concerns/subscribable_spec.rb62
-rw-r--r--spec/models/concerns/token_authenticatable_spec.rb164
-rw-r--r--spec/models/concerns/token_authenticatable_strategies/base_spec.rb36
-rw-r--r--spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb132
-rw-r--r--spec/models/concerns/triggerable_hooks_spec.rb36
-rw-r--r--spec/models/concerns/uniquify_spec.rb36
-rw-r--r--spec/models/container_repository_spec.rb160
-rw-r--r--spec/models/conversational_development_index/metric_spec.rb8
-rw-r--r--spec/models/cycle_analytics/code_spec.rb38
-rw-r--r--spec/models/cycle_analytics/issue_spec.rb37
-rw-r--r--spec/models/cycle_analytics/plan_spec.rb29
-rw-r--r--spec/models/cycle_analytics/production_spec.rb22
-rw-r--r--spec/models/cycle_analytics/review_spec.rb21
-rw-r--r--spec/models/cycle_analytics/staging_spec.rb48
-rw-r--r--spec/models/cycle_analytics/test_spec.rb17
-rw-r--r--spec/models/cycle_analytics_spec.rb12
-rw-r--r--spec/models/deploy_key_spec.rb16
-rw-r--r--spec/models/deploy_keys_project_spec.rb2
-rw-r--r--spec/models/deploy_token_spec.rb84
-rw-r--r--spec/models/deployment_spec.rb136
-rw-r--r--spec/models/diff_discussion_spec.rb58
-rw-r--r--spec/models/diff_note_spec.rb48
-rw-r--r--spec/models/diff_viewer/base_spec.rb100
-rw-r--r--spec/models/diff_viewer/server_side_spec.rb28
-rw-r--r--spec/models/discussion_spec.rb12
-rw-r--r--spec/models/email_spec.rb28
-rw-r--r--spec/models/environment_spec.rb424
-rw-r--r--spec/models/environment_status_spec.rb76
-rw-r--r--spec/models/error_tracking/project_error_tracking_setting_spec.rb168
-rw-r--r--spec/models/event_collection_spec.rb14
-rw-r--r--spec/models/event_spec.rb132
-rw-r--r--spec/models/external_issue_spec.rb40
-rw-r--r--spec/models/fork_network_member_spec.rb10
-rw-r--r--spec/models/fork_network_spec.rb22
-rw-r--r--spec/models/generic_commit_status_spec.rb36
-rw-r--r--spec/models/global_milestone_spec.rb104
-rw-r--r--spec/models/gpg_key_spec.rb104
-rw-r--r--spec/models/gpg_key_subkey_spec.rb6
-rw-r--r--spec/models/gpg_signature_spec.rb46
-rw-r--r--spec/models/group_custom_attribute_spec.rb6
-rw-r--r--spec/models/group_label_spec.rb38
-rw-r--r--spec/models/group_milestone_spec.rb34
-rw-r--r--spec/models/group_spec.rb319
-rw-r--r--spec/models/guest_spec.rb26
-rw-r--r--spec/models/hooks/active_hook_filter_spec.rb56
-rw-r--r--spec/models/hooks/project_hook_spec.rb14
-rw-r--r--spec/models/hooks/service_hook_spec.rb14
-rw-r--r--spec/models/hooks/system_hook_spec.rb52
-rw-r--r--spec/models/hooks/web_hook_log_spec.rb22
-rw-r--r--spec/models/hooks/web_hook_spec.rb60
-rw-r--r--spec/models/identity_spec.rb98
-rw-r--r--spec/models/import_export_upload_spec.rb16
-rw-r--r--spec/models/instance_configuration_spec.rb60
-rw-r--r--spec/models/internal_id_spec.rb84
-rw-r--r--spec/models/issue/metrics_spec.rb2
-rw-r--r--spec/models/issue_collection_spec.rb32
-rw-r--r--spec/models/issue_spec.rb360
-rw-r--r--spec/models/key_spec.rb46
-rw-r--r--spec/models/label_link_spec.rb2
-rw-r--r--spec/models/label_note_spec.rb10
-rw-r--r--spec/models/label_priority_spec.rb8
-rw-r--r--spec/models/label_spec.rb128
-rw-r--r--spec/models/legacy_diff_discussion_spec.rb16
-rw-r--r--spec/models/lfs_download_object_spec.rb50
-rw-r--r--spec/models/lfs_file_lock_spec.rb10
-rw-r--r--spec/models/lfs_object_spec.rb44
-rw-r--r--spec/models/lfs_objects_project_spec.rb14
-rw-r--r--spec/models/license_template_spec.rb42
-rw-r--r--spec/models/list_spec.rb40
-rw-r--r--spec/models/member_spec.rb130
-rw-r--r--spec/models/members/group_member_spec.rb38
-rw-r--r--spec/models/members/project_member_spec.rb49
-rw-r--r--spec/models/merge_request/metrics_spec.rb8
-rw-r--r--spec/models/merge_request_diff_commit_spec.rb28
-rw-r--r--spec/models/merge_request_diff_file_spec.rb20
-rw-r--r--spec/models/merge_request_diff_spec.rb146
-rw-r--r--spec/models/merge_request_spec.rb1304
-rw-r--r--spec/models/milestone_spec.rb216
-rw-r--r--spec/models/namespace_spec.rb348
-rw-r--r--spec/models/network/graph_spec.rb22
-rw-r--r--spec/models/note_diff_file_spec.rb6
-rw-r--r--spec/models/note_spec.rb258
-rw-r--r--spec/models/notification_recipient_spec.rb16
-rw-r--r--spec/models/notification_setting_spec.rb38
-rw-r--r--spec/models/pages_domain_spec.rb132
-rw-r--r--spec/models/personal_access_token_spec.rb36
-rw-r--r--spec/models/pool_repository_spec.rb20
-rw-r--r--spec/models/postgresql/replication_slot_spec.rb20
-rw-r--r--spec/models/programming_language_spec.rb2
-rw-r--r--spec/models/project_authorization_spec.rb10
-rw-r--r--spec/models/project_auto_devops_spec.rb118
-rw-r--r--spec/models/project_ci_cd_setting_spec.rb8
-rw-r--r--spec/models/project_custom_attribute_spec.rb6
-rw-r--r--spec/models/project_daily_statistic_spec.rb2
-rw-r--r--spec/models/project_deploy_token_spec.rb2
-rw-r--r--spec/models/project_feature_spec.rb44
-rw-r--r--spec/models/project_group_link_spec.rb2
-rw-r--r--spec/models/project_import_data_spec.rb40
-rw-r--r--spec/models/project_import_state_spec.rb46
-rw-r--r--spec/models/project_label_spec.rb76
-rw-r--r--spec/models/project_repository_spec.rb12
-rw-r--r--spec/models/project_services/asana_service_spec.rb68
-rw-r--r--spec/models/project_services/assembla_service_spec.rb8
-rw-r--r--spec/models/project_services/bamboo_service_spec.rb172
-rw-r--r--spec/models/project_services/bugzilla_service_spec.rb16
-rw-r--r--spec/models/project_services/buildkite_service_spec.rb72
-rw-r--r--spec/models/project_services/campfire_service_spec.rb30
-rw-r--r--spec/models/project_services/chat_message/issue_message_spec.rb104
-rw-r--r--spec/models/project_services/chat_message/merge_message_spec.rb92
-rw-r--r--spec/models/project_services/chat_message/note_message_spec.rb154
-rw-r--r--spec/models/project_services/chat_message/pipeline_message_spec.rb92
-rw-r--r--spec/models/project_services/chat_message/push_message_spec.rb181
-rw-r--r--spec/models/project_services/chat_message/wiki_page_message_spec.rb120
-rw-r--r--spec/models/project_services/chat_notification_service_spec.rb42
-rw-r--r--spec/models/project_services/custom_issue_tracker_service_spec.rb28
-rw-r--r--spec/models/project_services/discord_service_spec.rb2
-rw-r--r--spec/models/project_services/drone_ci_service_spec.rb52
-rw-r--r--spec/models/project_services/emails_on_push_service_spec.rb8
-rw-r--r--spec/models/project_services/external_wiki_service_spec.rb10
-rw-r--r--spec/models/project_services/flowdock_service_spec.rb12
-rw-r--r--spec/models/project_services/gitlab_issue_tracker_service_spec.rb20
-rw-r--r--spec/models/project_services/irker_service_spec.rb35
-rw-r--r--spec/models/project_services/issue_tracker_service_spec.rb16
-rw-r--r--spec/models/project_services/jira_service_spec.rb359
-rw-r--r--spec/models/project_services/kubernetes_service_spec.rb230
-rw-r--r--spec/models/project_services/mattermost_service_spec.rb2
-rw-r--r--spec/models/project_services/mattermost_slash_commands_service_spec.rb84
-rw-r--r--spec/models/project_services/microsoft_teams_service_spec.rb88
-rw-r--r--spec/models/project_services/packagist_service_spec.rb26
-rw-r--r--spec/models/project_services/pipelines_email_service_spec.rb104
-rw-r--r--spec/models/project_services/pivotaltracker_service_spec.rb64
-rw-r--r--spec/models/project_services/prometheus_service_spec.rb100
-rw-r--r--spec/models/project_services/pushover_service_spec.rb24
-rw-r--r--spec/models/project_services/redmine_service_spec.rb24
-rw-r--r--spec/models/project_services/slack_service_spec.rb2
-rw-r--r--spec/models/project_services/slack_slash_commands_service_spec.rb26
-rw-r--r--spec/models/project_services/teamcity_service_spec.rb146
-rw-r--r--spec/models/project_services/youtrack_service_spec.rb22
-rw-r--r--spec/models/project_snippet_spec.rb2
-rw-r--r--spec/models/project_spec.rb2152
-rw-r--r--spec/models/project_statistics_spec.rb32
-rw-r--r--spec/models/project_team_spec.rb99
-rw-r--r--spec/models/project_wiki_spec.rb99
-rw-r--r--spec/models/prometheus_metric_spec.rb74
-rw-r--r--spec/models/protectable_dropdown_spec.rb20
-rw-r--r--spec/models/protected_branch/merge_access_level_spec.rb2
-rw-r--r--spec/models/protected_branch/push_access_level_spec.rb2
-rw-r--r--spec/models/protected_branch_spec.rb42
-rw-r--r--spec/models/protected_tag_spec.rb6
-rw-r--r--spec/models/push_event_payload_spec.rb10
-rw-r--r--spec/models/push_event_spec.rb180
-rw-r--r--spec/models/redirect_route_spec.rb30
-rw-r--r--spec/models/release_spec.rb22
-rw-r--r--spec/models/releases/link_spec.rb70
-rw-r--r--spec/models/releases/source_spec.rb22
-rw-r--r--spec/models/remote_mirror_spec.rb232
-rw-r--r--spec/models/repository_language_spec.rb6
-rw-r--r--spec/models/repository_spec.rb1617
-rw-r--r--spec/models/resource_label_event_spec.rb50
-rw-r--r--spec/models/route_spec.rb238
-rw-r--r--spec/models/sent_notification_spec.rb144
-rw-r--r--spec/models/service_spec.rb171
-rw-r--r--spec/models/shard_spec.rb30
-rw-r--r--spec/models/snippet_blob_spec.rb30
-rw-r--r--spec/models/snippet_spec.rb212
-rw-r--r--spec/models/spam_log_spec.rb12
-rw-r--r--spec/models/ssh_host_key_spec.rb100
-rw-r--r--spec/models/subscription_spec.rb8
-rw-r--r--spec/models/suggestion_spec.rb22
-rw-r--r--spec/models/system_note_metadata_spec.rb14
-rw-r--r--spec/models/term_agreement_spec.rb8
-rw-r--r--spec/models/timelog_spec.rb20
-rw-r--r--spec/models/todo_spec.rb136
-rw-r--r--spec/models/tree_spec.rb38
-rw-r--r--spec/models/trending_project_spec.rb14
-rw-r--r--spec/models/upload_spec.rb70
-rw-r--r--spec/models/uploads/fog_spec.rb22
-rw-r--r--spec/models/uploads/local_spec.rb12
-rw-r--r--spec/models/user_agent_detail_spec.rb14
-rw-r--r--spec/models/user_callout_spec.rb8
-rw-r--r--spec/models/user_custom_attribute_spec.rb6
-rw-r--r--spec/models/user_interacted_project_spec.rb26
-rw-r--r--spec/models/user_preference_spec.rb40
-rw-r--r--spec/models/user_spec.rb1460
-rw-r--r--spec/models/user_status_spec.rb12
-rw-r--r--spec/models/wiki_directory_spec.rb32
-rw-r--r--spec/models/wiki_page_spec.rb270
307 files changed, 14122 insertions, 14075 deletions
diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb
index eee80e9bad7..4b514a95f09 100644
--- a/spec/models/ability_spec.rb
+++ b/spec/models/ability_spec.rb
@@ -1,15 +1,15 @@
-require 'spec_helper'
+require "spec_helper"
describe Ability do
- context 'using a nil subject' do
- it 'has no permissions' do
+ context "using a nil subject" do
+ it "has no permissions" do
expect(described_class.policy_for(nil, nil)).to be_banned
end
end
- describe '.users_that_can_read_project' do
- context 'using a public project' do
- it 'returns all the users' do
+ describe ".users_that_can_read_project" do
+ context "using a public project" do
+ it "returns all the users" do
project = create(:project, :public)
user = build(:user)
@@ -18,17 +18,17 @@ describe Ability do
end
end
- context 'using an internal project' do
+ context "using an internal project" do
let(:project) { create(:project, :internal) }
- it 'returns users that are administrators' do
+ it "returns users that are administrators" do
user = build(:user, admin: true)
expect(described_class.users_that_can_read_project([user], project))
.to eq([user])
end
- it 'returns internal users while skipping external users' do
+ it "returns internal users while skipping external users" do
user1 = build(:user)
user2 = build(:user, external: true)
users = [user1, user2]
@@ -37,7 +37,7 @@ describe Ability do
.to eq([user1])
end
- it 'returns external users if they are the project owner' do
+ it "returns external users if they are the project owner" do
user1 = build(:user, external: true)
user2 = build(:user, external: true)
users = [user1, user2]
@@ -48,7 +48,7 @@ describe Ability do
.to eq([user1])
end
- it 'returns external users if they are project members' do
+ it "returns external users if they are project members" do
user1 = build(:user, external: true)
user2 = build(:user, external: true)
users = [user1, user2]
@@ -59,7 +59,7 @@ describe Ability do
.to eq([user1])
end
- it 'returns an empty Array if all users are external users without access' do
+ it "returns an empty Array if all users are external users without access" do
user1 = build(:user, external: true)
user2 = build(:user, external: true)
users = [user1, user2]
@@ -69,17 +69,17 @@ describe Ability do
end
end
- context 'using a private project' do
+ context "using a private project" do
let(:project) { create(:project, :private) }
- it 'returns users that are administrators' do
+ it "returns users that are administrators" do
user = build(:user, admin: true)
expect(described_class.users_that_can_read_project([user], project))
.to eq([user])
end
- it 'returns external users if they are the project owner' do
+ it "returns external users if they are the project owner" do
user1 = build(:user, external: true)
user2 = build(:user, external: true)
users = [user1, user2]
@@ -90,7 +90,7 @@ describe Ability do
.to eq([user1])
end
- it 'returns external users if they are project members' do
+ it "returns external users if they are project members" do
user1 = build(:user, external: true)
user2 = build(:user, external: true)
users = [user1, user2]
@@ -101,7 +101,7 @@ describe Ability do
.to eq([user1])
end
- it 'returns an empty Array if all users are internal users without access' do
+ it "returns an empty Array if all users are internal users without access" do
user1 = build(:user)
user2 = build(:user)
users = [user1, user2]
@@ -110,7 +110,7 @@ describe Ability do
.to eq([])
end
- it 'returns an empty Array if all users are external users without access' do
+ it "returns an empty Array if all users are external users without access" do
user1 = build(:user, external: true)
user2 = build(:user, external: true)
users = [user1, user2]
@@ -121,7 +121,7 @@ describe Ability do
end
end
- describe '.users_that_can_read_personal_snippet' do
+ describe ".users_that_can_read_personal_snippet" do
def users_for_snippet(snippet)
described_class.users_that_can_read_personal_snippet(users, snippet)
end
@@ -129,28 +129,28 @@ describe Ability do
let(:users) { create_list(:user, 3) }
let(:author) { users[0] }
- it 'private snippet is readable only by its author' do
+ it "private snippet is readable only by its author" do
snippet = create(:personal_snippet, :private, author: author)
expect(users_for_snippet(snippet)).to match_array([author])
end
- it 'internal snippet is readable by all registered users' do
+ it "internal snippet is readable by all registered users" do
snippet = create(:personal_snippet, :public, author: author)
expect(users_for_snippet(snippet)).to match_array(users)
end
- it 'public snippet is readable by all users' do
+ it "public snippet is readable by all users" do
snippet = create(:personal_snippet, :public, author: author)
expect(users_for_snippet(snippet)).to match_array(users)
end
end
- describe '.merge_requests_readable_by_user' do
- context 'with an admin' do
- it 'returns all merge requests' do
+ describe ".merge_requests_readable_by_user" do
+ context "with an admin" do
+ it "returns all merge requests" do
user = build(:user, admin: true)
merge_request = build(:merge_request)
@@ -159,19 +159,19 @@ describe Ability do
end
end
- context 'without a user' do
- it 'returns merge_requests that are publicly visible' do
+ context "without a user" do
+ it "returns merge_requests that are publicly visible" do
hidden_merge_request = build(:merge_request)
visible_merge_request = build(:merge_request, source_project: build(:project, :public))
merge_requests = described_class
- .merge_requests_readable_by_user([hidden_merge_request, visible_merge_request])
+ .merge_requests_readable_by_user([hidden_merge_request, visible_merge_request])
expect(merge_requests).to eq([visible_merge_request])
end
end
- context 'with a user' do
+ context "with a user" do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:merge_request) { create(:merge_request, source_project: project) }
@@ -191,27 +191,27 @@ describe Ability do
project.add_developer(user)
end
- it 'returns projects visible to the user' do
+ it "returns projects visible to the user" do
expect(readable_merge_requests).to contain_exactly(merge_request, cross_project_merge_request)
end
- context 'when a user cannot read cross project and a filter is passed' do
+ context "when a user cannot read cross project and a filter is passed" do
before do
allow(described_class).to receive(:allowed?).and_call_original
expect(described_class).to receive(:allowed?).with(user, :read_cross_project) { false }
end
subject(:readable_merge_requests) do
- read_cross_project_filter = -> (merge_requests) do
+ read_cross_project_filter = ->(merge_requests) do
merge_requests.select { |mr| mr.source_project == project }
end
described_class.merge_requests_readable_by_user(
all_merge_requests, user,
- filters: { read_cross_project: read_cross_project_filter }
+ filters: {read_cross_project: read_cross_project_filter}
)
end
- it 'returns only MRs of the specified project without checking access on others' do
+ it "returns only MRs of the specified project without checking access on others" do
expect(described_class).not_to receive(:allowed?).with(user, :read_merge_request, cross_project_merge_request)
expect(readable_merge_requests).to contain_exactly(merge_request)
@@ -220,9 +220,9 @@ describe Ability do
end
end
- describe '.issues_readable_by_user' do
- context 'with an admin user' do
- it 'returns all given issues' do
+ describe ".issues_readable_by_user" do
+ context "with an admin user" do
+ it "returns all given issues" do
user = build(:user, admin: true)
issue = build(:issue)
@@ -231,8 +231,8 @@ describe Ability do
end
end
- context 'with a regular user' do
- it 'returns the issues readable by the user' do
+ context "with a regular user" do
+ it "returns the issues readable by the user" do
user = build(:user)
issue = build(:issue)
@@ -242,7 +242,7 @@ describe Ability do
.to eq([issue])
end
- it 'returns an empty Array when no issues are readable' do
+ it "returns an empty Array when no issues are readable" do
user = build(:user)
issue = build(:issue)
@@ -252,8 +252,8 @@ describe Ability do
end
end
- context 'without a regular user' do
- it 'returns issues that are publicly visible' do
+ context "without a regular user" do
+ it "returns issues that are publicly visible" do
hidden_issue = build(:issue)
visible_issue = build(:issue)
@@ -267,7 +267,7 @@ describe Ability do
end
end
- context 'when the user cannot read cross project' do
+ context "when the user cannot read cross project" do
let(:user) { create(:user) }
let(:issue) { create(:issue) }
let(:other_project_issue) { create(:issue) }
@@ -280,10 +280,10 @@ describe Ability do
allow(described_class).to receive(:allowed?).with(user, :read_cross_project, any_args) { false }
end
- it 'excludes issues from other projects whithout checking separatly when passing a scope' do
+ it "excludes issues from other projects whithout checking separatly when passing a scope" do
expect(described_class).not_to receive(:allowed?).with(user, :read_issue, other_project_issue)
- filters = { read_cross_project: -> (issues) { issues.where(project: project) } }
+ filters = {read_cross_project: ->(issues) { issues.where(project: project) }}
result = described_class.issues_readable_by_user(Issue.all, user, filters: filters)
expect(result).to contain_exactly(issue)
@@ -291,13 +291,13 @@ describe Ability do
end
end
- describe '.project_disabled_features_rules' do
+ describe ".project_disabled_features_rules" do
let(:project) { create(:project, :wiki_disabled) }
subject { described_class.policy_for(project.owner, project) }
- context 'wiki named abilities' do
- it 'disables wiki abilities if the project has no wiki' do
+ context "wiki named abilities" do
+ it "disables wiki abilities if the project has no wiki" do
expect(subject).not_to be_allowed(:read_wiki)
expect(subject).not_to be_allowed(:create_wiki)
expect(subject).not_to be_allowed(:update_wiki)
diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb
index f49a61062c1..6c3ebe2cc43 100644
--- a/spec/models/abuse_report_spec.rb
+++ b/spec/models/abuse_report_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
describe AbuseReport do
set(:report) { create(:abuse_report) }
@@ -7,8 +7,8 @@ describe AbuseReport do
it { expect(subject).to be_valid }
- describe 'associations' do
- it { is_expected.to belong_to(:reporter).class_name('User') }
+ describe "associations" do
+ it { is_expected.to belong_to(:reporter).class_name("User") }
it { is_expected.to belong_to(:user) }
it "aliases reporter to author" do
@@ -16,34 +16,34 @@ describe AbuseReport do
end
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:reporter) }
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_presence_of(:message) }
- it { is_expected.to validate_uniqueness_of(:user_id).with_message('has already been reported') }
+ it { is_expected.to validate_uniqueness_of(:user_id).with_message("has already been reported") }
end
- describe '#remove_user' do
- it 'blocks the user' do
+ describe "#remove_user" do
+ it "blocks the user" do
expect { subject.remove_user(deleted_by: user) }.to change { subject.user.blocked? }.to(true)
end
- it 'lets a worker delete the user' do
+ it "lets a worker delete the user" do
expect(DeleteUserWorker).to receive(:perform_async).with(user.id, subject.user.id, hard_delete: true)
subject.remove_user(deleted_by: user)
end
end
- describe '#notify' do
- it 'delivers' do
+ describe "#notify" do
+ it "delivers" do
expect(AbuseReportMailer).to receive(:notify).with(subject.id)
.and_return(spy)
subject.notify
end
- it 'returns early when not persisted' do
+ it "returns early when not persisted" do
report = build(:abuse_report)
expect(AbuseReportMailer).not_to receive(:notify)
diff --git a/spec/models/active_session_spec.rb b/spec/models/active_session_spec.rb
index 129b2f92683..639baf3cfe3 100644
--- a/spec/models/active_session_spec.rb
+++ b/spec/models/active_session_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
let(:user) do
@@ -7,31 +7,31 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
end
end
- let(:session) { double(:session, id: '6919a6f1bb119dd7396fadc38fd18d0d') }
+ let(:session) { double(:session, id: "6919a6f1bb119dd7396fadc38fd18d0d") }
let(:request) do
double(:request, {
- user_agent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 ' \
- '(KHTML, like Gecko) Mobile/12B466 [FBDV/iPhone7,2]',
- ip: '127.0.0.1',
- session: session
+ user_agent: "Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 " \
+ "(KHTML, like Gecko) Mobile/12B466 [FBDV/iPhone7,2]",
+ ip: "127.0.0.1",
+ session: session,
})
end
- describe '#current?' do
- it 'returns true if the active session matches the current session' do
- active_session = ActiveSession.new(session_id: '6919a6f1bb119dd7396fadc38fd18d0d')
+ describe "#current?" do
+ it "returns true if the active session matches the current session" do
+ active_session = ActiveSession.new(session_id: "6919a6f1bb119dd7396fadc38fd18d0d")
expect(active_session.current?(session)).to be true
end
- it 'returns false if the active session does not match the current session' do
- active_session = ActiveSession.new(session_id: '59822c7d9fcdfa03725eff41782ad97d')
+ it "returns false if the active session does not match the current session" do
+ active_session = ActiveSession.new(session_id: "59822c7d9fcdfa03725eff41782ad97d")
expect(active_session.current?(session)).to be false
end
- it 'returns false if the session id is nil' do
+ it "returns false if the session id is nil" do
active_session = ActiveSession.new(session_id: nil)
session = double(:session, id: nil)
@@ -39,12 +39,12 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
end
end
- describe '.list' do
- it 'returns all sessions by user' do
+ describe ".list" do
+ it "returns all sessions by user" do
Gitlab::Redis::SharedState.with do |redis|
- redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", Marshal.dump({ session_id: 'a' }))
- redis.set("session:user:gitlab:#{user.id}:59822c7d9fcdfa03725eff41782ad97d", Marshal.dump({ session_id: 'b' }))
- redis.set("session:user:gitlab:9999:5c8611e4f9c69645ad1a1492f4131358", '')
+ redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", Marshal.dump({session_id: "a"}))
+ redis.set("session:user:gitlab:#{user.id}:59822c7d9fcdfa03725eff41782ad97d", Marshal.dump({session_id: "b"}))
+ redis.set("session:user:gitlab:9999:5c8611e4f9c69645ad1a1492f4131358", "")
redis.sadd(
"session:lookup:user:gitlab:#{user.id}",
@@ -55,12 +55,12 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
)
end
- expect(ActiveSession.list(user)).to match_array [{ session_id: 'a' }, { session_id: 'b' }]
+ expect(ActiveSession.list(user)).to match_array [{session_id: "a"}, {session_id: "b"}]
end
- it 'does not return obsolete entries and cleans them up' do
+ it "does not return obsolete entries and cleans them up" do
Gitlab::Redis::SharedState.with do |redis|
- redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", Marshal.dump({ session_id: 'a' }))
+ redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", Marshal.dump({session_id: "a"}))
redis.sadd(
"session:lookup:user:gitlab:#{user.id}",
@@ -71,52 +71,52 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
)
end
- expect(ActiveSession.list(user)).to eq [{ session_id: 'a' }]
+ expect(ActiveSession.list(user)).to eq [{session_id: "a"}]
Gitlab::Redis::SharedState.with do |redis|
- expect(redis.sscan_each("session:lookup:user:gitlab:#{user.id}").to_a).to eq ['6919a6f1bb119dd7396fadc38fd18d0d']
+ expect(redis.sscan_each("session:lookup:user:gitlab:#{user.id}").to_a).to eq ["6919a6f1bb119dd7396fadc38fd18d0d"]
end
end
- it 'returns an empty array if the use does not have any active session' do
+ it "returns an empty array if the use does not have any active session" do
expect(ActiveSession.list(user)).to eq []
end
end
- describe '.set' do
- it 'sets a new redis entry for the user session and a lookup entry' do
+ describe ".set" do
+ it "sets a new redis entry for the user session and a lookup entry" do
ActiveSession.set(user, request)
Gitlab::Redis::SharedState.with do |redis|
expect(redis.scan_each.to_a).to match_array [
"session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d",
- "session:lookup:user:gitlab:#{user.id}"
+ "session:lookup:user:gitlab:#{user.id}",
]
end
end
- it 'adds timestamps and information from the request' do
- Timecop.freeze(Time.zone.parse('2018-03-12 09:06')) do
+ it "adds timestamps and information from the request" do
+ Timecop.freeze(Time.zone.parse("2018-03-12 09:06")) do
ActiveSession.set(user, request)
session = ActiveSession.list(user)
expect(session.count).to eq 1
expect(session.first).to have_attributes(
- ip_address: '127.0.0.1',
- browser: 'Mobile Safari',
- os: 'iOS',
- device_name: 'iPhone 6',
- device_type: 'smartphone',
- created_at: Time.zone.parse('2018-03-12 09:06'),
- updated_at: Time.zone.parse('2018-03-12 09:06'),
- session_id: '6919a6f1bb119dd7396fadc38fd18d0d'
+ ip_address: "127.0.0.1",
+ browser: "Mobile Safari",
+ os: "iOS",
+ device_name: "iPhone 6",
+ device_type: "smartphone",
+ created_at: Time.zone.parse("2018-03-12 09:06"),
+ updated_at: Time.zone.parse("2018-03-12 09:06"),
+ session_id: "6919a6f1bb119dd7396fadc38fd18d0d"
)
end
end
- it 'keeps the created_at from the login on consecutive requests' do
- now = Time.zone.parse('2018-03-12 09:06')
+ it "keeps the created_at from the login on consecutive requests" do
+ now = Time.zone.parse("2018-03-12 09:06")
Timecop.freeze(now) do
ActiveSession.set(user, request)
@@ -127,20 +127,20 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
session = ActiveSession.list(user)
expect(session.first).to have_attributes(
- created_at: Time.zone.parse('2018-03-12 09:06'),
- updated_at: Time.zone.parse('2018-03-12 09:07')
+ created_at: Time.zone.parse("2018-03-12 09:06"),
+ updated_at: Time.zone.parse("2018-03-12 09:07")
)
end
end
end
end
- describe '.destroy' do
- it 'removes the entry associated with the currently killed user session' do
+ describe ".destroy" do
+ it "removes the entry associated with the currently killed user session" do
Gitlab::Redis::SharedState.with do |redis|
- redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", '')
- redis.set("session:user:gitlab:#{user.id}:59822c7d9fcdfa03725eff41782ad97d", '')
- redis.set("session:user:gitlab:9999:5c8611e4f9c69645ad1a1492f4131358", '')
+ redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", "")
+ redis.set("session:user:gitlab:#{user.id}:59822c7d9fcdfa03725eff41782ad97d", "")
+ redis.set("session:user:gitlab:9999:5c8611e4f9c69645ad1a1492f4131358", "")
end
ActiveSession.destroy(user, request.session.id)
@@ -148,15 +148,15 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
Gitlab::Redis::SharedState.with do |redis|
expect(redis.scan_each(match: "session:user:gitlab:*")).to match_array [
"session:user:gitlab:#{user.id}:59822c7d9fcdfa03725eff41782ad97d",
- "session:user:gitlab:9999:5c8611e4f9c69645ad1a1492f4131358"
+ "session:user:gitlab:9999:5c8611e4f9c69645ad1a1492f4131358",
]
end
end
- it 'removes the lookup entry' do
+ it "removes the lookup entry" do
Gitlab::Redis::SharedState.with do |redis|
- redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", '')
- redis.sadd("session:lookup:user:gitlab:#{user.id}", '6919a6f1bb119dd7396fadc38fd18d0d')
+ redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", "")
+ redis.sadd("session:lookup:user:gitlab:#{user.id}", "6919a6f1bb119dd7396fadc38fd18d0d")
end
ActiveSession.destroy(user, request.session.id)
@@ -166,10 +166,10 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
end
end
- it 'removes the devise session' do
+ it "removes the devise session" do
Gitlab::Redis::SharedState.with do |redis|
- redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", '')
- redis.set("session:gitlab:6919a6f1bb119dd7396fadc38fd18d0d", '')
+ redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", "")
+ redis.set("session:gitlab:6919a6f1bb119dd7396fadc38fd18d0d", "")
end
ActiveSession.destroy(user, request.session.id)
@@ -179,9 +179,9 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
end
end
- it 'does not remove the devise session if the active session could not be found' do
+ it "does not remove the devise session if the active session could not be found" do
Gitlab::Redis::SharedState.with do |redis|
- redis.set("session:gitlab:6919a6f1bb119dd7396fadc38fd18d0d", '')
+ redis.set("session:gitlab:6919a6f1bb119dd7396fadc38fd18d0d", "")
end
other_user = create(:user)
@@ -194,22 +194,22 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
end
end
- describe '.cleanup' do
- it 'removes obsolete lookup entries' do
+ describe ".cleanup" do
+ it "removes obsolete lookup entries" do
Gitlab::Redis::SharedState.with do |redis|
- redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", '')
- redis.sadd("session:lookup:user:gitlab:#{user.id}", '6919a6f1bb119dd7396fadc38fd18d0d')
- redis.sadd("session:lookup:user:gitlab:#{user.id}", '59822c7d9fcdfa03725eff41782ad97d')
+ redis.set("session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", "")
+ redis.sadd("session:lookup:user:gitlab:#{user.id}", "6919a6f1bb119dd7396fadc38fd18d0d")
+ redis.sadd("session:lookup:user:gitlab:#{user.id}", "59822c7d9fcdfa03725eff41782ad97d")
end
ActiveSession.cleanup(user)
Gitlab::Redis::SharedState.with do |redis|
- expect(redis.smembers("session:lookup:user:gitlab:#{user.id}")).to eq ['6919a6f1bb119dd7396fadc38fd18d0d']
+ expect(redis.smembers("session:lookup:user:gitlab:#{user.id}")).to eq ["6919a6f1bb119dd7396fadc38fd18d0d"]
end
end
- it 'does not bail if there are no lookup entries' do
+ it "does not bail if there are no lookup entries" do
ActiveSession.cleanup(user)
end
end
diff --git a/spec/models/appearance_spec.rb b/spec/models/appearance_spec.rb
index 3e95aa2b5dd..0d1792ac2c8 100644
--- a/spec/models/appearance_spec.rb
+++ b/spec/models/appearance_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
describe Appearance do
subject { build(:appearance) }
@@ -8,8 +8,8 @@ describe Appearance do
it { is_expected.to have_many(:uploads) }
- describe '#single_appearance_row' do
- it 'adds an error when more than 1 row exists' do
+ describe "#single_appearance_row" do
+ it "adds an error when more than 1 row exists" do
create(:appearance)
new_row = build(:appearance)
@@ -19,77 +19,77 @@ describe Appearance do
end
end
- context 'with uploads' do
- it_behaves_like 'model with uploads', false do
+ context "with uploads" do
+ it_behaves_like "model with uploads", false do
let(:model_object) { create(:appearance, :with_logo) }
let(:upload_attribute) { :logo }
let(:uploader_class) { AttachmentUploader }
end
end
- shared_examples 'logo paths' do |logo_type|
+ shared_examples "logo paths" do |logo_type|
let(:appearance) { create(:appearance, "with_#{logo_type}".to_sym) }
- let(:filename) { 'dk.png' }
+ let(:filename) { "dk.png" }
let(:expected_path) { "/uploads/-/system/appearance/#{logo_type}/#{appearance.id}/#{filename}" }
- it 'returns nil when there is no upload' do
+ it "returns nil when there is no upload" do
expect(subject.send("#{logo_type}_path")).to be_nil
end
- it 'returns the path when the upload has been orphaned' do
+ it "returns the path when the upload has been orphaned" do
appearance.send(logo_type).upload.destroy
appearance.reload
expect(appearance.send("#{logo_type}_path")).to eq(expected_path)
end
- it 'returns a local path using the system route' do
+ it "returns a local path using the system route" do
expect(appearance.send("#{logo_type}_path")).to eq(expected_path)
end
- describe 'with asset host configured' do
- let(:asset_host) { 'https://gitlab-assets.example.com' }
+ describe "with asset host configured" do
+ let(:asset_host) { "https://gitlab-assets.example.com" }
before do
allow(ActionController::Base).to receive(:asset_host) { asset_host }
end
- it 'returns a full URL with the system path' do
+ it "returns a full URL with the system path" do
expect(appearance.send("#{logo_type}_path")).to eq("#{asset_host}#{expected_path}")
end
end
end
- %i(logo header_logo favicon).each do |logo_type|
- it_behaves_like 'logo paths', logo_type
+ %i[logo header_logo favicon].each do |logo_type|
+ it_behaves_like "logo paths", logo_type
end
- describe 'validations' do
- let(:triplet) { '#000' }
- let(:hex) { '#AABBCC' }
+ describe "validations" do
+ let(:triplet) { "#000" }
+ let(:hex) { "#AABBCC" }
it { is_expected.to allow_value(nil).for(:message_background_color) }
it { is_expected.to allow_value(triplet).for(:message_background_color) }
it { is_expected.to allow_value(hex).for(:message_background_color) }
- it { is_expected.not_to allow_value('000').for(:message_background_color) }
+ it { is_expected.not_to allow_value("000").for(:message_background_color) }
it { is_expected.to allow_value(nil).for(:message_font_color) }
it { is_expected.to allow_value(triplet).for(:message_font_color) }
it { is_expected.to allow_value(hex).for(:message_font_color) }
- it { is_expected.not_to allow_value('000').for(:message_font_color) }
+ it { is_expected.not_to allow_value("000").for(:message_font_color) }
end
- describe 'email_header_and_footer_enabled' do
- context 'default email_header_and_footer_enabled flag value' do
- it 'returns email_header_and_footer_enabled as true' do
+ describe "email_header_and_footer_enabled" do
+ context "default email_header_and_footer_enabled flag value" do
+ it "returns email_header_and_footer_enabled as true" do
appearance = build(:appearance)
expect(appearance.email_header_and_footer_enabled?).to eq(false)
end
end
- context 'when setting email_header_and_footer_enabled flag value' do
- it 'returns email_header_and_footer_enabled as true' do
+ context "when setting email_header_and_footer_enabled flag value" do
+ it "returns email_header_and_footer_enabled as true" do
appearance = build(:appearance, email_header_and_footer_enabled: true)
expect(appearance.email_header_and_footer_enabled?).to eq(true)
diff --git a/spec/models/application_record_spec.rb b/spec/models/application_record_spec.rb
index fd25132ed3a..62065dce247 100644
--- a/spec/models/application_record_spec.rb
+++ b/spec/models/application_record_spec.rb
@@ -1,18 +1,18 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe ApplicationRecord do
- describe '#id_in' do
+ describe "#id_in" do
let(:records) { create_list(:user, 3) }
- it 'returns records of the ids' do
+ it "returns records of the ids" do
expect(User.id_in(records.last(2).map(&:id))).to eq(records.last(2))
end
end
- describe '.safe_find_or_create_by' do
- it 'creates the user avoiding race conditions' do
+ describe ".safe_find_or_create_by" do
+ it "creates the user avoiding race conditions" do
expect(Suggestion).to receive(:find_or_create_by).and_raise(ActiveRecord::RecordNotUnique)
allow(Suggestion).to receive(:find_or_create_by).and_call_original
@@ -21,15 +21,15 @@ describe ApplicationRecord do
end
end
- describe '.safe_find_or_create_by!' do
- it 'creates a record using safe_find_or_create_by' do
+ describe ".safe_find_or_create_by!" do
+ it "creates a record using safe_find_or_create_by" do
expect(Suggestion).to receive(:find_or_create_by).and_call_original
expect(Suggestion.safe_find_or_create_by!(build(:suggestion).attributes))
.to be_a(Suggestion)
end
- it 'raises a validation error if the record was not persisted' do
+ it "raises a validation error if the record was not persisted" do
expect { Suggestion.find_or_create_by!(note: nil) }.to raise_error(ActiveRecord::RecordInvalid)
end
end
diff --git a/spec/models/application_setting/term_spec.rb b/spec/models/application_setting/term_spec.rb
index aa49594f4d1..706d31d1938 100644
--- a/spec/models/application_setting/term_spec.rb
+++ b/spec/models/application_setting/term_spec.rb
@@ -1,41 +1,41 @@
-require 'spec_helper'
+require "spec_helper"
describe ApplicationSetting::Term do
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:terms) }
end
- describe '.latest' do
- it 'finds the latest terms' do
+ describe ".latest" do
+ it "finds the latest terms" do
terms = create(:term)
expect(described_class.latest).to eq(terms)
end
end
- describe '#accepted_by_user?' do
+ describe "#accepted_by_user?" do
let(:user) { create(:user) }
let(:term) { create(:term) }
- it 'is true when the user accepted the terms' do
+ it "is true when the user accepted the terms" do
accept_terms(term, user)
expect(term.accepted_by_user?(user)).to be(true)
end
- it 'is false when the user declined the terms' do
+ it "is false when the user declined the terms" do
decline_terms(term, user)
expect(term.accepted_by_user?(user)).to be(false)
end
- it 'does not cause a query when the user accepted the current terms' do
+ it "does not cause a query when the user accepted the current terms" do
accept_terms(term, user)
expect { term.accepted_by_user?(user) }.not_to exceed_query_limit(0)
end
- it 'returns false if the currently accepted terms are different' do
+ it "returns false if the currently accepted terms are different" do
accept_terms(create(:term), user)
expect(term.accepted_by_user?(user)).to be(false)
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index 789e14e8a20..e61418da06c 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ApplicationSetting do
let(:setting) { described_class.create_from_defaults }
@@ -10,10 +10,10 @@ describe ApplicationSetting do
it { expect(setting.uuid).to be_present }
it { expect(setting).to have_db_column(:auto_devops_enabled) }
- describe 'validations' do
- let(:http) { 'http://example.com' }
- let(:https) { 'https://example.com' }
- let(:ftp) { 'ftp://example.com' }
+ describe "validations" do
+ let(:http) { "http://example.com" }
+ let(:https) { "https://example.com" }
+ let(:ftp) { "ftp://example.com" }
it { is_expected.to allow_value(nil).for(:home_page_url) }
it { is_expected.to allow_value(http).for(:home_page_url) }
@@ -28,31 +28,31 @@ describe ApplicationSetting do
it { is_expected.to allow_value("dev.gitlab.com").for(:commit_email_hostname) }
it { is_expected.not_to allow_value("@dev.gitlab").for(:commit_email_hostname) }
- describe 'default_artifacts_expire_in' do
- it 'sets an error if it cannot parse' do
- setting.update(default_artifacts_expire_in: 'a')
+ describe "default_artifacts_expire_in" do
+ it "sets an error if it cannot parse" do
+ setting.update(default_artifacts_expire_in: "a")
expect_invalid
end
- it 'sets an error if it is blank' do
- setting.update(default_artifacts_expire_in: ' ')
+ it "sets an error if it is blank" do
+ setting.update(default_artifacts_expire_in: " ")
expect_invalid
end
- it 'sets the value if it is valid' do
- setting.update(default_artifacts_expire_in: '30 days')
+ it "sets the value if it is valid" do
+ setting.update(default_artifacts_expire_in: "30 days")
expect(setting).to be_valid
- expect(setting.default_artifacts_expire_in).to eq('30 days')
+ expect(setting.default_artifacts_expire_in).to eq("30 days")
end
- it 'sets the value if it is 0' do
- setting.update(default_artifacts_expire_in: '0')
+ it "sets the value if it is 0" do
+ setting.update(default_artifacts_expire_in: "0")
expect(setting).to be_valid
- expect(setting.default_artifacts_expire_in).to eq('0')
+ expect(setting.default_artifacts_expire_in).to eq("0")
end
def expect_invalid
@@ -77,12 +77,12 @@ describe ApplicationSetting do
.is_less_than(65536)
end
- context 'key restrictions' do
- it 'supports all key types' do
+ context "key restrictions" do
+ it "supports all key types" do
expect(described_class::SUPPORTED_KEY_TYPES).to contain_exactly(:rsa, :dsa, :ecdsa, :ed25519)
end
- it 'does not allow all key types to be disabled' do
+ it "does not allow all key types to be disabled" do
described_class::SUPPORTED_KEY_TYPES.each do |type|
setting["#{type}_key_restriction"] = described_class::FORBIDDEN_KEY_VALUE
end
@@ -104,120 +104,120 @@ describe ApplicationSetting do
end
end
- it_behaves_like 'an object with email-formated attributes', :admin_notification_email do
+ it_behaves_like "an object with email-formated attributes", :admin_notification_email do
subject { setting }
end
# Upgraded databases will have this sort of content
- context 'repository_storages is a String, not an Array' do
+ context "repository_storages is a String, not an Array" do
before do
- described_class.where(id: setting.id).update_all(repository_storages: 'default')
+ described_class.where(id: setting.id).update_all(repository_storages: "default")
end
- it { expect(setting.repository_storages).to eq(['default']) }
+ it { expect(setting.repository_storages).to eq(["default"]) }
end
- context '#commit_email_hostname' do
- it 'returns configured gitlab hostname if commit_email_hostname is not defined' do
+ context "#commit_email_hostname" do
+ it "returns configured gitlab hostname if commit_email_hostname is not defined" do
setting.update(commit_email_hostname: nil)
expect(setting.commit_email_hostname).to eq("users.noreply.#{Gitlab.config.gitlab.host}")
end
end
- context 'auto_devops_domain setting' do
- context 'when auto_devops_enabled? is true' do
+ context "auto_devops_domain setting" do
+ context "when auto_devops_enabled? is true" do
before do
setting.update(auto_devops_enabled: true)
end
- it 'can be blank' do
- setting.update(auto_devops_domain: '')
+ it "can be blank" do
+ setting.update(auto_devops_domain: "")
expect(setting).to be_valid
end
- context 'with a valid value' do
+ context "with a valid value" do
before do
- setting.update(auto_devops_domain: 'domain.com')
+ setting.update(auto_devops_domain: "domain.com")
end
- it 'is valid' do
+ it "is valid" do
expect(setting).to be_valid
end
end
- context 'with an invalid value' do
+ context "with an invalid value" do
before do
- setting.update(auto_devops_domain: 'definitelynotahostname')
+ setting.update(auto_devops_domain: "definitelynotahostname")
end
- it 'is invalid' do
+ it "is invalid" do
expect(setting).to be_invalid
end
end
end
end
- context 'repository storages' do
+ context "repository storages" do
before do
storages = {
- 'custom1' => 'tmp/tests/custom_repositories_1',
- 'custom2' => 'tmp/tests/custom_repositories_2',
- 'custom3' => 'tmp/tests/custom_repositories_3'
+ "custom1" => "tmp/tests/custom_repositories_1",
+ "custom2" => "tmp/tests/custom_repositories_2",
+ "custom3" => "tmp/tests/custom_repositories_3",
}
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end
- describe 'inclusion' do
- it { is_expected.to allow_value('custom1').for(:repository_storages) }
- it { is_expected.to allow_value(%w(custom2 custom3)).for(:repository_storages) }
- it { is_expected.not_to allow_value('alternative').for(:repository_storages) }
- it { is_expected.not_to allow_value(%w(alternative custom1)).for(:repository_storages) }
+ describe "inclusion" do
+ it { is_expected.to allow_value("custom1").for(:repository_storages) }
+ it { is_expected.to allow_value(%w[custom2 custom3]).for(:repository_storages) }
+ it { is_expected.not_to allow_value("alternative").for(:repository_storages) }
+ it { is_expected.not_to allow_value(%w[alternative custom1]).for(:repository_storages) }
end
- describe 'presence' do
+ describe "presence" do
it { is_expected.not_to allow_value([]).for(:repository_storages) }
it { is_expected.not_to allow_value("").for(:repository_storages) }
it { is_expected.not_to allow_value(nil).for(:repository_storages) }
end
- describe '.pick_repository_storage' do
- it 'uses Array#sample to pick a random storage' do
- array = double('array', sample: 'random')
+ describe ".pick_repository_storage" do
+ it "uses Array#sample to pick a random storage" do
+ array = double("array", sample: "random")
expect(setting).to receive(:repository_storages).and_return(array)
- expect(setting.pick_repository_storage).to eq('random')
+ expect(setting.pick_repository_storage).to eq("random")
end
end
end
- context 'housekeeping settings' do
+ context "housekeeping settings" do
it { is_expected.not_to allow_value(0).for(:housekeeping_incremental_repack_period) }
- it 'wants the full repack period to be at least the incremental repack period' do
+ it "wants the full repack period to be at least the incremental repack period" do
subject.housekeeping_incremental_repack_period = 2
subject.housekeeping_full_repack_period = 1
expect(subject).not_to be_valid
end
- it 'wants the gc period to be at least the full repack period' do
+ it "wants the gc period to be at least the full repack period" do
subject.housekeeping_full_repack_period = 100
subject.housekeeping_gc_period = 90
expect(subject).not_to be_valid
end
- it 'allows the same period for incremental repack and full repack, effectively skipping incremental repack' do
+ it "allows the same period for incremental repack and full repack, effectively skipping incremental repack" do
subject.housekeeping_incremental_repack_period = 2
subject.housekeeping_full_repack_period = 2
expect(subject).to be_valid
end
- it 'allows the same period for full repack and gc, effectively skipping full repack' do
+ it "allows the same period for full repack and gc, effectively skipping full repack" do
subject.housekeeping_full_repack_period = 100
subject.housekeeping_gc_period = 100
@@ -225,7 +225,7 @@ describe ApplicationSetting do
end
end
- context 'gitaly timeouts' do
+ context "gitaly timeouts" do
[:gitaly_timeout_default, :gitaly_timeout_medium, :gitaly_timeout_fast].each do |timeout_name|
it do
is_expected.to validate_presence_of(timeout_name)
@@ -243,7 +243,7 @@ describe ApplicationSetting do
end
end
- it 'accepts all timeouts equal' do
+ it "accepts all timeouts equal" do
subject.gitaly_timeout_default = 0
subject.gitaly_timeout_medium = 0
subject.gitaly_timeout_fast = 0
@@ -251,7 +251,7 @@ describe ApplicationSetting do
expect(subject).to be_valid
end
- it 'accepts timeouts in descending order' do
+ it "accepts timeouts in descending order" do
subject.gitaly_timeout_default = 50
subject.gitaly_timeout_medium = 30
subject.gitaly_timeout_fast = 20
@@ -259,7 +259,7 @@ describe ApplicationSetting do
expect(subject).to be_valid
end
- it 'rejects timeouts in ascending order' do
+ it "rejects timeouts in ascending order" do
subject.gitaly_timeout_default = 20
subject.gitaly_timeout_medium = 30
subject.gitaly_timeout_fast = 50
@@ -267,7 +267,7 @@ describe ApplicationSetting do
expect(subject).to be_invalid
end
- it 'rejects medium timeout larger than default' do
+ it "rejects medium timeout larger than default" do
subject.gitaly_timeout_default = 30
subject.gitaly_timeout_medium = 50
subject.gitaly_timeout_fast = 20
@@ -275,7 +275,7 @@ describe ApplicationSetting do
expect(subject).to be_invalid
end
- it 'rejects medium timeout smaller than fast' do
+ it "rejects medium timeout smaller than fast" do
subject.gitaly_timeout_default = 30
subject.gitaly_timeout_medium = 15
subject.gitaly_timeout_fast = 20
@@ -284,14 +284,14 @@ describe ApplicationSetting do
end
end
- describe 'enforcing terms' do
- it 'requires the terms to present when enforcing users to accept' do
+ describe "enforcing terms" do
+ it "requires the terms to present when enforcing users to accept" do
subject.enforce_terms = true
expect(subject).to be_invalid
end
- it 'is valid when terms are created' do
+ it "is valid when terms are created" do
create(:term)
subject.enforce_terms = true
@@ -300,39 +300,39 @@ describe ApplicationSetting do
end
end
- context 'restrict creating duplicates' do
+ context "restrict creating duplicates" do
before do
described_class.create_from_defaults
end
- it 'raises an record creation violation if already created' do
+ it "raises an record creation violation if already created" do
expect { described_class.create_from_defaults }.to raise_error(ActiveRecord::RecordNotUnique)
end
end
- describe 'setting Sentry DSNs' do
- context 'server DSN' do
- it 'strips leading and trailing whitespace' do
- subject.update(sentry_dsn: ' http://test ')
+ describe "setting Sentry DSNs" do
+ context "server DSN" do
+ it "strips leading and trailing whitespace" do
+ subject.update(sentry_dsn: " http://test ")
- expect(subject.sentry_dsn).to eq('http://test')
+ expect(subject.sentry_dsn).to eq("http://test")
end
- it 'handles nil values' do
+ it "handles nil values" do
subject.update(sentry_dsn: nil)
expect(subject.sentry_dsn).to be_nil
end
end
- context 'client-side DSN' do
- it 'strips leading and trailing whitespace' do
- subject.update(clientside_sentry_dsn: ' http://test ')
+ context "client-side DSN" do
+ it "strips leading and trailing whitespace" do
+ subject.update(clientside_sentry_dsn: " http://test ")
- expect(subject.clientside_sentry_dsn).to eq('http://test')
+ expect(subject.clientside_sentry_dsn).to eq("http://test")
end
- it 'handles nil values' do
+ it "handles nil values" do
subject.update(clientside_sentry_dsn: nil)
expect(subject.clientside_sentry_dsn).to be_nil
@@ -340,26 +340,26 @@ describe ApplicationSetting do
end
end
- describe '#disabled_oauth_sign_in_sources=' do
+ describe "#disabled_oauth_sign_in_sources=" do
before do
allow(Devise).to receive(:omniauth_providers).and_return([:github])
end
- it 'removes unknown sources (as strings) from the array' do
+ it "removes unknown sources (as strings) from the array" do
subject.disabled_oauth_sign_in_sources = %w[github test]
expect(subject).to be_valid
- expect(subject.disabled_oauth_sign_in_sources).to eq ['github']
+ expect(subject.disabled_oauth_sign_in_sources).to eq ["github"]
end
- it 'removes unknown sources (as symbols) from the array' do
+ it "removes unknown sources (as symbols) from the array" do
subject.disabled_oauth_sign_in_sources = %i[github test]
expect(subject).to be_valid
- expect(subject.disabled_oauth_sign_in_sources).to eq ['github']
+ expect(subject.disabled_oauth_sign_in_sources).to eq ["github"]
end
- it 'ignores nil' do
+ it "ignores nil" do
subject.disabled_oauth_sign_in_sources = nil
expect(subject).to be_valid
@@ -367,169 +367,169 @@ describe ApplicationSetting do
end
end
- context 'restricted signup domains' do
- it 'sets single domain' do
- setting.domain_whitelist_raw = 'example.com'
- expect(setting.domain_whitelist).to eq(['example.com'])
+ context "restricted signup domains" do
+ it "sets single domain" do
+ setting.domain_whitelist_raw = "example.com"
+ expect(setting.domain_whitelist).to eq(["example.com"])
end
- it 'sets multiple domains with spaces' do
- setting.domain_whitelist_raw = 'example.com *.example.com'
- expect(setting.domain_whitelist).to eq(['example.com', '*.example.com'])
+ it "sets multiple domains with spaces" do
+ setting.domain_whitelist_raw = "example.com *.example.com"
+ expect(setting.domain_whitelist).to eq(["example.com", "*.example.com"])
end
- it 'sets multiple domains with newlines and a space' do
+ it "sets multiple domains with newlines and a space" do
setting.domain_whitelist_raw = "example.com\n *.example.com"
- expect(setting.domain_whitelist).to eq(['example.com', '*.example.com'])
+ expect(setting.domain_whitelist).to eq(["example.com", "*.example.com"])
end
- it 'sets multiple domains with commas' do
+ it "sets multiple domains with commas" do
setting.domain_whitelist_raw = "example.com, *.example.com"
- expect(setting.domain_whitelist).to eq(['example.com', '*.example.com'])
+ expect(setting.domain_whitelist).to eq(["example.com", "*.example.com"])
end
end
- context 'blacklisted signup domains' do
- it 'sets single domain' do
- setting.domain_blacklist_raw = 'example.com'
- expect(setting.domain_blacklist).to contain_exactly('example.com')
+ context "blacklisted signup domains" do
+ it "sets single domain" do
+ setting.domain_blacklist_raw = "example.com"
+ expect(setting.domain_blacklist).to contain_exactly("example.com")
end
- it 'sets multiple domains with spaces' do
- setting.domain_blacklist_raw = 'example.com *.example.com'
- expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com')
+ it "sets multiple domains with spaces" do
+ setting.domain_blacklist_raw = "example.com *.example.com"
+ expect(setting.domain_blacklist).to contain_exactly("example.com", "*.example.com")
end
- it 'sets multiple domains with newlines and a space' do
+ it "sets multiple domains with newlines and a space" do
setting.domain_blacklist_raw = "example.com\n *.example.com"
- expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com')
+ expect(setting.domain_blacklist).to contain_exactly("example.com", "*.example.com")
end
- it 'sets multiple domains with commas' do
+ it "sets multiple domains with commas" do
setting.domain_blacklist_raw = "example.com, *.example.com"
- expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com')
+ expect(setting.domain_blacklist).to contain_exactly("example.com", "*.example.com")
end
- it 'sets multiple domains with semicolon' do
+ it "sets multiple domains with semicolon" do
setting.domain_blacklist_raw = "example.com; *.example.com"
- expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com')
+ expect(setting.domain_blacklist).to contain_exactly("example.com", "*.example.com")
end
- it 'sets multiple domains with mixture of everything' do
+ it "sets multiple domains with mixture of everything" do
setting.domain_blacklist_raw = "example.com; *.example.com\n test.com\sblock.com yes.com"
- expect(setting.domain_blacklist).to contain_exactly('example.com', '*.example.com', 'test.com', 'block.com', 'yes.com')
+ expect(setting.domain_blacklist).to contain_exactly("example.com", "*.example.com", "test.com", "block.com", "yes.com")
end
- it 'sets multiple domain with file' do
- setting.domain_blacklist_file = File.open(Rails.root.join('spec/fixtures/', 'domain_blacklist.txt'))
- expect(setting.domain_blacklist).to contain_exactly('example.com', 'test.com', 'foo.bar')
+ it "sets multiple domain with file" do
+ setting.domain_blacklist_file = File.open(Rails.root.join("spec/fixtures/", "domain_blacklist.txt"))
+ expect(setting.domain_blacklist).to contain_exactly("example.com", "test.com", "foo.bar")
end
end
- describe 'performance bar settings' do
- describe 'performance_bar_allowed_group' do
- context 'with no performance_bar_allowed_group_id saved' do
- it 'returns nil' do
+ describe "performance bar settings" do
+ describe "performance_bar_allowed_group" do
+ context "with no performance_bar_allowed_group_id saved" do
+ it "returns nil" do
expect(setting.performance_bar_allowed_group).to be_nil
end
end
- context 'with a performance_bar_allowed_group_id saved' do
+ context "with a performance_bar_allowed_group_id saved" do
let(:group) { create(:group) }
before do
setting.update!(performance_bar_allowed_group_id: group.id)
end
- it 'returns the group' do
+ it "returns the group" do
expect(setting.reload.performance_bar_allowed_group).to eq(group)
end
end
end
- describe 'performance_bar_enabled' do
- context 'with the Performance Bar is enabled' do
+ describe "performance_bar_enabled" do
+ context "with the Performance Bar is enabled" do
let(:group) { create(:group) }
before do
setting.update!(performance_bar_allowed_group_id: group.id)
end
- it 'returns true' do
+ it "returns true" do
expect(setting.reload.performance_bar_enabled).to be_truthy
end
end
end
end
- describe 'usage ping settings' do
- context 'when the usage ping is disabled in gitlab.yml' do
+ describe "usage ping settings" do
+ context "when the usage ping is disabled in gitlab.yml" do
before do
allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(false)
end
- it 'does not allow the usage ping to be configured' do
+ it "does not allow the usage ping to be configured" do
expect(setting.usage_ping_can_be_configured?).to be_falsey
end
- context 'when the usage ping is disabled in the DB' do
+ context "when the usage ping is disabled in the DB" do
before do
setting.usage_ping_enabled = false
end
- it 'returns false for usage_ping_enabled' do
+ it "returns false for usage_ping_enabled" do
expect(setting.usage_ping_enabled).to be_falsey
end
end
- context 'when the usage ping is enabled in the DB' do
+ context "when the usage ping is enabled in the DB" do
before do
setting.usage_ping_enabled = true
end
- it 'returns false for usage_ping_enabled' do
+ it "returns false for usage_ping_enabled" do
expect(setting.usage_ping_enabled).to be_falsey
end
end
end
- context 'when the usage ping is enabled in gitlab.yml' do
+ context "when the usage ping is enabled in gitlab.yml" do
before do
allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(true)
end
- it 'allows the usage ping to be configured' do
+ it "allows the usage ping to be configured" do
expect(setting.usage_ping_can_be_configured?).to be_truthy
end
- context 'when the usage ping is disabled in the DB' do
+ context "when the usage ping is disabled in the DB" do
before do
setting.usage_ping_enabled = false
end
- it 'returns false for usage_ping_enabled' do
+ it "returns false for usage_ping_enabled" do
expect(setting.usage_ping_enabled).to be_falsey
end
end
- context 'when the usage ping is enabled in the DB' do
+ context "when the usage ping is enabled in the DB" do
before do
setting.usage_ping_enabled = true
end
- it 'returns true for usage_ping_enabled' do
+ it "returns true for usage_ping_enabled" do
expect(setting.usage_ping_enabled).to be_truthy
end
end
end
end
- describe '#allowed_key_types' do
- it 'includes all key types by default' do
+ describe "#allowed_key_types" do
+ it "includes all key types by default" do
expect(setting.allowed_key_types).to contain_exactly(*described_class::SUPPORTED_KEY_TYPES)
end
- it 'excludes disabled key types' do
+ it "excludes disabled key types" do
expect(setting.allowed_key_types).to include(:ed25519)
setting.ed25519_key_restriction = described_class::FORBIDDEN_KEY_VALUE
@@ -538,50 +538,50 @@ describe ApplicationSetting do
end
end
- describe '#key_restriction_for' do
- it 'returns the restriction value for recognised types' do
+ describe "#key_restriction_for" do
+ it "returns the restriction value for recognised types" do
setting.rsa_key_restriction = 1024
expect(setting.key_restriction_for(:rsa)).to eq(1024)
end
- it 'allows types to be passed as a string' do
+ it "allows types to be passed as a string" do
setting.rsa_key_restriction = 1024
- expect(setting.key_restriction_for('rsa')).to eq(1024)
+ expect(setting.key_restriction_for("rsa")).to eq(1024)
end
- it 'returns forbidden for unrecognised type' do
+ it "returns forbidden for unrecognised type" do
expect(setting.key_restriction_for(:foo)).to eq(described_class::FORBIDDEN_KEY_VALUE)
end
end
- describe '#allow_signup?' do
- it 'returns true' do
+ describe "#allow_signup?" do
+ it "returns true" do
expect(setting.allow_signup?).to be_truthy
end
- it 'returns false if signup is disabled' do
+ it "returns false if signup is disabled" do
allow(setting).to receive(:signup_enabled?).and_return(false)
expect(setting.allow_signup?).to be_falsey
end
- it 'returns false if password authentication is disabled for the web interface' do
+ it "returns false if password authentication is disabled for the web interface" do
allow(setting).to receive(:password_authentication_enabled_for_web?).and_return(false)
expect(setting.allow_signup?).to be_falsey
end
end
- describe '#user_default_internal_regex_enabled?' do
+ describe "#user_default_internal_regex_enabled?" do
using RSpec::Parameterized::TableSyntax
where(:user_default_external, :user_default_internal_regex, :result) do
false | nil | false
- false | '' | false
+ false | "" | false
false | '^(?:(?!\.ext@).)*$\r?\n?' | false
- true | '' | false
+ true | "" | false
true | nil | false
true | '^(?:(?!\.ext@).)*$\r?\n?' | true
end
@@ -598,25 +598,25 @@ describe ApplicationSetting do
end
end
- context 'diff limit settings' do
- describe '#diff_max_patch_bytes' do
- context 'validations' do
+ context "diff limit settings" do
+ describe "#diff_max_patch_bytes" do
+ context "validations" do
it { is_expected.to validate_presence_of(:diff_max_patch_bytes) }
it do
is_expected.to validate_numericality_of(:diff_max_patch_bytes)
- .only_integer
- .is_greater_than_or_equal_to(Gitlab::Git::Diff::DEFAULT_MAX_PATCH_BYTES)
- .is_less_than_or_equal_to(Gitlab::Git::Diff::MAX_PATCH_BYTES_UPPER_BOUND)
+ .only_integer
+ .is_greater_than_or_equal_to(Gitlab::Git::Diff::DEFAULT_MAX_PATCH_BYTES)
+ .is_less_than_or_equal_to(Gitlab::Git::Diff::MAX_PATCH_BYTES_UPPER_BOUND)
end
end
end
end
- describe '#archive_builds_older_than' do
+ describe "#archive_builds_older_than" do
subject { setting.archive_builds_older_than }
- context 'when the archive_builds_in_seconds is set' do
+ context "when the archive_builds_in_seconds is set" do
before do
setting.archive_builds_in_seconds = 3600
end
@@ -624,7 +624,7 @@ describe ApplicationSetting do
it { is_expected.to be_within(1.minute).of(1.hour.ago) }
end
- context 'when the archive_builds_in_seconds is set' do
+ context "when the archive_builds_in_seconds is set" do
before do
setting.archive_builds_in_seconds = nil
end
diff --git a/spec/models/award_emoji_spec.rb b/spec/models/award_emoji_spec.rb
index 3f52091698c..2b5d612b8a9 100644
--- a/spec/models/award_emoji_spec.rb
+++ b/spec/models/award_emoji_spec.rb
@@ -1,12 +1,12 @@
-require 'spec_helper'
+require "spec_helper"
describe AwardEmoji do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to(:awardable) }
it { is_expected.to belong_to(:user) }
end
- describe 'modules' do
+ describe "modules" do
it { is_expected.to include_module(Participable) }
end
@@ -42,35 +42,35 @@ describe AwardEmoji do
end
end
- describe 'expiring ETag cache' do
- context 'on a note' do
+ describe "expiring ETag cache" do
+ context "on a note" do
let(:note) { create(:note_on_issue) }
let(:award_emoji) { build(:award_emoji, user: build(:user), awardable: note) }
- it 'calls expire_etag_cache on the note when saved' do
+ it "calls expire_etag_cache on the note when saved" do
expect(note).to receive(:expire_etag_cache)
award_emoji.save!
end
- it 'calls expire_etag_cache on the note when destroyed' do
+ it "calls expire_etag_cache on the note when destroyed" do
expect(note).to receive(:expire_etag_cache)
award_emoji.destroy!
end
end
- context 'on another awardable' do
+ context "on another awardable" do
let(:issue) { create(:issue) }
let(:award_emoji) { build(:award_emoji, user: build(:user), awardable: issue) }
- it 'does not call expire_etag_cache on the issue when saved' do
+ it "does not call expire_etag_cache on the issue when saved" do
expect(issue).not_to receive(:expire_etag_cache)
award_emoji.save!
end
- it 'does not call expire_etag_cache on the issue when destroyed' do
+ it "does not call expire_etag_cache on the issue when destroyed" do
expect(issue).not_to receive(:expire_etag_cache)
award_emoji.destroy!
@@ -78,26 +78,26 @@ describe AwardEmoji do
end
end
- describe '.award_counts_for_user' do
+ describe ".award_counts_for_user" do
let(:user) { create(:user) }
before do
- create(:award_emoji, user: user, name: 'thumbsup')
- create(:award_emoji, user: user, name: 'thumbsup')
- create(:award_emoji, user: user, name: 'thumbsdown')
- create(:award_emoji, user: user, name: '+1')
+ create(:award_emoji, user: user, name: "thumbsup")
+ create(:award_emoji, user: user, name: "thumbsup")
+ create(:award_emoji, user: user, name: "thumbsdown")
+ create(:award_emoji, user: user, name: "+1")
end
- it 'returns the awarded emoji in descending order' do
+ it "returns the awarded emoji in descending order" do
awards = described_class.award_counts_for_user(user)
- expect(awards).to eq('thumbsup' => 2, 'thumbsdown' => 1, '+1' => 1)
+ expect(awards).to eq("thumbsup" => 2, "thumbsdown" => 1, "+1" => 1)
end
- it 'limits the returned number of rows' do
+ it "limits the returned number of rows" do
awards = described_class.award_counts_for_user(user, 1)
- expect(awards).to eq('thumbsup' => 2)
+ expect(awards).to eq("thumbsup" => 2)
end
end
end
diff --git a/spec/models/badge_spec.rb b/spec/models/badge_spec.rb
index 33dc19e3432..f5d599c1b54 100644
--- a/spec/models/badge_spec.rb
+++ b/spec/models/badge_spec.rb
@@ -1,94 +1,94 @@
-require 'spec_helper'
+require "spec_helper"
describe Badge do
- let(:placeholder_url) { 'http://www.example.com/%{project_path}/%{project_id}/%{default_branch}/%{commit_sha}' }
+ let(:placeholder_url) { "http://www.example.com/%{project_path}/%{project_id}/%{default_branch}/%{commit_sha}" }
- describe 'validations' do
+ describe "validations" do
# Requires the let variable url_sym
- shared_examples 'placeholder url' do
+ shared_examples "placeholder url" do
let(:badge) { build(:badge) }
- it 'allows url with http protocol' do
- badge[url_sym] = 'http://www.example.com'
+ it "allows url with http protocol" do
+ badge[url_sym] = "http://www.example.com"
expect(badge).to be_valid
end
- it 'allows url with https protocol' do
- badge[url_sym] = 'https://www.example.com'
+ it "allows url with https protocol" do
+ badge[url_sym] = "https://www.example.com"
expect(badge).to be_valid
end
- it 'cannot be empty' do
- badge[url_sym] = ''
+ it "cannot be empty" do
+ badge[url_sym] = ""
expect(badge).not_to be_valid
end
- it 'cannot be nil' do
+ it "cannot be nil" do
badge[url_sym] = nil
expect(badge).not_to be_valid
end
- it 'accept badges placeholders' do
+ it "accept badges placeholders" do
badge[url_sym] = placeholder_url
expect(badge).to be_valid
end
- it 'sanitize url' do
- badge[url_sym] = 'javascript:alert(1)'
+ it "sanitize url" do
+ badge[url_sym] = "javascript:alert(1)"
expect(badge).not_to be_valid
end
end
- context 'link_url format' do
+ context "link_url format" do
let(:url_sym) { :link_url }
- it_behaves_like 'placeholder url'
+ it_behaves_like "placeholder url"
end
- context 'image_url format' do
+ context "image_url format" do
let(:url_sym) { :image_url }
- it_behaves_like 'placeholder url'
+ it_behaves_like "placeholder url"
end
end
- shared_examples 'rendered_links' do
- it 'should use the project information to populate the url placeholders' do
+ shared_examples "rendered_links" do
+ it "should use the project information to populate the url placeholders" do
stub_project_commit_info(project)
expect(badge.public_send("rendered_#{method}", project)).to eq "http://www.example.com/#{project.full_path}/#{project.id}/master/whatever"
end
- it 'returns the url if the project used is nil' do
+ it "returns the url if the project used is nil" do
expect(badge.public_send("rendered_#{method}", nil)).to eq placeholder_url
end
def stub_project_commit_info(project)
- allow(project).to receive(:commit).and_return(double('Commit', sha: 'whatever'))
- allow(project).to receive(:default_branch).and_return('master')
+ allow(project).to receive(:commit).and_return(double("Commit", sha: "whatever"))
+ allow(project).to receive(:default_branch).and_return("master")
end
end
- context 'methods' do
+ context "methods" do
let(:badge) { build(:badge, link_url: placeholder_url, image_url: placeholder_url) }
let!(:project) { create(:project) }
- context '#rendered_link_url' do
+ context "#rendered_link_url" do
let(:method) { :link_url }
- it_behaves_like 'rendered_links'
+ it_behaves_like "rendered_links"
end
- context '#rendered_image_url' do
+ context "#rendered_image_url" do
let(:method) { :image_url }
- it_behaves_like 'rendered_links'
+ it_behaves_like "rendered_links"
end
end
end
diff --git a/spec/models/badges/group_badge_spec.rb b/spec/models/badges/group_badge_spec.rb
index ed7f83d0489..cec40f0d1f6 100644
--- a/spec/models/badges/group_badge_spec.rb
+++ b/spec/models/badges/group_badge_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe GroupBadge do
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:group) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:group) }
end
end
diff --git a/spec/models/badges/project_badge_spec.rb b/spec/models/badges/project_badge_spec.rb
index 0e1a8159cb6..e3ee0593e49 100644
--- a/spec/models/badges/project_badge_spec.rb
+++ b/spec/models/badges/project_badge_spec.rb
@@ -1,43 +1,43 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectBadge do
- let(:placeholder_url) { 'http://www.example.com/%{project_path}/%{project_id}/%{default_branch}/%{commit_sha}' }
+ let(:placeholder_url) { "http://www.example.com/%{project_path}/%{project_id}/%{default_branch}/%{commit_sha}" }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:project) }
end
- shared_examples 'rendered_links' do
- it 'should use the badge project information to populate the url placeholders' do
+ shared_examples "rendered_links" do
+ it "should use the badge project information to populate the url placeholders" do
stub_project_commit_info(project)
expect(badge.public_send("rendered_#{method}")).to eq "http://www.example.com/#{project.full_path}/#{project.id}/master/whatever"
end
def stub_project_commit_info(project)
- allow(project).to receive(:commit).and_return(double('Commit', sha: 'whatever'))
- allow(project).to receive(:default_branch).and_return('master')
+ allow(project).to receive(:commit).and_return(double("Commit", sha: "whatever"))
+ allow(project).to receive(:default_branch).and_return("master")
end
end
- context 'methods' do
+ context "methods" do
let(:badge) { build(:project_badge, link_url: placeholder_url, image_url: placeholder_url) }
let!(:project) { badge.project }
- context '#rendered_link_url' do
+ context "#rendered_link_url" do
let(:method) { :link_url }
- it_behaves_like 'rendered_links'
+ it_behaves_like "rendered_links"
end
- context '#rendered_image_url' do
+ context "#rendered_image_url" do
let(:method) { :image_url }
- it_behaves_like 'rendered_links'
+ it_behaves_like "rendered_links"
end
end
end
diff --git a/spec/models/blob_spec.rb b/spec/models/blob_spec.rb
index 05cf242e84d..c3aa1dc17cd 100644
--- a/spec/models/blob_spec.rb
+++ b/spec/models/blob_spec.rb
@@ -1,5 +1,4 @@
-# encoding: utf-8
-require 'rails_helper'
+require "rails_helper"
describe Blob do
include FakeBlobHelpers
@@ -10,32 +9,32 @@ describe Blob do
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
end
- describe '.decorate' do
- it 'returns NilClass when given nil' do
+ describe ".decorate" do
+ it "returns NilClass when given nil" do
expect(described_class.decorate(nil)).to be_nil
end
end
- describe '.lazy' do
+ describe ".lazy" do
let(:project) { create(:project, :repository) }
let(:same_project) { Project.find(project.id) }
let(:other_project) { create(:project, :repository) }
- let(:commit_id) { 'e63f41fe459e62e1228fcef60d7189127aeba95a' }
+ let(:commit_id) { "e63f41fe459e62e1228fcef60d7189127aeba95a" }
- it 'does not fetch blobs when none are accessed' do
+ it "does not fetch blobs when none are accessed" do
expect(project.repository).not_to receive(:blobs_at)
- described_class.lazy(project, commit_id, 'CHANGELOG')
+ described_class.lazy(project, commit_id, "CHANGELOG")
end
- it 'fetches all blobs for the same repository when one is accessed' do
- expect(project.repository).to receive(:blobs_at).with([[commit_id, 'CHANGELOG'], [commit_id, 'CONTRIBUTING.md']]).once.and_call_original
+ it "fetches all blobs for the same repository when one is accessed" do
+ expect(project.repository).to receive(:blobs_at).with([[commit_id, "CHANGELOG"], [commit_id, "CONTRIBUTING.md"]]).once.and_call_original
expect(other_project.repository).not_to receive(:blobs_at)
- changelog = described_class.lazy(project, commit_id, 'CHANGELOG')
- contributing = described_class.lazy(same_project, commit_id, 'CONTRIBUTING.md')
+ changelog = described_class.lazy(project, commit_id, "CHANGELOG")
+ contributing = described_class.lazy(same_project, commit_id, "CONTRIBUTING.md")
- described_class.lazy(other_project, commit_id, 'CHANGELOG')
+ described_class.lazy(other_project, commit_id, "CHANGELOG")
# Access property so the values are loaded
changelog.id
@@ -43,9 +42,9 @@ describe Blob do
end
end
- describe '#data' do
- context 'using a binary blob' do
- it 'returns the data as-is' do
+ describe "#data" do
+ context "using a binary blob" do
+ it "returns the data as-is" do
data = "\n\xFF\xB9\xC3"
blob = fake_blob(binary: true, data: data)
@@ -53,8 +52,8 @@ describe Blob do
end
end
- context 'using a text blob' do
- it 'converts the data to UTF-8' do
+ context "using a text blob" do
+ it "converts the data to UTF-8" do
blob = fake_blob(binary: false, data: "\n\xFF\xB9\xC3")
expect(blob.data).to eq("\n���")
@@ -62,80 +61,80 @@ describe Blob do
end
end
- describe '#external_storage_error?' do
- context 'if the blob is stored in LFS' do
- let(:blob) { fake_blob(path: 'file.pdf', lfs: true) }
+ describe "#external_storage_error?" do
+ context "if the blob is stored in LFS" do
+ let(:blob) { fake_blob(path: "file.pdf", lfs: true) }
- context 'when the project has LFS enabled' do
- it 'returns false' do
+ context "when the project has LFS enabled" do
+ it "returns false" do
expect(blob.external_storage_error?).to be_falsey
end
end
- context 'when the project does not have LFS enabled' do
+ context "when the project does not have LFS enabled" do
before do
project.lfs_enabled = false
end
- it 'returns true' do
+ it "returns true" do
expect(blob.external_storage_error?).to be_truthy
end
end
end
- context 'if the blob is not stored in LFS' do
- let(:blob) { fake_blob(path: 'file.md') }
+ context "if the blob is not stored in LFS" do
+ let(:blob) { fake_blob(path: "file.md") }
- it 'returns false' do
+ it "returns false" do
expect(blob.external_storage_error?).to be_falsey
end
end
end
- describe '#stored_externally?' do
- context 'if the blob is stored in LFS' do
- let(:blob) { fake_blob(path: 'file.pdf', lfs: true) }
+ describe "#stored_externally?" do
+ context "if the blob is stored in LFS" do
+ let(:blob) { fake_blob(path: "file.pdf", lfs: true) }
- context 'when the project has LFS enabled' do
- it 'returns true' do
+ context "when the project has LFS enabled" do
+ it "returns true" do
expect(blob.stored_externally?).to be_truthy
end
end
- context 'when the project does not have LFS enabled' do
+ context "when the project does not have LFS enabled" do
before do
project.lfs_enabled = false
end
- it 'returns false' do
+ it "returns false" do
expect(blob.stored_externally?).to be_falsey
end
end
end
- context 'if the blob is not stored in LFS' do
- let(:blob) { fake_blob(path: 'file.md') }
+ context "if the blob is not stored in LFS" do
+ let(:blob) { fake_blob(path: "file.md") }
- it 'returns false' do
+ it "returns false" do
expect(blob.stored_externally?).to be_falsey
end
end
end
- describe '#binary?' do
- context 'if the blob is stored externally' do
- context 'if the extension has a rich viewer' do
- context 'if the viewer is binary' do
- it 'returns true' do
- blob = fake_blob(path: 'file.pdf', lfs: true)
+ describe "#binary?" do
+ context "if the blob is stored externally" do
+ context "if the extension has a rich viewer" do
+ context "if the viewer is binary" do
+ it "returns true" do
+ blob = fake_blob(path: "file.pdf", lfs: true)
expect(blob.binary?).to be_truthy
end
end
- context 'if the viewer is text-based' do
- it 'return false' do
- blob = fake_blob(path: 'file.md', lfs: true)
+ context "if the viewer is text-based" do
+ it "return false" do
+ blob = fake_blob(path: "file.md", lfs: true)
expect(blob.binary?).to be_falsey
end
@@ -143,54 +142,54 @@ describe Blob do
end
context "if the extension doesn't have a rich viewer" do
- context 'if the extension has a text mime type' do
- context 'if the extension is for a programming language' do
- it 'returns false' do
- blob = fake_blob(path: 'file.txt', lfs: true)
+ context "if the extension has a text mime type" do
+ context "if the extension is for a programming language" do
+ it "returns false" do
+ blob = fake_blob(path: "file.txt", lfs: true)
expect(blob.binary?).to be_falsey
end
end
- context 'if the extension is not for a programming language' do
- it 'returns false' do
- blob = fake_blob(path: 'file.ics', lfs: true)
+ context "if the extension is not for a programming language" do
+ it "returns false" do
+ blob = fake_blob(path: "file.ics", lfs: true)
expect(blob.binary?).to be_falsey
end
end
end
- context 'if the extension has a binary mime type' do
- context 'if the extension is for a programming language' do
- it 'returns false' do
- blob = fake_blob(path: 'file.rb', lfs: true)
+ context "if the extension has a binary mime type" do
+ context "if the extension is for a programming language" do
+ it "returns false" do
+ blob = fake_blob(path: "file.rb", lfs: true)
expect(blob.binary?).to be_falsey
end
end
- context 'if the extension is not for a programming language' do
- it 'returns true' do
- blob = fake_blob(path: 'file.exe', lfs: true)
+ context "if the extension is not for a programming language" do
+ it "returns true" do
+ blob = fake_blob(path: "file.exe", lfs: true)
expect(blob.binary?).to be_truthy
end
end
end
- context 'if the extension has an unknown mime type' do
- context 'if the extension is for a programming language' do
- it 'returns false' do
- blob = fake_blob(path: 'file.ini', lfs: true)
+ context "if the extension has an unknown mime type" do
+ context "if the extension is for a programming language" do
+ it "returns false" do
+ blob = fake_blob(path: "file.ini", lfs: true)
expect(blob.binary?).to be_falsey
end
end
- context 'if the extension is not for a programming language' do
- it 'returns true' do
- blob = fake_blob(path: 'file.wtf', lfs: true)
+ context "if the extension is not for a programming language" do
+ it "returns true" do
+ blob = fake_blob(path: "file.wtf", lfs: true)
expect(blob.binary?).to be_truthy
end
@@ -199,18 +198,18 @@ describe Blob do
end
end
- context 'if the blob is not stored externally' do
- context 'if the blob is binary' do
- it 'returns true' do
- blob = fake_blob(path: 'file.pdf', binary: true)
+ context "if the blob is not stored externally" do
+ context "if the blob is binary" do
+ it "returns true" do
+ blob = fake_blob(path: "file.pdf", binary: true)
expect(blob.binary?).to be_truthy
end
end
- context 'if the blob is text-based' do
- it 'return false' do
- blob = fake_blob(path: 'file.md')
+ context "if the blob is text-based" do
+ it "return false" do
+ blob = fake_blob(path: "file.md")
expect(blob.binary?).to be_falsey
end
@@ -218,41 +217,41 @@ describe Blob do
end
end
- describe '#extension' do
- it 'returns the extension' do
- blob = fake_blob(path: 'file.md')
+ describe "#extension" do
+ it "returns the extension" do
+ blob = fake_blob(path: "file.md")
- expect(blob.extension).to eq('md')
+ expect(blob.extension).to eq("md")
end
end
- describe '#file_type' do
- it 'returns the file type' do
- blob = fake_blob(path: 'README.md')
+ describe "#file_type" do
+ it "returns the file type" do
+ blob = fake_blob(path: "README.md")
expect(blob.file_type).to eq(:readme)
end
end
- describe '#simple_viewer' do
- context 'when the blob is empty' do
- it 'returns an empty viewer' do
- blob = fake_blob(data: '', size: 0)
+ describe "#simple_viewer" do
+ context "when the blob is empty" do
+ it "returns an empty viewer" do
+ blob = fake_blob(data: "", size: 0)
expect(blob.simple_viewer).to be_a(BlobViewer::Empty)
end
end
- context 'when the file represented by the blob is binary' do
- it 'returns a download viewer' do
+ context "when the file represented by the blob is binary" do
+ it "returns a download viewer" do
blob = fake_blob(binary: true)
expect(blob.simple_viewer).to be_a(BlobViewer::Download)
end
end
- context 'when the file represented by the blob is text-based' do
- it 'returns a text viewer' do
+ context "when the file represented by the blob is text-based" do
+ it "returns a text viewer" do
blob = fake_blob
expect(blob.simple_viewer).to be_a(BlobViewer::Text)
@@ -260,129 +259,129 @@ describe Blob do
end
end
- describe '#rich_viewer' do
- context 'when the blob has an external storage error' do
+ describe "#rich_viewer" do
+ context "when the blob has an external storage error" do
before do
project.lfs_enabled = false
end
- it 'returns nil' do
- blob = fake_blob(path: 'file.pdf', lfs: true)
+ it "returns nil" do
+ blob = fake_blob(path: "file.pdf", lfs: true)
expect(blob.rich_viewer).to be_nil
end
end
- context 'when the blob is empty' do
- it 'returns nil' do
- blob = fake_blob(data: '')
+ context "when the blob is empty" do
+ it "returns nil" do
+ blob = fake_blob(data: "")
expect(blob.rich_viewer).to be_nil
end
end
- context 'when the blob is stored externally' do
- it 'returns a matching viewer' do
- blob = fake_blob(path: 'file.pdf', lfs: true)
+ context "when the blob is stored externally" do
+ it "returns a matching viewer" do
+ blob = fake_blob(path: "file.pdf", lfs: true)
expect(blob.rich_viewer).to be_a(BlobViewer::PDF)
end
end
- context 'when the blob is binary' do
- it 'returns a matching binary viewer' do
- blob = fake_blob(path: 'file.pdf', binary: true)
+ context "when the blob is binary" do
+ it "returns a matching binary viewer" do
+ blob = fake_blob(path: "file.pdf", binary: true)
expect(blob.rich_viewer).to be_a(BlobViewer::PDF)
end
end
- context 'when the blob is text-based' do
- it 'returns a matching text-based viewer' do
- blob = fake_blob(path: 'file.md')
+ context "when the blob is text-based" do
+ it "returns a matching text-based viewer" do
+ blob = fake_blob(path: "file.md")
expect(blob.rich_viewer).to be_a(BlobViewer::Markup)
end
end
end
- describe '#auxiliary_viewer' do
- context 'when the blob has an external storage error' do
+ describe "#auxiliary_viewer" do
+ context "when the blob has an external storage error" do
before do
project.lfs_enabled = false
end
- it 'returns nil' do
- blob = fake_blob(path: 'LICENSE', lfs: true)
+ it "returns nil" do
+ blob = fake_blob(path: "LICENSE", lfs: true)
expect(blob.auxiliary_viewer).to be_nil
end
end
- context 'when the blob is empty' do
- it 'returns nil' do
- blob = fake_blob(data: '')
+ context "when the blob is empty" do
+ it "returns nil" do
+ blob = fake_blob(data: "")
expect(blob.auxiliary_viewer).to be_nil
end
end
- context 'when the blob is stored externally' do
- it 'returns a matching viewer' do
- blob = fake_blob(path: 'LICENSE', lfs: true)
+ context "when the blob is stored externally" do
+ it "returns a matching viewer" do
+ blob = fake_blob(path: "LICENSE", lfs: true)
expect(blob.auxiliary_viewer).to be_a(BlobViewer::License)
end
end
- context 'when the blob is binary' do
- it 'returns nil' do
- blob = fake_blob(path: 'LICENSE', binary: true)
+ context "when the blob is binary" do
+ it "returns nil" do
+ blob = fake_blob(path: "LICENSE", binary: true)
expect(blob.auxiliary_viewer).to be_nil
end
end
- context 'when the blob is text-based' do
- it 'returns a matching text-based viewer' do
- blob = fake_blob(path: 'LICENSE')
+ context "when the blob is text-based" do
+ it "returns a matching text-based viewer" do
+ blob = fake_blob(path: "LICENSE")
expect(blob.auxiliary_viewer).to be_a(BlobViewer::License)
end
end
end
- describe '#rendered_as_text?' do
- context 'when ignoring errors' do
- context 'when the simple viewer is text-based' do
- it 'returns true' do
- blob = fake_blob(path: 'file.md', size: 100.megabytes)
+ describe "#rendered_as_text?" do
+ context "when ignoring errors" do
+ context "when the simple viewer is text-based" do
+ it "returns true" do
+ blob = fake_blob(path: "file.md", size: 100.megabytes)
expect(blob.rendered_as_text?).to be_truthy
end
end
- context 'when the simple viewer is binary' do
- it 'returns false' do
- blob = fake_blob(path: 'file.pdf', binary: true, size: 100.megabytes)
+ context "when the simple viewer is binary" do
+ it "returns false" do
+ blob = fake_blob(path: "file.pdf", binary: true, size: 100.megabytes)
expect(blob.rendered_as_text?).to be_falsey
end
end
end
- context 'when not ignoring errors' do
- context 'when the viewer has render errors' do
- it 'returns false' do
- blob = fake_blob(path: 'file.md', size: 100.megabytes)
+ context "when not ignoring errors" do
+ context "when the viewer has render errors" do
+ it "returns false" do
+ blob = fake_blob(path: "file.md", size: 100.megabytes)
expect(blob.rendered_as_text?(ignore_errors: false)).to be_falsey
end
end
context "when the viewer doesn't have render errors" do
- it 'returns true' do
- blob = fake_blob(path: 'file.md')
+ it "returns true" do
+ blob = fake_blob(path: "file.md")
expect(blob.rendered_as_text?(ignore_errors: false)).to be_truthy
end
diff --git a/spec/models/blob_viewer/base_spec.rb b/spec/models/blob_viewer/base_spec.rb
index 7ba28f72215..1d2e418e2b5 100644
--- a/spec/models/blob_viewer/base_spec.rb
+++ b/spec/models/blob_viewer/base_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::Base do
include FakeBlobHelpers
@@ -9,7 +9,7 @@ describe BlobViewer::Base do
Class.new(described_class) do
include BlobViewer::ServerSide
- self.extensions = %w(pdf)
+ self.extensions = %w[pdf]
self.binary = true
self.collapse_limit = 1.megabyte
self.size_limit = 5.megabytes
@@ -18,129 +18,129 @@ describe BlobViewer::Base do
let(:viewer) { viewer_class.new(blob) }
- describe '.can_render?' do
- context 'when the extension is supported' do
- context 'when the binaryness matches' do
- let(:blob) { fake_blob(path: 'file.pdf', binary: true) }
+ describe ".can_render?" do
+ context "when the extension is supported" do
+ context "when the binaryness matches" do
+ let(:blob) { fake_blob(path: "file.pdf", binary: true) }
- it 'returns true' do
+ it "returns true" do
expect(viewer_class.can_render?(blob)).to be_truthy
end
end
- context 'when the binaryness does not match' do
- let(:blob) { fake_blob(path: 'file.pdf', binary: false) }
+ context "when the binaryness does not match" do
+ let(:blob) { fake_blob(path: "file.pdf", binary: false) }
- it 'returns false' do
+ it "returns false" do
expect(viewer_class.can_render?(blob)).to be_falsey
end
end
end
- context 'when the file type is supported' do
+ context "when the file type is supported" do
before do
- viewer_class.file_types = %i(license)
+ viewer_class.file_types = %i[license]
viewer_class.binary = false
end
- context 'when the binaryness matches' do
- let(:blob) { fake_blob(path: 'LICENSE', binary: false) }
+ context "when the binaryness matches" do
+ let(:blob) { fake_blob(path: "LICENSE", binary: false) }
- it 'returns true' do
+ it "returns true" do
expect(viewer_class.can_render?(blob)).to be_truthy
end
end
- context 'when the binaryness does not match' do
- let(:blob) { fake_blob(path: 'LICENSE', binary: true) }
+ context "when the binaryness does not match" do
+ let(:blob) { fake_blob(path: "LICENSE", binary: true) }
- it 'returns false' do
+ it "returns false" do
expect(viewer_class.can_render?(blob)).to be_falsey
end
end
end
- context 'when the extension and file type are not supported' do
- let(:blob) { fake_blob(path: 'file.txt') }
+ context "when the extension and file type are not supported" do
+ let(:blob) { fake_blob(path: "file.txt") }
- it 'returns false' do
+ it "returns false" do
expect(viewer_class.can_render?(blob)).to be_falsey
end
end
end
- describe '#collapsed?' do
- context 'when the blob size is larger than the collapse limit' do
- let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
+ describe "#collapsed?" do
+ context "when the blob size is larger than the collapse limit" do
+ let(:blob) { fake_blob(path: "file.pdf", size: 2.megabytes) }
- it 'returns true' do
+ it "returns true" do
expect(viewer.collapsed?).to be_truthy
end
end
- context 'when the blob size is smaller than the collapse limit' do
- let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) }
+ context "when the blob size is smaller than the collapse limit" do
+ let(:blob) { fake_blob(path: "file.pdf", size: 10.kilobytes) }
- it 'returns false' do
+ it "returns false" do
expect(viewer.collapsed?).to be_falsey
end
end
end
- describe '#too_large?' do
- context 'when the blob size is larger than the size limit' do
- let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) }
+ describe "#too_large?" do
+ context "when the blob size is larger than the size limit" do
+ let(:blob) { fake_blob(path: "file.pdf", size: 10.megabytes) }
- it 'returns true' do
+ it "returns true" do
expect(viewer.too_large?).to be_truthy
end
end
- context 'when the blob size is smaller than the size limit' do
- let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
+ context "when the blob size is smaller than the size limit" do
+ let(:blob) { fake_blob(path: "file.pdf", size: 2.megabytes) }
- it 'returns false' do
+ it "returns false" do
expect(viewer.too_large?).to be_falsey
end
end
end
- describe '#render_error' do
- context 'when the blob is expanded' do
+ describe "#render_error" do
+ context "when the blob is expanded" do
before do
blob.expand!
end
- context 'when the blob size is larger than the size limit' do
- let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) }
+ context "when the blob size is larger than the size limit" do
+ let(:blob) { fake_blob(path: "file.pdf", size: 10.megabytes) }
- it 'returns :too_large' do
+ it "returns :too_large" do
expect(viewer.render_error).to eq(:too_large)
end
end
- context 'when the blob size is smaller than the size limit' do
- let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
+ context "when the blob size is smaller than the size limit" do
+ let(:blob) { fake_blob(path: "file.pdf", size: 2.megabytes) }
- it 'returns nil' do
+ it "returns nil" do
expect(viewer.render_error).to be_nil
end
end
end
- context 'when not expanded' do
- context 'when the blob size is larger than the collapse limit' do
- let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
+ context "when not expanded" do
+ context "when the blob size is larger than the collapse limit" do
+ let(:blob) { fake_blob(path: "file.pdf", size: 2.megabytes) }
- it 'returns :collapsed' do
+ it "returns :collapsed" do
expect(viewer.render_error).to eq(:collapsed)
end
end
- context 'when the blob size is smaller than the collapse limit' do
- let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) }
+ context "when the blob size is smaller than the collapse limit" do
+ let(:blob) { fake_blob(path: "file.pdf", size: 10.kilobytes) }
- it 'returns nil' do
+ it "returns nil" do
expect(viewer.render_error).to be_nil
end
end
diff --git a/spec/models/blob_viewer/changelog_spec.rb b/spec/models/blob_viewer/changelog_spec.rb
index db41eca0fc8..72153189c19 100644
--- a/spec/models/blob_viewer/changelog_spec.rb
+++ b/spec/models/blob_viewer/changelog_spec.rb
@@ -1,25 +1,25 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::Changelog do
include FakeBlobHelpers
let(:project) { create(:project, :repository) }
- let(:blob) { fake_blob(path: 'CHANGELOG') }
+ let(:blob) { fake_blob(path: "CHANGELOG") }
subject { described_class.new(blob) }
- describe '#render_error' do
- context 'when there are no tags' do
+ describe "#render_error" do
+ context "when there are no tags" do
before do
allow(project.repository).to receive(:tag_count).and_return(0)
end
- it 'returns :no_tags' do
+ it "returns :no_tags" do
expect(subject.render_error).to eq(:no_tags)
end
end
- context 'when there are tags' do
- it 'returns nil' do
+ context "when there are tags" do
+ it "returns nil" do
expect(subject.render_error).to be_nil
end
end
diff --git a/spec/models/blob_viewer/composer_json_spec.rb b/spec/models/blob_viewer/composer_json_spec.rb
index 85b0d9668a0..2fad5d3203c 100644
--- a/spec/models/blob_viewer/composer_json_spec.rb
+++ b/spec/models/blob_viewer/composer_json_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::ComposerJson do
include FakeBlobHelpers
@@ -12,14 +12,14 @@ describe BlobViewer::ComposerJson do
}
SPEC
end
- let(:blob) { fake_blob(path: 'composer.json', data: data) }
+ let(:blob) { fake_blob(path: "composer.json", data: data) }
subject { described_class.new(blob) }
- describe '#package_name' do
- it 'returns the package name' do
+ describe "#package_name" do
+ it "returns the package name" do
expect(subject).to receive(:prepare!)
- expect(subject.package_name).to eq('laravel/laravel')
+ expect(subject.package_name).to eq("laravel/laravel")
end
end
end
diff --git a/spec/models/blob_viewer/gemspec_spec.rb b/spec/models/blob_viewer/gemspec_spec.rb
index d8c4490637f..0de3b02eaed 100644
--- a/spec/models/blob_viewer/gemspec_spec.rb
+++ b/spec/models/blob_viewer/gemspec_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::Gemspec do
include FakeBlobHelpers
@@ -12,14 +12,14 @@ describe BlobViewer::Gemspec do
end
SPEC
end
- let(:blob) { fake_blob(path: 'activerecord.gemspec', data: data) }
+ let(:blob) { fake_blob(path: "activerecord.gemspec", data: data) }
subject { described_class.new(blob) }
- describe '#package_name' do
- it 'returns the package name' do
+ describe "#package_name" do
+ it "returns the package name" do
expect(subject).to receive(:prepare!)
- expect(subject.package_name).to eq('activerecord')
+ expect(subject.package_name).to eq("activerecord")
end
end
end
diff --git a/spec/models/blob_viewer/gitlab_ci_yml_spec.rb b/spec/models/blob_viewer/gitlab_ci_yml_spec.rb
index 16bf947b493..6633c761fe7 100644
--- a/spec/models/blob_viewer/gitlab_ci_yml_spec.rb
+++ b/spec/models/blob_viewer/gitlab_ci_yml_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::GitlabCiYml do
include FakeBlobHelpers
@@ -7,29 +7,29 @@ describe BlobViewer::GitlabCiYml do
set(:project) { create(:project, :repository) }
set(:user) { create(:user) }
- let(:data) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) }
- let(:blob) { fake_blob(path: '.gitlab-ci.yml', data: data) }
+ let(:data) { File.read(Rails.root.join("spec/support/gitlab_stubs/gitlab_ci.yml")) }
+ let(:blob) { fake_blob(path: ".gitlab-ci.yml", data: data) }
let(:sha) { sample_commit.id }
subject { described_class.new(blob) }
- describe '#validation_message' do
- it 'calls prepare! on the viewer' do
+ describe "#validation_message" do
+ it "calls prepare! on the viewer" do
expect(subject).to receive(:prepare!)
subject.validation_message(project: project, sha: sha, user: user)
end
- context 'when the configuration is valid' do
- it 'returns nil' do
+ context "when the configuration is valid" do
+ it "returns nil" do
expect(subject.validation_message(project: project, sha: sha, user: user)).to be_nil
end
end
- context 'when the configuration is invalid' do
- let(:data) { 'oof' }
+ context "when the configuration is invalid" do
+ let(:data) { "oof" }
- it 'returns the error message' do
- expect(subject.validation_message(project: project, sha: sha, user: user)).to eq('Invalid configuration format')
+ it "returns the error message" do
+ expect(subject.validation_message(project: project, sha: sha, user: user)).to eq("Invalid configuration format")
end
end
end
diff --git a/spec/models/blob_viewer/license_spec.rb b/spec/models/blob_viewer/license_spec.rb
index 222ed166ee0..5c315190592 100644
--- a/spec/models/blob_viewer/license_spec.rb
+++ b/spec/models/blob_viewer/license_spec.rb
@@ -1,32 +1,32 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::License do
include FakeBlobHelpers
let(:project) { create(:project, :repository) }
- let(:blob) { fake_blob(path: 'LICENSE') }
+ let(:blob) { fake_blob(path: "LICENSE") }
subject { described_class.new(blob) }
- describe '#license' do
- it 'returns the blob project repository license' do
+ describe "#license" do
+ it "returns the blob project repository license" do
expect(subject.license).not_to be_nil
expect(subject.license).to eq(project.repository.license)
end
end
- describe '#render_error' do
- context 'when there is no license' do
+ describe "#render_error" do
+ context "when there is no license" do
before do
allow(project.repository).to receive(:license).and_return(nil)
end
- it 'returns :unknown_license' do
+ it "returns :unknown_license" do
expect(subject.render_error).to eq(:unknown_license)
end
end
- context 'when there is a license' do
- it 'returns nil' do
+ context "when there is a license" do
+ it "returns nil" do
expect(subject.render_error).to be_nil
end
end
diff --git a/spec/models/blob_viewer/package_json_spec.rb b/spec/models/blob_viewer/package_json_spec.rb
index fbaa8d47a71..d2b41f59c2f 100644
--- a/spec/models/blob_viewer/package_json_spec.rb
+++ b/spec/models/blob_viewer/package_json_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::PackageJson do
include FakeBlobHelpers
@@ -12,35 +12,35 @@ describe BlobViewer::PackageJson do
}
SPEC
end
- let(:blob) { fake_blob(path: 'package.json', data: data) }
+ let(:blob) { fake_blob(path: "package.json", data: data) }
subject { described_class.new(blob) }
- describe '#package_name' do
- it 'returns the package name' do
+ describe "#package_name" do
+ it "returns the package name" do
expect(subject).to receive(:prepare!)
- expect(subject.package_name).to eq('module-name')
+ expect(subject.package_name).to eq("module-name")
end
end
- describe '#package_url' do
- it 'returns the package URL' do
+ describe "#package_url" do
+ it "returns the package URL" do
expect(subject).to receive(:prepare!)
expect(subject.package_url).to eq("https://www.npmjs.com/package/#{subject.package_name}")
end
end
- describe '#package_type' do
+ describe "#package_type" do
it 'returns "package"' do
expect(subject).to receive(:prepare!)
- expect(subject.package_type).to eq('package')
+ expect(subject.package_type).to eq("package")
end
end
context 'when package.json has "private": true' do
- let(:homepage) { 'http://example.com' }
+ let(:homepage) { "http://example.com" }
let(:data) do
<<-SPEC.strip_heredoc
{
@@ -51,22 +51,22 @@ describe BlobViewer::PackageJson do
}
SPEC
end
- let(:blob) { fake_blob(path: 'package.json', data: data) }
+ let(:blob) { fake_blob(path: "package.json", data: data) }
subject { described_class.new(blob) }
- describe '#package_url' do
- context 'when the homepage has a valid URL' do
- it 'returns homepage URL' do
+ describe "#package_url" do
+ context "when the homepage has a valid URL" do
+ it "returns homepage URL" do
expect(subject).to receive(:prepare!)
expect(subject.package_url).to eq(homepage)
end
end
- context 'when the homepage has an invalid URL' do
- let(:homepage) { 'javascript:alert()' }
+ context "when the homepage has an invalid URL" do
+ let(:homepage) { "javascript:alert()" }
- it 'returns nil' do
+ it "returns nil" do
expect(subject).to receive(:prepare!)
expect(subject.package_url).to be_nil
@@ -74,11 +74,11 @@ describe BlobViewer::PackageJson do
end
end
- describe '#package_type' do
+ describe "#package_type" do
it 'returns "private package"' do
expect(subject).to receive(:prepare!)
- expect(subject.package_type).to eq('private package')
+ expect(subject.package_type).to eq("private package")
end
end
end
diff --git a/spec/models/blob_viewer/podspec_json_spec.rb b/spec/models/blob_viewer/podspec_json_spec.rb
index 9a23877b23f..83d473970a1 100644
--- a/spec/models/blob_viewer/podspec_json_spec.rb
+++ b/spec/models/blob_viewer/podspec_json_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::PodspecJson do
include FakeBlobHelpers
@@ -12,14 +12,14 @@ describe BlobViewer::PodspecJson do
}
SPEC
end
- let(:blob) { fake_blob(path: 'AFNetworking.podspec.json', data: data) }
+ let(:blob) { fake_blob(path: "AFNetworking.podspec.json", data: data) }
subject { described_class.new(blob) }
- describe '#package_name' do
- it 'returns the package name' do
+ describe "#package_name" do
+ it "returns the package name" do
expect(subject).to receive(:prepare!)
- expect(subject.package_name).to eq('AFNetworking')
+ expect(subject.package_name).to eq("AFNetworking")
end
end
end
diff --git a/spec/models/blob_viewer/podspec_spec.rb b/spec/models/blob_viewer/podspec_spec.rb
index 02d06ea24d6..adea718355d 100644
--- a/spec/models/blob_viewer/podspec_spec.rb
+++ b/spec/models/blob_viewer/podspec_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::Podspec do
include FakeBlobHelpers
@@ -12,14 +12,14 @@ describe BlobViewer::Podspec do
end
SPEC
end
- let(:blob) { fake_blob(path: 'Reachability.podspec', data: data) }
+ let(:blob) { fake_blob(path: "Reachability.podspec", data: data) }
subject { described_class.new(blob) }
- describe '#package_name' do
- it 'returns the package name' do
+ describe "#package_name" do
+ it "returns the package name" do
expect(subject).to receive(:prepare!)
- expect(subject.package_name).to eq('Reachability')
+ expect(subject.package_name).to eq("Reachability")
end
end
end
diff --git a/spec/models/blob_viewer/readme_spec.rb b/spec/models/blob_viewer/readme_spec.rb
index 8d11d58cfca..acfb9269897 100644
--- a/spec/models/blob_viewer/readme_spec.rb
+++ b/spec/models/blob_viewer/readme_spec.rb
@@ -1,46 +1,46 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::Readme do
include FakeBlobHelpers
let(:project) { create(:project, :repository, :wiki_repo) }
- let(:blob) { fake_blob(path: 'README.md') }
+ let(:blob) { fake_blob(path: "README.md") }
subject { described_class.new(blob) }
- describe '#render_error' do
- context 'when there is no wiki' do
- it 'returns :no_wiki' do
+ describe "#render_error" do
+ context "when there is no wiki" do
+ it "returns :no_wiki" do
expect(subject.render_error).to eq(:no_wiki)
end
end
- context 'when there is an external wiki' do
+ context "when there is an external wiki" do
before do
project.has_external_wiki = true
end
- it 'returns nil' do
+ it "returns nil" do
expect(subject.render_error).to be_nil
end
end
- context 'when there is a local wiki' do
+ context "when there is a local wiki" do
before do
project.wiki_enabled = true
end
- context 'when the wiki is empty' do
- it 'returns :no_wiki' do
+ context "when the wiki is empty" do
+ it "returns :no_wiki" do
expect(subject.render_error).to eq(:no_wiki)
end
end
- context 'when the wiki is not empty' do
+ context "when the wiki is not empty" do
before do
- create(:wiki_page, wiki: project.wiki, attrs: { title: 'home', content: 'Home page' })
+ create(:wiki_page, wiki: project.wiki, attrs: {title: "home", content: "Home page"})
end
- it 'returns nil' do
+ it "returns nil" do
expect(subject.render_error).to be_nil
end
end
diff --git a/spec/models/blob_viewer/route_map_spec.rb b/spec/models/blob_viewer/route_map_spec.rb
index c13662427b0..ce71954a5cb 100644
--- a/spec/models/blob_viewer/route_map_spec.rb
+++ b/spec/models/blob_viewer/route_map_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::RouteMap do
include FakeBlobHelpers
@@ -11,27 +11,27 @@ describe BlobViewer::RouteMap do
public: 'team/'
MAP
end
- let(:blob) { fake_blob(path: '.gitlab/route-map.yml', data: data) }
+ let(:blob) { fake_blob(path: ".gitlab/route-map.yml", data: data) }
subject { described_class.new(blob) }
- describe '#validation_message' do
- it 'calls prepare! on the viewer' do
+ describe "#validation_message" do
+ it "calls prepare! on the viewer" do
expect(subject).to receive(:prepare!)
subject.validation_message
end
- context 'when the configuration is valid' do
- it 'returns nil' do
+ context "when the configuration is valid" do
+ it "returns nil" do
expect(subject.validation_message).to be_nil
end
end
- context 'when the configuration is invalid' do
- let(:data) { 'oof' }
+ context "when the configuration is invalid" do
+ let(:data) { "oof" }
- it 'returns the error message' do
- expect(subject.validation_message).to eq('Route map is not an array')
+ it "returns the error message" do
+ expect(subject.validation_message).to eq("Route map is not an array")
end
end
end
diff --git a/spec/models/blob_viewer/server_side_spec.rb b/spec/models/blob_viewer/server_side_spec.rb
index 63790486200..ef79bc618e5 100644
--- a/spec/models/blob_viewer/server_side_spec.rb
+++ b/spec/models/blob_viewer/server_side_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe BlobViewer::ServerSide do
include FakeBlobHelpers
@@ -13,27 +13,27 @@ describe BlobViewer::ServerSide do
subject { viewer_class.new(blob) }
- describe '#prepare!' do
- let(:blob) { fake_blob(path: 'file.txt') }
+ describe "#prepare!" do
+ let(:blob) { fake_blob(path: "file.txt") }
- it 'loads all blob data' do
+ it "loads all blob data" do
expect(blob).to receive(:load_all_data!)
subject.prepare!
end
end
- describe '#render_error' do
- context 'when the blob is stored externally' do
+ describe "#render_error" do
+ context "when the blob is stored externally" do
let(:project) { build(:project, lfs_enabled: true) }
- let(:blob) { fake_blob(path: 'file.pdf', lfs: true) }
+ let(:blob) { fake_blob(path: "file.pdf", lfs: true) }
before do
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
end
- it 'return :server_side_but_stored_externally' do
+ it "return :server_side_but_stored_externally" do
expect(subject.render_error).to eq(:server_side_but_stored_externally)
end
end
diff --git a/spec/models/board_group_recent_visit_spec.rb b/spec/models/board_group_recent_visit_spec.rb
index 59ad4e5417e..ad4c8e6078b 100644
--- a/spec/models/board_group_recent_visit_spec.rb
+++ b/spec/models/board_group_recent_visit_spec.rb
@@ -1,33 +1,33 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe BoardGroupRecentVisit do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:board) { create(:board, group: group) }
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:group) }
it { is_expected.to belong_to(:board) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_presence_of(:group) }
it { is_expected.to validate_presence_of(:board) }
end
- describe '#visited' do
- it 'creates a visit if one does not exists' do
+ describe "#visited" do
+ it "creates a visit if one does not exists" do
expect { described_class.visited!(user, board) }.to change(described_class, :count).by(1)
end
- shared_examples 'was visited previously' do
+ shared_examples "was visited previously" do
let!(:visit) { create :board_group_recent_visit, group: board.group, board: board, user: user, updated_at: 7.days.ago }
- it 'updates the timestamp' do
+ it "updates the timestamp" do
Timecop.freeze do
described_class.visited!(user, board)
@@ -37,20 +37,20 @@ describe BoardGroupRecentVisit do
end
end
- it_behaves_like 'was visited previously'
+ it_behaves_like "was visited previously"
- context 'when we try to create a visit that is not unique' do
+ context "when we try to create a visit that is not unique" do
before do
- expect(described_class).to receive(:find_or_create_by).and_raise(ActiveRecord::RecordNotUnique, 'record not unique')
+ expect(described_class).to receive(:find_or_create_by).and_raise(ActiveRecord::RecordNotUnique, "record not unique")
expect(described_class).to receive(:find_or_create_by).and_return(visit)
end
- it_behaves_like 'was visited previously'
+ it_behaves_like "was visited previously"
end
end
- describe '#latest' do
- it 'returns the most recent visited' do
+ describe "#latest" do
+ it "returns the most recent visited" do
board2 = create(:board, group: group)
board3 = create(:board, group: group)
diff --git a/spec/models/board_project_recent_visit_spec.rb b/spec/models/board_project_recent_visit_spec.rb
index 275581945fa..1d66fbce52e 100644
--- a/spec/models/board_project_recent_visit_spec.rb
+++ b/spec/models/board_project_recent_visit_spec.rb
@@ -1,33 +1,33 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe BoardProjectRecentVisit do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:board) { create(:board, project: project) }
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:board) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:board) }
end
- describe '#visited' do
- it 'creates a visit if one does not exists' do
+ describe "#visited" do
+ it "creates a visit if one does not exists" do
expect { described_class.visited!(user, board) }.to change(described_class, :count).by(1)
end
- shared_examples 'was visited previously' do
+ shared_examples "was visited previously" do
let!(:visit) { create :board_project_recent_visit, project: board.project, board: board, user: user, updated_at: 7.days.ago }
- it 'updates the timestamp' do
+ it "updates the timestamp" do
Timecop.freeze do
described_class.visited!(user, board)
@@ -37,20 +37,20 @@ describe BoardProjectRecentVisit do
end
end
- it_behaves_like 'was visited previously'
+ it_behaves_like "was visited previously"
- context 'when we try to create a visit that is not unique' do
+ context "when we try to create a visit that is not unique" do
before do
- expect(described_class).to receive(:find_or_create_by).and_raise(ActiveRecord::RecordNotUnique, 'record not unique')
+ expect(described_class).to receive(:find_or_create_by).and_raise(ActiveRecord::RecordNotUnique, "record not unique")
expect(described_class).to receive(:find_or_create_by).and_return(visit)
end
- it_behaves_like 'was visited previously'
+ it_behaves_like "was visited previously"
end
end
- describe '#latest' do
- it 'returns the most recent visited' do
+ describe "#latest" do
+ it "returns the most recent visited" do
board2 = create(:board, project: project)
board3 = create(:board, project: project)
diff --git a/spec/models/board_spec.rb b/spec/models/board_spec.rb
index 12d29540137..ad03462702c 100644
--- a/spec/models/board_spec.rb
+++ b/spec/models/board_spec.rb
@@ -1,12 +1,12 @@
-require 'rails_helper'
+require "rails_helper"
describe Board do
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:project) }
it { is_expected.to have_many(:lists).order(list_type: :asc, position: :asc).dependent(:delete_all) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:project) }
end
end
diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb
index 89839709131..df576d0339d 100644
--- a/spec/models/broadcast_message_spec.rb
+++ b/spec/models/broadcast_message_spec.rb
@@ -1,52 +1,52 @@
-require 'spec_helper'
+require "spec_helper"
describe BroadcastMessage do
subject { build(:broadcast_message) }
it { is_expected.to be_valid }
- describe 'validations' do
- let(:triplet) { '#000' }
- let(:hex) { '#AABBCC' }
+ describe "validations" do
+ let(:triplet) { "#000" }
+ let(:hex) { "#AABBCC" }
it { is_expected.to allow_value(nil).for(:color) }
it { is_expected.to allow_value(triplet).for(:color) }
it { is_expected.to allow_value(hex).for(:color) }
- it { is_expected.not_to allow_value('000').for(:color) }
+ it { is_expected.not_to allow_value("000").for(:color) }
it { is_expected.to allow_value(nil).for(:font) }
it { is_expected.to allow_value(triplet).for(:font) }
it { is_expected.to allow_value(hex).for(:font) }
- it { is_expected.not_to allow_value('000').for(:font) }
+ it { is_expected.not_to allow_value("000").for(:font) }
end
- describe '.current', :use_clean_rails_memory_store_caching do
- it 'returns message if time match' do
+ describe ".current", :use_clean_rails_memory_store_caching do
+ it "returns message if time match" do
message = create(:broadcast_message)
expect(described_class.current).to include(message)
end
- it 'returns multiple messages if time match' do
+ it "returns multiple messages if time match" do
message1 = create(:broadcast_message)
message2 = create(:broadcast_message)
expect(described_class.current).to contain_exactly(message1, message2)
end
- it 'returns empty list if time not come' do
+ it "returns empty list if time not come" do
create(:broadcast_message, :future)
expect(described_class.current).to be_empty
end
- it 'returns empty list if time has passed' do
+ it "returns empty list if time has passed" do
create(:broadcast_message, :expired)
expect(described_class.current).to be_empty
end
- it 'caches the output of the query' do
+ it "caches the output of the query" do
create(:broadcast_message)
expect(described_class).to receive(:current_and_future_messages).and_call_original.once
@@ -58,13 +58,13 @@ describe BroadcastMessage do
end
end
- it 'does not create new records' do
+ it "does not create new records" do
create(:broadcast_message)
expect { described_class.current }.not_to change { described_class.count }
end
- it 'includes messages that need to be displayed in the future' do
+ it "includes messages that need to be displayed in the future" do
create(:broadcast_message)
future = create(
@@ -80,14 +80,14 @@ describe BroadcastMessage do
end
end
- it 'does not clear the cache if only a future message should be displayed' do
+ it "does not clear the cache if only a future message should be displayed" do
create(:broadcast_message, :future)
expect(Rails.cache).not_to receive(:delete).with(described_class::CACHE_KEY)
expect(described_class.current.length).to eq(0)
end
- it 'clears the legacy cache key' do
+ it "clears the legacy cache key" do
create(:broadcast_message, :future)
expect(Rails.cache).to receive(:delete).with(described_class::LEGACY_CACHE_KEY)
@@ -95,28 +95,28 @@ describe BroadcastMessage do
end
end
- describe '#active?' do
- it 'is truthy when started and not ended' do
+ describe "#active?" do
+ it "is truthy when started and not ended" do
message = build(:broadcast_message)
expect(message).to be_active
end
- it 'is falsey when ended' do
+ it "is falsey when ended" do
message = build(:broadcast_message, :expired)
expect(message).not_to be_active
end
- it 'is falsey when not started' do
+ it "is falsey when not started" do
message = build(:broadcast_message, :future)
expect(message).not_to be_active
end
end
- describe '#started?' do
- it 'is truthy when starts_at has passed' do
+ describe "#started?" do
+ it "is truthy when starts_at has passed" do
message = build(:broadcast_message)
travel_to(3.days.from_now) do
@@ -124,7 +124,7 @@ describe BroadcastMessage do
end
end
- it 'is falsey when starts_at is in the future' do
+ it "is falsey when starts_at is in the future" do
message = build(:broadcast_message)
travel_to(3.days.ago) do
@@ -133,8 +133,8 @@ describe BroadcastMessage do
end
end
- describe '#ended?' do
- it 'is truthy when ends_at has passed' do
+ describe "#ended?" do
+ it "is truthy when ends_at has passed" do
message = build(:broadcast_message)
travel_to(3.days.from_now) do
@@ -142,7 +142,7 @@ describe BroadcastMessage do
end
end
- it 'is falsey when ends_at is in the future' do
+ it "is falsey when ends_at is in the future" do
message = build(:broadcast_message)
travel_to(3.days.ago) do
@@ -151,8 +151,8 @@ describe BroadcastMessage do
end
end
- describe '#flush_redis_cache' do
- it 'flushes the Redis cache' do
+ describe "#flush_redis_cache" do
+ it "flushes the Redis cache" do
message = create(:broadcast_message)
expect(Rails.cache).to receive(:delete).with(described_class::CACHE_KEY)
diff --git a/spec/models/chat_name_spec.rb b/spec/models/chat_name_spec.rb
index 504bc710b25..c65095a825c 100644
--- a/spec/models/chat_name_spec.rb
+++ b/spec/models/chat_name_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ChatName do
set(:chat_name) { create(:chat_name) }
@@ -15,8 +15,8 @@ describe ChatName do
it { is_expected.to validate_uniqueness_of(:user_id).scoped_to(:service_id) }
it { is_expected.to validate_uniqueness_of(:chat_id).scoped_to(:service_id, :team_id) }
- describe '#update_last_used_at', :clean_gitlab_redis_shared_state do
- it 'updates the last_used_at timestamp' do
+ describe "#update_last_used_at", :clean_gitlab_redis_shared_state do
+ it "updates the last_used_at timestamp" do
expect(subject.last_used_at).to be_nil
subject.update_last_used_at
@@ -24,7 +24,7 @@ describe ChatName do
expect(subject.last_used_at).to be_present
end
- it 'does not update last_used_at if it was recently updated' do
+ it "does not update last_used_at if it was recently updated" do
subject.update_last_used_at
time = subject.last_used_at
diff --git a/spec/models/chat_team_spec.rb b/spec/models/chat_team_spec.rb
index 70a9a206faa..c1f952dafcd 100644
--- a/spec/models/chat_team_spec.rb
+++ b/spec/models/chat_team_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ChatTeam do
set(:chat_team) { create(:chat_team) }
diff --git a/spec/models/ci/artifact_blob_spec.rb b/spec/models/ci/artifact_blob_spec.rb
index 0014bbcf9f5..a4edab3c0c1 100644
--- a/spec/models/ci/artifact_blob_spec.rb
+++ b/spec/models/ci/artifact_blob_spec.rb
@@ -1,75 +1,75 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::ArtifactBlob do
set(:project) { create(:project, :public) }
set(:build) { create(:ci_build, :artifacts, project: project) }
- let(:entry) { build.artifacts_metadata_entry('other_artifacts_0.1.2/another-subdirectory/banana_sample.gif') }
+ let(:entry) { build.artifacts_metadata_entry("other_artifacts_0.1.2/another-subdirectory/banana_sample.gif") }
subject { described_class.new(entry) }
- describe '#id' do
- it 'returns a hash of the path' do
+ describe "#id" do
+ it "returns a hash of the path" do
expect(subject.id).to eq(Digest::SHA1.hexdigest(entry.path))
end
end
- describe '#name' do
- it 'returns the entry name' do
+ describe "#name" do
+ it "returns the entry name" do
expect(subject.name).to eq(entry.name)
end
end
- describe '#path' do
- it 'returns the entry path' do
+ describe "#path" do
+ it "returns the entry path" do
expect(subject.path).to eq(entry.path)
end
end
- describe '#size' do
- it 'returns the entry size' do
+ describe "#size" do
+ it "returns the entry size" do
expect(subject.size).to eq(entry.metadata[:size])
end
end
- describe '#mode' do
- it 'returns the entry mode' do
+ describe "#mode" do
+ it "returns the entry mode" do
expect(subject.mode).to eq(entry.metadata[:mode])
end
end
- describe '#external_storage' do
- it 'returns :build_artifact' do
+ describe "#external_storage" do
+ it "returns :build_artifact" do
expect(subject.external_storage).to eq(:build_artifact)
end
end
- describe '#external_url' do
+ describe "#external_url" do
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
allow(Gitlab.config.pages).to receive(:artifacts_server).and_return(true)
end
- context '.gif extension' do
- it 'returns nil' do
+ context ".gif extension" do
+ it "returns nil" do
expect(subject.external_url(build.project, build)).to be_nil
end
end
- context 'txt extensions' do
- let(:path) { 'other_artifacts_0.1.2/doc_sample.txt' }
+ context "txt extensions" do
+ let(:path) { "other_artifacts_0.1.2/doc_sample.txt" }
let(:entry) { build.artifacts_metadata_entry(path) }
- it 'returns a URL' do
+ it "returns a URL" do
url = subject.external_url(build.project, build)
expect(url).not_to be_nil
expect(url).to eq("http://#{project.namespace.path}.#{Gitlab.config.pages.host}/-/#{project.path}/-/jobs/#{build.id}/artifacts/#{path}")
end
- context 'when port is configured' do
+ context "when port is configured" do
let(:port) { 1234 }
- it 'returns an URL with port number' do
+ it "returns an URL with port number" do
allow(Gitlab.config.pages).to receive(:url).and_return("#{Gitlab.config.pages.url}:#{port}")
url = subject.external_url(build.project, build)
@@ -81,22 +81,22 @@ describe Ci::ArtifactBlob do
end
end
- describe '#external_link?' do
+ describe "#external_link?" do
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
allow(Gitlab.config.pages).to receive(:artifacts_server).and_return(true)
end
- context 'gif extensions' do
- it 'returns false' do
+ context "gif extensions" do
+ it "returns false" do
expect(subject.external_link?(build)).to be false
end
end
- context 'txt extensions' do
- let(:entry) { build.artifacts_metadata_entry('other_artifacts_0.1.2/doc_sample.txt') }
+ context "txt extensions" do
+ let(:entry) { build.artifacts_metadata_entry("other_artifacts_0.1.2/doc_sample.txt") }
- it 'returns true' do
+ it "returns true" do
expect(subject.external_link?(build)).to be true
end
end
diff --git a/spec/models/ci/bridge_spec.rb b/spec/models/ci/bridge_spec.rb
index 741cdfef1a5..bfccfb462ce 100644
--- a/spec/models/ci/bridge_spec.rb
+++ b/spec/models/ci/bridge_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::Bridge do
set(:project) { create(:project) }
@@ -8,17 +8,17 @@ describe Ci::Bridge do
create(:ci_bridge, pipeline: pipeline)
end
- describe '#tags' do
- it 'only has a bridge tag' do
+ describe "#tags" do
+ it "only has a bridge tag" do
expect(bridge.tags).to eq [:bridge]
end
end
- describe '#detailed_status' do
+ describe "#detailed_status" do
let(:user) { create(:user) }
let(:status) { bridge.detailed_status(user) }
- it 'returns detailed status object' do
+ it "returns detailed status object" do
expect(status).to be_a Gitlab::Ci::Status::Success
end
end
diff --git a/spec/models/ci/build_metadata_spec.rb b/spec/models/ci/build_metadata_spec.rb
index 016a5899eef..c2e6a910864 100644
--- a/spec/models/ci/build_metadata_spec.rb
+++ b/spec/models/ci/build_metadata_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::BuildMetadata do
set(:user) { create(:user) }
@@ -9,18 +9,18 @@ describe Ci::BuildMetadata do
create(:ci_pipeline, project: project,
sha: project.commit.id,
ref: project.default_branch,
- status: 'success')
+ status: "success")
end
let(:build) { create(:ci_build, pipeline: pipeline) }
let(:metadata) { build.metadata }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe '#update_timeout_state' do
+ describe "#update_timeout_state" do
subject { metadata }
- context 'when runner is not assigned to the job' do
+ context "when runner is not assigned to the job" do
it "doesn't change timeout value" do
expect { subject.update_timeout_state }.not_to change { subject.reload.timeout }
end
@@ -30,32 +30,32 @@ describe Ci::BuildMetadata do
end
end
- context 'when runner is assigned to the job' do
+ context "when runner is assigned to the job" do
before do
build.update(runner: runner)
end
- context 'when runner timeout is lower than project timeout' do
+ context "when runner timeout is lower than project timeout" do
let(:runner) { create(:ci_runner, maximum_timeout: 1900) }
- it 'sets runner timeout' do
+ it "sets runner timeout" do
expect { subject.update_timeout_state }.to change { subject.reload.timeout }.to(1900)
end
- it 'sets runner_timeout_source' do
- expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to('runner_timeout_source')
+ it "sets runner_timeout_source" do
+ expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to("runner_timeout_source")
end
end
- context 'when runner timeout is higher than project timeout' do
+ context "when runner timeout is higher than project timeout" do
let(:runner) { create(:ci_runner, maximum_timeout: 2100) }
- it 'sets project timeout' do
+ it "sets project timeout" do
expect { subject.update_timeout_state }.to change { subject.reload.timeout }.to(2000)
end
- it 'sets project_timeout_source' do
- expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to('project_timeout_source')
+ it "sets project_timeout_source" do
+ expect { subject.update_timeout_state }.to change { subject.reload.timeout_source }.to("project_timeout_source")
end
end
end
diff --git a/spec/models/ci/build_runner_session_spec.rb b/spec/models/ci/build_runner_session_spec.rb
index 35622366829..f218ea55bd8 100644
--- a/spec/models/ci/build_runner_session_spec.rb
+++ b/spec/models/ci/build_runner_session_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::BuildRunnerSession, model: true do
let!(:build) { create(:ci_build, :with_runner_session) }
@@ -8,28 +8,28 @@ describe Ci::BuildRunnerSession, model: true do
it { is_expected.to belong_to(:build) }
it { is_expected.to validate_presence_of(:build) }
- it { is_expected.to validate_presence_of(:url).with_message('must be a valid URL') }
+ it { is_expected.to validate_presence_of(:url).with_message("must be a valid URL") }
- describe '#terminal_specification' do
+ describe "#terminal_specification" do
let(:terminal_specification) { subject.terminal_specification }
- it 'returns empty hash if no url' do
- subject.url = ''
+ it "returns empty hash if no url" do
+ subject.url = ""
expect(terminal_specification).to be_empty
end
- context 'when url is present' do
- it 'returns ca_pem nil if empty certificate' do
- subject.certificate = ''
+ context "when url is present" do
+ it "returns ca_pem nil if empty certificate" do
+ subject.certificate = ""
expect(terminal_specification[:ca_pem]).to be_nil
end
- it 'adds Authorization header if authorization is present' do
- subject.authorization = 'whatever'
+ it "adds Authorization header if authorization is present" do
+ subject.authorization = "whatever"
- expect(terminal_specification[:headers]).to include(Authorization: ['whatever'])
+ expect(terminal_specification[:headers]).to include(Authorization: ["whatever"])
end
end
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 81ff727b458..7e2ea60d093 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::Build do
set(:user) { create(:user) }
@@ -9,7 +9,7 @@ describe Ci::Build do
create(:ci_pipeline, project: project,
sha: project.commit.id,
ref: project.default_branch,
- status: 'success')
+ status: "success")
end
let(:build) { create(:ci_build, pipeline: pipeline) }
@@ -27,16 +27,16 @@ describe Ci::Build do
it { is_expected.to be_a(ArtifactMigratable) }
- describe 'associations' do
- it 'has a bidirectional relationship with projects' do
+ describe "associations" do
+ it "has a bidirectional relationship with projects" do
expect(described_class.reflect_on_association(:project).has_inverse?).to eq(:builds)
expect(Project.reflect_on_association(:builds).has_inverse?).to eq(:project)
end
end
- describe 'callbacks' do
- context 'when running after_create callback' do
- it 'triggers asynchronous build hooks worker' do
+ describe "callbacks" do
+ context "when running after_create callback" do
+ it "triggers asynchronous build hooks worker" do
expect(BuildHooksWorker).to receive(:perform_async)
create(:ci_build)
@@ -44,10 +44,10 @@ describe Ci::Build do
end
end
- describe 'status' do
- context 'when transitioning to any state from running' do
- it 'removes runner_session' do
- %w(success drop cancel).each do |event|
+ describe "status" do
+ context "when transitioning to any state from running" do
+ it "removes runner_session" do
+ %w[success drop cancel].each do |event|
build = FactoryBot.create(:ci_build, :running, :with_runner_session, pipeline: pipeline)
build.fire_events!(event)
@@ -58,7 +58,7 @@ describe Ci::Build do
end
end
- describe '.manual_actions' do
+ describe ".manual_actions" do
let!(:manual_but_created) { create(:ci_build, :manual, status: :created, pipeline: pipeline) }
let!(:manual_but_succeeded) { create(:ci_build, :manual, status: :success, pipeline: pipeline) }
let!(:manual_action) { create(:ci_build, :manual, pipeline: pipeline) }
@@ -70,22 +70,22 @@ describe Ci::Build do
it { is_expected.not_to include(manual_but_created) }
end
- describe '.ref_protected' do
+ describe ".ref_protected" do
subject { described_class.ref_protected }
- context 'when protected is true' do
+ context "when protected is true" do
let!(:job) { create(:ci_build, :protected) }
it { is_expected.to include(job) }
end
- context 'when protected is false' do
+ context "when protected is false" do
let!(:job) { create(:ci_build) }
it { is_expected.not_to include(job) }
end
- context 'when protected is nil' do
+ context "when protected is nil" do
let!(:job) { create(:ci_build) }
before do
@@ -96,137 +96,137 @@ describe Ci::Build do
end
end
- describe '.with_artifacts_archive' do
+ describe ".with_artifacts_archive" do
subject { described_class.with_artifacts_archive }
- context 'when job does not have an archive' do
+ context "when job does not have an archive" do
let!(:job) { create(:ci_build) }
- it 'does not return the job' do
+ it "does not return the job" do
is_expected.not_to include(job)
end
end
- context 'when job has a legacy archive' do
+ context "when job has a legacy archive" do
let!(:job) { create(:ci_build, :legacy_artifacts) }
- it 'returns the job' do
+ it "returns the job" do
is_expected.to include(job)
end
end
- context 'when job has a job artifact archive' do
+ context "when job has a job artifact archive" do
let!(:job) { create(:ci_build, :artifacts) }
- it 'returns the job' do
+ it "returns the job" do
is_expected.to include(job)
end
end
- context 'when job has a job artifact trace' do
+ context "when job has a job artifact trace" do
let!(:job) { create(:ci_build, :trace_artifact) }
- it 'does not return the job' do
+ it "does not return the job" do
is_expected.not_to include(job)
end
end
end
- describe '.with_live_trace' do
+ describe ".with_live_trace" do
subject { described_class.with_live_trace }
- context 'when build has live trace' do
+ context "when build has live trace" do
let!(:build) { create(:ci_build, :success, :trace_live) }
- it 'selects the build' do
+ it "selects the build" do
is_expected.to eq([build])
end
end
- context 'when build does not have live trace' do
+ context "when build does not have live trace" do
let!(:build) { create(:ci_build, :success, :trace_artifact) }
- it 'does not select the build' do
+ it "does not select the build" do
is_expected.to be_empty
end
end
end
- describe '.with_test_reports' do
+ describe ".with_test_reports" do
subject { described_class.with_test_reports }
- context 'when build has a test report' do
+ context "when build has a test report" do
let!(:build) { create(:ci_build, :success, :test_reports) }
- it 'selects the build' do
+ it "selects the build" do
is_expected.to eq([build])
end
end
- context 'when build does not have test reports' do
+ context "when build does not have test reports" do
let!(:build) { create(:ci_build, :success, :trace_artifact) }
- it 'does not select the build' do
+ it "does not select the build" do
is_expected.to be_empty
end
end
- context 'when there are multiple builds with test reports' do
+ context "when there are multiple builds with test reports" do
let!(:builds) { create_list(:ci_build, 5, :success, :test_reports) }
- it 'does not execute a query for selecting job artifact one by one' do
- recorded = ActiveRecord::QueryRecorder.new do
+ it "does not execute a query for selecting job artifact one by one" do
+ recorded = ActiveRecord::QueryRecorder.new {
subject.each do |build|
build.job_artifacts.map { |a| a.file.exists? }
end
- end
+ }
expect(recorded.count).to eq(2)
end
end
end
- describe '#actionize' do
- context 'when build is a created' do
+ describe "#actionize" do
+ context "when build is a created" do
before do
build.update_column(:status, :created)
end
- it 'makes build a manual action' do
+ it "makes build a manual action" do
expect(build.actionize).to be true
expect(build.reload).to be_manual
end
end
- context 'when build is not created' do
+ context "when build is not created" do
before do
build.update_column(:status, :pending)
end
- it 'does not change build status' do
+ it "does not change build status" do
expect(build.actionize).to be false
expect(build.reload).to be_pending
end
end
end
- describe '#schedulable?' do
+ describe "#schedulable?" do
subject { build.schedulable? }
- context 'when build is schedulable' do
+ context "when build is schedulable" do
let(:build) { create(:ci_build, :created, :schedulable, project: project) }
it { expect(subject).to be_truthy }
end
- context 'when build is not schedulable' do
+ context "when build is not schedulable" do
let(:build) { create(:ci_build, :created, project: project) }
it { expect(subject).to be_falsy }
end
end
- describe '#schedule' do
+ describe "#schedule" do
subject { build.schedule }
before do
@@ -235,7 +235,7 @@ describe Ci::Build do
let(:build) { create(:ci_build, :created, :schedulable, user: user, project: project) }
- it 'transits to scheduled' do
+ it "transits to scheduled" do
allow(Ci::BuildScheduleWorker).to receive(:perform_at)
subject
@@ -243,7 +243,7 @@ describe Ci::Build do
expect(build).to be_scheduled
end
- it 'updates scheduled_at column' do
+ it "updates scheduled_at column" do
allow(Ci::BuildScheduleWorker).to receive(:perform_at)
subject
@@ -251,7 +251,7 @@ describe Ci::Build do
expect(build.scheduled_at).not_to be_nil
end
- it 'schedules BuildScheduleWorker at the right time' do
+ it "schedules BuildScheduleWorker at the right time" do
Timecop.freeze do
expect(Ci::BuildScheduleWorker)
.to receive(:perform_at).with(be_like_time(1.minute.since), build.id)
@@ -261,29 +261,29 @@ describe Ci::Build do
end
end
- describe '#unschedule' do
+ describe "#unschedule" do
subject { build.unschedule }
- context 'when build is scheduled' do
+ context "when build is scheduled" do
let(:build) { create(:ci_build, :scheduled, pipeline: pipeline) }
- it 'cleans scheduled_at column' do
+ it "cleans scheduled_at column" do
subject
expect(build.scheduled_at).to be_nil
end
- it 'transits to manual' do
+ it "transits to manual" do
subject
expect(build).to be_manual
end
end
- context 'when build is not scheduled' do
+ context "when build is not scheduled" do
let(:build) { create(:ci_build, :created, pipeline: pipeline) }
- it 'does not transit status' do
+ it "does not transit status" do
subject
expect(build).to be_created
@@ -291,25 +291,25 @@ describe Ci::Build do
end
end
- describe '#options_scheduled_at' do
+ describe "#options_scheduled_at" do
subject { build.options_scheduled_at }
let(:build) { build_stubbed(:ci_build, options: option) }
- context 'when start_in is 1 day' do
- let(:option) { { start_in: '1 day' } }
+ context "when start_in is 1 day" do
+ let(:option) { {start_in: "1 day"} }
- it 'returns date after 1 day' do
+ it "returns date after 1 day" do
Timecop.freeze do
is_expected.to eq(1.day.since)
end
end
end
- context 'when start_in is 1 week' do
- let(:option) { { start_in: '1 week' } }
+ context "when start_in is 1 week" do
+ let(:option) { {start_in: "1 week"} }
- it 'returns date after 1 week' do
+ it "returns date after 1 week" do
Timecop.freeze do
is_expected.to eq(1.week.since)
end
@@ -317,29 +317,29 @@ describe Ci::Build do
end
end
- describe '#enqueue_scheduled' do
+ describe "#enqueue_scheduled" do
subject { build.enqueue_scheduled }
- context 'when build is scheduled and the right time has not come yet' do
+ context "when build is scheduled and the right time has not come yet" do
let(:build) { create(:ci_build, :scheduled, pipeline: pipeline) }
- it 'does not transits the status' do
+ it "does not transits the status" do
subject
expect(build).to be_scheduled
end
end
- context 'when build is scheduled and the right time has already come' do
+ context "when build is scheduled and the right time has already come" do
let(:build) { create(:ci_build, :expired_scheduled, pipeline: pipeline) }
- it 'cleans scheduled_at column' do
+ it "cleans scheduled_at column" do
subject
expect(build.scheduled_at).to be_nil
end
- it 'transits to pending' do
+ it "transits to pending" do
subject
expect(build).to be_pending
@@ -347,14 +347,14 @@ describe Ci::Build do
end
end
- describe '#any_runners_online?' do
+ describe "#any_runners_online?" do
subject { build.any_runners_online? }
- context 'when no runners' do
+ context "when no runners" do
it { is_expected.to be_falsey }
end
- context 'when there are runners' do
+ context "when there are runners" do
let(:runner) { create(:ci_runner, :project, projects: [build.project]) }
before do
@@ -363,39 +363,39 @@ describe Ci::Build do
it { is_expected.to be_truthy }
- it 'that is inactive' do
+ it "that is inactive" do
runner.update(active: false)
is_expected.to be_falsey
end
- it 'that is not online' do
+ it "that is not online" do
runner.update(contacted_at: nil)
is_expected.to be_falsey
end
- it 'that cannot handle build' do
+ it "that cannot handle build" do
expect_any_instance_of(Ci::Runner).to receive(:can_pick?).and_return(false)
is_expected.to be_falsey
end
end
end
- describe '#artifacts?' do
+ describe "#artifacts?" do
subject { build.artifacts? }
- context 'when new artifacts are used' do
- context 'artifacts archive does not exist' do
+ context "when new artifacts are used" do
+ context "artifacts archive does not exist" do
let(:build) { create(:ci_build) }
it { is_expected.to be_falsy }
end
- context 'artifacts archive exists' do
+ context "artifacts archive exists" do
let(:build) { create(:ci_build, :artifacts) }
it { is_expected.to be_truthy }
- context 'is expired' do
+ context "is expired" do
let(:build) { create(:ci_build, :artifacts, :expired) }
it { is_expected.to be_falsy }
@@ -403,24 +403,24 @@ describe Ci::Build do
end
end
- context 'when legacy artifacts are used' do
+ context "when legacy artifacts are used" do
let(:build) { create(:ci_build, :legacy_artifacts) }
subject { build.artifacts? }
- context 'is expired' do
+ context "is expired" do
let(:build) { create(:ci_build, :legacy_artifacts, :expired) }
it { is_expected.to be_falsy }
end
- context 'artifacts archive does not exist' do
+ context "artifacts archive does not exist" do
let(:build) { create(:ci_build) }
it { is_expected.to be_falsy }
end
- context 'artifacts archive exists' do
+ context "artifacts archive exists" do
let(:build) { create(:ci_build, :legacy_artifacts) }
it { is_expected.to be_truthy }
@@ -428,10 +428,10 @@ describe Ci::Build do
end
end
- describe '#browsable_artifacts?' do
+ describe "#browsable_artifacts?" do
subject { build.browsable_artifacts? }
- context 'artifacts metadata does not exist' do
+ context "artifacts metadata does not exist" do
before do
build.update(legacy_artifacts_metadata: nil)
end
@@ -439,17 +439,17 @@ describe Ci::Build do
it { is_expected.to be_falsy }
end
- context 'artifacts metadata does exists' do
+ context "artifacts metadata does exists" do
let(:build) { create(:ci_build, :artifacts) }
it { is_expected.to be_truthy }
end
end
- describe '#artifacts_expired?' do
+ describe "#artifacts_expired?" do
subject { build.artifacts_expired? }
- context 'is expired' do
+ context "is expired" do
before do
build.update(artifacts_expire_at: Time.now - 7.days)
end
@@ -457,7 +457,7 @@ describe Ci::Build do
it { is_expected.to be_truthy }
end
- context 'is not expired' do
+ context "is not expired" do
before do
build.update(artifacts_expire_at: Time.now + 7.days)
end
@@ -466,23 +466,23 @@ describe Ci::Build do
end
end
- describe '#artifacts_metadata?' do
+ describe "#artifacts_metadata?" do
subject { build.artifacts_metadata? }
- context 'artifacts metadata does not exist' do
+ context "artifacts metadata does not exist" do
it { is_expected.to be_falsy }
end
- context 'artifacts archive is a zip file and metadata exists' do
+ context "artifacts archive is a zip file and metadata exists" do
let(:build) { create(:ci_build, :artifacts) }
it { is_expected.to be_truthy }
end
end
- describe '#artifacts_expire_in' do
+ describe "#artifacts_expire_in" do
subject { build.artifacts_expire_in }
it { is_expected.to be_nil }
- context 'when artifacts_expire_at is specified' do
+ context "when artifacts_expire_at is specified" do
let(:expire_at) { Time.now + 7.days }
before do
@@ -493,50 +493,50 @@ describe Ci::Build do
end
end
- describe '#artifacts_expire_in=' do
+ describe "#artifacts_expire_in=" do
subject { build.artifacts_expire_in }
- it 'when assigning valid duration' do
- build.artifacts_expire_in = '7 days'
+ it "when assigning valid duration" do
+ build.artifacts_expire_in = "7 days"
is_expected.to be_within(10).of(7.days.to_i)
end
- it 'when assigning invalid duration' do
- expect { build.artifacts_expire_in = '7 elephants' }.to raise_error(ChronicDuration::DurationParseError)
+ it "when assigning invalid duration" do
+ expect { build.artifacts_expire_in = "7 elephants" }.to raise_error(ChronicDuration::DurationParseError)
is_expected.to be_nil
end
- it 'when resetting value' do
+ it "when resetting value" do
build.artifacts_expire_in = nil
is_expected.to be_nil
end
- it 'when setting to 0' do
- build.artifacts_expire_in = '0'
+ it "when setting to 0" do
+ build.artifacts_expire_in = "0"
is_expected.to be_nil
end
end
- describe '#commit' do
- it 'returns commit pipeline has been created for' do
+ describe "#commit" do
+ it "returns commit pipeline has been created for" do
expect(build.commit).to eq project.commit
end
end
- describe '#cache' do
- let(:options) { { cache: { key: "key", paths: ["public"], policy: "pull-push" } } }
+ describe "#cache" do
+ let(:options) { {cache: {key: "key", paths: ["public"], policy: "pull-push"}} }
subject { build.cache }
- context 'when build has cache' do
+ context "when build has cache" do
before do
allow(build).to receive(:options).and_return(options)
end
- context 'when project has jobs_cache_index' do
+ context "when project has jobs_cache_index" do
before do
allow_any_instance_of(Project).to receive(:jobs_cache_index).and_return(1)
end
@@ -544,7 +544,7 @@ describe Ci::Build do
it { is_expected.to be_an(Array).and all(include(key: "key-1")) }
end
- context 'when project does not have jobs_cache_index' do
+ context "when project does not have jobs_cache_index" do
before do
allow_any_instance_of(Project).to receive(:jobs_cache_index).and_return(nil)
end
@@ -553,7 +553,7 @@ describe Ci::Build do
end
end
- context 'when build does not have cache' do
+ context "when build does not have cache" do
before do
allow(build).to receive(:options).and_return({})
end
@@ -562,25 +562,25 @@ describe Ci::Build do
end
end
- describe '#depends_on_builds' do
- let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') }
- let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') }
- let!(:rubocop_test) { create(:ci_build, pipeline: pipeline, name: 'rubocop', stage_idx: 1, stage: 'test') }
- let!(:staging) { create(:ci_build, pipeline: pipeline, name: 'staging', stage_idx: 2, stage: 'deploy') }
+ describe "#depends_on_builds" do
+ let!(:build) { create(:ci_build, pipeline: pipeline, name: "build", stage_idx: 0, stage: "build") }
+ let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: "rspec", stage_idx: 1, stage: "test") }
+ let!(:rubocop_test) { create(:ci_build, pipeline: pipeline, name: "rubocop", stage_idx: 1, stage: "test") }
+ let!(:staging) { create(:ci_build, pipeline: pipeline, name: "staging", stage_idx: 2, stage: "deploy") }
- it 'expects to have no dependents if this is first build' do
+ it "expects to have no dependents if this is first build" do
expect(build.depends_on_builds).to be_empty
end
- it 'expects to have one dependent if this is test' do
+ it "expects to have one dependent if this is test" do
expect(rspec_test.depends_on_builds.map(&:id)).to contain_exactly(build.id)
end
- it 'expects to have all builds from build and test stage if this is last' do
+ it "expects to have all builds from build and test stage if this is last" do
expect(staging.depends_on_builds.map(&:id)).to contain_exactly(build.id, rspec_test.id, rubocop_test.id)
end
- it 'expects to have retried builds instead the original ones' do
+ it "expects to have retried builds instead the original ones" do
project.add_developer(user)
retried_rspec = described_class.retry(rspec_test, user)
@@ -590,16 +590,16 @@ describe Ci::Build do
end
end
- describe '#triggered_by?' do
+ describe "#triggered_by?" do
subject { build.triggered_by?(user) }
- context 'when user is owner' do
+ context "when user is owner" do
let(:build) { create(:ci_build, pipeline: pipeline, user: user) }
it { is_expected.to be_truthy }
end
- context 'when user is not owner' do
+ context "when user is not owner" do
let(:another_user) { create(:user) }
let(:build) { create(:ci_build, pipeline: pipeline, user: another_user) }
@@ -607,28 +607,28 @@ describe Ci::Build do
end
end
- describe '#detailed_status' do
- it 'returns a detailed status' do
+ describe "#detailed_status" do
+ it "returns a detailed status" do
expect(build.detailed_status(user))
.to be_a Gitlab::Ci::Status::Build::Cancelable
end
end
- describe '#coverage_regex' do
+ describe "#coverage_regex" do
subject { build.coverage_regex }
- context 'when project has build_coverage_regex set' do
+ context "when project has build_coverage_regex set" do
let(:project_regex) { '\(\d+\.\d+\) covered' }
before do
project.update_column(:build_coverage_regex, project_regex)
end
- context 'and coverage_regex attribute is not set' do
+ context "and coverage_regex attribute is not set" do
it { is_expected.to eq(project_regex) }
end
- context 'but coverage_regex attribute is also set' do
+ context "but coverage_regex attribute is also set" do
let(:build_regex) { 'Code coverage: \d+\.\d+' }
before do
@@ -639,16 +639,16 @@ describe Ci::Build do
end
end
- context 'when neither project nor build has coverage regex set' do
+ context "when neither project nor build has coverage regex set" do
it { is_expected.to be_nil }
end
end
- describe '#update_coverage' do
+ describe "#update_coverage" do
context "regarding coverage_regex's value," do
before do
build.coverage_regex = '\(\d+.\d+\%\) covered'
- build.trace.set('Coverage 1033 / 1051 LOC (98.29%) covered')
+ build.trace.set("Coverage 1033 / 1051 LOC (98.29%) covered")
end
it "saves the correct extracted coverage value" do
@@ -658,10 +658,10 @@ describe Ci::Build do
end
end
- describe '#parse_trace_sections!' do
- it 'calls ExtractSectionsFromBuildTraceService' do
+ describe "#parse_trace_sections!" do
+ it "calls ExtractSectionsFromBuildTraceService" do
expect(Ci::ExtractSectionsFromBuildTraceService)
- .to receive(:new).with(project, build.user).once.and_call_original
+ .to receive(:new).with(project, build.user).once.and_call_original
expect_any_instance_of(Ci::ExtractSectionsFromBuildTraceService)
.to receive(:execute).with(build).once
@@ -669,13 +669,13 @@ describe Ci::Build do
end
end
- describe '#trace' do
+ describe "#trace" do
subject { build.trace }
it { is_expected.to be_a(Gitlab::Ci::Trace) }
end
- describe '#has_trace?' do
+ describe "#has_trace?" do
subject { build.has_trace? }
it "expect to call exist? method" do
@@ -686,62 +686,62 @@ describe Ci::Build do
end
end
- describe '#has_job_artifacts?' do
+ describe "#has_job_artifacts?" do
subject { build.has_job_artifacts? }
- context 'when build has a job artifact' do
+ context "when build has a job artifact" do
let(:build) { create(:ci_build, :artifacts) }
it { is_expected.to be_truthy }
end
- context 'when build does not have job artifacts' do
+ context "when build does not have job artifacts" do
let(:build) { create(:ci_build, :legacy_artifacts) }
it { is_expected.to be_falsy }
end
end
- describe '#has_old_trace?' do
+ describe "#has_old_trace?" do
subject { build.has_old_trace? }
- context 'when old trace exists' do
+ context "when old trace exists" do
before do
- build.update_column(:trace, 'old trace')
+ build.update_column(:trace, "old trace")
end
it { is_expected.to be_truthy }
end
- context 'when old trace does not exist' do
+ context "when old trace does not exist" do
it { is_expected.to be_falsy }
end
end
- describe '#trace=' do
+ describe "#trace=" do
it "expect to fail trace=" do
expect { build.trace = "new" }.to raise_error(NotImplementedError)
end
end
- describe '#old_trace' do
+ describe "#old_trace" do
subject { build.old_trace }
before do
- build.update_column(:trace, 'old trace')
+ build.update_column(:trace, "old trace")
end
it "expect to receive data from database" do
- is_expected.to eq('old trace')
+ is_expected.to eq("old trace")
end
end
- describe '#erase_old_trace!' do
+ describe "#erase_old_trace!" do
subject { build.erase_old_trace! }
- context 'when old trace exists' do
+ context "when old trace exists" do
before do
- build.update_column(:trace, 'old trace')
+ build.update_column(:trace, "old trace")
end
it "erases old trace" do
@@ -757,8 +757,8 @@ describe Ci::Build do
end
end
- context 'when old trace does not exist' do
- it 'does not execute UPDATE query' do
+ context "when old trace does not exist" do
+ it "does not execute UPDATE query" do
recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.log.select { |l| l.match?(/UPDATE.*ci_builds/) }.count).to eq(0)
@@ -766,138 +766,138 @@ describe Ci::Build do
end
end
- describe '#hide_secrets' do
+ describe "#hide_secrets" do
let(:subject) { build.hide_secrets(data) }
- context 'hide runners token' do
+ context "hide runners token" do
let(:data) { "new #{project.runners_token} data"}
it { is_expected.to match(/^new x+ data$/) }
end
- context 'hide build token' do
+ context "hide build token" do
let(:data) { "new #{build.token} data"}
it { is_expected.to match(/^new x+ data$/) }
end
end
- describe 'state transition as a deployable' do
+ describe "state transition as a deployable" do
let!(:build) { create(:ci_build, :start_review_app) }
let(:deployment) { build.deployment }
let(:environment) { deployment.environment }
- it 'has deployments record with created status' do
+ it "has deployments record with created status" do
expect(deployment).to be_created
- expect(environment.name).to eq('review/master')
+ expect(environment.name).to eq("review/master")
end
- context 'when transits to running' do
+ context "when transits to running" do
before do
build.run!
end
- it 'transits deployment status to running' do
+ it "transits deployment status to running" do
expect(deployment).to be_running
end
end
- context 'when transits to success' do
+ context "when transits to success" do
before do
allow(Deployments::SuccessWorker).to receive(:perform_async)
build.success!
end
- it 'transits deployment status to success' do
+ it "transits deployment status to success" do
expect(deployment).to be_success
end
end
- context 'when transits to failed' do
+ context "when transits to failed" do
before do
build.drop!
end
- it 'transits deployment status to failed' do
+ it "transits deployment status to failed" do
expect(deployment).to be_failed
end
end
- context 'when transits to skipped' do
+ context "when transits to skipped" do
before do
build.skip!
end
- it 'transits deployment status to canceled' do
+ it "transits deployment status to canceled" do
expect(deployment).to be_canceled
end
end
- context 'when transits to canceled' do
+ context "when transits to canceled" do
before do
build.cancel!
end
- it 'transits deployment status to canceled' do
+ it "transits deployment status to canceled" do
expect(deployment).to be_canceled
end
end
end
- describe '#on_stop' do
+ describe "#on_stop" do
subject { build.on_stop }
- context 'when a job has a specification that it can be stopped from the other job' do
+ context "when a job has a specification that it can be stopped from the other job" do
let(:build) { create(:ci_build, :start_review_app) }
- it 'returns the other job name' do
- is_expected.to eq('stop_review_app')
+ it "returns the other job name" do
+ is_expected.to eq("stop_review_app")
end
end
- context 'when a job does not have environment information' do
+ context "when a job does not have environment information" do
let(:build) { create(:ci_build) }
- it 'returns nil' do
+ it "returns nil" do
is_expected.to be_nil
end
end
end
- describe 'deployment' do
- describe '#has_deployment?' do
+ describe "deployment" do
+ describe "#has_deployment?" do
subject { build.has_deployment? }
- context 'when build has a deployment' do
+ context "when build has a deployment" do
let!(:deployment) { create(:deployment, deployable: build) }
it { is_expected.to be_truthy }
end
- context 'when build does not have a deployment' do
+ context "when build does not have a deployment" do
it { is_expected.to be_falsy }
end
end
- describe '#outdated_deployment?' do
+ describe "#outdated_deployment?" do
subject { build.outdated_deployment? }
- context 'when build succeeded' do
+ context "when build succeeded" do
let(:build) { create(:ci_build, :success) }
let!(:deployment) { create(:deployment, :success, deployable: build) }
- context 'current deployment is latest' do
+ context "current deployment is latest" do
it { is_expected.to be_falsey }
end
- context 'current deployment is not latest on environment' do
+ context "current deployment is not latest on environment" do
let!(:deployment2) { create(:deployment, :success, environment: deployment.environment) }
it { is_expected.to be_truthy }
end
end
- context 'when build failed' do
+ context "when build failed" do
let(:build) { create(:ci_build, :failed) }
it { is_expected.to be_falsey }
@@ -905,19 +905,19 @@ describe Ci::Build do
end
end
- describe 'environment' do
- describe '#has_environment?' do
+ describe "environment" do
+ describe "#has_environment?" do
subject { build.has_environment? }
- context 'when environment is defined' do
+ context "when environment is defined" do
before do
- build.update(environment: 'review')
+ build.update(environment: "review")
end
it { is_expected.to be_truthy }
end
- context 'when environment is not defined' do
+ context "when environment is not defined" do
before do
build.update(environment: nil)
end
@@ -926,60 +926,60 @@ describe Ci::Build do
end
end
- describe '#expanded_environment_name' do
+ describe "#expanded_environment_name" do
subject { build.expanded_environment_name }
- context 'when environment uses $CI_COMMIT_REF_NAME' do
+ context "when environment uses $CI_COMMIT_REF_NAME" do
let(:build) do
create(:ci_build,
- ref: 'master',
- environment: 'review/$CI_COMMIT_REF_NAME')
+ ref: "master",
+ environment: "review/$CI_COMMIT_REF_NAME")
end
- it { is_expected.to eq('review/master') }
+ it { is_expected.to eq("review/master") }
end
- context 'when environment uses yaml_variables containing symbol keys' do
+ context "when environment uses yaml_variables containing symbol keys" do
let(:build) do
create(:ci_build,
- yaml_variables: [{ key: :APP_HOST, value: 'host' }],
- environment: 'review/$APP_HOST')
+ yaml_variables: [{key: :APP_HOST, value: "host"}],
+ environment: "review/$APP_HOST")
end
- it { is_expected.to eq('review/host') }
+ it { is_expected.to eq("review/host") }
end
- context 'when using persisted variables' do
+ context "when using persisted variables" do
let(:build) do
- create(:ci_build, environment: 'review/x$CI_BUILD_ID')
+ create(:ci_build, environment: "review/x$CI_BUILD_ID")
end
- it { is_expected.to eq('review/x') }
+ it { is_expected.to eq("review/x") }
end
end
- describe '#starts_environment?' do
+ describe "#starts_environment?" do
subject { build.starts_environment? }
- context 'when environment is defined' do
+ context "when environment is defined" do
before do
- build.update(environment: 'review')
+ build.update(environment: "review")
end
- context 'no action is defined' do
+ context "no action is defined" do
it { is_expected.to be_truthy }
end
- context 'and start action is defined' do
+ context "and start action is defined" do
before do
- build.update(options: { environment: { action: 'start' } } )
+ build.update(options: {environment: {action: "start"}})
end
it { is_expected.to be_truthy }
end
end
- context 'when environment is not defined' do
+ context "when environment is not defined" do
before do
build.update(environment: nil)
end
@@ -988,28 +988,28 @@ describe Ci::Build do
end
end
- describe '#stops_environment?' do
+ describe "#stops_environment?" do
subject { build.stops_environment? }
- context 'when environment is defined' do
+ context "when environment is defined" do
before do
- build.update(environment: 'review')
+ build.update(environment: "review")
end
- context 'no action is defined' do
+ context "no action is defined" do
it { is_expected.to be_falsey }
end
- context 'and stop action is defined' do
+ context "and stop action is defined" do
before do
- build.update(options: { environment: { action: 'stop' } } )
+ build.update(options: {environment: {action: "stop"}})
end
it { is_expected.to be_truthy }
end
end
- context 'when environment is not defined' do
+ context "when environment is not defined" do
before do
build.update(environment: nil)
end
@@ -1019,93 +1019,93 @@ describe Ci::Build do
end
end
- describe 'erasable build' do
- shared_examples 'erasable' do
- it 'removes artifact file' do
+ describe "erasable build" do
+ shared_examples "erasable" do
+ it "removes artifact file" do
expect(build.artifacts_file.exists?).to be_falsy
end
- it 'removes artifact metadata file' do
+ it "removes artifact metadata file" do
expect(build.artifacts_metadata.exists?).to be_falsy
end
- it 'removes all job_artifacts' do
+ it "removes all job_artifacts" do
expect(build.job_artifacts.count).to eq(0)
end
- it 'erases build trace in trace file' do
+ it "erases build trace in trace file" do
expect(build).not_to have_trace
end
- it 'sets erased to true' do
+ it "sets erased to true" do
expect(build.erased?).to be true
end
- it 'sets erase date' do
+ it "sets erase date" do
expect(build.erased_at).not_to be_falsy
end
end
- context 'build is not erasable' do
+ context "build is not erasable" do
let!(:build) { create(:ci_build) }
- describe '#erase' do
+ describe "#erase" do
subject { build.erase }
it { is_expected.to be false }
end
- describe '#erasable?' do
+ describe "#erasable?" do
subject { build.erasable? }
it { is_expected.to eq false }
end
end
- context 'build is erasable' do
- context 'new artifacts' do
+ context "build is erasable" do
+ context "new artifacts" do
let!(:build) { create(:ci_build, :test_reports, :trace_artifact, :success, :artifacts) }
- describe '#erase' do
+ describe "#erase" do
before do
build.erase(erased_by: erased_by)
end
- context 'erased by user' do
- let!(:erased_by) { create(:user, username: 'eraser') }
+ context "erased by user" do
+ let!(:erased_by) { create(:user, username: "eraser") }
- include_examples 'erasable'
+ include_examples "erasable"
- it 'records user who erased a build' do
+ it "records user who erased a build" do
expect(build.erased_by).to eq erased_by
end
end
- context 'erased by system' do
+ context "erased by system" do
let(:erased_by) { nil }
- include_examples 'erasable'
+ include_examples "erasable"
- it 'does not set user who erased a build' do
+ it "does not set user who erased a build" do
expect(build.erased_by).to be_nil
end
end
end
- describe '#erasable?' do
+ describe "#erasable?" do
subject { build.erasable? }
it { is_expected.to be_truthy }
end
- describe '#erased?' do
+ describe "#erased?" do
let!(:build) { create(:ci_build, :trace_artifact, :success, :artifacts) }
subject { build.erased? }
- context 'job has not been erased' do
+ context "job has not been erased" do
it { is_expected.to be_falsey }
end
- context 'job has been erased' do
+ context "job has been erased" do
before do
build.erase
end
@@ -1114,15 +1114,15 @@ describe Ci::Build do
end
end
- context 'metadata and build trace are not available' do
+ context "metadata and build trace are not available" do
let!(:build) { create(:ci_build, :success, :artifacts) }
before do
build.remove_artifacts_metadata!
end
- describe '#erase' do
- it 'does not raise error' do
+ describe "#erase" do
+ it "does not raise error" do
expect { build.erase }.not_to raise_error
end
end
@@ -1130,51 +1130,51 @@ describe Ci::Build do
end
end
- context 'old artifacts' do
- context 'build is erasable' do
- context 'new artifacts' do
+ context "old artifacts" do
+ context "build is erasable" do
+ context "new artifacts" do
let!(:build) { create(:ci_build, :trace_artifact, :success, :legacy_artifacts) }
- describe '#erase' do
+ describe "#erase" do
before do
build.erase(erased_by: erased_by)
end
- context 'erased by user' do
- let!(:erased_by) { create(:user, username: 'eraser') }
+ context "erased by user" do
+ let!(:erased_by) { create(:user, username: "eraser") }
- include_examples 'erasable'
+ include_examples "erasable"
- it 'records user who erased a build' do
+ it "records user who erased a build" do
expect(build.erased_by).to eq erased_by
end
end
- context 'erased by system' do
+ context "erased by system" do
let(:erased_by) { nil }
- include_examples 'erasable'
+ include_examples "erasable"
- it 'does not set user who erased a build' do
+ it "does not set user who erased a build" do
expect(build.erased_by).to be_nil
end
end
end
- describe '#erasable?' do
+ describe "#erasable?" do
subject { build.erasable? }
it { is_expected.to be_truthy }
end
- describe '#erased?' do
+ describe "#erased?" do
let!(:build) { create(:ci_build, :trace_artifact, :success, :legacy_artifacts) }
subject { build.erased? }
- context 'job has not been erased' do
+ context "job has not been erased" do
it { is_expected.to be_falsey }
end
- context 'job has been erased' do
+ context "job has been erased" do
before do
build.erase
end
@@ -1183,15 +1183,15 @@ describe Ci::Build do
end
end
- context 'metadata and build trace are not available' do
+ context "metadata and build trace are not available" do
let!(:build) { create(:ci_build, :success, :legacy_artifacts) }
before do
build.remove_artifacts_metadata!
end
- describe '#erase' do
- it 'does not raise error' do
+ describe "#erase" do
+ it "does not raise error" do
expect { build.erase }.not_to raise_error
end
end
@@ -1201,7 +1201,7 @@ describe Ci::Build do
end
end
- describe '#erase_erasable_artifacts!' do
+ describe "#erase_erasable_artifacts!" do
let!(:build) { create(:ci_build, :success) }
subject { build.erase_erasable_artifacts! }
@@ -1227,64 +1227,64 @@ describe Ci::Build do
end
end
- describe '#first_pending' do
- let!(:first) { create(:ci_build, pipeline: pipeline, status: 'pending', created_at: Date.yesterday) }
- let!(:second) { create(:ci_build, pipeline: pipeline, status: 'pending') }
+ describe "#first_pending" do
+ let!(:first) { create(:ci_build, pipeline: pipeline, status: "pending", created_at: Date.yesterday) }
+ let!(:second) { create(:ci_build, pipeline: pipeline, status: "pending") }
subject { described_class.first_pending }
it { is_expected.to be_a(described_class) }
- it('returns with the first pending build') { is_expected.to eq(first) }
+ it("returns with the first pending build") { is_expected.to eq(first) }
end
- describe '#failed_but_allowed?' do
+ describe "#failed_but_allowed?" do
subject { build.failed_but_allowed? }
- context 'when build is not allowed to fail' do
+ context "when build is not allowed to fail" do
before do
build.allow_failure = false
end
- context 'and build.status is success' do
+ context "and build.status is success" do
before do
- build.status = 'success'
+ build.status = "success"
end
it { is_expected.to be_falsey }
end
- context 'and build.status is failed' do
+ context "and build.status is failed" do
before do
- build.status = 'failed'
+ build.status = "failed"
end
it { is_expected.to be_falsey }
end
end
- context 'when build is allowed to fail' do
+ context "when build is allowed to fail" do
before do
build.allow_failure = true
end
- context 'and build.status is success' do
+ context "and build.status is success" do
before do
- build.status = 'success'
+ build.status = "success"
end
it { is_expected.to be_falsey }
end
- context 'and build status is failed' do
+ context "and build status is failed" do
before do
- build.status = 'failed'
+ build.status = "failed"
end
it { is_expected.to be_truthy }
end
- context 'when build is a manual action' do
+ context "when build is a manual action" do
before do
- build.status = 'manual'
+ build.status = "manual"
end
it { is_expected.to be_falsey }
@@ -1292,16 +1292,16 @@ describe Ci::Build do
end
end
- describe 'flags' do
- describe '#cancelable?' do
+ describe "flags" do
+ describe "#cancelable?" do
subject { build }
- context 'when build is cancelable' do
- context 'when build is pending' do
+ context "when build is cancelable" do
+ context "when build is pending" do
it { is_expected.to be_cancelable }
end
- context 'when build is running' do
+ context "when build is running" do
before do
build.run!
end
@@ -1309,15 +1309,15 @@ describe Ci::Build do
it { is_expected.to be_cancelable }
end
- context 'when build is created' do
+ context "when build is created" do
let(:build) { create(:ci_build, :created) }
it { is_expected.to be_cancelable }
end
end
- context 'when build is not cancelable' do
- context 'when build is successful' do
+ context "when build is not cancelable" do
+ context "when build is successful" do
before do
build.success!
end
@@ -1325,7 +1325,7 @@ describe Ci::Build do
it { is_expected.not_to be_cancelable }
end
- context 'when build is failed' do
+ context "when build is failed" do
before do
build.drop!
end
@@ -1335,11 +1335,11 @@ describe Ci::Build do
end
end
- describe '#retryable?' do
+ describe "#retryable?" do
subject { build }
- context 'when build is retryable' do
- context 'when build is successful' do
+ context "when build is retryable" do
+ context "when build is successful" do
before do
build.success!
end
@@ -1347,7 +1347,7 @@ describe Ci::Build do
it { is_expected.to be_retryable }
end
- context 'when build is failed' do
+ context "when build is failed" do
before do
build.drop!
end
@@ -1355,7 +1355,7 @@ describe Ci::Build do
it { is_expected.to be_retryable }
end
- context 'when build is canceled' do
+ context "when build is canceled" do
before do
build.cancel!
end
@@ -1364,8 +1364,8 @@ describe Ci::Build do
end
end
- context 'when build is not retryable' do
- context 'when build is running' do
+ context "when build is not retryable" do
+ context "when build is running" do
before do
build.run!
end
@@ -1373,7 +1373,7 @@ describe Ci::Build do
it { is_expected.not_to be_retryable }
end
- context 'when build is skipped' do
+ context "when build is skipped" do
before do
build.skip!
end
@@ -1381,7 +1381,7 @@ describe Ci::Build do
it { is_expected.not_to be_retryable }
end
- context 'when build is degenerated' do
+ context "when build is degenerated" do
before do
build.degenerate!
end
@@ -1391,203 +1391,203 @@ describe Ci::Build do
end
end
- describe '#action?' do
+ describe "#action?" do
before do
build.update(when: value)
end
subject { build.action? }
- context 'when is set to manual' do
- let(:value) { 'manual' }
+ context "when is set to manual" do
+ let(:value) { "manual" }
it { is_expected.to be_truthy }
end
- context 'when is set to delayed' do
- let(:value) { 'delayed' }
+ context "when is set to delayed" do
+ let(:value) { "delayed" }
it { is_expected.to be_truthy }
end
- context 'when set to something else' do
- let(:value) { 'something else' }
+ context "when set to something else" do
+ let(:value) { "something else" }
it { is_expected.to be_falsey }
end
end
end
- describe '#has_tags?' do
- context 'when build has tags' do
- subject { create(:ci_build, tag_list: ['tag']) }
+ describe "#has_tags?" do
+ context "when build has tags" do
+ subject { create(:ci_build, tag_list: ["tag"]) }
it { is_expected.to have_tags }
end
- context 'when build does not have tags' do
+ context "when build does not have tags" do
subject { create(:ci_build, tag_list: []) }
it { is_expected.not_to have_tags }
end
end
- describe 'build auto retry feature' do
- describe '#retries_count' do
- subject { create(:ci_build, name: 'test', pipeline: pipeline) }
+ describe "build auto retry feature" do
+ describe "#retries_count" do
+ subject { create(:ci_build, name: "test", pipeline: pipeline) }
- context 'when build has been retried several times' do
+ context "when build has been retried several times" do
before do
- create(:ci_build, :retried, name: 'test', pipeline: pipeline)
- create(:ci_build, :retried, name: 'test', pipeline: pipeline)
+ create(:ci_build, :retried, name: "test", pipeline: pipeline)
+ create(:ci_build, :retried, name: "test", pipeline: pipeline)
end
- it 'reports a correct retry count value' do
+ it "reports a correct retry count value" do
expect(subject.retries_count).to eq 2
end
end
- context 'when build has not been retried' do
- it 'returns zero' do
+ context "when build has not been retried" do
+ it "returns zero" do
expect(subject.retries_count).to eq 0
end
end
end
- describe '#retries_max' do
- context 'with retries max config option' do
- subject { create(:ci_build, options: { retry: { max: 1 } }) }
+ describe "#retries_max" do
+ context "with retries max config option" do
+ subject { create(:ci_build, options: {retry: {max: 1}}) }
- context 'when build_metadata_config is set' do
+ context "when build_metadata_config is set" do
before do
stub_feature_flags(ci_build_metadata_config: true)
end
- it 'returns the number of configured max retries' do
+ it "returns the number of configured max retries" do
expect(subject.retries_max).to eq 1
end
end
- context 'when build_metadata_config is not set' do
+ context "when build_metadata_config is not set" do
before do
stub_feature_flags(ci_build_metadata_config: false)
end
- it 'returns the number of configured max retries' do
+ it "returns the number of configured max retries" do
expect(subject.retries_max).to eq 1
end
end
end
- context 'without retries max config option' do
+ context "without retries max config option" do
subject { create(:ci_build) }
- it 'returns zero' do
+ it "returns zero" do
expect(subject.retries_max).to eq 0
end
end
- context 'when build is degenerated' do
+ context "when build is degenerated" do
subject { create(:ci_build, :degenerated) }
- it 'returns zero' do
+ it "returns zero" do
expect(subject.retries_max).to eq 0
end
end
- context 'with integer only config option' do
- subject { create(:ci_build, options: { retry: 1 }) }
+ context "with integer only config option" do
+ subject { create(:ci_build, options: {retry: 1}) }
- it 'returns the number of configured max retries' do
+ it "returns the number of configured max retries" do
expect(subject.retries_max).to eq 1
end
end
end
- describe '#retry_when' do
- context 'with retries when config option' do
- subject { create(:ci_build, options: { retry: { when: ['some_reason'] } }) }
+ describe "#retry_when" do
+ context "with retries when config option" do
+ subject { create(:ci_build, options: {retry: {when: ["some_reason"]}}) }
- it 'returns the configured when' do
- expect(subject.retry_when).to eq ['some_reason']
+ it "returns the configured when" do
+ expect(subject.retry_when).to eq ["some_reason"]
end
end
- context 'without retries when config option' do
+ context "without retries when config option" do
subject { create(:ci_build) }
- it 'returns always array' do
- expect(subject.retry_when).to eq ['always']
+ it "returns always array" do
+ expect(subject.retry_when).to eq ["always"]
end
end
- context 'with integer only config option' do
- subject { create(:ci_build, options: { retry: 1 }) }
+ context "with integer only config option" do
+ subject { create(:ci_build, options: {retry: 1}) }
- it 'returns always array' do
- expect(subject.retry_when).to eq ['always']
+ it "returns always array" do
+ expect(subject.retry_when).to eq ["always"]
end
end
end
- describe '#retry_failure?' do
+ describe "#retry_failure?" do
subject { create(:ci_build) }
- context 'when retries max is zero' do
+ context "when retries max is zero" do
before do
expect(subject).to receive(:retries_max).at_least(:once).and_return(0)
end
- it 'returns false' do
+ it "returns false" do
expect(subject.retry_failure?).to eq false
end
end
- context 'when retries max equals retries count' do
+ context "when retries max equals retries count" do
before do
expect(subject).to receive(:retries_max).at_least(:once).and_return(1)
expect(subject).to receive(:retries_count).at_least(:once).and_return(1)
end
- it 'returns false' do
+ it "returns false" do
expect(subject.retry_failure?).to eq false
end
end
- context 'when retries max is higher than retries count' do
+ context "when retries max is higher than retries count" do
before do
expect(subject).to receive(:retries_max).at_least(:once).and_return(2)
expect(subject).to receive(:retries_count).at_least(:once).and_return(1)
end
- context 'and retry when is always' do
+ context "and retry when is always" do
before do
- expect(subject).to receive(:retry_when).at_least(:once).and_return(['always'])
+ expect(subject).to receive(:retry_when).at_least(:once).and_return(["always"])
end
- it 'returns true' do
+ it "returns true" do
expect(subject.retry_failure?).to eq true
end
end
- context 'and retry when includes the failure_reason' do
+ context "and retry when includes the failure_reason" do
before do
- expect(subject).to receive(:failure_reason).at_least(:once).and_return('some_reason')
- expect(subject).to receive(:retry_when).at_least(:once).and_return(['some_reason'])
+ expect(subject).to receive(:failure_reason).at_least(:once).and_return("some_reason")
+ expect(subject).to receive(:retry_when).at_least(:once).and_return(["some_reason"])
end
- it 'returns true' do
+ it "returns true" do
expect(subject.retry_failure?).to eq true
end
end
- context 'and retry when does not include failure_reason' do
+ context "and retry when does not include failure_reason" do
before do
- expect(subject).to receive(:failure_reason).at_least(:once).and_return('some_reason')
- expect(subject).to receive(:retry_when).at_least(:once).and_return(['some', 'other failure'])
+ expect(subject).to receive(:failure_reason).at_least(:once).and_return("some_reason")
+ expect(subject).to receive(:retry_when).at_least(:once).and_return(["some", "other failure"])
end
- it 'returns false' do
+ it "returns false" do
expect(subject.retry_failure?).to eq false
end
end
@@ -1595,21 +1595,21 @@ describe Ci::Build do
end
end
- describe '#keep_artifacts!' do
+ describe "#keep_artifacts!" do
let(:build) { create(:ci_build, artifacts_expire_at: Time.now + 7.days) }
subject { build.keep_artifacts! }
- it 'to reset expire_at' do
+ it "to reset expire_at" do
subject
expect(build.artifacts_expire_at).to be_nil
end
- context 'when having artifacts files' do
- let!(:artifact) { create(:ci_job_artifact, job: build, expire_in: '7 days') }
+ context "when having artifacts files" do
+ let!(:artifact) { create(:ci_job_artifact, job: build, expire_in: "7 days") }
- it 'to reset dependent objects' do
+ it "to reset dependent objects" do
subject
expect(artifact.reload.expire_at).to be_nil
@@ -1617,20 +1617,20 @@ describe Ci::Build do
end
end
- describe '#artifacts_file_for_type' do
+ describe "#artifacts_file_for_type" do
let(:build) { create(:ci_build, :artifacts) }
let(:file_type) { :archive }
subject { build.artifacts_file_for_type(file_type) }
- it 'queries artifacts for type' do
+ it "queries artifacts for type" do
expect(build).to receive_message_chain(:job_artifacts, :find_by).with(file_type: Ci::JobArtifact.file_types[file_type])
subject
end
end
- describe '#merge_request' do
+ describe "#merge_request" do
def create_mr(build, pipeline, factory: :merge_request, created_at: Time.now)
create(factory, source_project: pipeline.project,
target_project: pipeline.project,
@@ -1638,7 +1638,7 @@ describe Ci::Build do
created_at: created_at)
end
- context 'when a MR has a reference to the pipeline' do
+ context "when a MR has a reference to the pipeline" do
before do
@merge_request = create_mr(build, pipeline, factory: :merge_request)
@@ -1647,18 +1647,18 @@ describe Ci::Build do
allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request])
end
- it 'returns the single associated MR' do
+ it "returns the single associated MR" do
expect(build.merge_request.id).to eq(@merge_request.id)
end
end
- context 'when there is not a MR referencing the pipeline' do
- it 'returns nil' do
+ context "when there is not a MR referencing the pipeline" do
+ it "returns nil" do
expect(build.merge_request).to be_nil
end
end
- context 'when more than one MR have a reference to the pipeline' do
+ context "when more than one MR have a reference to the pipeline" do
before do
@merge_request = create_mr(build, pipeline, factory: :merge_request)
@merge_request.close!
@@ -1670,12 +1670,12 @@ describe Ci::Build do
allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request, @merge_request2])
end
- it 'returns the first MR' do
+ it "returns the first MR" do
expect(build.merge_request.id).to eq(@merge_request.id)
end
end
- context 'when a Build is created after the MR' do
+ context "when a Build is created after the MR" do
before do
@merge_request = create_mr(build, pipeline, factory: :merge_request_with_diffs)
pipeline2 = create(:ci_pipeline, project: project)
@@ -1686,65 +1686,65 @@ describe Ci::Build do
allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request])
end
- it 'returns the current MR' do
+ it "returns the current MR" do
expect(@build2.merge_request.id).to eq(@merge_request.id)
end
end
end
- describe '#options' do
+ describe "#options" do
let(:options) do
{
image: "ruby:2.1",
services: ["postgres"],
- script: ["ls -a"]
+ script: ["ls -a"],
}
end
- it 'contains options' do
+ it "contains options" do
expect(build.options).to eq(options.stringify_keys)
end
- it 'allows to access with keys' do
- expect(build.options[:image]).to eq('ruby:2.1')
+ it "allows to access with keys" do
+ expect(build.options[:image]).to eq("ruby:2.1")
end
- it 'allows to access with strings' do
- expect(build.options['image']).to eq('ruby:2.1')
+ it "allows to access with strings" do
+ expect(build.options["image"]).to eq("ruby:2.1")
end
- context 'when ci_build_metadata_config is set' do
+ context "when ci_build_metadata_config is set" do
before do
stub_feature_flags(ci_build_metadata_config: true)
end
- it 'persist data in build metadata' do
+ it "persist data in build metadata" do
expect(build.metadata.read_attribute(:config_options)).to eq(options.stringify_keys)
end
- it 'does not persist data in build' do
+ it "does not persist data in build" do
expect(build.read_attribute(:options)).to be_nil
end
end
- context 'when ci_build_metadata_config is disabled' do
+ context "when ci_build_metadata_config is disabled" do
before do
stub_feature_flags(ci_build_metadata_config: false)
end
- it 'persist data in build' do
+ it "persist data in build" do
expect(build.read_attribute(:options)).to eq(options.symbolize_keys)
end
- it 'does not persist data in build metadata' do
+ it "does not persist data in build metadata" do
expect(build.metadata.read_attribute(:config_options)).to be_nil
end
end
end
- describe '#other_manual_actions' do
+ describe "#other_manual_actions" do
let(:build) { create(:ci_build, :manual, pipeline: pipeline) }
- let!(:other_build) { create(:ci_build, :manual, pipeline: pipeline, name: 'other action') }
+ let!(:other_build) { create(:ci_build, :manual, pipeline: pipeline, name: "other action") }
subject { build.other_manual_actions }
@@ -1752,32 +1752,32 @@ describe Ci::Build do
project.add_developer(user)
end
- it 'returns other actions' do
+ it "returns other actions" do
is_expected.to contain_exactly(other_build)
end
- context 'when build is retried' do
+ context "when build is retried" do
let!(:new_build) { described_class.retry(build, user) }
- it 'does not return any of them' do
+ it "does not return any of them" do
is_expected.not_to include(build, new_build)
end
end
- context 'when other build is retried' do
+ context "when other build is retried" do
let!(:retried_build) { described_class.retry(other_build, user) }
before do
retried_build.success
end
- it 'returns a retried build' do
+ it "returns a retried build" do
is_expected.to contain_exactly(retried_build)
end
end
end
- describe '#other_scheduled_actions' do
+ describe "#other_scheduled_actions" do
let(:build) { create(:ci_build, :scheduled, pipeline: pipeline) }
subject { build.other_scheduled_actions }
@@ -1787,46 +1787,46 @@ describe Ci::Build do
end
context "when other build's status is success" do
- let!(:other_build) { create(:ci_build, :schedulable, :success, pipeline: pipeline, name: 'other action') }
+ let!(:other_build) { create(:ci_build, :schedulable, :success, pipeline: pipeline, name: "other action") }
- it 'returns other actions' do
+ it "returns other actions" do
is_expected.to contain_exactly(other_build)
end
end
context "when other build's status is failed" do
- let!(:other_build) { create(:ci_build, :schedulable, :failed, pipeline: pipeline, name: 'other action') }
+ let!(:other_build) { create(:ci_build, :schedulable, :failed, pipeline: pipeline, name: "other action") }
- it 'returns other actions' do
+ it "returns other actions" do
is_expected.to contain_exactly(other_build)
end
end
context "when other build's status is running" do
- let!(:other_build) { create(:ci_build, :schedulable, :running, pipeline: pipeline, name: 'other action') }
+ let!(:other_build) { create(:ci_build, :schedulable, :running, pipeline: pipeline, name: "other action") }
- it 'does not return other actions' do
+ it "does not return other actions" do
is_expected.to be_empty
end
end
context "when other build's status is scheduled" do
- let!(:other_build) { create(:ci_build, :scheduled, pipeline: pipeline, name: 'other action') }
+ let!(:other_build) { create(:ci_build, :scheduled, pipeline: pipeline, name: "other action") }
- it 'does not return other actions' do
+ it "does not return other actions" do
is_expected.to contain_exactly(other_build)
end
end
end
- describe '#persisted_environment' do
+ describe "#persisted_environment" do
let!(:environment) do
create(:environment, project: project, name: "foo-#{project.default_branch}")
end
subject { build.persisted_environment }
- context 'when referenced literally' do
+ context "when referenced literally" do
let(:build) do
create(:ci_build, pipeline: pipeline, environment: "foo-#{project.default_branch}")
end
@@ -1834,7 +1834,7 @@ describe Ci::Build do
it { is_expected.to eq(environment) }
end
- context 'when referenced with a variable' do
+ context "when referenced with a variable" do
let(:build) do
create(:ci_build, pipeline: pipeline, environment: "foo-$CI_COMMIT_REF_NAME")
end
@@ -1842,24 +1842,24 @@ describe Ci::Build do
it { is_expected.to eq(environment) }
end
- context 'when there is no environment' do
+ context "when there is no environment" do
it { is_expected.to be_nil }
end
- context 'when build has a start environment' do
+ context "when build has a start environment" do
let(:build) { create(:ci_build, :deploy_to_production, pipeline: pipeline) }
- it 'does not expand environment name' do
+ it "does not expand environment name" do
expect(build).not_to receive(:expanded_environment_name)
subject
end
end
- context 'when build has a stop environment' do
+ context "when build has a stop environment" do
let(:build) { create(:ci_build, :stop_review_app, pipeline: pipeline) }
- it 'expands environment name' do
+ it "expands environment name" do
expect(build).to receive(:expanded_environment_name)
subject
@@ -1867,109 +1867,109 @@ describe Ci::Build do
end
end
- describe '#play' do
+ describe "#play" do
let(:build) { create(:ci_build, :manual, pipeline: pipeline) }
before do
project.add_developer(user)
end
- it 'enqueues the build' do
+ it "enqueues the build" do
expect(build.play(user)).to be_pending
end
end
- describe '#playable?' do
- context 'when build is a manual action' do
- context 'when build has been skipped' do
+ describe "#playable?" do
+ context "when build is a manual action" do
+ context "when build has been skipped" do
subject { build_stubbed(:ci_build, :manual, status: :skipped) }
it { is_expected.not_to be_playable }
end
- context 'when build has been canceled' do
+ context "when build has been canceled" do
subject { build_stubbed(:ci_build, :manual, status: :canceled) }
it { is_expected.to be_playable }
end
- context 'when build is successful' do
+ context "when build is successful" do
subject { build_stubbed(:ci_build, :manual, status: :success) }
it { is_expected.to be_playable }
end
- context 'when build has failed' do
+ context "when build has failed" do
subject { build_stubbed(:ci_build, :manual, status: :failed) }
it { is_expected.to be_playable }
end
- context 'when build is a manual untriggered action' do
+ context "when build is a manual untriggered action" do
subject { build_stubbed(:ci_build, :manual, status: :manual) }
it { is_expected.to be_playable }
end
- context 'when build is a manual and degenerated' do
+ context "when build is a manual and degenerated" do
subject { build_stubbed(:ci_build, :manual, :degenerated, status: :manual) }
it { is_expected.not_to be_playable }
end
end
- context 'when build is scheduled' do
+ context "when build is scheduled" do
subject { build_stubbed(:ci_build, :scheduled) }
it { is_expected.to be_playable }
end
- context 'when build is not a manual action' do
+ context "when build is not a manual action" do
subject { build_stubbed(:ci_build, :success) }
it { is_expected.not_to be_playable }
end
end
- describe 'project settings' do
- describe '#allow_git_fetch' do
- it 'return project allow_git_fetch configuration' do
+ describe "project settings" do
+ describe "#allow_git_fetch" do
+ it "return project allow_git_fetch configuration" do
expect(build.allow_git_fetch).to eq(project.build_allow_git_fetch)
end
end
end
- describe '#project' do
+ describe "#project" do
subject { build.project }
it { is_expected.to eq(pipeline.project) }
end
- describe '#project_id' do
+ describe "#project_id" do
subject { build.project_id }
it { is_expected.to eq(pipeline.project_id) }
end
- describe '#project_name' do
+ describe "#project_name" do
subject { build.project_name }
it { is_expected.to eq(project.name) }
end
- describe '#ref_slug' do
+ describe "#ref_slug" do
{
- 'master' => 'master',
- '1-foo' => '1-foo',
- 'fix/1-foo' => 'fix-1-foo',
- 'fix-1-foo' => 'fix-1-foo',
- 'a' * 63 => 'a' * 63,
- 'a' * 64 => 'a' * 63,
- 'FOO' => 'foo',
- '-' + 'a' * 61 + '-' => 'a' * 61,
- '-' + 'a' * 62 + '-' => 'a' * 62,
- '-' + 'a' * 63 + '-' => 'a' * 62,
- 'a' * 62 + ' ' => 'a' * 62
+ "master" => "master",
+ "1-foo" => "1-foo",
+ "fix/1-foo" => "fix-1-foo",
+ "fix-1-foo" => "fix-1-foo",
+ "a" * 63 => "a" * 63,
+ "a" * 64 => "a" * 63,
+ "FOO" => "foo",
+ "-" + "a" * 61 + "-" => "a" * 61,
+ "-" + "a" * 62 + "-" => "a" * 62,
+ "-" + "a" * 63 + "-" => "a" * 62,
+ "a" * 62 + " " => "a" * 62,
}.each do |ref, slug|
it "transforms #{ref} to #{slug}" do
build.ref = ref
@@ -1979,10 +1979,10 @@ describe Ci::Build do
end
end
- describe '#repo_url' do
+ describe "#repo_url" do
subject { build.repo_url }
- context 'when token is set' do
+ context "when token is set" do
before do
build.ensure_token
end
@@ -1991,11 +1991,11 @@ describe Ci::Build do
it { is_expected.to end_with(".git") }
it { is_expected.to start_with(project.web_url[0..6]) }
it { is_expected.to include(build.token) }
- it { is_expected.to include('gitlab-ci-token') }
+ it { is_expected.to include("gitlab-ci-token") }
it { is_expected.to include(project.web_url[7..-1]) }
end
- context 'when token is empty' do
+ context "when token is empty" do
before do
build.update_columns(token: nil, token_encrypted: nil)
end
@@ -2004,12 +2004,12 @@ describe Ci::Build do
end
end
- describe '#stuck?' do
+ describe "#stuck?" do
subject { build.stuck? }
context "when commit_status.status is pending" do
before do
- build.status = 'pending'
+ build.status = "pending"
end
it { is_expected.to be_truthy }
@@ -2032,32 +2032,32 @@ describe Ci::Build do
end
end
- describe '#has_expiring_artifacts?' do
- context 'when artifacts have expiration date set' do
+ describe "#has_expiring_artifacts?" do
+ context "when artifacts have expiration date set" do
before do
build.update(artifacts_expire_at: 1.day.from_now)
end
- it 'has expiring artifacts' do
+ it "has expiring artifacts" do
expect(build).to have_expiring_artifacts
end
end
- context 'when artifacts do not have expiration date set' do
+ context "when artifacts do not have expiration date set" do
before do
build.update(artifacts_expire_at: nil)
end
- it 'does not have expiring artifacts' do
+ it "does not have expiring artifacts" do
expect(build).not_to have_expiring_artifacts
end
end
end
- context 'when updating the build' do
+ context "when updating the build" do
let(:build) { create(:ci_build, artifacts_size: 23) }
- it 'updates project statistics' do
+ it "updates project statistics" do
build.artifacts_size = 42
expect(build).to receive(:update_project_statistics_after_save).and_call_original
@@ -2067,9 +2067,9 @@ describe Ci::Build do
.by(19)
end
- context 'when the artifact size stays the same' do
- it 'does not update project statistics' do
- build.name = 'changed'
+ context "when the artifact size stays the same" do
+ it "does not update project statistics" do
+ build.name = "changed"
expect(build).not_to receive(:update_project_statistics_after_save)
@@ -2078,10 +2078,10 @@ describe Ci::Build do
end
end
- context 'when destroying the build' do
+ context "when destroying the build" do
let!(:build) { create(:ci_build, artifacts_size: 23) }
- it 'updates project statistics' do
+ it "updates project statistics" do
expect(ProjectStatistics)
.to receive(:increment_statistic)
.and_call_original
@@ -2091,8 +2091,8 @@ describe Ci::Build do
.by(-23)
end
- context 'when the build is destroyed due to the project being destroyed' do
- it 'does not update the project statistics' do
+ context "when the build is destroyed due to the project being destroyed" do
+ it "does not update the project statistics" do
expect(ProjectStatistics)
.not_to receive(:increment_statistic)
@@ -2102,83 +2102,83 @@ describe Ci::Build do
end
end
- describe '#variables' do
+ describe "#variables" do
let(:container_registry_enabled) { false }
before do
- stub_container_registry_config(enabled: container_registry_enabled, host_port: 'registry.example.com')
+ stub_container_registry_config(enabled: container_registry_enabled, host_port: "registry.example.com")
end
subject { build.variables }
- context 'returns variables' do
+ context "returns variables" do
let(:predefined_variables) do
[
- { key: 'CI_PIPELINE_ID', value: pipeline.id.to_s, public: true, masked: false },
- { key: 'CI_PIPELINE_URL', value: project.web_url + "/pipelines/#{pipeline.id}", public: true, masked: false },
- { key: 'CI_JOB_ID', value: build.id.to_s, public: true, masked: false },
- { key: 'CI_JOB_URL', value: project.web_url + "/-/jobs/#{build.id}", public: true, masked: false },
- { key: 'CI_JOB_TOKEN', value: 'my-token', public: false, masked: false },
- { key: 'CI_BUILD_ID', value: build.id.to_s, public: true, masked: false },
- { key: 'CI_BUILD_TOKEN', value: 'my-token', public: false, masked: false },
- { key: 'CI_REGISTRY_USER', value: 'gitlab-ci-token', public: true, masked: false },
- { key: 'CI_REGISTRY_PASSWORD', value: 'my-token', public: false, masked: false },
- { key: 'CI_REPOSITORY_URL', value: build.repo_url, public: false, masked: false },
- { key: 'CI', value: 'true', public: true, masked: false },
- { key: 'GITLAB_CI', value: 'true', public: true, masked: false },
- { key: 'GITLAB_FEATURES', value: project.licensed_features.join(','), public: true, masked: false },
- { key: 'CI_SERVER_NAME', value: 'GitLab', public: true, masked: false },
- { key: 'CI_SERVER_VERSION', value: Gitlab::VERSION, public: true, masked: false },
- { key: 'CI_SERVER_VERSION_MAJOR', value: Gitlab.version_info.major.to_s, public: true, masked: false },
- { key: 'CI_SERVER_VERSION_MINOR', value: Gitlab.version_info.minor.to_s, public: true, masked: false },
- { key: 'CI_SERVER_VERSION_PATCH', value: Gitlab.version_info.patch.to_s, public: true, masked: false },
- { key: 'CI_SERVER_REVISION', value: Gitlab.revision, public: true, masked: false },
- { key: 'CI_JOB_NAME', value: 'test', public: true, masked: false },
- { key: 'CI_JOB_STAGE', value: 'test', public: true, masked: false },
- { key: 'CI_COMMIT_SHA', value: build.sha, public: true, masked: false },
- { key: 'CI_COMMIT_SHORT_SHA', value: build.short_sha, public: true, masked: false },
- { key: 'CI_COMMIT_BEFORE_SHA', value: build.before_sha, public: true, masked: false },
- { key: 'CI_COMMIT_REF_NAME', value: build.ref, public: true, masked: false },
- { key: 'CI_COMMIT_REF_SLUG', value: build.ref_slug, public: true, masked: false },
- { key: 'CI_NODE_TOTAL', value: '1', public: true, masked: false },
- { key: 'CI_BUILD_REF', value: build.sha, public: true, masked: false },
- { key: 'CI_BUILD_BEFORE_SHA', value: build.before_sha, public: true, masked: false },
- { key: 'CI_BUILD_REF_NAME', value: build.ref, public: true, masked: false },
- { key: 'CI_BUILD_REF_SLUG', value: build.ref_slug, public: true, masked: false },
- { key: 'CI_BUILD_NAME', value: 'test', public: true, masked: false },
- { key: 'CI_BUILD_STAGE', value: 'test', public: true, masked: false },
- { key: 'CI_PROJECT_ID', value: project.id.to_s, public: true, masked: false },
- { key: 'CI_PROJECT_NAME', value: project.path, public: true, masked: false },
- { key: 'CI_PROJECT_PATH', value: project.full_path, public: true, masked: false },
- { key: 'CI_PROJECT_PATH_SLUG', value: project.full_path_slug, public: true, masked: false },
- { key: 'CI_PROJECT_NAMESPACE', value: project.namespace.full_path, public: true, masked: false },
- { key: 'CI_PROJECT_URL', value: project.web_url, public: true, masked: false },
- { key: 'CI_PROJECT_VISIBILITY', value: 'private', public: true, masked: false },
- { key: 'CI_PAGES_DOMAIN', value: Gitlab.config.pages.host, public: true, masked: false },
- { key: 'CI_PAGES_URL', value: project.pages_url, public: true, masked: false },
- { key: 'CI_API_V4_URL', value: 'http://localhost/api/v4', public: true, masked: false },
- { key: 'CI_PIPELINE_IID', value: pipeline.iid.to_s, public: true, masked: false },
- { key: 'CI_CONFIG_PATH', value: pipeline.ci_yaml_file_path, public: true, masked: false },
- { key: 'CI_PIPELINE_SOURCE', value: pipeline.source, public: true, masked: false },
- { key: 'CI_COMMIT_MESSAGE', value: pipeline.git_commit_message, public: true, masked: false },
- { key: 'CI_COMMIT_TITLE', value: pipeline.git_commit_title, public: true, masked: false },
- { key: 'CI_COMMIT_DESCRIPTION', value: pipeline.git_commit_description, public: true, masked: false }
+ {key: "CI_PIPELINE_ID", value: pipeline.id.to_s, public: true, masked: false},
+ {key: "CI_PIPELINE_URL", value: project.web_url + "/pipelines/#{pipeline.id}", public: true, masked: false},
+ {key: "CI_JOB_ID", value: build.id.to_s, public: true, masked: false},
+ {key: "CI_JOB_URL", value: project.web_url + "/-/jobs/#{build.id}", public: true, masked: false},
+ {key: "CI_JOB_TOKEN", value: "my-token", public: false, masked: false},
+ {key: "CI_BUILD_ID", value: build.id.to_s, public: true, masked: false},
+ {key: "CI_BUILD_TOKEN", value: "my-token", public: false, masked: false},
+ {key: "CI_REGISTRY_USER", value: "gitlab-ci-token", public: true, masked: false},
+ {key: "CI_REGISTRY_PASSWORD", value: "my-token", public: false, masked: false},
+ {key: "CI_REPOSITORY_URL", value: build.repo_url, public: false, masked: false},
+ {key: "CI", value: "true", public: true, masked: false},
+ {key: "GITLAB_CI", value: "true", public: true, masked: false},
+ {key: "GITLAB_FEATURES", value: project.licensed_features.join(","), public: true, masked: false},
+ {key: "CI_SERVER_NAME", value: "GitLab", public: true, masked: false},
+ {key: "CI_SERVER_VERSION", value: Gitlab::VERSION, public: true, masked: false},
+ {key: "CI_SERVER_VERSION_MAJOR", value: Gitlab.version_info.major.to_s, public: true, masked: false},
+ {key: "CI_SERVER_VERSION_MINOR", value: Gitlab.version_info.minor.to_s, public: true, masked: false},
+ {key: "CI_SERVER_VERSION_PATCH", value: Gitlab.version_info.patch.to_s, public: true, masked: false},
+ {key: "CI_SERVER_REVISION", value: Gitlab.revision, public: true, masked: false},
+ {key: "CI_JOB_NAME", value: "test", public: true, masked: false},
+ {key: "CI_JOB_STAGE", value: "test", public: true, masked: false},
+ {key: "CI_COMMIT_SHA", value: build.sha, public: true, masked: false},
+ {key: "CI_COMMIT_SHORT_SHA", value: build.short_sha, public: true, masked: false},
+ {key: "CI_COMMIT_BEFORE_SHA", value: build.before_sha, public: true, masked: false},
+ {key: "CI_COMMIT_REF_NAME", value: build.ref, public: true, masked: false},
+ {key: "CI_COMMIT_REF_SLUG", value: build.ref_slug, public: true, masked: false},
+ {key: "CI_NODE_TOTAL", value: "1", public: true, masked: false},
+ {key: "CI_BUILD_REF", value: build.sha, public: true, masked: false},
+ {key: "CI_BUILD_BEFORE_SHA", value: build.before_sha, public: true, masked: false},
+ {key: "CI_BUILD_REF_NAME", value: build.ref, public: true, masked: false},
+ {key: "CI_BUILD_REF_SLUG", value: build.ref_slug, public: true, masked: false},
+ {key: "CI_BUILD_NAME", value: "test", public: true, masked: false},
+ {key: "CI_BUILD_STAGE", value: "test", public: true, masked: false},
+ {key: "CI_PROJECT_ID", value: project.id.to_s, public: true, masked: false},
+ {key: "CI_PROJECT_NAME", value: project.path, public: true, masked: false},
+ {key: "CI_PROJECT_PATH", value: project.full_path, public: true, masked: false},
+ {key: "CI_PROJECT_PATH_SLUG", value: project.full_path_slug, public: true, masked: false},
+ {key: "CI_PROJECT_NAMESPACE", value: project.namespace.full_path, public: true, masked: false},
+ {key: "CI_PROJECT_URL", value: project.web_url, public: true, masked: false},
+ {key: "CI_PROJECT_VISIBILITY", value: "private", public: true, masked: false},
+ {key: "CI_PAGES_DOMAIN", value: Gitlab.config.pages.host, public: true, masked: false},
+ {key: "CI_PAGES_URL", value: project.pages_url, public: true, masked: false},
+ {key: "CI_API_V4_URL", value: "http://localhost/api/v4", public: true, masked: false},
+ {key: "CI_PIPELINE_IID", value: pipeline.iid.to_s, public: true, masked: false},
+ {key: "CI_CONFIG_PATH", value: pipeline.ci_yaml_file_path, public: true, masked: false},
+ {key: "CI_PIPELINE_SOURCE", value: pipeline.source, public: true, masked: false},
+ {key: "CI_COMMIT_MESSAGE", value: pipeline.git_commit_message, public: true, masked: false},
+ {key: "CI_COMMIT_TITLE", value: pipeline.git_commit_title, public: true, masked: false},
+ {key: "CI_COMMIT_DESCRIPTION", value: pipeline.git_commit_description, public: true, masked: false},
]
end
before do
- build.set_token('my-token')
+ build.set_token("my-token")
build.yaml_variables = []
end
it { is_expected.to include(*predefined_variables) }
- describe 'variables ordering' do
- context 'when variables hierarchy is stubbed' do
- let(:build_pre_var) { { key: 'build', value: 'value', public: true, masked: false } }
- let(:project_pre_var) { { key: 'project', value: 'value', public: true, masked: false } }
- let(:pipeline_pre_var) { { key: 'pipeline', value: 'value', public: true, masked: false } }
- let(:build_yaml_var) { { key: 'yaml', value: 'value', public: true, masked: false } }
+ describe "variables ordering" do
+ context "when variables hierarchy is stubbed" do
+ let(:build_pre_var) { {key: "build", value: "value", public: true, masked: false} }
+ let(:project_pre_var) { {key: "project", value: "value", public: true, masked: false} }
+ let(:pipeline_pre_var) { {key: "pipeline", value: "value", public: true, masked: false} }
+ let(:build_yaml_var) { {key: "yaml", value: "value", public: true, masked: false} }
before do
allow(build).to receive(:predefined_variables) { [build_pre_var] }
@@ -2188,23 +2188,24 @@ describe Ci::Build do
allow_any_instance_of(Project)
.to receive(:predefined_variables) { [project_pre_var] }
- project.variables.create!(key: 'secret', value: 'value')
+ project.variables.create!(key: "secret", value: "value")
allow_any_instance_of(Ci::Pipeline)
.to receive(:predefined_variables) { [pipeline_pre_var] }
end
- it 'returns variables in order depending on resource hierarchy' do
+ it "returns variables in order depending on resource hierarchy" do
is_expected.to eq(
[build_pre_var,
project_pre_var,
pipeline_pre_var,
build_yaml_var,
- { key: 'secret', value: 'value', public: false, masked: false }])
+ {key: "secret", value: "value", public: false, masked: false},]
+ )
end
end
- context 'when build has environment and user-provided variables' do
+ context "when build has environment and user-provided variables" do
let(:expected_variables) do
predefined_variables.map { |variable| variable.fetch(:key) } +
%w[YAML_VARIABLE CI_ENVIRONMENT_NAME CI_ENVIRONMENT_SLUG
@@ -2213,15 +2214,15 @@ describe Ci::Build do
before do
create(:environment, project: build.project,
- name: 'staging')
+ name: "staging")
- build.yaml_variables = [{ key: 'YAML_VARIABLE',
- value: 'var',
- public: true }]
- build.environment = 'staging'
+ build.yaml_variables = [{key: "YAML_VARIABLE",
+ value: "var",
+ public: true,}]
+ build.environment = "staging"
end
- it 'matches explicit variables ordering' do
+ it "matches explicit variables ordering" do
received_variables = subject.map { |variable| variable.fetch(:key) }
expect(received_variables).to eq expected_variables
@@ -2230,13 +2231,13 @@ describe Ci::Build do
end
end
- context 'when build has user' do
+ context "when build has user" do
let(:user_variables) do
[
- { key: 'GITLAB_USER_ID', value: user.id.to_s, public: true, masked: false },
- { key: 'GITLAB_USER_EMAIL', value: user.email, public: true, masked: false },
- { key: 'GITLAB_USER_LOGIN', value: user.username, public: true, masked: false },
- { key: 'GITLAB_USER_NAME', value: user.name, public: true, masked: false }
+ {key: "GITLAB_USER_ID", value: user.id.to_s, public: true, masked: false},
+ {key: "GITLAB_USER_EMAIL", value: user.email, public: true, masked: false},
+ {key: "GITLAB_USER_LOGIN", value: user.username, public: true, masked: false},
+ {key: "GITLAB_USER_NAME", value: user.name, public: true, masked: false},
]
end
@@ -2247,91 +2248,91 @@ describe Ci::Build do
it { user_variables.each { |v| is_expected.to include(v) } }
end
- context 'when build has an environment' do
+ context "when build has an environment" do
let(:environment_variables) do
[
- { key: 'CI_ENVIRONMENT_NAME', value: 'production', public: true, masked: false },
- { key: 'CI_ENVIRONMENT_SLUG', value: 'prod-slug', public: true, masked: false }
+ {key: "CI_ENVIRONMENT_NAME", value: "production", public: true, masked: false},
+ {key: "CI_ENVIRONMENT_SLUG", value: "prod-slug", public: true, masked: false},
]
end
let!(:environment) do
create(:environment,
- project: build.project,
- name: 'production',
- slug: 'prod-slug',
- external_url: '')
+ project: build.project,
+ name: "production",
+ slug: "prod-slug",
+ external_url: "")
end
before do
- build.update(environment: 'production')
+ build.update(environment: "production")
end
- shared_examples 'containing environment variables' do
+ shared_examples "containing environment variables" do
it { environment_variables.each { |v| is_expected.to include(v) } }
end
- context 'when no URL was set' do
- it_behaves_like 'containing environment variables'
+ context "when no URL was set" do
+ it_behaves_like "containing environment variables"
- it 'does not have CI_ENVIRONMENT_URL' do
+ it "does not have CI_ENVIRONMENT_URL" do
keys = subject.map { |var| var[:key] }
- expect(keys).not_to include('CI_ENVIRONMENT_URL')
+ expect(keys).not_to include("CI_ENVIRONMENT_URL")
end
end
- context 'when an URL was set' do
- let(:url) { 'http://host/test' }
+ context "when an URL was set" do
+ let(:url) { "http://host/test" }
before do
environment_variables <<
- { key: 'CI_ENVIRONMENT_URL', value: url, public: true, masked: false }
+ {key: "CI_ENVIRONMENT_URL", value: url, public: true, masked: false}
end
- context 'when the URL was set from the job' do
+ context "when the URL was set from the job" do
before do
- build.update(options: { environment: { url: url } })
+ build.update(options: {environment: {url: url}})
end
- it_behaves_like 'containing environment variables'
+ it_behaves_like "containing environment variables"
- context 'when variables are used in the URL, it does not expand' do
- let(:url) { 'http://$CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG' }
+ context "when variables are used in the URL, it does not expand" do
+ let(:url) { "http://$CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG" }
- it_behaves_like 'containing environment variables'
+ it_behaves_like "containing environment variables"
- it 'puts $CI_ENVIRONMENT_URL in the last so all other variables are available to be used when runners are trying to expand it' do
+ it "puts $CI_ENVIRONMENT_URL in the last so all other variables are available to be used when runners are trying to expand it" do
expect(subject.last).to eq(environment_variables.last)
end
end
end
- context 'when the URL was not set from the job, but environment' do
+ context "when the URL was not set from the job, but environment" do
before do
environment.update(external_url: url)
end
- it_behaves_like 'containing environment variables'
+ it_behaves_like "containing environment variables"
end
end
end
- context 'when build started manually' do
+ context "when build started manually" do
before do
build.update(when: :manual)
end
let(:manual_variable) do
- { key: 'CI_JOB_MANUAL', value: 'true', public: true, masked: false }
+ {key: "CI_JOB_MANUAL", value: "true", public: true, masked: false}
end
it { is_expected.to include(manual_variable) }
end
- context 'when build is for tag' do
+ context "when build is for tag" do
let(:tag_variable) do
- { key: 'CI_COMMIT_TAG', value: 'master', public: true, masked: false }
+ {key: "CI_COMMIT_TAG", value: "master", public: true, masked: false}
end
before do
@@ -2341,33 +2342,33 @@ describe Ci::Build do
it { is_expected.to include(tag_variable) }
end
- context 'when CI variable is defined' do
+ context "when CI variable is defined" do
let(:ci_variable) do
- { key: 'SECRET_KEY', value: 'secret_value', public: false, masked: false }
+ {key: "SECRET_KEY", value: "secret_value", public: false, masked: false}
end
before do
create(:ci_variable,
- ci_variable.slice(:key, :value).merge(project: project))
+ ci_variable.slice(:key, :value).merge(project: project))
end
it { is_expected.to include(ci_variable) }
end
- context 'when protected variable is defined' do
+ context "when protected variable is defined" do
let(:ref) { Gitlab::Git::BRANCH_REF_PREFIX + build.ref }
let(:protected_variable) do
- { key: 'PROTECTED_KEY', value: 'protected_value', public: false, masked: false }
+ {key: "PROTECTED_KEY", value: "protected_value", public: false, masked: false}
end
before do
create(:ci_variable,
- :protected,
- protected_variable.slice(:key, :value).merge(project: project))
+ :protected,
+ protected_variable.slice(:key, :value).merge(project: project))
end
- context 'when the branch is protected' do
+ context "when the branch is protected" do
before do
allow(build.project).to receive(:protected_for?).with(ref).and_return(true)
end
@@ -2375,7 +2376,7 @@ describe Ci::Build do
it { is_expected.to include(protected_variable) }
end
- context 'when the tag is protected' do
+ context "when the tag is protected" do
before do
allow(build.project).to receive(:protected_for?).with(ref).and_return(true)
end
@@ -2383,38 +2384,38 @@ describe Ci::Build do
it { is_expected.to include(protected_variable) }
end
- context 'when the ref is not protected' do
+ context "when the ref is not protected" do
it { is_expected.not_to include(protected_variable) }
end
end
- context 'when group CI variable is defined' do
+ context "when group CI variable is defined" do
let(:ci_variable) do
- { key: 'SECRET_KEY', value: 'secret_value', public: false, masked: false }
+ {key: "SECRET_KEY", value: "secret_value", public: false, masked: false}
end
before do
create(:ci_group_variable,
- ci_variable.slice(:key, :value).merge(group: group))
+ ci_variable.slice(:key, :value).merge(group: group))
end
it { is_expected.to include(ci_variable) }
end
- context 'when group protected variable is defined' do
+ context "when group protected variable is defined" do
let(:ref) { Gitlab::Git::BRANCH_REF_PREFIX + build.ref }
let(:protected_variable) do
- { key: 'PROTECTED_KEY', value: 'protected_value', public: false, masked: false }
+ {key: "PROTECTED_KEY", value: "protected_value", public: false, masked: false}
end
before do
create(:ci_group_variable,
- :protected,
- protected_variable.slice(:key, :value).merge(group: group))
+ :protected,
+ protected_variable.slice(:key, :value).merge(group: group))
end
- context 'when the branch is protected' do
+ context "when the branch is protected" do
before do
allow(build.project).to receive(:protected_for?).with(ref).and_return(true)
end
@@ -2422,7 +2423,7 @@ describe Ci::Build do
it { is_expected.to include(protected_variable) }
end
- context 'when the tag is protected' do
+ context "when the tag is protected" do
before do
allow(build.project).to receive(:protected_for?).with(ref).and_return(true)
end
@@ -2430,66 +2431,66 @@ describe Ci::Build do
it { is_expected.to include(protected_variable) }
end
- context 'when the ref is not protected' do
+ context "when the ref is not protected" do
before do
- build.update_column(:ref, 'some/feature')
+ build.update_column(:ref, "some/feature")
end
it { is_expected.not_to include(protected_variable) }
end
end
- context 'when build is for triggers' do
+ context "when build is for triggers" do
let(:trigger) { create(:ci_trigger, project: project) }
let(:trigger_request) { create(:ci_trigger_request, pipeline: pipeline, trigger: trigger) }
let(:user_trigger_variable) do
- { key: 'TRIGGER_KEY_1', value: 'TRIGGER_VALUE_1', public: false, masked: false }
+ {key: "TRIGGER_KEY_1", value: "TRIGGER_VALUE_1", public: false, masked: false}
end
let(:predefined_trigger_variable) do
- { key: 'CI_PIPELINE_TRIGGERED', value: 'true', public: true, masked: false }
+ {key: "CI_PIPELINE_TRIGGERED", value: "true", public: true, masked: false}
end
before do
build.trigger_request = trigger_request
end
- shared_examples 'returns variables for triggers' do
+ shared_examples "returns variables for triggers" do
it { is_expected.to include(user_trigger_variable) }
it { is_expected.to include(predefined_trigger_variable) }
end
- context 'when variables are stored in trigger_request' do
+ context "when variables are stored in trigger_request" do
before do
- trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' } )
+ trigger_request.update_attribute(:variables, {"TRIGGER_KEY_1" => "TRIGGER_VALUE_1"})
end
- it_behaves_like 'returns variables for triggers'
+ it_behaves_like "returns variables for triggers"
end
- context 'when variables are stored in pipeline_variables' do
+ context "when variables are stored in pipeline_variables" do
before do
- create(:ci_pipeline_variable, pipeline: pipeline, key: 'TRIGGER_KEY_1', value: 'TRIGGER_VALUE_1')
+ create(:ci_pipeline_variable, pipeline: pipeline, key: "TRIGGER_KEY_1", value: "TRIGGER_VALUE_1")
end
- it_behaves_like 'returns variables for triggers'
+ it_behaves_like "returns variables for triggers"
end
end
- context 'when pipeline has a variable' do
+ context "when pipeline has a variable" do
let!(:pipeline_variable) { create(:ci_pipeline_variable, pipeline: pipeline) }
it { is_expected.to include(key: pipeline_variable.key, value: pipeline_variable.value, public: false, masked: false) }
end
- context 'when a job was triggered by a pipeline schedule' do
+ context "when a job was triggered by a pipeline schedule" do
let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) }
let!(:pipeline_schedule_variable) do
create(:ci_pipeline_schedule_variable,
- key: 'SCHEDULE_VARIABLE_KEY',
- pipeline_schedule: pipeline_schedule)
+ key: "SCHEDULE_VARIABLE_KEY",
+ pipeline_schedule: pipeline_schedule)
end
before do
@@ -2500,16 +2501,16 @@ describe Ci::Build do
it { is_expected.to include(key: pipeline_schedule_variable.key, value: pipeline_schedule_variable.value, public: false, masked: false) }
end
- context 'when container registry is enabled' do
+ context "when container registry is enabled" do
let(:container_registry_enabled) { true }
let(:ci_registry) do
- { key: 'CI_REGISTRY', value: 'registry.example.com', public: true, masked: false }
+ {key: "CI_REGISTRY", value: "registry.example.com", public: true, masked: false}
end
let(:ci_registry_image) do
- { key: 'CI_REGISTRY_IMAGE', value: project.container_registry_url, public: true, masked: false }
+ {key: "CI_REGISTRY_IMAGE", value: project.container_registry_url, public: true, masked: false}
end
- context 'and is disabled for project' do
+ context "and is disabled for project" do
before do
project.update(container_registry_enabled: false)
end
@@ -2518,7 +2519,7 @@ describe Ci::Build do
it { is_expected.not_to include(ci_registry_image) }
end
- context 'and is enabled for project' do
+ context "and is enabled for project" do
before do
project.update(container_registry_enabled: true)
end
@@ -2528,23 +2529,23 @@ describe Ci::Build do
end
end
- context 'when runner is assigned to build' do
- let(:runner) { create(:ci_runner, description: 'description', tag_list: %w(docker linux)) }
+ context "when runner is assigned to build" do
+ let(:runner) { create(:ci_runner, description: "description", tag_list: %w[docker linux]) }
before do
build.update(runner: runner)
end
- it { is_expected.to include({ key: 'CI_RUNNER_ID', value: runner.id.to_s, public: true, masked: false }) }
- it { is_expected.to include({ key: 'CI_RUNNER_DESCRIPTION', value: 'description', public: true, masked: false }) }
- it { is_expected.to include({ key: 'CI_RUNNER_TAGS', value: 'docker, linux', public: true, masked: false }) }
+ it { is_expected.to include({key: "CI_RUNNER_ID", value: runner.id.to_s, public: true, masked: false}) }
+ it { is_expected.to include({key: "CI_RUNNER_DESCRIPTION", value: "description", public: true, masked: false}) }
+ it { is_expected.to include({key: "CI_RUNNER_TAGS", value: "docker, linux", public: true, masked: false}) }
end
- context 'when build is for a deployment' do
- let(:deployment_variable) { { key: 'KUBERNETES_TOKEN', value: 'TOKEN', public: false, masked: false } }
+ context "when build is for a deployment" do
+ let(:deployment_variable) { {key: "KUBERNETES_TOKEN", value: "TOKEN", public: false, masked: false} }
before do
- build.environment = 'production'
+ build.environment = "production"
allow_any_instance_of(Project)
.to receive(:deployment_variables)
@@ -2554,57 +2555,59 @@ describe Ci::Build do
it { is_expected.to include(deployment_variable) }
end
- context 'when project has custom CI config path' do
- let(:ci_config_path) { { key: 'CI_CONFIG_PATH', value: 'custom', public: true, masked: false } }
+ context "when project has custom CI config path" do
+ let(:ci_config_path) { {key: "CI_CONFIG_PATH", value: "custom", public: true, masked: false} }
before do
- project.update(ci_config_path: 'custom')
+ project.update(ci_config_path: "custom")
end
it { is_expected.to include(ci_config_path) }
end
- context 'when using auto devops' do
- context 'and is enabled' do
+ context "when using auto devops" do
+ context "and is enabled" do
before do
- project.create_auto_devops!(enabled: true, domain: 'example.com')
+ project.create_auto_devops!(enabled: true, domain: "example.com")
end
it "includes AUTO_DEVOPS_DOMAIN" do
is_expected.to include(
- { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true, masked: false })
+ {key: "AUTO_DEVOPS_DOMAIN", value: "example.com", public: true, masked: false}
+ )
end
end
- context 'and is disabled' do
+ context "and is disabled" do
before do
- project.create_auto_devops!(enabled: false, domain: 'example.com')
+ project.create_auto_devops!(enabled: false, domain: "example.com")
end
it "includes AUTO_DEVOPS_DOMAIN" do
is_expected.not_to include(
- { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true, masked: false })
+ {key: "AUTO_DEVOPS_DOMAIN", value: "example.com", public: true, masked: false}
+ )
end
end
end
- context 'when pipeline variable overrides build variable' do
+ context "when pipeline variable overrides build variable" do
before do
- build.yaml_variables = [{ key: 'MYVAR', value: 'myvar', public: true }]
- pipeline.variables.build(key: 'MYVAR', value: 'pipeline value')
+ build.yaml_variables = [{key: "MYVAR", value: "myvar", public: true}]
+ pipeline.variables.build(key: "MYVAR", value: "pipeline value")
end
- it 'overrides YAML variable using a pipeline variable' do
+ it "overrides YAML variable using a pipeline variable" do
variables = subject.reverse.uniq { |variable| variable[:key] }.reverse
expect(variables)
- .not_to include(key: 'MYVAR', value: 'myvar', public: true, masked: false)
+ .not_to include(key: "MYVAR", value: "myvar", public: true, masked: false)
expect(variables)
- .to include(key: 'MYVAR', value: 'pipeline value', public: false, masked: false)
+ .to include(key: "MYVAR", value: "pipeline value", public: false, masked: false)
end
end
- context 'when build is parallelized' do
+ context "when build is parallelized" do
let(:total) { 5 }
let(:index) { 3 }
@@ -2614,80 +2617,80 @@ describe Ci::Build do
build.name = "#{build.name} #{index}/#{total}"
end
- it 'includes CI_NODE_INDEX' do
+ it "includes CI_NODE_INDEX" do
is_expected.to include(
- { key: 'CI_NODE_INDEX', value: index.to_s, public: true, masked: false }
+ {key: "CI_NODE_INDEX", value: index.to_s, public: true, masked: false}
)
end
- it 'includes correct CI_NODE_TOTAL' do
+ it "includes correct CI_NODE_TOTAL" do
is_expected.to include(
- { key: 'CI_NODE_TOTAL', value: total.to_s, public: true, masked: false }
+ {key: "CI_NODE_TOTAL", value: total.to_s, public: true, masked: false}
)
end
end
- context 'when build has not been persisted yet' do
+ context "when build has not been persisted yet" do
let(:build) do
described_class.new(
- name: 'rspec',
- stage: 'test',
- ref: 'feature',
+ name: "rspec",
+ stage: "test",
+ ref: "feature",
project: project,
pipeline: pipeline
)
end
- it 'returns static predefined variables' do
+ it "returns static predefined variables" do
expect(build.variables.size).to be >= 28
expect(build.variables)
- .to include(key: 'CI_COMMIT_REF_NAME', value: 'feature', public: true, masked: false)
+ .to include(key: "CI_COMMIT_REF_NAME", value: "feature", public: true, masked: false)
expect(build).not_to be_persisted
end
end
- context 'for deploy tokens' do
+ context "for deploy tokens" do
let(:deploy_token) { create(:deploy_token, :gitlab_deploy_token) }
let(:deploy_token_variables) do
[
- { key: 'CI_DEPLOY_USER', value: deploy_token.username, public: true, masked: false },
- { key: 'CI_DEPLOY_PASSWORD', value: deploy_token.token, public: false, masked: false }
+ {key: "CI_DEPLOY_USER", value: deploy_token.username, public: true, masked: false},
+ {key: "CI_DEPLOY_PASSWORD", value: deploy_token.token, public: false, masked: false},
]
end
- context 'when gitlab-deploy-token exists' do
+ context "when gitlab-deploy-token exists" do
before do
project.deploy_tokens << deploy_token
end
- it 'should include deploy token variables' do
+ it "should include deploy token variables" do
is_expected.to include(*deploy_token_variables)
end
end
- context 'when gitlab-deploy-token does not exist' do
- it 'should not include deploy token variables' do
- expect(subject.find { |v| v[:key] == 'CI_DEPLOY_USER'}).to be_nil
- expect(subject.find { |v| v[:key] == 'CI_DEPLOY_PASSWORD'}).to be_nil
+ context "when gitlab-deploy-token does not exist" do
+ it "should not include deploy token variables" do
+ expect(subject.find { |v| v[:key] == "CI_DEPLOY_USER"}).to be_nil
+ expect(subject.find { |v| v[:key] == "CI_DEPLOY_PASSWORD"}).to be_nil
end
end
end
end
- describe '#scoped_variables' do
- context 'when build has not been persisted yet' do
+ describe "#scoped_variables" do
+ context "when build has not been persisted yet" do
let(:build) do
described_class.new(
- name: 'rspec',
- stage: 'test',
- ref: 'feature',
+ name: "rspec",
+ stage: "test",
+ ref: "feature",
project: project,
pipeline: pipeline
)
end
- it 'does not persist the build' do
+ it "does not persist the build" do
expect(build).to be_valid
expect(build).not_to be_persisted
@@ -2696,7 +2699,7 @@ describe Ci::Build do
expect(build).not_to be_persisted
end
- it 'returns static predefined variables' do
+ it "returns static predefined variables" do
keys = %w[CI_JOB_NAME
CI_COMMIT_SHA
CI_COMMIT_SHORT_SHA
@@ -2711,10 +2714,10 @@ describe Ci::Build do
end
expect(variables)
- .to include(key: 'CI_COMMIT_REF_NAME', value: 'feature', public: true, masked: false)
+ .to include(key: "CI_COMMIT_REF_NAME", value: "feature", public: true, masked: false)
end
- it 'does not return prohibited variables' do
+ it "does not return prohibited variables" do
keys = %w[CI_JOB_ID
CI_JOB_URL
CI_JOB_TOKEN
@@ -2734,95 +2737,95 @@ describe Ci::Build do
end
end
- describe '#scoped_variables_hash' do
- context 'when overriding CI variables' do
+ describe "#scoped_variables_hash" do
+ context "when overriding CI variables" do
before do
- project.variables.create!(key: 'MY_VAR', value: 'my value 1')
- pipeline.variables.create!(key: 'MY_VAR', value: 'my value 2')
+ project.variables.create!(key: "MY_VAR", value: "my value 1")
+ pipeline.variables.create!(key: "MY_VAR", value: "my value 2")
end
- it 'returns a regular hash created using valid ordering' do
- expect(build.scoped_variables_hash).to include('MY_VAR': 'my value 2')
- expect(build.scoped_variables_hash).not_to include('MY_VAR': 'my value 1')
+ it "returns a regular hash created using valid ordering" do
+ expect(build.scoped_variables_hash).to include('MY_VAR': "my value 2")
+ expect(build.scoped_variables_hash).not_to include('MY_VAR': "my value 1")
end
end
- context 'when overriding user-provided variables' do
+ context "when overriding user-provided variables" do
before do
- pipeline.variables.build(key: 'MY_VAR', value: 'pipeline value')
- build.yaml_variables = [{ key: 'MY_VAR', value: 'myvar', public: true }]
+ pipeline.variables.build(key: "MY_VAR", value: "pipeline value")
+ build.yaml_variables = [{key: "MY_VAR", value: "myvar", public: true}]
end
- it 'returns a hash including variable with higher precedence' do
- expect(build.scoped_variables_hash).to include('MY_VAR': 'pipeline value')
- expect(build.scoped_variables_hash).not_to include('MY_VAR': 'myvar')
+ it "returns a hash including variable with higher precedence" do
+ expect(build.scoped_variables_hash).to include('MY_VAR': "pipeline value")
+ expect(build.scoped_variables_hash).not_to include('MY_VAR': "myvar")
end
end
end
- describe '#yaml_variables' do
+ describe "#yaml_variables" do
let(:build) { create(:ci_build, pipeline: pipeline, yaml_variables: variables) }
let(:variables) do
[
- { 'key' => :VARIABLE, 'value' => 'my value' },
- { 'key' => 'VARIABLE2', 'value' => 'my value 2' }
+ {"key" => :VARIABLE, "value" => "my value"},
+ {"key" => "VARIABLE2", "value" => "my value 2"},
]
end
- shared_examples 'having consistent representation' do
- it 'allows to access using symbols' do
- expect(build.reload.yaml_variables.first[:key]).to eq('VARIABLE')
- expect(build.reload.yaml_variables.first[:value]).to eq('my value')
- expect(build.reload.yaml_variables.second[:key]).to eq('VARIABLE2')
- expect(build.reload.yaml_variables.second[:value]).to eq('my value 2')
+ shared_examples "having consistent representation" do
+ it "allows to access using symbols" do
+ expect(build.reload.yaml_variables.first[:key]).to eq("VARIABLE")
+ expect(build.reload.yaml_variables.first[:value]).to eq("my value")
+ expect(build.reload.yaml_variables.second[:key]).to eq("VARIABLE2")
+ expect(build.reload.yaml_variables.second[:value]).to eq("my value 2")
end
end
- context 'when ci_build_metadata_config is set' do
+ context "when ci_build_metadata_config is set" do
before do
stub_feature_flags(ci_build_metadata_config: true)
end
- it_behaves_like 'having consistent representation'
+ it_behaves_like "having consistent representation"
- it 'persist data in build metadata' do
+ it "persist data in build metadata" do
expect(build.metadata.read_attribute(:config_variables)).not_to be_nil
end
- it 'does not persist data in build' do
+ it "does not persist data in build" do
expect(build.read_attribute(:yaml_variables)).to be_nil
end
end
- context 'when ci_build_metadata_config is disabled' do
+ context "when ci_build_metadata_config is disabled" do
before do
stub_feature_flags(ci_build_metadata_config: false)
end
- it_behaves_like 'having consistent representation'
+ it_behaves_like "having consistent representation"
- it 'persist data in build' do
+ it "persist data in build" do
expect(build.read_attribute(:yaml_variables)).not_to be_nil
end
- it 'does not persist data in build metadata' do
+ it "does not persist data in build metadata" do
expect(build.metadata.read_attribute(:config_variables)).to be_nil
end
end
end
- describe 'state transition: any => [:pending]' do
+ describe "state transition: any => [:pending]" do
let(:build) { create(:ci_build, :created) }
- it 'queues BuildQueueWorker' do
+ it "queues BuildQueueWorker" do
expect(BuildQueueWorker).to receive(:perform_async).with(build.id)
build.enqueue
end
end
- describe 'state transition: pending: :running' do
+ describe "state transition: pending: :running" do
let(:runner) { create(:ci_runner) }
let(:job) { create(:ci_build, :pending, runner: runner) }
@@ -2835,16 +2838,16 @@ describe Ci::Build do
rescue StateMachines::InvalidTransition
end
- shared_examples 'saves data on transition' do
- it 'saves timeout' do
+ shared_examples "saves data on transition" do
+ it "saves timeout" do
expect { job.run! }.to change { job.reload.ensure_metadata.timeout }.from(nil).to(expected_timeout)
end
- it 'saves timeout_source' do
- expect { job.run! }.to change { job.reload.ensure_metadata.timeout_source }.from('unknown_timeout_source').to(expected_timeout_source)
+ it "saves timeout_source" do
+ expect { job.run! }.to change { job.reload.ensure_metadata.timeout_source }.from("unknown_timeout_source").to(expected_timeout_source)
end
- context 'when Ci::BuildMetadata#update_timeout_state fails update' do
+ context "when Ci::BuildMetadata#update_timeout_state fails update" do
before do
allow_any_instance_of(Ci::BuildMetadata).to receive(:update_timeout_state).and_return(false)
end
@@ -2859,45 +2862,45 @@ describe Ci::Build do
end
end
- context 'when runner timeout overrides project timeout' do
+ context "when runner timeout overrides project timeout" do
let(:expected_timeout) { 900 }
- let(:expected_timeout_source) { 'runner_timeout_source' }
+ let(:expected_timeout_source) { "runner_timeout_source" }
before do
runner.update_attribute(:maximum_timeout, 900)
end
- it_behaves_like 'saves data on transition'
+ it_behaves_like "saves data on transition"
end
context "when runner timeout doesn't override project timeout" do
let(:expected_timeout) { 1800 }
- let(:expected_timeout_source) { 'project_timeout_source' }
+ let(:expected_timeout_source) { "project_timeout_source" }
before do
runner.update_attribute(:maximum_timeout, 3600)
end
- it_behaves_like 'saves data on transition'
+ it_behaves_like "saves data on transition"
end
end
- describe '#has_valid_build_dependencies?' do
- shared_examples 'validation is active' do
- context 'when depended job has not been completed yet' do
- let!(:pre_stage_job) { create(:ci_build, :manual, pipeline: pipeline, name: 'test', stage_idx: 0) }
+ describe "#has_valid_build_dependencies?" do
+ shared_examples "validation is active" do
+ context "when depended job has not been completed yet" do
+ let!(:pre_stage_job) { create(:ci_build, :manual, pipeline: pipeline, name: "test", stage_idx: 0) }
it { expect(job).to have_valid_build_dependencies }
end
- context 'when artifacts of depended job has been expired' do
- let!(:pre_stage_job) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test', stage_idx: 0) }
+ context "when artifacts of depended job has been expired" do
+ let!(:pre_stage_job) { create(:ci_build, :success, :expired, pipeline: pipeline, name: "test", stage_idx: 0) }
it { expect(job).not_to have_valid_build_dependencies }
end
- context 'when artifacts of depended job has been erased' do
- let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: 'test', stage_idx: 0, erased_at: 1.minute.ago) }
+ context "when artifacts of depended job has been erased" do
+ let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: "test", stage_idx: 0, erased_at: 1.minute.ago) }
before do
pre_stage_job.erase
@@ -2907,21 +2910,21 @@ describe Ci::Build do
end
end
- shared_examples 'validation is not active' do
- context 'when depended job has not been completed yet' do
- let!(:pre_stage_job) { create(:ci_build, :manual, pipeline: pipeline, name: 'test', stage_idx: 0) }
+ shared_examples "validation is not active" do
+ context "when depended job has not been completed yet" do
+ let!(:pre_stage_job) { create(:ci_build, :manual, pipeline: pipeline, name: "test", stage_idx: 0) }
it { expect(job).to have_valid_build_dependencies }
end
- context 'when artifacts of depended job has been expired' do
- let!(:pre_stage_job) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test', stage_idx: 0) }
+ context "when artifacts of depended job has been expired" do
+ let!(:pre_stage_job) { create(:ci_build, :success, :expired, pipeline: pipeline, name: "test", stage_idx: 0) }
it { expect(job).to have_valid_build_dependencies }
end
- context 'when artifacts of depended job has been erased' do
- let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: 'test', stage_idx: 0, erased_at: 1.minute.ago) }
+ context "when artifacts of depended job has been erased" do
+ let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: "test", stage_idx: 0, erased_at: 1.minute.ago) }
before do
pre_stage_job.erase
@@ -2933,12 +2936,12 @@ describe Ci::Build do
let!(:job) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 1, options: options) }
- context 'when validates for dependencies is enabled' do
+ context "when validates for dependencies is enabled" do
before do
stub_feature_flags(ci_disable_validates_dependencies: false)
end
- let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: 'test', stage_idx: 0) }
+ let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: "test", stage_idx: 0) }
context 'when "dependencies" keyword is not defined' do
let(:options) { {} }
@@ -2947,30 +2950,30 @@ describe Ci::Build do
end
context 'when "dependencies" keyword is empty' do
- let(:options) { { dependencies: [] } }
+ let(:options) { {dependencies: []} }
it { expect(job).to have_valid_build_dependencies }
end
context 'when "dependencies" keyword is specified' do
- let(:options) { { dependencies: ['test'] } }
+ let(:options) { {dependencies: ["test"]} }
- it_behaves_like 'validation is active'
+ it_behaves_like "validation is active"
end
end
- context 'when validates for dependencies is disabled' do
- let(:options) { { dependencies: ['test'] } }
+ context "when validates for dependencies is disabled" do
+ let(:options) { {dependencies: ["test"]} }
before do
stub_feature_flags(ci_disable_validates_dependencies: true)
end
- it_behaves_like 'validation is not active'
+ it_behaves_like "validation is not active"
end
end
- describe 'state transition when build fails' do
+ describe "state transition when build fails" do
let(:service) { MergeRequests::AddTodoWhenBuildFailsService.new(project, user) }
before do
@@ -2978,17 +2981,17 @@ describe Ci::Build do
allow(service).to receive(:close)
end
- context 'when build is configured to be retried' do
- subject { create(:ci_build, :running, options: { script: ["ls -al"], retry: 3 }, project: project, user: user) }
+ context "when build is configured to be retried" do
+ subject { create(:ci_build, :running, options: {script: ["ls -al"], retry: 3}, project: project, user: user) }
- it 'retries build and assigns the same user to it' do
+ it "retries build and assigns the same user to it" do
expect(described_class).to receive(:retry)
.with(subject, user)
subject.drop!
end
- it 'does not try to create a todo' do
+ it "does not try to create a todo" do
project.add_developer(user)
expect(service).not_to receive(:commit_status_merge_requests)
@@ -2996,7 +2999,7 @@ describe Ci::Build do
subject.drop!
end
- context 'when retry service raises Gitlab::Access::AccessDeniedError exception' do
+ context "when retry service raises Gitlab::Access::AccessDeniedError exception" do
let(:retry_service) { Ci::RetryBuildService.new(subject.project, subject.user) }
before do
@@ -3007,11 +3010,11 @@ describe Ci::Build do
allow(Rails.logger).to receive(:error)
end
- it 'handles raised exception' do
+ it "handles raised exception" do
expect { subject.drop! }.not_to raise_exception(Gitlab::Access::AccessDeniedError)
end
- it 'logs the error' do
+ it "logs the error" do
subject.drop!
expect(Rails.logger)
@@ -3019,23 +3022,23 @@ describe Ci::Build do
.with(a_string_matching("Unable to auto-retry job #{subject.id}"))
end
- it 'fails the job' do
+ it "fails the job" do
subject.drop!
expect(subject.failed?).to be_truthy
end
end
end
- context 'when build is not configured to be retried' do
+ context "when build is not configured to be retried" do
subject { create(:ci_build, :running, project: project, user: user) }
- it 'does not retry build' do
+ it "does not retry build" do
expect(described_class).not_to receive(:retry)
subject.drop!
end
- it 'does not count retries when not necessary' do
+ it "does not count retries when not necessary" do
expect(described_class).not_to receive(:retry)
expect_any_instance_of(described_class)
.not_to receive(:retries_count)
@@ -3043,7 +3046,7 @@ describe Ci::Build do
subject.drop!
end
- it 'creates a todo' do
+ it "creates a todo" do
project.add_developer(user)
expect(service).to receive(:commit_status_merge_requests)
@@ -3052,16 +3055,16 @@ describe Ci::Build do
end
end
- context 'when associated deployment failed to update its status' do
+ context "when associated deployment failed to update its status" do
let(:build) { create(:ci_build, :running, pipeline: pipeline) }
let!(:deployment) { create(:deployment, deployable: build) }
before do
allow_any_instance_of(Deployment)
- .to receive(:drop!).and_raise('Unexpected error')
+ .to receive(:drop!).and_raise("Unexpected error")
end
- it 'can drop the build' do
+ it "can drop the build" do
expect(Gitlab::Sentry).to receive(:track_exception)
expect { build.drop! }.not_to raise_error
@@ -3071,7 +3074,7 @@ describe Ci::Build do
end
end
- describe '.matches_tag_ids' do
+ describe ".matches_tag_ids" do
set(:build) { create(:ci_build, project: project, user: user) }
let(:tag_ids) { ::ActsAsTaggableOn::Tag.named_any(tag_list).ids }
@@ -3081,36 +3084,36 @@ describe Ci::Build do
build.update(tag_list: build_tag_list)
end
- context 'when have different tags' do
- let(:build_tag_list) { %w(A B) }
- let(:tag_list) { %w(C D) }
+ context "when have different tags" do
+ let(:build_tag_list) { %w[A B] }
+ let(:tag_list) { %w[C D] }
it "does not match a build" do
is_expected.not_to contain_exactly(build)
end
end
- context 'when have a subset of tags' do
- let(:build_tag_list) { %w(A B) }
- let(:tag_list) { %w(A B C D) }
+ context "when have a subset of tags" do
+ let(:build_tag_list) { %w[A B] }
+ let(:tag_list) { %w[A B C D] }
it "does match a build" do
is_expected.to contain_exactly(build)
end
end
- context 'when build does not have tags' do
+ context "when build does not have tags" do
let(:build_tag_list) { [] }
- let(:tag_list) { %w(C D) }
+ let(:tag_list) { %w[C D] }
it "does match a build" do
is_expected.to contain_exactly(build)
end
end
- context 'when does not have a subset of tags' do
- let(:build_tag_list) { %w(A B C) }
- let(:tag_list) { %w(C D) }
+ context "when does not have a subset of tags" do
+ let(:build_tag_list) { %w[A B C] }
+ let(:tag_list) { %w[C D] }
it "does not match a build" do
is_expected.not_to contain_exactly(build)
@@ -3118,7 +3121,7 @@ describe Ci::Build do
end
end
- describe '.matches_tags' do
+ describe ".matches_tags" do
set(:build) { create(:ci_build, project: project, user: user) }
subject { described_class.where(id: build).with_any_tags }
@@ -3127,15 +3130,15 @@ describe Ci::Build do
build.update(tag_list: tag_list)
end
- context 'when does have tags' do
- let(:tag_list) { %w(A B) }
+ context "when does have tags" do
+ let(:tag_list) { %w[A B] }
it "does match a build" do
is_expected.to contain_exactly(build)
end
end
- context 'when does not have tags' do
+ context "when does not have tags" do
let(:tag_list) { [] }
it "does not match a build" do
@@ -3144,24 +3147,24 @@ describe Ci::Build do
end
end
- describe 'pages deployments' do
+ describe "pages deployments" do
set(:build) { create(:ci_build, project: project, user: user) }
context 'when job is "pages"' do
before do
- build.name = 'pages'
+ build.name = "pages"
end
- context 'when pages are enabled' do
+ context "when pages are enabled" do
before do
allow(Gitlab.config.pages).to receive_messages(enabled: true)
end
- it 'is marked as pages generator' do
+ it "is marked as pages generator" do
expect(build).to be_pages_generator
end
- context 'job succeeds' do
+ context "job succeeds" do
it "calls pages worker" do
expect(PagesWorker).to receive(:perform_async).with(:deploy, build.id)
@@ -3169,7 +3172,7 @@ describe Ci::Build do
end
end
- context 'job fails' do
+ context "job fails" do
it "does not call pages worker" do
expect(PagesWorker).not_to receive(:perform_async)
@@ -3178,16 +3181,16 @@ describe Ci::Build do
end
end
- context 'when pages are disabled' do
+ context "when pages are disabled" do
before do
allow(Gitlab.config.pages).to receive_messages(enabled: false)
end
- it 'is not marked as pages generator' do
+ it "is not marked as pages generator" do
expect(build).not_to be_pages_generator
end
- context 'job succeeds' do
+ context "job succeeds" do
it "does not call pages worker" do
expect(PagesWorker).not_to receive(:perform_async)
@@ -3199,14 +3202,14 @@ describe Ci::Build do
context 'when job is not "pages"' do
before do
- build.name = 'other-job'
+ build.name = "other-job"
end
- it 'is not marked as pages generator' do
+ it "is not marked as pages generator" do
expect(build).not_to be_pages_generator
end
- context 'job succeeds' do
+ context "job succeeds" do
it "does not call pages worker" do
expect(PagesWorker).not_to receive(:perform_async)
@@ -3216,28 +3219,28 @@ describe Ci::Build do
end
end
- describe '#has_terminal?' do
+ describe "#has_terminal?" do
let(:states) { described_class.state_machines[:status].states.keys - [:running] }
subject { build.has_terminal? }
- it 'returns true if the build is running and it has a runner_session_url' do
- build.build_runner_session(url: 'whatever')
+ it "returns true if the build is running and it has a runner_session_url" do
+ build.build_runner_session(url: "whatever")
build.status = :running
expect(subject).to be_truthy
end
- context 'returns false' do
- it 'when runner_session_url is empty' do
+ context "returns false" do
+ it "when runner_session_url is empty" do
build.status = :running
expect(subject).to be_falsey
end
- context 'unless the build is running' do
+ context "unless the build is running" do
before do
- build.build_runner_session(url: 'whatever')
+ build.build_runner_session(url: "whatever")
end
it do
@@ -3251,20 +3254,20 @@ describe Ci::Build do
end
end
- describe '#collect_test_reports!' do
+ describe "#collect_test_reports!" do
subject { build.collect_test_reports!(test_reports) }
let(:test_reports) { Gitlab::Ci::Reports::TestReports.new }
it { expect(test_reports.get_suite(build.name).total_count).to eq(0) }
- context 'when build has a test report' do
- context 'when there is a JUnit test report from rspec test suite' do
+ context "when build has a test report" do
+ context "when there is a JUnit test report from rspec test suite" do
before do
create(:ci_job_artifact, :junit, job: build, project: build.project)
end
- it 'parses blobs and add the results to the test suite' do
+ it "parses blobs and add the results to the test suite" do
expect { subject }.not_to raise_error
expect(test_reports.get_suite(build.name).total_count).to eq(4)
@@ -3273,12 +3276,12 @@ describe Ci::Build do
end
end
- context 'when there is a JUnit test report from java ant test suite' do
+ context "when there is a JUnit test report from java ant test suite" do
before do
create(:ci_job_artifact, :junit_with_ant, job: build, project: build.project)
end
- it 'parses blobs and add the results to the test suite' do
+ it "parses blobs and add the results to the test suite" do
expect { subject }.not_to raise_error
expect(test_reports.get_suite(build.name).total_count).to eq(3)
@@ -3287,21 +3290,21 @@ describe Ci::Build do
end
end
- context 'when there is a corrupted JUnit test report' do
+ context "when there is a corrupted JUnit test report" do
before do
create(:ci_job_artifact, :junit_with_corrupted_data, job: build, project: build.project)
end
- it 'raises an error' do
+ it "raises an error" do
expect { subject }.to raise_error(Gitlab::Ci::Parsers::Test::Junit::JunitParserError)
end
end
end
end
- describe '#artifacts_metadata_entry' do
+ describe "#artifacts_metadata_entry" do
set(:build) { create(:ci_build, project: project) }
- let(:path) { 'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' }
+ let(:path) { "other_artifacts_0.1.2/another-subdirectory/banana_sample.gif" }
before do
stub_artifacts_object_storage
@@ -3309,113 +3312,113 @@ describe Ci::Build do
subject { build.artifacts_metadata_entry(path) }
- context 'when using local storage' do
+ context "when using local storage" do
let!(:metadata) { create(:ci_job_artifact, :metadata, job: build) }
- context 'for existing file' do
- it 'does exist' do
+ context "for existing file" do
+ it "does exist" do
is_expected.to be_exists
end
end
- context 'for non-existing file' do
- let(:path) { 'invalid-file' }
+ context "for non-existing file" do
+ let(:path) { "invalid-file" }
- it 'does not exist' do
+ it "does not exist" do
is_expected.not_to be_exists
end
end
end
- context 'when using remote storage' do
+ context "when using remote storage" do
include HttpIOHelpers
let!(:metadata) { create(:ci_job_artifact, :remote_store, :metadata, job: build) }
- let(:file_path) { expand_fixture_path('ci_build_artifacts_metadata.gz') }
+ let(:file_path) { expand_fixture_path("ci_build_artifacts_metadata.gz") }
before do
stub_remote_url_206(metadata.file.url, file_path)
end
- context 'for existing file' do
- it 'does exist' do
+ context "for existing file" do
+ it "does exist" do
is_expected.to be_exists
end
end
- context 'for non-existing file' do
- let(:path) { 'invalid-file' }
+ context "for non-existing file" do
+ let(:path) { "invalid-file" }
- it 'does not exist' do
+ it "does not exist" do
is_expected.not_to be_exists
end
end
end
end
- describe '#publishes_artifacts_reports?' do
+ describe "#publishes_artifacts_reports?" do
let(:build) { create(:ci_build, options: options) }
subject { build.publishes_artifacts_reports? }
- context 'when artifacts reports are defined' do
+ context "when artifacts reports are defined" do
let(:options) do
- { artifacts: { reports: { junit: "junit.xml" } } }
+ {artifacts: {reports: {junit: "junit.xml"}}}
end
it { is_expected.to be_truthy }
end
- context 'when artifacts reports missing defined' do
+ context "when artifacts reports missing defined" do
let(:options) do
- { artifacts: { paths: ["file.txt"] } }
+ {artifacts: {paths: ["file.txt"]}}
end
it { is_expected.to be_falsey }
end
- context 'when options are missing' do
+ context "when options are missing" do
let(:options) { nil }
it { is_expected.to be_falsey }
end
end
- describe '#runner_required_feature_names' do
+ describe "#runner_required_feature_names" do
let(:build) { create(:ci_build, options: options) }
subject { build.runner_required_feature_names }
- context 'when artifacts reports are defined' do
+ context "when artifacts reports are defined" do
let(:options) do
- { artifacts: { reports: { junit: "junit.xml" } } }
+ {artifacts: {reports: {junit: "junit.xml"}}}
end
it { is_expected.to include(:upload_multiple_artifacts) }
end
end
- describe '#supported_runner?' do
+ describe "#supported_runner?" do
set(:build) { create(:ci_build) }
subject { build.supported_runner?(runner_features) }
- context 'when feature is required by build' do
+ context "when feature is required by build" do
before do
expect(build).to receive(:runner_required_feature_names) do
[:upload_multiple_artifacts]
end
end
- context 'when runner provides given feature' do
+ context "when runner provides given feature" do
let(:runner_features) do
- { upload_multiple_artifacts: true }
+ {upload_multiple_artifacts: true}
end
it { is_expected.to be_truthy }
end
- context 'when runner does not provide given feature' do
+ context "when runner does not provide given feature" do
let(:runner_features) do
{}
end
@@ -3425,58 +3428,58 @@ describe Ci::Build do
end
end
- describe '#deployment_status' do
+ describe "#deployment_status" do
before do
allow_any_instance_of(described_class).to receive(:create_deployment)
end
- context 'when build is a last deployment' do
- let(:build) { create(:ci_build, :success, environment: 'production') }
- let(:environment) { create(:environment, name: 'production', project: build.project) }
+ context "when build is a last deployment" do
+ let(:build) { create(:ci_build, :success, environment: "production") }
+ let(:environment) { create(:environment, name: "production", project: build.project) }
let!(:deployment) { create(:deployment, :success, environment: environment, project: environment.project, deployable: build) }
it { expect(build.deployment_status).to eq(:last) }
end
- context 'when there is a newer build with deployment' do
- let(:build) { create(:ci_build, :success, environment: 'production') }
- let(:environment) { create(:environment, name: 'production', project: build.project) }
+ context "when there is a newer build with deployment" do
+ let(:build) { create(:ci_build, :success, environment: "production") }
+ let(:environment) { create(:environment, name: "production", project: build.project) }
let!(:deployment) { create(:deployment, :success, environment: environment, project: environment.project, deployable: build) }
let!(:last_deployment) { create(:deployment, :success, environment: environment, project: environment.project) }
it { expect(build.deployment_status).to eq(:out_of_date) }
end
- context 'when build with deployment has failed' do
- let(:build) { create(:ci_build, :failed, environment: 'production') }
- let(:environment) { create(:environment, name: 'production', project: build.project) }
+ context "when build with deployment has failed" do
+ let(:build) { create(:ci_build, :failed, environment: "production") }
+ let(:environment) { create(:environment, name: "production", project: build.project) }
let!(:deployment) { create(:deployment, :success, environment: environment, project: environment.project, deployable: build) }
it { expect(build.deployment_status).to eq(:failed) }
end
- context 'when build with deployment is running' do
- let(:build) { create(:ci_build, environment: 'production') }
- let(:environment) { create(:environment, name: 'production', project: build.project) }
+ context "when build with deployment is running" do
+ let(:build) { create(:ci_build, environment: "production") }
+ let(:environment) { create(:environment, name: "production", project: build.project) }
let!(:deployment) { create(:deployment, :success, environment: environment, project: environment.project, deployable: build) }
it { expect(build.deployment_status).to eq(:creating) }
end
end
- describe '#degenerated?' do
- context 'when build is degenerated' do
+ describe "#degenerated?" do
+ context "when build is degenerated" do
subject { create(:ci_build, :degenerated) }
it { is_expected.to be_degenerated }
end
- context 'when build is valid' do
+ context "when build is valid" do
subject { create(:ci_build) }
it { is_expected.not_to be_degenerated }
- context 'and becomes degenerated' do
+ context "and becomes degenerated" do
before do
subject.degenerate!
end
@@ -3486,7 +3489,7 @@ describe Ci::Build do
end
end
- describe 'degenerate!' do
+ describe "degenerate!" do
let(:build) { create(:ci_build) }
subject { build.degenerate! }
@@ -3495,7 +3498,7 @@ describe Ci::Build do
build.ensure_metadata
end
- it 'drops metadata' do
+ it "drops metadata" do
subject
expect(build.reload).to be_degenerated
@@ -3503,17 +3506,17 @@ describe Ci::Build do
end
end
- describe '#archived?' do
- context 'when build is degenerated' do
+ describe "#archived?" do
+ context "when build is degenerated" do
subject { create(:ci_build, :degenerated) }
it { is_expected.to be_archived }
end
- context 'for old build' do
+ context "for old build" do
subject { create(:ci_build, created_at: 1.day.ago) }
- context 'when archive_builds_in is set' do
+ context "when archive_builds_in is set" do
before do
stub_application_setting(archive_builds_in_seconds: 3600)
end
@@ -3521,7 +3524,7 @@ describe Ci::Build do
it { is_expected.to be_archived }
end
- context 'when archive_builds_in is not set' do
+ context "when archive_builds_in is not set" do
before do
stub_application_setting(archive_builds_in_seconds: nil)
end
@@ -3531,67 +3534,67 @@ describe Ci::Build do
end
end
- describe '#read_metadata_attribute' do
+ describe "#read_metadata_attribute" do
let(:build) { create(:ci_build, :degenerated) }
- let(:build_options) { { "key" => "build" } }
- let(:metadata_options) { { "key" => "metadata" } }
- let(:default_options) { { "key" => "default" } }
+ let(:build_options) { {"key" => "build"} }
+ let(:metadata_options) { {"key" => "metadata"} }
+ let(:default_options) { {"key" => "default"} }
subject { build.send(:read_metadata_attribute, :options, :config_options, default_options) }
- context 'when build and metadata options is set' do
+ context "when build and metadata options is set" do
before do
build.write_attribute(:options, build_options)
build.ensure_metadata.write_attribute(:config_options, metadata_options)
end
- it 'prefers build options' do
+ it "prefers build options" do
is_expected.to eq(build_options)
end
end
- context 'when only metadata options is set' do
+ context "when only metadata options is set" do
before do
build.write_attribute(:options, nil)
build.ensure_metadata.write_attribute(:config_options, metadata_options)
end
- it 'returns metadata options' do
+ it "returns metadata options" do
is_expected.to eq(metadata_options)
end
end
- context 'when none is set' do
- it 'returns default value' do
+ context "when none is set" do
+ it "returns default value" do
is_expected.to eq(default_options)
end
end
end
- describe '#write_metadata_attribute' do
+ describe "#write_metadata_attribute" do
let(:build) { create(:ci_build, :degenerated) }
- let(:options) { { "key" => "new options" } }
- let(:existing_options) { { "key" => "existing options" } }
+ let(:options) { {"key" => "new options"} }
+ let(:existing_options) { {"key" => "existing options"} }
subject { build.send(:write_metadata_attribute, :options, :config_options, options) }
- context 'when ci_build_metadata_config is set' do
+ context "when ci_build_metadata_config is set" do
before do
stub_feature_flags(ci_build_metadata_config: true)
end
- context 'when data in build is already set' do
+ context "when data in build is already set" do
before do
build.write_attribute(:options, existing_options)
end
- it 'does set metadata options' do
+ it "does set metadata options" do
subject
expect(build.metadata.read_attribute(:config_options)).to eq(options)
end
- it 'does reset build options' do
+ it "does reset build options" do
subject
expect(build.read_attribute(:options)).to be_nil
@@ -3599,23 +3602,23 @@ describe Ci::Build do
end
end
- context 'when ci_build_metadata_config is disabled' do
+ context "when ci_build_metadata_config is disabled" do
before do
stub_feature_flags(ci_build_metadata_config: false)
end
- context 'when data in build metadata is already set' do
+ context "when data in build metadata is already set" do
before do
build.ensure_metadata.write_attribute(:config_options, existing_options)
end
- it 'does set metadata options' do
+ it "does set metadata options" do
subject
expect(build.read_attribute(:options)).to eq(options)
end
- it 'does reset build options' do
+ it "does reset build options" do
subject
expect(build.metadata.read_attribute(:config_options)).to be_nil
diff --git a/spec/models/ci/build_trace_chunk_spec.rb b/spec/models/ci/build_trace_chunk_spec.rb
index 59db347582b..53e42daff04 100644
--- a/spec/models/ci/build_trace_chunk_spec.rb
+++ b/spec/models/ci/build_trace_chunk_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
include ExclusiveLeaseHelpers
@@ -12,20 +12,20 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
described_class.new(build: build, chunk_index: chunk_index, data_store: data_store, raw_data: raw_data)
end
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
before do
stub_feature_flags(ci_enable_live_trace: true)
stub_artifacts_object_storage
end
- context 'FastDestroyAll' do
+ context "FastDestroyAll" do
let(:parent) { create(:project) }
let(:pipeline) { create(:ci_pipeline, project: parent) }
let(:build) { create(:ci_build, :running, :trace_live, pipeline: pipeline, project: parent) }
let(:subjects) { build.trace_chunks }
- it_behaves_like 'fast destroyable'
+ it_behaves_like "fast destroyable"
def external_data_counter
Gitlab::Redis::SharedState.with do |redis|
@@ -34,135 +34,135 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
- describe 'CHUNK_SIZE' do
- it 'Chunk size can not be changed without special care' do
+ describe "CHUNK_SIZE" do
+ it "Chunk size can not be changed without special care" do
expect(described_class::CHUNK_SIZE).to eq(128.kilobytes)
end
end
- describe '.all_stores' do
+ describe ".all_stores" do
subject { described_class.all_stores }
- it 'returns a correctly ordered array' do
+ it "returns a correctly ordered array" do
is_expected.to eq(%w[redis database fog])
end
- it 'returns redis store as the lowest precedence' do
- expect(subject.first).to eq('redis')
+ it "returns redis store as the lowest precedence" do
+ expect(subject.first).to eq("redis")
end
- it 'returns fog store as the highest precedence' do
- expect(subject.last).to eq('fog')
+ it "returns fog store as the highest precedence" do
+ expect(subject.last).to eq("fog")
end
end
- describe '#data' do
+ describe "#data" do
subject { build_trace_chunk.data }
- context 'when data_store is redis' do
+ context "when data_store is redis" do
let(:data_store) { :redis }
before do
- build_trace_chunk.send(:unsafe_set_data!, 'Sample data in redis')
+ build_trace_chunk.send(:unsafe_set_data!, "Sample data in redis")
end
- it { is_expected.to eq('Sample data in redis') }
+ it { is_expected.to eq("Sample data in redis") }
end
- context 'when data_store is database' do
+ context "when data_store is database" do
let(:data_store) { :database }
- let(:raw_data) { 'Sample data in database' }
+ let(:raw_data) { "Sample data in database" }
- it { is_expected.to eq('Sample data in database') }
+ it { is_expected.to eq("Sample data in database") }
end
- context 'when data_store is fog' do
+ context "when data_store is fog" do
let(:data_store) { :fog }
before do
- build_trace_chunk.send(:unsafe_set_data!, 'Sample data in fog')
+ build_trace_chunk.send(:unsafe_set_data!, "Sample data in fog")
end
- it { is_expected.to eq('Sample data in fog') }
+ it { is_expected.to eq("Sample data in fog") }
end
end
- describe '#append' do
+ describe "#append" do
subject { build_trace_chunk.append(new_data, offset) }
- let(:new_data) { 'Sample new data' }
+ let(:new_data) { "Sample new data" }
let(:offset) { 0 }
let(:merged_data) { data + new_data.to_s }
- shared_examples_for 'Appending correctly' do
- context 'when offset is negative' do
+ shared_examples_for "Appending correctly" do
+ context "when offset is negative" do
let(:offset) { -1 }
- it { expect { subject }.to raise_error('Offset is out of range') }
+ it { expect { subject }.to raise_error("Offset is out of range") }
end
- context 'when offset is bigger than data size' do
+ context "when offset is bigger than data size" do
let(:offset) { data.bytesize + 1 }
- it { expect { subject }.to raise_error('Offset is out of range') }
+ it { expect { subject }.to raise_error("Offset is out of range") }
end
- context 'when new data overflows chunk size' do
- let(:new_data) { 'a' * (described_class::CHUNK_SIZE + 1) }
+ context "when new data overflows chunk size" do
+ let(:new_data) { "a" * (described_class::CHUNK_SIZE + 1) }
- it { expect { subject }.to raise_error('Chunk size overflow') }
+ it { expect { subject }.to raise_error("Chunk size overflow") }
end
- context 'when offset is EOF' do
+ context "when offset is EOF" do
let(:offset) { data.bytesize }
- it 'appends' do
+ it "appends" do
subject
expect(build_trace_chunk.data).to eq(merged_data)
end
- context 'when the other process is appending' do
+ context "when the other process is appending" do
let(:lease_key) { "trace_write:#{build_trace_chunk.build.id}:chunks:#{build_trace_chunk.chunk_index}" }
before do
stub_exclusive_lease_taken(lease_key)
end
- it 'raise an error' do
- expect { subject }.to raise_error('Failed to obtain a lock')
+ it "raise an error" do
+ expect { subject }.to raise_error("Failed to obtain a lock")
end
end
- context 'when new_data is nil' do
+ context "when new_data is nil" do
let(:new_data) { nil }
- it 'raises an error' do
- expect { subject }.to raise_error('New data is missing')
+ it "raises an error" do
+ expect { subject }.to raise_error("New data is missing")
end
end
- context 'when new_data is empty' do
- let(:new_data) { '' }
+ context "when new_data is empty" do
+ let(:new_data) { "" }
- it 'does not append' do
+ it "does not append" do
subject
expect(build_trace_chunk.data).to eq(data)
end
- it 'does not execute UPDATE' do
+ it "does not execute UPDATE" do
ActiveRecord::QueryRecorder.new { subject }.log.map do |query|
- expect(query).not_to include('UPDATE')
+ expect(query).not_to include("UPDATE")
end
end
end
end
- context 'when offset is middle of datasize' do
+ context "when offset is middle of datasize" do
let(:offset) { data.bytesize / 2 }
- it 'appends' do
+ it "appends" do
subject
expect(build_trace_chunk.data).to eq(data.byteslice(0, offset) + new_data)
@@ -170,17 +170,17 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
- shared_examples_for 'Scheduling sidekiq worker to flush data to persist store' do
- context 'when new data fulfilled chunk size' do
- let(:new_data) { 'a' * described_class::CHUNK_SIZE }
+ shared_examples_for "Scheduling sidekiq worker to flush data to persist store" do
+ context "when new data fulfilled chunk size" do
+ let(:new_data) { "a" * described_class::CHUNK_SIZE }
- it 'schedules trace chunk flush worker' do
+ it "schedules trace chunk flush worker" do
expect(Ci::BuildTraceChunkFlushWorker).to receive(:perform_async).once
subject
end
- it 'migrates data to object storage' do
+ it "migrates data to object storage" do
perform_enqueued_jobs do
subject
@@ -192,17 +192,17 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
- shared_examples_for 'Scheduling no sidekiq worker' do
- context 'when new data fulfilled chunk size' do
- let(:new_data) { 'a' * described_class::CHUNK_SIZE }
+ shared_examples_for "Scheduling no sidekiq worker" do
+ context "when new data fulfilled chunk size" do
+ let(:new_data) { "a" * described_class::CHUNK_SIZE }
- it 'does not schedule trace chunk flush worker' do
+ it "does not schedule trace chunk flush worker" do
expect(Ci::BuildTraceChunkFlushWorker).not_to receive(:perform_async)
subject
end
- it 'does not migrate data to object storage' do
+ it "does not migrate data to object storage" do
perform_enqueued_jobs do
data_store = build_trace_chunk.data_store
@@ -215,114 +215,114 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
- context 'when data_store is redis' do
+ context "when data_store is redis" do
let(:data_store) { :redis }
- context 'when there are no data' do
- let(:data) { '' }
+ context "when there are no data" do
+ let(:data) { "" }
- it 'has no data' do
+ it "has no data" do
expect(build_trace_chunk.data).to be_empty
end
- it_behaves_like 'Appending correctly'
- it_behaves_like 'Scheduling sidekiq worker to flush data to persist store'
+ it_behaves_like "Appending correctly"
+ it_behaves_like "Scheduling sidekiq worker to flush data to persist store"
end
- context 'when there are some data' do
- let(:data) { 'Sample data in redis' }
+ context "when there are some data" do
+ let(:data) { "Sample data in redis" }
before do
build_trace_chunk.send(:unsafe_set_data!, data)
end
- it 'has data' do
+ it "has data" do
expect(build_trace_chunk.data).to eq(data)
end
- it_behaves_like 'Appending correctly'
- it_behaves_like 'Scheduling sidekiq worker to flush data to persist store'
+ it_behaves_like "Appending correctly"
+ it_behaves_like "Scheduling sidekiq worker to flush data to persist store"
end
end
- context 'when data_store is database' do
+ context "when data_store is database" do
let(:data_store) { :database }
- context 'when there are no data' do
- let(:data) { '' }
+ context "when there are no data" do
+ let(:data) { "" }
- it 'has no data' do
+ it "has no data" do
expect(build_trace_chunk.data).to be_empty
end
- it_behaves_like 'Appending correctly'
- it_behaves_like 'Scheduling no sidekiq worker'
+ it_behaves_like "Appending correctly"
+ it_behaves_like "Scheduling no sidekiq worker"
end
- context 'when there are some data' do
- let(:raw_data) { 'Sample data in database' }
+ context "when there are some data" do
+ let(:raw_data) { "Sample data in database" }
let(:data) { raw_data }
- it 'has data' do
+ it "has data" do
expect(build_trace_chunk.data).to eq(data)
end
- it_behaves_like 'Appending correctly'
- it_behaves_like 'Scheduling no sidekiq worker'
+ it_behaves_like "Appending correctly"
+ it_behaves_like "Scheduling no sidekiq worker"
end
end
- context 'when data_store is fog' do
+ context "when data_store is fog" do
let(:data_store) { :fog }
- context 'when there are no data' do
- let(:data) { '' }
+ context "when there are no data" do
+ let(:data) { "" }
- it 'has no data' do
+ it "has no data" do
expect(build_trace_chunk.data).to be_empty
end
- it_behaves_like 'Appending correctly'
- it_behaves_like 'Scheduling no sidekiq worker'
+ it_behaves_like "Appending correctly"
+ it_behaves_like "Scheduling no sidekiq worker"
end
- context 'when there are some data' do
- let(:data) { 'Sample data in fog' }
+ context "when there are some data" do
+ let(:data) { "Sample data in fog" }
before do
build_trace_chunk.send(:unsafe_set_data!, data)
end
- it 'has data' do
+ it "has data" do
expect(build_trace_chunk.data).to eq(data)
end
- it_behaves_like 'Appending correctly'
- it_behaves_like 'Scheduling no sidekiq worker'
+ it_behaves_like "Appending correctly"
+ it_behaves_like "Scheduling no sidekiq worker"
end
end
end
- describe '#truncate' do
+ describe "#truncate" do
subject { build_trace_chunk.truncate(offset) }
- shared_examples_for 'truncates' do
- context 'when offset is negative' do
+ shared_examples_for "truncates" do
+ context "when offset is negative" do
let(:offset) { -1 }
- it { expect { subject }.to raise_error('Offset is out of range') }
+ it { expect { subject }.to raise_error("Offset is out of range") }
end
- context 'when offset is bigger than data size' do
+ context "when offset is bigger than data size" do
let(:offset) { data.bytesize + 1 }
- it { expect { subject }.to raise_error('Offset is out of range') }
+ it { expect { subject }.to raise_error("Offset is out of range") }
end
- context 'when offset is 10' do
+ context "when offset is 10" do
let(:offset) { 10 }
- it 'truncates' do
+ it "truncates" do
subject
expect(build_trace_chunk.data).to eq(data.byteslice(0, offset))
@@ -330,45 +330,45 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
- context 'when data_store is redis' do
+ context "when data_store is redis" do
let(:data_store) { :redis }
- let(:data) { 'Sample data in redis' }
+ let(:data) { "Sample data in redis" }
before do
build_trace_chunk.send(:unsafe_set_data!, data)
end
- it_behaves_like 'truncates'
+ it_behaves_like "truncates"
end
- context 'when data_store is database' do
+ context "when data_store is database" do
let(:data_store) { :database }
- let(:raw_data) { 'Sample data in database' }
+ let(:raw_data) { "Sample data in database" }
let(:data) { raw_data }
- it_behaves_like 'truncates'
+ it_behaves_like "truncates"
end
- context 'when data_store is fog' do
+ context "when data_store is fog" do
let(:data_store) { :fog }
- let(:data) { 'Sample data in fog' }
+ let(:data) { "Sample data in fog" }
before do
build_trace_chunk.send(:unsafe_set_data!, data)
end
- it_behaves_like 'truncates'
+ it_behaves_like "truncates"
end
end
- describe '#size' do
+ describe "#size" do
subject { build_trace_chunk.size }
- context 'when data_store is redis' do
+ context "when data_store is redis" do
let(:data_store) { :redis }
- context 'when data exists' do
- let(:data) { 'Sample data in redis' }
+ context "when data exists" do
+ let(:data) { "Sample data in redis" }
before do
build_trace_chunk.send(:unsafe_set_data!, data)
@@ -377,31 +377,31 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
it { is_expected.to eq(data.bytesize) }
end
- context 'when data exists' do
+ context "when data exists" do
it { is_expected.to eq(0) }
end
end
- context 'when data_store is database' do
+ context "when data_store is database" do
let(:data_store) { :database }
- context 'when data exists' do
- let(:raw_data) { 'Sample data in database' }
+ context "when data exists" do
+ let(:raw_data) { "Sample data in database" }
let(:data) { raw_data }
it { is_expected.to eq(data.bytesize) }
end
- context 'when data does not exist' do
+ context "when data does not exist" do
it { is_expected.to eq(0) }
end
end
- context 'when data_store is fog' do
+ context "when data_store is fog" do
let(:data_store) { :fog }
- context 'when data exists' do
- let(:data) { 'Sample data in fog' }
+ context "when data exists" do
+ let(:data) { "Sample data in fog" }
let(:key) { "tmp/builds/#{build.id}/chunks/#{chunk_index}.log" }
before do
@@ -411,41 +411,41 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
it { is_expected.to eq(data.bytesize) }
end
- context 'when data does not exist' do
+ context "when data does not exist" do
it { is_expected.to eq(0) }
end
end
end
- describe '#persist_data!' do
+ describe "#persist_data!" do
subject { build_trace_chunk.persist_data! }
- shared_examples_for 'Atomic operation' do
- context 'when the other process is persisting' do
+ shared_examples_for "Atomic operation" do
+ context "when the other process is persisting" do
let(:lease_key) { "trace_write:#{build_trace_chunk.build.id}:chunks:#{build_trace_chunk.chunk_index}" }
before do
stub_exclusive_lease_taken(lease_key)
end
- it 'raise an error' do
- expect { subject }.to raise_error('Failed to obtain a lock')
+ it "raise an error" do
+ expect { subject }.to raise_error("Failed to obtain a lock")
end
end
end
- context 'when data_store is redis' do
+ context "when data_store is redis" do
let(:data_store) { :redis }
- context 'when data exists' do
+ context "when data exists" do
before do
build_trace_chunk.send(:unsafe_set_data!, data)
end
- context 'when data size reached CHUNK_SIZE' do
- let(:data) { 'a' * described_class::CHUNK_SIZE }
+ context "when data size reached CHUNK_SIZE" do
+ let(:data) { "a" * described_class::CHUNK_SIZE }
- it 'persists the data' do
+ it "persists the data" do
expect(build_trace_chunk.redis?).to be_truthy
expect(Ci::BuildTraceChunks::Redis.new.data(build_trace_chunk)).to eq(data)
expect(Ci::BuildTraceChunks::Database.new.data(build_trace_chunk)).to be_nil
@@ -459,13 +459,13 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
expect(Ci::BuildTraceChunks::Fog.new.data(build_trace_chunk)).to eq(data)
end
- it_behaves_like 'Atomic operation'
+ it_behaves_like "Atomic operation"
end
- context 'when data size has not reached CHUNK_SIZE' do
- let(:data) { 'Sample data in redis' }
+ context "when data size has not reached CHUNK_SIZE" do
+ let(:data) { "Sample data in redis" }
- it 'does not persist the data and the orignal data is intact' do
+ it "does not persist the data and the orignal data is intact" do
expect { subject }.to raise_error(described_class::FailedToPersistDataError)
expect(build_trace_chunk.redis?).to be_truthy
@@ -476,25 +476,25 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
- context 'when data does not exist' do
- it 'does not persist' do
+ context "when data does not exist" do
+ it "does not persist" do
expect { subject }.to raise_error(described_class::FailedToPersistDataError)
end
end
end
- context 'when data_store is database' do
+ context "when data_store is database" do
let(:data_store) { :database }
- context 'when data exists' do
+ context "when data exists" do
before do
build_trace_chunk.send(:unsafe_set_data!, data)
end
- context 'when data size reached CHUNK_SIZE' do
- let(:data) { 'a' * described_class::CHUNK_SIZE }
+ context "when data size reached CHUNK_SIZE" do
+ let(:data) { "a" * described_class::CHUNK_SIZE }
- it 'persists the data' do
+ it "persists the data" do
expect(build_trace_chunk.database?).to be_truthy
expect(Ci::BuildTraceChunks::Redis.new.data(build_trace_chunk)).to be_nil
expect(Ci::BuildTraceChunks::Database.new.data(build_trace_chunk)).to eq(data)
@@ -508,13 +508,13 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
expect(Ci::BuildTraceChunks::Fog.new.data(build_trace_chunk)).to eq(data)
end
- it_behaves_like 'Atomic operation'
+ it_behaves_like "Atomic operation"
end
- context 'when data size has not reached CHUNK_SIZE' do
- let(:data) { 'Sample data in database' }
+ context "when data size has not reached CHUNK_SIZE" do
+ let(:data) { "Sample data in database" }
- it 'does not persist the data and the orignal data is intact' do
+ it "does not persist the data and the orignal data is intact" do
expect { subject }.to raise_error(described_class::FailedToPersistDataError)
expect(build_trace_chunk.database?).to be_truthy
@@ -525,25 +525,25 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
- context 'when data does not exist' do
- it 'does not persist' do
+ context "when data does not exist" do
+ it "does not persist" do
expect { subject }.to raise_error(described_class::FailedToPersistDataError)
end
end
end
- context 'when data_store is fog' do
+ context "when data_store is fog" do
let(:data_store) { :fog }
- context 'when data exists' do
+ context "when data exists" do
before do
build_trace_chunk.send(:unsafe_set_data!, data)
end
- context 'when data size reached CHUNK_SIZE' do
- let(:data) { 'a' * described_class::CHUNK_SIZE }
+ context "when data size reached CHUNK_SIZE" do
+ let(:data) { "a" * described_class::CHUNK_SIZE }
- it 'does not change data store' do
+ it "does not change data store" do
expect(build_trace_chunk.fog?).to be_truthy
expect(Ci::BuildTraceChunks::Redis.new.data(build_trace_chunk)).to be_nil
expect(Ci::BuildTraceChunks::Database.new.data(build_trace_chunk)).to be_nil
@@ -557,13 +557,13 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
expect(Ci::BuildTraceChunks::Fog.new.data(build_trace_chunk)).to eq(data)
end
- it_behaves_like 'Atomic operation'
+ it_behaves_like "Atomic operation"
end
- context 'when data size has not reached CHUNK_SIZE' do
- let(:data) { 'Sample data in fog' }
+ context "when data size has not reached CHUNK_SIZE" do
+ let(:data) { "Sample data in fog" }
- it 'does not raise error' do
+ it "does not raise error" do
expect { subject }.not_to raise_error
end
end
@@ -571,7 +571,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
- describe 'deletes data in redis after a parent record destroyed' do
+ describe "deletes data in redis after a parent record destroyed" do
let(:project) { create(:project) }
before do
@@ -581,7 +581,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
create(:ci_build, :running, :trace_live, pipeline: pipeline, project: project)
end
- shared_examples_for 'deletes all build_trace_chunk and data in redis' do
+ shared_examples_for "deletes all build_trace_chunk and data in redis" do
it do
Gitlab::Redis::SharedState.with do |redis|
expect(redis.scan_each(match: "gitlab:ci:trace:*:chunks:*").to_a.size).to eq(3)
@@ -599,22 +599,22 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
- context 'when traces are archived' do
+ context "when traces are archived" do
let(:subject) do
project.builds.each do |build|
build.success!
end
end
- it_behaves_like 'deletes all build_trace_chunk and data in redis'
+ it_behaves_like "deletes all build_trace_chunk and data in redis"
end
- context 'when project is destroyed' do
+ context "when project is destroyed" do
let(:subject) do
project.destroy!
end
- it_behaves_like 'deletes all build_trace_chunk and data in redis'
+ it_behaves_like "deletes all build_trace_chunk and data in redis"
end
end
end
diff --git a/spec/models/ci/build_trace_chunks/database_spec.rb b/spec/models/ci/build_trace_chunks/database_spec.rb
index d8fc9d57e95..85509faab4d 100644
--- a/spec/models/ci/build_trace_chunks/database_spec.rb
+++ b/spec/models/ci/build_trace_chunks/database_spec.rb
@@ -1,72 +1,72 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::BuildTraceChunks::Database do
let(:data_store) { described_class.new }
- describe '#available?' do
+ describe "#available?" do
subject { data_store.available? }
it { is_expected.to be_truthy }
end
- describe '#data' do
+ describe "#data" do
subject { data_store.data(model) }
- context 'when data exists' do
- let(:model) { create(:ci_build_trace_chunk, :database_with_data, initial_data: 'sample data in database') }
+ context "when data exists" do
+ let(:model) { create(:ci_build_trace_chunk, :database_with_data, initial_data: "sample data in database") }
- it 'returns the data' do
- is_expected.to eq('sample data in database')
+ it "returns the data" do
+ is_expected.to eq("sample data in database")
end
end
- context 'when data does not exist' do
+ context "when data does not exist" do
let(:model) { create(:ci_build_trace_chunk, :database_without_data) }
- it 'returns nil' do
+ it "returns nil" do
is_expected.to be_nil
end
end
end
- describe '#set_data' do
+ describe "#set_data" do
subject { data_store.set_data(model, data) }
- let(:data) { 'abc123' }
+ let(:data) { "abc123" }
- context 'when data exists' do
- let(:model) { create(:ci_build_trace_chunk, :database_with_data, initial_data: 'sample data in database') }
+ context "when data exists" do
+ let(:model) { create(:ci_build_trace_chunk, :database_with_data, initial_data: "sample data in database") }
- it 'overwrites data' do
- expect(data_store.data(model)).to eq('sample data in database')
+ it "overwrites data" do
+ expect(data_store.data(model)).to eq("sample data in database")
subject
- expect(data_store.data(model)).to eq('abc123')
+ expect(data_store.data(model)).to eq("abc123")
end
end
- context 'when data does not exist' do
+ context "when data does not exist" do
let(:model) { create(:ci_build_trace_chunk, :database_without_data) }
- it 'sets new data' do
+ it "sets new data" do
expect(data_store.data(model)).to be_nil
subject
- expect(data_store.data(model)).to eq('abc123')
+ expect(data_store.data(model)).to eq("abc123")
end
end
end
- describe '#delete_data' do
+ describe "#delete_data" do
subject { data_store.delete_data(model) }
- context 'when data exists' do
- let(:model) { create(:ci_build_trace_chunk, :database_with_data, initial_data: 'sample data in database') }
+ context "when data exists" do
+ let(:model) { create(:ci_build_trace_chunk, :database_with_data, initial_data: "sample data in database") }
- it 'deletes data' do
- expect(data_store.data(model)).to eq('sample data in database')
+ it "deletes data" do
+ expect(data_store.data(model)).to eq("sample data in database")
subject
@@ -74,10 +74,10 @@ describe Ci::BuildTraceChunks::Database do
end
end
- context 'when data does not exist' do
+ context "when data does not exist" do
let(:model) { create(:ci_build_trace_chunk, :database_without_data) }
- it 'does nothing' do
+ it "does nothing" do
expect(data_store.data(model)).to be_nil
subject
@@ -87,7 +87,7 @@ describe Ci::BuildTraceChunks::Database do
end
end
- describe '#keys' do
+ describe "#keys" do
subject { data_store.keys(relation) }
let(:build) { create(:ci_build) }
@@ -98,7 +98,7 @@ describe Ci::BuildTraceChunks::Database do
create(:ci_build_trace_chunk, :database_with_data, chunk_index: 1, build: build)
end
- it 'returns empty array' do
+ it "returns empty array" do
is_expected.to eq([])
end
end
diff --git a/spec/models/ci/build_trace_chunks/fog_spec.rb b/spec/models/ci/build_trace_chunks/fog_spec.rb
index 8f49190af13..7b89db3e39f 100644
--- a/spec/models/ci/build_trace_chunks/fog_spec.rb
+++ b/spec/models/ci/build_trace_chunks/fog_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::BuildTraceChunks::Fog do
let(:data_store) { described_class.new }
@@ -7,14 +7,14 @@ describe Ci::BuildTraceChunks::Fog do
stub_artifacts_object_storage
end
- describe '#available?' do
+ describe "#available?" do
subject { data_store.available? }
- context 'when object storage is enabled' do
+ context "when object storage is enabled" do
it { is_expected.to be_truthy }
end
- context 'when object storage is disabled' do
+ context "when object storage is disabled" do
before do
stub_artifacts_object_storage(enabled: false)
end
@@ -23,64 +23,64 @@ describe Ci::BuildTraceChunks::Fog do
end
end
- describe '#data' do
+ describe "#data" do
subject { data_store.data(model) }
- context 'when data exists' do
- let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: 'sample data in fog') }
+ context "when data exists" do
+ let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: "sample data in fog") }
- it 'returns the data' do
- is_expected.to eq('sample data in fog')
+ it "returns the data" do
+ is_expected.to eq("sample data in fog")
end
end
- context 'when data does not exist' do
+ context "when data does not exist" do
let(:model) { create(:ci_build_trace_chunk, :fog_without_data) }
- it 'returns nil' do
+ it "returns nil" do
expect { data_store.data(model) }.to raise_error(Excon::Error::NotFound)
end
end
end
- describe '#set_data' do
+ describe "#set_data" do
subject { data_store.set_data(model, data) }
- let(:data) { 'abc123' }
+ let(:data) { "abc123" }
- context 'when data exists' do
- let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: 'sample data in fog') }
+ context "when data exists" do
+ let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: "sample data in fog") }
- it 'overwrites data' do
- expect(data_store.data(model)).to eq('sample data in fog')
+ it "overwrites data" do
+ expect(data_store.data(model)).to eq("sample data in fog")
subject
- expect(data_store.data(model)).to eq('abc123')
+ expect(data_store.data(model)).to eq("abc123")
end
end
- context 'when data does not exist' do
+ context "when data does not exist" do
let(:model) { create(:ci_build_trace_chunk, :fog_without_data) }
- it 'sets new data' do
+ it "sets new data" do
expect { data_store.data(model) }.to raise_error(Excon::Error::NotFound)
subject
- expect(data_store.data(model)).to eq('abc123')
+ expect(data_store.data(model)).to eq("abc123")
end
end
end
- describe '#delete_data' do
+ describe "#delete_data" do
subject { data_store.delete_data(model) }
- context 'when data exists' do
- let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: 'sample data in fog') }
+ context "when data exists" do
+ let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: "sample data in fog") }
- it 'deletes data' do
- expect(data_store.data(model)).to eq('sample data in fog')
+ it "deletes data" do
+ expect(data_store.data(model)).to eq("sample data in fog")
subject
@@ -88,10 +88,10 @@ describe Ci::BuildTraceChunks::Fog do
end
end
- context 'when data does not exist' do
+ context "when data does not exist" do
let(:model) { create(:ci_build_trace_chunk, :fog_without_data) }
- it 'does nothing' do
+ it "does nothing" do
expect { data_store.data(model) }.to raise_error(Excon::Error::NotFound)
subject
@@ -101,7 +101,7 @@ describe Ci::BuildTraceChunks::Fog do
end
end
- describe '#keys' do
+ describe "#keys" do
subject { data_store.keys(relation) }
let(:build) { create(:ci_build) }
@@ -112,12 +112,12 @@ describe Ci::BuildTraceChunks::Fog do
create(:ci_build_trace_chunk, :fog_with_data, chunk_index: 1, build: build)
end
- it 'returns keys' do
+ it "returns keys" do
is_expected.to eq([[build.id, 0], [build.id, 1]])
end
end
- describe '#delete_keys' do
+ describe "#delete_keys" do
subject { data_store.delete_keys(keys) }
let(:build) { create(:ci_build) }
@@ -129,17 +129,17 @@ describe Ci::BuildTraceChunks::Fog do
create(:ci_build_trace_chunk, :fog_with_data, chunk_index: 1, build: build)
end
- it 'deletes multiple data' do
+ it "deletes multiple data" do
::Fog::Storage.new(JobArtifactUploader.object_store_credentials).tap do |connection|
- expect(connection.get_object('artifacts', "tmp/builds/#{build.id}/chunks/0.log")[:body]).to be_present
- expect(connection.get_object('artifacts', "tmp/builds/#{build.id}/chunks/1.log")[:body]).to be_present
+ expect(connection.get_object("artifacts", "tmp/builds/#{build.id}/chunks/0.log")[:body]).to be_present
+ expect(connection.get_object("artifacts", "tmp/builds/#{build.id}/chunks/1.log")[:body]).to be_present
end
subject
::Fog::Storage.new(JobArtifactUploader.object_store_credentials).tap do |connection|
- expect { connection.get_object('artifacts', "tmp/builds/#{build.id}/chunks/0.log")[:body] }.to raise_error(Excon::Error::NotFound)
- expect { connection.get_object('artifacts', "tmp/builds/#{build.id}/chunks/1.log")[:body] }.to raise_error(Excon::Error::NotFound)
+ expect { connection.get_object("artifacts", "tmp/builds/#{build.id}/chunks/0.log")[:body] }.to raise_error(Excon::Error::NotFound)
+ expect { connection.get_object("artifacts", "tmp/builds/#{build.id}/chunks/1.log")[:body] }.to raise_error(Excon::Error::NotFound)
end
end
end
diff --git a/spec/models/ci/build_trace_chunks/redis_spec.rb b/spec/models/ci/build_trace_chunks/redis_spec.rb
index 9da1e6a95ee..632328d9973 100644
--- a/spec/models/ci/build_trace_chunks/redis_spec.rb
+++ b/spec/models/ci/build_trace_chunks/redis_spec.rb
@@ -1,72 +1,72 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::BuildTraceChunks::Redis, :clean_gitlab_redis_shared_state do
let(:data_store) { described_class.new }
- describe '#available?' do
+ describe "#available?" do
subject { data_store.available? }
it { is_expected.to be_truthy }
end
- describe '#data' do
+ describe "#data" do
subject { data_store.data(model) }
- context 'when data exists' do
- let(:model) { create(:ci_build_trace_chunk, :redis_with_data, initial_data: 'sample data in redis') }
+ context "when data exists" do
+ let(:model) { create(:ci_build_trace_chunk, :redis_with_data, initial_data: "sample data in redis") }
- it 'returns the data' do
- is_expected.to eq('sample data in redis')
+ it "returns the data" do
+ is_expected.to eq("sample data in redis")
end
end
- context 'when data does not exist' do
+ context "when data does not exist" do
let(:model) { create(:ci_build_trace_chunk, :redis_without_data) }
- it 'returns nil' do
+ it "returns nil" do
is_expected.to be_nil
end
end
end
- describe '#set_data' do
+ describe "#set_data" do
subject { data_store.set_data(model, data) }
- let(:data) { 'abc123' }
+ let(:data) { "abc123" }
- context 'when data exists' do
- let(:model) { create(:ci_build_trace_chunk, :redis_with_data, initial_data: 'sample data in redis') }
+ context "when data exists" do
+ let(:model) { create(:ci_build_trace_chunk, :redis_with_data, initial_data: "sample data in redis") }
- it 'overwrites data' do
- expect(data_store.data(model)).to eq('sample data in redis')
+ it "overwrites data" do
+ expect(data_store.data(model)).to eq("sample data in redis")
subject
- expect(data_store.data(model)).to eq('abc123')
+ expect(data_store.data(model)).to eq("abc123")
end
end
- context 'when data does not exist' do
+ context "when data does not exist" do
let(:model) { create(:ci_build_trace_chunk, :redis_without_data) }
- it 'sets new data' do
+ it "sets new data" do
expect(data_store.data(model)).to be_nil
subject
- expect(data_store.data(model)).to eq('abc123')
+ expect(data_store.data(model)).to eq("abc123")
end
end
end
- describe '#delete_data' do
+ describe "#delete_data" do
subject { data_store.delete_data(model) }
- context 'when data exists' do
- let(:model) { create(:ci_build_trace_chunk, :redis_with_data, initial_data: 'sample data in redis') }
+ context "when data exists" do
+ let(:model) { create(:ci_build_trace_chunk, :redis_with_data, initial_data: "sample data in redis") }
- it 'deletes data' do
- expect(data_store.data(model)).to eq('sample data in redis')
+ it "deletes data" do
+ expect(data_store.data(model)).to eq("sample data in redis")
subject
@@ -74,10 +74,10 @@ describe Ci::BuildTraceChunks::Redis, :clean_gitlab_redis_shared_state do
end
end
- context 'when data does not exist' do
+ context "when data does not exist" do
let(:model) { create(:ci_build_trace_chunk, :redis_without_data) }
- it 'does nothing' do
+ it "does nothing" do
expect(data_store.data(model)).to be_nil
subject
@@ -87,7 +87,7 @@ describe Ci::BuildTraceChunks::Redis, :clean_gitlab_redis_shared_state do
end
end
- describe '#keys' do
+ describe "#keys" do
subject { data_store.keys(relation) }
let(:build) { create(:ci_build) }
@@ -98,12 +98,12 @@ describe Ci::BuildTraceChunks::Redis, :clean_gitlab_redis_shared_state do
create(:ci_build_trace_chunk, :redis_with_data, chunk_index: 1, build: build)
end
- it 'returns keys' do
+ it "returns keys" do
is_expected.to eq([[build.id, 0], [build.id, 1]])
end
end
- describe '#delete_keys' do
+ describe "#delete_keys" do
subject { data_store.delete_keys(keys) }
let(:build) { create(:ci_build) }
@@ -115,7 +115,7 @@ describe Ci::BuildTraceChunks::Redis, :clean_gitlab_redis_shared_state do
create(:ci_build_trace_chunk, :redis_with_data, chunk_index: 1, build: build)
end
- it 'deletes multiple data' do
+ it "deletes multiple data" do
Gitlab::Redis::SharedState.with do |redis|
expect(redis.exists("gitlab:ci:trace:#{build.id}:chunks:0")).to be_truthy
expect(redis.exists("gitlab:ci:trace:#{build.id}:chunks:1")).to be_truthy
diff --git a/spec/models/ci/build_trace_section_name_spec.rb b/spec/models/ci/build_trace_section_name_spec.rb
index 386ee6880cb..0cb5223718a 100644
--- a/spec/models/ci/build_trace_section_name_spec.rb
+++ b/spec/models/ci/build_trace_section_name_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::BuildTraceSectionName, model: true do
subject { build(:ci_build_trace_section_name) }
diff --git a/spec/models/ci/build_trace_section_spec.rb b/spec/models/ci/build_trace_section_spec.rb
index 541a9a36fb8..38a8ba3148c 100644
--- a/spec/models/ci/build_trace_section_spec.rb
+++ b/spec/models/ci/build_trace_section_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::BuildTraceSection, model: true do
it { is_expected.to belong_to(:build)}
diff --git a/spec/models/ci/group_spec.rb b/spec/models/ci/group_spec.rb
index 838fa63cb1f..9bb76bdb0a4 100644
--- a/spec/models/ci/group_spec.rb
+++ b/spec/models/ci/group_spec.rb
@@ -1,8 +1,8 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::Group do
subject do
- described_class.new('test', name: 'rspec', jobs: jobs)
+ described_class.new("test", name: "rspec", jobs: jobs)
end
let!(:jobs) { build_list(:ci_build, 1, :success) }
@@ -14,77 +14,77 @@ describe Ci::Group do
it { is_expected.to respond_to(:jobs) }
it { is_expected.to respond_to(:status) }
- describe '#size' do
- it 'returns the number of statuses in the group' do
+ describe "#size" do
+ it "returns the number of statuses in the group" do
expect(subject.size).to eq(1)
end
end
- describe '#detailed_status' do
- context 'when there is only one item in the group' do
- it 'calls the status from the object itself' do
+ describe "#detailed_status" do
+ context "when there is only one item in the group" do
+ it "calls the status from the object itself" do
expect(jobs.first).to receive(:detailed_status)
expect(subject.detailed_status(double(:user)))
end
end
- context 'when there are more than one commit status in the group' do
+ context "when there are more than one commit status in the group" do
let(:jobs) do
[create(:ci_build, :failed),
- create(:ci_build, :success)]
+ create(:ci_build, :success),]
end
- it 'fabricates a new detailed status object' do
+ it "fabricates a new detailed status object" do
expect(subject.detailed_status(double(:user)))
.to be_a(Gitlab::Ci::Status::Failed)
end
end
end
- describe '.fabricate' do
+ describe ".fabricate" do
let(:pipeline) { create(:ci_empty_pipeline) }
let(:stage) { create(:ci_stage_entity, pipeline: pipeline) }
before do
- create_build(:ci_build, name: 'rspec 0 2')
- create_build(:ci_build, name: 'rspec 0 1')
- create_build(:ci_build, name: 'spinach 0 1')
- create_build(:commit_status, name: 'aaaaa')
+ create_build(:ci_build, name: "rspec 0 2")
+ create_build(:ci_build, name: "rspec 0 1")
+ create_build(:ci_build, name: "spinach 0 1")
+ create_build(:commit_status, name: "aaaaa")
end
- it 'returns an array of three groups' do
+ it "returns an array of three groups" do
expect(stage.groups).to be_a Array
expect(stage.groups).to all(be_a described_class)
expect(stage.groups.size).to eq 3
end
- it 'returns groups with correctly ordered statuses' do
+ it "returns groups with correctly ordered statuses" do
expect(stage.groups.first.jobs.map(&:name))
- .to eq ['aaaaa']
+ .to eq ["aaaaa"]
expect(stage.groups.second.jobs.map(&:name))
- .to eq ['rspec 0 1', 'rspec 0 2']
+ .to eq ["rspec 0 1", "rspec 0 2"]
expect(stage.groups.third.jobs.map(&:name))
- .to eq ['spinach 0 1']
+ .to eq ["spinach 0 1"]
end
- it 'returns groups with correct names' do
+ it "returns groups with correct names" do
expect(stage.groups.map(&:name))
.to eq %w[aaaaa rspec spinach]
end
- context 'when a name is nil on legacy pipelines' do
+ context "when a name is nil on legacy pipelines" do
before do
pipeline.builds.first.update_attribute(:name, nil)
end
- it 'returns an array of three groups' do
+ it "returns an array of three groups" do
expect(stage.groups.map(&:name))
- .to eq ['', 'aaaaa', 'rspec', 'spinach']
+ .to eq ["", "aaaaa", "rspec", "spinach"]
end
end
- def create_build(type, status: 'success', **opts)
+ def create_build(type, status: "success", **opts)
create(type, pipeline: pipeline,
stage: stage.name,
status: status,
diff --git a/spec/models/ci/group_variable_spec.rb b/spec/models/ci/group_variable_spec.rb
index 21d96bf3454..5ae52c793a4 100644
--- a/spec/models/ci/group_variable_spec.rb
+++ b/spec/models/ci/group_variable_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::GroupVariable do
subject { build(:ci_group_variable) }
@@ -8,23 +8,23 @@ describe Ci::GroupVariable do
it { is_expected.to include_module(Maskable) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:group_id).with_message(/\(\w+\) has already been taken/) }
- describe '.unprotected' do
+ describe ".unprotected" do
subject { described_class.unprotected }
- context 'when variable is protected' do
+ context "when variable is protected" do
before do
create(:ci_group_variable, :protected)
end
- it 'returns nothing' do
+ it "returns nothing" do
is_expected.to be_empty
end
end
- context 'when variable is not protected' do
+ context "when variable is not protected" do
let(:variable) { create(:ci_group_variable, protected: false) }
- it 'returns the variable' do
+ it "returns the variable" do
is_expected.to contain_exactly(variable)
end
end
diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb
index c68ba02b8de..45b153f5d8a 100644
--- a/spec/models/ci/job_artifact_spec.rb
+++ b/spec/models/ci/job_artifact_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::JobArtifact do
let(:artifact) { create(:ci_job_artifact, :archive) }
@@ -15,75 +15,75 @@ describe Ci::JobArtifact do
it { is_expected.to delegate_method(:open).to(:file) }
it { is_expected.to delegate_method(:exists?).to(:file) }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe '.test_reports' do
+ describe ".test_reports" do
subject { described_class.test_reports }
- context 'when there is a test report' do
+ context "when there is a test report" do
let!(:artifact) { create(:ci_job_artifact, :junit) }
it { is_expected.to eq([artifact]) }
end
- context 'when there are no test reports' do
+ context "when there are no test reports" do
let!(:artifact) { create(:ci_job_artifact, :archive) }
it { is_expected.to be_empty }
end
end
- describe '.erasable' do
+ describe ".erasable" do
subject { described_class.erasable }
- context 'when there is an erasable artifact' do
+ context "when there is an erasable artifact" do
let!(:artifact) { create(:ci_job_artifact, :junit) }
it { is_expected.to eq([artifact]) }
end
- context 'when there are no erasable artifacts' do
+ context "when there are no erasable artifacts" do
let!(:artifact) { create(:ci_job_artifact, :trace) }
it { is_expected.to be_empty }
end
end
- describe 'callbacks' do
+ describe "callbacks" do
subject { create(:ci_job_artifact, :archive) }
- describe '#schedule_background_upload' do
- context 'when object storage is disabled' do
+ describe "#schedule_background_upload" do
+ context "when object storage is disabled" do
before do
stub_artifacts_object_storage(enabled: false)
end
- it 'does not schedule the migration' do
+ it "does not schedule the migration" do
expect(ObjectStorage::BackgroundMoveWorker).not_to receive(:perform_async)
subject
end
end
- context 'when object storage is enabled' do
- context 'when background upload is enabled' do
+ context "when object storage is enabled" do
+ context "when background upload is enabled" do
before do
stub_artifacts_object_storage(background_upload: true)
end
- it 'schedules the model for migration' do
- expect(ObjectStorage::BackgroundMoveWorker).to receive(:perform_async).with('JobArtifactUploader', described_class.name, :file, kind_of(Numeric))
+ it "schedules the model for migration" do
+ expect(ObjectStorage::BackgroundMoveWorker).to receive(:perform_async).with("JobArtifactUploader", described_class.name, :file, kind_of(Numeric))
subject
end
end
- context 'when background upload is disabled' do
+ context "when background upload is disabled" do
before do
stub_artifacts_object_storage(background_upload: false)
end
- it 'schedules the model for migration' do
+ it "schedules the model for migration" do
expect(ObjectStorage::BackgroundMoveWorker).not_to receive(:perform_async)
subject
@@ -93,35 +93,35 @@ describe Ci::JobArtifact do
end
end
- context 'creating the artifact' do
+ context "creating the artifact" do
let(:project) { create(:project) }
let(:artifact) { create(:ci_job_artifact, :archive, project: project) }
- it 'sets the size from the file size' do
+ it "sets the size from the file size" do
expect(artifact.size).to eq(106365)
end
- it 'updates the project statistics' do
+ it "updates the project statistics" do
expect { artifact }
.to change { project.statistics.reload.build_artifacts_size }
.by(106365)
end
end
- context 'updating the artifact file' do
- it 'updates the artifact size' do
- artifact.update!(file: fixture_file_upload('spec/fixtures/dk.png'))
+ context "updating the artifact file" do
+ it "updates the artifact size" do
+ artifact.update!(file: fixture_file_upload("spec/fixtures/dk.png"))
expect(artifact.size).to eq(1062)
end
- it 'updates the project statistics' do
- expect { artifact.update!(file: fixture_file_upload('spec/fixtures/dk.png')) }
+ it "updates the project statistics" do
+ expect { artifact.update!(file: fixture_file_upload("spec/fixtures/dk.png")) }
.to change { artifact.project.statistics.reload.build_artifacts_size }
.by(1062 - 106365)
end
end
- describe 'validates file format' do
+ describe "validates file format" do
subject { artifact }
described_class::TYPE_AND_FORMAT_PAIRS.except(:trace).each do |file_type, file_format|
@@ -147,7 +147,7 @@ describe Ci::JobArtifact do
end
end
- describe 'validates DEFAULT_FILE_NAMES' do
+ describe "validates DEFAULT_FILE_NAMES" do
subject { described_class::DEFAULT_FILE_NAMES }
described_class.file_types.each do |file_type, _|
@@ -157,7 +157,7 @@ describe Ci::JobArtifact do
end
end
- describe 'validates TYPE_AND_FORMAT_PAIRS' do
+ describe "validates TYPE_AND_FORMAT_PAIRS" do
subject { described_class::TYPE_AND_FORMAT_PAIRS }
described_class.file_types.each do |file_type, _|
@@ -167,58 +167,58 @@ describe Ci::JobArtifact do
end
end
- describe '#file' do
+ describe "#file" do
subject { artifact.file }
- context 'the uploader api' do
+ context "the uploader api" do
it { is_expected.to respond_to(:store_dir) }
it { is_expected.to respond_to(:cache_dir) }
it { is_expected.to respond_to(:work_dir) }
end
end
- describe '#each_blob' do
- context 'when file format is gzip' do
- context 'when gzip file contains one file' do
+ describe "#each_blob" do
+ context "when file format is gzip" do
+ context "when gzip file contains one file" do
let(:artifact) { build(:ci_job_artifact, :junit) }
- it 'iterates blob once' do
+ it "iterates blob once" do
expect { |b| artifact.each_blob(&b) }.to yield_control.once
end
end
- context 'when gzip file contains three files' do
+ context "when gzip file contains three files" do
let(:artifact) { build(:ci_job_artifact, :junit_with_three_testsuites) }
- it 'iterates blob three times' do
+ it "iterates blob three times" do
expect { |b| artifact.each_blob(&b) }.to yield_control.exactly(3).times
end
end
end
- context 'when file format is raw' do
+ context "when file format is raw" do
let(:artifact) { build(:ci_job_artifact, :codequality, file_format: :raw) }
- it 'iterates blob once' do
+ it "iterates blob once" do
expect { |b| artifact.each_blob(&b) }.to yield_control.once
end
end
- context 'when there are no adapters for the file format' do
+ context "when there are no adapters for the file format" do
let(:artifact) { build(:ci_job_artifact, :junit, file_format: :zip) }
- it 'raises an error' do
+ it "raises an error" do
expect { |b| artifact.each_blob(&b) }.to raise_error(described_class::NotSupportedAdapterError)
end
end
end
- describe '#expire_in' do
+ describe "#expire_in" do
subject { artifact.expire_in }
it { is_expected.to be_nil }
- context 'when expire_at is specified' do
+ context "when expire_at is specified" do
let(:expire_at) { Time.now + 7.days }
before do
@@ -229,40 +229,40 @@ describe Ci::JobArtifact do
end
end
- describe '#expire_in=' do
+ describe "#expire_in=" do
subject { artifact.expire_in }
- it 'when assigning valid duration' do
- artifact.expire_in = '7 days'
+ it "when assigning valid duration" do
+ artifact.expire_in = "7 days"
is_expected.to be_within(10).of(7.days.to_i)
end
- it 'when assigning invalid duration' do
- expect { artifact.expire_in = '7 elephants' }.to raise_error(ChronicDuration::DurationParseError)
+ it "when assigning invalid duration" do
+ expect { artifact.expire_in = "7 elephants" }.to raise_error(ChronicDuration::DurationParseError)
is_expected.to be_nil
end
- it 'when resetting value' do
+ it "when resetting value" do
artifact.expire_in = nil
is_expected.to be_nil
end
- it 'when setting to 0' do
- artifact.expire_in = '0'
+ it "when setting to 0" do
+ artifact.expire_in = "0"
is_expected.to be_nil
end
end
- context 'when destroying the artifact' do
+ context "when destroying the artifact" do
let(:project) { create(:project, :repository) }
let(:pipeline) { create(:ci_pipeline, project: project) }
let!(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
- it 'updates the project statistics' do
+ it "updates the project statistics" do
artifact = build.job_artifacts.first
expect(ProjectStatistics)
@@ -274,8 +274,8 @@ describe Ci::JobArtifact do
.by(-106365)
end
- context 'when it is destroyed from the project level' do
- it 'does not update the project statistics' do
+ context "when it is destroyed from the project level" do
+ it "does not update the project statistics" do
expect(ProjectStatistics)
.not_to receive(:increment_statistic)
@@ -285,37 +285,37 @@ describe Ci::JobArtifact do
end
end
- describe 'file is being stored' do
+ describe "file is being stored" do
subject { create(:ci_job_artifact, :archive) }
- context 'when object has nil store' do
+ context "when object has nil store" do
before do
subject.update_column(:file_store, nil)
subject.reload
end
- it 'is stored locally' do
+ it "is stored locally" do
expect(subject.file_store).to be(nil)
expect(subject.file).to be_file_storage
expect(subject.file.object_store).to eq(ObjectStorage::Store::LOCAL)
end
end
- context 'when existing object has local store' do
- it 'is stored locally' do
+ context "when existing object has local store" do
+ it "is stored locally" do
expect(subject.file_store).to be(ObjectStorage::Store::LOCAL)
expect(subject.file).to be_file_storage
expect(subject.file.object_store).to eq(ObjectStorage::Store::LOCAL)
end
end
- context 'when direct upload is enabled' do
+ context "when direct upload is enabled" do
before do
stub_artifacts_object_storage(direct_upload: true)
end
- context 'when file is stored' do
- it 'is stored remotely' do
+ context "when file is stored" do
+ it "is stored remotely" do
expect(subject.file_store).to eq(ObjectStorage::Store::REMOTE)
expect(subject.file).not_to be_file_storage
expect(subject.file.object_store).to eq(ObjectStorage::Store::REMOTE)
diff --git a/spec/models/ci/legacy_stage_spec.rb b/spec/models/ci/legacy_stage_spec.rb
index 0c33c1466b7..74866845dae 100644
--- a/spec/models/ci/legacy_stage_spec.rb
+++ b/spec/models/ci/legacy_stage_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::LegacyStage do
let(:stage) { build(:ci_stage) }
let(:pipeline) { stage.pipeline }
let(:stage_name) { stage.name }
- describe '#expectations' do
+ describe "#expectations" do
subject { stage }
it { is_expected.to include_module(StaticModel) }
@@ -16,10 +16,10 @@ describe Ci::LegacyStage do
it { is_expected.to delegate_method(:project).to(:pipeline) }
end
- describe '#statuses' do
+ describe "#statuses" do
let!(:stage_build) { create_job(:ci_build) }
let!(:commit_status) { create_job(:commit_status) }
- let!(:other_build) { create_job(:ci_build, stage: 'other stage') }
+ let!(:other_build) { create_job(:ci_build, stage: "other stage") }
subject { stage.statuses }
@@ -28,50 +28,50 @@ describe Ci::LegacyStage do
end
end
- describe '#groups' do
+ describe "#groups" do
before do
- create_job(:ci_build, name: 'rspec 0 2')
- create_job(:ci_build, name: 'rspec 0 1')
- create_job(:ci_build, name: 'spinach 0 1')
- create_job(:commit_status, name: 'aaaaa')
+ create_job(:ci_build, name: "rspec 0 2")
+ create_job(:ci_build, name: "rspec 0 1")
+ create_job(:ci_build, name: "spinach 0 1")
+ create_job(:commit_status, name: "aaaaa")
end
- it 'returns an array of three groups' do
+ it "returns an array of three groups" do
expect(stage.groups).to be_a Array
expect(stage.groups).to all(be_a Ci::Group)
expect(stage.groups.size).to eq 3
end
- it 'returns groups with correctly ordered statuses' do
+ it "returns groups with correctly ordered statuses" do
expect(stage.groups.first.jobs.map(&:name))
- .to eq ['aaaaa']
+ .to eq ["aaaaa"]
expect(stage.groups.second.jobs.map(&:name))
- .to eq ['rspec 0 1', 'rspec 0 2']
+ .to eq ["rspec 0 1", "rspec 0 2"]
expect(stage.groups.third.jobs.map(&:name))
- .to eq ['spinach 0 1']
+ .to eq ["spinach 0 1"]
end
- it 'returns groups with correct names' do
+ it "returns groups with correct names" do
expect(stage.groups.map(&:name))
.to eq %w[aaaaa rspec spinach]
end
- context 'when a name is nil on legacy pipelines' do
+ context "when a name is nil on legacy pipelines" do
before do
pipeline.builds.first.update_attribute(:name, nil)
end
- it 'returns an array of three groups' do
+ it "returns an array of three groups" do
expect(stage.groups.map(&:name))
- .to eq ['', 'aaaaa', 'rspec', 'spinach']
+ .to eq ["", "aaaaa", "rspec", "spinach"]
end
end
end
- describe '#statuses_count' do
+ describe "#statuses_count" do
before do
create_job(:ci_build)
- create_job(:ci_build, stage: 'other stage')
+ create_job(:ci_build, stage: "other stage")
end
subject { stage.statuses_count }
@@ -81,7 +81,7 @@ describe Ci::LegacyStage do
end
end
- describe '#builds' do
+ describe "#builds" do
let!(:stage_build) { create_job(:ci_build) }
let!(:commit_status) { create_job(:commit_status) }
@@ -92,25 +92,25 @@ describe Ci::LegacyStage do
end
end
- describe '#status' do
+ describe "#status" do
subject { stage.status }
- context 'if status is already defined' do
- let(:stage) { build(:ci_stage, status: 'success') }
+ context "if status is already defined" do
+ let(:stage) { build(:ci_stage, status: "success") }
it "returns defined status" do
- is_expected.to eq('success')
+ is_expected.to eq("success")
end
end
- context 'if status has to be calculated' do
+ context "if status has to be calculated" do
let!(:stage_build) { create_job(:ci_build, status: :failed) }
it "returns status of a build" do
- is_expected.to eq('failed')
+ is_expected.to eq("failed")
end
- context 'and builds are retried' do
+ context "and builds are retried" do
let!(:new_build) { create_job(:ci_build, status: :success) }
before do
@@ -118,156 +118,156 @@ describe Ci::LegacyStage do
end
it "returns status of latest build" do
- is_expected.to eq('success')
+ is_expected.to eq("success")
end
end
end
end
- describe '#detailed_status' do
+ describe "#detailed_status" do
let(:user) { create(:user) }
subject { stage.detailed_status(user) }
- context 'when build is created' do
+ context "when build is created" do
let!(:stage_build) { create_job(:ci_build, status: :created) }
- it 'returns detailed status for created stage' do
- expect(subject.text).to eq 'created'
+ it "returns detailed status for created stage" do
+ expect(subject.text).to eq "created"
end
end
- context 'when build is pending' do
+ context "when build is pending" do
let!(:stage_build) { create_job(:ci_build, status: :pending) }
- it 'returns detailed status for pending stage' do
- expect(subject.text).to eq 'pending'
+ it "returns detailed status for pending stage" do
+ expect(subject.text).to eq "pending"
end
end
- context 'when build is running' do
+ context "when build is running" do
let!(:stage_build) { create_job(:ci_build, status: :running) }
- it 'returns detailed status for running stage' do
- expect(subject.text).to eq 'running'
+ it "returns detailed status for running stage" do
+ expect(subject.text).to eq "running"
end
end
- context 'when build is successful' do
+ context "when build is successful" do
let!(:stage_build) { create_job(:ci_build, status: :success) }
- it 'returns detailed status for successful stage' do
- expect(subject.text).to eq 'passed'
+ it "returns detailed status for successful stage" do
+ expect(subject.text).to eq "passed"
end
end
- context 'when build is failed' do
+ context "when build is failed" do
let!(:stage_build) { create_job(:ci_build, status: :failed) }
- it 'returns detailed status for failed stage' do
- expect(subject.text).to eq 'failed'
+ it "returns detailed status for failed stage" do
+ expect(subject.text).to eq "failed"
end
end
- context 'when build is canceled' do
+ context "when build is canceled" do
let!(:stage_build) { create_job(:ci_build, status: :canceled) }
- it 'returns detailed status for canceled stage' do
- expect(subject.text).to eq 'canceled'
+ it "returns detailed status for canceled stage" do
+ expect(subject.text).to eq "canceled"
end
end
- context 'when build is skipped' do
+ context "when build is skipped" do
let!(:stage_build) { create_job(:ci_build, status: :skipped) }
- it 'returns detailed status for skipped stage' do
- expect(subject.text).to eq 'skipped'
+ it "returns detailed status for skipped stage" do
+ expect(subject.text).to eq "skipped"
end
end
end
- describe '#success?' do
- context 'when stage is successful' do
+ describe "#success?" do
+ context "when stage is successful" do
before do
create_job(:ci_build, status: :success)
create_job(:generic_commit_status, status: :success)
end
- it 'is successful' do
+ it "is successful" do
expect(stage).to be_success
end
end
- context 'when stage is not successful' do
+ context "when stage is not successful" do
before do
create_job(:ci_build, status: :failed)
create_job(:generic_commit_status, status: :success)
end
- it 'is not successful' do
+ it "is not successful" do
expect(stage).not_to be_success
end
end
end
- describe '#has_warnings?' do
- context 'when stage has warnings' do
- context 'when using memoized warnings flag' do
- context 'when there are warnings' do
+ describe "#has_warnings?" do
+ context "when stage has warnings" do
+ context "when using memoized warnings flag" do
+ context "when there are warnings" do
let(:stage) { build(:ci_stage, warnings: 2) }
- it 'returns true using memoized value' do
+ it "returns true using memoized value" do
expect(stage).not_to receive(:statuses)
expect(stage).to have_warnings
end
end
- context 'when there are no warnings' do
+ context "when there are no warnings" do
let(:stage) { build(:ci_stage, warnings: 0) }
- it 'returns false using memoized value' do
+ it "returns false using memoized value" do
expect(stage).not_to receive(:statuses)
expect(stage).not_to have_warnings
end
end
- context 'when number of warnings is not a valid value' do
+ context "when number of warnings is not a valid value" do
let(:stage) { build(:ci_stage, warnings: true) }
- it 'calculates statuses using database queries' do
+ it "calculates statuses using database queries" do
expect(stage).to receive(:statuses).and_call_original
expect(stage).not_to have_warnings
end
end
end
- context 'when calculating warnings from statuses' do
+ context "when calculating warnings from statuses" do
before do
create(:ci_build, :failed, :allowed_to_fail,
- stage: stage_name, pipeline: pipeline)
+ stage: stage_name, pipeline: pipeline)
end
- it 'has warnings calculated from statuses' do
+ it "has warnings calculated from statuses" do
expect(stage).to receive(:statuses).and_call_original
expect(stage).to have_warnings
end
end
end
- context 'when stage does not have warnings' do
+ context "when stage does not have warnings" do
before do
create(:ci_build, :success, stage: stage_name,
pipeline: pipeline)
end
- it 'does not have warnings calculated from statuses' do
+ it "does not have warnings calculated from statuses" do
expect(stage).to receive(:statuses).and_call_original
expect(stage).not_to have_warnings
end
end
end
- def create_job(type, status: 'success', stage: stage_name, **opts)
+ def create_job(type, status: "success", stage: stage_name, **opts)
create(type, pipeline: pipeline, stage: stage, status: status, **opts)
end
end
diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb
index 8ee15f0e734..e48c71bd3a8 100644
--- a/spec/models/ci/pipeline_schedule_spec.rb
+++ b/spec/models/ci/pipeline_schedule_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::PipelineSchedule do
it { is_expected.to belong_to(:project) }
@@ -13,21 +13,21 @@ describe Ci::PipelineSchedule do
it { is_expected.to respond_to(:description) }
it { is_expected.to respond_to(:next_run_at) }
- describe 'validations' do
- it 'does not allow invalid cron patters' do
- pipeline_schedule = build(:ci_pipeline_schedule, cron: '0 0 0 * *')
+ describe "validations" do
+ it "does not allow invalid cron patters" do
+ pipeline_schedule = build(:ci_pipeline_schedule, cron: "0 0 0 * *")
expect(pipeline_schedule).not_to be_valid
end
- it 'does not allow invalid cron patters' do
- pipeline_schedule = build(:ci_pipeline_schedule, cron_timezone: 'invalid')
+ it "does not allow invalid cron patters" do
+ pipeline_schedule = build(:ci_pipeline_schedule, cron_timezone: "invalid")
expect(pipeline_schedule).not_to be_valid
end
- context 'when active is false' do
- it 'does not allow nullified ref' do
+ context "when active is false" do
+ it "does not allow nullified ref" do
pipeline_schedule = build(:ci_pipeline_schedule, :inactive, ref: nil)
expect(pipeline_schedule).not_to be_valid
@@ -35,29 +35,29 @@ describe Ci::PipelineSchedule do
end
end
- describe '#set_next_run_at' do
+ describe "#set_next_run_at" do
let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly) }
- context 'when creates new pipeline schedule' do
+ context "when creates new pipeline schedule" do
let(:expected_next_run_at) do
Gitlab::Ci::CronParser.new(pipeline_schedule.cron, pipeline_schedule.cron_timezone)
.next_time_from(Time.now)
end
- it 'updates next_run_at automatically' do
+ it "updates next_run_at automatically" do
expect(described_class.last.next_run_at).to eq(expected_next_run_at)
end
end
- context 'when updates cron of exsisted pipeline schedule' do
- let(:new_cron) { '0 0 1 1 *' }
+ context "when updates cron of exsisted pipeline schedule" do
+ let(:new_cron) { "0 0 1 1 *" }
let(:expected_next_run_at) do
Gitlab::Ci::CronParser.new(new_cron, pipeline_schedule.cron_timezone)
.next_time_from(Time.now)
end
- it 'updates next_run_at automatically' do
+ it "updates next_run_at automatically" do
pipeline_schedule.update!(cron: new_cron)
expect(described_class.last.next_run_at).to eq(expected_next_run_at)
@@ -65,10 +65,10 @@ describe Ci::PipelineSchedule do
end
end
- describe '#schedule_next_run!' do
+ describe "#schedule_next_run!" do
let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly) }
- context 'when reschedules after 10 days from now' do
+ context "when reschedules after 10 days from now" do
let(:future_time) { 10.days.from_now }
let(:expected_next_run_at) do
@@ -76,7 +76,7 @@ describe Ci::PipelineSchedule do
.next_time_from(future_time)
end
- it 'points to proper next_run_at' do
+ it "points to proper next_run_at" do
Timecop.freeze(future_time) do
pipeline_schedule.schedule_next_run!
@@ -86,29 +86,29 @@ describe Ci::PipelineSchedule do
end
end
- describe '#real_next_run' do
+ describe "#real_next_run" do
subject do
described_class.last.real_next_run(worker_cron: worker_cron,
worker_time_zone: worker_time_zone)
end
- context 'when GitLab time_zone is UTC' do
+ context "when GitLab time_zone is UTC" do
before do
allow(Time).to receive(:zone)
.and_return(ActiveSupport::TimeZone[worker_time_zone])
end
- let(:worker_time_zone) { 'UTC' }
+ let(:worker_time_zone) { "UTC" }
- context 'when cron_timezone is Eastern Time (US & Canada)' do
+ context "when cron_timezone is Eastern Time (US & Canada)" do
before do
create(:ci_pipeline_schedule, :nightly,
- cron_timezone: 'Eastern Time (US & Canada)')
+ cron_timezone: "Eastern Time (US & Canada)")
end
- let(:worker_cron) { '0 1 2 3 *' }
+ let(:worker_cron) { "0 1 2 3 *" }
- it 'returns the next time worker executes' do
+ it "returns the next time worker executes" do
expect(subject.min).to eq(0)
expect(subject.hour).to eq(1)
expect(subject.day).to eq(2)
@@ -118,7 +118,7 @@ describe Ci::PipelineSchedule do
end
end
- describe '#job_variables' do
+ describe "#job_variables" do
let!(:pipeline_schedule) { create(:ci_pipeline_schedule) }
let!(:pipeline_schedule_variables) do
diff --git a/spec/models/ci/pipeline_schedule_variable_spec.rb b/spec/models/ci/pipeline_schedule_variable_spec.rb
index dc8427f28bc..dd29b8cb0b7 100644
--- a/spec/models/ci/pipeline_schedule_variable_spec.rb
+++ b/spec/models/ci/pipeline_schedule_variable_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::PipelineScheduleVariable do
subject { build(:ci_pipeline_schedule_variable) }
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index ee400bec04b..7c7b7bb32b2 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::Pipeline, :mailer do
include ProjectForksHelper
@@ -10,7 +10,7 @@ describe Ci::Pipeline, :mailer do
create(:ci_empty_pipeline, status: :created, project: project)
end
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:user) }
@@ -34,29 +34,29 @@ describe Ci::Pipeline, :mailer do
it { is_expected.to respond_to :short_sha }
it { is_expected.to delegate_method(:full_path).to(:project).with_prefix }
- describe 'associations' do
- it 'has a bidirectional relationship with projects' do
+ describe "associations" do
+ it "has a bidirectional relationship with projects" do
expect(described_class.reflect_on_association(:project).has_inverse?).to eq(:all_pipelines)
expect(Project.reflect_on_association(:all_pipelines).has_inverse?).to eq(:project)
expect(Project.reflect_on_association(:ci_pipelines).has_inverse?).to eq(:project)
end
end
- describe '.processables' do
+ describe ".processables" do
before do
- create(:ci_build, name: 'build', pipeline: pipeline)
- create(:ci_bridge, name: 'bridge', pipeline: pipeline)
- create(:commit_status, name: 'commit status', pipeline: pipeline)
- create(:generic_commit_status, name: 'generic status', pipeline: pipeline)
+ create(:ci_build, name: "build", pipeline: pipeline)
+ create(:ci_bridge, name: "bridge", pipeline: pipeline)
+ create(:commit_status, name: "commit status", pipeline: pipeline)
+ create(:generic_commit_status, name: "generic status", pipeline: pipeline)
end
- it 'has an association with processable CI/CD entities' do
- pipeline.processables.pluck('name').yield_self do |processables|
+ it "has an association with processable CI/CD entities" do
+ pipeline.processables.pluck("name").yield_self do |processables|
expect(processables).to match_array %w[build bridge]
end
end
- it 'makes it possible to append a new processable' do
+ it "makes it possible to append a new processable" do
pipeline.processables << build(:ci_bridge)
pipeline.save!
@@ -65,20 +65,20 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '.sort_by_merge_request_pipelines' do
+ describe ".sort_by_merge_request_pipelines" do
subject { described_class.sort_by_merge_request_pipelines }
- context 'when branch pipelines exist' do
+ context "when branch pipelines exist" do
let!(:branch_pipeline_1) { create(:ci_pipeline, source: :push) }
let!(:branch_pipeline_2) { create(:ci_pipeline, source: :push) }
- it 'returns pipelines order by id' do
+ it "returns pipelines order by id" do
expect(subject).to eq([branch_pipeline_2,
- branch_pipeline_1])
+ branch_pipeline_1,])
end
end
- context 'when merge request pipelines exist' do
+ context "when merge request pipelines exist" do
let!(:merge_request_pipeline_1) do
create(:ci_pipeline, source: :merge_request, merge_request: merge_request)
end
@@ -89,19 +89,19 @@ describe Ci::Pipeline, :mailer do
let(:merge_request) do
create(:merge_request,
- source_project: project,
- source_branch: 'feature',
- target_project: project,
- target_branch: 'master')
+ source_project: project,
+ source_branch: "feature",
+ target_project: project,
+ target_branch: "master")
end
- it 'returns pipelines order by id' do
+ it "returns pipelines order by id" do
expect(subject).to eq([merge_request_pipeline_2,
- merge_request_pipeline_1])
+ merge_request_pipeline_1,])
end
end
- context 'when both branch pipeline and merge request pipeline exist' do
+ context "when both branch pipeline and merge request pipeline exist" do
let!(:branch_pipeline_1) { create(:ci_pipeline, source: :push) }
let!(:branch_pipeline_2) { create(:ci_pipeline, source: :push) }
@@ -115,22 +115,22 @@ describe Ci::Pipeline, :mailer do
let(:merge_request) do
create(:merge_request,
- source_project: project,
- source_branch: 'feature',
- target_project: project,
- target_branch: 'master')
+ source_project: project,
+ source_branch: "feature",
+ target_project: project,
+ target_branch: "master")
end
- it 'returns merge request pipeline first' do
+ it "returns merge request pipeline first" do
expect(subject).to eq([merge_request_pipeline_2,
merge_request_pipeline_1,
branch_pipeline_2,
- branch_pipeline_1])
+ branch_pipeline_1,])
end
end
end
- describe '.detached_merge_request_pipelines' do
+ describe ".detached_merge_request_pipelines" do
subject { described_class.detached_merge_request_pipelines(merge_request) }
let!(:pipeline) do
@@ -140,20 +140,20 @@ describe Ci::Pipeline, :mailer do
let(:merge_request) { create(:merge_request) }
let(:target_sha) { nil }
- it 'returns detached merge request pipelines' do
+ it "returns detached merge request pipelines" do
is_expected.to eq([pipeline])
end
- context 'when target sha exists' do
+ context "when target sha exists" do
let(:target_sha) { merge_request.target_branch_sha }
- it 'returns empty array' do
+ it "returns empty array" do
is_expected.to be_empty
end
end
end
- describe '#detached_merge_request_pipeline?' do
+ describe "#detached_merge_request_pipeline?" do
subject { pipeline.detached_merge_request_pipeline? }
let!(:pipeline) do
@@ -165,14 +165,14 @@ describe Ci::Pipeline, :mailer do
it { is_expected.to be_truthy }
- context 'when target sha exists' do
+ context "when target sha exists" do
let(:target_sha) { merge_request.target_branch_sha }
it { is_expected.to be_falsy }
end
end
- describe '.merge_request_pipelines' do
+ describe ".merge_request_pipelines" do
subject { described_class.merge_request_pipelines(merge_request) }
let!(:pipeline) do
@@ -182,20 +182,20 @@ describe Ci::Pipeline, :mailer do
let(:merge_request) { create(:merge_request) }
let(:target_sha) { merge_request.target_branch_sha }
- it 'returns merge pipelines' do
+ it "returns merge pipelines" do
is_expected.to eq([pipeline])
end
- context 'when target sha is empty' do
+ context "when target sha is empty" do
let(:target_sha) { nil }
- it 'returns empty array' do
+ it "returns empty array" do
is_expected.to be_empty
end
end
end
- describe '#merge_request_pipeline?' do
+ describe "#merge_request_pipeline?" do
subject { pipeline.merge_request_pipeline? }
let!(:pipeline) do
@@ -207,14 +207,14 @@ describe Ci::Pipeline, :mailer do
it { is_expected.to be_truthy }
- context 'when target sha is empty' do
+ context "when target sha is empty" do
let(:target_sha) { nil }
it { is_expected.to be_falsy }
end
end
- describe '.mergeable_merge_request_pipelines' do
+ describe ".mergeable_merge_request_pipelines" do
subject { described_class.mergeable_merge_request_pipelines(merge_request) }
let!(:pipeline) do
@@ -224,20 +224,20 @@ describe Ci::Pipeline, :mailer do
let(:merge_request) { create(:merge_request) }
let(:target_sha) { merge_request.target_branch_sha }
- it 'returns mergeable merge pipelines' do
+ it "returns mergeable merge pipelines" do
is_expected.to eq([pipeline])
end
- context 'when target sha does not point the head of the target branch' do
+ context "when target sha does not point the head of the target branch" do
let(:target_sha) { merge_request.diff_head_sha }
- it 'returns empty array' do
+ it "returns empty array" do
is_expected.to be_empty
end
end
end
- describe '#mergeable_merge_request_pipeline?' do
+ describe "#mergeable_merge_request_pipeline?" do
subject { pipeline.mergeable_merge_request_pipeline? }
let!(:pipeline) do
@@ -249,63 +249,63 @@ describe Ci::Pipeline, :mailer do
it { is_expected.to be_truthy }
- context 'when target sha does not point the head of the target branch' do
+ context "when target sha does not point the head of the target branch" do
let(:target_sha) { merge_request.diff_head_sha }
it { is_expected.to be_falsy }
end
end
- describe '.merge_request' do
+ describe ".merge_request" do
subject { described_class.merge_request }
- context 'when there is a merge request pipeline' do
+ context "when there is a merge request pipeline" do
let!(:pipeline) { create(:ci_pipeline, source: :merge_request, merge_request: merge_request) }
let(:merge_request) { create(:merge_request) }
- it 'returns merge request pipeline first' do
+ it "returns merge request pipeline first" do
expect(subject).to eq([pipeline])
end
end
- context 'when there are no merge request pipelines' do
+ context "when there are no merge request pipelines" do
let!(:pipeline) { create(:ci_pipeline, source: :push) }
- it 'returns empty array' do
+ it "returns empty array" do
expect(subject).to be_empty
end
end
end
- describe 'Validations for merge request pipelines' do
+ describe "Validations for merge request pipelines" do
let(:pipeline) { build(:ci_pipeline, source: source, merge_request: merge_request) }
- context 'when source is merge request' do
+ context "when source is merge request" do
let(:source) { :merge_request }
- context 'when merge request is specified' do
- let(:merge_request) { create(:merge_request, source_project: project, source_branch: 'feature', target_project: project, target_branch: 'master') }
+ context "when merge request is specified" do
+ let(:merge_request) { create(:merge_request, source_project: project, source_branch: "feature", target_project: project, target_branch: "master") }
it { expect(pipeline).to be_valid }
end
- context 'when merge request is empty' do
+ context "when merge request is empty" do
let(:merge_request) { nil }
it { expect(pipeline).not_to be_valid }
end
end
- context 'when source is web' do
+ context "when source is web" do
let(:source) { :web }
- context 'when merge request is specified' do
- let(:merge_request) { create(:merge_request, source_project: project, source_branch: 'feature', target_project: project, target_branch: 'master') }
+ context "when merge request is specified" do
+ let(:merge_request) { create(:merge_request, source_project: project, source_branch: "feature", target_project: project, target_branch: "master") }
it { expect(pipeline).not_to be_valid }
end
- context 'when merge request is empty' do
+ context "when merge request is empty" do
let(:merge_request) { nil }
it { expect(pipeline).to be_valid }
@@ -313,18 +313,18 @@ describe Ci::Pipeline, :mailer do
end
end
- describe 'modules' do
- it_behaves_like 'AtomicInternalId', validate_presence: false do
+ describe "modules" do
+ it_behaves_like "AtomicInternalId", validate_presence: false do
let(:internal_id_attribute) { :iid }
let(:instance) { build(:ci_pipeline) }
let(:scope) { :project }
- let(:scope_attrs) { { project: instance.project } }
+ let(:scope_attrs) { {project: instance.project} }
let(:usage) { :ci_pipelines }
end
end
- describe '#source' do
- context 'when creating new pipeline' do
+ describe "#source" do
+ context "when creating new pipeline" do
let(:pipeline) do
build(:ci_empty_pipeline, status: :created, project: project, source: nil)
end
@@ -334,7 +334,7 @@ describe Ci::Pipeline, :mailer do
end
end
- context 'when updating existing pipeline' do
+ context "when updating existing pipeline" do
before do
pipeline.update_attribute(:source, nil)
end
@@ -345,55 +345,55 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#block' do
- it 'changes pipeline status to manual' do
+ describe "#block" do
+ it "changes pipeline status to manual" do
expect(pipeline.block).to be true
expect(pipeline.reload).to be_manual
expect(pipeline.reload).to be_blocked
end
end
- describe '#delay' do
+ describe "#delay" do
subject { pipeline.delay }
let(:pipeline) { build(:ci_pipeline, status: :created) }
- it 'changes pipeline status to schedule' do
+ it "changes pipeline status to schedule" do
subject
expect(pipeline).to be_scheduled
end
end
- describe '#valid_commit_sha' do
- context 'commit.sha can not start with 00000000' do
+ describe "#valid_commit_sha" do
+ context "commit.sha can not start with 00000000" do
before do
- pipeline.sha = '0' * 40
+ pipeline.sha = "0" * 40
pipeline.valid_commit_sha
end
- it('commit errors should not be empty') { expect(pipeline.errors).not_to be_empty }
+ it("commit errors should not be empty") { expect(pipeline.errors).not_to be_empty }
end
end
- describe '#short_sha' do
+ describe "#short_sha" do
subject { pipeline.short_sha }
- it 'has 8 items' do
+ it "has 8 items" do
expect(subject.size).to eq(8)
end
it { expect(pipeline.sha).to start_with(subject) }
end
- describe '#retried' do
+ describe "#retried" do
subject { pipeline.retried }
before do
- @build1 = create(:ci_build, pipeline: pipeline, name: 'deploy', retried: true)
- @build2 = create(:ci_build, pipeline: pipeline, name: 'deploy')
+ @build1 = create(:ci_build, pipeline: pipeline, name: "deploy", retried: true)
+ @build2 = create(:ci_build, pipeline: pipeline, name: "deploy")
end
- it 'returns old builds' do
+ it "returns old builds" do
is_expected.to contain_exactly(@build1)
end
end
@@ -428,36 +428,36 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#retryable?' do
+ describe "#retryable?" do
subject { pipeline.retryable? }
- context 'no failed builds' do
+ context "no failed builds" do
before do
- create_build('rspec', 'success')
+ create_build("rspec", "success")
end
- it 'is not retryable' do
+ it "is not retryable" do
is_expected.to be_falsey
end
- context 'one canceled job' do
+ context "one canceled job" do
before do
- create_build('rubocop', 'canceled')
+ create_build("rubocop", "canceled")
end
- it 'is retryable' do
+ it "is retryable" do
is_expected.to be_truthy
end
end
end
- context 'with failed builds' do
+ context "with failed builds" do
before do
- create_build('rspec', 'running')
- create_build('rubocop', 'failed')
+ create_build("rspec", "running")
+ create_build("rubocop", "failed")
end
- it 'is retryable' do
+ it "is retryable" do
is_expected.to be_truthy
end
end
@@ -467,21 +467,21 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#persisted_variables' do
- context 'when pipeline is not persisted yet' do
+ describe "#persisted_variables" do
+ context "when pipeline is not persisted yet" do
subject { build(:ci_pipeline).persisted_variables }
- it 'does not contain some variables' do
+ it "does not contain some variables" do
keys = subject.map { |variable| variable[:key] }
- expect(keys).not_to include 'CI_PIPELINE_ID'
+ expect(keys).not_to include "CI_PIPELINE_ID"
end
end
- context 'when pipeline is persisted' do
+ context "when pipeline is persisted" do
subject { build_stubbed(:ci_pipeline).persisted_variables }
- it 'does contains persisted variables' do
+ it "does contains persisted variables" do
keys = subject.map { |variable| variable[:key] }
expect(keys).to eq %w[CI_PIPELINE_ID CI_PIPELINE_URL]
@@ -489,10 +489,10 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#predefined_variables' do
+ describe "#predefined_variables" do
subject { pipeline.predefined_variables }
- it 'includes all predefined variables in a valid order' do
+ it "includes all predefined variables in a valid order" do
keys = subject.map { |variable| variable[:key] }
expect(keys).to eq %w[CI_PIPELINE_IID
@@ -503,336 +503,338 @@ describe Ci::Pipeline, :mailer do
CI_COMMIT_DESCRIPTION]
end
- context 'when source is merge request' do
+ context "when source is merge request" do
let(:pipeline) do
create(:ci_pipeline, source: :merge_request, merge_request: merge_request)
end
let(:merge_request) do
create(:merge_request,
- source_project: project,
- source_branch: 'feature',
- target_project: project,
- target_branch: 'master')
+ source_project: project,
+ source_branch: "feature",
+ target_project: project,
+ target_branch: "master")
end
- it 'exposes merge request pipeline variables' do
+ it "exposes merge request pipeline variables" do
expect(subject.to_hash)
.to include(
- 'CI_MERGE_REQUEST_ID' => merge_request.id.to_s,
- 'CI_MERGE_REQUEST_IID' => merge_request.iid.to_s,
- 'CI_MERGE_REQUEST_REF_PATH' => merge_request.ref_path.to_s,
- 'CI_MERGE_REQUEST_PROJECT_ID' => merge_request.project.id.to_s,
- 'CI_MERGE_REQUEST_PROJECT_PATH' => merge_request.project.full_path,
- 'CI_MERGE_REQUEST_PROJECT_URL' => merge_request.project.web_url,
- 'CI_MERGE_REQUEST_TARGET_BRANCH_NAME' => merge_request.target_branch.to_s,
- 'CI_MERGE_REQUEST_TARGET_BRANCH_SHA' => pipeline.target_sha.to_s,
- 'CI_MERGE_REQUEST_SOURCE_PROJECT_ID' => merge_request.source_project.id.to_s,
- 'CI_MERGE_REQUEST_SOURCE_PROJECT_PATH' => merge_request.source_project.full_path,
- 'CI_MERGE_REQUEST_SOURCE_PROJECT_URL' => merge_request.source_project.web_url,
- 'CI_MERGE_REQUEST_SOURCE_BRANCH_NAME' => merge_request.source_branch.to_s,
- 'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA' => pipeline.source_sha.to_s)
- end
-
- context 'when source project does not exist' do
+ "CI_MERGE_REQUEST_ID" => merge_request.id.to_s,
+ "CI_MERGE_REQUEST_IID" => merge_request.iid.to_s,
+ "CI_MERGE_REQUEST_REF_PATH" => merge_request.ref_path.to_s,
+ "CI_MERGE_REQUEST_PROJECT_ID" => merge_request.project.id.to_s,
+ "CI_MERGE_REQUEST_PROJECT_PATH" => merge_request.project.full_path,
+ "CI_MERGE_REQUEST_PROJECT_URL" => merge_request.project.web_url,
+ "CI_MERGE_REQUEST_TARGET_BRANCH_NAME" => merge_request.target_branch.to_s,
+ "CI_MERGE_REQUEST_TARGET_BRANCH_SHA" => pipeline.target_sha.to_s,
+ "CI_MERGE_REQUEST_SOURCE_PROJECT_ID" => merge_request.source_project.id.to_s,
+ "CI_MERGE_REQUEST_SOURCE_PROJECT_PATH" => merge_request.source_project.full_path,
+ "CI_MERGE_REQUEST_SOURCE_PROJECT_URL" => merge_request.source_project.web_url,
+ "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" => merge_request.source_branch.to_s,
+ "CI_MERGE_REQUEST_SOURCE_BRANCH_SHA" => pipeline.source_sha.to_s
+ )
+ end
+
+ context "when source project does not exist" do
before do
merge_request.update_column(:source_project_id, nil)
end
- it 'does not expose source project related variables' do
+ it "does not expose source project related variables" do
expect(subject.to_hash.keys).not_to include(
%w[CI_MERGE_REQUEST_SOURCE_PROJECT_ID
CI_MERGE_REQUEST_SOURCE_PROJECT_PATH
CI_MERGE_REQUEST_SOURCE_PROJECT_URL
- CI_MERGE_REQUEST_SOURCE_BRANCH_NAME])
+ CI_MERGE_REQUEST_SOURCE_BRANCH_NAME]
+ )
end
end
end
end
- describe '#protected_ref?' do
+ describe "#protected_ref?" do
before do
pipeline.project = create(:project, :repository)
end
- it 'delegates method to project' do
+ it "delegates method to project" do
expect(pipeline).not_to be_protected_ref
end
end
- describe '#legacy_trigger' do
+ describe "#legacy_trigger" do
let(:trigger_request) { create(:ci_trigger_request) }
before do
pipeline.trigger_requests << trigger_request
end
- it 'returns first trigger request' do
+ it "returns first trigger request" do
expect(pipeline.legacy_trigger).to eq trigger_request
end
end
- describe '#auto_canceled?' do
+ describe "#auto_canceled?" do
subject { pipeline.auto_canceled? }
- context 'when it is canceled' do
+ context "when it is canceled" do
before do
pipeline.cancel
end
- context 'when there is auto_canceled_by' do
+ context "when there is auto_canceled_by" do
before do
pipeline.update(auto_canceled_by: create(:ci_empty_pipeline))
end
- it 'is auto canceled' do
+ it "is auto canceled" do
is_expected.to be_truthy
end
end
- context 'when there is no auto_canceled_by' do
- it 'is not auto canceled' do
+ context "when there is no auto_canceled_by" do
+ it "is not auto canceled" do
is_expected.to be_falsey
end
end
- context 'when it is retried and canceled manually' do
+ context "when it is retried and canceled manually" do
before do
pipeline.enqueue
pipeline.cancel
end
- it 'is not auto canceled' do
+ it "is not auto canceled" do
is_expected.to be_falsey
end
end
end
end
- describe 'pipeline stages' do
- describe '#stage_seeds' do
+ describe "pipeline stages" do
+ describe "#stage_seeds" do
let(:pipeline) { build(:ci_pipeline, config: config) }
- let(:config) { { rspec: { script: 'rake' } } }
+ let(:config) { {rspec: {script: "rake"}} }
- it 'returns preseeded stage seeds object' do
+ it "returns preseeded stage seeds object" do
expect(pipeline.stage_seeds)
.to all(be_a Gitlab::Ci::Pipeline::Seed::Base)
expect(pipeline.stage_seeds.count).to eq 1
end
- context 'when no refs policy is specified' do
+ context "when no refs policy is specified" do
let(:config) do
- { production: { stage: 'deploy', script: 'cap prod' },
- rspec: { stage: 'test', script: 'rspec' },
- spinach: { stage: 'test', script: 'spinach' } }
+ {production: {stage: "deploy", script: "cap prod"},
+ rspec: {stage: "test", script: "rspec"},
+ spinach: {stage: "test", script: "spinach"},}
end
- it 'correctly fabricates a stage seeds object' do
+ it "correctly fabricates a stage seeds object" do
seeds = pipeline.stage_seeds
expect(seeds.size).to eq 2
- expect(seeds.first.attributes[:name]).to eq 'test'
- expect(seeds.second.attributes[:name]).to eq 'deploy'
- expect(seeds.dig(0, 0, :name)).to eq 'rspec'
- expect(seeds.dig(0, 1, :name)).to eq 'spinach'
- expect(seeds.dig(1, 0, :name)).to eq 'production'
+ expect(seeds.first.attributes[:name]).to eq "test"
+ expect(seeds.second.attributes[:name]).to eq "deploy"
+ expect(seeds.dig(0, 0, :name)).to eq "rspec"
+ expect(seeds.dig(0, 1, :name)).to eq "spinach"
+ expect(seeds.dig(1, 0, :name)).to eq "production"
end
end
- context 'when refs policy is specified' do
+ context "when refs policy is specified" do
let(:pipeline) do
- build(:ci_pipeline, ref: 'feature', tag: true, config: config)
+ build(:ci_pipeline, ref: "feature", tag: true, config: config)
end
let(:config) do
- { production: { stage: 'deploy', script: 'cap prod', only: ['master'] },
- spinach: { stage: 'test', script: 'spinach', only: ['tags'] } }
+ {production: {stage: "deploy", script: "cap prod", only: ["master"]},
+ spinach: {stage: "test", script: "spinach", only: ["tags"]},}
end
- it 'returns stage seeds only assigned to master to master' do
+ it "returns stage seeds only assigned to master to master" do
seeds = pipeline.stage_seeds
expect(seeds.size).to eq 1
- expect(seeds.first.attributes[:name]).to eq 'test'
- expect(seeds.dig(0, 0, :name)).to eq 'spinach'
+ expect(seeds.first.attributes[:name]).to eq "test"
+ expect(seeds.dig(0, 0, :name)).to eq "spinach"
end
end
- context 'when source policy is specified' do
+ context "when source policy is specified" do
let(:pipeline) { build(:ci_pipeline, source: :schedule, config: config) }
let(:config) do
- { production: { stage: 'deploy', script: 'cap prod', only: ['triggers'] },
- spinach: { stage: 'test', script: 'spinach', only: ['schedules'] } }
+ {production: {stage: "deploy", script: "cap prod", only: ["triggers"]},
+ spinach: {stage: "test", script: "spinach", only: ["schedules"]},}
end
- it 'returns stage seeds only assigned to schedules' do
+ it "returns stage seeds only assigned to schedules" do
seeds = pipeline.stage_seeds
expect(seeds.size).to eq 1
- expect(seeds.first.attributes[:name]).to eq 'test'
- expect(seeds.dig(0, 0, :name)).to eq 'spinach'
+ expect(seeds.first.attributes[:name]).to eq "test"
+ expect(seeds.dig(0, 0, :name)).to eq "spinach"
end
end
- context 'when kubernetes policy is specified' do
+ context "when kubernetes policy is specified" do
let(:config) do
{
- spinach: { stage: 'test', script: 'spinach' },
+ spinach: {stage: "test", script: "spinach"},
production: {
- stage: 'deploy',
- script: 'cap',
- only: { kubernetes: 'active' }
- }
+ stage: "deploy",
+ script: "cap",
+ only: {kubernetes: "active"},
+ },
}
end
- context 'when kubernetes is active' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
- it 'returns seeds for kubernetes dependent job' do
+ context "when kubernetes is active" do
+ shared_examples "same behavior between KubernetesService and Platform::Kubernetes" do
+ it "returns seeds for kubernetes dependent job" do
seeds = pipeline.stage_seeds
expect(seeds.size).to eq 2
- expect(seeds.dig(0, 0, :name)).to eq 'spinach'
- expect(seeds.dig(1, 0, :name)).to eq 'production'
+ expect(seeds.dig(0, 0, :name)).to eq "spinach"
+ expect(seeds.dig(1, 0, :name)).to eq "production"
end
end
- context 'when user configured kubernetes from Integration > Kubernetes' do
+ context "when user configured kubernetes from Integration > Kubernetes" do
let(:project) { create(:kubernetes_project) }
let(:pipeline) { build(:ci_pipeline, project: project, config: config) }
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
+ it_behaves_like "same behavior between KubernetesService and Platform::Kubernetes"
end
- context 'when user configured kubernetes from CI/CD > Clusters' do
+ context "when user configured kubernetes from CI/CD > Clusters" do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
let(:pipeline) { build(:ci_pipeline, project: project, config: config) }
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
+ it_behaves_like "same behavior between KubernetesService and Platform::Kubernetes"
end
end
- context 'when kubernetes is not active' do
- it 'does not return seeds for kubernetes dependent job' do
+ context "when kubernetes is not active" do
+ it "does not return seeds for kubernetes dependent job" do
seeds = pipeline.stage_seeds
expect(seeds.size).to eq 1
- expect(seeds.dig(0, 0, :name)).to eq 'spinach'
+ expect(seeds.dig(0, 0, :name)).to eq "spinach"
end
end
end
- context 'when variables policy is specified' do
+ context "when variables policy is specified" do
let(:config) do
- { unit: { script: 'minitest', only: { variables: ['$CI_PIPELINE_SOURCE'] } },
- feature: { script: 'spinach', only: { variables: ['$UNDEFINED'] } } }
+ {unit: {script: "minitest", only: {variables: ["$CI_PIPELINE_SOURCE"]}},
+ feature: {script: "spinach", only: {variables: ["$UNDEFINED"]}},}
end
- it 'returns stage seeds only when variables expression is truthy' do
+ it "returns stage seeds only when variables expression is truthy" do
seeds = pipeline.stage_seeds
expect(seeds.size).to eq 1
- expect(seeds.dig(0, 0, :name)).to eq 'unit'
+ expect(seeds.dig(0, 0, :name)).to eq "unit"
end
end
end
- describe '#seeds_size' do
- context 'when refs policy is specified' do
+ describe "#seeds_size" do
+ context "when refs policy is specified" do
let(:config) do
- { production: { stage: 'deploy', script: 'cap prod', only: ['master'] },
- spinach: { stage: 'test', script: 'spinach', only: ['tags'] } }
+ {production: {stage: "deploy", script: "cap prod", only: ["master"]},
+ spinach: {stage: "test", script: "spinach", only: ["tags"]},}
end
let(:pipeline) do
- build(:ci_pipeline, ref: 'feature', tag: true, config: config)
+ build(:ci_pipeline, ref: "feature", tag: true, config: config)
end
- it 'returns real seeds size' do
+ it "returns real seeds size" do
expect(pipeline.seeds_size).to eq 1
end
end
end
- describe 'legacy stages' do
+ describe "legacy stages" do
before do
create(:commit_status, pipeline: pipeline,
- stage: 'build',
- name: 'linux',
+ stage: "build",
+ name: "linux",
stage_idx: 0,
- status: 'success')
+ status: "success")
create(:commit_status, pipeline: pipeline,
- stage: 'build',
- name: 'mac',
+ stage: "build",
+ name: "mac",
stage_idx: 0,
- status: 'failed')
+ status: "failed")
create(:commit_status, pipeline: pipeline,
- stage: 'deploy',
- name: 'staging',
+ stage: "deploy",
+ name: "staging",
stage_idx: 2,
- status: 'running')
+ status: "running")
create(:commit_status, pipeline: pipeline,
- stage: 'test',
- name: 'rspec',
+ stage: "test",
+ name: "rspec",
stage_idx: 1,
- status: 'success')
+ status: "success")
end
- describe '#legacy_stages' do
+ describe "#legacy_stages" do
subject { pipeline.legacy_stages }
- context 'stages list' do
- it 'returns ordered list of stages' do
+ context "stages list" do
+ it "returns ordered list of stages" do
expect(subject.map(&:name)).to eq(%w[build test deploy])
end
end
- context 'stages with statuses' do
+ context "stages with statuses" do
let(:statuses) do
subject.map { |stage| [stage.name, stage.status] }
end
- it 'returns list of stages with correct statuses' do
- expect(statuses).to eq([%w(build failed),
- %w(test success),
- %w(deploy running)])
+ it "returns list of stages with correct statuses" do
+ expect(statuses).to eq([%w[build failed],
+ %w[test success],
+ %w[deploy running],])
end
- context 'when commit status is retried' do
+ context "when commit status is retried" do
before do
create(:commit_status, pipeline: pipeline,
- stage: 'build',
- name: 'mac',
+ stage: "build",
+ name: "mac",
stage_idx: 0,
- status: 'success')
+ status: "success")
pipeline.process!
end
- it 'ignores the previous state' do
- expect(statuses).to eq([%w(build success),
- %w(test success),
- %w(deploy running)])
+ it "ignores the previous state" do
+ expect(statuses).to eq([%w[build success],
+ %w[test success],
+ %w[deploy running],])
end
end
end
- context 'when there is a stage with warnings' do
+ context "when there is a stage with warnings" do
before do
create(:commit_status, pipeline: pipeline,
- stage: 'deploy',
- name: 'prod:2',
+ stage: "deploy",
+ name: "prod:2",
stage_idx: 2,
- status: 'failed',
+ status: "failed",
allow_failure: true)
end
- it 'populates stage with correct number of warnings' do
+ it "populates stage with correct number of warnings" do
deploy_stage = pipeline.legacy_stages.third
expect(deploy_stage).not_to receive(:statuses)
@@ -841,116 +843,116 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#stages_count' do
- it 'returns a valid number of stages' do
+ describe "#stages_count" do
+ it "returns a valid number of stages" do
expect(pipeline.stages_count).to eq(3)
end
end
- describe '#stages_names' do
- it 'returns a valid names of stages' do
- expect(pipeline.stages_names).to eq(%w(build test deploy))
+ describe "#stages_names" do
+ it "returns a valid names of stages" do
+ expect(pipeline.stages_names).to eq(%w[build test deploy])
end
end
end
- describe '#legacy_stage' do
- subject { pipeline.legacy_stage('test') }
+ describe "#legacy_stage" do
+ subject { pipeline.legacy_stage("test") }
- context 'with status in stage' do
+ context "with status in stage" do
before do
- create(:commit_status, pipeline: pipeline, stage: 'test')
+ create(:commit_status, pipeline: pipeline, stage: "test")
end
it { expect(subject).to be_a Ci::LegacyStage }
- it { expect(subject.name).to eq 'test' }
+ it { expect(subject.name).to eq "test" }
it { expect(subject.statuses).not_to be_empty }
end
- context 'without status in stage' do
+ context "without status in stage" do
before do
- create(:commit_status, pipeline: pipeline, stage: 'build')
+ create(:commit_status, pipeline: pipeline, stage: "build")
end
- it 'return stage object' do
+ it "return stage object" do
is_expected.to be_nil
end
end
end
- describe '#stages' do
+ describe "#stages" do
before do
create(:ci_stage_entity, project: project,
pipeline: pipeline,
- name: 'build')
+ name: "build")
end
- it 'returns persisted stages' do
+ it "returns persisted stages" do
expect(pipeline.stages).not_to be_empty
expect(pipeline.stages).to all(be_persisted)
end
end
- describe '#ordered_stages' do
+ describe "#ordered_stages" do
before do
create(:ci_stage_entity, project: project,
pipeline: pipeline,
position: 4,
- name: 'deploy')
+ name: "deploy")
create(:ci_build, project: project,
pipeline: pipeline,
- stage: 'test',
+ stage: "test",
stage_idx: 3,
- name: 'test')
+ name: "test")
create(:ci_build, project: project,
pipeline: pipeline,
- stage: 'build',
+ stage: "build",
stage_idx: 2,
- name: 'build')
+ name: "build")
create(:ci_stage_entity, project: project,
pipeline: pipeline,
position: 1,
- name: 'sanity')
+ name: "sanity")
create(:ci_stage_entity, project: project,
pipeline: pipeline,
position: 5,
- name: 'cleanup')
+ name: "cleanup")
end
subject { pipeline.ordered_stages }
- context 'when using legacy stages' do
+ context "when using legacy stages" do
before do
stub_feature_flags(ci_pipeline_persisted_stages: false)
end
- it 'returns legacy stages in valid order' do
+ it "returns legacy stages in valid order" do
expect(subject.map(&:name)).to eq %w[build test]
end
end
- context 'when using persisted stages' do
+ context "when using persisted stages" do
before do
stub_feature_flags(ci_pipeline_persisted_stages: true)
end
- context 'when pipelines is not complete' do
- it 'still returns legacy stages' do
+ context "when pipelines is not complete" do
+ it "still returns legacy stages" do
expect(subject).to all(be_a Ci::LegacyStage)
expect(subject.map(&:name)).to eq %w[build test]
end
end
- context 'when pipeline is complete' do
+ context "when pipeline is complete" do
before do
pipeline.succeed!
end
- it 'returns stages in valid order' do
+ it "returns stages in valid order" do
expect(subject).to all(be_a Ci::Stage)
expect(subject.map(&:name))
.to eq %w[sanity build test deploy cleanup]
@@ -960,14 +962,14 @@ describe Ci::Pipeline, :mailer do
end
end
- describe 'state machine' do
+ describe "state machine" do
let(:current) { Time.now.change(usec: 0) }
- let(:build) { create_build('build1', queued_at: 0) }
- let(:build_b) { create_build('build2', queued_at: 0) }
- let(:build_c) { create_build('build3', queued_at: 0) }
+ let(:build) { create_build("build1", queued_at: 0) }
+ let(:build_b) { create_build("build2", queued_at: 0) }
+ let(:build_c) { create_build("build3", queued_at: 0) }
- describe '#duration' do
- context 'when multiple builds are finished' do
+ describe "#duration" do
+ context "when multiple builds are finished" do
before do
travel_to(current + 30) do
build.run!
@@ -985,16 +987,16 @@ describe Ci::Pipeline, :mailer do
end
end
- it 'matches sum of builds duration' do
+ it "matches sum of builds duration" do
pipeline.reload
expect(pipeline.duration).to eq(40)
end
end
- context 'when pipeline becomes blocked' do
- let!(:build) { create_build('build:1') }
- let!(:action) { create_build('manual:action', :manual) }
+ context "when pipeline becomes blocked" do
+ let!(:build) { create_build("build:1") }
+ let!(:action) { create_build("manual:action", :manual) }
before do
travel_to(current + 1.minute) do
@@ -1006,7 +1008,7 @@ describe Ci::Pipeline, :mailer do
end
end
- it 'recalculates pipeline duration' do
+ it "recalculates pipeline duration" do
pipeline.reload
expect(pipeline).to be_manual
@@ -1015,58 +1017,58 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#started_at' do
- it 'updates on transitioning to running' do
+ describe "#started_at" do
+ it "updates on transitioning to running" do
build.run
expect(pipeline.reload.started_at).not_to be_nil
end
- it 'does not update on transitioning to success' do
+ it "does not update on transitioning to success" do
build.success
expect(pipeline.reload.started_at).to be_nil
end
end
- describe '#finished_at' do
- it 'updates on transitioning to success' do
+ describe "#finished_at" do
+ it "updates on transitioning to success" do
build.success
expect(pipeline.reload.finished_at).not_to be_nil
end
- it 'does not update on transitioning to running' do
+ it "does not update on transitioning to running" do
build.run
expect(pipeline.reload.finished_at).to be_nil
end
end
- describe 'merge request metrics' do
+ describe "merge request metrics" do
let(:project) { create(:project, :repository) }
- let(:pipeline) { FactoryBot.create(:ci_empty_pipeline, status: 'created', project: project, ref: 'master', sha: project.repository.commit('master').id) }
+ let(:pipeline) { FactoryBot.create(:ci_empty_pipeline, status: "created", project: project, ref: "master", sha: project.repository.commit("master").id) }
let!(:merge_request) { create(:merge_request, source_project: project, source_branch: pipeline.ref) }
before do
expect(PipelineMetricsWorker).to receive(:perform_async).with(pipeline.id)
end
- context 'when transitioning to running' do
- it 'schedules metrics workers' do
+ context "when transitioning to running" do
+ it "schedules metrics workers" do
pipeline.run
end
end
- context 'when transitioning to success' do
- it 'schedules metrics workers' do
+ context "when transitioning to success" do
+ it "schedules metrics workers" do
pipeline.succeed
end
end
end
- describe 'pipeline caching' do
- it 'performs ExpirePipelinesCacheWorker' do
+ describe "pipeline caching" do
+ it "performs ExpirePipelinesCacheWorker" do
expect(ExpirePipelineCacheWorker).to receive(:perform_async).with(pipeline.id)
pipeline.cancel
@@ -1075,107 +1077,107 @@ describe Ci::Pipeline, :mailer do
def create_build(name, *traits, queued_at: current, started_from: 0, **opts)
create(:ci_build, *traits,
- name: name,
- pipeline: pipeline,
- queued_at: queued_at,
- started_at: queued_at + started_from,
- **opts)
+ name: name,
+ pipeline: pipeline,
+ queued_at: queued_at,
+ started_at: queued_at + started_from,
+ **opts)
end
end
- describe '#branch?' do
+ describe "#branch?" do
subject { pipeline.branch? }
- context 'when ref is not a tag' do
+ context "when ref is not a tag" do
before do
pipeline.tag = false
end
- it 'return true' do
+ it "return true" do
is_expected.to be_truthy
end
- context 'when source is merge request' do
+ context "when source is merge request" do
let(:pipeline) do
create(:ci_pipeline, source: :merge_request, merge_request: merge_request)
end
let(:merge_request) do
create(:merge_request,
- source_project: project,
- source_branch: 'feature',
- target_project: project,
- target_branch: 'master')
+ source_project: project,
+ source_branch: "feature",
+ target_project: project,
+ target_branch: "master")
end
- it 'returns false' do
+ it "returns false" do
is_expected.to be_falsey
end
end
end
- context 'when ref is a tag' do
+ context "when ref is a tag" do
before do
pipeline.tag = true
end
- it 'return false' do
+ it "return false" do
is_expected.to be_falsey
end
end
end
- describe '#git_ref' do
+ describe "#git_ref" do
subject { pipeline.send(:git_ref) }
- context 'when ref is branch' do
+ context "when ref is branch" do
let(:pipeline) { create(:ci_pipeline, tag: false) }
- it 'returns branch ref' do
+ it "returns branch ref" do
is_expected.to eq(Gitlab::Git::BRANCH_REF_PREFIX + pipeline.ref.to_s)
end
end
- context 'when ref is tag' do
+ context "when ref is tag" do
let(:pipeline) { create(:ci_pipeline, tag: true) }
- it 'returns branch ref' do
+ it "returns branch ref" do
is_expected.to eq(Gitlab::Git::TAG_REF_PREFIX + pipeline.ref.to_s)
end
end
- context 'when ref is merge request' do
+ context "when ref is merge request" do
let(:pipeline) do
create(:ci_pipeline,
- source: :merge_request,
- merge_request: merge_request)
+ source: :merge_request,
+ merge_request: merge_request)
end
let(:merge_request) do
create(:merge_request,
- source_project: project,
- source_branch: 'feature',
- target_project: project,
- target_branch: 'master')
+ source_project: project,
+ source_branch: "feature",
+ target_project: project,
+ target_branch: "master")
end
- it 'returns branch ref' do
+ it "returns branch ref" do
is_expected.to eq(Gitlab::Git::BRANCH_REF_PREFIX + pipeline.ref.to_s)
end
end
end
- describe 'ref_exists?' do
- context 'when repository exists' do
+ describe "ref_exists?" do
+ context "when repository exists" do
using RSpec::Parameterized::TableSyntax
let(:project) { create(:project, :repository) }
where(:tag, :ref, :result) do
- false | 'master' | true
- false | 'non-existent-branch' | false
- true | 'v1.1.0' | true
- true | 'non-existent-tag' | false
+ false | "master" | true
+ false | "non-existent-branch" | false
+ true | "v1.1.0" | true
+ true | "non-existent-tag" | false
end
with_them do
@@ -1189,223 +1191,224 @@ describe Ci::Pipeline, :mailer do
end
end
- context 'when repository does not exist' do
+ context "when repository does not exist" do
let(:pipeline) do
- create(:ci_empty_pipeline, project: project, ref: 'master')
+ create(:ci_empty_pipeline, project: project, ref: "master")
end
- it 'always returns false' do
+ it "always returns false" do
expect(pipeline.ref_exists?).to eq false
end
end
end
- context 'with non-empty project' do
+ context "with non-empty project" do
let(:project) { create(:project, :repository) }
let(:pipeline) do
create(:ci_pipeline,
- project: project,
- ref: project.default_branch,
- sha: project.commit.sha)
+ project: project,
+ ref: project.default_branch,
+ sha: project.commit.sha)
end
- describe '#latest?' do
- context 'with latest sha' do
- it 'returns true' do
+ describe "#latest?" do
+ context "with latest sha" do
+ it "returns true" do
expect(pipeline).to be_latest
end
end
- context 'with not latest sha' do
+ context "with not latest sha" do
before do
pipeline.update(
- sha: project.commit("#{project.default_branch}~1").sha)
+ sha: project.commit("#{project.default_branch}~1").sha
+ )
end
- it 'returns false' do
+ it "returns false" do
expect(pipeline).not_to be_latest
end
end
end
end
- describe '#manual_actions' do
+ describe "#manual_actions" do
subject { pipeline.manual_actions }
- it 'when none defined' do
+ it "when none defined" do
is_expected.to be_empty
end
- context 'when action defined' do
- let!(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'deploy') }
+ context "when action defined" do
+ let!(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: "deploy") }
- it 'returns one action' do
+ it "returns one action" do
is_expected.to contain_exactly(manual)
end
- context 'there are multiple of the same name' do
- let!(:manual2) { create(:ci_build, :manual, pipeline: pipeline, name: 'deploy') }
+ context "there are multiple of the same name" do
+ let!(:manual2) { create(:ci_build, :manual, pipeline: pipeline, name: "deploy") }
before do
manual.update(retried: true)
end
- it 'returns latest one' do
+ it "returns latest one" do
is_expected.to contain_exactly(manual2)
end
end
end
end
- describe '#branch_updated?' do
- context 'when pipeline has before SHA' do
+ describe "#branch_updated?" do
+ context "when pipeline has before SHA" do
before do
- pipeline.update_column(:before_sha, 'a1b2c3d4')
+ pipeline.update_column(:before_sha, "a1b2c3d4")
end
- it 'runs on a branch update push' do
+ it "runs on a branch update push" do
expect(pipeline.before_sha).not_to be Gitlab::Git::BLANK_SHA
expect(pipeline.branch_updated?).to be true
end
end
- context 'when pipeline does not have before SHA' do
+ context "when pipeline does not have before SHA" do
before do
pipeline.update_column(:before_sha, Gitlab::Git::BLANK_SHA)
end
- it 'does not run on a branch updating push' do
+ it "does not run on a branch updating push" do
expect(pipeline.branch_updated?).to be false
end
end
end
- describe '#modified_paths' do
- context 'when old and new revisions are set' do
+ describe "#modified_paths" do
+ context "when old and new revisions are set" do
let(:project) { create(:project, :repository) }
before do
- pipeline.update(before_sha: '1234abcd', sha: '2345bcde')
+ pipeline.update(before_sha: "1234abcd", sha: "2345bcde")
end
- it 'fetches stats for changes between commits' do
+ it "fetches stats for changes between commits" do
expect(project.repository)
- .to receive(:diff_stats).with('1234abcd', '2345bcde')
+ .to receive(:diff_stats).with("1234abcd", "2345bcde")
.and_call_original
pipeline.modified_paths
end
end
- context 'when either old or new revision is missing' do
+ context "when either old or new revision is missing" do
before do
pipeline.update_column(:before_sha, Gitlab::Git::BLANK_SHA)
end
- it 'returns nil' do
+ it "returns nil" do
expect(pipeline.modified_paths).to be_nil
end
end
- context 'when source is merge request' do
+ context "when source is merge request" do
let(:pipeline) do
create(:ci_pipeline, source: :merge_request, merge_request: merge_request)
end
let(:merge_request) do
create(:merge_request,
- source_project: project,
- source_branch: 'feature',
- target_project: project,
- target_branch: 'master')
+ source_project: project,
+ source_branch: "feature",
+ target_project: project,
+ target_branch: "master")
end
- it 'returns merge request modified paths' do
+ it "returns merge request modified paths" do
expect(pipeline.modified_paths).to match(merge_request.modified_paths)
end
end
end
- describe '#has_kubernetes_active?' do
- context 'when kubernetes is active' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
- it 'returns true' do
+ describe "#has_kubernetes_active?" do
+ context "when kubernetes is active" do
+ shared_examples "same behavior between KubernetesService and Platform::Kubernetes" do
+ it "returns true" do
expect(pipeline).to have_kubernetes_active
end
end
- context 'when user configured kubernetes from Integration > Kubernetes' do
+ context "when user configured kubernetes from Integration > Kubernetes" do
let(:project) { create(:kubernetes_project) }
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
+ it_behaves_like "same behavior between KubernetesService and Platform::Kubernetes"
end
- context 'when user configured kubernetes from CI/CD > Clusters' do
+ context "when user configured kubernetes from CI/CD > Clusters" do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
+ it_behaves_like "same behavior between KubernetesService and Platform::Kubernetes"
end
end
- context 'when kubernetes is not active' do
- it 'returns false' do
+ context "when kubernetes is not active" do
+ it "returns false" do
expect(pipeline).not_to have_kubernetes_active
end
end
end
- describe '#has_warnings?' do
+ describe "#has_warnings?" do
subject { pipeline.has_warnings? }
- context 'build which is allowed to fail fails' do
+ context "build which is allowed to fail fails" do
before do
- create :ci_build, :success, pipeline: pipeline, name: 'rspec'
- create :ci_build, :allowed_to_fail, :failed, pipeline: pipeline, name: 'rubocop'
+ create :ci_build, :success, pipeline: pipeline, name: "rspec"
+ create :ci_build, :allowed_to_fail, :failed, pipeline: pipeline, name: "rubocop"
end
- it 'returns true' do
+ it "returns true" do
is_expected.to be_truthy
end
end
- context 'build which is allowed to fail succeeds' do
+ context "build which is allowed to fail succeeds" do
before do
- create :ci_build, :success, pipeline: pipeline, name: 'rspec'
- create :ci_build, :allowed_to_fail, :success, pipeline: pipeline, name: 'rubocop'
+ create :ci_build, :success, pipeline: pipeline, name: "rspec"
+ create :ci_build, :allowed_to_fail, :success, pipeline: pipeline, name: "rubocop"
end
- it 'returns false' do
+ it "returns false" do
is_expected.to be_falsey
end
end
- context 'build is retried and succeeds' do
+ context "build is retried and succeeds" do
before do
- create :ci_build, :success, pipeline: pipeline, name: 'rubocop'
- create :ci_build, :failed, pipeline: pipeline, name: 'rspec'
- create :ci_build, :success, pipeline: pipeline, name: 'rspec'
+ create :ci_build, :success, pipeline: pipeline, name: "rubocop"
+ create :ci_build, :failed, pipeline: pipeline, name: "rspec"
+ create :ci_build, :success, pipeline: pipeline, name: "rspec"
end
- it 'returns false' do
+ it "returns false" do
is_expected.to be_falsey
end
end
end
- describe '#number_of_warnings' do
- it 'returns the number of warnings' do
- create(:ci_build, :allowed_to_fail, :failed, pipeline: pipeline, name: 'rubocop')
+ describe "#number_of_warnings" do
+ it "returns the number of warnings" do
+ create(:ci_build, :allowed_to_fail, :failed, pipeline: pipeline, name: "rubocop")
expect(pipeline.number_of_warnings).to eq(1)
end
- it 'supports eager loading of the number of warnings' do
+ it "supports eager loading of the number of warnings" do
pipeline2 = create(:ci_empty_pipeline, status: :created, project: project)
- create(:ci_build, :allowed_to_fail, :failed, pipeline: pipeline, name: 'rubocop')
- create(:ci_build, :allowed_to_fail, :failed, pipeline: pipeline2, name: 'rubocop')
+ create(:ci_build, :allowed_to_fail, :failed, pipeline: pipeline, name: "rubocop")
+ create(:ci_build, :allowed_to_fail, :failed, pipeline: pipeline2, name: "rubocop")
pipelines = project.ci_pipelines.to_a
@@ -1421,12 +1424,12 @@ describe Ci::Pipeline, :mailer do
end
end
- shared_context 'with some outdated pipelines' do
+ shared_context "with some outdated pipelines" do
before do
- create_pipeline(:canceled, 'ref', 'A', project)
- create_pipeline(:success, 'ref', 'A', project)
- create_pipeline(:failed, 'ref', 'B', project)
- create_pipeline(:skipped, 'feature', 'C', project)
+ create_pipeline(:canceled, "ref", "A", project)
+ create_pipeline(:success, "ref", "A", project)
+ create_pipeline(:failed, "ref", "B", project)
+ create_pipeline(:skipped, "feature", "C", project)
end
def create_pipeline(status, ref, sha, project)
@@ -1440,75 +1443,75 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '.newest_first' do
- include_context 'with some outdated pipelines'
+ describe ".newest_first" do
+ include_context "with some outdated pipelines"
- it 'returns the pipelines from new to old' do
+ it "returns the pipelines from new to old" do
expect(described_class.newest_first.pluck(:status))
.to eq(%w[skipped failed success canceled])
end
- it 'searches limited backlog' do
+ it "searches limited backlog" do
expect(described_class.newest_first(limit: 1).pluck(:status))
.to eq(%w[skipped])
end
end
- describe '.latest_status' do
- include_context 'with some outdated pipelines'
+ describe ".latest_status" do
+ include_context "with some outdated pipelines"
- context 'when no ref is specified' do
- it 'returns the status of the latest pipeline' do
- expect(described_class.latest_status).to eq('skipped')
+ context "when no ref is specified" do
+ it "returns the status of the latest pipeline" do
+ expect(described_class.latest_status).to eq("skipped")
end
end
- context 'when ref is specified' do
- it 'returns the status of the latest pipeline for the given ref' do
- expect(described_class.latest_status('ref')).to eq('failed')
+ context "when ref is specified" do
+ it "returns the status of the latest pipeline for the given ref" do
+ expect(described_class.latest_status("ref")).to eq("failed")
end
end
end
- describe '.latest_successful_for' do
- include_context 'with some outdated pipelines'
+ describe ".latest_successful_for" do
+ include_context "with some outdated pipelines"
let!(:latest_successful_pipeline) do
- create_pipeline(:success, 'ref', 'D', project)
+ create_pipeline(:success, "ref", "D", project)
end
- it 'returns the latest successful pipeline' do
- expect(described_class.latest_successful_for('ref'))
+ it "returns the latest successful pipeline" do
+ expect(described_class.latest_successful_for("ref"))
.to eq(latest_successful_pipeline)
end
end
- describe '.latest_successful_for_refs' do
- include_context 'with some outdated pipelines'
+ describe ".latest_successful_for_refs" do
+ include_context "with some outdated pipelines"
let!(:latest_successful_pipeline1) do
- create_pipeline(:success, 'ref1', 'D', project)
+ create_pipeline(:success, "ref1", "D", project)
end
let!(:latest_successful_pipeline2) do
- create_pipeline(:success, 'ref2', 'D', project)
+ create_pipeline(:success, "ref2", "D", project)
end
- it 'returns the latest successful pipeline for both refs' do
- refs = %w(ref1 ref2 ref3)
+ it "returns the latest successful pipeline for both refs" do
+ refs = %w[ref1 ref2 ref3]
- expect(described_class.latest_successful_for_refs(refs)).to eq({ 'ref1' => latest_successful_pipeline1, 'ref2' => latest_successful_pipeline2 })
+ expect(described_class.latest_successful_for_refs(refs)).to eq({"ref1" => latest_successful_pipeline1, "ref2" => latest_successful_pipeline2})
end
end
- describe '.latest_status_per_commit' do
+ describe ".latest_status_per_commit" do
let(:project) { create(:project) }
before do
pairs = [
%w[success ref1 123],
%w[manual master 123],
- %w[failed ref 456]
+ %w[failed ref 456],
]
pairs.each do |(status, ref, sha)|
@@ -1522,115 +1525,115 @@ describe Ci::Pipeline, :mailer do
end
end
- context 'without a ref' do
- it 'returns a Hash containing the latest status per commit for all refs' do
+ context "without a ref" do
+ it "returns a Hash containing the latest status per commit for all refs" do
expect(described_class.latest_status_per_commit(%w[123 456]))
- .to eq({ '123' => 'manual', '456' => 'failed' })
+ .to eq({"123" => "manual", "456" => "failed"})
end
- it 'only includes the status of the given commit SHAs' do
+ it "only includes the status of the given commit SHAs" do
expect(described_class.latest_status_per_commit(%w[123]))
- .to eq({ '123' => 'manual' })
+ .to eq({"123" => "manual"})
end
- context 'when there are two pipelines for a ref and SHA' do
- it 'returns the status of the latest pipeline' do
+ context "when there are two pipelines for a ref and SHA" do
+ it "returns the status of the latest pipeline" do
create(
:ci_empty_pipeline,
- status: 'failed',
- ref: 'master',
- sha: '123',
+ status: "failed",
+ ref: "master",
+ sha: "123",
project: project
)
expect(described_class.latest_status_per_commit(%w[123]))
- .to eq({ '123' => 'failed' })
+ .to eq({"123" => "failed"})
end
end
end
- context 'with a ref' do
- it 'only includes the pipelines for the given ref' do
- expect(described_class.latest_status_per_commit(%w[123 456], 'master'))
- .to eq({ '123' => 'manual' })
+ context "with a ref" do
+ it "only includes the pipelines for the given ref" do
+ expect(described_class.latest_status_per_commit(%w[123 456], "master"))
+ .to eq({"123" => "manual"})
end
end
end
- describe '.latest_successful_ids_per_project' do
+ describe ".latest_successful_ids_per_project" do
let(:projects) { create_list(:project, 2) }
let!(:pipeline1) { create(:ci_pipeline, :success, project: projects[0]) }
let!(:pipeline2) { create(:ci_pipeline, :success, project: projects[0]) }
let!(:pipeline3) { create(:ci_pipeline, :failed, project: projects[0]) }
let!(:pipeline4) { create(:ci_pipeline, :success, project: projects[1]) }
- it 'returns expected pipeline ids' do
+ it "returns expected pipeline ids" do
expect(described_class.latest_successful_ids_per_project)
.to contain_exactly(pipeline2, pipeline4)
end
end
- describe '.internal_sources' do
+ describe ".internal_sources" do
subject { described_class.internal_sources }
it { is_expected.to be_an(Array) }
end
- describe '#status' do
+ describe "#status" do
let(:build) do
- create(:ci_build, :created, pipeline: pipeline, name: 'test')
+ create(:ci_build, :created, pipeline: pipeline, name: "test")
end
subject { pipeline.reload.status }
- context 'on queuing' do
+ context "on queuing" do
before do
build.enqueue
end
- it { is_expected.to eq('pending') }
+ it { is_expected.to eq("pending") }
end
- context 'on run' do
+ context "on run" do
before do
build.enqueue
build.run
end
- it { is_expected.to eq('running') }
+ it { is_expected.to eq("running") }
end
- context 'on drop' do
+ context "on drop" do
before do
build.drop
end
- it { is_expected.to eq('failed') }
+ it { is_expected.to eq("failed") }
end
- context 'on success' do
+ context "on success" do
before do
build.success
end
- it { is_expected.to eq('success') }
+ it { is_expected.to eq("success") }
end
- context 'on cancel' do
+ context "on cancel" do
before do
build.cancel
end
- context 'when build is pending' do
+ context "when build is pending" do
let(:build) do
create(:ci_build, :pending, pipeline: pipeline)
end
- it { is_expected.to eq('canceled') }
+ it { is_expected.to eq("canceled") }
end
end
- context 'on failure and build retry' do
+ context "on failure and build retry" do
before do
stub_not_protect_default_branch
@@ -1644,11 +1647,11 @@ describe Ci::Pipeline, :mailer do
# Instead of: created > failed > pending
# Since the pipeline already run, so it should not be pending anymore
- it { is_expected.to eq('running') }
+ it { is_expected.to eq("running") }
end
end
- describe '#ci_yaml_file_path' do
+ describe "#ci_yaml_file_path" do
subject { pipeline.ci_yaml_file_path }
%i[unknown_source repository_source].each do |source|
@@ -1657,74 +1660,74 @@ describe Ci::Pipeline, :mailer do
pipeline.config_source = described_class.config_sources.fetch(source)
end
- it 'returns the path from project' do
- allow(pipeline.project).to receive(:ci_config_path) { 'custom/path' }
+ it "returns the path from project" do
+ allow(pipeline.project).to receive(:ci_config_path) { "custom/path" }
- is_expected.to eq('custom/path')
+ is_expected.to eq("custom/path")
end
- it 'returns default when custom path is nil' do
+ it "returns default when custom path is nil" do
allow(pipeline.project).to receive(:ci_config_path) { nil }
- is_expected.to eq('.gitlab-ci.yml')
+ is_expected.to eq(".gitlab-ci.yml")
end
- it 'returns default when custom path is empty' do
- allow(pipeline.project).to receive(:ci_config_path) { '' }
+ it "returns default when custom path is empty" do
+ allow(pipeline.project).to receive(:ci_config_path) { "" }
- is_expected.to eq('.gitlab-ci.yml')
+ is_expected.to eq(".gitlab-ci.yml")
end
end
end
- context 'when pipeline is for auto-devops' do
+ context "when pipeline is for auto-devops" do
before do
- pipeline.config_source = 'auto_devops_source'
+ pipeline.config_source = "auto_devops_source"
end
- it 'does not return config file' do
+ it "does not return config file" do
is_expected.to be_nil
end
end
end
- describe '#set_config_source' do
- context 'when pipelines does not contain needed data and auto devops is disabled' do
+ describe "#set_config_source" do
+ context "when pipelines does not contain needed data and auto devops is disabled" do
before do
stub_application_setting(auto_devops_enabled: false)
end
- it 'defines source to be unknown' do
+ it "defines source to be unknown" do
pipeline.set_config_source
expect(pipeline).to be_unknown_source
end
end
- context 'when pipeline contains all needed data' do
+ context "when pipeline contains all needed data" do
let(:pipeline) do
create(:ci_pipeline, project: project,
- sha: '1234',
- ref: 'master',
+ sha: "1234",
+ ref: "master",
source: :push)
end
- context 'when the repository has a config file' do
+ context "when the repository has a config file" do
before do
allow(project.repository).to receive(:gitlab_ci_yml_for)
- .and_return('config')
+ .and_return("config")
end
- it 'defines source to be from repository' do
+ it "defines source to be from repository" do
pipeline.set_config_source
expect(pipeline).to be_repository_source
end
- context 'when loading an object' do
+ context "when loading an object" do
let(:new_pipeline) { Ci::Pipeline.find(pipeline.id) }
- it 'does not redefine the source' do
+ it "does not redefine the source" do
# force to overwrite the source
pipeline.unknown_source!
@@ -1733,15 +1736,15 @@ describe Ci::Pipeline, :mailer do
end
end
- context 'when the repository does not have a config file' do
- let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content }
+ context "when the repository does not have a config file" do
+ let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find("Auto-DevOps").content }
- context 'auto devops enabled' do
+ context "auto devops enabled" do
before do
- allow(project).to receive(:ci_config_path) { 'custom' }
+ allow(project).to receive(:ci_config_path) { "custom" }
end
- it 'defines source to be auto devops' do
+ it "defines source to be auto devops" do
pipeline.set_config_source
expect(pipeline).to be_auto_devops_source
@@ -1751,38 +1754,38 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#ci_yaml_file' do
- let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content }
+ describe "#ci_yaml_file" do
+ let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find("Auto-DevOps").content }
- context 'the source is unknown' do
+ context "the source is unknown" do
before do
pipeline.unknown_source!
end
- it 'returns the configuration if found' do
+ it "returns the configuration if found" do
allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for)
- .and_return('config')
+ .and_return("config")
expect(pipeline.ci_yaml_file).to be_a(String)
expect(pipeline.ci_yaml_file).not_to eq(implied_yml)
expect(pipeline.yaml_errors).to be_nil
end
- it 'sets yaml errors if not found' do
+ it "sets yaml errors if not found" do
expect(pipeline.ci_yaml_file).to be_nil
expect(pipeline.yaml_errors)
- .to start_with('Failed to load CI/CD config file')
+ .to start_with("Failed to load CI/CD config file")
end
end
- context 'the source is the repository' do
+ context "the source is the repository" do
before do
pipeline.repository_source!
end
- it 'returns the configuration if found' do
+ it "returns the configuration if found" do
allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for)
- .and_return('config')
+ .and_return("config")
expect(pipeline.ci_yaml_file).to be_a(String)
expect(pipeline.ci_yaml_file).not_to eq(implied_yml)
@@ -1790,157 +1793,157 @@ describe Ci::Pipeline, :mailer do
end
end
- context 'when the source is auto_devops_source' do
+ context "when the source is auto_devops_source" do
before do
stub_application_setting(auto_devops_enabled: true)
pipeline.auto_devops_source!
end
- it 'finds the implied config' do
+ it "finds the implied config" do
expect(pipeline.ci_yaml_file).to eq(implied_yml)
expect(pipeline.yaml_errors).to be_nil
end
end
end
- describe '#update_status' do
- context 'when pipeline is empty' do
- it 'updates does not change pipeline status' do
+ describe "#update_status" do
+ context "when pipeline is empty" do
+ it "updates does not change pipeline status" do
expect(pipeline.statuses.latest.status).to be_nil
expect { pipeline.update_status }
- .to change { pipeline.reload.status }.to 'skipped'
+ .to change { pipeline.reload.status }.to "skipped"
end
end
- context 'when updating status to pending' do
+ context "when updating status to pending" do
before do
allow(pipeline)
.to receive_message_chain(:statuses, :latest, :status)
.and_return(:running)
end
- it 'updates pipeline status to running' do
+ it "updates pipeline status to running" do
expect { pipeline.update_status }
- .to change { pipeline.reload.status }.to 'running'
+ .to change { pipeline.reload.status }.to "running"
end
end
- context 'when updating status to scheduled' do
+ context "when updating status to scheduled" do
before do
allow(pipeline)
.to receive_message_chain(:statuses, :latest, :status)
.and_return(:scheduled)
end
- it 'updates pipeline status to scheduled' do
+ it "updates pipeline status to scheduled" do
expect { pipeline.update_status }
- .to change { pipeline.reload.status }.to 'scheduled'
+ .to change { pipeline.reload.status }.to "scheduled"
end
end
- context 'when statuses status was not recognized' do
+ context "when statuses status was not recognized" do
before do
allow(pipeline)
.to receive(:latest_builds_status)
.and_return(:unknown)
end
- it 'raises an exception' do
+ it "raises an exception" do
expect { pipeline.update_status }
.to raise_error(HasStatus::UnknownStatusError)
end
end
end
- describe '#detailed_status' do
+ describe "#detailed_status" do
subject { pipeline.detailed_status(user) }
- context 'when pipeline is created' do
+ context "when pipeline is created" do
let(:pipeline) { create(:ci_pipeline, status: :created) }
- it 'returns detailed status for created pipeline' do
- expect(subject.text).to eq 'created'
+ it "returns detailed status for created pipeline" do
+ expect(subject.text).to eq "created"
end
end
- context 'when pipeline is pending' do
+ context "when pipeline is pending" do
let(:pipeline) { create(:ci_pipeline, status: :pending) }
- it 'returns detailed status for pending pipeline' do
- expect(subject.text).to eq 'pending'
+ it "returns detailed status for pending pipeline" do
+ expect(subject.text).to eq "pending"
end
end
- context 'when pipeline is running' do
+ context "when pipeline is running" do
let(:pipeline) { create(:ci_pipeline, status: :running) }
- it 'returns detailed status for running pipeline' do
- expect(subject.text).to eq 'running'
+ it "returns detailed status for running pipeline" do
+ expect(subject.text).to eq "running"
end
end
- context 'when pipeline is successful' do
+ context "when pipeline is successful" do
let(:pipeline) { create(:ci_pipeline, status: :success) }
- it 'returns detailed status for successful pipeline' do
- expect(subject.text).to eq 'passed'
+ it "returns detailed status for successful pipeline" do
+ expect(subject.text).to eq "passed"
end
end
- context 'when pipeline is failed' do
+ context "when pipeline is failed" do
let(:pipeline) { create(:ci_pipeline, status: :failed) }
- it 'returns detailed status for failed pipeline' do
- expect(subject.text).to eq 'failed'
+ it "returns detailed status for failed pipeline" do
+ expect(subject.text).to eq "failed"
end
end
- context 'when pipeline is canceled' do
+ context "when pipeline is canceled" do
let(:pipeline) { create(:ci_pipeline, status: :canceled) }
- it 'returns detailed status for canceled pipeline' do
- expect(subject.text).to eq 'canceled'
+ it "returns detailed status for canceled pipeline" do
+ expect(subject.text).to eq "canceled"
end
end
- context 'when pipeline is skipped' do
+ context "when pipeline is skipped" do
let(:pipeline) { create(:ci_pipeline, status: :skipped) }
- it 'returns detailed status for skipped pipeline' do
- expect(subject.text).to eq 'skipped'
+ it "returns detailed status for skipped pipeline" do
+ expect(subject.text).to eq "skipped"
end
end
- context 'when pipeline is blocked' do
+ context "when pipeline is blocked" do
let(:pipeline) { create(:ci_pipeline, status: :manual) }
- it 'returns detailed status for blocked pipeline' do
- expect(subject.text).to eq 'blocked'
+ it "returns detailed status for blocked pipeline" do
+ expect(subject.text).to eq "blocked"
end
end
- context 'when pipeline is successful but with warnings' do
+ context "when pipeline is successful but with warnings" do
let(:pipeline) { create(:ci_pipeline, status: :success) }
before do
create(:ci_build, :allowed_to_fail, :failed, pipeline: pipeline)
end
- it 'retruns detailed status for successful pipeline with warnings' do
- expect(subject.label).to eq 'passed with warnings'
+ it "retruns detailed status for successful pipeline with warnings" do
+ expect(subject.label).to eq "passed with warnings"
end
end
end
- describe '#cancelable?' do
+ describe "#cancelable?" do
%i[created running pending].each do |status0|
context "when there is a build #{status0}" do
before do
create(:ci_build, status0, pipeline: pipeline)
end
- it 'is cancelable' do
+ it "is cancelable" do
expect(pipeline.cancelable?).to be_truthy
end
end
@@ -1950,7 +1953,7 @@ describe Ci::Pipeline, :mailer do
create(:generic_commit_status, status0, pipeline: pipeline)
end
- it 'is cancelable' do
+ it "is cancelable" do
expect(pipeline.cancelable?).to be_truthy
end
end
@@ -1962,7 +1965,7 @@ describe Ci::Pipeline, :mailer do
create(:generic_commit_status, status1, pipeline: pipeline)
end
- it 'is cancelable' do
+ it "is cancelable" do
expect(pipeline.cancelable?).to be_truthy
end
end
@@ -1973,7 +1976,7 @@ describe Ci::Pipeline, :mailer do
create(:ci_build, status1, pipeline: pipeline)
end
- it 'is cancelable' do
+ it "is cancelable" do
expect(pipeline.cancelable?).to be_truthy
end
end
@@ -1984,7 +1987,7 @@ describe Ci::Pipeline, :mailer do
create(:ci_build, status1, pipeline: pipeline)
end
- it 'is cancelable' do
+ it "is cancelable" do
expect(pipeline.cancelable?).to be_truthy
end
end
@@ -1997,7 +2000,7 @@ describe Ci::Pipeline, :mailer do
create(:ci_build, status, pipeline: pipeline)
end
- it 'is not cancelable' do
+ it "is not cancelable" do
expect(pipeline.cancelable?).to be_falsey
end
end
@@ -2007,27 +2010,27 @@ describe Ci::Pipeline, :mailer do
create(:generic_commit_status, status, pipeline: pipeline)
end
- it 'is not cancelable' do
+ it "is not cancelable" do
expect(pipeline.cancelable?).to be_falsey
end
end
end
- context 'when there is a manual action present in the pipeline' do
+ context "when there is a manual action present in the pipeline" do
before do
create(:ci_build, :manual, pipeline: pipeline)
end
- it 'is not cancelable' do
+ it "is not cancelable" do
expect(pipeline).not_to be_cancelable
end
end
end
- describe '#cancel_running' do
+ describe "#cancel_running" do
let(:latest_status) { pipeline.statuses.pluck(:status) }
- context 'when there is a running external job and a regular job' do
+ context "when there is a running external job and a regular job" do
before do
create(:ci_build, :running, pipeline: pipeline)
create(:generic_commit_status, :running, pipeline: pipeline)
@@ -2035,12 +2038,12 @@ describe Ci::Pipeline, :mailer do
pipeline.cancel_running
end
- it 'cancels both jobs' do
- expect(latest_status).to contain_exactly('canceled', 'canceled')
+ it "cancels both jobs" do
+ expect(latest_status).to contain_exactly("canceled", "canceled")
end
end
- context 'when jobs are in different stages' do
+ context "when jobs are in different stages" do
before do
create(:ci_build, :running, stage_idx: 0, pipeline: pipeline)
create(:ci_build, :running, stage_idx: 1, pipeline: pipeline)
@@ -2048,12 +2051,12 @@ describe Ci::Pipeline, :mailer do
pipeline.cancel_running
end
- it 'cancels both jobs' do
- expect(latest_status).to contain_exactly('canceled', 'canceled')
+ it "cancels both jobs" do
+ expect(latest_status).to contain_exactly("canceled", "canceled")
end
end
- context 'when there are created builds present in the pipeline' do
+ context "when there are created builds present in the pipeline" do
before do
create(:ci_build, :running, stage_idx: 0, pipeline: pipeline)
create(:ci_build, :created, stage_idx: 1, pipeline: pipeline)
@@ -2061,13 +2064,13 @@ describe Ci::Pipeline, :mailer do
pipeline.cancel_running
end
- it 'cancels created builds' do
- expect(latest_status).to eq %w(canceled canceled)
+ it "cancels created builds" do
+ expect(latest_status).to eq %w[canceled canceled]
end
end
end
- describe '#retry_failed' do
+ describe "#retry_failed" do
let(:latest_status) { pipeline.statuses.latest.pluck(:status) }
before do
@@ -2076,49 +2079,49 @@ describe Ci::Pipeline, :mailer do
project.add_developer(user)
end
- context 'when there is a failed build and failed external status' do
+ context "when there is a failed build and failed external status" do
before do
- create(:ci_build, :failed, name: 'build', pipeline: pipeline)
- create(:generic_commit_status, :failed, name: 'jenkins', pipeline: pipeline)
+ create(:ci_build, :failed, name: "build", pipeline: pipeline)
+ create(:generic_commit_status, :failed, name: "jenkins", pipeline: pipeline)
pipeline.retry_failed(user)
end
- it 'retries only build' do
- expect(latest_status).to contain_exactly('pending', 'failed')
+ it "retries only build" do
+ expect(latest_status).to contain_exactly("pending", "failed")
end
end
- context 'when builds are in different stages' do
+ context "when builds are in different stages" do
before do
- create(:ci_build, :failed, name: 'build', stage_idx: 0, pipeline: pipeline)
- create(:ci_build, :failed, name: 'jenkins', stage_idx: 1, pipeline: pipeline)
+ create(:ci_build, :failed, name: "build", stage_idx: 0, pipeline: pipeline)
+ create(:ci_build, :failed, name: "jenkins", stage_idx: 1, pipeline: pipeline)
pipeline.retry_failed(user)
end
- it 'retries both builds' do
- expect(latest_status).to contain_exactly('pending', 'created')
+ it "retries both builds" do
+ expect(latest_status).to contain_exactly("pending", "created")
end
end
- context 'when there are canceled and failed' do
+ context "when there are canceled and failed" do
before do
- create(:ci_build, :failed, name: 'build', stage_idx: 0, pipeline: pipeline)
- create(:ci_build, :canceled, name: 'jenkins', stage_idx: 1, pipeline: pipeline)
+ create(:ci_build, :failed, name: "build", stage_idx: 0, pipeline: pipeline)
+ create(:ci_build, :canceled, name: "jenkins", stage_idx: 1, pipeline: pipeline)
pipeline.retry_failed(user)
end
- it 'retries both builds' do
- expect(latest_status).to contain_exactly('pending', 'created')
+ it "retries both builds" do
+ expect(latest_status).to contain_exactly("pending", "created")
end
end
end
- describe '#execute_hooks' do
- let!(:build_a) { create_build('a', 0) }
- let!(:build_b) { create_build('b', 0) }
+ describe "#execute_hooks" do
+ let!(:build_a) { create_build("a", 0) }
+ let!(:build_b) { create_build("b", 0) }
let!(:hook) do
create(:project_hook, project: project, pipeline_events: enabled)
@@ -2128,26 +2131,26 @@ describe Ci::Pipeline, :mailer do
WebHookWorker.drain
end
- context 'with pipeline hooks enabled' do
+ context "with pipeline hooks enabled" do
let(:enabled) { true }
before do
WebMock.stub_request(:post, hook.url)
end
- context 'with multiple builds' do
- context 'when build is queued' do
+ context "with multiple builds" do
+ context "when build is queued" do
before do
build_a.enqueue
build_b.enqueue
end
- it 'receives a pending event once' do
- expect(WebMock).to have_requested_pipeline_hook('pending').once
+ it "receives a pending event once" do
+ expect(WebMock).to have_requested_pipeline_hook("pending").once
end
end
- context 'when build is run' do
+ context "when build is run" do
before do
build_a.enqueue
build_a.run
@@ -2155,12 +2158,12 @@ describe Ci::Pipeline, :mailer do
build_b.run
end
- it 'receives a running event once' do
- expect(WebMock).to have_requested_pipeline_hook('running').once
+ it "receives a running event once" do
+ expect(WebMock).to have_requested_pipeline_hook("running").once
end
end
- context 'when all builds succeed' do
+ context "when all builds succeed" do
before do
build_a.success
@@ -2168,34 +2171,34 @@ describe Ci::Pipeline, :mailer do
build_b.reload.success
end
- it 'receives a success event once' do
- expect(WebMock).to have_requested_pipeline_hook('success').once
+ it "receives a success event once" do
+ expect(WebMock).to have_requested_pipeline_hook("success").once
end
end
- context 'when stage one failed' do
- let!(:build_b) { create_build('b', 1) }
+ context "when stage one failed" do
+ let!(:build_b) { create_build("b", 1) }
before do
build_a.drop
end
- it 'receives a failed event once' do
- expect(WebMock).to have_requested_pipeline_hook('failed').once
+ it "receives a failed event once" do
+ expect(WebMock).to have_requested_pipeline_hook("failed").once
end
end
def have_requested_pipeline_hook(status)
have_requested(:post, hook.url).with do |req|
json_body = JSON.parse(req.body)
- json_body['object_attributes']['status'] == status &&
- json_body['builds'].length == 2
+ json_body["object_attributes"]["status"] == status &&
+ json_body["builds"].length == 2
end
end
end
end
- context 'with pipeline hooks disabled' do
+ context "with pipeline hooks disabled" do
let(:enabled) { false }
before do
@@ -2203,40 +2206,40 @@ describe Ci::Pipeline, :mailer do
build_b.enqueue
end
- it 'did not execute pipeline_hook after touched' do
+ it "did not execute pipeline_hook after touched" do
expect(WebMock).not_to have_requested(:post, hook.url)
end
end
def create_build(name, stage_idx)
create(:ci_build,
- :created,
- pipeline: pipeline,
- name: name,
- stage_idx: stage_idx)
+ :created,
+ pipeline: pipeline,
+ name: name,
+ stage_idx: stage_idx)
end
end
describe "#merge_requests" do
let(:project) { create(:project) }
- let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: 'master', sha: 'a288a022a53a5a944fae87bcec6efc87b7061808') }
+ let(:pipeline) { create(:ci_empty_pipeline, status: "created", project: project, ref: "master", sha: "a288a022a53a5a944fae87bcec6efc87b7061808") }
it "returns merge requests whose `diff_head_sha` matches the pipeline's SHA" do
- allow_any_instance_of(MergeRequest).to receive(:diff_head_sha) { 'a288a022a53a5a944fae87bcec6efc87b7061808' }
+ allow_any_instance_of(MergeRequest).to receive(:diff_head_sha) { "a288a022a53a5a944fae87bcec6efc87b7061808" }
merge_request = create(:merge_request, source_project: project, head_pipeline: pipeline, source_branch: pipeline.ref)
expect(pipeline.merge_requests).to eq([merge_request])
end
it "doesn't return merge requests whose source branch doesn't match the pipeline's ref" do
- create(:merge_request, source_project: project, source_branch: 'feature', target_branch: 'master')
+ create(:merge_request, source_project: project, source_branch: "feature", target_branch: "master")
expect(pipeline.merge_requests).to be_empty
end
it "doesn't return merge requests whose `diff_head_sha` doesn't match the pipeline's SHA" do
create(:merge_request, source_project: project, source_branch: pipeline.ref)
- allow_any_instance_of(MergeRequest).to receive(:diff_head_sha) { '97de212e80737a608d939f648d959671fb0a0142b' }
+ allow_any_instance_of(MergeRequest).to receive(:diff_head_sha) { "97de212e80737a608d939f648d959671fb0a0142b" }
expect(pipeline.merge_requests).to be_empty
end
@@ -2245,8 +2248,8 @@ describe Ci::Pipeline, :mailer do
describe "#all_merge_requests" do
let(:project) { create(:project) }
- shared_examples 'a method that returns all merge requests for a given pipeline' do
- let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: pipeline_project, ref: 'master') }
+ shared_examples "a method that returns all merge requests for a given pipeline" do
+ let(:pipeline) { create(:ci_empty_pipeline, status: "created", project: pipeline_project, ref: "master") }
it "returns all merge requests having the same source branch" do
merge_request = create(:merge_request, source_project: pipeline_project, target_project: project, source_branch: pipeline.ref)
@@ -2255,133 +2258,133 @@ describe Ci::Pipeline, :mailer do
end
it "doesn't return merge requests having a different source branch" do
- create(:merge_request, source_project: pipeline_project, target_project: project, source_branch: 'feature', target_branch: 'master')
+ create(:merge_request, source_project: pipeline_project, target_project: project, source_branch: "feature", target_branch: "master")
expect(pipeline.all_merge_requests).to be_empty
end
- context 'when there is a merge request pipeline' do
- let(:source_branch) { 'feature' }
- let(:target_branch) { 'master' }
+ context "when there is a merge request pipeline" do
+ let(:source_branch) { "feature" }
+ let(:target_branch) { "master" }
let!(:pipeline) do
create(:ci_pipeline,
- source: :merge_request,
- project: pipeline_project,
- ref: source_branch,
- merge_request: merge_request)
+ source: :merge_request,
+ project: pipeline_project,
+ ref: source_branch,
+ merge_request: merge_request)
end
let(:merge_request) do
create(:merge_request,
- source_project: pipeline_project,
- source_branch: source_branch,
- target_project: project,
- target_branch: target_branch)
+ source_project: pipeline_project,
+ source_branch: source_branch,
+ target_project: project,
+ target_branch: target_branch)
end
- it 'returns an associated merge request' do
+ it "returns an associated merge request" do
expect(pipeline.all_merge_requests).to eq([merge_request])
end
- context 'when there is another merge request pipeline that targets a different branch' do
- let(:target_branch_2) { 'merge-test' }
+ context "when there is another merge request pipeline that targets a different branch" do
+ let(:target_branch_2) { "merge-test" }
let!(:pipeline_2) do
create(:ci_pipeline,
- source: :merge_request,
- project: pipeline_project,
- ref: source_branch,
- merge_request: merge_request_2)
+ source: :merge_request,
+ project: pipeline_project,
+ ref: source_branch,
+ merge_request: merge_request_2)
end
let(:merge_request_2) do
create(:merge_request,
- source_project: pipeline_project,
- source_branch: source_branch,
- target_project: project,
- target_branch: target_branch_2)
+ source_project: pipeline_project,
+ source_branch: source_branch,
+ target_project: project,
+ target_branch: target_branch_2)
end
- it 'does not return an associated merge request' do
+ it "does not return an associated merge request" do
expect(pipeline.all_merge_requests).not_to include(merge_request_2)
end
end
end
end
- it_behaves_like 'a method that returns all merge requests for a given pipeline' do
+ it_behaves_like "a method that returns all merge requests for a given pipeline" do
let(:pipeline_project) { project }
end
- context 'for a fork' do
+ context "for a fork" do
let(:fork) { fork_project(project) }
- it_behaves_like 'a method that returns all merge requests for a given pipeline' do
+ it_behaves_like "a method that returns all merge requests for a given pipeline" do
let(:pipeline_project) { fork }
end
end
end
- describe '#stuck?' do
+ describe "#stuck?" do
before do
create(:ci_build, :pending, pipeline: pipeline)
end
- context 'when pipeline is stuck' do
- it 'is stuck' do
+ context "when pipeline is stuck" do
+ it "is stuck" do
expect(pipeline).to be_stuck
end
end
- context 'when pipeline is not stuck' do
+ context "when pipeline is not stuck" do
before do
create(:ci_runner, :instance, :online)
end
- it 'is not stuck' do
+ it "is not stuck" do
expect(pipeline).not_to be_stuck
end
end
end
- describe '#has_yaml_errors?' do
- context 'when pipeline has errors' do
+ describe "#has_yaml_errors?" do
+ context "when pipeline has errors" do
let(:pipeline) do
- create(:ci_pipeline, config: { rspec: nil })
+ create(:ci_pipeline, config: {rspec: nil})
end
- it 'contains yaml errors' do
+ it "contains yaml errors" do
expect(pipeline).to have_yaml_errors
end
end
- context 'when pipeline does not have errors' do
+ context "when pipeline does not have errors" do
let(:pipeline) do
- create(:ci_pipeline, config: { rspec: { script: 'rake test' } })
+ create(:ci_pipeline, config: {rspec: {script: "rake test"}})
end
- it 'does not contain yaml errors' do
+ it "does not contain yaml errors" do
expect(pipeline).not_to have_yaml_errors
end
end
end
- describe 'notifications when pipeline success or failed' do
+ describe "notifications when pipeline success or failed" do
let(:project) { create(:project, :repository) }
let(:pipeline) do
create(:ci_pipeline,
- project: project,
- sha: project.commit('master').sha,
- user: create(:user))
+ project: project,
+ sha: project.commit("master").sha,
+ user: create(:user))
end
before do
project.add_developer(pipeline.user)
pipeline.user.global_notification_setting
- .update(level: 'custom', failed_pipeline: true, success_pipeline: true)
+ .update(level: "custom", failed_pipeline: true, success_pipeline: true)
perform_enqueued_jobs do
pipeline.enqueue
@@ -2389,29 +2392,29 @@ describe Ci::Pipeline, :mailer do
end
end
- shared_examples 'sending a notification' do
- it 'sends an email' do
+ shared_examples "sending a notification" do
+ it "sends an email" do
should_only_email(pipeline.user, kind: :bcc)
end
end
- shared_examples 'not sending any notification' do
- it 'does not send any email' do
+ shared_examples "not sending any notification" do
+ it "does not send any email" do
should_not_email_anyone
end
end
- context 'with success pipeline' do
+ context "with success pipeline" do
before do
perform_enqueued_jobs do
pipeline.succeed
end
end
- it_behaves_like 'sending a notification'
+ it_behaves_like "sending a notification"
end
- context 'with failed pipeline' do
+ context "with failed pipeline" do
before do
perform_enqueued_jobs do
create(:ci_build, :failed, pipeline: pipeline)
@@ -2421,46 +2424,46 @@ describe Ci::Pipeline, :mailer do
end
end
- it_behaves_like 'sending a notification'
+ it_behaves_like "sending a notification"
end
- context 'with skipped pipeline' do
+ context "with skipped pipeline" do
before do
perform_enqueued_jobs do
pipeline.skip
end
end
- it_behaves_like 'not sending any notification'
+ it_behaves_like "not sending any notification"
end
- context 'with cancelled pipeline' do
+ context "with cancelled pipeline" do
before do
perform_enqueued_jobs do
pipeline.cancel
end
end
- it_behaves_like 'not sending any notification'
+ it_behaves_like "not sending any notification"
end
end
- describe '#latest_builds_with_artifacts' do
+ describe "#latest_builds_with_artifacts" do
let!(:pipeline) { create(:ci_pipeline, :success) }
let!(:build) do
create(:ci_build, :success, :artifacts, pipeline: pipeline)
end
- it 'returns an Array' do
+ it "returns an Array" do
expect(pipeline.latest_builds_with_artifacts).to be_an_instance_of(Array)
end
- it 'returns the latest builds' do
+ it "returns the latest builds" do
expect(pipeline.latest_builds_with_artifacts).to eq([build])
end
- it 'memoizes the returned relation' do
+ it "memoizes the returned relation" do
query_count = ActiveRecord::QueryRecorder
.new { 2.times { pipeline.latest_builds_with_artifacts.to_a } }
.count
@@ -2469,28 +2472,28 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#has_test_reports?' do
+ describe "#has_test_reports?" do
subject { pipeline.has_test_reports? }
- context 'when pipeline has builds with test reports' do
+ context "when pipeline has builds with test reports" do
before do
create(:ci_build, :test_reports, pipeline: pipeline, project: project)
end
- context 'when pipeline status is running' do
+ context "when pipeline status is running" do
let(:pipeline) { create(:ci_pipeline, :running, project: project) }
it { is_expected.to be_falsey }
end
- context 'when pipeline status is success' do
+ context "when pipeline status is success" do
let(:pipeline) { create(:ci_pipeline, :success, project: project) }
it { is_expected.to be_truthy }
end
end
- context 'when pipeline does not have builds with test reports' do
+ context "when pipeline does not have builds with test reports" do
before do
create(:ci_build, :artifacts, pipeline: pipeline, project: project)
end
@@ -2500,7 +2503,7 @@ describe Ci::Pipeline, :mailer do
it { is_expected.to be_falsey }
end
- context 'when retried build has test reports' do
+ context "when retried build has test reports" do
before do
create(:ci_build, :retried, :test_reports, pipeline: pipeline, project: project)
end
@@ -2511,29 +2514,29 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#test_reports' do
+ describe "#test_reports" do
subject { pipeline.test_reports }
- context 'when pipeline has multiple builds with test reports' do
- let!(:build_rspec) { create(:ci_build, :success, name: 'rspec', pipeline: pipeline, project: project) }
- let!(:build_java) { create(:ci_build, :success, name: 'java', pipeline: pipeline, project: project) }
+ context "when pipeline has multiple builds with test reports" do
+ let!(:build_rspec) { create(:ci_build, :success, name: "rspec", pipeline: pipeline, project: project) }
+ let!(:build_java) { create(:ci_build, :success, name: "java", pipeline: pipeline, project: project) }
before do
create(:ci_job_artifact, :junit, job: build_rspec, project: project)
create(:ci_job_artifact, :junit_with_ant, job: build_java, project: project)
end
- it 'returns test reports with collected data' do
+ it "returns test reports with collected data" do
expect(subject.total_count).to be(7)
expect(subject.success_count).to be(5)
expect(subject.failed_count).to be(2)
end
- context 'when builds are retried' do
- let!(:build_rspec) { create(:ci_build, :retried, :success, name: 'rspec', pipeline: pipeline, project: project) }
- let!(:build_java) { create(:ci_build, :retried, :success, name: 'java', pipeline: pipeline, project: project) }
+ context "when builds are retried" do
+ let!(:build_rspec) { create(:ci_build, :retried, :success, name: "rspec", pipeline: pipeline, project: project) }
+ let!(:build_java) { create(:ci_build, :retried, :success, name: "java", pipeline: pipeline, project: project) }
- it 'does not take retried builds into account' do
+ it "does not take retried builds into account" do
expect(subject.total_count).to be(0)
expect(subject.success_count).to be(0)
expect(subject.failed_count).to be(0)
@@ -2541,41 +2544,41 @@ describe Ci::Pipeline, :mailer do
end
end
- context 'when pipeline does not have any builds with test reports' do
- it 'returns empty test reports' do
+ context "when pipeline does not have any builds with test reports" do
+ it "returns empty test reports" do
expect(subject.total_count).to be(0)
end
end
end
- describe '#total_size' do
+ describe "#total_size" do
let!(:build_job1) { create(:ci_build, pipeline: pipeline, stage_idx: 0) }
let!(:build_job2) { create(:ci_build, pipeline: pipeline, stage_idx: 0) }
let!(:test_job_failed_and_retried) { create(:ci_build, :failed, :retried, pipeline: pipeline, stage_idx: 1) }
let!(:second_test_job) { create(:ci_build, pipeline: pipeline, stage_idx: 1) }
let!(:deploy_job) { create(:ci_build, pipeline: pipeline, stage_idx: 2) }
- it 'returns all jobs (including failed and retried)' do
+ it "returns all jobs (including failed and retried)" do
expect(pipeline.total_size).to eq(5)
end
end
- describe '#status' do
- context 'when transitioning to failed' do
- context 'when pipeline has autodevops as source' do
+ describe "#status" do
+ context "when transitioning to failed" do
+ context "when pipeline has autodevops as source" do
let(:pipeline) { create(:ci_pipeline, :running, :auto_devops_source) }
- it 'calls autodevops disable service' do
+ it "calls autodevops disable service" do
expect(AutoDevops::DisableWorker).to receive(:perform_async).with(pipeline.id)
pipeline.drop
end
end
- context 'when pipeline has other source' do
+ context "when pipeline has other source" do
let(:pipeline) { create(:ci_pipeline, :running, :repository_source) }
- it 'does not call auto devops disable service' do
+ it "does not call auto devops disable service" do
expect(AutoDevops::DisableWorker).not_to receive(:perform_async)
pipeline.drop
@@ -2584,8 +2587,8 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#default_branch?' do
- let(:default_branch) { 'master'}
+ describe "#default_branch?" do
+ let(:default_branch) { "master"}
subject { pipeline.default_branch? }
@@ -2593,7 +2596,7 @@ describe Ci::Pipeline, :mailer do
allow(project).to receive(:default_branch).and_return(default_branch)
end
- context 'when pipeline ref is the default branch of the project' do
+ context "when pipeline ref is the default branch of the project" do
let(:pipeline) do
build(:ci_empty_pipeline, status: :created, project: project, ref: default_branch)
end
@@ -2603,9 +2606,9 @@ describe Ci::Pipeline, :mailer do
end
end
- context 'when pipeline ref is not the default branch of the project' do
+ context "when pipeline ref is not the default branch of the project" do
let(:pipeline) do
- build(:ci_empty_pipeline, status: :created, project: project, ref: 'another_branch')
+ build(:ci_empty_pipeline, status: :created, project: project, ref: "another_branch")
end
it "returns false" do
diff --git a/spec/models/ci/pipeline_variable_spec.rb b/spec/models/ci/pipeline_variable_spec.rb
index 03d09cb31d6..d457e34a6ba 100644
--- a/spec/models/ci/pipeline_variable_spec.rb
+++ b/spec/models/ci/pipeline_variable_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::PipelineVariable do
subject { build(:ci_pipeline_variable) }
@@ -6,12 +6,12 @@ describe Ci::PipelineVariable do
it { is_expected.to include_module(HasVariable) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_id) }
- describe '#hook_attrs' do
- let(:variable) { create(:ci_pipeline_variable, key: 'foo', value: 'bar') }
+ describe "#hook_attrs" do
+ let(:variable) { create(:ci_pipeline_variable, key: "foo", value: "bar") }
subject { variable.hook_attrs }
it { is_expected.to be_a(Hash) }
- it { is_expected.to eq({ key: 'foo', value: 'bar' }) }
+ it { is_expected.to eq({key: "foo", value: "bar"}) }
end
end
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index eb2daed7f32..0fe42d74487 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -1,76 +1,76 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::Runner do
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe 'validation' do
+ describe "validation" do
it { is_expected.to validate_presence_of(:access_level) }
it { is_expected.to validate_presence_of(:runner_type) }
- context 'when runner is not allowed to pick untagged jobs' do
- context 'when runner does not have tags' do
- it 'is not valid' do
+ context "when runner is not allowed to pick untagged jobs" do
+ context "when runner does not have tags" do
+ it "is not valid" do
runner = build(:ci_runner, tag_list: [], run_untagged: false)
expect(runner).to be_invalid
end
end
- context 'when runner has tags' do
- it 'is valid' do
- runner = build(:ci_runner, tag_list: ['tag'], run_untagged: false)
+ context "when runner has tags" do
+ it "is valid" do
+ runner = build(:ci_runner, tag_list: ["tag"], run_untagged: false)
expect(runner).to be_valid
end
end
end
- context '#exactly_one_group' do
+ context "#exactly_one_group" do
let(:group) { create(:group) }
let(:runner) { create(:ci_runner, :group, groups: [group]) }
- it 'disallows assigning group if already assigned to a group' do
+ it "disallows assigning group if already assigned to a group" do
runner.groups << build(:group)
expect(runner).not_to be_valid
- expect(runner.errors.full_messages).to include('Runner needs to be assigned to exactly one group')
+ expect(runner.errors.full_messages).to include("Runner needs to be assigned to exactly one group")
end
end
- context 'runner_type validations' do
+ context "runner_type validations" do
set(:group) { create(:group) }
set(:project) { create(:project) }
let(:group_runner) { create(:ci_runner, :group, groups: [group]) }
let(:project_runner) { create(:ci_runner, :project, projects: [project]) }
let(:instance_runner) { create(:ci_runner, :instance) }
- it 'disallows assigning group to project_type runner' do
+ it "disallows assigning group to project_type runner" do
project_runner.groups << build(:group)
expect(project_runner).not_to be_valid
- expect(project_runner.errors.full_messages).to include('Runner cannot have groups assigned')
+ expect(project_runner.errors.full_messages).to include("Runner cannot have groups assigned")
end
- it 'disallows assigning group to instance_type runner' do
+ it "disallows assigning group to instance_type runner" do
instance_runner.groups << build(:group)
expect(instance_runner).not_to be_valid
- expect(instance_runner.errors.full_messages).to include('Runner cannot have groups assigned')
+ expect(instance_runner.errors.full_messages).to include("Runner cannot have groups assigned")
end
- it 'disallows assigning project to group_type runner' do
+ it "disallows assigning project to group_type runner" do
group_runner.projects << build(:project)
expect(group_runner).not_to be_valid
- expect(group_runner.errors.full_messages).to include('Runner cannot have projects assigned')
+ expect(group_runner.errors.full_messages).to include("Runner cannot have projects assigned")
end
- it 'disallows assigning project to instance_type runner' do
+ it "disallows assigning project to instance_type runner" do
instance_runner.projects << build(:project)
expect(instance_runner).not_to be_valid
- expect(instance_runner.errors.full_messages).to include('Runner cannot have projects assigned')
+ expect(instance_runner.errors.full_messages).to include("Runner cannot have projects assigned")
end
- it 'should fail to save a group assigned to a project runner even if the runner is already saved' do
+ it "should fail to save a group assigned to a project runner even if the runner is already saved" do
group_runner
expect { create(:group, runners: [project_runner]) }
@@ -79,8 +79,8 @@ describe Ci::Runner do
end
end
- describe '#access_level' do
- context 'when creating new runner and access_level is nil' do
+ describe "#access_level" do
+ context "when creating new runner and access_level is nil" do
let(:runner) do
build(:ci_runner, access_level: nil)
end
@@ -90,7 +90,7 @@ describe Ci::Runner do
end
end
- context 'when creating new runner and access_level is defined in enum' do
+ context "when creating new runner and access_level is defined in enum" do
let(:runner) do
build(:ci_runner, access_level: :not_protected)
end
@@ -100,27 +100,27 @@ describe Ci::Runner do
end
end
- context 'when creating new runner and access_level is not defined in enum' do
+ context "when creating new runner and access_level is not defined in enum" do
it "raises an error" do
expect { build(:ci_runner, access_level: :this_is_not_defined) }.to raise_error(ArgumentError)
end
end
end
- describe '.instance_type' do
+ describe ".instance_type" do
let(:group) { create(:group) }
let(:project) { create(:project) }
let!(:group_runner) { create(:ci_runner, :group, groups: [group]) }
let!(:project_runner) { create(:ci_runner, :project, projects: [project]) }
let!(:shared_runner) { create(:ci_runner, :instance) }
- it 'returns only shared runners' do
+ it "returns only shared runners" do
expect(described_class.instance_type).to contain_exactly(shared_runner)
end
end
- describe '.belonging_to_project' do
- it 'returns the specific project runner' do
+ describe ".belonging_to_project" do
+ it "returns the specific project runner" do
# own
specific_project = create(:project)
specific_runner = create(:ci_runner, :project, projects: [specific_project])
@@ -133,7 +133,7 @@ describe Ci::Runner do
end
end
- describe '.belonging_to_parent_group_of_project' do
+ describe ".belonging_to_parent_group_of_project" do
let(:project) { create(:project, group: group) }
let(:group) { create(:group) }
let(:runner) { create(:ci_runner, :group, groups: [group]) }
@@ -141,24 +141,24 @@ describe Ci::Runner do
let!(:unrelated_project) { create(:project, group: unrelated_group) }
let!(:unrelated_runner) { create(:ci_runner, :group, groups: [unrelated_group]) }
- it 'returns the specific group runner' do
+ it "returns the specific group runner" do
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner)
end
- context 'with a parent group with a runner', :nested_groups do
+ context "with a parent group with a runner", :nested_groups do
let(:runner) { create(:ci_runner, :group, groups: [parent_group]) }
let(:project) { create(:project, group: group) }
let(:group) { create(:group, parent: parent_group) }
let(:parent_group) { create(:group) }
- it 'returns the group runner from the parent group' do
+ it "returns the group runner from the parent group" do
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner)
end
end
end
- describe '.owned_or_instance_wide' do
- it 'returns a globally shared, a project specific and a group specific runner' do
+ describe ".owned_or_instance_wide" do
+ it "returns a globally shared, a project specific and a group specific runner" do
# group specific
group = create(:group)
project = create(:project, group: group)
@@ -176,32 +176,32 @@ describe Ci::Runner do
end
end
- describe '#display_name' do
- it 'returns the description if it has a value' do
- runner = build(:ci_runner, description: 'Linux/Ruby-1.9.3-p448')
- expect(runner.display_name).to eq 'Linux/Ruby-1.9.3-p448'
+ describe "#display_name" do
+ it "returns the description if it has a value" do
+ runner = build(:ci_runner, description: "Linux/Ruby-1.9.3-p448")
+ expect(runner.display_name).to eq "Linux/Ruby-1.9.3-p448"
end
- it 'returns the token if it does not have a description' do
+ it "returns the token if it does not have a description" do
runner = create(:ci_runner)
expect(runner.display_name).to eq runner.description
end
- it 'returns the token if the description is an empty string' do
- runner = build(:ci_runner, description: '', token: 'token')
+ it "returns the token if the description is an empty string" do
+ runner = build(:ci_runner, description: "", token: "token")
expect(runner.display_name).to eq runner.token
end
end
- describe '#assign_to' do
+ describe "#assign_to" do
let(:project) { create(:project) }
subject { runner.assign_to(project) }
- context 'with shared_runner' do
+ context "with shared_runner" do
let(:runner) { create(:ci_runner, :instance) }
- it 'transitions shared runner to project runner and assigns project' do
+ it "transitions shared runner to project runner and assigns project" do
expect(subject).to be_truthy
expect(runner).to be_project_type
@@ -210,18 +210,18 @@ describe Ci::Runner do
end
end
- context 'with group runner' do
+ context "with group runner" do
let(:group) { create(:group) }
let(:runner) { create(:ci_runner, :group, groups: [group]) }
- it 'raises an error' do
+ it "raises an error" do
expect { subject }
- .to raise_error(ArgumentError, 'Transitioning a group runner to a project runner is not supported')
+ .to raise_error(ArgumentError, "Transitioning a group runner to a project runner is not supported")
end
end
end
- describe '.online' do
+ describe ".online" do
subject { described_class.online }
before do
@@ -232,7 +232,7 @@ describe Ci::Runner do
it { is_expected.to eq([@runner2])}
end
- describe '#online?' do
+ describe "#online?" do
let(:runner) { create(:ci_runner, :instance) }
subject { runner.online? }
@@ -243,12 +243,12 @@ describe Ci::Runner do
.with(:platform).and_return("darwin")
end
- context 'no cache value' do
+ context "no cache value" do
before do
stub_redis_runner_contacted_at(nil)
end
- context 'never contacted' do
+ context "never contacted" do
before do
runner.contacted_at = nil
end
@@ -256,7 +256,7 @@ describe Ci::Runner do
it { is_expected.to be_falsey }
end
- context 'contacted long time ago time' do
+ context "contacted long time ago time" do
before do
runner.contacted_at = 1.year.ago
end
@@ -264,7 +264,7 @@ describe Ci::Runner do
it { is_expected.to be_falsey }
end
- context 'contacted 1s ago' do
+ context "contacted 1s ago" do
before do
runner.contacted_at = 1.second.ago
end
@@ -273,8 +273,8 @@ describe Ci::Runner do
end
end
- context 'with cache value' do
- context 'contacted long time ago time' do
+ context "with cache value" do
+ context "contacted long time ago time" do
before do
runner.contacted_at = 1.year.ago
stub_redis_runner_contacted_at(1.year.ago.to_s)
@@ -283,7 +283,7 @@ describe Ci::Runner do
it { is_expected.to be_falsey }
end
- context 'contacted 1s ago' do
+ context "contacted 1s ago" do
before do
runner.contacted_at = 50.minutes.ago
stub_redis_runner_contacted_at(1.second.ago.to_s)
@@ -297,12 +297,12 @@ describe Ci::Runner do
Gitlab::Redis::SharedState.with do |redis|
cache_key = runner.send(:cache_attribute_key)
expect(redis).to receive(:get).with(cache_key)
- .and_return({ contacted_at: value }.to_json).at_least(:once)
+ .and_return({contacted_at: value}.to_json).at_least(:once)
end
end
end
- describe '.offline' do
+ describe ".offline" do
subject { described_class.offline }
before do
@@ -313,7 +313,7 @@ describe Ci::Runner do
it { is_expected.to eq([@runner1])}
end
- describe '#can_pick?' do
+ describe "#can_pick?" do
set(:pipeline) { create(:ci_pipeline) }
let(:build) { create(:ci_build, pipeline: pipeline) }
let(:runner_project) { build.project }
@@ -323,110 +323,110 @@ describe Ci::Runner do
subject { runner.can_pick?(build) }
- context 'a different runner' do
+ context "a different runner" do
let(:other_project) { create(:project) }
let(:other_runner) { create(:ci_runner, :project, projects: [other_project], tag_list: tag_list, run_untagged: run_untagged) }
- it 'cannot handle builds' do
+ it "cannot handle builds" do
expect(other_runner.can_pick?(build)).to be_falsey
end
end
- context 'when runner does not have tags' do
- it 'can handle builds without tags' do
+ context "when runner does not have tags" do
+ it "can handle builds without tags" do
expect(runner.can_pick?(build)).to be_truthy
end
- it 'cannot handle build with tags' do
- build.tag_list = ['aa']
+ it "cannot handle build with tags" do
+ build.tag_list = ["aa"]
expect(runner.can_pick?(build)).to be_falsey
end
end
- context 'when runner has tags' do
- let(:tag_list) { %w(bb cc) }
+ context "when runner has tags" do
+ let(:tag_list) { %w[bb cc] }
- shared_examples 'tagged build picker' do
- it 'can handle build with matching tags' do
- build.tag_list = ['bb']
+ shared_examples "tagged build picker" do
+ it "can handle build with matching tags" do
+ build.tag_list = ["bb"]
expect(runner.can_pick?(build)).to be_truthy
end
- it 'cannot handle build without matching tags' do
- build.tag_list = ['aa']
+ it "cannot handle build without matching tags" do
+ build.tag_list = ["aa"]
expect(runner.can_pick?(build)).to be_falsey
end
end
- context 'when runner can pick untagged jobs' do
- it 'can handle builds without tags' do
+ context "when runner can pick untagged jobs" do
+ it "can handle builds without tags" do
expect(runner.can_pick?(build)).to be_truthy
end
- it_behaves_like 'tagged build picker'
+ it_behaves_like "tagged build picker"
end
- context 'when runner cannot pick untagged jobs' do
+ context "when runner cannot pick untagged jobs" do
let(:run_untagged) { false }
- it 'cannot handle builds without tags' do
+ it "cannot handle builds without tags" do
expect(runner.can_pick?(build)).to be_falsey
end
- it_behaves_like 'tagged build picker'
+ it_behaves_like "tagged build picker"
end
end
- context 'when runner is shared' do
+ context "when runner is shared" do
let(:runner) { create(:ci_runner, :instance) }
- it 'can handle builds' do
+ it "can handle builds" do
expect(runner.can_pick?(build)).to be_truthy
end
- context 'when runner is locked' do
+ context "when runner is locked" do
let(:runner) { create(:ci_runner, :instance, locked: true) }
- it 'can handle builds' do
+ it "can handle builds" do
expect(runner.can_pick?(build)).to be_truthy
end
end
end
- context 'when runner is not shared' do
- context 'when runner is assigned to a project' do
- it 'can handle builds' do
+ context "when runner is not shared" do
+ context "when runner is assigned to a project" do
+ it "can handle builds" do
expect(runner.can_pick?(build)).to be_truthy
end
end
- context 'when runner is assigned to another project' do
+ context "when runner is assigned to another project" do
let(:runner_project) { create(:project) }
- it 'cannot handle builds' do
+ it "cannot handle builds" do
expect(runner.can_pick?(build)).to be_falsey
end
end
- context 'when runner is assigned to a group' do
+ context "when runner is assigned to a group" do
let(:group) { create(:group, projects: [build.project]) }
let(:runner) { create(:ci_runner, :group, tag_list: tag_list, run_untagged: run_untagged, groups: [group]) }
- it 'can handle builds' do
+ it "can handle builds" do
expect(runner.can_pick?(build)).to be_truthy
end
end
end
- context 'when access_level of runner is not_protected' do
+ context "when access_level of runner is not_protected" do
before do
runner.not_protected!
end
- context 'when build is protected' do
+ context "when build is protected" do
before do
build.protected = true
end
@@ -434,7 +434,7 @@ describe Ci::Runner do
it { is_expected.to be_truthy }
end
- context 'when build is unprotected' do
+ context "when build is unprotected" do
before do
build.protected = false
end
@@ -443,12 +443,12 @@ describe Ci::Runner do
end
end
- context 'when access_level of runner is ref_protected' do
+ context "when access_level of runner is ref_protected" do
before do
runner.ref_protected!
end
- context 'when build is protected' do
+ context "when build is protected" do
before do
build.protected = true
end
@@ -456,7 +456,7 @@ describe Ci::Runner do
it { is_expected.to be_truthy }
end
- context 'when build is unprotected' do
+ context "when build is unprotected" do
before do
build.protected = false
end
@@ -466,12 +466,12 @@ describe Ci::Runner do
end
end
- describe '#status' do
+ describe "#status" do
let(:runner) { create(:ci_runner, :instance, contacted_at: 1.second.ago) }
subject { runner.status }
- context 'never connected' do
+ context "never connected" do
before do
runner.contacted_at = nil
end
@@ -479,7 +479,7 @@ describe Ci::Runner do
it { is_expected.to eq(:not_connected) }
end
- context 'contacted 1s ago' do
+ context "contacted 1s ago" do
before do
runner.contacted_at = 1.second.ago
end
@@ -487,7 +487,7 @@ describe Ci::Runner do
it { is_expected.to eq(:online) }
end
- context 'contacted long time ago' do
+ context "contacted long time ago" do
before do
runner.contacted_at = 1.year.ago
end
@@ -495,7 +495,7 @@ describe Ci::Runner do
it { is_expected.to eq(:offline) }
end
- context 'inactive' do
+ context "inactive" do
before do
runner.active = false
end
@@ -504,50 +504,50 @@ describe Ci::Runner do
end
end
- describe '#tick_runner_queue' do
+ describe "#tick_runner_queue" do
let(:runner) { create(:ci_runner) }
- it 'returns a new last_update value' do
+ it "returns a new last_update value" do
expect(runner.tick_runner_queue).not_to be_empty
end
end
- describe '#ensure_runner_queue_value' do
+ describe "#ensure_runner_queue_value" do
let(:runner) { create(:ci_runner) }
- it 'sets a new last_update value when it is called the first time' do
+ it "sets a new last_update value when it is called the first time" do
last_update = runner.ensure_runner_queue_value
expect_value_in_queues.to eq(last_update)
end
- it 'does not change if it is not expired and called again' do
+ it "does not change if it is not expired and called again" do
last_update = runner.ensure_runner_queue_value
expect(runner.ensure_runner_queue_value).to eq(last_update)
expect_value_in_queues.to eq(last_update)
end
- context 'updates runner queue after changing editable value' do
+ context "updates runner queue after changing editable value" do
let!(:last_update) { runner.ensure_runner_queue_value }
before do
- Ci::UpdateRunnerService.new(runner).update(description: 'new runner')
+ Ci::UpdateRunnerService.new(runner).update(description: "new runner")
end
- it 'sets a new last_update value' do
+ it "sets a new last_update value" do
expect_value_in_queues.not_to eq(last_update)
end
end
- context 'does not update runner value after save' do
+ context "does not update runner value after save" do
let!(:last_update) { runner.ensure_runner_queue_value }
before do
runner.touch
end
- it 'has an old last_update value' do
+ it "has an old last_update value" do
expect_value_in_queues.to eq(last_update)
end
end
@@ -560,34 +560,34 @@ describe Ci::Runner do
end
end
- describe '#update_cached_info' do
+ describe "#update_cached_info" do
let(:runner) { create(:ci_runner, :project) }
- subject { runner.update_cached_info(architecture: '18-bit') }
+ subject { runner.update_cached_info(architecture: "18-bit") }
- context 'when database was updated recently' do
+ context "when database was updated recently" do
before do
runner.contacted_at = Time.now
end
- it 'updates cache' do
+ it "updates cache" do
expect_redis_update
subject
end
end
- context 'when database was not updated recently' do
+ context "when database was not updated recently" do
before do
runner.contacted_at = 2.hours.ago
end
- context 'with invalid runner' do
+ context "with invalid runner" do
before do
runner.projects = []
end
- it 'still updates redis cache and database' do
+ it "still updates redis cache and database" do
expect(runner).to be_invalid
expect_redis_update
@@ -595,7 +595,7 @@ describe Ci::Runner do
end
end
- it 'updates redis cache and database' do
+ it "updates redis cache and database" do
expect_redis_update
does_db_update
end
@@ -614,10 +614,10 @@ describe Ci::Runner do
end
end
- describe '#destroy' do
+ describe "#destroy" do
let(:runner) { create(:ci_runner) }
- context 'when there is a tick in the queue' do
+ context "when there is a tick in the queue" do
let!(:queue_key) { runner.send(:runner_queue_key) }
before do
@@ -625,7 +625,7 @@ describe Ci::Runner do
runner.destroy
end
- it 'cleans up the queue' do
+ it "cleans up the queue" do
Gitlab::Redis::Queues.with do |redis|
expect(redis.get(queue_key)).to be_nil
end
@@ -633,7 +633,7 @@ describe Ci::Runner do
end
end
- describe '.assignable_for' do
+ describe ".assignable_for" do
let(:project) { create(:project) }
let(:group) { create(:group) }
let(:another_project) { create(:project) }
@@ -642,13 +642,13 @@ describe Ci::Runner do
let!(:group_runner) { create(:ci_runner, :group, groups: [group]) }
let!(:instance_runner) { create(:ci_runner, :instance) }
- context 'with already assigned project' do
+ context "with already assigned project" do
subject { described_class.assignable_for(project) }
it { is_expected.to be_empty }
end
- context 'with a different project' do
+ context "with a different project" do
subject { described_class.assignable_for(another_project) }
it { is_expected.to include(unlocked_project_runner) }
@@ -675,95 +675,95 @@ describe Ci::Runner do
end
end
- describe '#has_tags?' do
- context 'when runner has tags' do
- subject { create(:ci_runner, tag_list: ['tag']) }
+ describe "#has_tags?" do
+ context "when runner has tags" do
+ subject { create(:ci_runner, tag_list: ["tag"]) }
it { is_expected.to have_tags }
end
- context 'when runner does not have tags' do
+ context "when runner does not have tags" do
subject { create(:ci_runner, tag_list: []) }
it { is_expected.not_to have_tags }
end
end
- describe '.search' do
- let(:runner) { create(:ci_runner, token: '123abc', description: 'test runner') }
+ describe ".search" do
+ let(:runner) { create(:ci_runner, token: "123abc", description: "test runner") }
- it 'returns runners with a matching token' do
+ it "returns runners with a matching token" do
expect(described_class.search(runner.token)).to eq([runner])
end
- it 'returns runners with a partially matching token' do
+ it "returns runners with a partially matching token" do
expect(described_class.search(runner.token[0..2])).to eq([runner])
end
- it 'returns runners with a matching token regardless of the casing' do
+ it "returns runners with a matching token regardless of the casing" do
expect(described_class.search(runner.token.upcase)).to eq([runner])
end
- it 'returns runners with a matching description' do
+ it "returns runners with a matching description" do
expect(described_class.search(runner.description)).to eq([runner])
end
- it 'returns runners with a partially matching description' do
+ it "returns runners with a partially matching description" do
expect(described_class.search(runner.description[0..2])).to eq([runner])
end
- it 'returns runners with a matching description regardless of the casing' do
+ it "returns runners with a matching description regardless of the casing" do
expect(described_class.search(runner.description.upcase)).to eq([runner])
end
end
- describe '#assigned_to_group?' do
+ describe "#assigned_to_group?" do
subject { runner.assigned_to_group? }
- context 'when project runner' do
- let(:runner) { create(:ci_runner, :project, description: 'Project runner', projects: [project]) }
+ context "when project runner" do
+ let(:runner) { create(:ci_runner, :project, description: "Project runner", projects: [project]) }
let(:project) { create(:project) }
it { is_expected.to be_falsey }
end
- context 'when shared runner' do
- let(:runner) { create(:ci_runner, :instance, description: 'Shared runner') }
+ context "when shared runner" do
+ let(:runner) { create(:ci_runner, :instance, description: "Shared runner") }
it { is_expected.to be_falsey }
end
- context 'when group runner' do
+ context "when group runner" do
let(:group) { create(:group) }
- let(:runner) { create(:ci_runner, :group, description: 'Group runner', groups: [group]) }
+ let(:runner) { create(:ci_runner, :group, description: "Group runner", groups: [group]) }
it { is_expected.to be_truthy }
end
end
- describe '#assigned_to_project?' do
+ describe "#assigned_to_project?" do
subject { runner.assigned_to_project? }
- context 'when group runner' do
- let(:runner) { create(:ci_runner, :group, description: 'Group runner', groups: [group]) }
+ context "when group runner" do
+ let(:runner) { create(:ci_runner, :group, description: "Group runner", groups: [group]) }
let(:group) { create(:group) }
it { is_expected.to be_falsey }
end
- context 'when shared runner' do
- let(:runner) { create(:ci_runner, :instance, description: 'Shared runner') }
+ context "when shared runner" do
+ let(:runner) { create(:ci_runner, :instance, description: "Shared runner") }
it { is_expected.to be_falsey }
end
- context 'when project runner' do
- let(:runner) { create(:ci_runner, :project, description: 'Project runner', projects: [project]) }
+ context "when project runner" do
+ let(:runner) { create(:ci_runner, :project, description: "Project runner", projects: [project]) }
let(:project) { create(:project) }
it { is_expected.to be_truthy }
end
end
- describe '#pick_build!' do
- context 'runner can pick the build' do
- it 'calls #tick_runner_queue' do
+ describe "#pick_build!" do
+ context "runner can pick the build" do
+ it "calls #tick_runner_queue" do
ci_build = build(:ci_build)
runner = build(:ci_runner)
allow(runner).to receive(:can_pick?).with(ci_build).and_return(true)
@@ -774,8 +774,8 @@ describe Ci::Runner do
end
end
- context 'runner cannot pick the build' do
- it 'does not call #tick_runner_queue' do
+ context "runner cannot pick the build" do
+ it "does not call #tick_runner_queue" do
ci_build = build(:ci_build)
runner = build(:ci_runner)
allow(runner).to receive(:can_pick?).with(ci_build).and_return(false)
@@ -787,38 +787,38 @@ describe Ci::Runner do
end
end
- describe 'project runner without projects is destroyable' do
+ describe "project runner without projects is destroyable" do
subject { create(:ci_runner, :project, :without_projects) }
- it 'does not have projects' do
+ it "does not have projects" do
expect(subject.runner_projects).to be_empty
end
- it 'can be destroyed' do
+ it "can be destroyed" do
subject
expect { subject.destroy }.to change { described_class.count }.by(-1)
end
end
- describe '.order_by' do
- it 'supports ordering by the contact date' do
+ describe ".order_by" do
+ it "supports ordering by the contact date" do
runner1 = create(:ci_runner, contacted_at: 1.year.ago)
runner2 = create(:ci_runner, contacted_at: 1.month.ago)
- runners = described_class.order_by('contacted_asc')
+ runners = described_class.order_by("contacted_asc")
expect(runners).to eq([runner1, runner2])
end
- it 'supports ordering by the creation date' do
+ it "supports ordering by the creation date" do
runner1 = create(:ci_runner, created_at: 1.year.ago)
runner2 = create(:ci_runner, created_at: 1.month.ago)
- runners = described_class.order_by('created_asc')
+ runners = described_class.order_by("created_asc")
expect(runners).to eq([runner2, runner1])
end
end
- describe '#uncached_contacted_at' do
+ describe "#uncached_contacted_at" do
let(:contacted_at_stored) { 1.hour.ago.change(usec: 0) }
let(:runner) { create(:ci_runner, contacted_at: contacted_at_stored) }
diff --git a/spec/models/ci/stage_spec.rb b/spec/models/ci/stage_spec.rb
index 3228c400155..9c2790f8ae7 100644
--- a/spec/models/ci/stage_spec.rb
+++ b/spec/models/ci/stage_spec.rb
@@ -1,122 +1,122 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::Stage, :models do
let(:stage) { create(:ci_stage_entity) }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe 'associations' do
+ describe "associations" do
before do
create(:ci_build, stage_id: stage.id)
create(:commit_status, stage_id: stage.id)
end
- describe '#statuses' do
- it 'returns all commit statuses' do
+ describe "#statuses" do
+ it "returns all commit statuses" do
expect(stage.statuses.count).to be 2
end
end
- describe '#builds' do
- it 'returns only builds' do
+ describe "#builds" do
+ it "returns only builds" do
expect(stage.builds).to be_one
end
end
end
- describe '#status' do
- context 'when stage is pending' do
- let(:stage) { create(:ci_stage_entity, status: 'pending') }
+ describe "#status" do
+ context "when stage is pending" do
+ let(:stage) { create(:ci_stage_entity, status: "pending") }
- it 'has a correct status value' do
- expect(stage.status).to eq 'pending'
+ it "has a correct status value" do
+ expect(stage.status).to eq "pending"
end
end
- context 'when stage is success' do
- let(:stage) { create(:ci_stage_entity, status: 'success') }
+ context "when stage is success" do
+ let(:stage) { create(:ci_stage_entity, status: "success") }
- it 'has a correct status value' do
- expect(stage.status).to eq 'success'
+ it "has a correct status value" do
+ expect(stage.status).to eq "success"
end
end
- context 'when stage status is not defined' do
+ context "when stage status is not defined" do
before do
stage.update_column(:status, nil)
end
- it 'sets the default value' do
+ it "sets the default value" do
expect(described_class.find(stage.id).status)
- .to eq 'created'
+ .to eq "created"
end
end
end
- describe '#update_status' do
- context 'when stage objects needs to be updated' do
+ describe "#update_status" do
+ context "when stage objects needs to be updated" do
before do
create(:ci_build, :success, stage_id: stage.id)
create(:ci_build, :running, stage_id: stage.id)
end
- it 'updates stage status correctly' do
+ it "updates stage status correctly" do
expect { stage.update_status }
.to change { stage.reload.status }
- .to 'running'
+ .to "running"
end
end
- context 'when stage has only created builds' do
+ context "when stage has only created builds" do
let(:stage) { create(:ci_stage_entity, status: :created) }
before do
create(:ci_build, :created, stage_id: stage.id)
end
- it 'updates status to skipped' do
- expect(stage.reload.status).to eq 'created'
+ it "updates status to skipped" do
+ expect(stage.reload.status).to eq "created"
end
end
- context 'when stage is skipped because of skipped builds' do
+ context "when stage is skipped because of skipped builds" do
before do
create(:ci_build, :skipped, stage_id: stage.id)
end
- it 'updates status to skipped' do
+ it "updates status to skipped" do
expect { stage.update_status }
.to change { stage.reload.status }
- .to 'skipped'
+ .to "skipped"
end
end
- context 'when stage is scheduled because of scheduled builds' do
+ context "when stage is scheduled because of scheduled builds" do
before do
create(:ci_build, :scheduled, stage_id: stage.id)
end
- it 'updates status to scheduled' do
+ it "updates status to scheduled" do
expect { stage.update_status }
.to change { stage.reload.status }
- .to 'scheduled'
+ .to "scheduled"
end
end
- context 'when stage is skipped because is empty' do
- it 'updates status to skipped' do
+ context "when stage is skipped because is empty" do
+ it "updates status to skipped" do
expect { stage.update_status }
.to change { stage.reload.status }
- .to 'skipped'
+ .to "skipped"
end
end
- context 'when stage object is locked' do
+ context "when stage object is locked" do
before do
create(:ci_build, :failed, stage_id: stage.id)
end
- it 'retries a lock to update a stage status' do
+ it "retries a lock to update a stage status" do
stage.lock_version = 100
stage.update_status
@@ -125,21 +125,21 @@ describe Ci::Stage, :models do
end
end
- context 'when statuses status was not recognized' do
+ context "when statuses status was not recognized" do
before do
allow(stage)
.to receive_message_chain(:statuses, :latest, :status)
.and_return(:unknown)
end
- it 'raises an exception' do
+ it "raises an exception" do
expect { stage.update_status }
.to raise_error(HasStatus::UnknownStatusError)
end
end
end
- describe '#detailed_status' do
+ describe "#detailed_status" do
using RSpec::Parameterized::TableSyntax
let(:user) { create(:user) }
@@ -168,12 +168,12 @@ describe Ci::Stage, :models do
end
end
- it 'has a correct label' do
+ it "has a correct label" do
expect(subject.label).to eq label.to_s
end
end
- context 'when stage has warnings' do
+ context "when stage has warnings" do
before do
create(:ci_build, project: stage.project,
pipeline: stage.pipeline,
@@ -184,48 +184,48 @@ describe Ci::Stage, :models do
stage.update_status
end
- it 'is passed with warnings' do
- expect(subject.label).to eq 'passed with warnings'
+ it "is passed with warnings" do
+ expect(subject.label).to eq "passed with warnings"
end
end
end
- describe '#groups' do
+ describe "#groups" do
before do
- create(:ci_build, stage_id: stage.id, name: 'rspec 0 1')
- create(:ci_build, stage_id: stage.id, name: 'rspec 0 2')
+ create(:ci_build, stage_id: stage.id, name: "rspec 0 1")
+ create(:ci_build, stage_id: stage.id, name: "rspec 0 2")
end
- it 'groups stage builds by name' do
+ it "groups stage builds by name" do
expect(stage.groups).to be_one
- expect(stage.groups.first.name).to eq 'rspec'
+ expect(stage.groups.first.name).to eq "rspec"
end
end
- describe '#delay' do
+ describe "#delay" do
subject { stage.delay }
let(:stage) { create(:ci_stage_entity, status: :created) }
- it 'updates stage status' do
+ it "updates stage status" do
subject
expect(stage).to be_scheduled
end
end
- describe '#position' do
- context 'when stage has been imported and does not have position index set' do
+ describe "#position" do
+ context "when stage has been imported and does not have position index set" do
before do
stage.update_column(:position, nil)
end
- context 'when stage has statuses' do
+ context "when stage has statuses" do
before do
create(:ci_build, :running, stage_id: stage.id, stage_idx: 10)
end
- it 'recalculates index before updating status' do
+ it "recalculates index before updating status" do
expect(stage.reload.position).to be_nil
stage.update_status
@@ -234,8 +234,8 @@ describe Ci::Stage, :models do
end
end
- context 'when stage does not have statuses' do
- it 'fallbacks to zero' do
+ context "when stage does not have statuses" do
+ it "fallbacks to zero" do
expect(stage.reload.position).to be_nil
stage.update_status
@@ -246,39 +246,39 @@ describe Ci::Stage, :models do
end
end
- context 'when stage has warnings' do
+ context "when stage has warnings" do
before do
create(:ci_build, :failed, :allowed_to_fail, stage_id: stage.id)
end
- describe '#has_warnings?' do
- it 'returns true' do
+ describe "#has_warnings?" do
+ it "returns true" do
expect(stage).to have_warnings
end
end
- describe '#number_of_warnings' do
- it 'returns a lazy stage warnings counter' do
- lazy_queries = ActiveRecord::QueryRecorder.new do
+ describe "#number_of_warnings" do
+ it "returns a lazy stage warnings counter" do
+ lazy_queries = ActiveRecord::QueryRecorder.new {
stage.number_of_warnings
- end
+ }
- synced_queries = ActiveRecord::QueryRecorder.new do
+ synced_queries = ActiveRecord::QueryRecorder.new {
stage.number_of_warnings.to_i
- end
+ }
expect(lazy_queries.count).to eq 0
expect(synced_queries.count).to eq 1
- expect(stage.number_of_warnings.inspect).to include 'BatchLoader'
+ expect(stage.number_of_warnings.inspect).to include "BatchLoader"
expect(stage.number_of_warnings).to eq 1
end
end
end
- context 'when stage does not have warnings' do
- describe '#has_warnings?' do
- it 'returns false' do
+ context "when stage does not have warnings" do
+ describe "#has_warnings?" do
+ it "returns false" do
expect(stage).not_to have_warnings
end
end
diff --git a/spec/models/ci/trigger_request_spec.rb b/spec/models/ci/trigger_request_spec.rb
index 7dcf3528f73..683d3f12d85 100644
--- a/spec/models/ci/trigger_request_spec.rb
+++ b/spec/models/ci/trigger_request_spec.rb
@@ -1,14 +1,14 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::TriggerRequest do
- describe 'validation' do
- it 'be invalid if saving a variable' do
- trigger = build(:ci_trigger_request, variables: { TRIGGER_KEY_1: 'TRIGGER_VALUE_1' } )
+ describe "validation" do
+ it "be invalid if saving a variable" do
+ trigger = build(:ci_trigger_request, variables: {TRIGGER_KEY_1: "TRIGGER_VALUE_1"})
expect(trigger).not_to be_valid
end
- it 'be valid if not saving a variable' do
+ it "be valid if not saving a variable" do
trigger = build(:ci_trigger_request)
expect(trigger).to be_valid
diff --git a/spec/models/ci/trigger_spec.rb b/spec/models/ci/trigger_spec.rb
index d4b72205203..672a1bbbba6 100644
--- a/spec/models/ci/trigger_spec.rb
+++ b/spec/models/ci/trigger_spec.rb
@@ -1,60 +1,60 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::Trigger do
let(:project) { create :project }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:owner) }
it { is_expected.to have_many(:trigger_requests) }
end
- describe 'before_validation' do
- it 'sets an random token if none provided' do
+ describe "before_validation" do
+ it "sets an random token if none provided" do
trigger = create(:ci_trigger_without_token, project: project)
expect(trigger.token).not_to be_nil
end
- it 'does not set a random token if one provided' do
- trigger = create(:ci_trigger, project: project, token: 'token')
+ it "does not set a random token if one provided" do
+ trigger = create(:ci_trigger, project: project, token: "token")
- expect(trigger.token).to eq('token')
+ expect(trigger.token).to eq("token")
end
end
- describe '#short_token' do
- let(:trigger) { create(:ci_trigger, token: '12345678') }
+ describe "#short_token" do
+ let(:trigger) { create(:ci_trigger, token: "12345678") }
subject { trigger.short_token }
- it 'returns shortened token' do
- is_expected.to eq('1234')
+ it "returns shortened token" do
+ is_expected.to eq("1234")
end
end
- describe '#legacy?' do
+ describe "#legacy?" do
let(:trigger) { create(:ci_trigger, owner: owner, project: project) }
subject { trigger }
- context 'when owner is blank' do
+ context "when owner is blank" do
let(:owner) { nil }
it { is_expected.to be_legacy }
end
- context 'when owner is set' do
+ context "when owner is set" do
let(:owner) { create(:user) }
it { is_expected.not_to be_legacy }
end
end
- describe '#can_access_project?' do
+ describe "#can_access_project?" do
let(:trigger) { create(:ci_trigger, owner: owner, project: project) }
- context 'when owner is blank' do
+ context "when owner is blank" do
let(:owner) { nil }
subject { trigger.can_access_project? }
@@ -62,12 +62,12 @@ describe Ci::Trigger do
it { is_expected.to eq(true) }
end
- context 'when owner is set' do
+ context "when owner is set" do
let(:owner) { create(:user) }
subject { trigger.can_access_project? }
- context 'and is member of the project' do
+ context "and is member of the project" do
before do
project.add_developer(owner)
end
@@ -75,7 +75,7 @@ describe Ci::Trigger do
it { is_expected.to eq(true) }
end
- context 'and is not member of the project' do
+ context "and is not member of the project" do
it { is_expected.to eq(false) }
end
end
diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb
index 02c07a2bd83..05d4d9a9ecd 100644
--- a/spec/models/ci/variable_spec.rb
+++ b/spec/models/ci/variable_spec.rb
@@ -1,32 +1,32 @@
-require 'spec_helper'
+require "spec_helper"
describe Ci::Variable do
subject { build(:ci_variable) }
- describe 'validations' do
+ describe "validations" do
it { is_expected.to include_module(HasVariable) }
it { is_expected.to include_module(Presentable) }
it { is_expected.to include_module(Maskable) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id, :environment_scope).with_message(/\(\w+\) has already been taken/) }
end
- describe '.unprotected' do
+ describe ".unprotected" do
subject { described_class.unprotected }
- context 'when variable is protected' do
+ context "when variable is protected" do
before do
create(:ci_variable, :protected)
end
- it 'returns nothing' do
+ it "returns nothing" do
is_expected.to be_empty
end
end
- context 'when variable is not protected' do
+ context "when variable is not protected" do
let(:variable) { create(:ci_variable, protected: false) }
- it 'returns the variable' do
+ it "returns the variable" do
is_expected.to contain_exactly(variable)
end
end
diff --git a/spec/models/clusters/applications/cert_manager_spec.rb b/spec/models/clusters/applications/cert_manager_spec.rb
index cf5cbf8ec5c..8cc0a6b2dc9 100644
--- a/spec/models/clusters/applications/cert_manager_spec.rb
+++ b/spec/models/clusters/applications/cert_manager_spec.rb
@@ -1,40 +1,40 @@
-require 'rails_helper'
+require "rails_helper"
describe Clusters::Applications::CertManager do
let(:cert_manager) { create(:clusters_applications_cert_managers) }
- include_examples 'cluster application core specs', :clusters_applications_cert_managers
- include_examples 'cluster application status specs', :clusters_applications_cert_managers
- include_examples 'cluster application version specs', :clusters_applications_cert_managers
- include_examples 'cluster application initial status specs'
+ include_examples "cluster application core specs", :clusters_applications_cert_managers
+ include_examples "cluster application status specs", :clusters_applications_cert_managers
+ include_examples "cluster application version specs", :clusters_applications_cert_managers
+ include_examples "cluster application initial status specs"
- describe '#install_command' do
- let(:cluster_issuer_file) { { "cluster_issuer.yaml": "---\napiVersion: certmanager.k8s.io/v1alpha1\nkind: ClusterIssuer\nmetadata:\n name: letsencrypt-prod\nspec:\n acme:\n server: https://acme-v02.api.letsencrypt.org/directory\n email: admin@example.com\n privateKeySecretRef:\n name: letsencrypt-prod\n http01: {}\n" } }
+ describe "#install_command" do
+ let(:cluster_issuer_file) { {"cluster_issuer.yaml": "---\napiVersion: certmanager.k8s.io/v1alpha1\nkind: ClusterIssuer\nmetadata:\n name: letsencrypt-prod\nspec:\n acme:\n server: https://acme-v02.api.letsencrypt.org/directory\n email: admin@example.com\n privateKeySecretRef:\n name: letsencrypt-prod\n http01: {}\n"} }
subject { cert_manager.install_command }
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) }
- it 'should be initialized with cert_manager arguments' do
- expect(subject.name).to eq('certmanager')
- expect(subject.chart).to eq('stable/cert-manager')
- expect(subject.version).to eq('v0.5.2')
+ it "should be initialized with cert_manager arguments" do
+ expect(subject.name).to eq("certmanager")
+ expect(subject.chart).to eq("stable/cert-manager")
+ expect(subject.version).to eq("v0.5.2")
expect(subject).to be_rbac
expect(subject.files).to eq(cert_manager.files.merge(cluster_issuer_file))
- expect(subject.postinstall).to eq(['/usr/bin/kubectl create -f /data/helm/certmanager/config/cluster_issuer.yaml'])
+ expect(subject.postinstall).to eq(["/usr/bin/kubectl create -f /data/helm/certmanager/config/cluster_issuer.yaml"])
end
- context 'for a specific user' do
+ context "for a specific user" do
before do
- cert_manager.email = 'abc@xyz.com'
- cluster_issuer_file[:'cluster_issuer.yaml'].gsub! 'admin@example.com', 'abc@xyz.com'
+ cert_manager.email = "abc@xyz.com"
+ cluster_issuer_file[:'cluster_issuer.yaml'].gsub! "admin@example.com", "abc@xyz.com"
end
- it 'should use his/her email to register issuer with certificate provider' do
+ it "should use his/her email to register issuer with certificate provider" do
expect(subject.files).to eq(cert_manager.files.merge(cluster_issuer_file))
end
end
- context 'on a non rbac enabled cluster' do
+ context "on a non rbac enabled cluster" do
before do
cert_manager.cluster.platform_kubernetes.abac!
end
@@ -42,27 +42,27 @@ describe Clusters::Applications::CertManager do
it { is_expected.not_to be_rbac }
end
- context 'application failed to install previously' do
- let(:cert_manager) { create(:clusters_applications_cert_managers, :errored, version: '0.0.1') }
+ context "application failed to install previously" do
+ let(:cert_manager) { create(:clusters_applications_cert_managers, :errored, version: "0.0.1") }
- it 'should be initialized with the locked version' do
- expect(subject.version).to eq('v0.5.2')
+ it "should be initialized with the locked version" do
+ expect(subject.version).to eq("v0.5.2")
end
end
end
- describe '#files' do
+ describe "#files" do
let(:application) { cert_manager }
let(:values) { subject[:'values.yaml'] }
subject { application.files }
- it 'should include cert_manager specific keys in the values.yaml file' do
- expect(values).to include('ingressShim')
+ it "should include cert_manager specific keys in the values.yaml file" do
+ expect(values).to include("ingressShim")
end
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:email) }
end
end
diff --git a/spec/models/clusters/applications/helm_spec.rb b/spec/models/clusters/applications/helm_spec.rb
index f16eff92167..8edd8f199d6 100644
--- a/spec/models/clusters/applications/helm_spec.rb
+++ b/spec/models/clusters/applications/helm_spec.rb
@@ -1,9 +1,9 @@
-require 'rails_helper'
+require "rails_helper"
describe Clusters::Applications::Helm do
- include_examples 'cluster application core specs', :clusters_applications_helm
+ include_examples "cluster application core specs", :clusters_applications_helm
- describe '.available' do
+ describe ".available" do
subject { described_class.available }
let!(:installed_cluster) { create(:clusters_applications_helm, :installed) }
@@ -16,29 +16,29 @@ describe Clusters::Applications::Helm do
it { is_expected.to contain_exactly(installed_cluster, updated_cluster) }
end
- describe '#issue_client_cert' do
+ describe "#issue_client_cert" do
let(:application) { create(:clusters_applications_helm) }
subject { application.issue_client_cert }
- it 'returns a new cert' do
+ it "returns a new cert" do
is_expected.to be_kind_of(Gitlab::Kubernetes::Helm::Certificate)
expect(subject.cert_string).not_to eq(application.ca_cert)
expect(subject.key_string).not_to eq(application.ca_key)
end
end
- describe '#install_command' do
+ describe "#install_command" do
let(:helm) { create(:clusters_applications_helm) }
subject { helm.install_command }
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InitCommand) }
- it 'should be initialized with 1 arguments' do
- expect(subject.name).to eq('helm')
+ it "should be initialized with 1 arguments" do
+ expect(subject.name).to eq("helm")
end
- it 'should have cert files' do
+ it "should have cert files" do
expect(subject.files[:'ca.pem']).to be_present
expect(subject.files[:'ca.pem']).to eq(helm.ca_cert)
@@ -49,12 +49,12 @@ describe Clusters::Applications::Helm do
expect(cert.not_after).to be > 999.years.from_now
end
- describe 'rbac' do
- context 'rbac cluster' do
+ describe "rbac" do
+ context "rbac cluster" do
it { expect(subject).to be_rbac }
end
- context 'non rbac cluster' do
+ context "non rbac cluster" do
before do
helm.cluster.platform_kubernetes.abac!
end
diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb
index d5fd42509a3..64f8e0b628b 100644
--- a/spec/models/clusters/applications/ingress_spec.rb
+++ b/spec/models/clusters/applications/ingress_spec.rb
@@ -1,77 +1,77 @@
-require 'rails_helper'
+require "rails_helper"
describe Clusters::Applications::Ingress do
let(:ingress) { create(:clusters_applications_ingress) }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- include_examples 'cluster application core specs', :clusters_applications_ingress
- include_examples 'cluster application status specs', :clusters_applications_ingress
- include_examples 'cluster application version specs', :clusters_applications_ingress
- include_examples 'cluster application helm specs', :clusters_applications_ingress
- include_examples 'cluster application initial status specs'
+ include_examples "cluster application core specs", :clusters_applications_ingress
+ include_examples "cluster application status specs", :clusters_applications_ingress
+ include_examples "cluster application version specs", :clusters_applications_ingress
+ include_examples "cluster application helm specs", :clusters_applications_ingress
+ include_examples "cluster application initial status specs"
before do
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in)
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async)
end
- describe '#make_installed!' do
+ describe "#make_installed!" do
before do
application.make_installed!
end
let(:application) { create(:clusters_applications_ingress, :installing) }
- it 'schedules a ClusterWaitForIngressIpAddressWorker' do
+ it "schedules a ClusterWaitForIngressIpAddressWorker" do
expect(ClusterWaitForIngressIpAddressWorker).to have_received(:perform_in)
- .with(Clusters::Applications::Ingress::FETCH_IP_ADDRESS_DELAY, 'ingress', application.id)
+ .with(Clusters::Applications::Ingress::FETCH_IP_ADDRESS_DELAY, "ingress", application.id)
end
end
- describe '#schedule_status_update' do
+ describe "#schedule_status_update" do
let(:application) { create(:clusters_applications_ingress, :installed) }
before do
application.schedule_status_update
end
- it 'schedules a ClusterWaitForIngressIpAddressWorker' do
+ it "schedules a ClusterWaitForIngressIpAddressWorker" do
expect(ClusterWaitForIngressIpAddressWorker).to have_received(:perform_async)
- .with('ingress', application.id)
+ .with("ingress", application.id)
end
- context 'when the application is not installed' do
+ context "when the application is not installed" do
let(:application) { create(:clusters_applications_ingress, :installing) }
- it 'does not schedule a ClusterWaitForIngressIpAddressWorker' do
+ it "does not schedule a ClusterWaitForIngressIpAddressWorker" do
expect(ClusterWaitForIngressIpAddressWorker).not_to have_received(:perform_async)
end
end
- context 'when there is already an external_ip' do
- let(:application) { create(:clusters_applications_ingress, :installed, external_ip: '111.222.222.111') }
+ context "when there is already an external_ip" do
+ let(:application) { create(:clusters_applications_ingress, :installed, external_ip: "111.222.222.111") }
- it 'does not schedule a ClusterWaitForIngressIpAddressWorker' do
+ it "does not schedule a ClusterWaitForIngressIpAddressWorker" do
expect(ClusterWaitForIngressIpAddressWorker).not_to have_received(:perform_in)
end
end
end
- describe '#install_command' do
+ describe "#install_command" do
subject { ingress.install_command }
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) }
- it 'should be initialized with ingress arguments' do
- expect(subject.name).to eq('ingress')
- expect(subject.chart).to eq('stable/nginx-ingress')
- expect(subject.version).to eq('1.1.2')
+ it "should be initialized with ingress arguments" do
+ expect(subject.name).to eq("ingress")
+ expect(subject.chart).to eq("stable/nginx-ingress")
+ expect(subject.version).to eq("1.1.2")
expect(subject).to be_rbac
expect(subject.files).to eq(ingress.files)
end
- context 'on a non rbac enabled cluster' do
+ context "on a non rbac enabled cluster" do
before do
ingress.cluster.platform_kubernetes.abac!
end
@@ -79,26 +79,26 @@ describe Clusters::Applications::Ingress do
it { is_expected.not_to be_rbac }
end
- context 'application failed to install previously' do
- let(:ingress) { create(:clusters_applications_ingress, :errored, version: 'nginx') }
+ context "application failed to install previously" do
+ let(:ingress) { create(:clusters_applications_ingress, :errored, version: "nginx") }
- it 'should be initialized with the locked version' do
- expect(subject.version).to eq('1.1.2')
+ it "should be initialized with the locked version" do
+ expect(subject.version).to eq("1.1.2")
end
end
end
- describe '#files' do
+ describe "#files" do
let(:application) { ingress }
let(:values) { subject[:'values.yaml'] }
subject { application.files }
- it 'should include ingress valid keys in values' do
- expect(values).to include('image')
- expect(values).to include('repository')
- expect(values).to include('stats')
- expect(values).to include('podAnnotations')
+ it "should include ingress valid keys in values" do
+ expect(values).to include("image")
+ expect(values).to include("repository")
+ expect(values).to include("stats")
+ expect(values).to include("podAnnotations")
end
end
end
diff --git a/spec/models/clusters/applications/jupyter_spec.rb b/spec/models/clusters/applications/jupyter_spec.rb
index 2c22c24c498..d7e8bc294f8 100644
--- a/spec/models/clusters/applications/jupyter_spec.rb
+++ b/spec/models/clusters/applications/jupyter_spec.rb
@@ -1,51 +1,51 @@
-require 'rails_helper'
+require "rails_helper"
describe Clusters::Applications::Jupyter do
- include_examples 'cluster application core specs', :clusters_applications_jupyter
- include_examples 'cluster application status specs', :clusters_applications_jupyter
- include_examples 'cluster application version specs', :clusters_applications_jupyter
- include_examples 'cluster application helm specs', :clusters_applications_jupyter
+ include_examples "cluster application core specs", :clusters_applications_jupyter
+ include_examples "cluster application status specs", :clusters_applications_jupyter
+ include_examples "cluster application version specs", :clusters_applications_jupyter
+ include_examples "cluster application helm specs", :clusters_applications_jupyter
it { is_expected.to belong_to(:oauth_application) }
- describe '#set_initial_status' do
+ describe "#set_initial_status" do
before do
jupyter.set_initial_status
end
- context 'when ingress is not installed' do
+ context "when ingress is not installed" do
let(:cluster) { create(:cluster, :provided_by_gcp) }
let(:jupyter) { create(:clusters_applications_jupyter, cluster: cluster) }
it { expect(jupyter).to be_not_installable }
end
- context 'when ingress is installed and external_ip is assigned' do
- let(:ingress) { create(:clusters_applications_ingress, :installed, external_ip: '127.0.0.1') }
+ context "when ingress is installed and external_ip is assigned" do
+ let(:ingress) { create(:clusters_applications_ingress, :installed, external_ip: "127.0.0.1") }
let(:jupyter) { create(:clusters_applications_jupyter, cluster: ingress.cluster) }
it { expect(jupyter).to be_installable }
end
end
- describe '#install_command' do
- let!(:ingress) { create(:clusters_applications_ingress, :installed, external_ip: '127.0.0.1') }
+ describe "#install_command" do
+ let!(:ingress) { create(:clusters_applications_ingress, :installed, external_ip: "127.0.0.1") }
let!(:jupyter) { create(:clusters_applications_jupyter, cluster: ingress.cluster) }
subject { jupyter.install_command }
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) }
- it 'should be initialized with 4 arguments' do
- expect(subject.name).to eq('jupyter')
- expect(subject.chart).to eq('jupyter/jupyterhub')
- expect(subject.version).to eq('v0.6')
+ it "should be initialized with 4 arguments" do
+ expect(subject.name).to eq("jupyter")
+ expect(subject.chart).to eq("jupyter/jupyterhub")
+ expect(subject.version).to eq("v0.6")
expect(subject).to be_rbac
- expect(subject.repository).to eq('https://jupyterhub.github.io/helm-chart/')
+ expect(subject.repository).to eq("https://jupyterhub.github.io/helm-chart/")
expect(subject.files).to eq(jupyter.files)
end
- context 'on a non rbac enabled cluster' do
+ context "on a non rbac enabled cluster" do
before do
jupyter.cluster.platform_kubernetes.abac!
end
@@ -53,34 +53,34 @@ describe Clusters::Applications::Jupyter do
it { is_expected.not_to be_rbac }
end
- context 'application failed to install previously' do
- let(:jupyter) { create(:clusters_applications_jupyter, :errored, version: '0.0.1') }
+ context "application failed to install previously" do
+ let(:jupyter) { create(:clusters_applications_jupyter, :errored, version: "0.0.1") }
- it 'should be initialized with the locked version' do
- expect(subject.version).to eq('v0.6')
+ it "should be initialized with the locked version" do
+ expect(subject.version).to eq("v0.6")
end
end
end
- describe '#files' do
+ describe "#files" do
let(:application) { create(:clusters_applications_jupyter) }
let(:values) { subject[:'values.yaml'] }
subject { application.files }
- it 'should include valid values' do
- expect(values).to include('ingress')
- expect(values).to include('hub')
- expect(values).to include('rbac')
- expect(values).to include('proxy')
- expect(values).to include('auth')
- expect(values).to include('singleuser')
+ it "should include valid values" do
+ expect(values).to include("ingress")
+ expect(values).to include("hub")
+ expect(values).to include("rbac")
+ expect(values).to include("proxy")
+ expect(values).to include("auth")
+ expect(values).to include("singleuser")
expect(values).to match(/clientId: '?#{application.oauth_application.uid}/)
expect(values).to match(/callbackUrl: '?#{application.callback_url}/)
end
- context 'when cluster belongs to a project' do
- it 'sets GitLab project id' do
+ context "when cluster belongs to a project" do
+ it "sets GitLab project id" do
expect(values).to match(/GITLAB_CLUSTER_ID: '?#{application.cluster.id}/)
end
end
diff --git a/spec/models/clusters/applications/knative_spec.rb b/spec/models/clusters/applications/knative_spec.rb
index 006b922ab27..fa051dfc61e 100644
--- a/spec/models/clusters/applications/knative_spec.rb
+++ b/spec/models/clusters/applications/knative_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
describe Clusters::Applications::Knative do
include KubernetesHelpers
@@ -6,91 +6,91 @@ describe Clusters::Applications::Knative do
let(:knative) { create(:clusters_applications_knative) }
- include_examples 'cluster application core specs', :clusters_applications_knative
- include_examples 'cluster application status specs', :clusters_applications_knative
- include_examples 'cluster application helm specs', :clusters_applications_knative
- include_examples 'cluster application version specs', :clusters_applications_knative
- include_examples 'cluster application initial status specs'
+ include_examples "cluster application core specs", :clusters_applications_knative
+ include_examples "cluster application status specs", :clusters_applications_knative
+ include_examples "cluster application helm specs", :clusters_applications_knative
+ include_examples "cluster application version specs", :clusters_applications_knative
+ include_examples "cluster application initial status specs"
before do
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in)
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async)
end
- describe 'when rbac is not enabled' do
+ describe "when rbac is not enabled" do
let(:cluster) { create(:cluster, :provided_by_gcp, :rbac_disabled) }
let(:knative_no_rbac) { create(:clusters_applications_knative, cluster: cluster) }
it { expect(knative_no_rbac).to be_not_installable }
end
- describe 'make_installed with external_ip' do
+ describe "make_installed with external_ip" do
before do
application.make_installed!
end
let(:application) { create(:clusters_applications_knative, :installing) }
- it 'schedules a ClusterWaitForIngressIpAddressWorker' do
+ it "schedules a ClusterWaitForIngressIpAddressWorker" do
expect(ClusterWaitForIngressIpAddressWorker).to have_received(:perform_in)
- .with(Clusters::Applications::Knative::FETCH_IP_ADDRESS_DELAY, 'knative', application.id)
+ .with(Clusters::Applications::Knative::FETCH_IP_ADDRESS_DELAY, "knative", application.id)
end
end
- describe '#schedule_status_update with external_ip' do
+ describe "#schedule_status_update with external_ip" do
let(:application) { create(:clusters_applications_knative, :installed) }
before do
application.schedule_status_update
end
- it 'schedules a ClusterWaitForIngressIpAddressWorker' do
+ it "schedules a ClusterWaitForIngressIpAddressWorker" do
expect(ClusterWaitForIngressIpAddressWorker).to have_received(:perform_async)
- .with('knative', application.id)
+ .with("knative", application.id)
end
- context 'when the application is not installed' do
+ context "when the application is not installed" do
let(:application) { create(:clusters_applications_knative, :installing) }
- it 'does not schedule a ClusterWaitForIngressIpAddressWorker' do
+ it "does not schedule a ClusterWaitForIngressIpAddressWorker" do
expect(ClusterWaitForIngressIpAddressWorker).not_to have_received(:perform_async)
end
end
- context 'when there is already an external_ip' do
- let(:application) { create(:clusters_applications_knative, :installed, external_ip: '111.222.222.111') }
+ context "when there is already an external_ip" do
+ let(:application) { create(:clusters_applications_knative, :installed, external_ip: "111.222.222.111") }
- it 'does not schedule a ClusterWaitForIngressIpAddressWorker' do
+ it "does not schedule a ClusterWaitForIngressIpAddressWorker" do
expect(ClusterWaitForIngressIpAddressWorker).not_to have_received(:perform_in)
end
end
end
- describe '#install_command' do
+ describe "#install_command" do
subject { knative.install_command }
- it 'should be an instance of Helm::InstallCommand' do
+ it "should be an instance of Helm::InstallCommand" do
expect(subject).to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand)
end
- it 'should be initialized with knative arguments' do
- expect(subject.name).to eq('knative')
- expect(subject.chart).to eq('knative/knative')
- expect(subject.version).to eq('0.2.2')
+ it "should be initialized with knative arguments" do
+ expect(subject.name).to eq("knative")
+ expect(subject.chart).to eq("knative/knative")
+ expect(subject.version).to eq("0.2.2")
expect(subject.files).to eq(knative.files)
end
- it 'should not install metrics for prometheus' do
+ it "should not install metrics for prometheus" do
expect(subject.postinstall).to be_nil
end
- context 'with prometheus installed' do
+ context "with prometheus installed" do
let(:prometheus) { create(:clusters_applications_prometheus, :installed) }
let(:knative) { create(:clusters_applications_knative, cluster: prometheus.cluster) }
subject { knative.install_command }
- it 'should install metrics' do
+ it "should install metrics" do
expect(subject.postinstall).not_to be_nil
expect(subject.postinstall.length).to be(1)
expect(subject.postinstall[0]).to eql("kubectl apply -f #{Clusters::Applications::Knative::METRICS_CONFIG}")
@@ -98,22 +98,22 @@ describe Clusters::Applications::Knative do
end
end
- describe '#files' do
+ describe "#files" do
let(:application) { knative }
let(:values) { subject[:'values.yaml'] }
subject { application.files }
- it 'should include knative specific keys in the values.yaml file' do
- expect(values).to include('domain')
+ it "should include knative specific keys in the values.yaml file" do
+ expect(values).to include("domain")
end
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:hostname) }
end
- describe '#service_pod_details' do
+ describe "#service_pod_details" do
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:service) { cluster.platform_kubernetes }
let(:knative) { create(:clusters_applications_knative, cluster: cluster) }
@@ -132,17 +132,17 @@ describe Clusters::Applications::Knative do
stub_reactive_cache(knative,
{
services: kube_response(kube_knative_services_body),
- pods: kube_response(kube_knative_pods_body(cluster.cluster_project.project.name, namespace.namespace))
+ pods: kube_response(kube_knative_pods_body(cluster.cluster_project.project.name, namespace.namespace)),
})
synchronous_reactive_cache(knative)
end
- it 'should be able k8s core for pod details' do
+ it "should be able k8s core for pod details" do
expect(knative.service_pod_details(namespace.namespace, cluster.cluster_project.project.name)).not_to be_nil
end
end
- describe '#services' do
+ describe "#services" do
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:service) { cluster.platform_kubernetes }
let(:knative) { create(:clusters_applications_knative, cluster: cluster) }
@@ -162,25 +162,25 @@ describe Clusters::Applications::Knative do
stub_kubeclient_service_pods
end
- it 'should have an unintialized cache' do
+ it "should have an unintialized cache" do
is_expected.to be_nil
end
- context 'when using synchronous reactive cache' do
+ context "when using synchronous reactive cache" do
before do
stub_reactive_cache(knative,
{
services: kube_response(kube_knative_services_body),
- pods: kube_response(kube_knative_pods_body(cluster.cluster_project.project.name, namespace.namespace))
+ pods: kube_response(kube_knative_pods_body(cluster.cluster_project.project.name, namespace.namespace)),
})
synchronous_reactive_cache(knative)
end
- it 'should have cached services' do
+ it "should have cached services" do
is_expected.not_to be_nil
end
- it 'should match our namespace' do
+ it "should match our namespace" do
expect(knative.services_for(ns: namespace)).not_to be_nil
end
end
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb
index 81708b0c2ed..f242522f20a 100644
--- a/spec/models/clusters/applications/prometheus_spec.rb
+++ b/spec/models/clusters/applications/prometheus_spec.rb
@@ -1,35 +1,35 @@
-require 'rails_helper'
+require "rails_helper"
describe Clusters::Applications::Prometheus do
include KubernetesHelpers
- include_examples 'cluster application core specs', :clusters_applications_prometheus
- include_examples 'cluster application status specs', :clusters_applications_prometheus
- include_examples 'cluster application version specs', :clusters_applications_prometheus
- include_examples 'cluster application helm specs', :clusters_applications_prometheus
- include_examples 'cluster application initial status specs'
+ include_examples "cluster application core specs", :clusters_applications_prometheus
+ include_examples "cluster application status specs", :clusters_applications_prometheus
+ include_examples "cluster application version specs", :clusters_applications_prometheus
+ include_examples "cluster application helm specs", :clusters_applications_prometheus
+ include_examples "cluster application initial status specs"
- describe 'transition to installed' do
+ describe "transition to installed" do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) }
- let(:prometheus_service) { double('prometheus_service') }
+ let(:prometheus_service) { double("prometheus_service") }
subject { create(:clusters_applications_prometheus, :installing, cluster: cluster) }
before do
- allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_service
+ allow(project).to receive(:find_or_initialize_service).with("prometheus").and_return prometheus_service
end
- it 'ensures Prometheus service is activated' do
+ it "ensures Prometheus service is activated" do
expect(prometheus_service).to receive(:update).with(active: true)
subject.make_installed
end
end
- describe '#prometheus_client' do
- context 'cluster is nil' do
- it 'returns nil' do
+ describe "#prometheus_client" do
+ context "cluster is nil" do
+ it "returns nil" do
expect(subject.cluster).to be_nil
expect(subject.prometheus_client).to be_nil
end
@@ -39,12 +39,12 @@ describe Clusters::Applications::Prometheus do
let(:cluster) { create(:cluster) }
subject { create(:clusters_applications_prometheus, cluster: cluster) }
- it 'returns nil' do
+ it "returns nil" do
expect(subject.prometheus_client).to be_nil
end
end
- context 'cluster has kubeclient' do
+ context "cluster has kubeclient" do
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:kubernetes_url) { subject.cluster.platform_kubernetes.api_url }
let(:kube_client) { subject.cluster.kubeclient.core_client }
@@ -52,55 +52,55 @@ describe Clusters::Applications::Prometheus do
subject { create(:clusters_applications_prometheus, cluster: cluster) }
before do
- subject.cluster.platform_kubernetes.namespace = 'a-namespace'
+ subject.cluster.platform_kubernetes.namespace = "a-namespace"
stub_kubeclient_discover(cluster.platform_kubernetes.api_url)
create(:cluster_kubernetes_namespace,
- cluster: cluster,
- cluster_project: cluster.cluster_project,
- project: cluster.cluster_project.project)
+ cluster: cluster,
+ cluster_project: cluster.cluster_project,
+ project: cluster.cluster_project.project)
end
- it 'creates proxy prometheus rest client' do
+ it "creates proxy prometheus rest client" do
expect(subject.prometheus_client).to be_instance_of(RestClient::Resource)
end
- it 'creates proper url' do
+ it "creates proper url" do
expect(subject.prometheus_client.url).to eq("#{kubernetes_url}/api/v1/namespaces/gitlab-managed-apps/services/prometheus-prometheus-server:80/proxy")
end
- it 'copies options and headers from kube client to proxy client' do
+ it "copies options and headers from kube client to proxy client" do
expect(subject.prometheus_client.options).to eq(kube_client.rest_client.options.merge(headers: kube_client.headers))
end
- context 'when cluster is not reachable' do
+ context "when cluster is not reachable" do
before do
- allow(kube_client).to receive(:proxy_url).and_raise(Kubeclient::HttpError.new(401, 'Unauthorized', nil))
+ allow(kube_client).to receive(:proxy_url).and_raise(Kubeclient::HttpError.new(401, "Unauthorized", nil))
end
- it 'returns nil' do
+ it "returns nil" do
expect(subject.prometheus_client).to be_nil
end
end
end
end
- describe '#install_command' do
+ describe "#install_command" do
let(:prometheus) { create(:clusters_applications_prometheus) }
subject { prometheus.install_command }
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) }
- it 'should be initialized with 3 arguments' do
- expect(subject.name).to eq('prometheus')
- expect(subject.chart).to eq('stable/prometheus')
- expect(subject.version).to eq('6.7.3')
+ it "should be initialized with 3 arguments" do
+ expect(subject.name).to eq("prometheus")
+ expect(subject.chart).to eq("stable/prometheus")
+ expect(subject.version).to eq("6.7.3")
expect(subject).to be_rbac
expect(subject.files).to eq(prometheus.files)
end
- context 'on a non rbac enabled cluster' do
+ context "on a non rbac enabled cluster" do
before do
prometheus.cluster.platform_kubernetes.abac!
end
@@ -108,51 +108,51 @@ describe Clusters::Applications::Prometheus do
it { is_expected.not_to be_rbac }
end
- context 'application failed to install previously' do
- let(:prometheus) { create(:clusters_applications_prometheus, :errored, version: '2.0.0') }
+ context "application failed to install previously" do
+ let(:prometheus) { create(:clusters_applications_prometheus, :errored, version: "2.0.0") }
- it 'should be initialized with the locked version' do
- expect(subject.version).to eq('6.7.3')
+ it "should be initialized with the locked version" do
+ expect(subject.version).to eq("6.7.3")
end
end
- it 'should not install knative metrics' do
+ it "should not install knative metrics" do
expect(subject.postinstall).to be_nil
end
- context 'with knative installed' do
- let(:knative) { create(:clusters_applications_knative, :updated ) }
+ context "with knative installed" do
+ let(:knative) { create(:clusters_applications_knative, :updated) }
let(:prometheus) { create(:clusters_applications_prometheus, cluster: knative.cluster) }
subject { prometheus.install_command }
- it 'should install knative metrics' do
+ it "should install knative metrics" do
expect(subject.postinstall).to include("kubectl apply -f #{Clusters::Applications::Knative::METRICS_CONFIG}")
end
end
end
- describe '#upgrade_command' do
+ describe "#upgrade_command" do
let(:prometheus) { build(:clusters_applications_prometheus) }
let(:values) { prometheus.values }
- it 'returns an instance of Gitlab::Kubernetes::Helm::InstallCommand' do
+ it "returns an instance of Gitlab::Kubernetes::Helm::InstallCommand" do
expect(prometheus.upgrade_command(values)).to be_an_instance_of(::Gitlab::Kubernetes::Helm::InstallCommand)
end
- it 'should be initialized with 3 arguments' do
+ it "should be initialized with 3 arguments" do
command = prometheus.upgrade_command(values)
- expect(command.name).to eq('prometheus')
- expect(command.chart).to eq('stable/prometheus')
- expect(command.version).to eq('6.7.3')
+ expect(command.name).to eq("prometheus")
+ expect(command.chart).to eq("stable/prometheus")
+ expect(command.version).to eq("6.7.3")
expect(command.files).to eq(prometheus.files)
end
end
- describe '#update_in_progress?' do
- context 'when app is updating' do
- it 'returns true' do
+ describe "#update_in_progress?" do
+ context "when app is updating" do
+ it "returns true" do
cluster = create(:cluster)
prometheus_app = build(:clusters_applications_prometheus, :updating, cluster: cluster)
@@ -161,9 +161,9 @@ describe Clusters::Applications::Prometheus do
end
end
- describe '#update_errored?' do
- context 'when app errored' do
- it 'returns true' do
+ describe "#update_errored?" do
+ context "when app errored" do
+ it "returns true" do
cluster = create(:cluster)
prometheus_app = build(:clusters_applications_prometheus, :update_errored, cluster: cluster)
@@ -172,37 +172,37 @@ describe Clusters::Applications::Prometheus do
end
end
- describe '#files' do
+ describe "#files" do
let(:application) { create(:clusters_applications_prometheus) }
let(:values) { subject[:'values.yaml'] }
subject { application.files }
- it 'should include prometheus valid values' do
- expect(values).to include('alertmanager')
- expect(values).to include('kubeStateMetrics')
- expect(values).to include('nodeExporter')
- expect(values).to include('pushgateway')
- expect(values).to include('serverFiles')
+ it "should include prometheus valid values" do
+ expect(values).to include("alertmanager")
+ expect(values).to include("kubeStateMetrics")
+ expect(values).to include("nodeExporter")
+ expect(values).to include("pushgateway")
+ expect(values).to include("serverFiles")
end
end
- describe '#files_with_replaced_values' do
+ describe "#files_with_replaced_values" do
let(:application) { build(:clusters_applications_prometheus) }
let(:files) { application.files }
- subject { application.files_with_replaced_values({ hello: :world }) }
+ subject { application.files_with_replaced_values({hello: :world}) }
- it 'does not modify #files' do
+ it "does not modify #files" do
expect(subject[:'values.yaml']).not_to eq(files)
expect(files[:'values.yaml']).to eq(application.values)
end
- it 'returns values.yaml with replaced values' do
- expect(subject[:'values.yaml']).to eq({ hello: :world })
+ it "returns values.yaml with replaced values" do
+ expect(subject[:'values.yaml']).to eq({hello: :world})
end
- it 'should include cert files' do
+ it "should include cert files" do
expect(subject[:'ca.pem']).to be_present
expect(subject[:'ca.pem']).to eq(application.cluster.application_helm.ca_cert)
@@ -213,12 +213,12 @@ describe Clusters::Applications::Prometheus do
expect(cert.not_after).to be < 60.minutes.from_now
end
- context 'when the helm application does not have a ca_cert' do
+ context "when the helm application does not have a ca_cert" do
before do
application.cluster.application_helm.ca_cert = nil
end
- it 'should not include cert files' do
+ it "should not include cert files" do
expect(subject[:'ca.pem']).not_to be_present
expect(subject[:'cert.pem']).not_to be_present
expect(subject[:'key.pem']).not_to be_present
diff --git a/spec/models/clusters/applications/runner_spec.rb b/spec/models/clusters/applications/runner_spec.rb
index 6972fc03415..0235e828b29 100644
--- a/spec/models/clusters/applications/runner_spec.rb
+++ b/spec/models/clusters/applications/runner_spec.rb
@@ -1,34 +1,34 @@
-require 'rails_helper'
+require "rails_helper"
describe Clusters::Applications::Runner do
let(:ci_runner) { create(:ci_runner) }
- include_examples 'cluster application core specs', :clusters_applications_runner
- include_examples 'cluster application status specs', :clusters_applications_runner
- include_examples 'cluster application version specs', :clusters_applications_runner
- include_examples 'cluster application helm specs', :clusters_applications_runner
- include_examples 'cluster application initial status specs'
+ include_examples "cluster application core specs", :clusters_applications_runner
+ include_examples "cluster application status specs", :clusters_applications_runner
+ include_examples "cluster application version specs", :clusters_applications_runner
+ include_examples "cluster application helm specs", :clusters_applications_runner
+ include_examples "cluster application initial status specs"
it { is_expected.to belong_to(:runner) }
- describe '#install_command' do
- let(:kubeclient) { double('kubernetes client') }
+ describe "#install_command" do
+ let(:kubeclient) { double("kubernetes client") }
let(:gitlab_runner) { create(:clusters_applications_runner, runner: ci_runner) }
subject { gitlab_runner.install_command }
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) }
- it 'should be initialized with 4 arguments' do
- expect(subject.name).to eq('runner')
- expect(subject.chart).to eq('runner/gitlab-runner')
- expect(subject.version).to eq('0.2.0')
+ it "should be initialized with 4 arguments" do
+ expect(subject.name).to eq("runner")
+ expect(subject.chart).to eq("runner/gitlab-runner")
+ expect(subject.version).to eq("0.2.0")
expect(subject).to be_rbac
- expect(subject.repository).to eq('https://charts.gitlab.io')
+ expect(subject.repository).to eq("https://charts.gitlab.io")
expect(subject.files).to eq(gitlab_runner.files)
end
- context 'on a non rbac enabled cluster' do
+ context "on a non rbac enabled cluster" do
before do
gitlab_runner.cluster.platform_kubernetes.abac!
end
@@ -36,62 +36,62 @@ describe Clusters::Applications::Runner do
it { is_expected.not_to be_rbac }
end
- context 'application failed to install previously' do
- let(:gitlab_runner) { create(:clusters_applications_runner, :errored, runner: ci_runner, version: '0.1.13') }
+ context "application failed to install previously" do
+ let(:gitlab_runner) { create(:clusters_applications_runner, :errored, runner: ci_runner, version: "0.1.13") }
- it 'should be initialized with the locked version' do
- expect(subject.version).to eq('0.2.0')
+ it "should be initialized with the locked version" do
+ expect(subject.version).to eq("0.2.0")
end
end
end
- describe '#files' do
+ describe "#files" do
let(:application) { create(:clusters_applications_runner, runner: ci_runner) }
let(:values) { subject[:'values.yaml'] }
subject { application.files }
- it 'should include runner valid values' do
- expect(values).to include('concurrent')
- expect(values).to include('checkInterval')
- expect(values).to include('rbac')
- expect(values).to include('runners')
- expect(values).to include('privileged: true')
- expect(values).to include('image: ubuntu:16.04')
- expect(values).to include('resources')
+ it "should include runner valid values" do
+ expect(values).to include("concurrent")
+ expect(values).to include("checkInterval")
+ expect(values).to include("rbac")
+ expect(values).to include("runners")
+ expect(values).to include("privileged: true")
+ expect(values).to include("image: ubuntu:16.04")
+ expect(values).to include("resources")
expect(values).to match(/runnerToken: '?#{ci_runner.token}/)
expect(values).to match(/gitlabUrl: '?#{Gitlab::Routing.url_helpers.root_url}/)
end
- context 'without a runner' do
+ context "without a runner" do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) }
let(:application) { create(:clusters_applications_runner, runner: nil, cluster: cluster) }
- it 'creates a runner' do
- expect do
+ it "creates a runner" do
+ expect {
subject
- end.to change { Ci::Runner.count }.by(1)
+ }.to change { Ci::Runner.count }.by(1)
end
- it 'uses the new runner token' do
+ it "uses the new runner token" do
expect(values).to match(/runnerToken: '?#{application.reload.runner.token}/)
end
- it 'assigns the new runner to runner' do
+ it "assigns the new runner to runner" do
subject
expect(application.reload.runner).to be_project_type
end
end
- context 'with duplicated values on vendor/runner/values.yaml' do
+ context "with duplicated values on vendor/runner/values.yaml" do
let(:stub_values) do
{
"concurrent" => 4,
"checkInterval" => 3,
"rbac" => {
- "create" => false
+ "create" => false,
},
"clusterWideAccess" => false,
"runners" => {
@@ -99,8 +99,8 @@ describe Clusters::Applications::Runner do
"image" => "ubuntu:16.04",
"builds" => {},
"services" => {},
- "helpers" => {}
- }
+ "helpers" => {},
+ },
}
end
@@ -108,7 +108,7 @@ describe Clusters::Applications::Runner do
allow(application).to receive(:chart_values).and_return(stub_values)
end
- it 'should overwrite values.yaml' do
+ it "should overwrite values.yaml" do
expect(values).to match(/privileged: '?#{application.privileged}/)
end
end
diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb
index 3feed4e9718..fad9ec37873 100644
--- a/spec/models/clusters/cluster_spec.rb
+++ b/spec/models/clusters/cluster_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe Clusters::Cluster do
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
it { is_expected.to belong_to(:user) }
it { is_expected.to have_many(:cluster_projects) }
@@ -34,7 +34,7 @@ describe Clusters::Cluster do
it { is_expected.to respond_to :project }
- describe '.enabled' do
+ describe ".enabled" do
subject { described_class.enabled }
let!(:cluster) { create(:cluster, enabled: true) }
@@ -46,7 +46,7 @@ describe Clusters::Cluster do
it { is_expected.to contain_exactly(cluster) }
end
- describe '.disabled' do
+ describe ".disabled" do
subject { described_class.disabled }
let!(:cluster) { create(:cluster, enabled: false) }
@@ -58,7 +58,7 @@ describe Clusters::Cluster do
it { is_expected.to contain_exactly(cluster) }
end
- describe '.user_provided' do
+ describe ".user_provided" do
subject { described_class.user_provided }
let!(:cluster) { create(:cluster, :provided_by_user) }
@@ -70,7 +70,7 @@ describe Clusters::Cluster do
it { is_expected.to contain_exactly(cluster) }
end
- describe '.gcp_provided' do
+ describe ".gcp_provided" do
subject { described_class.gcp_provided }
let!(:cluster) { create(:cluster, :provided_by_gcp) }
@@ -82,7 +82,7 @@ describe Clusters::Cluster do
it { is_expected.to contain_exactly(cluster) }
end
- describe '.gcp_installed' do
+ describe ".gcp_installed" do
subject { described_class.gcp_installed }
let!(:cluster) { create(:cluster, :provided_by_gcp) }
@@ -94,18 +94,18 @@ describe Clusters::Cluster do
it { is_expected.to contain_exactly(cluster) }
end
- describe '.missing_kubernetes_namespace' do
+ describe ".missing_kubernetes_namespace" do
let!(:cluster) { create(:cluster, :provided_by_gcp, :project) }
let(:project) { cluster.project }
let(:kubernetes_namespaces) { project.kubernetes_namespaces }
subject do
- described_class.joins(:projects).where(projects: { id: project.id }).missing_kubernetes_namespace(kubernetes_namespaces)
+ described_class.joins(:projects).where(projects: {id: project.id}).missing_kubernetes_namespace(kubernetes_namespaces)
end
it { is_expected.to contain_exactly(cluster) }
- context 'kubernetes namespace exists' do
+ context "kubernetes namespace exists" do
before do
create(:cluster_kubernetes_namespace, project: project, cluster: cluster)
end
@@ -114,75 +114,75 @@ describe Clusters::Cluster do
end
end
- describe 'validations' do
+ describe "validations" do
subject { cluster.valid? }
- context 'when validates name' do
- context 'when provided by user' do
+ context "when validates name" do
+ context "when provided by user" do
let!(:cluster) { build(:cluster, :provided_by_user, name: name) }
- context 'when name is empty' do
- let(:name) { '' }
+ context "when name is empty" do
+ let(:name) { "" }
it { is_expected.to be_falsey }
end
- context 'when name is nil' do
+ context "when name is nil" do
let(:name) { nil }
it { is_expected.to be_falsey }
end
- context 'when name is present' do
- let(:name) { 'cluster-name-1' }
+ context "when name is present" do
+ let(:name) { "cluster-name-1" }
it { is_expected.to be_truthy }
end
end
- context 'when provided by gcp' do
+ context "when provided by gcp" do
let!(:cluster) { build(:cluster, :provided_by_gcp, name: name) }
- context 'when name is shorter than 1' do
- let(:name) { '' }
+ context "when name is shorter than 1" do
+ let(:name) { "" }
it { is_expected.to be_falsey }
end
- context 'when name is longer than 63' do
- let(:name) { 'a' * 64 }
+ context "when name is longer than 63" do
+ let(:name) { "a" * 64 }
it { is_expected.to be_falsey }
end
- context 'when name includes invalid character' do
- let(:name) { '!!!!!!' }
+ context "when name includes invalid character" do
+ let(:name) { "!!!!!!" }
it { is_expected.to be_falsey }
end
- context 'when name is present' do
- let(:name) { 'cluster-name-1' }
+ context "when name is present" do
+ let(:name) { "cluster-name-1" }
it { is_expected.to be_truthy }
end
- context 'when record is persisted' do
- let(:name) { 'cluster-name-1' }
+ context "when record is persisted" do
+ let(:name) { "cluster-name-1" }
before do
cluster.save!
end
- context 'when name is changed' do
+ context "when name is changed" do
before do
- cluster.name = 'new-cluster-name'
+ cluster.name = "new-cluster-name"
end
it { is_expected.to be_falsey }
end
- context 'when name is same' do
+ context "when name is same" do
before do
cluster.name = name
end
@@ -193,94 +193,94 @@ describe Clusters::Cluster do
end
end
- context 'when validates restrict_modification' do
- context 'when creation is on going' do
+ context "when validates restrict_modification" do
+ context "when creation is on going" do
let!(:cluster) { create(:cluster, :providing_by_gcp) }
it { expect(cluster.update(enabled: false)).to be_falsey }
end
- context 'when creation is done' do
+ context "when creation is done" do
let!(:cluster) { create(:cluster, :provided_by_gcp) }
it { expect(cluster.update(enabled: false)).to be_truthy }
end
end
- describe 'cluster_type validations' do
+ describe "cluster_type validations" do
let(:instance_cluster) { create(:cluster, :instance) }
let(:group_cluster) { create(:cluster, :group) }
let(:project_cluster) { create(:cluster, :project) }
- it 'validates presence' do
+ it "validates presence" do
cluster = build(:cluster, :project, cluster_type: nil)
expect(cluster).not_to be_valid
expect(cluster.errors.full_messages).to include("Cluster type can't be blank")
end
- context 'project_type cluster' do
- it 'does not allow setting group' do
+ context "project_type cluster" do
+ it "does not allow setting group" do
project_cluster.groups << build(:group)
expect(project_cluster).not_to be_valid
- expect(project_cluster.errors.full_messages).to include('Cluster cannot have groups assigned')
+ expect(project_cluster.errors.full_messages).to include("Cluster cannot have groups assigned")
end
end
- context 'group_type cluster' do
- it 'does not allow setting project' do
+ context "group_type cluster" do
+ it "does not allow setting project" do
group_cluster.projects << build(:project)
expect(group_cluster).not_to be_valid
- expect(group_cluster.errors.full_messages).to include('Cluster cannot have projects assigned')
+ expect(group_cluster.errors.full_messages).to include("Cluster cannot have projects assigned")
end
end
- context 'instance_type cluster' do
- it 'does not allow setting group' do
+ context "instance_type cluster" do
+ it "does not allow setting group" do
instance_cluster.groups << build(:group)
expect(instance_cluster).not_to be_valid
- expect(instance_cluster.errors.full_messages).to include('Cluster cannot have groups assigned')
+ expect(instance_cluster.errors.full_messages).to include("Cluster cannot have groups assigned")
end
- it 'does not allow setting project' do
+ it "does not allow setting project" do
instance_cluster.projects << build(:project)
expect(instance_cluster).not_to be_valid
- expect(instance_cluster.errors.full_messages).to include('Cluster cannot have projects assigned')
+ expect(instance_cluster.errors.full_messages).to include("Cluster cannot have projects assigned")
end
end
end
- describe 'domain validation' do
+ describe "domain validation" do
let(:cluster) { build(:cluster) }
subject { cluster }
- context 'when cluster has domain' do
+ context "when cluster has domain" do
let(:cluster) { build(:cluster, :with_domain) }
it { is_expected.to be_valid }
end
- context 'when cluster is not a valid hostname' do
- let(:cluster) { build(:cluster, domain: 'http://not.a.valid.hostname') }
+ context "when cluster is not a valid hostname" do
+ let(:cluster) { build(:cluster, domain: "http://not.a.valid.hostname") }
- it 'should add an error on domain' do
+ it "should add an error on domain" do
expect(subject).not_to be_valid
expect(subject.errors[:domain].first).to eq('contains invalid characters (valid characters: [a-z0-9\\-])')
end
end
- context 'when cluster does not have a domain' do
+ context "when cluster does not have a domain" do
it { is_expected.to be_valid }
end
end
end
- describe '.ancestor_clusters_for_clusterable' do
+ describe ".ancestor_clusters_for_clusterable" do
let(:group_cluster) { create(:cluster, :provided_by_gcp, :group) }
let(:group) { group_cluster.group }
let(:hierarchy_order) { :desc }
@@ -290,23 +290,23 @@ describe Clusters::Cluster do
described_class.ancestor_clusters_for_clusterable(clusterable, hierarchy_order: hierarchy_order)
end
- context 'when project does not belong to this group' do
+ context "when project does not belong to this group" do
let(:project) { create(:project, group: create(:group)) }
- it 'returns nothing' do
+ it "returns nothing" do
is_expected.to be_empty
end
end
- context 'when group has a configured kubernetes cluster' do
+ context "when group has a configured kubernetes cluster" do
let(:project) { create(:project, group: group) }
- it 'returns the group cluster' do
+ it "returns the group cluster" do
is_expected.to eq([group_cluster])
end
end
- context 'when sub-group has configured kubernetes cluster', :nested_groups do
+ context "when sub-group has configured kubernetes cluster", :nested_groups do
let(:sub_group_cluster) { create(:cluster, :provided_by_gcp, :group) }
let(:sub_group) { sub_group_cluster.group }
let(:project) { create(:project, group: sub_group) }
@@ -315,149 +315,149 @@ describe Clusters::Cluster do
sub_group.update!(parent: group)
end
- it 'returns clusters in order, descending the hierachy' do
+ it "returns clusters in order, descending the hierachy" do
is_expected.to eq([group_cluster, sub_group_cluster])
end
- it 'avoids N+1 queries' do
+ it "avoids N+1 queries" do
another_project = create(:project)
- control_count = ActiveRecord::QueryRecorder.new do
+ control_count = ActiveRecord::QueryRecorder.new {
described_class.ancestor_clusters_for_clusterable(another_project, hierarchy_order: hierarchy_order)
- end.count
+ }.count
cluster2 = create(:cluster, :provided_by_gcp, :group)
child2 = cluster2.group
child2.update!(parent: sub_group)
project = create(:project, group: child2)
- expect do
+ expect {
described_class.ancestor_clusters_for_clusterable(project, hierarchy_order: hierarchy_order)
- end.not_to exceed_query_limit(control_count)
+ }.not_to exceed_query_limit(control_count)
end
- context 'for a group' do
+ context "for a group" do
let(:clusterable) { sub_group }
- it 'returns clusters in order for a group' do
+ it "returns clusters in order for a group" do
is_expected.to eq([group_cluster])
end
end
end
- context 'scope chaining' do
+ context "scope chaining" do
let(:project) { create(:project, group: group) }
subject { described_class.none.ancestor_clusters_for_clusterable(project) }
- it 'returns nothing' do
+ it "returns nothing" do
is_expected.to be_empty
end
end
end
- describe '#provider' do
+ describe "#provider" do
subject { cluster.provider }
- context 'when provider is gcp' do
+ context "when provider is gcp" do
let(:cluster) { create(:cluster, :provided_by_gcp) }
- it 'returns a provider' do
+ it "returns a provider" do
is_expected.to eq(cluster.provider_gcp)
expect(subject.class.name.deconstantize).to eq(Clusters::Providers.to_s)
end
end
- context 'when provider is user' do
+ context "when provider is user" do
let(:cluster) { create(:cluster, :provided_by_user) }
it { is_expected.to be_nil }
end
end
- describe '#platform' do
+ describe "#platform" do
subject { cluster.platform }
- context 'when platform is kubernetes' do
+ context "when platform is kubernetes" do
let(:cluster) { create(:cluster, :provided_by_user) }
- it 'returns a platform' do
+ it "returns a platform" do
is_expected.to eq(cluster.platform_kubernetes)
expect(subject.class.name.deconstantize).to eq(Clusters::Platforms.to_s)
end
end
end
- describe '#all_projects' do
+ describe "#all_projects" do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, projects: [project]) }
subject { cluster.all_projects }
- context 'project cluster' do
- it 'returns project' do
+ context "project cluster" do
+ it "returns project" do
is_expected.to eq([project])
end
end
- context 'group cluster' do
+ context "group cluster" do
let(:cluster) { create(:cluster, :group) }
let(:group) { cluster.group }
let(:project) { create(:project, group: group) }
let(:subgroup) { create(:group, parent: group) }
let(:subproject) { create(:project, group: subgroup) }
- it 'returns all projects for group' do
+ it "returns all projects for group" do
is_expected.to contain_exactly(project, subproject)
end
end
end
- describe '#first_project' do
+ describe "#first_project" do
subject { cluster.first_project }
- context 'when cluster belongs to a project' do
+ context "when cluster belongs to a project" do
let(:cluster) { create(:cluster, :project) }
let(:project) { Clusters::Project.find_by_cluster_id(cluster.id).project }
it { is_expected.to eq(project) }
end
- context 'when cluster does not belong to projects' do
+ context "when cluster does not belong to projects" do
let(:cluster) { create(:cluster) }
it { is_expected.to be_nil }
end
end
- describe '#group' do
+ describe "#group" do
subject { cluster.group }
- context 'when cluster belongs to a group' do
+ context "when cluster belongs to a group" do
let(:cluster) { create(:cluster, :group) }
let(:group) { cluster.groups.first }
it { is_expected.to eq(group) }
end
- context 'when cluster does not belong to any group' do
+ context "when cluster does not belong to any group" do
let(:cluster) { create(:cluster) }
it { is_expected.to be_nil }
end
end
- describe '#applications' do
+ describe "#applications" do
set(:cluster) { create(:cluster) }
subject { cluster.applications }
- context 'when none of applications are created' do
- it 'returns a list of a new objects' do
+ context "when none of applications are created" do
+ it "returns a list of a new objects" do
is_expected.not_to be_empty
end
end
- context 'when applications are created' do
+ context "when applications are created" do
let!(:helm) { create(:clusters_applications_helm, cluster: cluster) }
let!(:ingress) { create(:clusters_applications_ingress, cluster: cluster) }
let!(:cert_manager) { create(:clusters_applications_cert_managers, cluster: cluster) }
@@ -466,18 +466,18 @@ describe Clusters::Cluster do
let!(:jupyter) { create(:clusters_applications_jupyter, cluster: cluster) }
let!(:knative) { create(:clusters_applications_knative, cluster: cluster) }
- it 'returns a list of created applications' do
+ it "returns a list of created applications" do
is_expected.to contain_exactly(helm, ingress, cert_manager, prometheus, runner, jupyter, knative)
end
end
end
- describe '#created?' do
+ describe "#created?" do
let(:cluster) { create(:cluster, :provided_by_gcp) }
subject { cluster.created? }
- context 'when status_name is :created' do
+ context "when status_name is :created" do
before do
allow(cluster).to receive_message_chain(:provider, :status_name).and_return(:created)
end
@@ -485,7 +485,7 @@ describe Clusters::Cluster do
it { is_expected.to eq(true) }
end
- context 'when status_name is not :created' do
+ context "when status_name is not :created" do
before do
allow(cluster).to receive_message_chain(:provider, :status_name).and_return(:creating)
end
@@ -494,127 +494,127 @@ describe Clusters::Cluster do
end
end
- describe '#allow_user_defined_namespace?' do
+ describe "#allow_user_defined_namespace?" do
let(:cluster) { create(:cluster, :provided_by_gcp) }
subject { cluster.allow_user_defined_namespace? }
- context 'project type cluster' do
+ context "project type cluster" do
it { is_expected.to be_truthy }
end
- context 'group type cluster' do
+ context "group type cluster" do
let(:cluster) { create(:cluster, :provided_by_gcp, :group) }
it { is_expected.to be_falsey }
end
- context 'instance type cluster' do
+ context "instance type cluster" do
let(:cluster) { create(:cluster, :provided_by_gcp, :instance) }
it { is_expected.to be_falsey }
end
end
- describe '#kube_ingress_domain' do
+ describe "#kube_ingress_domain" do
let(:cluster) { create(:cluster, :provided_by_gcp) }
subject { cluster.kube_ingress_domain }
- context 'with domain set in cluster' do
+ context "with domain set in cluster" do
let(:cluster) { create(:cluster, :provided_by_gcp, :with_domain) }
it { is_expected.to eq(cluster.domain) }
end
- context 'with no domain on cluster' do
- context 'with a project cluster' do
+ context "with no domain on cluster" do
+ context "with a project cluster" do
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
- context 'with domain set at instance level' do
+ context "with domain set at instance level" do
before do
- stub_application_setting(auto_devops_domain: 'global_domain.com')
+ stub_application_setting(auto_devops_domain: "global_domain.com")
- it { is_expected.to eq('global_domain.com') }
+ it { is_expected.to eq("global_domain.com") }
end
end
- context 'with domain set on ProjectAutoDevops' do
+ context "with domain set on ProjectAutoDevops" do
before do
- auto_devops = project.build_auto_devops(domain: 'legacy-ado-domain.com')
+ auto_devops = project.build_auto_devops(domain: "legacy-ado-domain.com")
auto_devops.save
end
- it { is_expected.to eq('legacy-ado-domain.com') }
+ it { is_expected.to eq("legacy-ado-domain.com") }
end
- context 'with domain set as environment variable on project' do
+ context "with domain set as environment variable on project" do
before do
- variable = project.variables.build(key: 'AUTO_DEVOPS_DOMAIN', value: 'project-ado-domain.com')
+ variable = project.variables.build(key: "AUTO_DEVOPS_DOMAIN", value: "project-ado-domain.com")
variable.save
end
- it { is_expected.to eq('project-ado-domain.com') }
+ it { is_expected.to eq("project-ado-domain.com") }
end
- context 'with domain set as environment variable on the group project' do
+ context "with domain set as environment variable on the group project" do
let(:group) { create(:group) }
before do
project.update(parent_id: group.id)
- variable = group.variables.build(key: 'AUTO_DEVOPS_DOMAIN', value: 'group-ado-domain.com')
+ variable = group.variables.build(key: "AUTO_DEVOPS_DOMAIN", value: "group-ado-domain.com")
variable.save
end
- it { is_expected.to eq('group-ado-domain.com') }
+ it { is_expected.to eq("group-ado-domain.com") }
end
end
- context 'with a group cluster' do
+ context "with a group cluster" do
let(:cluster) { create(:cluster, :group, :provided_by_gcp) }
- context 'with domain set as environment variable for the group' do
+ context "with domain set as environment variable for the group" do
let(:group) { cluster.group }
before do
- variable = group.variables.build(key: 'AUTO_DEVOPS_DOMAIN', value: 'group-ado-domain.com')
+ variable = group.variables.build(key: "AUTO_DEVOPS_DOMAIN", value: "group-ado-domain.com")
variable.save
end
- it { is_expected.to eq('group-ado-domain.com') }
+ it { is_expected.to eq("group-ado-domain.com") }
end
end
end
end
- describe '#predefined_variables' do
+ describe "#predefined_variables" do
subject { cluster.predefined_variables }
- context 'with an instance domain' do
+ context "with an instance domain" do
let(:cluster) { create(:cluster, :provided_by_gcp) }
before do
- stub_application_setting(auto_devops_domain: 'global_domain.com')
+ stub_application_setting(auto_devops_domain: "global_domain.com")
end
- it 'should include KUBE_INGRESS_BASE_DOMAIN' do
- expect(subject.to_hash).to include(KUBE_INGRESS_BASE_DOMAIN: 'global_domain.com')
+ it "should include KUBE_INGRESS_BASE_DOMAIN" do
+ expect(subject.to_hash).to include(KUBE_INGRESS_BASE_DOMAIN: "global_domain.com")
end
end
- context 'with a cluster domain' do
- let(:cluster) { create(:cluster, :provided_by_gcp, domain: 'example.com') }
+ context "with a cluster domain" do
+ let(:cluster) { create(:cluster, :provided_by_gcp, domain: "example.com") }
- it 'should include KUBE_INGRESS_BASE_DOMAIN' do
- expect(subject.to_hash).to include(KUBE_INGRESS_BASE_DOMAIN: 'example.com')
+ it "should include KUBE_INGRESS_BASE_DOMAIN" do
+ expect(subject.to_hash).to include(KUBE_INGRESS_BASE_DOMAIN: "example.com")
end
end
- context 'with no domain' do
+ context "with no domain" do
let(:cluster) { create(:cluster, :provided_by_gcp, :project) }
- it 'should return an empty array' do
+ it "should return an empty array" do
expect(subject.to_hash).to be_empty
end
end
diff --git a/spec/models/clusters/group_spec.rb b/spec/models/clusters/group_spec.rb
index ba145342cb8..b507d276a72 100644
--- a/spec/models/clusters/group_spec.rb
+++ b/spec/models/clusters/group_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe Clusters::Group do
it { is_expected.to belong_to(:cluster) }
diff --git a/spec/models/clusters/kubernetes_namespace_spec.rb b/spec/models/clusters/kubernetes_namespace_spec.rb
index b865909c7fd..0cbb6b07e20 100644
--- a/spec/models/clusters/kubernetes_namespace_spec.rb
+++ b/spec/models/clusters/kubernetes_namespace_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
RSpec.describe Clusters::KubernetesNamespace, type: :model do
it { is_expected.to belong_to(:cluster_project) }
@@ -8,71 +8,71 @@ RSpec.describe Clusters::KubernetesNamespace, type: :model do
it { is_expected.to belong_to(:cluster) }
it { is_expected.to have_one(:platform_kubernetes) }
- describe 'has_service_account_token' do
+ describe "has_service_account_token" do
subject { described_class.has_service_account_token }
- context 'namespace has service_account_token' do
+ context "namespace has service_account_token" do
let!(:namespace) { create(:cluster_kubernetes_namespace, :with_token) }
it { is_expected.to include(namespace) }
end
- context 'namespace has no service_account_token' do
+ context "namespace has no service_account_token" do
let!(:namespace) { create(:cluster_kubernetes_namespace) }
it { is_expected.not_to include(namespace) }
end
end
- describe 'namespace uniqueness validation' do
+ describe "namespace uniqueness validation" do
let(:cluster_project) { create(:cluster_project) }
- let(:kubernetes_namespace) { build(:cluster_kubernetes_namespace, namespace: 'my-namespace') }
+ let(:kubernetes_namespace) { build(:cluster_kubernetes_namespace, namespace: "my-namespace") }
subject { kubernetes_namespace }
- context 'when cluster is using the namespace' do
+ context "when cluster is using the namespace" do
before do
create(:cluster_kubernetes_namespace,
- cluster: kubernetes_namespace.cluster,
- namespace: 'my-namespace')
+ cluster: kubernetes_namespace.cluster,
+ namespace: "my-namespace")
end
it { is_expected.not_to be_valid }
end
- context 'when cluster is not using the namespace' do
+ context "when cluster is not using the namespace" do
it { is_expected.to be_valid }
end
end
- describe '#set_defaults' do
+ describe "#set_defaults" do
let(:kubernetes_namespace) { build(:cluster_kubernetes_namespace) }
let(:cluster) { kubernetes_namespace.cluster }
let(:platform) { kubernetes_namespace.platform_kubernetes }
subject { kubernetes_namespace.set_defaults }
- describe '#namespace' do
+ describe "#namespace" do
before do
platform.update_column(:namespace, namespace)
end
- context 'when platform has a namespace assigned' do
- let(:namespace) { 'platform-namespace' }
+ context "when platform has a namespace assigned" do
+ let(:namespace) { "platform-namespace" }
- it 'should copy the namespace' do
+ it "should copy the namespace" do
subject
- expect(kubernetes_namespace.namespace).to eq('platform-namespace')
+ expect(kubernetes_namespace.namespace).to eq("platform-namespace")
end
end
- context 'when platform does not have namespace assigned' do
+ context "when platform does not have namespace assigned" do
let(:project) { kubernetes_namespace.project }
let(:namespace) { nil }
let(:project_slug) { "#{project.path}-#{project.id}" }
- it 'should fallback to project namespace' do
+ it "should fallback to project namespace" do
subject
expect(kubernetes_namespace.namespace).to eq(project_slug)
@@ -80,10 +80,10 @@ RSpec.describe Clusters::KubernetesNamespace, type: :model do
end
end
- describe '#service_account_name' do
+ describe "#service_account_name" do
let(:service_account_name) { "#{kubernetes_namespace.namespace}-service-account" }
- it 'should set a service account name based on namespace' do
+ it "should set a service account name based on namespace" do
subject
expect(kubernetes_namespace.service_account_name).to eq(service_account_name)
@@ -91,32 +91,32 @@ RSpec.describe Clusters::KubernetesNamespace, type: :model do
end
end
- describe '#predefined_variables' do
+ describe "#predefined_variables" do
let(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, cluster: cluster, service_account_token: token) }
let(:cluster) { create(:cluster, :project, platform_kubernetes: platform) }
let(:platform) { create(:cluster_platform_kubernetes, api_url: api_url, ca_cert: ca_pem, token: token) }
- let(:api_url) { 'https://kube.domain.com' }
- let(:ca_pem) { File.read(Rails.root.join('spec/fixtures/clusters/sample_cert.pem')) }
- let(:token) { 'token' }
+ let(:api_url) { "https://kube.domain.com" }
+ let(:ca_pem) { File.read(Rails.root.join("spec/fixtures/clusters/sample_cert.pem")) }
+ let(:token) { "token" }
let(:kubeconfig) do
- config_file = expand_fixture_path('config/kubeconfig.yml')
+ config_file = expand_fixture_path("config/kubeconfig.yml")
config = YAML.safe_load(File.read(config_file))
- config.dig('users', 0, 'user')['token'] = token
- config.dig('contexts', 0, 'context')['namespace'] = kubernetes_namespace.namespace
- config.dig('clusters', 0, 'cluster')['certificate-authority-data'] =
+ config.dig("users", 0, "user")["token"] = token
+ config.dig("contexts", 0, "context")["namespace"] = kubernetes_namespace.namespace
+ config.dig("clusters", 0, "cluster")["certificate-authority-data"] =
Base64.strict_encode64(ca_pem)
YAML.dump(config)
end
- it 'sets the variables' do
+ it "sets the variables" do
expect(kubernetes_namespace.predefined_variables).to include(
- { key: 'KUBE_SERVICE_ACCOUNT', value: kubernetes_namespace.service_account_name, public: true },
- { key: 'KUBE_NAMESPACE', value: kubernetes_namespace.namespace, public: true },
- { key: 'KUBE_TOKEN', value: kubernetes_namespace.service_account_token, public: false },
- { key: 'KUBECONFIG', value: kubeconfig, public: false, file: true }
+ {key: "KUBE_SERVICE_ACCOUNT", value: kubernetes_namespace.service_account_name, public: true},
+ {key: "KUBE_NAMESPACE", value: kubernetes_namespace.namespace, public: true},
+ {key: "KUBE_TOKEN", value: kubernetes_namespace.service_account_token, public: false},
+ {key: "KUBECONFIG", value: kubeconfig, public: false, file: true}
)
end
end
diff --git a/spec/models/clusters/platforms/kubernetes_spec.rb b/spec/models/clusters/platforms/kubernetes_spec.rb
index 4068d98d8f7..483f17628d7 100644
--- a/spec/models/clusters/platforms/kubernetes_spec.rb
+++ b/spec/models/clusters/platforms/kubernetes_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching do
include KubernetesHelpers
@@ -9,7 +9,7 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
it { is_expected.to be_kind_of(ReactiveCaching) }
it { is_expected.to respond_to :ca_pem }
- it { is_expected.to validate_exclusion_of(:namespace).in_array(%w(gitlab-managed-apps)) }
+ it { is_expected.to validate_exclusion_of(:namespace).in_array(%w[gitlab-managed-apps]) }
it { is_expected.to validate_presence_of(:api_url) }
it { is_expected.to validate_presence_of(:token) }
@@ -18,51 +18,51 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
it { is_expected.to delegate_method(:managed?).to(:cluster) }
it { is_expected.to delegate_method(:kubernetes_namespace).to(:cluster) }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe 'before_validation' do
- context 'when namespace includes upper case' do
+ describe "before_validation" do
+ context "when namespace includes upper case" do
let(:kubernetes) { create(:cluster_platform_kubernetes, :configured, namespace: namespace) }
- let(:namespace) { 'ABC' }
+ let(:namespace) { "ABC" }
- it 'converts to lower case' do
- expect(kubernetes.namespace).to eq('abc')
+ it "converts to lower case" do
+ expect(kubernetes.namespace).to eq("abc")
end
end
end
- describe 'validation' do
+ describe "validation" do
subject { kubernetes.valid? }
- context 'when validates namespace' do
+ context "when validates namespace" do
let(:kubernetes) { build(:cluster_platform_kubernetes, :configured, namespace: namespace) }
- context 'when namespace is blank' do
- let(:namespace) { '' }
+ context "when namespace is blank" do
+ let(:namespace) { "" }
it { is_expected.to be_truthy }
end
- context 'when namespace is longer than 63' do
- let(:namespace) { 'a' * 64 }
+ context "when namespace is longer than 63" do
+ let(:namespace) { "a" * 64 }
it { is_expected.to be_falsey }
end
- context 'when namespace includes invalid character' do
- let(:namespace) { '!!!!!!' }
+ context "when namespace includes invalid character" do
+ let(:namespace) { "!!!!!!" }
it { is_expected.to be_falsey }
end
- context 'when namespace is vaild' do
- let(:namespace) { 'namespace-123' }
+ context "when namespace is vaild" do
+ let(:namespace) { "namespace-123" }
it { is_expected.to be_truthy }
end
- context 'for group cluster' do
- let(:namespace) { 'namespace-123' }
+ context "for group cluster" do
+ let(:namespace) { "namespace-123" }
let(:cluster) { build(:cluster, :group, :provided_by_user) }
let(:kubernetes) { cluster.platform_kubernetes }
@@ -74,61 +74,61 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
end
end
- context 'when validates api_url' do
+ context "when validates api_url" do
let(:kubernetes) { build(:cluster_platform_kubernetes, :configured) }
before do
kubernetes.api_url = api_url
end
- context 'when api_url is invalid url' do
- let(:api_url) { '!!!!!!' }
+ context "when api_url is invalid url" do
+ let(:api_url) { "!!!!!!" }
it { expect(kubernetes.save).to be_falsey }
end
- context 'when api_url is nil' do
+ context "when api_url is nil" do
let(:api_url) { nil }
it { expect(kubernetes.save).to be_falsey }
end
- context 'when api_url is valid url' do
- let(:api_url) { 'https://111.111.111.111' }
+ context "when api_url is valid url" do
+ let(:api_url) { "https://111.111.111.111" }
it { expect(kubernetes.save).to be_truthy }
end
end
- context 'when validates token' do
+ context "when validates token" do
let(:kubernetes) { build(:cluster_platform_kubernetes, :configured) }
before do
kubernetes.token = token
end
- context 'when token is nil' do
+ context "when token is nil" do
let(:token) { nil }
it { expect(kubernetes.save).to be_falsey }
end
end
- context 'ca_cert' do
+ context "ca_cert" do
let(:kubernetes) { build(:cluster_platform_kubernetes, ca_pem: ca_pem) }
- context 'with a valid certificate' do
- let(:ca_pem) { File.read(Rails.root.join('spec/fixtures/clusters/sample_cert.pem')) }
+ context "with a valid certificate" do
+ let(:ca_pem) { File.read(Rails.root.join("spec/fixtures/clusters/sample_cert.pem")) }
it { is_expected.to be_truthy }
end
- context 'with an invalid certificate' do
+ context "with an invalid certificate" do
let(:ca_pem) { "invalid" }
it { is_expected.to be_falsey }
- context 'but the certificate is not being updated' do
+ context "but the certificate is not being updated" do
before do
allow(kubernetes).to receive(:ca_cert_changed?).and_return(false)
end
@@ -137,53 +137,53 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
end
end
- context 'with no certificate' do
+ context "with no certificate" do
let(:ca_pem) { "" }
it { is_expected.to be_truthy }
end
end
- describe 'when using reserved namespaces' do
+ describe "when using reserved namespaces" do
subject { build(:cluster_platform_kubernetes, namespace: namespace) }
- context 'when no namespace is manually assigned' do
+ context "when no namespace is manually assigned" do
let(:namespace) { nil }
it { is_expected.to be_valid }
end
- context 'when no reserved namespace is assigned' do
- let(:namespace) { 'my-namespace' }
+ context "when no reserved namespace is assigned" do
+ let(:namespace) { "my-namespace" }
it { is_expected.to be_valid }
end
- context 'when reserved namespace is assigned' do
- let(:namespace) { 'gitlab-managed-apps' }
+ context "when reserved namespace is assigned" do
+ let(:namespace) { "gitlab-managed-apps" }
it { is_expected.not_to be_valid }
end
end
end
- describe '#kubeclient' do
+ describe "#kubeclient" do
let(:cluster) { create(:cluster, :project) }
- let(:kubernetes) { build(:cluster_platform_kubernetes, :configured, namespace: 'a-namespace', cluster: cluster) }
+ let(:kubernetes) { build(:cluster_platform_kubernetes, :configured, namespace: "a-namespace", cluster: cluster) }
subject { kubernetes.kubeclient }
before do
create(:cluster_kubernetes_namespace,
- cluster: kubernetes.cluster,
- cluster_project: kubernetes.cluster.cluster_project,
- project: kubernetes.cluster.cluster_project.project)
+ cluster: kubernetes.cluster,
+ cluster_project: kubernetes.cluster.cluster_project,
+ project: kubernetes.cluster.cluster_project.project)
end
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::KubeClient) }
end
- describe '#rbac?' do
+ describe "#rbac?" do
let(:kubernetes) { build(:cluster_platform_kubernetes, :configured) }
subject { kubernetes.rbac? }
@@ -191,28 +191,28 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
it { is_expected.to be_truthy }
end
- describe '#actual_namespace' do
+ describe "#actual_namespace" do
let(:cluster) { create(:cluster, :project) }
let(:project) { cluster.project }
let(:platform) do
create(:cluster_platform_kubernetes,
- cluster: cluster,
- namespace: namespace)
+ cluster: cluster,
+ namespace: namespace)
end
subject { platform.actual_namespace }
- context 'with a namespace assigned' do
- let(:namespace) { 'namespace-123' }
+ context "with a namespace assigned" do
+ let(:namespace) { "namespace-123" }
it { is_expected.to eq(namespace) }
end
- context 'with no namespace assigned' do
+ context "with no namespace assigned" do
let(:namespace) { nil }
- context 'when kubernetes namespace is present' do
+ context "when kubernetes namespace is present" do
let(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, cluster: cluster) }
before do
@@ -222,127 +222,127 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
it { is_expected.to eq(kubernetes_namespace.namespace) }
end
- context 'when kubernetes namespace is not present' do
+ context "when kubernetes namespace is not present" do
it { is_expected.to eq("#{project.path}-#{project.id}") }
end
end
end
- describe '#predefined_variables' do
+ describe "#predefined_variables" do
let!(:cluster) { create(:cluster, :project, platform_kubernetes: kubernetes) }
let(:kubernetes) { create(:cluster_platform_kubernetes, api_url: api_url, ca_cert: ca_pem) }
- let(:api_url) { 'https://kube.domain.com' }
- let(:ca_pem) { File.read(Rails.root.join('spec/fixtures/clusters/sample_cert.pem')) }
+ let(:api_url) { "https://kube.domain.com" }
+ let(:ca_pem) { File.read(Rails.root.join("spec/fixtures/clusters/sample_cert.pem")) }
subject { kubernetes.predefined_variables(project: cluster.project) }
- shared_examples 'setting variables' do
- it 'sets the variables' do
+ shared_examples "setting variables" do
+ it "sets the variables" do
expect(subject).to include(
- { key: 'KUBE_URL', value: api_url, public: true },
- { key: 'KUBE_CA_PEM', value: ca_pem, public: true },
- { key: 'KUBE_CA_PEM_FILE', value: ca_pem, public: true, file: true }
+ {key: "KUBE_URL", value: api_url, public: true},
+ {key: "KUBE_CA_PEM", value: ca_pem, public: true},
+ {key: "KUBE_CA_PEM_FILE", value: ca_pem, public: true, file: true}
)
end
end
- context 'kubernetes namespace is created with no service account token' do
+ context "kubernetes namespace is created with no service account token" do
let!(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, cluster: cluster) }
- it_behaves_like 'setting variables'
+ it_behaves_like "setting variables"
- it 'sets KUBE_TOKEN' do
+ it "sets KUBE_TOKEN" do
expect(subject).to include(
- { key: 'KUBE_TOKEN', value: kubernetes.token, public: false }
+ {key: "KUBE_TOKEN", value: kubernetes.token, public: false}
)
end
end
- context 'kubernetes namespace is created with no service account token' do
+ context "kubernetes namespace is created with no service account token" do
let!(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, :with_token, cluster: cluster) }
- it_behaves_like 'setting variables'
+ it_behaves_like "setting variables"
- it 'sets KUBE_TOKEN' do
+ it "sets KUBE_TOKEN" do
expect(subject).to include(
- { key: 'KUBE_TOKEN', value: kubernetes_namespace.service_account_token, public: false }
+ {key: "KUBE_TOKEN", value: kubernetes_namespace.service_account_token, public: false}
)
end
end
- context 'namespace is provided' do
- let(:namespace) { 'my-project' }
+ context "namespace is provided" do
+ let(:namespace) { "my-project" }
before do
kubernetes.namespace = namespace
end
- it_behaves_like 'setting variables'
+ it_behaves_like "setting variables"
- it 'sets KUBE_TOKEN' do
+ it "sets KUBE_TOKEN" do
expect(subject).to include(
- { key: 'KUBE_TOKEN', value: kubernetes.token, public: false }
+ {key: "KUBE_TOKEN", value: kubernetes.token, public: false}
)
end
end
- context 'no namespace provided' do
+ context "no namespace provided" do
let(:namespace) { kubernetes.actual_namespace }
- it_behaves_like 'setting variables'
+ it_behaves_like "setting variables"
- it 'sets KUBE_TOKEN' do
+ it "sets KUBE_TOKEN" do
expect(subject).to include(
- { key: 'KUBE_TOKEN', value: kubernetes.token, public: false }
+ {key: "KUBE_TOKEN", value: kubernetes.token, public: false}
)
end
end
- context 'group level cluster' do
+ context "group level cluster" do
let!(:cluster) { create(:cluster, :group, platform_kubernetes: kubernetes) }
let(:project) { create(:project, group: cluster.group) }
subject { kubernetes.predefined_variables(project: project) }
- context 'no kubernetes namespace for the project' do
- it_behaves_like 'setting variables'
+ context "no kubernetes namespace for the project" do
+ it_behaves_like "setting variables"
- it 'does not return KUBE_TOKEN' do
+ it "does not return KUBE_TOKEN" do
expect(subject).not_to include(
- { key: 'KUBE_TOKEN', value: kubernetes.token, public: false }
+ {key: "KUBE_TOKEN", value: kubernetes.token, public: false}
)
end
end
- context 'kubernetes namespace exists for the project' do
+ context "kubernetes namespace exists for the project" do
let!(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, :with_token, cluster: cluster, project: project) }
- it_behaves_like 'setting variables'
+ it_behaves_like "setting variables"
- it 'sets KUBE_TOKEN' do
+ it "sets KUBE_TOKEN" do
expect(subject).to include(
- { key: 'KUBE_TOKEN', value: kubernetes_namespace.service_account_token, public: false }
+ {key: "KUBE_TOKEN", value: kubernetes_namespace.service_account_token, public: false}
)
end
end
end
- context 'with a domain' do
+ context "with a domain" do
let!(:cluster) do
create(:cluster, :provided_by_gcp, :with_domain,
- platform_kubernetes: kubernetes)
+ platform_kubernetes: kubernetes)
end
- it 'sets KUBE_INGRESS_BASE_DOMAIN' do
+ it "sets KUBE_INGRESS_BASE_DOMAIN" do
expect(subject).to include(
- { key: 'KUBE_INGRESS_BASE_DOMAIN', value: cluster.domain, public: true }
+ {key: "KUBE_INGRESS_BASE_DOMAIN", value: cluster.domain, public: true}
)
end
end
end
- describe '#terminals' do
+ describe "#terminals" do
subject { service.terminals(environment) }
let!(:cluster) { create(:cluster, :project, platform_kubernetes: service) }
@@ -350,15 +350,15 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
let(:service) { create(:cluster_platform_kubernetes, :configured) }
let(:environment) { build(:environment, project: project, name: "env", slug: "env-000000") }
- context 'with invalid pods' do
- it 'returns no terminals' do
- stub_reactive_cache(service, pods: [{ "bad" => "pod" }])
+ context "with invalid pods" do
+ it "returns no terminals" do
+ stub_reactive_cache(service, pods: [{"bad" => "pod"}])
is_expected.to be_empty
end
end
- context 'with valid pods' do
+ context "with valid pods" do
let(:pod) { kube_pod(app: environment.slug) }
let(:pod_with_no_terminal) { kube_pod(app: environment.slug, status: "Pending") }
let(:terminals) { kube_terminals(service, pod) }
@@ -370,11 +370,11 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
)
end
- it 'returns terminals' do
+ it "returns terminals" do
is_expected.to eq(terminals + terminals)
end
- it 'uses max session time from settings' do
+ it "uses max session time from settings" do
stub_application_setting(terminal_max_session_time: 600)
times = subject.map { |terminal| terminal[:max_session_time] }
@@ -383,20 +383,20 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
end
end
- describe '#calculate_reactive_cache' do
+ describe "#calculate_reactive_cache" do
subject { service.calculate_reactive_cache }
let!(:cluster) { create(:cluster, :project, enabled: enabled, platform_kubernetes: service) }
let(:service) { create(:cluster_platform_kubernetes, :configured) }
let(:enabled) { true }
- context 'when cluster is disabled' do
+ context "when cluster is disabled" do
let(:enabled) { false }
it { is_expected.to be_nil }
end
- context 'when kubernetes responds with valid pods and deployments' do
+ context "when kubernetes responds with valid pods and deployments" do
before do
stub_kubeclient_pods
stub_kubeclient_deployments
@@ -405,7 +405,7 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
it { is_expected.to include(pods: [kube_pod]) }
end
- context 'when kubernetes responds with 500s' do
+ context "when kubernetes responds with 500s" do
before do
stub_kubeclient_pods(status: 500)
stub_kubeclient_deployments(status: 500)
@@ -414,7 +414,7 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
it { expect { subject }.to raise_error(Kubeclient::HttpError) }
end
- context 'when kubernetes responds with 404s' do
+ context "when kubernetes responds with 404s" do
before do
stub_kubeclient_pods(status: 404)
stub_kubeclient_deployments(status: 404)
@@ -424,21 +424,21 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
end
end
- describe '#update_kubernetes_namespace' do
+ describe "#update_kubernetes_namespace" do
let(:cluster) { create(:cluster, :provided_by_gcp) }
let(:platform) { cluster.platform }
- context 'when namespace is updated' do
- it 'should call ConfigureWorker' do
+ context "when namespace is updated" do
+ it "should call ConfigureWorker" do
expect(ClusterConfigureWorker).to receive(:perform_async).with(cluster.id).once
- platform.namespace = 'new-namespace'
+ platform.namespace = "new-namespace"
platform.save
end
end
- context 'when namespace is not updated' do
- it 'should not call ConfigureWorker' do
+ context "when namespace is not updated" do
+ it "should not call ConfigureWorker" do
expect(ClusterConfigureWorker).not_to receive(:perform_async)
platform.username = "new-username"
diff --git a/spec/models/clusters/project_spec.rb b/spec/models/clusters/project_spec.rb
index 82ef5a23c18..859968b4710 100644
--- a/spec/models/clusters/project_spec.rb
+++ b/spec/models/clusters/project_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Clusters::Project do
it { is_expected.to belong_to(:cluster) }
diff --git a/spec/models/clusters/providers/gcp_spec.rb b/spec/models/clusters/providers/gcp_spec.rb
index 5012e6f15c6..cb0134aaeb1 100644
--- a/spec/models/clusters/providers/gcp_spec.rb
+++ b/spec/models/clusters/providers/gcp_spec.rb
@@ -1,72 +1,72 @@
-require 'spec_helper'
+require "spec_helper"
describe Clusters::Providers::Gcp do
it { is_expected.to belong_to(:cluster) }
it { is_expected.to validate_presence_of(:zone) }
- describe 'default_value_for' do
+ describe "default_value_for" do
let(:gcp) { build(:cluster_provider_gcp) }
it "has default value" do
- expect(gcp.zone).to eq('us-central1-a')
+ expect(gcp.zone).to eq("us-central1-a")
expect(gcp.num_nodes).to eq(3)
- expect(gcp.machine_type).to eq('n1-standard-2')
+ expect(gcp.machine_type).to eq("n1-standard-2")
end
end
- describe 'validation' do
+ describe "validation" do
subject { gcp.valid? }
- context 'when validates gcp_project_id' do
+ context "when validates gcp_project_id" do
let(:gcp) { build(:cluster_provider_gcp, gcp_project_id: gcp_project_id) }
- context 'when gcp_project_id is shorter than 1' do
- let(:gcp_project_id) { '' }
+ context "when gcp_project_id is shorter than 1" do
+ let(:gcp_project_id) { "" }
it { is_expected.to be_falsey }
end
- context 'when gcp_project_id is longer than 63' do
- let(:gcp_project_id) { 'a' * 64 }
+ context "when gcp_project_id is longer than 63" do
+ let(:gcp_project_id) { "a" * 64 }
it { is_expected.to be_falsey }
end
- context 'when gcp_project_id includes invalid character' do
- let(:gcp_project_id) { '!!!!!!' }
+ context "when gcp_project_id includes invalid character" do
+ let(:gcp_project_id) { "!!!!!!" }
it { is_expected.to be_falsey }
end
- context 'when gcp_project_id is valid' do
- let(:gcp_project_id) { 'gcp-project-1' }
+ context "when gcp_project_id is valid" do
+ let(:gcp_project_id) { "gcp-project-1" }
it { is_expected.to be_truthy }
end
end
- context 'when validates num_nodes' do
+ context "when validates num_nodes" do
let(:gcp) { build(:cluster_provider_gcp, num_nodes: num_nodes) }
- context 'when num_nodes is string' do
- let(:num_nodes) { 'A3' }
+ context "when num_nodes is string" do
+ let(:num_nodes) { "A3" }
it { is_expected.to be_falsey }
end
- context 'when num_nodes is nil' do
+ context "when num_nodes is nil" do
let(:num_nodes) { nil }
it { is_expected.to be_falsey }
end
- context 'when num_nodes is smaller than 1' do
+ context "when num_nodes is smaller than 1" do
let(:num_nodes) { 0 }
it { is_expected.to be_falsey }
end
- context 'when num_nodes is valid' do
+ context "when num_nodes is valid" do
let(:num_nodes) { 3 }
it { is_expected.to be_truthy }
@@ -74,7 +74,7 @@ describe Clusters::Providers::Gcp do
end
end
- describe '#legacy_abac?' do
+ describe "#legacy_abac?" do
let(:gcp) { build(:cluster_provider_gcp) }
subject { gcp }
@@ -82,52 +82,52 @@ describe Clusters::Providers::Gcp do
it { is_expected.not_to be_legacy_abac }
end
- describe '#state_machine' do
- context 'when any => [:created]' do
+ describe "#state_machine" do
+ context "when any => [:created]" do
let(:gcp) { build(:cluster_provider_gcp, :creating) }
before do
gcp.make_created
end
- it 'nullify access_token and operation_id' do
+ it "nullify access_token and operation_id" do
expect(gcp.access_token).to be_nil
expect(gcp.operation_id).to be_nil
expect(gcp).to be_created
end
end
- context 'when any => [:creating]' do
+ context "when any => [:creating]" do
let(:gcp) { build(:cluster_provider_gcp) }
- context 'when operation_id is present' do
- let(:operation_id) { 'operation-xxx' }
+ context "when operation_id is present" do
+ let(:operation_id) { "operation-xxx" }
before do
gcp.make_creating(operation_id)
end
- it 'sets operation_id' do
+ it "sets operation_id" do
expect(gcp.operation_id).to eq(operation_id)
expect(gcp).to be_creating
end
end
- context 'when operation_id is nil' do
+ context "when operation_id is nil" do
let(:operation_id) { nil }
- it 'raises an error' do
+ it "raises an error" do
expect { gcp.make_creating(operation_id) }
- .to raise_error('operation_id is required')
+ .to raise_error("operation_id is required")
end
end
end
- context 'when any => [:errored]' do
+ context "when any => [:errored]" do
let(:gcp) { build(:cluster_provider_gcp, :creating) }
- let(:status_reason) { 'err msg' }
+ let(:status_reason) { "err msg" }
- it 'nullify access_token and operation_id' do
+ it "nullify access_token and operation_id" do
gcp.make_errored(status_reason)
expect(gcp.access_token).to be_nil
@@ -136,10 +136,10 @@ describe Clusters::Providers::Gcp do
expect(gcp).to be_errored
end
- context 'when status_reason is nil' do
+ context "when status_reason is nil" do
let(:gcp) { build(:cluster_provider_gcp, :errored) }
- it 'does not set status_reason' do
+ it "does not set status_reason" do
gcp.make_errored(nil)
expect(gcp.status_reason).not_to be_nil
@@ -148,41 +148,41 @@ describe Clusters::Providers::Gcp do
end
end
- describe '#on_creation?' do
+ describe "#on_creation?" do
subject { gcp.on_creation? }
- context 'when status is creating' do
+ context "when status is creating" do
let(:gcp) { create(:cluster_provider_gcp, :creating) }
it { is_expected.to be_truthy }
end
- context 'when status is created' do
+ context "when status is created" do
let(:gcp) { create(:cluster_provider_gcp, :created) }
it { is_expected.to be_falsey }
end
end
- describe '#api_client' do
+ describe "#api_client" do
subject { gcp.api_client }
- context 'when status is creating' do
+ context "when status is creating" do
let(:gcp) { build(:cluster_provider_gcp, :creating) }
- it 'returns Cloud Platform API clinet' do
+ it "returns Cloud Platform API clinet" do
expect(subject).to be_an_instance_of(GoogleApi::CloudPlatform::Client)
expect(subject.access_token).to eq(gcp.access_token)
end
end
- context 'when status is created' do
+ context "when status is created" do
let(:gcp) { build(:cluster_provider_gcp, :created) }
it { is_expected.to be_nil }
end
- context 'when status is errored' do
+ context "when status is errored" do
let(:gcp) { build(:cluster_provider_gcp, :errored) }
it { is_expected.to be_nil }
diff --git a/spec/models/commit_collection_spec.rb b/spec/models/commit_collection_spec.rb
index 0f5d03ff458..a84ba24ca97 100644
--- a/spec/models/commit_collection_spec.rb
+++ b/spec/models/commit_collection_spec.rb
@@ -1,32 +1,32 @@
-require 'spec_helper'
+require "spec_helper"
describe CommitCollection do
let(:project) { create(:project, :repository) }
let(:commit) { project.commit("c1c67abbaf91f624347bb3ae96eabe3a1b742478") }
- describe '#each' do
- it 'yields every commit' do
+ describe "#each" do
+ it "yields every commit" do
collection = described_class.new(project, [commit])
expect { |b| collection.each(&b) }.to yield_with_args(commit)
end
end
- describe '.authors' do
- it 'returns a relation of users when users are found' do
+ describe ".authors" do
+ it "returns a relation of users when users are found" do
user = create(:user, email: commit.author_email.upcase)
collection = described_class.new(project, [commit])
expect(collection.authors).to contain_exactly(user)
end
- it 'returns empty array when authors cannot be found' do
+ it "returns empty array when authors cannot be found" do
collection = described_class.new(project, [commit])
expect(collection.authors).to be_empty
end
- it 'excludes authors of merge commits' do
+ it "excludes authors of merge commits" do
commit = project.commit("60ecb67744cb56576c30214ff52294f8ce2def98")
create(:user, email: commit.author_email.upcase)
collection = described_class.new(project, [commit])
@@ -35,54 +35,54 @@ describe CommitCollection do
end
end
- describe '#without_merge_commits' do
- it 'returns all commits except merge commits' do
+ describe "#without_merge_commits" do
+ it "returns all commits except merge commits" do
collection = described_class.new(project, [
build(:commit),
- build(:commit, :merge_commit)
+ build(:commit, :merge_commit),
])
expect(collection.without_merge_commits.size).to eq(1)
end
end
- describe '#with_pipeline_status' do
- it 'sets the pipeline status for every commit so no additional queries are necessary' do
+ describe "#with_pipeline_status" do
+ it "sets the pipeline status for every commit so no additional queries are necessary" do
create(
:ci_empty_pipeline,
- ref: 'master',
+ ref: "master",
sha: commit.id,
- status: 'success',
+ status: "success",
project: project
)
collection = described_class.new(project, [commit])
collection.with_pipeline_status
- recorder = ActiveRecord::QueryRecorder.new do
- expect(commit.status).to eq('success')
- end
+ recorder = ActiveRecord::QueryRecorder.new {
+ expect(commit.status).to eq("success")
+ }
expect(recorder.count).to be_zero
end
end
- describe '#respond_to_missing?' do
- it 'returns true when the underlying Array responds to the message' do
+ describe "#respond_to_missing?" do
+ it "returns true when the underlying Array responds to the message" do
collection = described_class.new(project, [])
expect(collection.respond_to?(:last)).to eq(true)
end
- it 'returns false when the underlying Array does not respond to the message' do
+ it "returns false when the underlying Array does not respond to the message" do
collection = described_class.new(project, [])
expect(collection.respond_to?(:foo)).to eq(false)
end
end
- describe '#method_missing' do
- it 'delegates undefined methods to the underlying Array' do
+ describe "#method_missing" do
+ it "delegates undefined methods to the underlying Array" do
collection = described_class.new(project, [commit])
expect(collection.length).to eq(1)
diff --git a/spec/models/commit_range_spec.rb b/spec/models/commit_range_spec.rb
index f2efcd9d0e9..23840026881 100644
--- a/spec/models/commit_range_spec.rb
+++ b/spec/models/commit_range_spec.rb
@@ -1,7 +1,7 @@
-require 'spec_helper'
+require "spec_helper"
describe CommitRange do
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Referable) }
@@ -20,12 +20,12 @@ describe CommitRange do
let(:range) { described_class.new("#{sha_from}...#{sha_to}", project) }
let(:range2) { described_class.new("#{sha_from}..#{sha_to}", project) }
- it 'raises ArgumentError when given an invalid range string' do
+ it "raises ArgumentError when given an invalid range string" do
expect { described_class.new("Foo", project) }.to raise_error(ArgumentError)
end
- describe '#initialize' do
- it 'does not modify strings in-place' do
+ describe "#initialize" do
+ it "does not modify strings in-place" do
input = "#{sha_from}...#{sha_to} "
described_class.new(input, project)
@@ -34,118 +34,118 @@ describe CommitRange do
end
end
- describe '#to_s' do
- it 'is correct for three-dot syntax' do
+ describe "#to_s" do
+ it "is correct for three-dot syntax" do
expect(range.to_s).to eq "#{full_sha_from}...#{full_sha_to}"
end
- it 'is correct for two-dot syntax' do
+ it "is correct for two-dot syntax" do
expect(range2.to_s).to eq "#{full_sha_from}..#{full_sha_to}"
end
end
- describe '#to_reference' do
+ describe "#to_reference" do
let(:cross) { create(:project, namespace: project.namespace) }
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(range.to_reference).to eq "#{full_sha_from}...#{full_sha_to}"
end
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(range2.to_reference).to eq "#{full_sha_from}..#{full_sha_to}"
end
- it 'supports a cross-project reference' do
+ it "supports a cross-project reference" do
expect(range.to_reference(cross)).to eq "#{project.path}@#{full_sha_from}...#{full_sha_to}"
end
end
- describe '#reference_link_text' do
+ describe "#reference_link_text" do
let(:cross) { create(:project, namespace: project.namespace) }
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(range.reference_link_text).to eq "#{sha_from}...#{sha_to}"
end
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(range2.reference_link_text).to eq "#{sha_from}..#{sha_to}"
end
- it 'supports a cross-project reference' do
+ it "supports a cross-project reference" do
expect(range.reference_link_text(cross)).to eq "#{project.path}@#{sha_from}...#{sha_to}"
end
end
- describe '#to_param' do
- it 'includes the correct keys' do
- expect(range.to_param.keys).to eq %i(from to)
+ describe "#to_param" do
+ it "includes the correct keys" do
+ expect(range.to_param.keys).to eq %i[from to]
end
- it 'includes the correct values for a three-dot range' do
- expect(range.to_param).to eq({ from: full_sha_from, to: full_sha_to })
+ it "includes the correct values for a three-dot range" do
+ expect(range.to_param).to eq({from: full_sha_from, to: full_sha_to})
end
- it 'includes the correct values for a two-dot range' do
- expect(range2.to_param).to eq({ from: full_sha_from + '^', to: full_sha_to })
+ it "includes the correct values for a two-dot range" do
+ expect(range2.to_param).to eq({from: full_sha_from + "^", to: full_sha_to})
end
end
- describe '#exclude_start?' do
- it 'is false for three-dot ranges' do
+ describe "#exclude_start?" do
+ it "is false for three-dot ranges" do
expect(range.exclude_start?).to eq false
end
- it 'is true for two-dot ranges' do
+ it "is true for two-dot ranges" do
expect(range2.exclude_start?).to eq true
end
end
- describe '#valid_commits?' do
- context 'with a valid repo' do
+ describe "#valid_commits?" do
+ context "with a valid repo" do
before do
expect(project).to receive(:valid_repo?).and_return(true)
end
- it 'is false when `sha_from` is invalid' do
+ it "is false when `sha_from` is invalid" do
expect(project).to receive(:commit).with(sha_from).and_return(nil)
expect(project).to receive(:commit).with(sha_to).and_call_original
expect(range).not_to be_valid_commits
end
- it 'is false when `sha_to` is invalid' do
+ it "is false when `sha_to` is invalid" do
expect(project).to receive(:commit).with(sha_from).and_call_original
expect(project).to receive(:commit).with(sha_to).and_return(nil)
expect(range).not_to be_valid_commits
end
- it 'is true when both `sha_from` and `sha_to` are valid' do
+ it "is true when both `sha_from` and `sha_to` are valid" do
expect(range).to be_valid_commits
end
end
- context 'without a valid repo' do
+ context "without a valid repo" do
before do
expect(project).to receive(:valid_repo?).and_return(false)
end
- it 'returns false' do
+ it "returns false" do
expect(range).not_to be_valid_commits
end
end
end
- describe '#has_been_reverted?' do
+ describe "#has_been_reverted?" do
let(:issue) { create(:issue) }
let(:user) { issue.author }
- it 'returns true if the commit has been reverted' do
+ it "returns true if the commit has been reverted" do
create(:note_on_issue,
- noteable: issue,
- system: true,
- note: commit1.revert_description(user),
- project: issue.project)
+ noteable: issue,
+ system: true,
+ note: commit1.revert_description(user),
+ project: issue.project)
expect_any_instance_of(Commit).to receive(:reverts_commit?)
.with(commit1, user)
@@ -154,7 +154,7 @@ describe CommitRange do
expect(commit1.has_been_reverted?(user, issue.notes_with_associations)).to eq(true)
end
- it 'returns false if the commit has not been reverted' do
+ it "returns false if the commit has not been reverted" do
expect(commit1.has_been_reverted?(user, issue.notes_with_associations)).to eq(false)
end
end
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index baad8352185..058397a9f32 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -1,10 +1,10 @@
-require 'spec_helper'
+require "spec_helper"
describe Commit do
let(:project) { create(:project, :public, :repository) }
let(:commit) { project.commit }
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Mentionable) }
@@ -14,52 +14,52 @@ describe Commit do
it { is_expected.to include_module(Presentable) }
end
- describe '.lazy' do
+ describe ".lazy" do
set(:project) { create(:project, :repository) }
- context 'when the commits are found' do
+ context "when the commits are found" do
let(:oids) do
- %w(
+ %w[
498214de67004b1da3d820901307bed2a68a8ef6
c642fe9b8b9f28f9225d7ea953fe14e74748d53b
6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9
048721d90c449b244b7b4c53a9186b04330174ec
281d3a76f31c812dbf48abce82ccf6860adedd81
- )
+ ]
end
subject { oids.map { |oid| described_class.lazy(project, oid) } }
- it 'batches requests for commits' do
+ it "batches requests for commits" do
expect(project.repository).to receive(:commits_by).once.and_call_original
subject.first.title
subject.last.title
end
- it 'maintains ordering' do
+ it "maintains ordering" do
subject.each_with_index do |commit, i|
expect(commit.id).to eq(oids[i])
end
end
end
- context 'when not found' do
- it 'returns nil as commit' do
- commit = described_class.lazy(project, 'deadbeef').__sync
+ context "when not found" do
+ it "returns nil as commit" do
+ commit = described_class.lazy(project, "deadbeef").__sync
expect(commit).to be_nil
end
end
end
- describe '#author', :request_store do
- it 'looks up the author in a case-insensitive way' do
+ describe "#author", :request_store do
+ it "looks up the author in a case-insensitive way" do
user = create(:user, email: commit.author_email.upcase)
expect(commit.author).to eq(user)
end
- it 'caches the author' do
+ it "caches the author" do
user = create(:user, email: commit.author_email)
expect(commit.author).to eq(user)
@@ -70,14 +70,14 @@ describe Commit do
expect(commit.author).to eq(user)
end
- context 'using eager loading' do
- let!(:alice) { create(:user, email: 'alice@example.com') }
- let!(:bob) { create(:user, email: 'hunter2@example.com') }
+ context "using eager loading" do
+ let!(:alice) { create(:user, email: "alice@example.com") }
+ let!(:bob) { create(:user, email: "hunter2@example.com") }
let!(:jeff) { create(:user) }
let(:alice_commit) do
described_class.new(RepoHelpers.sample_commit, project).tap do |c|
- c.author_email = 'alice@example.com'
+ c.author_email = "alice@example.com"
end
end
@@ -85,13 +85,13 @@ describe Commit do
# The commit for Bob uses one of his alternative Emails, instead of the
# primary one.
described_class.new(RepoHelpers.sample_commit, project).tap do |c|
- c.author_email = 'bob@example.com'
+ c.author_email = "bob@example.com"
end
end
let(:eve_commit) do
described_class.new(RepoHelpers.sample_commit, project).tap do |c|
- c.author_email = 'eve@example.com'
+ c.author_email = "eve@example.com"
end
end
@@ -105,11 +105,11 @@ describe Commit do
let!(:commits) { [alice_commit, bob_commit, eve_commit, jeff_commit] }
before do
- create(:email, user: bob, email: 'bob@example.com')
+ create(:email, user: bob, email: "bob@example.com")
end
- it 'executes only two SQL queries' do
- recorder = ActiveRecord::QueryRecorder.new do
+ it "executes only two SQL queries" do
+ recorder = ActiveRecord::QueryRecorder.new {
# Running this first ensures we don't run one query for every
# commit.
commits.each(&:lazy_author)
@@ -117,7 +117,7 @@ describe Commit do
# This forces the execution of the SQL queries necessary to load the
# data.
commits.each { |c| c.author.try(:id) }
- end
+ }
expect(recorder.count).to eq(2)
end
@@ -141,71 +141,71 @@ describe Commit do
end
it "preloads the authors for Commits using a User's outdated private commit Email" do
- jeff.update!(username: 'new-username')
+ jeff.update!(username: "new-username")
commits.each(&:lazy_author)
expect(jeff_commit.author).to eq(jeff)
end
- it 'sets the author to Nil if an author could not be found for a Commit' do
+ it "sets the author to Nil if an author could not be found for a Commit" do
commits.each(&:lazy_author)
expect(eve_commit.author).to be_nil
end
- it 'does not execute SQL queries once the authors are preloaded' do
+ it "does not execute SQL queries once the authors are preloaded" do
commits.each(&:lazy_author)
commits.each { |c| c.author.try(:id) }
- recorder = ActiveRecord::QueryRecorder.new do
+ recorder = ActiveRecord::QueryRecorder.new {
alice_commit.author
bob_commit.author
eve_commit.author
- end
+ }
expect(recorder.count).to be_zero
end
end
end
- describe '#to_reference' do
- let(:project) { create(:project, :repository, path: 'sample-project') }
+ describe "#to_reference" do
+ let(:project) { create(:project, :repository, path: "sample-project") }
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(commit.to_reference).to eq commit.id
end
- it 'supports a cross-project reference' do
- another_project = build(:project, :repository, name: 'another-project', namespace: project.namespace)
+ it "supports a cross-project reference" do
+ another_project = build(:project, :repository, name: "another-project", namespace: project.namespace)
expect(commit.to_reference(another_project)).to eq "sample-project@#{commit.id}"
end
end
- describe '#reference_link_text' do
- let(:project) { create(:project, :repository, path: 'sample-project') }
+ describe "#reference_link_text" do
+ let(:project) { create(:project, :repository, path: "sample-project") }
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(commit.reference_link_text).to eq commit.short_id
end
- it 'supports a cross-project reference' do
- another_project = build(:project, :repository, name: 'another-project', namespace: project.namespace)
+ it "supports a cross-project reference" do
+ another_project = build(:project, :repository, name: "another-project", namespace: project.namespace)
expect(commit.reference_link_text(another_project)).to eq "sample-project@#{commit.short_id}"
end
end
- describe '#title' do
+ describe "#title" do
it "returns no_commit_message when safe_message is blank" do
- allow(commit).to receive(:safe_message).and_return('')
+ allow(commit).to receive(:safe_message).and_return("")
expect(commit.title).to eq("--no commit message")
end
- it 'truncates a message without a newline at natural break to 80 characters' do
- message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.'
+ it "truncates a message without a newline at natural break to 80 characters" do
+ message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris."
allow(commit).to receive(:safe_message).and_return(message)
- expect(commit.title).to eq('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id...')
+ expect(commit.title).to eq("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id...")
end
it "truncates a message with a newline before 80 characters at the newline" do
@@ -216,24 +216,24 @@ describe Commit do
end
it "does not truncates a message with a newline after 80 but less 100 characters" do
- message = <<eos
-Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit.
-Vivamus egestas lacinia lacus, sed rutrum mauris.
-eos
+ message = <<~eos
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit.
+ Vivamus egestas lacinia lacus, sed rutrum mauris.
+ eos
allow(commit).to receive(:safe_message).and_return(message)
expect(commit.title).to eq(message.split("\n").first)
end
end
- describe '#full_title' do
+ describe "#full_title" do
it "returns no_commit_message when safe_message is blank" do
- allow(commit).to receive(:safe_message).and_return('')
+ allow(commit).to receive(:safe_message).and_return("")
expect(commit.full_title).to eq("--no commit message")
end
it "returns entire message if there is no newline" do
- message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.'
+ message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris."
allow(commit).to receive(:safe_message).and_return(message)
expect(commit.full_title).to eq(message)
@@ -247,28 +247,28 @@ eos
end
end
- describe 'description' do
- it 'returns no_commit_message when safe_message is blank' do
+ describe "description" do
+ it "returns no_commit_message when safe_message is blank" do
allow(commit).to receive(:safe_message).and_return(nil)
- expect(commit.description).to eq('--no commit message')
+ expect(commit.description).to eq("--no commit message")
end
- it 'returns description of commit message if title less than 100 characters' do
- message = <<eos
-Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit.
-Vivamus egestas lacinia lacus, sed rutrum mauris.
-eos
+ it "returns description of commit message if title less than 100 characters" do
+ message = <<~eos
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit.
+ Vivamus egestas lacinia lacus, sed rutrum mauris.
+ eos
allow(commit).to receive(:safe_message).and_return(message)
- expect(commit.description).to eq('Vivamus egestas lacinia lacus, sed rutrum mauris.')
+ expect(commit.description).to eq("Vivamus egestas lacinia lacus, sed rutrum mauris.")
end
- it 'returns full commit message if commit title more than 100 characters' do
- message = <<eos
-Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.
-Vivamus egestas lacinia lacus, sed rutrum mauris.
-eos
+ it "returns full commit message if commit title more than 100 characters" do
+ message = <<~eos
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.
+ Vivamus egestas lacinia lacus, sed rutrum mauris.
+ eos
allow(commit).to receive(:safe_message).and_return(message)
expect(commit.description).to eq(message)
@@ -289,7 +289,7 @@ eos
it { is_expected.to respond_to(:id) }
end
- describe '#closes_issues' do
+ describe "#closes_issues" do
let(:issue) { create :issue, project: project }
let(:other_project) { create(:project, :public) }
let(:other_issue) { create :issue, project: other_project }
@@ -300,7 +300,7 @@ eos
other_project.add_developer(committer)
end
- it 'detects issues that this commit is marked as closing' do
+ it "detects issues that this commit is marked as closing" do
ext_ref = "#{other_project.full_path}##{other_issue.iid}"
allow(commit).to receive_messages(
@@ -313,7 +313,7 @@ eos
end
end
- it_behaves_like 'a mentionable' do
+ it_behaves_like "a mentionable" do
subject { create(:project, :repository).commit }
let(:author) { create(:user, email: subject.author_email) }
@@ -326,47 +326,47 @@ eos
let(:extra_commits) { [subject] }
end
- describe '#hook_attrs' do
+ describe "#hook_attrs" do
let(:data) { commit.hook_attrs(with_changed_files: true) }
it { expect(data).to be_a(Hash) }
- it { expect(data[:message]).to include('adds bar folder and branch-test text file to check Repository merged_to_root_ref method') }
- it { expect(data[:timestamp]).to eq('2016-09-27T14:37:46Z') }
+ it { expect(data[:message]).to include("adds bar folder and branch-test text file to check Repository merged_to_root_ref method") }
+ it { expect(data[:timestamp]).to eq("2016-09-27T14:37:46Z") }
it { expect(data[:added]).to contain_exactly("bar/branch-test.txt") }
it { expect(data[:modified]).to eq([]) }
it { expect(data[:removed]).to eq([]) }
end
- describe '#cherry_pick_message' do
+ describe "#cherry_pick_message" do
let(:user) { create(:user) }
- context 'of a regular commit' do
- let(:commit) { project.commit('video') }
+ context "of a regular commit" do
+ let(:commit) { project.commit("video") }
it { expect(commit.cherry_pick_message(user)).to include("\n\n(cherry picked from commit 88790590ed1337ab189bccaa355f068481c90bec)") }
end
- context 'of a merge commit' do
+ context "of a merge commit" do
let(:repository) { project.repository }
let(:merge_request) do
create(:merge_request,
- source_branch: 'video',
- target_branch: 'master',
- source_project: project,
- author: user)
+ source_branch: "video",
+ target_branch: "master",
+ source_project: project,
+ author: user)
end
let(:merge_commit) do
merge_commit_id = repository.merge(user,
- merge_request.diff_head_sha,
- merge_request,
- 'Test message')
+ merge_request.diff_head_sha,
+ merge_request,
+ "Test message")
repository.commit(merge_commit_id)
end
- context 'that is found' do
+ context "that is found" do
before do
# Artificially mark as completed.
merge_request.update(merge_commit_sha: merge_commit.id)
@@ -386,20 +386,20 @@ eos
end
context "that is existing but not found" do
- it 'does not include details of the merged commits' do
+ it "does not include details of the merged commits" do
expect(merge_commit.cherry_pick_message(user)).to end_with("(cherry picked from commit #{merge_commit.sha})")
end
end
end
end
- describe '#reverts_commit?' do
+ describe "#reverts_commit?" do
let(:another_commit) { double(:commit, revert_description: "This reverts commit #{commit.sha}") }
let(:user) { commit.author }
it { expect(commit.reverts_commit?(another_commit, user)).to be_falsy }
- context 'commit has no description' do
+ context "commit has no description" do
before do
allow(commit).to receive(:description?).and_return(false)
end
@@ -434,94 +434,94 @@ eos
end
end
- describe '#last_pipeline' do
+ describe "#last_pipeline" do
let!(:first_pipeline) do
create(:ci_empty_pipeline,
project: project,
sha: commit.sha,
- status: 'success')
+ status: "success")
end
let!(:second_pipeline) do
create(:ci_empty_pipeline,
project: project,
sha: commit.sha,
- status: 'success')
+ status: "success")
end
- it 'returns last pipeline' do
+ it "returns last pipeline" do
expect(commit.last_pipeline).to eq second_pipeline
end
end
- describe '#status' do
- context 'without ref argument' do
+ describe "#status" do
+ context "without ref argument" do
before do
%w[success failed created pending].each do |status|
create(:ci_empty_pipeline,
- project: project,
- sha: commit.sha,
- status: status)
+ project: project,
+ sha: commit.sha,
+ status: status)
end
end
- it 'gives compound status from latest pipelines' do
+ it "gives compound status from latest pipelines" do
expect(commit.status).to eq(Ci::Pipeline.latest_status)
- expect(commit.status).to eq('pending')
+ expect(commit.status).to eq("pending")
end
end
- context 'when a particular ref is specified' do
+ context "when a particular ref is specified" do
let!(:pipeline_from_master) do
create(:ci_empty_pipeline,
- project: project,
- sha: commit.sha,
- ref: 'master',
- status: 'failed')
+ project: project,
+ sha: commit.sha,
+ ref: "master",
+ status: "failed")
end
let!(:pipeline_from_fix) do
create(:ci_empty_pipeline,
- project: project,
- sha: commit.sha,
- ref: 'fix',
- status: 'success')
+ project: project,
+ sha: commit.sha,
+ ref: "fix",
+ status: "success")
end
- it 'gives pipelines from a particular branch' do
- expect(commit.status('master')).to eq(pipeline_from_master.status)
- expect(commit.status('fix')).to eq(pipeline_from_fix.status)
+ it "gives pipelines from a particular branch" do
+ expect(commit.status("master")).to eq(pipeline_from_master.status)
+ expect(commit.status("fix")).to eq(pipeline_from_fix.status)
end
- it 'gives compound status from latest pipelines if ref is nil' do
+ it "gives compound status from latest pipelines if ref is nil" do
expect(commit.status(nil)).to eq(pipeline_from_fix.status)
end
end
end
- describe '#set_status_for_ref' do
- it 'sets the status for a given reference' do
- commit.set_status_for_ref('master', 'failed')
+ describe "#set_status_for_ref" do
+ it "sets the status for a given reference" do
+ commit.set_status_for_ref("master", "failed")
- expect(commit.status('master')).to eq('failed')
+ expect(commit.status("master")).to eq("failed")
end
end
- describe '#participants' do
+ describe "#participants" do
let(:user1) { build(:user) }
let(:user2) { build(:user) }
let!(:note1) do
create(:note_on_commit,
- commit_id: commit.id,
- project: project,
- note: 'foo')
+ commit_id: commit.id,
+ project: project,
+ note: "foo")
end
let!(:note2) do
create(:note_on_commit,
- commit_id: commit.id,
- project: project,
- note: 'bar')
+ commit_id: commit.id,
+ project: project,
+ note: "bar")
end
before do
@@ -529,57 +529,57 @@ eos
allow(commit).to receive(:committer).and_return(user2)
end
- it 'includes the commit author' do
+ it "includes the commit author" do
expect(commit.participants).to include(commit.author)
end
- it 'includes the committer' do
+ it "includes the committer" do
expect(commit.participants).to include(commit.committer)
end
- it 'includes the authors of the commit notes' do
+ it "includes the authors of the commit notes" do
expect(commit.participants).to include(note1.author, note2.author)
end
end
- describe '#uri_type' do
- it 'returns the URI type at the given path' do
- expect(commit.uri_type('files/html')).to be(:tree)
- expect(commit.uri_type('files/images/logo-black.png')).to be(:raw)
- expect(project.commit('video').uri_type('files/videos/intro.mp4')).to be(:raw)
- expect(commit.uri_type('files/js/application.js')).to be(:blob)
+ describe "#uri_type" do
+ it "returns the URI type at the given path" do
+ expect(commit.uri_type("files/html")).to be(:tree)
+ expect(commit.uri_type("files/images/logo-black.png")).to be(:raw)
+ expect(project.commit("video").uri_type("files/videos/intro.mp4")).to be(:raw)
+ expect(commit.uri_type("files/js/application.js")).to be(:blob)
end
it "returns nil if the path doesn't exists" do
- expect(commit.uri_type('this/path/doesnt/exist')).to be_nil
- expect(commit.uri_type('../path/doesnt/exist')).to be_nil
+ expect(commit.uri_type("this/path/doesnt/exist")).to be_nil
+ expect(commit.uri_type("../path/doesnt/exist")).to be_nil
end
- it 'is nil if the path is nil or empty' do
+ it "is nil if the path is nil or empty" do
expect(commit.uri_type(nil)).to be_nil
expect(commit.uri_type("")).to be_nil
end
end
- describe '.from_hash' do
+ describe ".from_hash" do
let(:new_commit) { described_class.from_hash(commit.to_hash, project) }
- it 'returns a Commit' do
+ it "returns a Commit" do
expect(new_commit).to be_an_instance_of(described_class)
end
- it 'wraps a Gitlab::Git::Commit' do
+ it "wraps a Gitlab::Git::Commit" do
expect(new_commit.raw).to be_an_instance_of(Gitlab::Git::Commit)
end
- it 'stores the correct commit fields' do
+ it "stores the correct commit fields" do
expect(new_commit.id).to eq(commit.id)
expect(new_commit.message).to eq(commit.message)
end
end
- describe '#work_in_progress?' do
- ['squash! ', 'fixup! ', 'wip: ', 'WIP: ', '[WIP] '].each do |wip_prefix|
+ describe "#work_in_progress?" do
+ ["squash! ", "fixup! ", "wip: ", "WIP: ", "[WIP] "].each do |wip_prefix|
it "detects the '#{wip_prefix}' prefix" do
commit.message = "#{wip_prefix}#{commit.message}"
@@ -606,32 +606,32 @@ eos
end
end
- describe '.valid_hash?' do
- it 'checks hash contents' do
- expect(described_class.valid_hash?('abcdef01239ABCDEF')).to be true
+ describe ".valid_hash?" do
+ it "checks hash contents" do
+ expect(described_class.valid_hash?("abcdef01239ABCDEF")).to be true
expect(described_class.valid_hash?("abcdef01239ABCD\nEF")).to be false
- expect(described_class.valid_hash?(' abcdef01239ABCDEF ')).to be false
- expect(described_class.valid_hash?('Gabcdef01239ABCDEF')).to be false
- expect(described_class.valid_hash?('gabcdef01239ABCDEF')).to be false
- expect(described_class.valid_hash?('-abcdef01239ABCDEF')).to be false
+ expect(described_class.valid_hash?(" abcdef01239ABCDEF ")).to be false
+ expect(described_class.valid_hash?("Gabcdef01239ABCDEF")).to be false
+ expect(described_class.valid_hash?("gabcdef01239ABCDEF")).to be false
+ expect(described_class.valid_hash?("-abcdef01239ABCDEF")).to be false
end
- it 'checks hash length' do
- expect(described_class.valid_hash?('a' * 6)).to be false
- expect(described_class.valid_hash?('a' * 7)).to be true
- expect(described_class.valid_hash?('a' * 40)).to be true
- expect(described_class.valid_hash?('a' * 41)).to be false
+ it "checks hash length" do
+ expect(described_class.valid_hash?("a" * 6)).to be false
+ expect(described_class.valid_hash?("a" * 7)).to be true
+ expect(described_class.valid_hash?("a" * 40)).to be true
+ expect(described_class.valid_hash?("a" * 41)).to be false
end
end
- describe '#merge_requests' do
+ describe "#merge_requests" do
let!(:project) { create(:project, :repository) }
- let!(:merge_request1) { create(:merge_request, source_project: project, source_branch: 'master', target_branch: 'feature') }
- let!(:merge_request2) { create(:merge_request, source_project: project, source_branch: 'merged-target', target_branch: 'feature') }
+ let!(:merge_request1) { create(:merge_request, source_project: project, source_branch: "master", target_branch: "feature") }
+ let!(:merge_request2) { create(:merge_request, source_project: project, source_branch: "merged-target", target_branch: "feature") }
let(:commit1) { merge_request1.merge_request_diff.commits.last }
let(:commit2) { merge_request1.merge_request_diff.commits.first }
- it 'returns merge_requests that introduced that commit' do
+ it "returns merge_requests that introduced that commit" do
expect(commit1.merge_requests).to contain_exactly(merge_request1, merge_request2)
expect(commit2.merge_requests).to contain_exactly(merge_request1)
end
diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb
index 8b7c88805c1..266f0921f07 100644
--- a/spec/models/commit_status_spec.rb
+++ b/spec/models/commit_status_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe CommitStatus do
set(:project) { create(:project, :repository) }
@@ -7,13 +7,13 @@ describe CommitStatus do
create(:ci_pipeline, project: project, sha: project.commit.id)
end
- let(:commit_status) { create_status(stage: 'test') }
+ let(:commit_status) { create_status(stage: "test") }
def create_status(**opts)
create(:commit_status, pipeline: pipeline, **opts)
end
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
it { is_expected.to belong_to(:pipeline) }
it { is_expected.to belong_to(:user) }
@@ -21,7 +21,7 @@ describe CommitStatus do
it { is_expected.to belong_to(:auto_canceled_by) }
it { is_expected.to validate_presence_of(:name) }
- it { is_expected.to validate_inclusion_of(:status).in_array(%w(pending running failed success canceled)) }
+ it { is_expected.to validate_inclusion_of(:status).in_array(%w[pending running failed success canceled]) }
it { is_expected.to delegate_method(:sha).to(:pipeline) }
it { is_expected.to delegate_method(:short_sha).to(:pipeline) }
@@ -31,7 +31,7 @@ describe CommitStatus do
it { is_expected.to respond_to :running? }
it { is_expected.to respond_to :pending? }
- describe '#author' do
+ describe "#author" do
subject { commit_status.author }
before do
@@ -41,20 +41,20 @@ describe CommitStatus do
it { is_expected.to eq(commit_status.user) }
end
- describe 'status state machine' do
+ describe "status state machine" do
let!(:commit_status) { create(:commit_status, :running, project: project) }
- it 'invalidates the cache after a transition' do
+ it "invalidates the cache after a transition" do
expect(ExpireJobCacheWorker).to receive(:perform_async).with(commit_status.id)
commit_status.success!
end
end
- describe '#started?' do
+ describe "#started?" do
subject { commit_status.started? }
- context 'without started_at' do
+ context "without started_at" do
before do
commit_status.started_at = nil
end
@@ -83,7 +83,7 @@ describe CommitStatus do
end
end
- describe '#active?' do
+ describe "#active?" do
subject { commit_status.active? }
%w[pending running].each do |state|
@@ -107,7 +107,7 @@ describe CommitStatus do
end
end
- describe '#complete?' do
+ describe "#complete?" do
subject { commit_status.complete? }
%w[success failed canceled].each do |state|
@@ -131,13 +131,13 @@ describe CommitStatus do
end
end
- describe '#cancel' do
+ describe "#cancel" do
subject { job.cancel }
- context 'when status is scheduled' do
+ context "when status is scheduled" do
let(:job) { build(:commit_status, :scheduled) }
- it 'updates the status' do
+ it "updates the status" do
subject
expect(job).to be_canceled
@@ -145,38 +145,38 @@ describe CommitStatus do
end
end
- describe '#auto_canceled?' do
+ describe "#auto_canceled?" do
subject { commit_status.auto_canceled? }
- context 'when it is canceled' do
+ context "when it is canceled" do
before do
- commit_status.update(status: 'canceled')
+ commit_status.update(status: "canceled")
end
- context 'when there is auto_canceled_by' do
+ context "when there is auto_canceled_by" do
before do
commit_status.update(auto_canceled_by: create(:ci_empty_pipeline))
end
- it 'is auto canceled' do
+ it "is auto canceled" do
is_expected.to be_truthy
end
end
- context 'when there is no auto_canceled_by' do
- it 'is not auto canceled' do
+ context "when there is no auto_canceled_by" do
+ it "is not auto canceled" do
is_expected.to be_falsey
end
end
end
end
- describe '#duration' do
+ describe "#duration" do
subject { commit_status.duration }
it { is_expected.to eq(120.0) }
- context 'if the building process has not started yet' do
+ context "if the building process has not started yet" do
before do
commit_status.started_at = nil
commit_status.finished_at = nil
@@ -185,7 +185,7 @@ describe CommitStatus do
it { is_expected.to be_nil }
end
- context 'if the building process has started' do
+ context "if the building process has started" do
before do
commit_status.started_at = Time.now - 1.minute
commit_status.finished_at = nil
@@ -196,195 +196,195 @@ describe CommitStatus do
end
end
- describe '.latest' do
+ describe ".latest" do
subject { described_class.latest.order(:id) }
let(:statuses) do
- [create_status(name: 'aa', ref: 'bb', status: 'running', retried: true),
- create_status(name: 'cc', ref: 'cc', status: 'pending', retried: true),
- create_status(name: 'aa', ref: 'cc', status: 'success', retried: true),
- create_status(name: 'cc', ref: 'bb', status: 'success'),
- create_status(name: 'aa', ref: 'bb', status: 'success')]
+ [create_status(name: "aa", ref: "bb", status: "running", retried: true),
+ create_status(name: "cc", ref: "cc", status: "pending", retried: true),
+ create_status(name: "aa", ref: "cc", status: "success", retried: true),
+ create_status(name: "cc", ref: "bb", status: "success"),
+ create_status(name: "aa", ref: "bb", status: "success"),]
end
- it 'returns unique statuses' do
+ it "returns unique statuses" do
is_expected.to eq(statuses.values_at(3, 4))
end
end
- describe '.retried' do
+ describe ".retried" do
subject { described_class.retried.order(:id) }
let(:statuses) do
- [create_status(name: 'aa', ref: 'bb', status: 'running', retried: true),
- create_status(name: 'cc', ref: 'cc', status: 'pending', retried: true),
- create_status(name: 'aa', ref: 'cc', status: 'success', retried: true),
- create_status(name: 'cc', ref: 'bb', status: 'success'),
- create_status(name: 'aa', ref: 'bb', status: 'success')]
+ [create_status(name: "aa", ref: "bb", status: "running", retried: true),
+ create_status(name: "cc", ref: "cc", status: "pending", retried: true),
+ create_status(name: "aa", ref: "cc", status: "success", retried: true),
+ create_status(name: "cc", ref: "bb", status: "success"),
+ create_status(name: "aa", ref: "bb", status: "success"),]
end
- it 'returns unique statuses' do
+ it "returns unique statuses" do
is_expected.to contain_exactly(*statuses.values_at(0, 1, 2))
end
end
- describe '.running_or_pending' do
+ describe ".running_or_pending" do
subject { described_class.running_or_pending.order(:id) }
let(:statuses) do
- [create_status(name: 'aa', ref: 'bb', status: 'running'),
- create_status(name: 'cc', ref: 'cc', status: 'pending'),
- create_status(name: 'aa', ref: nil, status: 'success'),
- create_status(name: 'dd', ref: nil, status: 'failed'),
- create_status(name: 'ee', ref: nil, status: 'canceled')]
+ [create_status(name: "aa", ref: "bb", status: "running"),
+ create_status(name: "cc", ref: "cc", status: "pending"),
+ create_status(name: "aa", ref: nil, status: "success"),
+ create_status(name: "dd", ref: nil, status: "failed"),
+ create_status(name: "ee", ref: nil, status: "canceled"),]
end
- it 'returns statuses that are running or pending' do
+ it "returns statuses that are running or pending" do
is_expected.to contain_exactly(*statuses.values_at(0, 1))
end
end
- describe '.after_stage' do
+ describe ".after_stage" do
subject { described_class.after_stage(0) }
let(:statuses) do
- [create_status(name: 'aa', stage_idx: 0),
- create_status(name: 'cc', stage_idx: 1),
- create_status(name: 'aa', stage_idx: 2)]
+ [create_status(name: "aa", stage_idx: 0),
+ create_status(name: "cc", stage_idx: 1),
+ create_status(name: "aa", stage_idx: 2),]
end
- it 'returns statuses from second and third stage' do
+ it "returns statuses from second and third stage" do
is_expected.to eq(statuses.values_at(1, 2))
end
end
- describe '.exclude_ignored' do
+ describe ".exclude_ignored" do
subject { described_class.exclude_ignored.order(:id) }
let(:statuses) do
- [create_status(when: 'manual', status: 'skipped'),
- create_status(when: 'manual', status: 'success'),
- create_status(when: 'manual', status: 'failed'),
- create_status(when: 'on_failure', status: 'skipped'),
- create_status(when: 'on_failure', status: 'success'),
- create_status(when: 'on_failure', status: 'failed'),
- create_status(allow_failure: true, status: 'success'),
- create_status(allow_failure: true, status: 'failed'),
- create_status(allow_failure: false, status: 'success'),
- create_status(allow_failure: false, status: 'failed'),
- create_status(allow_failure: true, status: 'manual'),
- create_status(allow_failure: false, status: 'manual')]
- end
-
- it 'returns statuses without what we want to ignore' do
+ [create_status(when: "manual", status: "skipped"),
+ create_status(when: "manual", status: "success"),
+ create_status(when: "manual", status: "failed"),
+ create_status(when: "on_failure", status: "skipped"),
+ create_status(when: "on_failure", status: "success"),
+ create_status(when: "on_failure", status: "failed"),
+ create_status(allow_failure: true, status: "success"),
+ create_status(allow_failure: true, status: "failed"),
+ create_status(allow_failure: false, status: "success"),
+ create_status(allow_failure: false, status: "failed"),
+ create_status(allow_failure: true, status: "manual"),
+ create_status(allow_failure: false, status: "manual"),]
+ end
+
+ it "returns statuses without what we want to ignore" do
is_expected.to eq(statuses.values_at(0, 1, 2, 3, 4, 5, 6, 8, 9, 11))
end
end
- describe '.failed_but_allowed' do
+ describe ".failed_but_allowed" do
subject { described_class.failed_but_allowed.order(:id) }
let(:statuses) do
- [create_status(allow_failure: true, status: 'success'),
- create_status(allow_failure: true, status: 'failed'),
- create_status(allow_failure: false, status: 'success'),
- create_status(allow_failure: false, status: 'failed'),
- create_status(allow_failure: true, status: 'canceled'),
- create_status(allow_failure: false, status: 'canceled'),
- create_status(allow_failure: true, status: 'manual'),
- create_status(allow_failure: false, status: 'manual')]
+ [create_status(allow_failure: true, status: "success"),
+ create_status(allow_failure: true, status: "failed"),
+ create_status(allow_failure: false, status: "success"),
+ create_status(allow_failure: false, status: "failed"),
+ create_status(allow_failure: true, status: "canceled"),
+ create_status(allow_failure: false, status: "canceled"),
+ create_status(allow_failure: true, status: "manual"),
+ create_status(allow_failure: false, status: "manual"),]
end
- it 'returns statuses without what we want to ignore' do
+ it "returns statuses without what we want to ignore" do
is_expected.to eq(statuses.values_at(1, 4))
end
end
- describe '.status' do
- context 'when there are multiple statuses present' do
+ describe ".status" do
+ context "when there are multiple statuses present" do
before do
- create_status(status: 'running')
- create_status(status: 'success')
- create_status(allow_failure: true, status: 'failed')
+ create_status(status: "running")
+ create_status(status: "success")
+ create_status(allow_failure: true, status: "failed")
end
- it 'returns a correct compound status' do
- expect(described_class.all.status).to eq 'running'
+ it "returns a correct compound status" do
+ expect(described_class.all.status).to eq "running"
end
end
- context 'when there are only allowed to fail commit statuses present' do
+ context "when there are only allowed to fail commit statuses present" do
before do
- create_status(allow_failure: true, status: 'failed')
+ create_status(allow_failure: true, status: "failed")
end
- it 'returns status that indicates success' do
- expect(described_class.all.status).to eq 'success'
+ it "returns status that indicates success" do
+ expect(described_class.all.status).to eq "success"
end
end
- context 'when using a scope to select latest statuses' do
+ context "when using a scope to select latest statuses" do
before do
- create_status(name: 'test', retried: true, status: 'failed')
- create_status(allow_failure: true, name: 'test', status: 'failed')
+ create_status(name: "test", retried: true, status: "failed")
+ create_status(allow_failure: true, name: "test", status: "failed")
end
- it 'returns status according to the scope' do
- expect(described_class.latest.status).to eq 'success'
+ it "returns status according to the scope" do
+ expect(described_class.latest.status).to eq "success"
end
end
end
- describe '#before_sha' do
+ describe "#before_sha" do
subject { commit_status.before_sha }
- context 'when no before_sha is set for pipeline' do
+ context "when no before_sha is set for pipeline" do
before do
pipeline.before_sha = nil
end
- it 'returns blank sha' do
+ it "returns blank sha" do
is_expected.to eq(Gitlab::Git::BLANK_SHA)
end
end
- context 'for before_sha set for pipeline' do
- let(:value) { '1234' }
+ context "for before_sha set for pipeline" do
+ let(:value) { "1234" }
before do
pipeline.before_sha = value
end
- it 'returns the set value' do
+ it "returns the set value" do
is_expected.to eq(value)
end
end
end
- describe '#commit' do
- it 'returns commit pipeline has been created for' do
+ describe "#commit" do
+ it "returns commit pipeline has been created for" do
expect(commit_status.commit).to eq project.commit
end
end
- describe '#group_name' do
+ describe "#group_name" do
subject { commit_status.group_name }
tests = {
- 'rspec:windows' => 'rspec:windows',
- 'rspec:windows 0' => 'rspec:windows 0',
- 'rspec:windows 0 test' => 'rspec:windows 0 test',
- 'rspec:windows 0 1' => 'rspec:windows',
- 'rspec:windows 0 1 name' => 'rspec:windows name',
- 'rspec:windows 0/1' => 'rspec:windows',
- 'rspec:windows 0/1 name' => 'rspec:windows name',
- 'rspec:windows 0:1' => 'rspec:windows',
- 'rspec:windows 0:1 name' => 'rspec:windows name',
- 'rspec:windows 10000 20000' => 'rspec:windows',
- 'rspec:windows 0 : / 1' => 'rspec:windows',
- 'rspec:windows 0 : / 1 name' => 'rspec:windows name',
- '0 1 name ruby' => 'name ruby',
- '0 :/ 1 name ruby' => 'name ruby'
+ "rspec:windows" => "rspec:windows",
+ "rspec:windows 0" => "rspec:windows 0",
+ "rspec:windows 0 test" => "rspec:windows 0 test",
+ "rspec:windows 0 1" => "rspec:windows",
+ "rspec:windows 0 1 name" => "rspec:windows name",
+ "rspec:windows 0/1" => "rspec:windows",
+ "rspec:windows 0/1 name" => "rspec:windows name",
+ "rspec:windows 0:1" => "rspec:windows",
+ "rspec:windows 0:1 name" => "rspec:windows name",
+ "rspec:windows 10000 20000" => "rspec:windows",
+ "rspec:windows 0 : / 1" => "rspec:windows",
+ "rspec:windows 0 : / 1 name" => "rspec:windows name",
+ "0 1 name ruby" => "name ruby",
+ "0 :/ 1 name ruby" => "name ruby",
}
tests.each do |name, group_name|
@@ -396,24 +396,24 @@ describe CommitStatus do
end
end
- describe '#detailed_status' do
+ describe "#detailed_status" do
let(:user) { create(:user) }
- it 'returns a detailed status' do
+ it "returns a detailed status" do
expect(commit_status.detailed_status(user))
.to be_a Gitlab::Ci::Status::Success
end
end
- describe '#sortable_name' do
+ describe "#sortable_name" do
tests = {
- 'karma' => ['karma'],
- 'karma 0 20' => ['karma ', 0, ' ', 20],
- 'karma 10 20' => ['karma ', 10, ' ', 20],
- 'karma 50:100' => ['karma ', 50, ':', 100],
- 'karma 1.10' => ['karma ', 1, '.', 10],
- 'karma 1.5.1' => ['karma ', 1, '.', 5, '.', 1],
- 'karma 1 a' => ['karma ', 1, ' a']
+ "karma" => ["karma"],
+ "karma 0 20" => ["karma ", 0, " ", 20],
+ "karma 10 20" => ["karma ", 10, " ", 20],
+ "karma 50:100" => ["karma ", 50, ":", 100],
+ "karma 1.10" => ["karma ", 1, ".", 10],
+ "karma 1.5.1" => ["karma ", 1, ".", 5, ".", 1],
+ "karma 1 a" => ["karma ", 1, " a"],
}
tests.each do |name, sortable_name|
@@ -424,7 +424,7 @@ describe CommitStatus do
end
end
- describe '#locking_enabled?' do
+ describe "#locking_enabled?" do
before do
commit_status.lock_version = 100
end
@@ -460,7 +460,7 @@ describe CommitStatus do
end
end
- describe 'set failure_reason when drop' do
+ describe "set failure_reason when drop" do
let(:commit_status) { create(:commit_status, :created) }
subject do
@@ -468,46 +468,46 @@ describe CommitStatus do
commit_status
end
- context 'when failure_reason is nil' do
+ context "when failure_reason is nil" do
let(:reason) { }
it { is_expected.to be_unknown_failure }
end
- context 'when failure_reason is script_failure' do
+ context "when failure_reason is script_failure" do
let(:reason) { :script_failure }
it { is_expected.to be_script_failure }
end
end
- describe 'ensure stage assignment' do
- context 'when commit status has a stage_id assigned' do
+ describe "ensure stage assignment" do
+ context "when commit status has a stage_id assigned" do
let!(:stage) do
create(:ci_stage_entity, project: project, pipeline: pipeline)
end
let(:commit_status) do
- create(:commit_status, stage_id: stage.id, name: 'rspec', stage: 'test')
+ create(:commit_status, stage_id: stage.id, name: "rspec", stage: "test")
end
- it 'does not create a new stage' do
+ it "does not create a new stage" do
expect { commit_status }.not_to change { Ci::Stage.count }
expect(commit_status.stage_id).to eq stage.id
end
end
- context 'when commit status does not have a stage_id assigned' do
+ context "when commit status does not have a stage_id assigned" do
let(:commit_status) do
- create(:commit_status, name: 'rspec', stage: 'test', status: :success)
+ create(:commit_status, name: "rspec", stage: "test", status: :success)
end
let(:stage) { Ci::Stage.first }
- it 'creates a new stage' do
+ it "creates a new stage" do
expect { commit_status }.to change { Ci::Stage.count }.by(1)
- expect(stage.name).to eq 'test'
+ expect(stage.name).to eq "test"
expect(stage.project).to eq commit_status.project
expect(stage.pipeline).to eq commit_status.pipeline
expect(stage.status).to eq commit_status.status
@@ -515,22 +515,22 @@ describe CommitStatus do
end
end
- context 'when commit status does not have stage but it exists' do
+ context "when commit status does not have stage but it exists" do
let!(:stage) do
create(:ci_stage_entity, project: project,
pipeline: pipeline,
- name: 'test')
+ name: "test")
end
let(:commit_status) do
create(:commit_status, project: project,
pipeline: pipeline,
- name: 'rspec',
- stage: 'test',
+ name: "rspec",
+ stage: "test",
status: :success)
end
- it 'uses existing stage' do
+ it "uses existing stage" do
expect { commit_status }.not_to change { Ci::Stage.count }
expect(commit_status.stage_id).to eq stage.id
@@ -538,57 +538,57 @@ describe CommitStatus do
end
end
- context 'when commit status is being imported' do
+ context "when commit status is being imported" do
let(:commit_status) do
- create(:commit_status, name: 'rspec', stage: 'test', importing: true)
+ create(:commit_status, name: "rspec", stage: "test", importing: true)
end
- it 'does not create a new stage' do
+ it "does not create a new stage" do
expect { commit_status }.not_to change { Ci::Stage.count }
expect(commit_status.stage_id).not_to be_present
end
end
end
- describe '#enqueue' do
+ describe "#enqueue" do
let!(:current_time) { Time.new(2018, 4, 5, 14, 0, 0) }
before do
allow(Time).to receive(:now).and_return(current_time)
end
- shared_examples 'commit status enqueued' do
- it 'sets queued_at value when enqueued' do
+ shared_examples "commit status enqueued" do
+ it "sets queued_at value when enqueued" do
expect { commit_status.enqueue }.to change { commit_status.reload.queued_at }.from(nil).to(current_time)
end
end
- context 'when initial state is :created' do
+ context "when initial state is :created" do
let(:commit_status) { create(:commit_status, :created) }
- it_behaves_like 'commit status enqueued'
+ it_behaves_like "commit status enqueued"
end
- context 'when initial state is :skipped' do
+ context "when initial state is :skipped" do
let(:commit_status) { create(:commit_status, :skipped) }
- it_behaves_like 'commit status enqueued'
+ it_behaves_like "commit status enqueued"
end
- context 'when initial state is :manual' do
+ context "when initial state is :manual" do
let(:commit_status) { create(:commit_status, :manual) }
- it_behaves_like 'commit status enqueued'
+ it_behaves_like "commit status enqueued"
end
- context 'when initial state is :scheduled' do
+ context "when initial state is :scheduled" do
let(:commit_status) { create(:commit_status, :scheduled) }
- it_behaves_like 'commit status enqueued'
+ it_behaves_like "commit status enqueued"
end
end
- describe '#present' do
+ describe "#present" do
subject { commit_status.present }
it { is_expected.to be_a(CommitStatusPresenter) }
diff --git a/spec/models/compare_spec.rb b/spec/models/compare_spec.rb
index 0bc3ee014e6..832eb9cbfed 100644
--- a/spec/models/compare_spec.rb
+++ b/spec/models/compare_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Compare do
include RepoHelpers
@@ -13,32 +13,32 @@ describe Compare do
subject { described_class.new(raw_compare, project) }
- describe '#start_commit' do
- it 'returns raw compare base commit' do
+ describe "#start_commit" do
+ it "returns raw compare base commit" do
expect(subject.start_commit.id).to eq(start_commit.id)
end
- it 'returns nil if compare base commit is nil' do
+ it "returns nil if compare base commit is nil" do
expect(raw_compare).to receive(:base).and_return(nil)
expect(subject.start_commit).to eq(nil)
end
end
- describe '#commit' do
- it 'returns raw compare head commit' do
+ describe "#commit" do
+ it "returns raw compare head commit" do
expect(subject.commit.id).to eq(head_commit.id)
end
- it 'returns nil if compare head commit is nil' do
+ it "returns nil if compare head commit is nil" do
expect(raw_compare).to receive(:head).and_return(nil)
expect(subject.commit).to eq(nil)
end
end
- describe '#base_commit_sha' do
- it 'returns @base_sha if it is present' do
+ describe "#base_commit_sha" do
+ it "returns @base_sha if it is present" do
expect(project).not_to receive(:merge_base_commit)
sha = double
@@ -47,7 +47,7 @@ describe Compare do
expect(service.base_commit_sha).to eq(sha)
end
- it 'fetches merge base SHA from repo when @base_sha is nil' do
+ it "fetches merge base SHA from repo when @base_sha is nil" do
expect(project).to receive(:merge_base_commit)
.with(start_commit.id, head_commit.id)
.once
@@ -57,7 +57,7 @@ describe Compare do
.to eq(project.repository.merge_base(start_commit.id, head_commit.id))
end
- it 'is memoized on first call' do
+ it "is memoized on first call" do
expect(project).to receive(:merge_base_commit)
.with(start_commit.id, head_commit.id)
.once
@@ -66,57 +66,51 @@ describe Compare do
3.times { subject.base_commit_sha }
end
- it 'returns nil if there is no start_commit' do
+ it "returns nil if there is no start_commit" do
expect(subject).to receive(:start_commit).and_return(nil)
expect(subject.base_commit_sha).to eq(nil)
end
- it 'returns nil if there is no head commit' do
+ it "returns nil if there is no head commit" do
expect(subject).to receive(:head_commit).and_return(nil)
expect(subject.base_commit_sha).to eq(nil)
end
end
- describe '#diff_refs' do
- it 'uses base_commit_sha sha as base_sha' do
+ describe "#diff_refs" do
+ it "uses base_commit_sha sha as base_sha" do
expect(subject.diff_refs.base_sha).to eq(subject.base_commit_sha)
end
- it 'uses start_commit sha as start_sha' do
+ it "uses start_commit sha as start_sha" do
expect(subject.diff_refs.start_sha).to eq(start_commit.id)
end
- it 'uses commit sha as head sha' do
+ it "uses commit sha as head sha" do
expect(subject.diff_refs.head_sha).to eq(head_commit.id)
end
end
- describe '#modified_paths' do
- context 'changes are present' do
+ describe "#modified_paths" do
+ context "changes are present" do
let(:raw_compare) do
Gitlab::Git::Compare.new(
- project.repository.raw_repository, 'before-create-delete-modify-move', 'after-create-delete-modify-move'
+ project.repository.raw_repository, "before-create-delete-modify-move", "after-create-delete-modify-move"
)
end
- it 'returns affected file paths, without duplication' do
- expect(subject.modified_paths).to contain_exactly(*%w{
- foo/for_move.txt
- foo/bar/for_move.txt
- foo/for_create.txt
- foo/for_delete.txt
- foo/for_edit.txt
- })
+ it "returns affected file paths, without duplication" do
+ expect(subject.modified_paths).to contain_exactly("foo/for_move.txt", "foo/bar/for_move.txt", "foo/for_create.txt", "foo/for_delete.txt", "foo/for_edit.txt")
end
end
- context 'changes are absent' do
+ context "changes are absent" do
let(:start_commit) { sample_commit }
let(:head_commit) { sample_commit }
- it 'returns empty array' do
+ it "returns empty array" do
expect(subject.modified_paths).to eq([])
end
end
diff --git a/spec/models/concerns/access_requestable_spec.rb b/spec/models/concerns/access_requestable_spec.rb
index 04d6cfa2c02..461d7a17de9 100644
--- a/spec/models/concerns/access_requestable_spec.rb
+++ b/spec/models/concerns/access_requestable_spec.rb
@@ -1,8 +1,8 @@
-require 'spec_helper'
+require "spec_helper"
describe AccessRequestable do
- describe 'Group' do
- describe '#request_access' do
+ describe "Group" do
+ describe "#request_access" do
let(:group) { create(:group, :public, :access_requestable) }
let(:user) { create(:user) }
@@ -10,7 +10,7 @@ describe AccessRequestable do
it { expect(group.request_access(user).user).to eq(user) }
end
- describe '#access_requested?' do
+ describe "#access_requested?" do
let(:group) { create(:group, :public, :access_requestable) }
let(:user) { create(:user) }
@@ -22,15 +22,15 @@ describe AccessRequestable do
end
end
- describe 'Project' do
- describe '#request_access' do
+ describe "Project" do
+ describe "#request_access" do
let(:project) { create(:project, :public, :access_requestable) }
let(:user) { create(:user) }
it { expect(project.request_access(user)).to be_a(ProjectMember) }
end
- describe '#access_requested?' do
+ describe "#access_requested?" do
let(:project) { create(:project, :public, :access_requestable) }
let(:user) { create(:user) }
diff --git a/spec/models/concerns/avatarable_spec.rb b/spec/models/concerns/avatarable_spec.rb
index 1ea7f2b9985..245625b80bd 100644
--- a/spec/models/concerns/avatarable_spec.rb
+++ b/spec/models/concerns/avatarable_spec.rb
@@ -1,43 +1,43 @@
-require 'spec_helper'
+require "spec_helper"
describe Avatarable do
let(:project) { create(:project, :with_avatar) }
let(:gitlab_host) { "https://gitlab.example.com" }
let(:relative_url_root) { "/gitlab" }
- let(:asset_host) { 'https://gitlab-assets.example.com' }
+ let(:asset_host) { "https://gitlab-assets.example.com" }
before do
stub_config_setting(base_url: gitlab_host)
stub_config_setting(relative_url_root: relative_url_root)
end
- describe '#update' do
+ describe "#update" do
let(:validator) { project._validators[:avatar].detect { |v| v.is_a?(FileSizeValidator) } }
- context 'when avatar changed' do
- it 'validates the file size' do
+ context "when avatar changed" do
+ it "validates the file size" do
expect(validator).to receive(:validate_each).and_call_original
- project.update(avatar: 'uploads/avatar.png')
+ project.update(avatar: "uploads/avatar.png")
end
end
- context 'when avatar was not changed' do
- it 'skips validation of file size' do
+ context "when avatar was not changed" do
+ it "skips validation of file size" do
expect(validator).not_to receive(:validate_each)
- project.update(name: 'Hello world')
+ project.update(name: "Hello world")
end
end
end
- describe '#avatar_path' do
- context 'with caching enabled', :request_store do
+ describe "#avatar_path" do
+ context "with caching enabled", :request_store do
let!(:avatar_path) { [relative_url_root, project.avatar.local_url].join }
let!(:avatar_url) { [gitlab_host, relative_url_root, project.avatar.local_url].join }
- it 'only calls local_url once' do
+ it "only calls local_url once" do
expect(project.avatar).to receive(:local_url).once.and_call_original
2.times do
@@ -45,21 +45,21 @@ describe Avatarable do
end
end
- it 'calls local_url twice for path and URLs' do
+ it "calls local_url twice for path and URLs" do
expect(project.avatar).to receive(:local_url).exactly(2).times.and_call_original
expect(project.avatar_path(only_path: true)).to eq(avatar_path)
expect(project.avatar_path(only_path: false)).to eq(avatar_url)
end
- it 'calls local_url twice for different sizes' do
+ it "calls local_url twice for different sizes" do
expect(project.avatar).to receive(:local_url).exactly(2).times.and_call_original
expect(project.avatar_path).to eq(avatar_path)
expect(project.avatar_path(size: 40)).to eq(avatar_path + "?width=40")
end
- it 'handles unpersisted objects' do
+ it "handles unpersisted objects" do
new_project = build(:project, :with_avatar)
path = [relative_url_root, new_project.avatar.local_url].join
expect(new_project.avatar).to receive(:local_url).exactly(2).times.and_call_original
@@ -96,11 +96,11 @@ describe Avatarable do
let(:avatar_path) { (avatar_path_prefix + [project.avatar.local_url]).join }
- it 'returns the expected avatar path' do
+ it "returns the expected avatar path" do
expect(project.avatar_path(only_path: only_path)).to eq(avatar_path)
end
- it 'returns the expected avatar path with width parameter' do
+ it "returns the expected avatar path with width parameter" do
expect(project.avatar_path(only_path: only_path, size: 128)).to eq(avatar_path + "?width=128")
end
@@ -111,7 +111,7 @@ describe Avatarable do
project.avatar.migrate!(ObjectStorage::Store::REMOTE)
end
- it 'returns the expected avatar path' do
+ it "returns the expected avatar path" do
expect(project.avatar_url(only_path: only_path)).to eq(avatar_path)
end
end
diff --git a/spec/models/concerns/awardable_spec.rb b/spec/models/concerns/awardable_spec.rb
index 5713106418d..54623244b7d 100644
--- a/spec/models/concerns/awardable_spec.rb
+++ b/spec/models/concerns/awardable_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Awardable do
let!(:issue) { create(:issue) }
@@ -62,18 +62,18 @@ describe Awardable do
end
end
- describe '#user_can_award?' do
+ describe "#user_can_award?" do
let(:user) { create(:user) }
before do
issue.project.add_guest(user)
end
- it 'is truthy when the user is allowed to award emoji' do
+ it "is truthy when the user is allowed to award emoji" do
expect(issue.user_can_award?(user)).to be_truthy
end
- it 'is falsy when the project is archived' do
+ it "is falsy when the project is archived" do
issue.project.update!(archived: true)
expect(issue.user_can_award?(user)).to be_falsy
@@ -90,10 +90,10 @@ describe Awardable do
end
end
- describe 'querying award_emoji on an Awardable' do
+ describe "querying award_emoji on an Awardable" do
let(:issue) { create(:issue) }
- it 'sorts in ascending fashion' do
+ it "sorts in ascending fashion" do
create_list(:award_emoji, 3, awardable: issue)
expect(issue.award_emoji).to eq issue.award_emoji.sort_by(&:id)
diff --git a/spec/models/concerns/batch_destroy_dependent_associations_spec.rb b/spec/models/concerns/batch_destroy_dependent_associations_spec.rb
index e5392fe0462..14dced7846e 100644
--- a/spec/models/concerns/batch_destroy_dependent_associations_spec.rb
+++ b/spec/models/concerns/batch_destroy_dependent_associations_spec.rb
@@ -1,8 +1,8 @@
-require 'spec_helper'
+require "spec_helper"
describe BatchDestroyDependentAssociations do
class TestProject < ActiveRecord::Base
- self.table_name = 'projects'
+ self.table_name = "projects"
has_many :builds, dependent: :destroy
has_many :notification_settings, as: :source, dependent: :delete_all
@@ -12,21 +12,21 @@ describe BatchDestroyDependentAssociations do
include BatchDestroyDependentAssociations
end
- describe '#dependent_associations_to_destroy' do
+ describe "#dependent_associations_to_destroy" do
set(:project) { TestProject.new }
- it 'returns the right associations' do
+ it "returns the right associations" do
expect(project.dependent_associations_to_destroy.map(&:name)).to match_array([:builds])
end
end
- describe '#destroy_dependent_associations_in_batches' do
+ describe "#destroy_dependent_associations_in_batches" do
set(:project) { create(:project) }
set(:build) { create(:ci_build, project: project) }
set(:notification_setting) { create(:notification_setting, project: project) }
let!(:todos) { create(:todo, project: project) }
- it 'destroys multiple builds' do
+ it "destroys multiple builds" do
create(:ci_build, project: project)
expect(Ci::Build.count).to eq(2)
@@ -36,7 +36,7 @@ describe BatchDestroyDependentAssociations do
expect(Ci::Build.count).to eq(0)
end
- it 'destroys builds in batches' do
+ it "destroys builds in batches" do
expect(project).to receive_message_chain(:builds, :find_each).and_yield(build)
expect(build).to receive(:destroy).and_call_original
@@ -48,7 +48,7 @@ describe BatchDestroyDependentAssociations do
expect(NotificationSetting.count).to eq(User.count)
end
- it 'excludes associations' do
+ it "excludes associations" do
project.destroy_dependent_associations_in_batches(exclude: [:builds])
expect(Ci::Build.count).to eq(1)
diff --git a/spec/models/concerns/blob_language_from_git_attributes_spec.rb b/spec/models/concerns/blob_language_from_git_attributes_spec.rb
index 7f05073b08e..619e3e17498 100644
--- a/spec/models/concerns/blob_language_from_git_attributes_spec.rb
+++ b/spec/models/concerns/blob_language_from_git_attributes_spec.rb
@@ -1,22 +1,22 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe BlobLanguageFromGitAttributes do
include FakeBlobHelpers
let(:project) { build(:project, :repository) }
- describe '#language_from_gitattributes' do
- subject(:blob) { fake_blob(path: 'file.md') }
+ describe "#language_from_gitattributes" do
+ subject(:blob) { fake_blob(path: "file.md") }
- it 'returns return value from gitattribute' do
- expect(blob.project.repository).to receive(:gitattribute).with(blob.path, 'gitlab-language').and_return('erb?parent=json')
+ it "returns return value from gitattribute" do
+ expect(blob.project.repository).to receive(:gitattribute).with(blob.path, "gitlab-language").and_return("erb?parent=json")
- expect(blob.language_from_gitattributes).to eq('erb?parent=json')
+ expect(blob.language_from_gitattributes).to eq("erb?parent=json")
end
- it 'returns nil if project is absent' do
+ it "returns nil if project is absent" do
allow(blob).to receive(:project).and_return(nil)
expect(blob.language_from_gitattributes).to eq(nil)
diff --git a/spec/models/concerns/blocks_json_serialization_spec.rb b/spec/models/concerns/blocks_json_serialization_spec.rb
index 5906b588d0e..a95d2379696 100644
--- a/spec/models/concerns/blocks_json_serialization_spec.rb
+++ b/spec/models/concerns/blocks_json_serialization_spec.rb
@@ -1,16 +1,16 @@
-require 'rails_helper'
+require "rails_helper"
describe BlocksJsonSerialization do
- DummyModel = Class.new do
+ DummyModel = Class.new {
include BlocksJsonSerialization
- end
+ }
- it 'blocks as_json' do
+ it "blocks as_json" do
expect { DummyModel.new.as_json }
.to raise_error(described_class::JsonSerializationError, /DummyModel/)
end
- it 'blocks to_json' do
+ it "blocks to_json" do
expect { DummyModel.new.to_json }
.to raise_error(described_class::JsonSerializationError, /DummyModel/)
end
diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb
index 447279f19a8..e89dd5d3fc4 100644
--- a/spec/models/concerns/cache_markdown_field_spec.rb
+++ b/spec/models/concerns/cache_markdown_field_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe CacheMarkdownField do
# The minimum necessary ActiveModel to test this concern
@@ -70,10 +70,10 @@ describe CacheMarkdownField do
Class.new(ThingWithMarkdownFields) { add_attr(new_attr) }
end
- let(:markdown) { '`Foo`' }
+ let(:markdown) { "`Foo`" }
let(:html) { '<p dir="auto"><code>Foo</code></p>' }
- let(:updated_markdown) { '`Bar`' }
+ let(:updated_markdown) { "`Bar`" }
let(:updated_html) { '<p dir="auto"><code>Bar</code></p>' }
let(:thing) { ThingWithMarkdownFields.new(foo: markdown, foo_html: html, cached_markdown_version: cache_version) }
@@ -83,13 +83,13 @@ describe CacheMarkdownField do
stub_commonmark_sourcepos_disabled
end
- describe '.attributes' do
- it 'excludes cache attributes' do
+ describe ".attributes" do
+ it "excludes cache attributes" do
expect(thing.attributes.keys.sort).to eq(%w[bar baz foo])
end
end
- context 'an unchanged markdown field' do
+ context "an unchanged markdown field" do
before do
thing.foo = thing.foo
thing.save
@@ -101,7 +101,7 @@ describe CacheMarkdownField do
it { expect(thing.cached_markdown_version).to eq(cache_version) }
end
- context 'a changed markdown field' do
+ context "a changed markdown field" do
let(:thing) { ThingWithMarkdownFields.new(foo: markdown, foo_html: html, cached_markdown_version: cache_version - 1) }
before do
@@ -113,50 +113,50 @@ describe CacheMarkdownField do
it { expect(thing.cached_markdown_version).to eq(cache_version) }
end
- context 'when a markdown field is set repeatedly to an empty string' do
+ context "when a markdown field is set repeatedly to an empty string" do
it do
expect(thing).to receive(:refresh_markdown_cache).once
- thing.foo = ''
+ thing.foo = ""
thing.save
- thing.foo = ''
+ thing.foo = ""
thing.save
end
end
- context 'when a markdown field is set repeatedly to a string which renders as empty html' do
+ context "when a markdown field is set repeatedly to a string which renders as empty html" do
it do
expect(thing).to receive(:refresh_markdown_cache).once
- thing.foo = '[//]: # (This is also a comment.)'
+ thing.foo = "[//]: # (This is also a comment.)"
thing.save
- thing.foo = '[//]: # (This is also a comment.)'
+ thing.foo = "[//]: # (This is also a comment.)"
thing.save
end
end
- context 'when a markdown field and html field are both changed' do
+ context "when a markdown field and html field are both changed" do
it do
expect(thing).not_to receive(:refresh_markdown_cache)
- thing.foo = '_look over there!_'
- thing.foo_html = '<em>look over there!</em>'
+ thing.foo = "_look over there!_"
+ thing.foo_html = "<em>look over there!</em>"
thing.save
end
end
- context 'a non-markdown field changed' do
+ context "a non-markdown field changed" do
let(:thing) { ThingWithMarkdownFields.new(foo: markdown, foo_html: html, cached_markdown_version: cache_version - 1) }
before do
- thing.bar = 'OK'
+ thing.bar = "OK"
thing.save
end
- it { expect(thing.bar).to eq('OK') }
+ it { expect(thing.bar).to eq("OK") }
it { expect(thing.foo).to eq(markdown) }
it { expect(thing.foo_html).to eq(html) }
it { expect(thing.cached_markdown_version).to eq(cache_version) }
end
- context 'version is out of date' do
+ context "version is out of date" do
let(:thing) { ThingWithMarkdownFields.new(foo: updated_markdown, foo_html: html, cached_markdown_version: nil) }
before do
@@ -167,90 +167,90 @@ describe CacheMarkdownField do
it { expect(thing.cached_markdown_version).to eq(cache_version) }
end
- describe '#cached_html_up_to_date?' do
+ describe "#cached_html_up_to_date?" do
let(:thing) { ThingWithMarkdownFields.new(foo: markdown, foo_html: html, cached_markdown_version: cache_version) }
subject { thing.cached_html_up_to_date?(:foo) }
- it 'returns false when the version is absent' do
+ it "returns false when the version is absent" do
thing.cached_markdown_version = nil
is_expected.to be_falsy
end
- it 'returns false when the cached version is too old' do
+ it "returns false when the cached version is too old" do
thing.cached_markdown_version = cache_version - 1
is_expected.to be_falsy
end
- it 'returns false when the cached version is in future' do
+ it "returns false when the cached version is in future" do
thing.cached_markdown_version = cache_version + 1
is_expected.to be_falsy
end
- it 'returns false when the local version was bumped' do
+ it "returns false when the local version was bumped" do
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:local_markdown_version).and_return(2)
thing.cached_markdown_version = cache_version
is_expected.to be_falsy
end
- it 'returns true when the local version is default' do
+ it "returns true when the local version is default" do
thing.cached_markdown_version = cache_version
is_expected.to be_truthy
end
- it 'returns true when the cached version is just right' do
+ it "returns true when the cached version is just right" do
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:local_markdown_version).and_return(2)
thing.cached_markdown_version = cache_version + 2
is_expected.to be_truthy
end
- it 'returns false if markdown has been changed but html has not' do
+ it "returns false if markdown has been changed but html has not" do
thing.foo = updated_html
is_expected.to be_falsy
end
- it 'returns true if markdown has not been changed but html has' do
+ it "returns true if markdown has not been changed but html has" do
thing.foo_html = updated_html
is_expected.to be_truthy
end
- it 'returns true if markdown and html have both been changed' do
+ it "returns true if markdown and html have both been changed" do
thing.foo = updated_markdown
thing.foo_html = updated_html
is_expected.to be_truthy
end
- it 'returns false if the markdown field is set but the html is not' do
+ it "returns false if the markdown field is set but the html is not" do
thing.foo_html = nil
is_expected.to be_falsy
end
end
- describe '#latest_cached_markdown_version' do
+ describe "#latest_cached_markdown_version" do
subject { thing.latest_cached_markdown_version }
- it 'returns default version' do
+ it "returns default version" do
thing.cached_markdown_version = nil
is_expected.to eq(cache_version)
end
end
- describe '#refresh_markdown_cache' do
+ describe "#refresh_markdown_cache" do
before do
thing.foo = updated_markdown
end
- it 'fills all html fields' do
+ it "fills all html fields" do
thing.refresh_markdown_cache
expect(thing.foo_html).to eq(updated_html)
@@ -258,13 +258,13 @@ describe CacheMarkdownField do
expect(thing.baz_html_changed?).to be_truthy
end
- it 'does not save the result' do
+ it "does not save the result" do
expect(thing).not_to receive(:update_columns)
thing.refresh_markdown_cache
end
- it 'updates the markdown cache version' do
+ it "updates the markdown cache version" do
thing.cached_markdown_version = nil
thing.refresh_markdown_cache
@@ -272,14 +272,14 @@ describe CacheMarkdownField do
end
end
- describe '#refresh_markdown_cache!' do
+ describe "#refresh_markdown_cache!" do
let(:thing) { ThingWithMarkdownFields.new(foo: markdown, foo_html: html, cached_markdown_version: cache_version) }
before do
thing.foo = updated_markdown
end
- it 'fills all html fields' do
+ it "fills all html fields" do
thing.refresh_markdown_cache!
expect(thing.foo_html).to eq(updated_html)
@@ -287,14 +287,14 @@ describe CacheMarkdownField do
expect(thing.baz_html_changed?).to be_truthy
end
- it 'skips saving if not persisted' do
+ it "skips saving if not persisted" do
expect(thing).to receive(:persisted?).and_return(false)
expect(thing).not_to receive(:update_columns)
thing.refresh_markdown_cache!
end
- it 'saves the changes using #update_columns' do
+ it "saves the changes using #update_columns" do
expect(thing).to receive(:persisted?).and_return(true)
expect(thing).to receive(:update_columns)
.with("foo_html" => updated_html, "baz_html" => "", "cached_markdown_version" => cache_version)
@@ -303,45 +303,45 @@ describe CacheMarkdownField do
end
end
- describe '#banzai_render_context' do
+ describe "#banzai_render_context" do
subject(:context) { thing.banzai_render_context(:foo) }
- it 'sets project to nil if the object lacks a project' do
+ it "sets project to nil if the object lacks a project" do
is_expected.to have_key(:project)
expect(context[:project]).to be_nil
end
- it 'excludes author if the object lacks an author' do
+ it "excludes author if the object lacks an author" do
is_expected.not_to have_key(:author)
end
- it 'raises if the context for an unrecognised field is requested' do
+ it "raises if the context for an unrecognised field is requested" do
expect { thing.banzai_render_context(:not_found) }.to raise_error(ArgumentError)
end
- it 'includes the pipeline' do
+ it "includes the pipeline" do
baz = thing.banzai_render_context(:baz)
expect(baz[:pipeline]).to eq(:single_line)
end
- it 'returns copies of the context template' do
+ it "returns copies of the context template" do
template = thing.cached_markdown_fields[:baz]
copy = thing.banzai_render_context(:baz)
expect(copy).not_to be(template)
end
- context 'with a project' do
+ context "with a project" do
let(:project) { create(:project, group: create(:group)) }
let(:thing) { thing_subclass(:project).new(foo: markdown, foo_html: html, project: project) }
- it 'sets the project in the context' do
+ it "sets the project in the context" do
is_expected.to have_key(:project)
expect(context[:project]).to eq(project)
end
- it 'invalidates the cache when project changes' do
+ it "invalidates the cache when project changes" do
thing.project = :new_project
allow(Banzai::Renderer).to receive(:cacheless_render_field).and_return(updated_html)
@@ -353,15 +353,15 @@ describe CacheMarkdownField do
end
end
- context 'with an author' do
+ context "with an author" do
let(:thing) { thing_subclass(:author).new(foo: markdown, foo_html: html, author: :author_value) }
- it 'sets the author in the context' do
+ it "sets the author in the context" do
is_expected.to have_key(:author)
expect(context[:author]).to eq(:author_value)
end
- it 'invalidates the cache when author changes' do
+ it "invalidates the cache when author changes" do
thing.author = :new_author
allow(Banzai::Renderer).to receive(:cacheless_render_field).and_return(updated_html)
diff --git a/spec/models/concerns/cacheable_attributes_spec.rb b/spec/models/concerns/cacheable_attributes_spec.rb
index 43a544cfe26..e8ef745e83d 100644
--- a/spec/models/concerns/cacheable_attributes_spec.rb
+++ b/spec/models/concerns/cacheable_attributes_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe CacheableAttributes do
let(:minimal_test_class) do
@@ -9,15 +9,15 @@ describe CacheableAttributes do
include CacheableAttributes
def self.name
- 'TestClass'
+ "TestClass"
end
def self.first
- @_first ||= new('foo' => 'a')
+ @_first ||= new("foo" => "a")
end
def self.last
- @_last ||= new('foo' => 'a', 'bar' => 'b')
+ @_last ||= new("foo" => "a", "bar" => "b")
end
def self.column_names
@@ -32,20 +32,20 @@ describe CacheableAttributes do
end
end
- shared_context 'with defaults' do
+ shared_context "with defaults" do
before do
minimal_test_class.define_singleton_method(:defaults) do
- { foo: 'a', bar: 'b', baz: 'c' }
+ {foo: "a", bar: "b", baz: "c"}
end
end
end
- describe '.current_without_cache' do
- it 'defaults to last' do
+ describe ".current_without_cache" do
+ it "defaults to last" do
expect(minimal_test_class.current_without_cache).to eq(minimal_test_class.last)
end
- it 'can be overridden' do
+ it "can be overridden" do
minimal_test_class.define_singleton_method(:current_without_cache) do
first
end
@@ -54,45 +54,45 @@ describe CacheableAttributes do
end
end
- describe '.cache_key' do
- it 'excludes cache attributes' do
+ describe ".cache_key" do
+ it "excludes cache attributes" do
expect(minimal_test_class.cache_key).to eq("TestClass:#{Gitlab::VERSION}:#{Rails.version}")
end
end
- describe '.defaults' do
- it 'defaults to {}' do
+ describe ".defaults" do
+ it "defaults to {}" do
expect(minimal_test_class.defaults).to eq({})
end
- context 'with defaults defined' do
- include_context 'with defaults'
+ context "with defaults defined" do
+ include_context "with defaults"
- it 'can be overridden' do
- expect(minimal_test_class.defaults).to eq({ foo: 'a', bar: 'b', baz: 'c' })
+ it "can be overridden" do
+ expect(minimal_test_class.defaults).to eq({foo: "a", bar: "b", baz: "c"})
end
end
end
- describe '.build_from_defaults' do
- include_context 'with defaults'
+ describe ".build_from_defaults" do
+ include_context "with defaults"
- context 'without any attributes given' do
- it 'intializes a new object with the defaults' do
+ context "without any attributes given" do
+ it "intializes a new object with the defaults" do
expect(minimal_test_class.build_from_defaults.attributes).to eq(minimal_test_class.defaults.stringify_keys)
end
end
- context 'with attributes given' do
- it 'intializes a new object with the given attributes merged into the defaults' do
- expect(minimal_test_class.build_from_defaults(foo: 'd').attributes['foo']).to eq('d')
+ context "with attributes given" do
+ it "intializes a new object with the given attributes merged into the defaults" do
+ expect(minimal_test_class.build_from_defaults(foo: "d").attributes["foo"]).to eq("d")
end
end
- describe 'edge cases on concrete implementations' do
- describe '.build_from_defaults' do
- context 'without any attributes given' do
- it 'intializes all attributes even if they are nil' do
+ describe "edge cases on concrete implementations" do
+ describe ".build_from_defaults" do
+ context "without any attributes given" do
+ it "intializes all attributes even if they are nil" do
record = ApplicationSetting.build_from_defaults
expect(record).not_to be_persisted
@@ -103,31 +103,31 @@ describe CacheableAttributes do
end
end
- describe '.current', :use_clean_rails_memory_store_caching do
- context 'redis unavailable' do
+ describe ".current", :use_clean_rails_memory_store_caching do
+ context "redis unavailable" do
before do
allow(minimal_test_class).to receive(:last).and_return(:last)
expect(Rails.cache).to receive(:read).with(minimal_test_class.cache_key).and_raise(Redis::BaseError)
end
- context 'in production environment' do
+ context "in production environment" do
before do
expect(Rails.env).to receive(:production?).and_return(true)
end
- it 'returns an uncached record and logs a warning' do
+ it "returns an uncached record and logs a warning" do
expect(Rails.logger).to receive(:warn).with("Cached record for TestClass couldn't be loaded, falling back to uncached record: Redis::BaseError")
expect(minimal_test_class.current).to eq(:last)
end
end
- context 'in other environments' do
+ context "in other environments" do
before do
expect(Rails.env).to receive(:production?).and_return(false)
end
- it 'returns an uncached record and logs a warning' do
+ it "returns an uncached record and logs a warning" do
expect(Rails.logger).not_to receive(:warn)
expect { minimal_test_class.current }.to raise_error(Redis::BaseError)
@@ -135,8 +135,8 @@ describe CacheableAttributes do
end
end
- context 'when a record is not yet present' do
- it 'does not cache nil object' do
+ context "when a record is not yet present" do
+ it "does not cache nil object" do
# when missing settings a nil object is returned, but not cached
allow(ApplicationSetting).to receive(:current_without_cache).twice.and_return(nil)
@@ -144,7 +144,7 @@ describe CacheableAttributes do
expect(Rails.cache.exist?(ApplicationSetting.cache_key)).to be(false)
end
- it 'caches non-nil object' do
+ it "caches non-nil object" do
create(:application_setting)
expect(ApplicationSetting.current).to eq(ApplicationSetting.last)
@@ -157,13 +157,13 @@ describe CacheableAttributes do
end
end
- describe 'edge cases' do
- describe 'caching behavior', :use_clean_rails_memory_store_caching do
+ describe "edge cases" do
+ describe "caching behavior", :use_clean_rails_memory_store_caching do
before do
stub_commonmark_sourcepos_disabled
end
- it 'retrieves upload fields properly' do
+ it "retrieves upload fields properly" do
ar_record = create(:appearance, :with_logo)
ar_record.cache!
@@ -171,22 +171,22 @@ describe CacheableAttributes do
expect(cache_record).to be_persisted
expect(cache_record.logo).to be_an(AttachmentUploader)
- expect(cache_record.logo.url).to end_with('/dk.png')
+ expect(cache_record.logo.url).to end_with("/dk.png")
end
- it 'retrieves markdown fields properly' do
- ar_record = create(:appearance, description: '**Hello**')
+ it "retrieves markdown fields properly" do
+ ar_record = create(:appearance, description: "**Hello**")
ar_record.cache!
cache_record = Appearance.current
- expect(cache_record.description).to eq('**Hello**')
+ expect(cache_record.description).to eq("**Hello**")
expect(cache_record.description_html).to eq('<p dir="auto"><strong>Hello</strong></p>')
end
end
end
- it 'uses RequestStore in addition to Rails.cache', :request_store do
+ it "uses RequestStore in addition to Rails.cache", :request_store do
# Warm up the cache
create(:application_setting).cache!
@@ -196,39 +196,39 @@ describe CacheableAttributes do
end
end
- describe '.cached', :use_clean_rails_memory_store_caching do
- context 'when cache is cold' do
- it 'returns nil' do
+ describe ".cached", :use_clean_rails_memory_store_caching do
+ context "when cache is cold" do
+ it "returns nil" do
expect(minimal_test_class.cached).to be_nil
end
end
- context 'when cached is warm' do
+ context "when cached is warm" do
before do
# Warm up the cache
create(:appearance).cache!
end
- it 'retrieves the record from cache' do
+ it "retrieves the record from cache" do
expect(ActiveRecord::QueryRecorder.new { Appearance.cached }.count).to eq(0)
expect(Appearance.cached).to eq(Appearance.current_without_cache)
end
end
end
- describe '#cache!', :use_clean_rails_memory_store_caching do
+ describe "#cache!", :use_clean_rails_memory_store_caching do
let(:record) { create(:appearance) }
- it 'caches the attributes' do
+ it "caches the attributes" do
record.cache!
expect(Rails.cache.read(Appearance.cache_key)).to eq(record)
end
- describe 'edge cases' do
+ describe "edge cases" do
let(:record) { create(:appearance) }
- it 'caches the attributes' do
+ it "caches the attributes" do
record.cache!
expect(Rails.cache.read(Appearance.cache_key)).to eq(record)
diff --git a/spec/models/concerns/case_sensitivity_spec.rb b/spec/models/concerns/case_sensitivity_spec.rb
index 1bf6c9b3404..98d9593f7a2 100644
--- a/spec/models/concerns/case_sensitivity_spec.rb
+++ b/spec/models/concerns/case_sensitivity_spec.rb
@@ -1,49 +1,49 @@
-require 'spec_helper'
+require "spec_helper"
describe CaseSensitivity do
- describe '.iwhere' do
+ describe ".iwhere" do
let(:connection) { ActiveRecord::Base.connection }
let(:model) do
Class.new(ActiveRecord::Base) do
include CaseSensitivity
- self.table_name = 'namespaces'
+ self.table_name = "namespaces"
end
end
- let!(:model_1) { model.create(path: 'mOdEl-1', name: 'mOdEl 1') }
- let!(:model_2) { model.create(path: 'mOdEl-2', name: 'mOdEl 2') }
+ let!(:model_1) { model.create(path: "mOdEl-1", name: "mOdEl 1") }
+ let!(:model_2) { model.create(path: "mOdEl-2", name: "mOdEl 2") }
- it 'finds a single instance by a single attribute regardless of case' do
- expect(model.iwhere(path: 'MODEL-1')).to contain_exactly(model_1)
+ it "finds a single instance by a single attribute regardless of case" do
+ expect(model.iwhere(path: "MODEL-1")).to contain_exactly(model_1)
end
- it 'finds multiple instances by a single attribute regardless of case' do
- expect(model.iwhere(path: %w(MODEL-1 model-2))).to contain_exactly(model_1, model_2)
+ it "finds multiple instances by a single attribute regardless of case" do
+ expect(model.iwhere(path: %w[MODEL-1 model-2])).to contain_exactly(model_1, model_2)
end
- it 'finds instances by multiple attributes' do
- expect(model.iwhere(path: %w(MODEL-1 model-2), name: 'model 1'))
+ it "finds instances by multiple attributes" do
+ expect(model.iwhere(path: %w[MODEL-1 model-2], name: "model 1"))
.to contain_exactly(model_1)
end
# Using `mysql` & `postgresql` metadata-tags here because both adapters build
# the query slightly differently
- context 'for MySQL', :mysql do
- it 'builds a simple query' do
- query = model.iwhere(path: %w(MODEL-1 model-2), name: 'model 1').to_sql
+ context "for MySQL", :mysql do
+ it "builds a simple query" do
+ query = model.iwhere(path: %w[MODEL-1 model-2], name: "model 1").to_sql
expected_query = <<~QRY.strip
- SELECT `namespaces`.* FROM `namespaces` WHERE (`namespaces`.`path` IN ('MODEL-1', 'model-2')) AND (`namespaces`.`name` = 'model 1')
+ SELECT `namespaces`.* FROM `namespaces` WHERE (`namespaces`.`path` IN ('MODEL-1', 'model-2')) AND (`namespaces`.`name` = 'model 1')
QRY
expect(query).to eq(expected_query)
end
end
- context 'for PostgreSQL', :postgresql do
- it 'builds a query using LOWER' do
- query = model.iwhere(path: %w(MODEL-1 model-2), name: 'model 1').to_sql
+ context "for PostgreSQL", :postgresql do
+ it "builds a query using LOWER" do
+ query = model.iwhere(path: %w[MODEL-1 model-2], name: "model 1").to_sql
expected_query = <<~QRY.strip
- SELECT \"namespaces\".* FROM \"namespaces\" WHERE (LOWER(\"namespaces\".\"path\") IN (LOWER('MODEL-1'), LOWER('model-2'))) AND (LOWER(\"namespaces\".\"name\") = LOWER('model 1'))
+ SELECT \"namespaces\".* FROM \"namespaces\" WHERE (LOWER(\"namespaces\".\"path\") IN (LOWER('MODEL-1'), LOWER('model-2'))) AND (LOWER(\"namespaces\".\"name\") = LOWER('model 1'))
QRY
expect(query).to eq(expected_query)
diff --git a/spec/models/concerns/chronic_duration_attribute_spec.rb b/spec/models/concerns/chronic_duration_attribute_spec.rb
index 51221e07ca3..5f90bfa09d0 100644
--- a/spec/models/concerns/chronic_duration_attribute_spec.rb
+++ b/spec/models/concerns/chronic_duration_attribute_spec.rb
@@ -1,18 +1,18 @@
-require 'spec_helper'
+require "spec_helper"
-shared_examples 'ChronicDurationAttribute reader' do
- it 'contains dynamically created reader method' do
+shared_examples "ChronicDurationAttribute reader" do
+ it "contains dynamically created reader method" do
expect(subject.class).to be_public_method_defined(virtual_field)
end
- it 'outputs chronic duration formatted value' do
+ it "outputs chronic duration formatted value" do
subject.send("#{source_field}=", 120)
- expect(subject.send(virtual_field)).to eq('2m')
+ expect(subject.send(virtual_field)).to eq("2m")
end
- context 'when value is set to nil' do
- it 'outputs nil' do
+ context "when value is set to nil" do
+ it "outputs nil" do
subject.send("#{source_field}=", nil)
expect(subject.send(virtual_field)).to be_nil
@@ -20,69 +20,69 @@ shared_examples 'ChronicDurationAttribute reader' do
end
end
-shared_examples 'ChronicDurationAttribute writer' do
- it 'contains dynamically created writer method' do
+shared_examples "ChronicDurationAttribute writer" do
+ it "contains dynamically created writer method" do
expect(subject.class).to be_public_method_defined("#{virtual_field}=")
end
before do
- subject.send("#{virtual_field}=", '10m')
+ subject.send("#{virtual_field}=", "10m")
end
- it 'parses chronic duration input' do
+ it "parses chronic duration input" do
expect(subject.send(source_field)).to eq(600)
end
- it 'passes validation' do
+ it "passes validation" do
expect(subject.valid?).to be_truthy
end
- context 'when negative input is used' do
+ context "when negative input is used" do
before do
subject.send("#{source_field}=", 3600)
end
it "doesn't raise exception" do
- expect { subject.send("#{virtual_field}=", '-10m') }.not_to raise_error
+ expect { subject.send("#{virtual_field}=", "-10m") }.not_to raise_error
end
it "doesn't change value" do
- expect { subject.send("#{virtual_field}=", '-10m') }.not_to change { subject.send(source_field) }
+ expect { subject.send("#{virtual_field}=", "-10m") }.not_to change { subject.send(source_field) }
end
it "doesn't pass validation" do
- subject.send("#{virtual_field}=", '-10m')
+ subject.send("#{virtual_field}=", "-10m")
expect(subject.valid?).to be_falsey
expect(subject.errors&.messages)
- .to include(base: ['Maximum job timeout has a value which could not be accepted'])
+ .to include(base: ["Maximum job timeout has a value which could not be accepted"])
end
end
- context 'when empty input is used' do
+ context "when empty input is used" do
before do
- subject.send("#{virtual_field}=", '')
+ subject.send("#{virtual_field}=", "")
end
- it 'writes default value' do
+ it "writes default value" do
expect(subject.send(source_field)).to eq(default_value)
end
- it 'passes validation' do
+ it "passes validation" do
expect(subject.valid?).to be_truthy
end
end
- context 'when nil input is used' do
+ context "when nil input is used" do
before do
subject.send("#{virtual_field}=", nil)
end
- it 'writes default value' do
+ it "writes default value" do
expect(subject.send(source_field)).to eq(default_value)
end
- it 'passes validation' do
+ it "passes validation" do
expect(subject.valid?).to be_truthy
end
@@ -92,31 +92,31 @@ shared_examples 'ChronicDurationAttribute writer' do
end
end
-describe 'ChronicDurationAttribute' do
- context 'when default value is not set' do
+describe "ChronicDurationAttribute" do
+ context "when default value is not set" do
let(:source_field) {:maximum_timeout}
let(:virtual_field) {:maximum_timeout_human_readable}
let(:default_value) { nil }
subject { create(:ci_runner) }
- it_behaves_like 'ChronicDurationAttribute reader'
- it_behaves_like 'ChronicDurationAttribute writer'
+ it_behaves_like "ChronicDurationAttribute reader"
+ it_behaves_like "ChronicDurationAttribute writer"
end
- context 'when default value is set' do
+ context "when default value is set" do
let(:source_field) {:build_timeout}
let(:virtual_field) {:build_timeout_human_readable}
let(:default_value) { 3600 }
subject { create(:project) }
- it_behaves_like 'ChronicDurationAttribute reader'
- it_behaves_like 'ChronicDurationAttribute writer'
+ it_behaves_like "ChronicDurationAttribute reader"
+ it_behaves_like "ChronicDurationAttribute writer"
end
end
-describe 'ChronicDurationAttribute - reader' do
+describe "ChronicDurationAttribute - reader" do
let(:source_field) {:timeout}
let(:virtual_field) {:timeout_human_readable}
@@ -126,5 +126,5 @@ describe 'ChronicDurationAttribute - reader' do
expect(subject.class).not_to be_public_method_defined("#{virtual_field}=")
end
- it_behaves_like 'ChronicDurationAttribute reader'
+ it_behaves_like "ChronicDurationAttribute reader"
end
diff --git a/spec/models/concerns/deployable_spec.rb b/spec/models/concerns/deployable_spec.rb
index 6951be903fe..af029db6763 100644
--- a/spec/models/concerns/deployable_spec.rb
+++ b/spec/models/concerns/deployable_spec.rb
@@ -1,7 +1,7 @@
-require 'rails_helper'
+require "rails_helper"
describe Deployable do
- describe '#create_deployment' do
+ describe "#create_deployment" do
let(:deployment) { job.deployment }
let(:environment) { deployment&.environment }
@@ -9,63 +9,64 @@ describe Deployable do
job.reload
end
- context 'when the deployable object will deploy to production' do
+ context "when the deployable object will deploy to production" do
let!(:job) { create(:ci_build, :start_review_app) }
- it 'creates a deployment and environment record' do
+ it "creates a deployment and environment record" do
expect(deployment.project).to eq(job.project)
expect(deployment.ref).to eq(job.ref)
expect(deployment.tag).to eq(job.tag)
expect(deployment.sha).to eq(job.sha)
expect(deployment.user).to eq(job.user)
expect(deployment.deployable).to eq(job)
- expect(deployment.on_stop).to eq('stop_review_app')
- expect(environment.name).to eq('review/master')
+ expect(deployment.on_stop).to eq("stop_review_app")
+ expect(environment.name).to eq("review/master")
end
end
- context 'when the deployable object will stop an environment' do
+ context "when the deployable object will stop an environment" do
let!(:job) { create(:ci_build, :stop_review_app) }
- it 'does not create a deployment record' do
+ it "does not create a deployment record" do
expect(deployment).to be_nil
end
end
- context 'when the deployable object has already had a deployment' do
+ context "when the deployable object has already had a deployment" do
let!(:job) { create(:ci_build, :start_review_app, deployment: race_deployment) }
let!(:race_deployment) { create(:deployment, :success) }
- it 'does not create a new deployment' do
+ it "does not create a new deployment" do
expect(deployment).to eq(race_deployment)
end
end
- context 'when the deployable object will not deploy' do
+ context "when the deployable object will not deploy" do
let!(:job) { create(:ci_build) }
- it 'does not create a deployment and environment record' do
+ it "does not create a deployment and environment record" do
expect(deployment).to be_nil
expect(environment).to be_nil
end
end
- context 'when environment scope contains invalid character' do
+ context "when environment scope contains invalid character" do
let(:job) do
create(
:ci_build,
- name: 'job:deploy-to-test-site',
- environment: '$CI_JOB_NAME',
+ name: "job:deploy-to-test-site",
+ environment: "$CI_JOB_NAME",
options: {
environment: {
- name: '$CI_JOB_NAME',
- url: 'http://staging.example.com/$CI_JOB_NAME',
- on_stop: 'stop_review_app'
- }
- })
+ name: "$CI_JOB_NAME",
+ url: "http://staging.example.com/$CI_JOB_NAME",
+ on_stop: "stop_review_app",
+ },
+ }
+ )
end
- it 'does not create a deployment and environment record' do
+ it "does not create a deployment and environment record" do
expect(deployment).to be_nil
expect(environment).to be_nil
end
diff --git a/spec/models/concerns/deployment_platform_spec.rb b/spec/models/concerns/deployment_platform_spec.rb
index 19ab4382b53..d8fc7ce1e79 100644
--- a/spec/models/concerns/deployment_platform_spec.rb
+++ b/spec/models/concerns/deployment_platform_spec.rb
@@ -1,37 +1,37 @@
-require 'rails_helper'
+require "rails_helper"
describe DeploymentPlatform do
let(:project) { create(:project) }
- describe '#deployment_platform' do
+ describe "#deployment_platform" do
subject { project.deployment_platform }
- context 'with no Kubernetes configuration on CI/CD, no Kubernetes Service and a Kubernetes template configured' do
+ context "with no Kubernetes configuration on CI/CD, no Kubernetes Service and a Kubernetes template configured" do
let!(:kubernetes_service) { create(:kubernetes_service, template: true) }
- it 'returns a platform kubernetes' do
+ it "returns a platform kubernetes" do
expect(subject).to be_a_kind_of(Clusters::Platforms::Kubernetes)
end
- it 'creates a cluster and a platform kubernetes' do
+ it "creates a cluster and a platform kubernetes" do
expect { subject }
.to change { Clusters::Cluster.count }.by(1)
.and change { Clusters::Platforms::Kubernetes.count }.by(1)
end
- it 'includes appropriate attributes for Cluster' do
+ it "includes appropriate attributes for Cluster" do
cluster = subject.cluster
- expect(cluster.name).to eq('kubernetes-template')
+ expect(cluster.name).to eq("kubernetes-template")
expect(cluster.project).to eq(project)
- expect(cluster.provider_type).to eq('user')
- expect(cluster.platform_type).to eq('kubernetes')
+ expect(cluster.provider_type).to eq("user")
+ expect(cluster.platform_type).to eq("kubernetes")
end
- it 'creates a platform kubernetes' do
+ it "creates a platform kubernetes" do
expect { subject }.to change { Clusters::Platforms::Kubernetes.count }.by(1)
end
- it 'copies attributes from Clusters::Platform::Kubernetes template into the new Cluster::Platforms::Kubernetes' do
+ it "copies attributes from Clusters::Platform::Kubernetes template into the new Cluster::Platforms::Kubernetes" do
expect(subject.api_url).to eq(kubernetes_service.api_url)
expect(subject.ca_pem).to eq(kubernetes_service.ca_pem)
expect(subject.token).to eq(kubernetes_service.token)
@@ -39,32 +39,32 @@ describe DeploymentPlatform do
end
end
- context 'with no Kubernetes configuration on CI/CD, no Kubernetes Service and no Kubernetes template configured' do
+ context "with no Kubernetes configuration on CI/CD, no Kubernetes Service and no Kubernetes template configured" do
it { is_expected.to be_nil }
end
- context 'when project has configured kubernetes from CI/CD > Clusters' do
+ context "when project has configured kubernetes from CI/CD > Clusters" do
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let(:platform_kubernetes) { cluster.platform_kubernetes }
- it 'returns the Kubernetes platform' do
+ it "returns the Kubernetes platform" do
expect(subject).to eq(platform_kubernetes)
end
- context 'with a group level kubernetes cluster' do
+ context "with a group level kubernetes cluster" do
let(:group_cluster) { create(:cluster, :provided_by_gcp, :group) }
before do
project.update!(group: group_cluster.group)
end
- it 'returns the Kubernetes platform from the project cluster' do
+ it "returns the Kubernetes platform from the project cluster" do
expect(subject).to eq(platform_kubernetes)
end
end
end
- context 'when group has configured kubernetes cluster' do
+ context "when group has configured kubernetes cluster" do
let!(:group_cluster) { create(:cluster, :provided_by_gcp, :group) }
let(:group) { group_cluster.group }
@@ -72,11 +72,11 @@ describe DeploymentPlatform do
project.update!(group: group)
end
- it 'returns the Kubernetes platform' do
+ it "returns the Kubernetes platform" do
is_expected.to eq(group_cluster.platform_kubernetes)
end
- context 'when child group has configured kubernetes cluster', :nested_groups do
+ context "when child group has configured kubernetes cluster", :nested_groups do
let!(:child_group1_cluster) { create(:cluster, :provided_by_gcp, :group) }
let(:child_group1) { child_group1_cluster.group }
@@ -85,11 +85,11 @@ describe DeploymentPlatform do
child_group1.update!(parent: group)
end
- it 'returns the Kubernetes platform for the child group' do
+ it "returns the Kubernetes platform for the child group" do
is_expected.to eq(child_group1_cluster.platform_kubernetes)
end
- context 'deeply nested group' do
+ context "deeply nested group" do
let!(:child_group2_cluster) { create(:cluster, :provided_by_gcp, :group) }
let(:child_group2) { child_group2_cluster.group }
@@ -98,42 +98,42 @@ describe DeploymentPlatform do
project.update!(group: child_group2)
end
- it 'returns most nested group cluster Kubernetes platform' do
+ it "returns most nested group cluster Kubernetes platform" do
is_expected.to eq(child_group2_cluster.platform_kubernetes)
end
- context 'cluster in the middle of hierarchy is disabled' do
+ context "cluster in the middle of hierarchy is disabled" do
before do
child_group2_cluster.update!(enabled: false)
end
- it 'returns closest enabled Kubenetes platform' do
+ it "returns closest enabled Kubenetes platform" do
is_expected.to eq(child_group1_cluster.platform_kubernetes)
end
end
end
end
- context 'feature flag disabled' do
+ context "feature flag disabled" do
before do
stub_feature_flags(group_clusters: false)
end
- it 'returns nil' do
+ it "returns nil" do
is_expected.to be_nil
end
end
end
- context 'when user configured kubernetes integration from project services' do
+ context "when user configured kubernetes integration from project services" do
let!(:kubernetes_service) { create(:kubernetes_service, project: project) }
- it 'returns the Kubernetes service' do
+ it "returns the Kubernetes service" do
expect(subject).to eq(kubernetes_service)
end
end
- context 'when the cluster creation fails' do
+ context "when the cluster creation fails" do
let!(:kubernetes_service) { create(:kubernetes_service, template: true) }
before do
diff --git a/spec/models/concerns/discussion_on_diff_spec.rb b/spec/models/concerns/discussion_on_diff_spec.rb
index 64bf04071e8..53fea1ed801 100644
--- a/spec/models/concerns/discussion_on_diff_spec.rb
+++ b/spec/models/concerns/discussion_on_diff_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe DiscussionOnDiff do
subject { create(:diff_note_on_merge_request, line_number: 18).to_discussion }
@@ -13,27 +13,27 @@ describe DiscussionOnDiff do
expect(truncated_lines.count).to be <= DiffDiscussion::NUMBER_OF_TRUNCATED_DIFF_LINES
end
- context 'with truncated diff lines diff limit set' do
+ context "with truncated diff lines diff limit set" do
let(:truncated_lines) do
subject.truncated_diff_lines(
diff_limit: diff_limit
)
end
- context 'when diff limit is higher than default' do
+ context "when diff limit is higher than default" do
let(:diff_limit) { DiffDiscussion::NUMBER_OF_TRUNCATED_DIFF_LINES + 1 }
- it 'returns fewer lines than the default' do
+ it "returns fewer lines than the default" do
expect(subject.diff_lines.count).to be > diff_limit
expect(truncated_lines.count).to be <= DiffDiscussion::NUMBER_OF_TRUNCATED_DIFF_LINES
end
end
- context 'when diff_limit is lower than default' do
+ context "when diff_limit is lower than default" do
let(:diff_limit) { 3 }
- it 'returns fewer lines than the default' do
+ it "returns fewer lines than the default" do
expect(subject.diff_lines.count).to be > DiffDiscussion::NUMBER_OF_TRUNCATED_DIFF_LINES
expect(truncated_lines.count).to be <= diff_limit
@@ -57,36 +57,36 @@ describe DiscussionOnDiff do
end
end
- context 'when the discussion is on an image' do
+ context "when the discussion is on an image" do
subject { create(:image_diff_note_on_merge_request).to_discussion }
- it 'returns an empty array' do
+ it "returns an empty array" do
expect(truncated_lines).to eq([])
end
end
end
- describe '#line_code_in_diffs' do
- context 'when the discussion is active in the diff' do
+ describe "#line_code_in_diffs" do
+ context "when the discussion is active in the diff" do
let(:diff_refs) { subject.position.diff_refs }
- it 'returns the current line code' do
+ it "returns the current line code" do
expect(subject.line_code_in_diffs(diff_refs)).to eq(subject.line_code)
end
end
- context 'when the discussion was created in the diff' do
+ context "when the discussion was created in the diff" do
let(:diff_refs) { subject.original_position.diff_refs }
- it 'returns the original line code' do
+ it "returns the original line code" do
expect(subject.line_code_in_diffs(diff_refs)).to eq(subject.original_line_code)
end
end
- context 'when the discussion is unrelated to the diff' do
+ context "when the discussion is unrelated to the diff" do
let(:diff_refs) { subject.project.commit(RepoHelpers.sample_commit.id).diff_refs }
- it 'returns nil' do
+ it "returns nil" do
expect(subject.line_code_in_diffs(diff_refs)).to be_nil
end
end
diff --git a/spec/models/concerns/each_batch_spec.rb b/spec/models/concerns/each_batch_spec.rb
index 17224c09693..848f046d09a 100644
--- a/spec/models/concerns/each_batch_spec.rb
+++ b/spec/models/concerns/each_batch_spec.rb
@@ -1,12 +1,12 @@
-require 'spec_helper'
+require "spec_helper"
describe EachBatch do
- describe '.each_batch' do
+ describe ".each_batch" do
let(:model) do
Class.new(ActiveRecord::Base) do
include EachBatch
- self.table_name = 'users'
+ self.table_name = "users"
end
end
@@ -14,34 +14,34 @@ describe EachBatch do
5.times { create(:user, updated_at: 1.day.ago) }
end
- shared_examples 'each_batch handling' do |kwargs|
- it 'yields an ActiveRecord::Relation when a block is given' do
+ shared_examples "each_batch handling" do |kwargs|
+ it "yields an ActiveRecord::Relation when a block is given" do
model.each_batch(kwargs) do |relation|
expect(relation).to be_a_kind_of(ActiveRecord::Relation)
end
end
- it 'yields a batch index as the second argument' do
+ it "yields a batch index as the second argument" do
model.each_batch(kwargs) do |_, index|
expect(index).to eq(1)
end
end
- it 'accepts a custom batch size' do
+ it "accepts a custom batch size" do
amount = 0
- model.each_batch(kwargs.merge({ of: 1 })) { amount += 1 }
+ model.each_batch(kwargs.merge({of: 1})) { amount += 1 }
expect(amount).to eq(5)
end
- it 'does not include ORDER BYs in the yielded relations' do
+ it "does not include ORDER BYs in the yielded relations" do
model.each_batch do |relation|
- expect(relation.to_sql).not_to include('ORDER BY')
+ expect(relation.to_sql).not_to include("ORDER BY")
end
end
- it 'allows updating of the yielded relations' do
+ it "allows updating of the yielded relations" do
time = Time.now
model.each_batch do |relation|
@@ -52,7 +52,7 @@ describe EachBatch do
end
end
- it_behaves_like 'each_batch handling', {}
- it_behaves_like 'each_batch handling', { order_hint: :updated_at }
+ it_behaves_like "each_batch handling", {}
+ it_behaves_like "each_batch handling", {order_hint: :updated_at}
end
end
diff --git a/spec/models/concerns/editable_spec.rb b/spec/models/concerns/editable_spec.rb
index 49a9a8ebcbc..49350966c96 100644
--- a/spec/models/concerns/editable_spec.rb
+++ b/spec/models/concerns/editable_spec.rb
@@ -1,7 +1,7 @@
-require 'spec_helper'
+require "spec_helper"
describe Editable do
- describe '#edited?' do
+ describe "#edited?" do
let(:issue) { create(:issue, last_edited_at: nil) }
let(:edited_issue) { create(:issue, created_at: 3.days.ago, last_edited_at: 2.days.ago) }
diff --git a/spec/models/concerns/expirable_spec.rb b/spec/models/concerns/expirable_spec.rb
index f7b436f32e6..34052832986 100644
--- a/spec/models/concerns/expirable_spec.rb
+++ b/spec/models/concerns/expirable_spec.rb
@@ -1,28 +1,28 @@
-require 'spec_helper'
+require "spec_helper"
describe Expirable do
- describe 'ProjectMember' do
+ describe "ProjectMember" do
let(:no_expire) { create(:project_member) }
let(:expire_later) { create(:project_member, expires_at: Time.current + 6.days) }
let(:expired) { create(:project_member, expires_at: Time.current - 6.days) }
- describe '.expired' do
+ describe ".expired" do
it { expect(ProjectMember.expired).to match_array([expired]) }
end
- describe '#expired?' do
+ describe "#expired?" do
it { expect(no_expire.expired?).to eq(false) }
it { expect(expire_later.expired?).to eq(false) }
it { expect(expired.expired?).to eq(true) }
end
- describe '#expires?' do
+ describe "#expires?" do
it { expect(no_expire.expires?).to eq(false) }
it { expect(expire_later.expires?).to eq(true) }
it { expect(expired.expires?).to eq(true) }
end
- describe '#expires_soon?' do
+ describe "#expires_soon?" do
it { expect(no_expire.expires_soon?).to eq(false) }
it { expect(expire_later.expires_soon?).to eq(true) }
it { expect(expired.expires_soon?).to eq(true) }
diff --git a/spec/models/concerns/faster_cache_keys_spec.rb b/spec/models/concerns/faster_cache_keys_spec.rb
index 8d3f94267fa..0d96edeb0e3 100644
--- a/spec/models/concerns/faster_cache_keys_spec.rb
+++ b/spec/models/concerns/faster_cache_keys_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe FasterCacheKeys do
- describe '#cache_key' do
- it 'returns a String' do
+ describe "#cache_key" do
+ it "returns a String" do
# We're using a fixed string here so it's easier to set an expectation for
# the resulting cache key.
- time = '2016-08-08 16:39:00+02'
+ time = "2016-08-08 16:39:00+02"
issue = build(:issue, updated_at: time)
issue.extend(described_class)
diff --git a/spec/models/concerns/feature_gate_spec.rb b/spec/models/concerns/feature_gate_spec.rb
index 3f601243245..6bd7e023f9a 100644
--- a/spec/models/concerns/feature_gate_spec.rb
+++ b/spec/models/concerns/feature_gate_spec.rb
@@ -1,15 +1,15 @@
-require 'spec_helper'
+require "spec_helper"
describe FeatureGate do
- describe 'User' do
- describe '#flipper_id' do
- context 'when user is not persisted' do
+ describe "User" do
+ describe "#flipper_id" do
+ context "when user is not persisted" do
let(:user) { build(:user) }
it { expect(user.flipper_id).to be_nil }
end
- context 'when user is persisted' do
+ context "when user is persisted" do
let(:user) { create(:user) }
it { expect(user.flipper_id).to eq "User:#{user.id}" }
diff --git a/spec/models/concerns/from_union_spec.rb b/spec/models/concerns/from_union_spec.rb
index ee427a667c6..ec76d8ef9f0 100644
--- a/spec/models/concerns/from_union_spec.rb
+++ b/spec/models/concerns/from_union_spec.rb
@@ -1,33 +1,33 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe FromUnion do
- describe '.from_union' do
+ describe ".from_union" do
let(:model) do
Class.new(ActiveRecord::Base) do
- self.table_name = 'users'
+ self.table_name = "users"
include FromUnion
end
end
- it 'selects from the results of the UNION' do
+ it "selects from the results of the UNION" do
query = model.from_union([model.where(id: 1), model.where(id: 2)])
expect(query.to_sql).to match(/FROM \(SELECT.+UNION.+SELECT.+\) users/m)
end
- it 'supports the use of a custom alias for the sub query' do
+ it "supports the use of a custom alias for the sub query" do
query = model.from_union(
[model.where(id: 1), model.where(id: 2)],
- alias_as: 'kittens'
+ alias_as: "kittens"
)
expect(query.to_sql).to match(/FROM \(SELECT.+UNION.+SELECT.+\) kittens/m)
end
- it 'supports keeping duplicate rows' do
+ it "supports keeping duplicate rows" do
query = model.from_union(
[model.where(id: 1), model.where(id: 2)],
remove_duplicates: false
diff --git a/spec/models/concerns/group_descendant_spec.rb b/spec/models/concerns/group_descendant_spec.rb
index 28352d8c961..625dfa7de1f 100644
--- a/spec/models/concerns/group_descendant_spec.rb
+++ b/spec/models/concerns/group_descendant_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe GroupDescendant, :nested_groups do
let(:parent) { create(:group) }
@@ -9,9 +9,9 @@ describe GroupDescendant, :nested_groups do
groups + [parent, subgroup, subsub_group]
end
- context 'for a group' do
- describe '#hierarchy' do
- it 'only queries once for the ancestors' do
+ context "for a group" do
+ describe "#hierarchy" do
+ it "only queries once for the ancestors" do
# make sure the subsub_group does not have anything cached
test_group = create(:group, parent: subsub_group).reload
@@ -20,73 +20,73 @@ describe GroupDescendant, :nested_groups do
expect(query_count).to eq(1)
end
- it 'only queries once for the ancestors when a top is given' do
+ it "only queries once for the ancestors when a top is given" do
test_group = create(:group, parent: subsub_group).reload
recorder = ActiveRecord::QueryRecorder.new { test_group.hierarchy(subgroup) }
expect(recorder.count).to eq(1)
end
- it 'builds a hierarchy for a group' do
- expected_hierarchy = { parent => { subgroup => subsub_group } }
+ it "builds a hierarchy for a group" do
+ expected_hierarchy = {parent => {subgroup => subsub_group}}
expect(subsub_group.hierarchy).to eq(expected_hierarchy)
end
- it 'builds a hierarchy upto a specified parent' do
- expected_hierarchy = { subgroup => subsub_group }
+ it "builds a hierarchy upto a specified parent" do
+ expected_hierarchy = {subgroup => subsub_group}
expect(subsub_group.hierarchy(parent)).to eq(expected_hierarchy)
end
- it 'raises an error if specifying a base that is not part of the tree' do
+ it "raises an error if specifying a base that is not part of the tree" do
expect { subsub_group.hierarchy(build_stubbed(:group)) }
- .to raise_error('specified top is not part of the tree')
+ .to raise_error("specified top is not part of the tree")
end
end
- describe '.build_hierarchy' do
- it 'combines hierarchies until the top' do
+ describe ".build_hierarchy" do
+ it "combines hierarchies until the top" do
other_subgroup = create(:group, parent: parent)
other_subsub_group = create(:group, parent: subgroup)
groups = all_preloaded_groups(other_subgroup, subsub_group, other_subsub_group)
- expected_hierarchy = { parent => [other_subgroup, { subgroup => [subsub_group, other_subsub_group] }] }
+ expected_hierarchy = {parent => [other_subgroup, {subgroup => [subsub_group, other_subsub_group]}]}
expect(described_class.build_hierarchy(groups)).to eq(expected_hierarchy)
end
- it 'combines upto a given parent' do
+ it "combines upto a given parent" do
other_subgroup = create(:group, parent: parent)
other_subsub_group = create(:group, parent: subgroup)
groups = [other_subgroup, subsub_group, other_subsub_group]
groups << subgroup # Add the parent as if it was preloaded
- expected_hierarchy = [other_subgroup, { subgroup => [subsub_group, other_subsub_group] }]
+ expected_hierarchy = [other_subgroup, {subgroup => [subsub_group, other_subsub_group]}]
expect(described_class.build_hierarchy(groups, parent)).to eq(expected_hierarchy)
end
- it 'handles building a tree out of order' do
+ it "handles building a tree out of order" do
other_subgroup = create(:group, parent: parent)
other_subgroup2 = create(:group, parent: parent)
other_subsub_group = create(:group, parent: other_subgroup)
groups = all_preloaded_groups(subsub_group, other_subgroup2, other_subsub_group, other_subgroup)
- expected_hierarchy = { parent => [{ subgroup => subsub_group }, other_subgroup2, { other_subgroup => other_subsub_group }] }
+ expected_hierarchy = {parent => [{subgroup => subsub_group}, other_subgroup2, {other_subgroup => other_subsub_group}]}
expect(described_class.build_hierarchy(groups)).to eq(expected_hierarchy)
end
- it 'tracks the exception when a parent was not preloaded' do
+ it "tracks the exception when a parent was not preloaded" do
expect(Gitlab::Sentry).to receive(:track_exception).and_call_original
expect { GroupDescendant.build_hierarchy([subsub_group]) }.to raise_error(ArgumentError)
end
- it 'recovers if a parent was not reloaded by querying for the parent' do
- expected_hierarchy = { parent => { subgroup => subsub_group } }
+ it "recovers if a parent was not reloaded by querying for the parent" do
+ expected_hierarchy = {parent => {subgroup => subsub_group}}
# this does not raise in production, so stubbing it here.
allow(Gitlab::Sentry).to receive(:track_exception)
@@ -94,61 +94,61 @@ describe GroupDescendant, :nested_groups do
expect(GroupDescendant.build_hierarchy([subsub_group])).to eq(expected_hierarchy)
end
- it 'raises an error if not all elements were preloaded' do
+ it "raises an error if not all elements were preloaded" do
expect { described_class.build_hierarchy([subsub_group]) }
.to raise_error(/was not preloaded/)
end
end
end
- context 'for a project' do
+ context "for a project" do
let(:project) { create(:project, namespace: subsub_group) }
- describe '#hierarchy' do
- it 'builds a hierarchy for a project' do
- expected_hierarchy = { parent => { subgroup => { subsub_group => project } } }
+ describe "#hierarchy" do
+ it "builds a hierarchy for a project" do
+ expected_hierarchy = {parent => {subgroup => {subsub_group => project}}}
expect(project.hierarchy).to eq(expected_hierarchy)
end
- it 'builds a hierarchy upto a specified parent' do
- expected_hierarchy = { subsub_group => project }
+ it "builds a hierarchy upto a specified parent" do
+ expected_hierarchy = {subsub_group => project}
expect(project.hierarchy(subgroup)).to eq(expected_hierarchy)
end
end
- describe '.build_hierarchy' do
- it 'combines hierarchies until the top' do
+ describe ".build_hierarchy" do
+ it "combines hierarchies until the top" do
other_project = create(:project, namespace: parent)
other_subgroup_project = create(:project, namespace: subgroup)
elements = all_preloaded_groups(other_project, subsub_group, other_subgroup_project)
- expected_hierarchy = { parent => [other_project, { subgroup => [subsub_group, other_subgroup_project] }] }
+ expected_hierarchy = {parent => [other_project, {subgroup => [subsub_group, other_subgroup_project]}]}
expect(described_class.build_hierarchy(elements)).to eq(expected_hierarchy)
end
- it 'combines upto a given parent' do
+ it "combines upto a given parent" do
other_project = create(:project, namespace: parent)
other_subgroup_project = create(:project, namespace: subgroup)
elements = [other_project, subsub_group, other_subgroup_project]
elements << subgroup # Added as if it was preloaded
- expected_hierarchy = [other_project, { subgroup => [subsub_group, other_subgroup_project] }]
+ expected_hierarchy = [other_project, {subgroup => [subsub_group, other_subgroup_project]}]
expect(described_class.build_hierarchy(elements, parent)).to eq(expected_hierarchy)
end
- it 'merges to elements in the same hierarchy' do
- expected_hierarchy = { parent => subgroup }
+ it "merges to elements in the same hierarchy" do
+ expected_hierarchy = {parent => subgroup}
expect(described_class.build_hierarchy([parent, subgroup])).to eq(expected_hierarchy)
end
- it 'merges complex hierarchies' do
+ it "merges complex hierarchies" do
project = create(:project, namespace: parent)
sub_project = create(:project, namespace: subgroup)
subsubsub_group = create(:group, parent: subsub_group)
@@ -165,11 +165,11 @@ describe GroupDescendant, :nested_groups do
project,
{
subgroup => [
- { subsub_group => [{ subsubsub_group => subsubsub_project }, subsub_project] },
- sub_project
- ]
+ {subsub_group => [{subsubsub_group => subsubsub_project}, subsub_project]},
+ sub_project,
+ ],
},
- { other_subgroup => other_subproject }
+ {other_subgroup => other_subproject},
]
actual_hierarchy = described_class.build_hierarchy(elements, parent)
diff --git a/spec/models/concerns/has_ref_spec.rb b/spec/models/concerns/has_ref_spec.rb
index 8aed72d77a4..21840d08830 100644
--- a/spec/models/concerns/has_ref_spec.rb
+++ b/spec/models/concerns/has_ref_spec.rb
@@ -1,57 +1,57 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe HasRef do
- describe '#branch?' do
+ describe "#branch?" do
let(:build) { create(:ci_build) }
subject { build.branch? }
- context 'is not a tag' do
+ context "is not a tag" do
before do
build.tag = false
end
- it 'return true when tag is set to false' do
+ it "return true when tag is set to false" do
is_expected.to be_truthy
end
end
- context 'is not a tag' do
+ context "is not a tag" do
before do
build.tag = true
end
- it 'return false when tag is set to true' do
+ it "return false when tag is set to true" do
is_expected.to be_falsey
end
end
end
- describe '#git_ref' do
+ describe "#git_ref" do
subject { build.git_ref }
- context 'when tag is true' do
+ context "when tag is true" do
let(:build) { create(:ci_build, tag: true) }
- it 'returns a tag ref' do
+ it "returns a tag ref" do
is_expected.to start_with(Gitlab::Git::TAG_REF_PREFIX)
end
end
- context 'when tag is false' do
+ context "when tag is false" do
let(:build) { create(:ci_build, tag: false) }
- it 'returns a branch ref' do
+ it "returns a branch ref" do
is_expected.to start_with(Gitlab::Git::BRANCH_REF_PREFIX)
end
end
- context 'when tag is nil' do
+ context "when tag is nil" do
let(:build) { create(:ci_build, tag: nil) }
- it 'returns a branch ref' do
+ it "returns a branch ref" do
is_expected.to start_with(Gitlab::Git::BRANCH_REF_PREFIX)
end
end
diff --git a/spec/models/concerns/has_status_spec.rb b/spec/models/concerns/has_status_spec.rb
index 6b1038cb8fd..7e06f3f074c 100644
--- a/spec/models/concerns/has_status_spec.rb
+++ b/spec/models/concerns/has_status_spec.rb
@@ -1,185 +1,185 @@
-require 'spec_helper'
+require "spec_helper"
describe HasStatus do
- describe '.status' do
+ describe ".status" do
subject { CommitStatus.status }
- shared_examples 'build status summary' do
- context 'all successful' do
+ shared_examples "build status summary" do
+ context "all successful" do
let!(:statuses) { Array.new(2) { create(type, status: :success) } }
- it { is_expected.to eq 'success' }
+ it { is_expected.to eq "success" }
end
- context 'at least one failed' do
+ context "at least one failed" do
let!(:statuses) do
[create(type, status: :success), create(type, status: :failed)]
end
- it { is_expected.to eq 'failed' }
+ it { is_expected.to eq "failed" }
end
- context 'at least one running' do
+ context "at least one running" do
let!(:statuses) do
[create(type, status: :success), create(type, status: :running)]
end
- it { is_expected.to eq 'running' }
+ it { is_expected.to eq "running" }
end
- context 'at least one pending' do
+ context "at least one pending" do
let!(:statuses) do
[create(type, status: :success), create(type, status: :pending)]
end
- it { is_expected.to eq 'running' }
+ it { is_expected.to eq "running" }
end
- context 'success and failed but allowed to fail' do
+ context "success and failed but allowed to fail" do
let!(:statuses) do
[create(type, status: :success),
- create(type, status: :failed, allow_failure: true)]
+ create(type, status: :failed, allow_failure: true),]
end
- it { is_expected.to eq 'success' }
+ it { is_expected.to eq "success" }
end
- context 'one failed but allowed to fail' do
+ context "one failed but allowed to fail" do
let!(:statuses) do
[create(type, status: :failed, allow_failure: true)]
end
- it { is_expected.to eq 'success' }
+ it { is_expected.to eq "success" }
end
- context 'success and canceled' do
+ context "success and canceled" do
let!(:statuses) do
[create(type, status: :success), create(type, status: :canceled)]
end
- it { is_expected.to eq 'canceled' }
+ it { is_expected.to eq "canceled" }
end
- context 'one failed and one canceled' do
+ context "one failed and one canceled" do
let!(:statuses) do
[create(type, status: :failed), create(type, status: :canceled)]
end
- it { is_expected.to eq 'failed' }
+ it { is_expected.to eq "failed" }
end
- context 'one failed but allowed to fail and one canceled' do
+ context "one failed but allowed to fail and one canceled" do
let!(:statuses) do
[create(type, status: :failed, allow_failure: true),
- create(type, status: :canceled)]
+ create(type, status: :canceled),]
end
- it { is_expected.to eq 'canceled' }
+ it { is_expected.to eq "canceled" }
end
- context 'one running one canceled' do
+ context "one running one canceled" do
let!(:statuses) do
[create(type, status: :running), create(type, status: :canceled)]
end
- it { is_expected.to eq 'running' }
+ it { is_expected.to eq "running" }
end
- context 'all canceled' do
+ context "all canceled" do
let!(:statuses) do
[create(type, status: :canceled), create(type, status: :canceled)]
end
- it { is_expected.to eq 'canceled' }
+ it { is_expected.to eq "canceled" }
end
- context 'success and canceled but allowed to fail' do
+ context "success and canceled but allowed to fail" do
let!(:statuses) do
[create(type, status: :success),
- create(type, status: :canceled, allow_failure: true)]
+ create(type, status: :canceled, allow_failure: true),]
end
- it { is_expected.to eq 'success' }
+ it { is_expected.to eq "success" }
end
- context 'one finished and second running but allowed to fail' do
+ context "one finished and second running but allowed to fail" do
let!(:statuses) do
[create(type, status: :success),
- create(type, status: :running, allow_failure: true)]
+ create(type, status: :running, allow_failure: true),]
end
- it { is_expected.to eq 'running' }
+ it { is_expected.to eq "running" }
end
- context 'when one status finished and second is still created' do
+ context "when one status finished and second is still created" do
let!(:statuses) do
[create(type, status: :success), create(type, status: :created)]
end
- it { is_expected.to eq 'running' }
+ it { is_expected.to eq "running" }
end
- context 'when there is a manual status before created status' do
+ context "when there is a manual status before created status" do
let!(:statuses) do
[create(type, status: :success),
create(type, status: :manual, allow_failure: false),
- create(type, status: :created)]
+ create(type, status: :created),]
end
- it { is_expected.to eq 'manual' }
+ it { is_expected.to eq "manual" }
end
- context 'when one status is a blocking manual action' do
+ context "when one status is a blocking manual action" do
let!(:statuses) do
[create(type, status: :failed),
- create(type, status: :manual, allow_failure: false)]
+ create(type, status: :manual, allow_failure: false),]
end
- it { is_expected.to eq 'manual' }
+ it { is_expected.to eq "manual" }
end
- context 'when one status is a non-blocking manual action' do
+ context "when one status is a non-blocking manual action" do
let!(:statuses) do
[create(type, status: :failed),
- create(type, status: :manual, allow_failure: true)]
+ create(type, status: :manual, allow_failure: true),]
end
- it { is_expected.to eq 'failed' }
+ it { is_expected.to eq "failed" }
end
end
- context 'ci build statuses' do
+ context "ci build statuses" do
let(:type) { :ci_build }
- it_behaves_like 'build status summary'
+ it_behaves_like "build status summary"
end
- context 'generic commit statuses' do
+ context "generic commit statuses" do
let(:type) { :generic_commit_status }
- it_behaves_like 'build status summary'
+ it_behaves_like "build status summary"
end
end
- context 'for scope with one status' do
- shared_examples 'having a job' do |status|
+ context "for scope with one status" do
+ shared_examples "having a job" do |status|
%i[ci_build generic_commit_status].each do |type|
context "when it's #{status} #{type} job" do
let!(:job) { create(type, status) }
describe ".#{status}" do
- it 'contains the job' do
+ it "contains the job" do
expect(CommitStatus.public_send(status).all)
.to contain_exactly(job)
end
end
- describe '.relevant' do
+ describe ".relevant" do
if status == :created
- it 'contains nothing' do
+ it "contains nothing" do
expect(CommitStatus.relevant.all).to be_empty
end
else
- it 'contains the job' do
+ it "contains the job" do
expect(CommitStatus.relevant.all).to contain_exactly(job)
end
end
@@ -190,151 +190,151 @@ describe HasStatus do
%i[created running pending success
failed canceled skipped].each do |status|
- it_behaves_like 'having a job', status
+ it_behaves_like "having a job", status
end
end
- context 'for scope with more statuses' do
- shared_examples 'containing the job' do |status|
+ context "for scope with more statuses" do
+ shared_examples "containing the job" do |status|
%i[ci_build generic_commit_status].each do |type|
context "when it's #{status} #{type} job" do
let!(:job) { create(type, status) }
- it 'contains the job' do
+ it "contains the job" do
is_expected.to contain_exactly(job)
end
end
end
end
- shared_examples 'not containing the job' do |status|
+ shared_examples "not containing the job" do |status|
%i[ci_build generic_commit_status].each do |type|
context "when it's #{status} #{type} job" do
let!(:job) { create(type, status) }
- it 'contains nothing' do
+ it "contains nothing" do
is_expected.to be_empty
end
end
end
end
- describe '.running_or_pending' do
+ describe ".running_or_pending" do
subject { CommitStatus.running_or_pending }
%i[running pending].each do |status|
- it_behaves_like 'containing the job', status
+ it_behaves_like "containing the job", status
end
%i[created failed success].each do |status|
- it_behaves_like 'not containing the job', status
+ it_behaves_like "not containing the job", status
end
end
- describe '.alive' do
+ describe ".alive" do
subject { CommitStatus.alive }
%i[running pending created].each do |status|
- it_behaves_like 'containing the job', status
+ it_behaves_like "containing the job", status
end
%i[failed success].each do |status|
- it_behaves_like 'not containing the job', status
+ it_behaves_like "not containing the job", status
end
end
- describe '.created_or_pending' do
+ describe ".created_or_pending" do
subject { CommitStatus.created_or_pending }
%i[created pending].each do |status|
- it_behaves_like 'containing the job', status
+ it_behaves_like "containing the job", status
end
%i[running failed success].each do |status|
- it_behaves_like 'not containing the job', status
+ it_behaves_like "not containing the job", status
end
end
- describe '.finished' do
+ describe ".finished" do
subject { CommitStatus.finished }
%i[success failed canceled].each do |status|
- it_behaves_like 'containing the job', status
+ it_behaves_like "containing the job", status
end
%i[created running pending].each do |status|
- it_behaves_like 'not containing the job', status
+ it_behaves_like "not containing the job", status
end
end
- describe '.cancelable' do
+ describe ".cancelable" do
subject { CommitStatus.cancelable }
%i[running pending created scheduled].each do |status|
- it_behaves_like 'containing the job', status
+ it_behaves_like "containing the job", status
end
%i[failed success skipped canceled manual].each do |status|
- it_behaves_like 'not containing the job', status
+ it_behaves_like "not containing the job", status
end
end
- describe '.manual' do
+ describe ".manual" do
subject { CommitStatus.manual }
%i[manual].each do |status|
- it_behaves_like 'containing the job', status
+ it_behaves_like "containing the job", status
end
%i[failed success skipped canceled].each do |status|
- it_behaves_like 'not containing the job', status
+ it_behaves_like "not containing the job", status
end
end
- describe '.scheduled' do
+ describe ".scheduled" do
subject { CommitStatus.scheduled }
%i[scheduled].each do |status|
- it_behaves_like 'containing the job', status
+ it_behaves_like "containing the job", status
end
%i[failed success skipped canceled].each do |status|
- it_behaves_like 'not containing the job', status
+ it_behaves_like "not containing the job", status
end
end
end
- describe '::DEFAULT_STATUS' do
- it 'is a status created' do
- expect(described_class::DEFAULT_STATUS).to eq 'created'
+ describe "::DEFAULT_STATUS" do
+ it "is a status created" do
+ expect(described_class::DEFAULT_STATUS).to eq "created"
end
end
- describe '::BLOCKED_STATUS' do
- it 'is a status manual' do
+ describe "::BLOCKED_STATUS" do
+ it "is a status manual" do
expect(described_class::BLOCKED_STATUS).to eq %w[manual scheduled]
end
end
- describe 'blocked?' do
+ describe "blocked?" do
subject { object.blocked? }
%w[ci_pipeline ci_stage ci_build generic_commit_status].each do |type|
let(:object) { build(type, status: status) }
- context 'when status is scheduled' do
+ context "when status is scheduled" do
let(:status) { :scheduled }
it { is_expected.to be_truthy }
end
- context 'when status is manual' do
+ context "when status is manual" do
let(:status) { :manual }
it { is_expected.to be_truthy }
end
- context 'when status is created' do
+ context "when status is created" do
let(:status) { :created }
it { is_expected.to be_falsy }
@@ -342,10 +342,10 @@ describe HasStatus do
end
end
- describe '.status_sql' do
+ describe ".status_sql" do
subject { Ci::Build.status_sql }
- it 'returns SQL' do
+ it "returns SQL" do
puts subject
end
end
diff --git a/spec/models/concerns/has_variable_spec.rb b/spec/models/concerns/has_variable_spec.rb
index bff96e12ffa..5b9d825c168 100644
--- a/spec/models/concerns/has_variable_spec.rb
+++ b/spec/models/concerns/has_variable_spec.rb
@@ -1,61 +1,61 @@
-require 'spec_helper'
+require "spec_helper"
describe HasVariable do
subject { build(:ci_variable) }
it { is_expected.to validate_presence_of(:key) }
it { is_expected.to validate_length_of(:key).is_at_most(255) }
- it { is_expected.to allow_value('foo').for(:key) }
- it { is_expected.not_to allow_value('foo bar').for(:key) }
- it { is_expected.not_to allow_value('foo/bar').for(:key) }
+ it { is_expected.to allow_value("foo").for(:key) }
+ it { is_expected.not_to allow_value("foo bar").for(:key) }
+ it { is_expected.not_to allow_value("foo/bar").for(:key) }
- describe '#key=' do
- context 'when the new key is nil' do
- it 'strips leading and trailing whitespaces' do
+ describe "#key=" do
+ context "when the new key is nil" do
+ it "strips leading and trailing whitespaces" do
subject.key = nil
- expect(subject.key).to eq('')
+ expect(subject.key).to eq("")
end
end
- context 'when the new key has leadind and trailing whitespaces' do
- it 'strips leading and trailing whitespaces' do
- subject.key = ' my key '
+ context "when the new key has leadind and trailing whitespaces" do
+ it "strips leading and trailing whitespaces" do
+ subject.key = " my key "
- expect(subject.key).to eq('my key')
+ expect(subject.key).to eq("my key")
end
end
end
- describe '#value' do
+ describe "#value" do
before do
- subject.value = 'secret'
+ subject.value = "secret"
end
- it 'stores the encrypted value' do
+ it "stores the encrypted value" do
expect(subject.encrypted_value).not_to be_nil
end
- it 'stores an iv for value' do
+ it "stores an iv for value" do
expect(subject.encrypted_value_iv).not_to be_nil
end
- it 'stores a salt for value' do
+ it "stores a salt for value" do
expect(subject.encrypted_value_salt).not_to be_nil
end
- it 'fails to decrypt if iv is incorrect' do
+ it "fails to decrypt if iv is incorrect" do
# attr_encrypted expects the IV to be 16 bytes and base64-encoded
- subject.encrypted_value_iv = [SecureRandom.hex(8)].pack('m')
+ subject.encrypted_value_iv = [SecureRandom.hex(8)].pack("m")
subject.instance_variable_set(:@value, nil)
expect { subject.value }
- .to raise_error(OpenSSL::Cipher::CipherError, 'bad decrypt')
+ .to raise_error(OpenSSL::Cipher::CipherError, "bad decrypt")
end
end
- describe '#to_runner_variable' do
- it 'returns a hash for the runner' do
+ describe "#to_runner_variable" do
+ it "returns a hash for the runner" do
expect(subject.to_runner_variable)
.to include(key: subject.key, value: subject.value, public: false)
end
diff --git a/spec/models/concerns/ignorable_column_spec.rb b/spec/models/concerns/ignorable_column_spec.rb
index b70f2331a0e..9b7adb44c8f 100644
--- a/spec/models/concerns/ignorable_column_spec.rb
+++ b/spec/models/concerns/ignorable_column_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe IgnorableColumn do
let :base_class do
@@ -6,9 +6,9 @@ describe IgnorableColumn do
def self.columns
# This method does not have access to "double"
[
- Struct.new(:name).new('id'),
- Struct.new(:name).new('title'),
- Struct.new(:name).new('date')
+ Struct.new(:name).new("id"),
+ Struct.new(:name).new("title"),
+ Struct.new(:name).new("date"),
]
end
end
@@ -20,23 +20,23 @@ describe IgnorableColumn do
end
end
- describe '.columns' do
- it 'returns the columns, excluding the ignored ones' do
+ describe ".columns" do
+ it "returns the columns, excluding the ignored ones" do
model.ignore_column(:title, :date)
- expect(model.columns.map(&:name)).to eq(%w(id))
+ expect(model.columns.map(&:name)).to eq(%w[id])
end
end
- describe '.ignored_columns' do
- it 'returns a Set' do
+ describe ".ignored_columns" do
+ it "returns a Set" do
expect(model.ignored_columns).to be_an_instance_of(Set)
end
- it 'returns the names of the ignored columns' do
+ it "returns the names of the ignored columns" do
model.ignore_column(:title, :date)
- expect(model.ignored_columns).to eq(Set.new(%w(title date)))
+ expect(model.ignored_columns).to eq(Set.new(%w[title date]))
end
end
end
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index 41159348e04..b6c0bdb75a2 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -1,8 +1,8 @@
-require 'spec_helper'
+require "spec_helper"
describe Issuable do
let(:issuable_class) { Issue }
- let(:issue) { create(:issue, title: 'An issue', description: 'A description') }
+ let(:issue) { create(:issue, title: "An issue", description: "A description") }
let(:user) { create(:user) }
describe "Associations" do
@@ -14,18 +14,18 @@ describe Issuable do
it { is_expected.to have_many(:todos).dependent(:destroy) }
it { is_expected.to have_many(:labels) }
- context 'Notes' do
+ context "Notes" do
let!(:note) { create(:note, noteable: issue, project: issue.project) }
let(:scoped_issue) { Issue.includes(notes: :author).find(issue.id) }
- it 'indicates if the notes have their authors loaded' do
+ it "indicates if the notes have their authors loaded" do
expect(issue.notes).not_to be_authors_loaded
expect(scoped_issue.notes).to be_authors_loaded
end
end
end
- describe 'Included modules' do
+ describe "Included modules" do
let(:described_class) { issuable_class }
it { is_expected.to include_module(Awardable) }
@@ -53,12 +53,12 @@ describe Issuable do
it { expect(issuable_class).to respond_to(:assigned) }
end
- describe 'author_name' do
- it 'is delegated to author' do
+ describe "author_name" do
+ it "is delegated to author" do
expect(issue.author_name).to eq issue.author.name
end
- it 'returns nil when author is nil' do
+ it "returns nil when author is nil" do
issue.author_id = nil
issue.save(validate: false)
@@ -68,152 +68,152 @@ describe Issuable do
describe ".search" do
let!(:searchable_issue) { create(:issue, title: "Searchable awesome issue") }
- let!(:searchable_issue2) { create(:issue, title: 'Aw') }
+ let!(:searchable_issue2) { create(:issue, title: "Aw") }
- it 'returns issues with a matching title' do
+ it "returns issues with a matching title" do
expect(issuable_class.search(searchable_issue.title))
.to eq([searchable_issue])
end
- it 'returns issues with a partially matching title' do
- expect(issuable_class.search('able')).to eq([searchable_issue])
+ it "returns issues with a partially matching title" do
+ expect(issuable_class.search("able")).to eq([searchable_issue])
end
- it 'returns issues with a matching title regardless of the casing' do
+ it "returns issues with a matching title regardless of the casing" do
expect(issuable_class.search(searchable_issue.title.upcase))
.to eq([searchable_issue])
end
- it 'returns issues with a fuzzy matching title' do
- expect(issuable_class.search('searchable issue')).to eq([searchable_issue])
+ it "returns issues with a fuzzy matching title" do
+ expect(issuable_class.search("searchable issue")).to eq([searchable_issue])
end
- it 'returns issues with a matching title for a query shorter than 3 chars' do
+ it "returns issues with a matching title for a query shorter than 3 chars" do
expect(issuable_class.search(searchable_issue2.title.downcase)).to eq([searchable_issue2])
end
end
describe ".full_search" do
let!(:searchable_issue) do
- create(:issue, title: "Searchable awesome issue", description: 'Many cute kittens')
+ create(:issue, title: "Searchable awesome issue", description: "Many cute kittens")
end
let!(:searchable_issue2) { create(:issue, title: "Aw", description: "Cu") }
- it 'returns issues with a matching title' do
+ it "returns issues with a matching title" do
expect(issuable_class.full_search(searchable_issue.title))
.to eq([searchable_issue])
end
- it 'returns issues with a partially matching title' do
- expect(issuable_class.full_search('able')).to eq([searchable_issue])
+ it "returns issues with a partially matching title" do
+ expect(issuable_class.full_search("able")).to eq([searchable_issue])
end
- it 'returns issues with a matching title regardless of the casing' do
+ it "returns issues with a matching title regardless of the casing" do
expect(issuable_class.full_search(searchable_issue.title.upcase))
.to eq([searchable_issue])
end
- it 'returns issues with a fuzzy matching title' do
- expect(issuable_class.full_search('searchable issue')).to eq([searchable_issue])
+ it "returns issues with a fuzzy matching title" do
+ expect(issuable_class.full_search("searchable issue")).to eq([searchable_issue])
end
- it 'returns issues with a matching description' do
+ it "returns issues with a matching description" do
expect(issuable_class.full_search(searchable_issue.description))
.to eq([searchable_issue])
end
- it 'returns issues with a partially matching description' do
+ it "returns issues with a partially matching description" do
expect(issuable_class.full_search(searchable_issue.description))
.to eq([searchable_issue])
end
- it 'returns issues with a matching description regardless of the casing' do
+ it "returns issues with a matching description regardless of the casing" do
expect(issuable_class.full_search(searchable_issue.description.upcase))
.to eq([searchable_issue])
end
- it 'returns issues with a fuzzy matching description' do
- expect(issuable_class.full_search('many kittens')).to eq([searchable_issue])
+ it "returns issues with a fuzzy matching description" do
+ expect(issuable_class.full_search("many kittens")).to eq([searchable_issue])
end
- it 'returns issues with a matching description for a query shorter than 3 chars' do
+ it "returns issues with a matching description for a query shorter than 3 chars" do
expect(issuable_class.full_search(searchable_issue2.description.downcase)).to eq([searchable_issue2])
end
context 'when matching columns is "title"' do
- it 'returns issues with a matching title' do
- expect(issuable_class.full_search(searchable_issue.title, matched_columns: 'title'))
+ it "returns issues with a matching title" do
+ expect(issuable_class.full_search(searchable_issue.title, matched_columns: "title"))
.to eq([searchable_issue])
end
- it 'returns no issues with a matching description' do
- expect(issuable_class.full_search(searchable_issue.description, matched_columns: 'title'))
+ it "returns no issues with a matching description" do
+ expect(issuable_class.full_search(searchable_issue.description, matched_columns: "title"))
.to be_empty
end
end
context 'when matching columns is "description"' do
- it 'returns no issues with a matching title' do
- expect(issuable_class.full_search(searchable_issue.title, matched_columns: 'description'))
+ it "returns no issues with a matching title" do
+ expect(issuable_class.full_search(searchable_issue.title, matched_columns: "description"))
.to be_empty
end
- it 'returns issues with a matching description' do
- expect(issuable_class.full_search(searchable_issue.description, matched_columns: 'description'))
+ it "returns issues with a matching description" do
+ expect(issuable_class.full_search(searchable_issue.description, matched_columns: "description"))
.to eq([searchable_issue])
end
end
context 'when matching columns is "title,description"' do
- it 'returns issues with a matching title' do
- expect(issuable_class.full_search(searchable_issue.title, matched_columns: 'title,description'))
+ it "returns issues with a matching title" do
+ expect(issuable_class.full_search(searchable_issue.title, matched_columns: "title,description"))
.to eq([searchable_issue])
end
- it 'returns issues with a matching description' do
- expect(issuable_class.full_search(searchable_issue.description, matched_columns: 'title,description'))
+ it "returns issues with a matching description" do
+ expect(issuable_class.full_search(searchable_issue.description, matched_columns: "title,description"))
.to eq([searchable_issue])
end
end
context 'when matching columns is nil"' do
- it 'returns issues with a matching title' do
+ it "returns issues with a matching title" do
expect(issuable_class.full_search(searchable_issue.title, matched_columns: nil))
.to eq([searchable_issue])
end
- it 'returns issues with a matching description' do
+ it "returns issues with a matching description" do
expect(issuable_class.full_search(searchable_issue.description, matched_columns: nil))
.to eq([searchable_issue])
end
end
context 'when matching columns is "invalid"' do
- it 'returns issues with a matching title' do
- expect(issuable_class.full_search(searchable_issue.title, matched_columns: 'invalid'))
+ it "returns issues with a matching title" do
+ expect(issuable_class.full_search(searchable_issue.title, matched_columns: "invalid"))
.to eq([searchable_issue])
end
- it 'returns issues with a matching description' do
- expect(issuable_class.full_search(searchable_issue.description, matched_columns: 'invalid'))
+ it "returns issues with a matching description" do
+ expect(issuable_class.full_search(searchable_issue.description, matched_columns: "invalid"))
.to eq([searchable_issue])
end
end
context 'when matching columns is "title,invalid"' do
- it 'returns issues with a matching title' do
- expect(issuable_class.full_search(searchable_issue.title, matched_columns: 'title,invalid'))
+ it "returns issues with a matching title" do
+ expect(issuable_class.full_search(searchable_issue.title, matched_columns: "title,invalid"))
.to eq([searchable_issue])
end
- it 'returns no issues with a matching description' do
- expect(issuable_class.full_search(searchable_issue.description, matched_columns: 'title,invalid'))
+ it "returns no issues with a matching description" do
+ expect(issuable_class.full_search(searchable_issue.description, matched_columns: "title,invalid"))
.to be_empty
end
end
end
- describe '.to_ability_name' do
+ describe ".to_ability_name" do
it { expect(Issue.to_ability_name).to eq("issue") }
it { expect(MergeRequest.to_ability_name).to eq("merge_request") }
end
@@ -266,72 +266,72 @@ describe Issuable do
let!(:issue3) { create(:issue, project: project) }
it "sorts desc" do
- issues = project.issues.sort_by_attribute('milestone_due_desc')
+ issues = project.issues.sort_by_attribute("milestone_due_desc")
expect(issues).to match_array([issue2, issue1, issue, issue3])
end
it "sorts asc" do
- issues = project.issues.sort_by_attribute('milestone_due_asc')
+ issues = project.issues.sort_by_attribute("milestone_due_asc")
expect(issues).to match_array([issue1, issue2, issue, issue3])
end
end
- context 'when all of the results are level on the sort key' do
+ context "when all of the results are level on the sort key" do
let!(:issues) do
10.times { create(:issue, project: project) }
end
- it 'has no duplicates across pages' do
- sorted_issue_ids = 1.upto(10).map do |i|
- project.issues.sort_by_attribute('milestone_due_desc').page(i).per(1).first.id
- end
+ it "has no duplicates across pages" do
+ sorted_issue_ids = 1.upto(10).map { |i|
+ project.issues.sort_by_attribute("milestone_due_desc").page(i).per(1).first.id
+ }
expect(sorted_issue_ids).to eq(sorted_issue_ids.uniq)
end
end
end
- describe '#subscribed?' do
+ describe "#subscribed?" do
let(:project) { issue.project }
- context 'user is not a participant in the issue' do
+ context "user is not a participant in the issue" do
before do
allow(issue).to receive(:participants).with(user).and_return([])
end
- it 'returns false when no subcription exists' do
+ it "returns false when no subcription exists" do
expect(issue.subscribed?(user, project)).to be_falsey
end
- it 'returns true when a subcription exists and subscribed is true' do
+ it "returns true when a subcription exists and subscribed is true" do
issue.subscriptions.create(user: user, project: project, subscribed: true)
expect(issue.subscribed?(user, project)).to be_truthy
end
- it 'returns false when a subcription exists and subscribed is false' do
+ it "returns false when a subcription exists and subscribed is false" do
issue.subscriptions.create(user: user, project: project, subscribed: false)
expect(issue.subscribed?(user, project)).to be_falsey
end
end
- context 'user is a participant in the issue' do
+ context "user is a participant in the issue" do
before do
allow(issue).to receive(:participants).with(user).and_return([user])
end
- it 'returns false when no subcription exists' do
+ it "returns false when no subcription exists" do
expect(issue.subscribed?(user, project)).to be_truthy
end
- it 'returns true when a subcription exists and subscribed is true' do
+ it "returns true when a subcription exists and subscribed is true" do
issue.subscriptions.create(user: user, project: project, subscribed: true)
expect(issue.subscribed?(user, project)).to be_truthy
end
- it 'returns false when a subcription exists and subscribed is false' do
+ it "returns false when a subcription exists and subscribed is false" do
issue.subscriptions.create(user: user, project: project, subscribed: false)
expect(issue.subscribed?(user, project)).to be_falsey
@@ -339,23 +339,23 @@ describe Issuable do
end
end
- describe '#time_estimate=' do
- it 'coerces the value below Gitlab::Database::MAX_INT_VALUE' do
+ describe "#time_estimate=" do
+ it "coerces the value below Gitlab::Database::MAX_INT_VALUE" do
expect { issue.time_estimate = 100 }.to change { issue.time_estimate }.to(100)
expect { issue.time_estimate = Gitlab::Database::MAX_INT_VALUE + 100 }.to change { issue.time_estimate }.to(Gitlab::Database::MAX_INT_VALUE)
end
- it 'skips coercion for not Integer values' do
+ it "skips coercion for not Integer values" do
expect { issue.time_estimate = nil }.to change { issue.time_estimate }.to(nil)
- expect { issue.time_estimate = 'invalid time' }.not_to raise_error
+ expect { issue.time_estimate = "invalid time" }.not_to raise_error
expect { issue.time_estimate = 22.33 }.not_to raise_error
end
end
- describe '#to_hook_data' do
+ describe "#to_hook_data" do
let(:builder) { double }
- context 'labels are updated' do
+ context "labels are updated" do
let(:labels) { create_list(:label, 2) }
before do
@@ -364,18 +364,19 @@ describe Issuable do
.to receive(:new).with(issue).and_return(builder)
end
- it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
+ it "delegates to Gitlab::HookData::IssuableBuilder#build" do
expect(builder).to receive(:build).with(
user: user,
changes: hash_including(
- 'labels' => [[labels[0].hook_attrs], [labels[1].hook_attrs]]
- ))
+ "labels" => [[labels[0].hook_attrs], [labels[1].hook_attrs]]
+ )
+ )
- issue.to_hook_data(user, old_associations: { labels: [labels[0]] })
+ issue.to_hook_data(user, old_associations: {labels: [labels[0]]})
end
end
- context 'total_time_spent is updated' do
+ context "total_time_spent is updated" do
before do
issue.spend_time(duration: 2, user_id: user.id, spent_at: Time.now)
issue.save
@@ -383,18 +384,19 @@ describe Issuable do
.to receive(:new).with(issue).and_return(builder)
end
- it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
+ it "delegates to Gitlab::HookData::IssuableBuilder#build" do
expect(builder).to receive(:build).with(
user: user,
changes: hash_including(
- 'total_time_spent' => [1, 2]
- ))
+ "total_time_spent" => [1, 2]
+ )
+ )
- issue.to_hook_data(user, old_associations: { total_time_spent: 1 })
+ issue.to_hook_data(user, old_associations: {total_time_spent: 1})
end
end
- context 'issue is assigned' do
+ context "issue is assigned" do
let(:user2) { create(:user) }
before do
@@ -403,18 +405,19 @@ describe Issuable do
.to receive(:new).with(issue).and_return(builder)
end
- it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
+ it "delegates to Gitlab::HookData::IssuableBuilder#build" do
expect(builder).to receive(:build).with(
user: user,
changes: hash_including(
- 'assignees' => [[user.hook_attrs], [user.hook_attrs, user2.hook_attrs]]
- ))
+ "assignees" => [[user.hook_attrs], [user.hook_attrs, user2.hook_attrs]]
+ )
+ )
- issue.to_hook_data(user, old_associations: { assignees: [user] })
+ issue.to_hook_data(user, old_associations: {assignees: [user]})
end
end
- context 'merge_request is assigned' do
+ context "merge_request is assigned" do
let(:merge_request) { create(:merge_request) }
let(:user2) { create(:user) }
@@ -425,34 +428,35 @@ describe Issuable do
.to receive(:new).with(merge_request).and_return(builder)
end
- it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
+ it "delegates to Gitlab::HookData::IssuableBuilder#build" do
expect(builder).to receive(:build).with(
user: user,
changes: hash_including(
- 'assignee_id' => [user.id, user2.id],
- 'assignee' => [user.hook_attrs, user2.hook_attrs]
- ))
+ "assignee_id" => [user.id, user2.id],
+ "assignee" => [user.hook_attrs, user2.hook_attrs]
+ )
+ )
- merge_request.to_hook_data(user, old_associations: { assignees: [user] })
+ merge_request.to_hook_data(user, old_associations: {assignees: [user]})
end
end
end
- describe '#labels_array' do
+ describe "#labels_array" do
let(:project) { create(:project) }
- let(:bug) { create(:label, project: project, title: 'bug') }
+ let(:bug) { create(:label, project: project, title: "bug") }
let(:issue) { create(:issue, project: project) }
before do
issue.labels << bug
end
- it 'loads the association and returns it as an array' do
+ it "loads the association and returns it as an array" do
expect(issue.reload.labels_array).to eq([bug])
end
end
- describe '#user_notes_count' do
+ describe "#user_notes_count" do
let(:project) { create(:project) }
let(:issue1) { create(:issue, project: project) }
let(:issue2) { create(:issue, project: project) }
@@ -462,7 +466,7 @@ describe Issuable do
create_list(:note, 6, noteable: issue2, project: project)
end
- it 'counts the user notes' do
+ it "counts the user notes" do
expect(issue1.user_notes_count).to be(3)
expect(issue2.user_notes_count).to be(6)
end
@@ -482,14 +486,14 @@ describe Issuable do
end
end
- describe '.order_due_date_and_labels_priority' do
+ describe ".order_due_date_and_labels_priority" do
let(:project) { create(:project) }
def create_issue(milestone, labels)
create(:labeled_issue, milestone: milestone, labels: labels, project: project)
end
- it 'sorts issues in order of milestone due date, then label priority' do
+ it "sorts issues in order of milestone due date, then label priority" do
first_priority = create(:label, project: project, priority: 1)
second_priority = create(:label, project: project, priority: 2)
no_priority = create(:label, project: project)
@@ -518,15 +522,15 @@ describe Issuable do
second_milestone_no_labels,
third_milestone_first_priority,
no_milestone_second_priority,
- third_milestone_no_priority])
+ third_milestone_no_priority,])
end
end
- describe '.order_labels_priority' do
- let(:label_1) { create(:label, title: 'label_1', project: issue.project, priority: 1) }
- let(:label_2) { create(:label, title: 'label_2', project: issue.project, priority: 2) }
+ describe ".order_labels_priority" do
+ let(:label_1) { create(:label, title: "label_1", project: issue.project, priority: 1) }
+ let(:label_2) { create(:label, title: "label_2", project: issue.project, priority: 2) }
- subject { Issue.order_labels_priority(excluded_labels: ['label_1']).first.highest_priority }
+ subject { Issue.order_labels_priority(excluded_labels: ["label_1"]).first.highest_priority }
before do
issue.labels << label_1
@@ -538,9 +542,9 @@ describe Issuable do
describe ".with_label" do
let(:project) { create(:project, :public) }
- let(:bug) { create(:label, project: project, title: 'bug') }
- let(:feature) { create(:label, project: project, title: 'feature') }
- let(:enhancement) { create(:label, project: project, title: 'enhancement') }
+ let(:bug) { create(:label, project: project, title: "bug") }
+ let(:feature) { create(:label, project: project, title: "feature") }
+ let(:enhancement) { create(:label, project: project, title: "enhancement") }
let(:issue1) { create(:issue, title: "Bugfix1", project: project) }
let(:issue2) { create(:issue, title: "Bugfix2", project: project) }
let(:issue3) { create(:issue, title: "Feature1", project: project) }
@@ -553,20 +557,20 @@ describe Issuable do
issue3.labels << feature
end
- it 'finds the correct issue containing just enhancement label' do
+ it "finds the correct issue containing just enhancement label" do
expect(Issue.with_label(enhancement.title)).to match_array([issue2])
end
- it 'finds the correct issues containing the same label' do
+ it "finds the correct issues containing the same label" do
expect(Issue.with_label(bug.title)).to match_array([issue1, issue2])
end
- it 'finds the correct issues containing only both labels' do
+ it "finds the correct issues containing only both labels" do
expect(Issue.with_label([bug.title, enhancement.title])).to match_array([issue2])
end
end
- describe '#spend_time' do
+ describe "#spend_time" do
let(:user) { create(:user) }
let(:issue) { create(:issue) }
@@ -575,14 +579,14 @@ describe Issuable do
issue.save!
end
- context 'adding time' do
- it 'should update the total time spent' do
+ context "adding time" do
+ it "should update the total time spent" do
spend_time(1800)
expect(issue.total_time_spent).to eq(1800)
end
- it 'updates issues updated_at' do
+ it "updates issues updated_at" do
issue
Timecop.travel(1.minute.from_now) do
@@ -591,32 +595,32 @@ describe Issuable do
end
end
- context 'subtracting time' do
+ context "subtracting time" do
before do
spend_time(1800)
end
- it 'should update the total time spent' do
+ it "should update the total time spent" do
spend_time(-900)
expect(issue.total_time_spent).to eq(900)
end
- context 'when time to subtract exceeds the total time spent' do
- it 'raise a validation error' do
+ context "when time to subtract exceeds the total time spent" do
+ it "raise a validation error" do
Timecop.travel(1.minute.from_now) do
- expect do
- expect do
+ expect {
+ expect {
spend_time(-3600)
- end.to raise_error(ActiveRecord::RecordInvalid)
- end.not_to change { issue.updated_at }
+ }.to raise_error(ActiveRecord::RecordInvalid)
+ }.not_to change { issue.updated_at }
end
end
end
end
end
- describe '#first_contribution?' do
+ describe "#first_contribution?" do
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
let(:other_project) { create(:project) }
diff --git a/spec/models/concerns/loaded_in_group_list_spec.rb b/spec/models/concerns/loaded_in_group_list_spec.rb
index 7a279547a3a..435d863b2da 100644
--- a/spec/models/concerns/loaded_in_group_list_spec.rb
+++ b/spec/models/concerns/loaded_in_group_list_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe LoadedInGroupList do
let(:parent) { create(:group) }
subject(:found_group) { Group.with_selects_for_list.find_by(id: parent.id) }
- describe '.with_selects_for_list' do
- it 'includes the preloaded counts for groups' do
+ describe ".with_selects_for_list" do
+ it "includes the preloaded counts for groups" do
create(:group, parent: parent)
create(:project, namespace: parent)
parent.add_developer(create(:user))
@@ -17,29 +17,29 @@ describe LoadedInGroupList do
expect(found_group.preloaded_member_count).to eq(1)
end
- context 'with archived projects' do
- it 'counts including archived projects when `true` is passed' do
+ context "with archived projects" do
+ it "counts including archived projects when `true` is passed" do
create(:project, namespace: parent, archived: true)
create(:project, namespace: parent)
- found_group = Group.with_selects_for_list(archived: 'true').find_by(id: parent.id)
+ found_group = Group.with_selects_for_list(archived: "true").find_by(id: parent.id)
expect(found_group.preloaded_project_count).to eq(2)
end
- it 'counts only archived projects when `only` is passed' do
+ it "counts only archived projects when `only` is passed" do
create_list(:project, 2, namespace: parent, archived: true)
create(:project, namespace: parent)
- found_group = Group.with_selects_for_list(archived: 'only').find_by(id: parent.id)
+ found_group = Group.with_selects_for_list(archived: "only").find_by(id: parent.id)
expect(found_group.preloaded_project_count).to eq(2)
end
end
end
- describe '#children_count' do
- it 'counts groups and projects' do
+ describe "#children_count" do
+ it "counts groups and projects" do
create(:group, parent: parent)
create(:project, namespace: parent)
diff --git a/spec/models/concerns/manual_inverse_association_spec.rb b/spec/models/concerns/manual_inverse_association_spec.rb
index ff4a04ea573..025e94e06c3 100644
--- a/spec/models/concerns/manual_inverse_association_spec.rb
+++ b/spec/models/concerns/manual_inverse_association_spec.rb
@@ -1,9 +1,9 @@
-require 'spec_helper'
+require "spec_helper"
describe ManualInverseAssociation do
let(:model) do
Class.new(MergeRequest) do
- belongs_to :manual_association, class_name: 'MergeRequestDiff', foreign_key: :latest_merge_request_diff_id
+ belongs_to :manual_association, class_name: "MergeRequestDiff", foreign_key: :latest_merge_request_diff_id
manual_inverse_association :manual_association, :merge_request
end
end
@@ -14,36 +14,36 @@ describe ManualInverseAssociation do
let(:instance) { create(:merge_request).becomes(model) }
- describe '.manual_inverse_association' do
- context 'when the relation exists' do
+ describe ".manual_inverse_association" do
+ context "when the relation exists" do
before do
instance.create_merge_request_diff
instance.reload
end
- it 'loads the relation' do
+ it "loads the relation" do
expect(instance.manual_association).to be_an_instance_of(MergeRequestDiff)
end
- it 'does not perform extra queries after loading' do
+ it "does not perform extra queries after loading" do
instance.manual_association
expect { instance.manual_association.merge_request }
.not_to exceed_query_limit(0)
end
- it 'allows reloading the relation' do
- query_count = ActiveRecord::QueryRecorder.new do
+ it "allows reloading the relation" do
+ query_count = ActiveRecord::QueryRecorder.new {
instance.manual_association
instance.reload_manual_association
- end.count
+ }.count
expect(query_count).to eq(2)
end
end
- context 'when the relation does not return a value' do
- it 'does not try to set an inverse' do
+ context "when the relation does not return a value" do
+ it "does not try to set an inverse" do
expect(instance.manual_association).to be_nil
end
end
diff --git a/spec/models/concerns/maskable_spec.rb b/spec/models/concerns/maskable_spec.rb
index aeba7ad862f..c5473cec3cd 100644
--- a/spec/models/concerns/maskable_spec.rb
+++ b/spec/models/concerns/maskable_spec.rb
@@ -1,58 +1,58 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe Maskable do
let(:variable) { build(:ci_variable) }
- describe 'masked value validations' do
+ describe "masked value validations" do
subject { variable }
- context 'when variable is masked' do
+ context "when variable is masked" do
before do
subject.masked = true
end
- it { is_expected.not_to allow_value('hello').for(:value) }
- it { is_expected.not_to allow_value('hello world').for(:value) }
- it { is_expected.not_to allow_value('hello$VARIABLEworld').for(:value) }
+ it { is_expected.not_to allow_value("hello").for(:value) }
+ it { is_expected.not_to allow_value("hello world").for(:value) }
+ it { is_expected.not_to allow_value("hello$VARIABLEworld").for(:value) }
it { is_expected.not_to allow_value('hello\rworld').for(:value) }
- it { is_expected.to allow_value('helloworld').for(:value) }
+ it { is_expected.to allow_value("helloworld").for(:value) }
end
- context 'when variable is not masked' do
+ context "when variable is not masked" do
before do
subject.masked = false
end
- it { is_expected.to allow_value('hello').for(:value) }
- it { is_expected.to allow_value('hello world').for(:value) }
- it { is_expected.to allow_value('hello$VARIABLEworld').for(:value) }
+ it { is_expected.to allow_value("hello").for(:value) }
+ it { is_expected.to allow_value("hello world").for(:value) }
+ it { is_expected.to allow_value("hello$VARIABLEworld").for(:value) }
it { is_expected.to allow_value('hello\rworld').for(:value) }
- it { is_expected.to allow_value('helloworld').for(:value) }
+ it { is_expected.to allow_value("helloworld").for(:value) }
end
end
- describe 'REGEX' do
+ describe "REGEX" do
subject { Maskable::REGEX }
- it 'does not match strings shorter than 8 letters' do
- expect(subject.match?('hello')).to eq(false)
+ it "does not match strings shorter than 8 letters" do
+ expect(subject.match?("hello")).to eq(false)
end
- it 'does not match strings with spaces' do
- expect(subject.match?('hello world')).to eq(false)
+ it "does not match strings with spaces" do
+ expect(subject.match?("hello world")).to eq(false)
end
- it 'does not match strings with shell variables' do
- expect(subject.match?('hello$VARIABLEworld')).to eq(false)
+ it "does not match strings with shell variables" do
+ expect(subject.match?("hello$VARIABLEworld")).to eq(false)
end
- it 'does not match strings with escape characters' do
+ it "does not match strings with escape characters" do
expect(subject.match?('hello\rworld')).to eq(false)
end
- it 'does not match strings that span more than one line' do
+ it "does not match strings that span more than one line" do
string = <<~EOS
hello
world
@@ -61,15 +61,15 @@ describe Maskable do
expect(subject.match?(string)).to eq(false)
end
- it 'matches valid strings' do
- expect(subject.match?('helloworld')).to eq(true)
+ it "matches valid strings" do
+ expect(subject.match?("helloworld")).to eq(true)
end
end
- describe '#to_runner_variable' do
+ describe "#to_runner_variable" do
subject { variable.to_runner_variable }
- it 'exposes the masked attribute' do
+ it "exposes the masked attribute" do
expect(subject).to include(:masked)
end
end
diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb
index a9b237fa9ea..e747492be14 100644
--- a/spec/models/concerns/mentionable_spec.rb
+++ b/spec/models/concerns/mentionable_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Mentionable do
class Example
@@ -12,32 +12,32 @@ describe Mentionable do
end
end
- describe 'references' do
+ describe "references" do
let(:project) { create(:project) }
let(:mentionable) { Example.new }
- it 'excludes JIRA references' do
+ it "excludes JIRA references" do
allow(project).to receive_messages(jira_tracker?: true)
mentionable.project = project
- mentionable.message = 'JIRA-123'
+ mentionable.message = "JIRA-123"
expect(mentionable.referenced_mentionables).to be_empty
end
end
end
describe Issue, "Mentionable" do
- describe '#mentioned_users' do
- let!(:user) { create(:user, username: 'stranger') }
- let!(:user2) { create(:user, username: 'john') }
- let!(:user3) { create(:user, username: 'jim') }
+ describe "#mentioned_users" do
+ let!(:user) { create(:user, username: "stranger") }
+ let!(:user2) { create(:user, username: "john") }
+ let!(:user3) { create(:user, username: "jim") }
let(:issue) { create(:issue, description: "#{user.to_reference} mentioned") }
subject { issue.mentioned_users }
it { expect(subject).to contain_exactly(user) }
- context 'when a note on personal snippet' do
+ context "when a note on personal snippet" do
let!(:note) { create(:note_on_personal_snippet, note: "#{user.to_reference} mentioned #{user3.to_reference}") }
subject { note.mentioned_users }
@@ -46,8 +46,8 @@ describe Issue, "Mentionable" do
end
end
- describe '#referenced_mentionables' do
- context 'with an issue on a private project' do
+ describe "#referenced_mentionables" do
+ context "with an issue on a private project" do
let(:project) { create(:project, :public) }
let(:issue) { create(:issue, project: project) }
let(:public_issue) { create(:issue, project: project) }
@@ -60,31 +60,31 @@ describe Issue, "Mentionable" do
issue.referenced_mentionables(current_user)
end
- context 'when the current user can see the issue' do
+ context "when the current user can see the issue" do
before do
private_project.add_developer(user)
end
- it 'includes the reference' do
+ it "includes the reference" do
expect(referenced_issues(user)).to contain_exactly(private_issue, public_issue)
end
end
- context 'when the current user cannot see the issue' do
- it 'does not include the reference' do
+ context "when the current user cannot see the issue" do
+ it "does not include the reference" do
expect(referenced_issues(user)).to contain_exactly(public_issue)
end
end
- context 'when there is no current user' do
- it 'does not include the reference' do
+ context "when there is no current user" do
+ it "does not include the reference" do
expect(referenced_issues(nil)).to contain_exactly(public_issue)
end
end
end
end
- describe '#create_cross_references!' do
+ describe "#create_cross_references!" do
let(:project) { create(:project, :repository) }
let(:author) { build(:user) }
let(:commit) { project.commit }
@@ -94,14 +94,14 @@ describe Issue, "Mentionable" do
create(:issue, project: project, description: "See #{commit.to_reference}")
end
- it 'correctly removes already-mentioned Commits' do
+ it "correctly removes already-mentioned Commits" do
expect(SystemNoteService).not_to receive(:cross_reference)
issue.create_cross_references!(author, [commit2])
end
end
- describe '#create_new_cross_references!' do
+ describe "#create_new_cross_references!" do
let(:project) { create(:project) }
let(:author) { create(:author) }
let(:issues) { create_list(:issue, 2, project: project, author: author) }
@@ -110,17 +110,17 @@ describe Issue, "Mentionable" do
project.add_developer(author)
end
- context 'before changes are persisted' do
- it 'ignores pre-existing references' do
+ context "before changes are persisted" do
+ it "ignores pre-existing references" do
issue = create_issue(description: issues[0].to_reference)
expect(SystemNoteService).not_to receive(:cross_reference)
- issue.description = 'New description'
+ issue.description = "New description"
issue.create_new_cross_references!
end
- it 'notifies new references' do
+ it "notifies new references" do
issue = create_issue(description: issues[0].to_reference)
expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args)
@@ -130,17 +130,17 @@ describe Issue, "Mentionable" do
end
end
- context 'after changes are persisted' do
- it 'ignores pre-existing references' do
+ context "after changes are persisted" do
+ it "ignores pre-existing references" do
issue = create_issue(description: issues[0].to_reference)
expect(SystemNoteService).not_to receive(:cross_reference)
- issue.update(description: 'New description')
+ issue.update(description: "New description")
issue.create_new_cross_references!
end
- it 'notifies new references' do
+ it "notifies new references" do
issue = create_issue(description: issues[0].to_reference)
expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args)
@@ -149,7 +149,7 @@ describe Issue, "Mentionable" do
issue.create_new_cross_references!
end
- it 'notifies new references from project snippet note' do
+ it "notifies new references from project snippet note" do
snippet = create(:snippet, project: project)
note = create(:note, note: issues[0].to_reference, noteable: snippet, project: project, author: author)
@@ -166,36 +166,36 @@ describe Issue, "Mentionable" do
end
end
-describe Commit, 'Mentionable' do
+describe Commit, "Mentionable" do
let(:project) { create(:project, :public, :repository) }
let(:commit) { project.commit }
- describe '#matches_cross_reference_regex?' do
+ describe "#matches_cross_reference_regex?" do
it "is false when message doesn't reference anything" do
allow(commit.raw).to receive(:message).and_return "WIP: Do something"
expect(commit.matches_cross_reference_regex?).to be_falsey
end
- it 'is true if issue #number mentioned in title' do
+ it "is true if issue #number mentioned in title" do
allow(commit.raw).to receive(:message).and_return "#1"
expect(commit.matches_cross_reference_regex?).to be_truthy
end
- it 'is true if references an MR' do
+ it "is true if references an MR" do
allow(commit.raw).to receive(:message).and_return "See merge request !12"
expect(commit.matches_cross_reference_regex?).to be_truthy
end
- it 'is true if references a commit' do
+ it "is true if references a commit" do
allow(commit.raw).to receive(:message).and_return "a1b2c3d4"
expect(commit.matches_cross_reference_regex?).to be_truthy
end
- it 'is true if issue referenced by url' do
+ it "is true if issue referenced by url" do
issue = create(:issue, project: project)
allow(commit.raw).to receive(:message).and_return Gitlab::UrlBuilder.build(issue)
@@ -203,17 +203,17 @@ describe Commit, 'Mentionable' do
expect(commit.matches_cross_reference_regex?).to be_truthy
end
- context 'with external issue tracker' do
+ context "with external issue tracker" do
let(:project) { create(:jira_project, :repository) }
- it 'is true if external issues referenced' do
- allow(commit.raw).to receive(:message).and_return 'JIRA-123'
+ it "is true if external issues referenced" do
+ allow(commit.raw).to receive(:message).and_return "JIRA-123"
expect(commit.matches_cross_reference_regex?).to be_truthy
end
- it 'is true if internal issues referenced' do
- allow(commit.raw).to receive(:message).and_return '#123'
+ it "is true if internal issues referenced" do
+ allow(commit.raw).to receive(:message).and_return "#123"
expect(commit.matches_cross_reference_regex?).to be_truthy
end
diff --git a/spec/models/concerns/milestoneish_spec.rb b/spec/models/concerns/milestoneish_spec.rb
index 87bf731340f..24bd9ec8881 100644
--- a/spec/models/concerns/milestoneish_spec.rb
+++ b/spec/models/concerns/milestoneish_spec.rb
@@ -1,6 +1,6 @@
-require 'spec_helper'
+require "spec_helper"
-describe Milestone, 'Milestoneish' do
+describe Milestone, "Milestoneish" do
let(:author) { create(:user) }
let(:assignee) { create(:user) }
let(:non_member) { create(:user) }
@@ -19,17 +19,17 @@ describe Milestone, 'Milestoneish' do
let!(:closed_security_issue_3) { create(:issue, :confidential, :closed, project: project, author: author, milestone: milestone) }
let!(:closed_security_issue_4) { create(:issue, :confidential, :closed, project: project, assignees: [assignee], milestone: milestone) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) }
- let(:label_1) { create(:label, title: 'label_1', project: project, priority: 1) }
- let(:label_2) { create(:label, title: 'label_2', project: project, priority: 2) }
- let(:label_3) { create(:label, title: 'label_3', project: project) }
+ let(:label_1) { create(:label, title: "label_1", project: project, priority: 1) }
+ let(:label_2) { create(:label, title: "label_2", project: project, priority: 2) }
+ let(:label_3) { create(:label, title: "label_3", project: project) }
before do
project.add_developer(member)
project.add_guest(guest)
end
- describe '#sorted_issues' do
- it 'sorts issues by label priority' do
+ describe "#sorted_issues" do
+ it "sorts issues by label priority" do
issue.labels << label_1
security_issue_1.labels << label_2
closed_issue_1.labels << label_3
@@ -42,11 +42,11 @@ describe Milestone, 'Milestoneish' do
end
end
- describe '#sorted_merge_requests' do
- it 'sorts merge requests by label priority' do
- merge_request_1 = create(:labeled_merge_request, labels: [label_2], source_project: project, source_branch: 'branch_1', milestone: milestone)
- merge_request_2 = create(:labeled_merge_request, labels: [label_1], source_project: project, source_branch: 'branch_2', milestone: milestone)
- merge_request_3 = create(:labeled_merge_request, labels: [label_3], source_project: project, source_branch: 'branch_3', milestone: milestone)
+ describe "#sorted_merge_requests" do
+ it "sorts merge requests by label priority" do
+ merge_request_1 = create(:labeled_merge_request, labels: [label_2], source_project: project, source_branch: "branch_1", milestone: milestone)
+ merge_request_2 = create(:labeled_merge_request, labels: [label_1], source_project: project, source_branch: "branch_2", milestone: milestone)
+ merge_request_3 = create(:labeled_merge_request, labels: [label_3], source_project: project, source_branch: "branch_3", milestone: milestone)
merge_requests = milestone.sorted_merge_requests
@@ -56,64 +56,64 @@ describe Milestone, 'Milestoneish' do
end
end
- describe '#closed_items_count' do
- it 'does not count confidential issues for non project members' do
+ describe "#closed_items_count" do
+ it "does not count confidential issues for non project members" do
expect(milestone.closed_items_count(non_member)).to eq 2
end
- it 'does not count confidential issues for project members with guest role' do
+ it "does not count confidential issues for project members with guest role" do
expect(milestone.closed_items_count(guest)).to eq 2
end
- it 'counts confidential issues for author' do
+ it "counts confidential issues for author" do
expect(milestone.closed_items_count(author)).to eq 4
end
- it 'counts confidential issues for assignee' do
+ it "counts confidential issues for assignee" do
expect(milestone.closed_items_count(assignee)).to eq 4
end
- it 'counts confidential issues for project members' do
+ it "counts confidential issues for project members" do
expect(milestone.closed_items_count(member)).to eq 6
end
- it 'counts all issues for admin' do
+ it "counts all issues for admin" do
expect(milestone.closed_items_count(admin)).to eq 6
end
end
- describe '#total_items_count' do
- it 'does not count confidential issues for non project members' do
+ describe "#total_items_count" do
+ it "does not count confidential issues for non project members" do
expect(milestone.total_items_count(non_member)).to eq 4
end
- it 'does not count confidential issues for project members with guest role' do
+ it "does not count confidential issues for project members with guest role" do
expect(milestone.total_items_count(guest)).to eq 4
end
- it 'counts confidential issues for author' do
+ it "counts confidential issues for author" do
expect(milestone.total_items_count(author)).to eq 7
end
- it 'counts confidential issues for assignee' do
+ it "counts confidential issues for assignee" do
expect(milestone.total_items_count(assignee)).to eq 7
end
- it 'counts confidential issues for project members' do
+ it "counts confidential issues for project members" do
expect(milestone.total_items_count(member)).to eq 10
end
- it 'counts all issues for admin' do
+ it "counts all issues for admin" do
expect(milestone.total_items_count(admin)).to eq 10
end
end
- describe '#complete?' do
- it 'returns false when has items opened' do
+ describe "#complete?" do
+ it "returns false when has items opened" do
expect(milestone.complete?(non_member)).to eq false
end
- it 'returns true when all items are closed' do
+ it "returns true when all items are closed" do
issue.close
merge_request.close
@@ -121,74 +121,74 @@ describe Milestone, 'Milestoneish' do
end
end
- describe '#percent_complete' do
- it 'does not count confidential issues for non project members' do
+ describe "#percent_complete" do
+ it "does not count confidential issues for non project members" do
expect(milestone.percent_complete(non_member)).to eq 50
end
- it 'does not count confidential issues for project members with guest role' do
+ it "does not count confidential issues for project members with guest role" do
expect(milestone.percent_complete(guest)).to eq 50
end
- it 'counts confidential issues for author' do
+ it "counts confidential issues for author" do
expect(milestone.percent_complete(author)).to eq 57
end
- it 'counts confidential issues for assignee' do
+ it "counts confidential issues for assignee" do
expect(milestone.percent_complete(assignee)).to eq 57
end
- it 'counts confidential issues for project members' do
+ it "counts confidential issues for project members" do
expect(milestone.percent_complete(member)).to eq 60
end
- it 'counts confidential issues for admin' do
+ it "counts confidential issues for admin" do
expect(milestone.percent_complete(admin)).to eq 60
end
end
- describe '#remaining_days' do
- it 'shows 0 if no due date' do
+ describe "#remaining_days" do
+ it "shows 0 if no due date" do
milestone = build_stubbed(:milestone)
expect(milestone.remaining_days).to eq(0)
end
- it 'shows 0 if expired' do
+ it "shows 0 if expired" do
milestone = build_stubbed(:milestone, due_date: 2.days.ago)
expect(milestone.remaining_days).to eq(0)
end
- it 'shows correct remaining days' do
+ it "shows correct remaining days" do
milestone = build_stubbed(:milestone, due_date: 2.days.from_now)
expect(milestone.remaining_days).to eq(2)
end
end
- describe '#elapsed_days' do
- it 'shows 0 if no start_date set' do
+ describe "#elapsed_days" do
+ it "shows 0 if no start_date set" do
milestone = build_stubbed(:milestone)
expect(milestone.elapsed_days).to eq(0)
end
- it 'shows 0 if start_date is a future' do
+ it "shows 0 if start_date is a future" do
milestone = build_stubbed(:milestone, start_date: Time.now + 2.days)
expect(milestone.elapsed_days).to eq(0)
end
- it 'shows correct amount of days' do
+ it "shows correct amount of days" do
milestone = build_stubbed(:milestone, start_date: Time.now - 2.days)
expect(milestone.elapsed_days).to eq(2)
end
end
- describe '#total_issue_time_spent' do
- it 'calculates total issue time spent' do
+ describe "#total_issue_time_spent" do
+ it "calculates total issue time spent" do
closed_issue_1.spend_time(duration: 300, user_id: author.id)
closed_issue_1.save!
closed_issue_2.spend_time(duration: 600, user_id: assignee.id)
@@ -198,8 +198,8 @@ describe Milestone, 'Milestoneish' do
end
end
- describe '#human_total_issue_time_spent' do
- it 'returns nil if no time has been spent' do
+ describe "#human_total_issue_time_spent" do
+ it "returns nil if no time has been spent" do
expect(milestone.human_total_issue_time_spent).to be_nil
end
end
diff --git a/spec/models/concerns/noteable_spec.rb b/spec/models/concerns/noteable_spec.rb
index 485a6e165a1..760b6c50679 100644
--- a/spec/models/concerns/noteable_spec.rb
+++ b/spec/models/concerns/noteable_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Noteable do
let!(:active_diff_note1) { create(:diff_note_on_merge_request) }
@@ -40,10 +40,10 @@ describe Noteable do
)
end
- describe '#discussions' do
+ describe "#discussions" do
let(:discussions) { subject.discussions }
- it 'includes discussions for diff notes, commit diff notes, commit notes, and regular notes' do
+ it "includes discussions for diff notes, commit diff notes, commit notes, and regular notes" do
expect(discussions).to eq([
DiffDiscussion.new([active_diff_note1, active_diff_note2], subject),
DiffDiscussion.new([active_diff_note3], subject),
@@ -54,12 +54,12 @@ describe Noteable do
Discussion.new([commit_discussion_note1, commit_discussion_note2], subject),
Discussion.new([commit_discussion_note3], subject),
IndividualNoteDiscussion.new([note1], subject),
- IndividualNoteDiscussion.new([note2], subject)
+ IndividualNoteDiscussion.new([note2], subject),
])
end
end
- describe '#grouped_diff_discussions' do
+ describe "#grouped_diff_discussions" do
let(:grouped_diff_discussions) { subject.grouped_diff_discussions }
it "includes active discussions" do
@@ -225,34 +225,34 @@ describe Noteable do
allow(third_discussion).to receive(:to_be_resolved?).and_return(false)
end
- it 'includes only discussions that need to be resolved' do
+ it "includes only discussions that need to be resolved" do
expect(subject.discussions_to_be_resolved).to eq([first_discussion])
end
end
- describe '#discussions_can_be_resolved_by?' do
+ describe "#discussions_can_be_resolved_by?" do
let(:user) { build(:user) }
- context 'all discussions can be resolved by the user' do
+ context "all discussions can be resolved by the user" do
before do
allow(first_discussion).to receive(:can_resolve?).with(user).and_return(true)
allow(second_discussion).to receive(:can_resolve?).with(user).and_return(true)
allow(third_discussion).to receive(:can_resolve?).with(user).and_return(true)
end
- it 'allows a user to resolve the discussions' do
+ it "allows a user to resolve the discussions" do
expect(subject.discussions_can_be_resolved_by?(user)).to be(true)
end
end
- context 'one discussion cannot be resolved by the user' do
+ context "one discussion cannot be resolved by the user" do
before do
allow(first_discussion).to receive(:can_resolve?).with(user).and_return(true)
allow(second_discussion).to receive(:can_resolve?).with(user).and_return(true)
allow(third_discussion).to receive(:can_resolve?).with(user).and_return(false)
end
- it 'allows a user to resolve the discussions' do
+ it "allows a user to resolve the discussions" do
expect(subject.discussions_can_be_resolved_by?(user)).to be(false)
end
end
diff --git a/spec/models/concerns/optionally_search_spec.rb b/spec/models/concerns/optionally_search_spec.rb
index ff4212ddf18..c03fd2ab391 100644
--- a/spec/models/concerns/optionally_search_spec.rb
+++ b/spec/models/concerns/optionally_search_spec.rb
@@ -1,42 +1,42 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe OptionallySearch do
let(:model) do
Class.new(ActiveRecord::Base) do
- self.table_name = 'users'
+ self.table_name = "users"
include OptionallySearch
end
end
- describe '.search' do
- it 'raises NotImplementedError' do
- expect { model.search('foo') }.to raise_error(NotImplementedError)
+ describe ".search" do
+ it "raises NotImplementedError" do
+ expect { model.search("foo") }.to raise_error(NotImplementedError)
end
end
- describe '.optionally_search' do
- context 'when a query is given' do
- it 'delegates to the search method' do
+ describe ".optionally_search" do
+ context "when a query is given" do
+ it "delegates to the search method" do
expect(model)
.to receive(:search)
- .with('foo')
+ .with("foo")
- model.optionally_search('foo')
+ model.optionally_search("foo")
end
end
- context 'when no query is given' do
- it 'returns the current relation' do
+ context "when no query is given" do
+ it "returns the current relation" do
expect(model.optionally_search).to be_a_kind_of(ActiveRecord::Relation)
end
end
- context 'when an empty query is given' do
- it 'returns the current relation' do
- expect(model.optionally_search(''))
+ context "when an empty query is given" do
+ it "returns the current relation" do
+ expect(model.optionally_search(""))
.to be_a_kind_of(ActiveRecord::Relation)
end
end
diff --git a/spec/models/concerns/participable_spec.rb b/spec/models/concerns/participable_spec.rb
index 431f1482615..4fb5204474f 100644
--- a/spec/models/concerns/participable_spec.rb
+++ b/spec/models/concerns/participable_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Participable do
let(:model) do
@@ -7,8 +7,8 @@ describe Participable do
end
end
- describe '.participant' do
- it 'adds the participant attributes to the existing list' do
+ describe ".participant" do
+ it "adds the participant attributes to the existing list" do
model.participant(:foo)
model.participant(:bar)
@@ -16,8 +16,8 @@ describe Participable do
end
end
- describe '#participants' do
- it 'returns the list of participants' do
+ describe "#participants" do
+ it "returns the list of participants" do
model.participant(:foo)
model.participant(:bar)
@@ -37,7 +37,7 @@ describe Participable do
expect(participants).to include(user3)
end
- it 'caches the raw list of participants' do
+ it "caches the raw list of participants" do
instance = model.new
user1 = build(:user)
@@ -47,7 +47,7 @@ describe Participable do
instance.participants(user1)
end
- it 'supports attributes returning another Participable' do
+ it "supports attributes returning another Participable" do
other_model = Class.new { include Participable }
other_model.participant(:bar)
@@ -66,15 +66,15 @@ describe Participable do
expect(instance.participants(user1)).to eq([user2])
end
- context 'when using a Proc as an attribute' do
- it 'calls the supplied Proc' do
+ context "when using a Proc as an attribute" do
+ it "calls the supplied Proc" do
user1 = build(:user)
project = build(:project, :public)
user_arg = nil
ext_arg = nil
- model.participant -> (user, ext) do
+ model.participant ->(user, ext) do
user_arg = user
ext_arg = ext
end
diff --git a/spec/models/concerns/presentable_spec.rb b/spec/models/concerns/presentable_spec.rb
index 941647a79fb..ce31c9193b8 100644
--- a/spec/models/concerns/presentable_spec.rb
+++ b/spec/models/concerns/presentable_spec.rb
@@ -1,15 +1,15 @@
-require 'spec_helper'
+require "spec_helper"
describe Presentable do
let(:build) { Ci::Build.new }
- describe '#present' do
- it 'returns a presenter' do
+ describe "#present" do
+ it "returns a presenter" do
expect(build.present).to be_a(Ci::BuildPresenter)
end
- it 'takes optional attributes' do
- expect(build.present(foo: 'bar').foo).to eq('bar')
+ it "takes optional attributes" do
+ expect(build.present(foo: "bar").foo).to eq("bar")
end
end
end
diff --git a/spec/models/concerns/project_features_compatibility_spec.rb b/spec/models/concerns/project_features_compatibility_spec.rb
index 9041690023f..b05f51c8656 100644
--- a/spec/models/concerns/project_features_compatibility_spec.rb
+++ b/spec/models/concerns/project_features_compatibility_spec.rb
@@ -1,8 +1,8 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectFeaturesCompatibility do
let(:project) { create(:project) }
- let(:features) { %w(issues wiki builds merge_requests snippets) }
+ let(:features) { %w[issues wiki builds merge_requests snippets] }
# We had issues_enabled, snippets_enabled, builds_enabled, merge_requests_enabled and issues_enabled fields on projects table
# All those fields got moved to a new table called project_feature and are now integers instead of booleans
diff --git a/spec/models/concerns/prometheus_adapter_spec.rb b/spec/models/concerns/prometheus_adapter_spec.rb
index f4b9c57e71a..6b6681a1d69 100644
--- a/spec/models/concerns/prometheus_adapter_spec.rb
+++ b/spec/models/concerns/prometheus_adapter_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
include PrometheusHelpers
@@ -14,32 +14,32 @@ describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
let(:described_class) { TestClass }
let(:environment_query) { Gitlab::Prometheus::Queries::EnvironmentQuery }
- describe '#query' do
- describe 'environment' do
- let(:environment) { build_stubbed(:environment, slug: 'env-slug') }
+ describe "#query" do
+ describe "environment" do
+ let(:environment) { build_stubbed(:environment, slug: "env-slug") }
around do |example|
Timecop.freeze { example.run }
end
- context 'with valid data' do
+ context "with valid data" do
subject { service.query(:environment, environment) }
before do
stub_reactive_cache(service, prometheus_data, environment_query, environment.id)
end
- it 'returns reactive data' do
+ it "returns reactive data" do
is_expected.to eq(prometheus_metrics_data)
end
end
end
- describe 'matched_metrics' do
+ describe "matched_metrics" do
let(:matched_metrics_query) { Gitlab::Prometheus::Queries::MatchedMetricQuery }
let(:prometheus_client_wrapper) { double(:prometheus_client_wrapper, label_values: nil) }
- context 'with valid data' do
+ context "with valid data" do
subject { service.query(:matched_metrics) }
before do
@@ -47,14 +47,14 @@ describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
synchronous_reactive_cache(service)
end
- it 'returns reactive data' do
+ it "returns reactive data" do
expect(subject[:success]).to be_truthy
expect(subject[:data]).to eq([])
end
end
end
- describe 'deployment' do
+ describe "deployment" do
let(:deployment) { build_stubbed(:deployment) }
let(:deployment_query) { Gitlab::Prometheus::Queries::DeploymentQuery }
@@ -62,22 +62,22 @@ describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
Timecop.freeze { example.run }
end
- context 'with valid data' do
+ context "with valid data" do
subject { service.query(:deployment, deployment) }
before do
stub_reactive_cache(service, prometheus_data, deployment_query, deployment.id)
end
- it 'returns reactive data' do
+ it "returns reactive data" do
expect(subject).to eq(prometheus_metrics_data)
end
end
end
end
- describe '#calculate_reactive_cache' do
- let(:environment) { create(:environment, slug: 'env-slug') }
+ describe "#calculate_reactive_cache" do
+ let(:environment) { create(:environment, slug: "env-slug") }
before do
service.manual_configuration = true
service.active = true
@@ -91,7 +91,7 @@ describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
Timecop.freeze { example.run }
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
service.active = false
end
@@ -99,7 +99,7 @@ describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
it { is_expected.to be_nil }
end
- context 'when Prometheus responds with valid data' do
+ context "when Prometheus responds with valid data" do
before do
stub_all_prometheus_requests(environment.slug)
end
diff --git a/spec/models/concerns/protected_ref_access_spec.rb b/spec/models/concerns/protected_ref_access_spec.rb
index ce602337647..b328b74ca3e 100644
--- a/spec/models/concerns/protected_ref_access_spec.rb
+++ b/spec/models/concerns/protected_ref_access_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ProtectedRefAccess do
subject(:protected_ref_access) do
@@ -7,21 +7,21 @@ describe ProtectedRefAccess do
let(:project) { protected_ref_access.project }
- describe '#check_access' do
- it 'is always true for admins' do
+ describe "#check_access" do
+ it "is always true for admins" do
admin = create(:admin)
expect(protected_ref_access.check_access(admin)).to be_truthy
end
- it 'is true for maintainers' do
+ it "is true for maintainers" do
maintainer = create(:user)
project.add_maintainer(maintainer)
expect(protected_ref_access.check_access(maintainer)).to be_truthy
end
- it 'is for developers of the project' do
+ it "is for developers of the project" do
developer = create(:user)
project.add_developer(developer)
diff --git a/spec/models/concerns/reactive_caching_spec.rb b/spec/models/concerns/reactive_caching_spec.rb
index 03ae45e6b17..47522c81c0d 100644
--- a/spec/models/concerns/reactive_caching_spec.rb
+++ b/spec/models/concerns/reactive_caching_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ReactiveCaching, :use_clean_rails_memory_store_caching do
include ExclusiveLeaseHelpers
@@ -34,23 +34,23 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
let(:cache_key) { "foo:666" }
let(:instance) { CacheTest.new(666, &calculation) }
- describe '#with_reactive_cache' do
+ describe "#with_reactive_cache" do
before do
stub_reactive_cache
end
subject(:go!) { instance.result }
- context 'when cache is empty' do
+ context "when cache is empty" do
it { is_expected.to be_nil }
- it 'enqueues a background worker to bootstrap the cache' do
+ it "enqueues a background worker to bootstrap the cache" do
expect(ReactiveCachingWorker).to receive(:perform_async).with(CacheTest, 666)
go!
end
- it 'updates the cache lifespan' do
+ it "updates the cache lifespan" do
expect(reactive_cache_alive?(instance)).to be_falsy
go!
@@ -59,26 +59,26 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
end
end
- context 'when the cache is full' do
+ context "when the cache is full" do
before do
stub_reactive_cache(instance, 4)
end
it { is_expected.to eq(4) }
- it 'does not enqueue a background worker' do
+ it "does not enqueue a background worker" do
expect(ReactiveCachingWorker).not_to receive(:perform_async)
go!
end
- it 'updates the cache lifespan' do
+ it "updates the cache lifespan" do
expect(Rails.cache).to receive(:write).with(alive_reactive_cache_key(instance), true, expires_in: anything)
go!
end
- context 'and expired' do
+ context "and expired" do
before do
invalidate_reactive_cache(instance)
end
@@ -86,8 +86,8 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
it { is_expected.to be_nil }
end
- context 'when cache was invalidated' do
- it 'refreshes cache' do
+ context "when cache was invalidated" do
+ it "refreshes cache" do
expect(ReactiveCachingWorker).to receive(:perform_async).with(CacheTest, 666)
instance.with_reactive_cache { raise described_class::InvalidateReactiveCache }
@@ -95,7 +95,7 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
end
end
- context 'when cache contains non-nil but blank value' do
+ context "when cache contains non-nil but blank value" do
before do
stub_reactive_cache(instance, false)
end
@@ -104,7 +104,7 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
end
end
- describe '#clear_reactive_cache!' do
+ describe "#clear_reactive_cache!" do
before do
stub_reactive_cache(instance, 4)
instance.clear_reactive_cache!
@@ -114,22 +114,22 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
it { expect(reactive_cache_alive?(instance)).to be_falsy }
end
- describe '#exclusively_update_reactive_cache!' do
+ describe "#exclusively_update_reactive_cache!" do
subject(:go!) { instance.exclusively_update_reactive_cache! }
- context 'when the lease is free and lifetime is not exceeded' do
+ context "when the lease is free and lifetime is not exceeded" do
before do
stub_reactive_cache(instance, "preexisting")
end
- it 'takes and releases the lease' do
- expect_to_obtain_exclusive_lease(cache_key, 'uuid')
- expect_to_cancel_exclusive_lease(cache_key, 'uuid')
+ it "takes and releases the lease" do
+ expect_to_obtain_exclusive_lease(cache_key, "uuid")
+ expect_to_cancel_exclusive_lease(cache_key, "uuid")
go!
end
- it 'caches the result of #calculate_reactive_cache' do
+ it "caches the result of #calculate_reactive_cache" do
go!
expect(read_reactive_cache(instance)).to eq(calculation.call)
@@ -148,19 +148,19 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
2.times { instance.exclusively_update_reactive_cache! }
end
- context 'and #calculate_reactive_cache raises an exception' do
+ context "and #calculate_reactive_cache raises an exception" do
before do
stub_reactive_cache(instance, "preexisting")
end
let(:calculation) { -> { raise "foo"} }
- it 'leaves the cache untouched' do
+ it "leaves the cache untouched" do
expect { go! }.to raise_error("foo")
expect(read_reactive_cache(instance)).to eq("preexisting")
end
- it 'enqueues a repeat worker' do
+ it "enqueues a repeat worker" do
expect_reactive_cache_update_queued(instance)
expect { go! }.to raise_error("foo")
@@ -168,16 +168,16 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
end
end
- context 'when lifetime is exceeded' do
- it 'skips the calculation' do
+ context "when lifetime is exceeded" do
+ it "skips the calculation" do
expect(instance).to receive(:calculate_reactive_cache).never
go!
end
end
- context 'when the lease is already taken' do
- it 'skips the calculation' do
+ context "when the lease is already taken" do
+ it "skips the calculation" do
stub_exclusive_lease_taken(cache_key)
expect(instance).to receive(:calculate_reactive_cache).never
diff --git a/spec/models/concerns/redactable_spec.rb b/spec/models/concerns/redactable_spec.rb
index 7feeaa54069..156893fcc50 100644
--- a/spec/models/concerns/redactable_spec.rb
+++ b/spec/models/concerns/redactable_spec.rb
@@ -1,21 +1,21 @@
-require 'spec_helper'
+require "spec_helper"
describe Redactable do
before do
stub_commonmark_sourcepos_disabled
end
- shared_examples 'model with redactable field' do
- it 'redacts unsubscribe token' do
- model[field] = 'some text /sent_notifications/00000000000000000000000000000000/unsubscribe more text'
+ shared_examples "model with redactable field" do
+ it "redacts unsubscribe token" do
+ model[field] = "some text /sent_notifications/00000000000000000000000000000000/unsubscribe more text"
model.save!
- expect(model[field]).to eq 'some text /sent_notifications/REDACTED/unsubscribe more text'
+ expect(model[field]).to eq "some text /sent_notifications/REDACTED/unsubscribe more text"
end
- it 'ignores not hexadecimal tokens' do
- text = 'some text /sent_notifications/token/unsubscribe more text'
+ it "ignores not hexadecimal tokens" do
+ text = "some text /sent_notifications/token/unsubscribe more text"
model[field] = text
model.save!
@@ -23,8 +23,8 @@ describe Redactable do
expect(model[field]).to eq text
end
- it 'ignores not matching texts' do
- text = 'some text /sent_notifications/.*/unsubscribe more text'
+ it "ignores not matching texts" do
+ text = "some text /sent_notifications/.*/unsubscribe more text"
model[field] = text
model.save!
@@ -32,40 +32,40 @@ describe Redactable do
expect(model[field]).to eq text
end
- it 'redacts the field when saving the model before creating markdown cache' do
- model[field] = 'some text /sent_notifications/00000000000000000000000000000000/unsubscribe more text'
+ it "redacts the field when saving the model before creating markdown cache" do
+ model[field] = "some text /sent_notifications/00000000000000000000000000000000/unsubscribe more text"
model.save!
- expected = 'some text /sent_notifications/REDACTED/unsubscribe more text'
+ expected = "some text /sent_notifications/REDACTED/unsubscribe more text"
expect(model[field]).to eq expected
expect(model["#{field}_html"]).to eq "<p dir=\"auto\">#{expected}</p>"
end
end
- context 'when model is an issue' do
- it_behaves_like 'model with redactable field' do
+ context "when model is an issue" do
+ it_behaves_like "model with redactable field" do
let(:model) { create(:issue) }
let(:field) { :description }
end
end
- context 'when model is a merge request' do
- it_behaves_like 'model with redactable field' do
+ context "when model is a merge request" do
+ it_behaves_like "model with redactable field" do
let(:model) { create(:merge_request) }
let(:field) { :description }
end
end
- context 'when model is a note' do
- it_behaves_like 'model with redactable field' do
+ context "when model is a note" do
+ it_behaves_like "model with redactable field" do
let(:model) { create(:note) }
let(:field) { :note }
end
end
- context 'when model is a snippet' do
- it_behaves_like 'model with redactable field' do
+ context "when model is a snippet" do
+ it_behaves_like "model with redactable field" do
let(:model) { create(:snippet) }
let(:field) { :description }
end
diff --git a/spec/models/concerns/redis_cacheable_spec.rb b/spec/models/concerns/redis_cacheable_spec.rb
index 23c6c6233e9..7e1efb8af04 100644
--- a/spec/models/concerns/redis_cacheable_spec.rb
+++ b/spec/models/concerns/redis_cacheable_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe RedisCacheable do
let(:model) do
@@ -12,12 +12,12 @@ describe RedisCacheable do
end
def has_attribute?(attribute)
- attributes.has_key?(attribute)
+ attributes.key?(attribute)
end
end
end
- let(:payload) { { name: 'value', time: Time.zone.now } }
+ let(:payload) { {name: "value", time: Time.zone.now} }
let(:instance) { model.new(1, payload) }
let(:cache_key) { instance.__send__(:cache_attribute_key) }
@@ -25,10 +25,10 @@ describe RedisCacheable do
model.include(described_class)
end
- describe '#cached_attribute' do
+ describe "#cached_attribute" do
subject { instance.cached_attribute(payload.keys.first) }
- it 'gets the cache attribute' do
+ it "gets the cache attribute" do
Gitlab::Redis::SharedState.with do |redis|
expect(redis).to receive(:get).with(cache_key)
.and_return(payload.to_json)
@@ -38,10 +38,10 @@ describe RedisCacheable do
end
end
- describe '#cache_attributes' do
+ describe "#cache_attributes" do
subject { instance.cache_attributes(payload) }
- it 'sets the cache attributes' do
+ it "sets the cache attributes" do
Gitlab::Redis::SharedState.with do |redis|
expect(redis).to receive(:set).with(cache_key, payload.to_json, anything)
end
@@ -50,23 +50,23 @@ describe RedisCacheable do
end
end
- describe '#cached_attr_reader', :clean_gitlab_redis_shared_state do
+ describe "#cached_attr_reader", :clean_gitlab_redis_shared_state do
subject { instance.name }
before do
model.cached_attr_reader(:name)
end
- context 'when there is no cached value' do
- it 'reads the attribute' do
+ context "when there is no cached value" do
+ it "reads the attribute" do
expect(instance).to receive(:read_attribute).and_call_original
expect(subject).to eq(payload[:name])
end
end
- context 'when there is a cached value' do
- it 'reads the cached value' do
+ context "when there is a cached value" do
+ it "reads the cached value" do
expect(instance).not_to receive(:read_attribute)
instance.cache_attributes(payload)
@@ -75,24 +75,24 @@ describe RedisCacheable do
end
end
- it 'always returns the latest values' do
+ it "always returns the latest values" do
expect(instance.name).to eq(payload[:name])
- instance.cache_attributes(name: 'new_value')
+ instance.cache_attributes(name: "new_value")
- expect(instance.name).to eq('new_value')
+ expect(instance.name).to eq("new_value")
end
end
- describe '#cast_value_from_cache' do
+ describe "#cast_value_from_cache" do
subject { instance.__send__(:cast_value_from_cache, attribute, value) }
- context 'with runner contacted_at' do
+ context "with runner contacted_at" do
let(:instance) { Ci::Runner.new }
let(:attribute) { :contacted_at }
- let(:value) { '2018-05-07 13:53:08 UTC' }
+ let(:value) { "2018-05-07 13:53:08 UTC" }
- it 'converts cache string to appropriate type' do
+ it "converts cache string to appropriate type" do
expect(subject).to be_an_instance_of(ActiveSupport::TimeWithZone)
end
end
diff --git a/spec/models/concerns/relative_positioning_spec.rb b/spec/models/concerns/relative_positioning_spec.rb
index ac8da30b6c9..53adf192524 100644
--- a/spec/models/concerns/relative_positioning_spec.rb
+++ b/spec/models/concerns/relative_positioning_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe RelativePositioning do
let(:project) { create(:project) }
@@ -6,8 +6,8 @@ describe RelativePositioning do
let(:issue1) { create(:issue, project: project) }
let(:new_issue) { create(:issue, project: project) }
- describe '.move_to_end' do
- it 'moves the object to the end' do
+ describe ".move_to_end" do
+ it "moves the object to the end" do
Issue.move_to_end([issue, issue1])
expect(issue1.prev_relative_position).to eq issue.relative_position
@@ -15,7 +15,7 @@ describe RelativePositioning do
expect(issue1.next_relative_position).to eq nil
end
- it 'does not perform any moves if all issues have their relative_position set' do
+ it "does not perform any moves if all issues have their relative_position set" do
issue.update!(relative_position: 1)
expect(issue).not_to receive(:save)
@@ -24,34 +24,34 @@ describe RelativePositioning do
end
end
- describe '#max_relative_position' do
- it 'returns maximum position' do
+ describe "#max_relative_position" do
+ it "returns maximum position" do
expect(issue.max_relative_position).to eq issue1.relative_position
end
end
- describe '#prev_relative_position' do
- it 'returns previous position if there is an issue above' do
+ describe "#prev_relative_position" do
+ it "returns previous position if there is an issue above" do
expect(issue1.prev_relative_position).to eq issue.relative_position
end
- it 'returns nil if there is no issue above' do
+ it "returns nil if there is no issue above" do
expect(issue.prev_relative_position).to eq nil
end
end
- describe '#next_relative_position' do
- it 'returns next position if there is an issue below' do
+ describe "#next_relative_position" do
+ it "returns next position if there is an issue below" do
expect(issue.next_relative_position).to eq issue1.relative_position
end
- it 'returns nil if there is no issue below' do
+ it "returns nil if there is no issue below" do
expect(issue1.next_relative_position).to eq nil
end
end
- describe '#move_before' do
- it 'moves issue before' do
+ describe "#move_before" do
+ it "moves issue before" do
[issue1, issue].each(&:move_to_end)
issue.move_before(issue1)
@@ -60,8 +60,8 @@ describe RelativePositioning do
end
end
- describe '#move_after' do
- it 'moves issue after' do
+ describe "#move_after" do
+ it "moves issue after" do
[issue, issue1].each(&:move_to_end)
issue.move_after(issue1)
@@ -70,87 +70,87 @@ describe RelativePositioning do
end
end
- describe '#move_to_end' do
+ describe "#move_to_end" do
before do
[issue, issue1].each do |issue|
issue.move_to_end && issue.save
end
end
- it 'moves issue to the end' do
+ it "moves issue to the end" do
new_issue.move_to_end
expect(new_issue.relative_position).to be > issue1.relative_position
end
end
- describe '#shift_after?' do
+ describe "#shift_after?" do
before do
[issue, issue1].each do |issue|
issue.move_to_end && issue.save
end
end
- it 'returns true' do
+ it "returns true" do
issue.update(relative_position: issue1.relative_position - 1)
expect(issue.shift_after?).to be_truthy
end
- it 'returns false' do
+ it "returns false" do
issue.update(relative_position: issue1.relative_position - 2)
expect(issue.shift_after?).to be_falsey
end
end
- describe '#shift_before?' do
+ describe "#shift_before?" do
before do
[issue, issue1].each do |issue|
issue.move_to_end && issue.save
end
end
- it 'returns true' do
+ it "returns true" do
issue.update(relative_position: issue1.relative_position + 1)
expect(issue.shift_before?).to be_truthy
end
- it 'returns false' do
+ it "returns false" do
issue.update(relative_position: issue1.relative_position + 2)
expect(issue.shift_before?).to be_falsey
end
end
- describe '#move_between' do
+ describe "#move_between" do
before do
[issue, issue1].each do |issue|
issue.move_to_end && issue.save
end
end
- it 'positions issue between two other' do
+ it "positions issue between two other" do
new_issue.move_between(issue, issue1)
expect(new_issue.relative_position).to be > issue.relative_position
expect(new_issue.relative_position).to be < issue1.relative_position
end
- it 'positions issue between on top' do
+ it "positions issue between on top" do
new_issue.move_between(nil, issue)
expect(new_issue.relative_position).to be < issue.relative_position
end
- it 'positions issue between to end' do
+ it "positions issue between to end" do
new_issue.move_between(issue1, nil)
expect(new_issue.relative_position).to be > issue1.relative_position
end
- it 'positions issues even when after and before positions are the same' do
+ it "positions issues even when after and before positions are the same" do
issue1.update relative_position: issue.relative_position
new_issue.move_between(issue, issue1)
@@ -159,7 +159,7 @@ describe RelativePositioning do
expect(issue.relative_position).to be < issue1.relative_position
end
- it 'positions issues between other two if distance is 1' do
+ it "positions issues between other two if distance is 1" do
issue1.update relative_position: issue.relative_position + 1
new_issue.move_between(issue, issue1)
@@ -168,7 +168,7 @@ describe RelativePositioning do
expect(issue.relative_position).to be < issue1.relative_position
end
- it 'positions issue in the middle of other two if distance is big enough' do
+ it "positions issue in the middle of other two if distance is big enough" do
issue.update relative_position: 6000
issue1.update relative_position: 10000
@@ -177,7 +177,7 @@ describe RelativePositioning do
expect(new_issue.relative_position).to eq(8000)
end
- it 'positions issue closer to the middle if we are at the very top' do
+ it "positions issue closer to the middle if we are at the very top" do
issue1.update relative_position: 6000
new_issue.move_between(nil, issue1)
@@ -185,7 +185,7 @@ describe RelativePositioning do
expect(new_issue.relative_position).to eq(6000 - RelativePositioning::IDEAL_DISTANCE)
end
- it 'positions issue closer to the middle if we are at the very bottom' do
+ it "positions issue closer to the middle if we are at the very bottom" do
issue.update relative_position: 6000
issue1.update relative_position: nil
@@ -194,7 +194,7 @@ describe RelativePositioning do
expect(new_issue.relative_position).to eq(6000 + RelativePositioning::IDEAL_DISTANCE)
end
- it 'positions issue in the middle of other two if distance is not big enough' do
+ it "positions issue in the middle of other two if distance is not big enough" do
issue.update relative_position: 100
issue1.update relative_position: 400
@@ -203,7 +203,7 @@ describe RelativePositioning do
expect(new_issue.relative_position).to eq(250)
end
- it 'positions issue in the middle of other two is there is no place' do
+ it "positions issue in the middle of other two is there is no place" do
issue.update relative_position: 100
issue1.update relative_position: 101
@@ -212,7 +212,7 @@ describe RelativePositioning do
expect(new_issue.relative_position).to be_between(issue.relative_position, issue1.relative_position)
end
- it 'uses rebalancing if there is no place' do
+ it "uses rebalancing if there is no place" do
issue.update relative_position: 100
issue1.update relative_position: 101
issue2 = create(:issue, relative_position: 102, project: project)
@@ -225,7 +225,7 @@ describe RelativePositioning do
expect(issue.reload.relative_position).not_to eq(100)
end
- it 'positions issue right if we pass none-sequential parameters' do
+ it "positions issue right if we pass none-sequential parameters" do
issue.update relative_position: 99
issue1.update relative_position: 101
issue2 = create(:issue, relative_position: 102, project: project)
diff --git a/spec/models/concerns/resolvable_discussion_spec.rb b/spec/models/concerns/resolvable_discussion_spec.rb
index 97b046b0f21..45d689c731f 100644
--- a/spec/models/concerns/resolvable_discussion_spec.rb
+++ b/spec/models/concerns/resolvable_discussion_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Discussion, ResolvableDiscussion do
subject { described_class.new([first_note, second_note, third_note]) }
diff --git a/spec/models/concerns/resolvable_note_spec.rb b/spec/models/concerns/resolvable_note_spec.rb
index fcb5250278e..6800688b84c 100644
--- a/spec/models/concerns/resolvable_note_spec.rb
+++ b/spec/models/concerns/resolvable_note_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe Note, ResolvableNote do
let(:project) { create(:project, :repository) }
let(:merge_request) { create(:merge_request, source_project: project) }
subject { create(:discussion_note_on_merge_request, noteable: merge_request, project: project) }
- context 'resolvability scopes' do
+ context "resolvability scopes" do
let!(:note1) { create(:note, project: project) }
let!(:note2) { create(:diff_note_on_commit, project: project) }
let!(:note3) { create(:diff_note_on_merge_request, :resolved, noteable: merge_request, project: project) }
@@ -13,26 +13,26 @@ describe Note, ResolvableNote do
let!(:note5) { create(:discussion_note_on_issue, project: project) }
let!(:note6) { create(:discussion_note_on_merge_request, :system, noteable: merge_request, project: project) }
- describe '.potentially_resolvable' do
- it 'includes diff and discussion notes on merge requests' do
+ describe ".potentially_resolvable" do
+ it "includes diff and discussion notes on merge requests" do
expect(Note.potentially_resolvable).to match_array([note3, note4, note6])
end
end
- describe '.resolvable' do
- it 'includes non-system diff and discussion notes on merge requests' do
+ describe ".resolvable" do
+ it "includes non-system diff and discussion notes on merge requests" do
expect(Note.resolvable).to match_array([note3, note4])
end
end
- describe '.resolved' do
- it 'includes resolved non-system diff and discussion notes on merge requests' do
+ describe ".resolved" do
+ it "includes resolved non-system diff and discussion notes on merge requests" do
expect(Note.resolved).to match_array([note3])
end
end
- describe '.unresolved' do
- it 'includes non-resolved non-system diff and discussion notes on merge requests' do
+ describe ".unresolved" do
+ it "includes non-resolved non-system diff and discussion notes on merge requests" do
expect(Note.unresolved).to match_array([note4])
end
end
@@ -52,7 +52,7 @@ describe Note, ResolvableNote do
unresolved_note.reload
end
- it 'resolves only the resolvable, not yet resolved notes' do
+ it "resolves only the resolvable, not yet resolved notes" do
expect(commit_note.resolved_at).to be_nil
expect(resolved_note.resolved_by).not_to eq(current_user)
expect(unresolved_note.resolved_at).not_to be_nil
@@ -69,13 +69,13 @@ describe Note, ResolvableNote do
resolved_note.reload
end
- it 'unresolves the resolved notes' do
+ it "unresolves the resolved notes" do
expect(resolved_note.resolved_by).to be_nil
expect(resolved_note.resolved_at).to be_nil
end
end
- describe '#resolvable?' do
+ describe "#resolvable?" do
context "when potentially resolvable" do
before do
allow(subject).to receive(:potentially_resolvable?).and_return(true)
@@ -150,31 +150,31 @@ describe Note, ResolvableNote do
describe "#resolved?" do
let(:current_user) { create(:user) }
- context 'when not resolvable' do
+ context "when not resolvable" do
before do
subject.resolve!(current_user)
allow(subject).to receive(:resolvable?).and_return(false)
end
- it 'returns false' do
+ it "returns false" do
expect(subject.resolved?).to be_falsey
end
end
- context 'when resolvable' do
- context 'when the note has been resolved' do
+ context "when resolvable" do
+ context "when the note has been resolved" do
before do
subject.resolve!(current_user)
end
- it 'returns true' do
+ it "returns true" do
expect(subject.resolved?).to be_truthy
end
end
- context 'when the note has not been resolved' do
- it 'returns false' do
+ context "when the note has not been resolved" do
+ it "returns false" do
expect(subject.resolved?).to be_falsey
end
end
@@ -328,7 +328,7 @@ describe Note, ResolvableNote do
end
describe "#potentially_resolvable?" do
- it 'returns false if noteable could not be found' do
+ it "returns false if noteable could not be found" do
allow(subject).to receive(:noteable).and_return(nil)
expect(subject.potentially_resolvable?).to be_falsey
diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb
index 565266321d3..8d5566407bf 100644
--- a/spec/models/concerns/routable_spec.rb
+++ b/spec/models/concerns/routable_spec.rb
@@ -1,82 +1,82 @@
-require 'spec_helper'
+require "spec_helper"
-describe Group, 'Routable' do
- let!(:group) { create(:group, name: 'foo') }
+describe Group, "Routable" do
+ let!(:group) { create(:group, name: "foo") }
- describe 'Validations' do
+ describe "Validations" do
it { is_expected.to validate_presence_of(:route) }
end
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to have_one(:route).dependent(:destroy) }
it { is_expected.to have_many(:redirect_routes).dependent(:destroy) }
end
- describe 'Callbacks' do
- it 'creates route record on create' do
+ describe "Callbacks" do
+ it "creates route record on create" do
expect(group.route.path).to eq(group.path)
expect(group.route.name).to eq(group.name)
end
- it 'updates route record on path change' do
- group.update(path: 'wow', name: 'much')
+ it "updates route record on path change" do
+ group.update(path: "wow", name: "much")
- expect(group.route.path).to eq('wow')
- expect(group.route.name).to eq('much')
+ expect(group.route.path).to eq("wow")
+ expect(group.route.name).to eq("much")
end
- it 'ensure route path uniqueness across different objects' do
- create(:group, parent: group, path: 'xyz')
- duplicate = build(:project, namespace: group, path: 'xyz')
+ it "ensure route path uniqueness across different objects" do
+ create(:group, parent: group, path: "xyz")
+ duplicate = build(:project, namespace: group, path: "xyz")
- expect { duplicate.save! }.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Path has already been taken')
+ expect { duplicate.save! }.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Path has already been taken")
end
end
- describe '.find_by_full_path' do
+ describe ".find_by_full_path" do
let!(:nested_group) { create(:group, parent: group) }
- context 'without any redirect routes' do
+ context "without any redirect routes" do
it { expect(described_class.find_by_full_path(group.to_param)).to eq(group) }
it { expect(described_class.find_by_full_path(group.to_param.upcase)).to eq(group) }
it { expect(described_class.find_by_full_path(nested_group.to_param)).to eq(nested_group) }
- it { expect(described_class.find_by_full_path('unknown')).to eq(nil) }
+ it { expect(described_class.find_by_full_path("unknown")).to eq(nil) }
end
- context 'with redirect routes' do
- let!(:group_redirect_route) { group.redirect_routes.create!(path: 'bar') }
- let!(:nested_group_redirect_route) { nested_group.redirect_routes.create!(path: nested_group.path.sub('foo', 'bar')) }
+ context "with redirect routes" do
+ let!(:group_redirect_route) { group.redirect_routes.create!(path: "bar") }
+ let!(:nested_group_redirect_route) { nested_group.redirect_routes.create!(path: nested_group.path.sub("foo", "bar")) }
- context 'without follow_redirects option' do
- context 'with the given path not matching any route' do
- it { expect(described_class.find_by_full_path('unknown')).to eq(nil) }
+ context "without follow_redirects option" do
+ context "with the given path not matching any route" do
+ it { expect(described_class.find_by_full_path("unknown")).to eq(nil) }
end
- context 'with the given path matching the canonical route' do
+ context "with the given path matching the canonical route" do
it { expect(described_class.find_by_full_path(group.to_param)).to eq(group) }
it { expect(described_class.find_by_full_path(group.to_param.upcase)).to eq(group) }
it { expect(described_class.find_by_full_path(nested_group.to_param)).to eq(nested_group) }
end
- context 'with the given path matching a redirect route' do
+ context "with the given path matching a redirect route" do
it { expect(described_class.find_by_full_path(group_redirect_route.path)).to eq(nil) }
it { expect(described_class.find_by_full_path(group_redirect_route.path.upcase)).to eq(nil) }
it { expect(described_class.find_by_full_path(nested_group_redirect_route.path)).to eq(nil) }
end
end
- context 'with follow_redirects option set to true' do
- context 'with the given path not matching any route' do
- it { expect(described_class.find_by_full_path('unknown', follow_redirects: true)).to eq(nil) }
+ context "with follow_redirects option set to true" do
+ context "with the given path not matching any route" do
+ it { expect(described_class.find_by_full_path("unknown", follow_redirects: true)).to eq(nil) }
end
- context 'with the given path matching the canonical route' do
+ context "with the given path matching the canonical route" do
it { expect(described_class.find_by_full_path(group.to_param, follow_redirects: true)).to eq(group) }
it { expect(described_class.find_by_full_path(group.to_param.upcase, follow_redirects: true)).to eq(group) }
it { expect(described_class.find_by_full_path(nested_group.to_param, follow_redirects: true)).to eq(nested_group) }
end
- context 'with the given path matching a redirect route' do
+ context "with the given path matching a redirect route" do
it { expect(described_class.find_by_full_path(group_redirect_route.path, follow_redirects: true)).to eq(group) }
it { expect(described_class.find_by_full_path(group_redirect_route.path.upcase, follow_redirects: true)).to eq(group) }
it { expect(described_class.find_by_full_path(nested_group_redirect_route.path, follow_redirects: true)).to eq(nested_group) }
@@ -85,29 +85,29 @@ describe Group, 'Routable' do
end
end
- describe '.where_full_path_in' do
- context 'without any paths' do
- it 'returns an empty relation' do
+ describe ".where_full_path_in" do
+ context "without any paths" do
+ it "returns an empty relation" do
expect(described_class.where_full_path_in([])).to eq([])
end
end
- context 'without any valid paths' do
- it 'returns an empty relation' do
+ context "without any valid paths" do
+ it "returns an empty relation" do
expect(described_class.where_full_path_in(%w[unknown])).to eq([])
end
end
- context 'with valid paths' do
+ context "with valid paths" do
let!(:nested_group) { create(:group, parent: group) }
- it 'returns the projects matching the paths' do
+ it "returns the projects matching the paths" do
result = described_class.where_full_path_in([group.to_param, nested_group.to_param])
expect(result).to contain_exactly(group, nested_group)
end
- it 'returns projects regardless of the casing of paths' do
+ it "returns projects regardless of the casing of paths" do
result = described_class.where_full_path_in([group.to_param.upcase, nested_group.to_param.upcase])
expect(result).to contain_exactly(group, nested_group)
@@ -115,7 +115,7 @@ describe Group, 'Routable' do
end
end
- describe '#full_path' do
+ describe "#full_path" do
let(:group) { create(:group) }
let(:nested_group) { create(:group, parent: group) }
@@ -123,7 +123,7 @@ describe Group, 'Routable' do
it { expect(nested_group.full_path).to eq("#{group.full_path}/#{nested_group.path}") }
end
- describe '#full_name' do
+ describe "#full_name" do
let(:group) { create(:group) }
let(:nested_group) { create(:group, parent: group) }
@@ -132,14 +132,14 @@ describe Group, 'Routable' do
end
end
-describe Project, 'Routable' do
- describe '#full_path' do
+describe Project, "Routable" do
+ describe "#full_path" do
let(:project) { build_stubbed(:project) }
it { expect(project.full_path).to eq "#{project.namespace.full_path}/#{project.path}" }
end
- describe '#full_name' do
+ describe "#full_name" do
let(:project) { build_stubbed(:project) }
it { expect(project.full_name).to eq "#{project.namespace.human_name} / #{project.name}" }
diff --git a/spec/models/concerns/sha_attribute_spec.rb b/spec/models/concerns/sha_attribute_spec.rb
index 0d3beb6a6e3..8675af673c0 100644
--- a/spec/models/concerns/sha_attribute_spec.rb
+++ b/spec/models/concerns/sha_attribute_spec.rb
@@ -1,42 +1,42 @@
-require 'spec_helper'
+require "spec_helper"
describe ShaAttribute do
let(:model) { Class.new { include ShaAttribute } }
before do
columns = [
- double(:column, name: 'name', type: :text),
- double(:column, name: 'sha1', type: :binary)
+ double(:column, name: "name", type: :text),
+ double(:column, name: "sha1", type: :binary),
]
allow(model).to receive(:columns).and_return(columns)
end
- describe '#sha_attribute' do
- context 'when in non-production' do
+ describe "#sha_attribute" do
+ context "when in non-production" do
before do
allow(Rails.env).to receive(:production?).and_return(false)
end
- context 'when the table exists' do
+ context "when the table exists" do
before do
allow(model).to receive(:table_exists?).and_return(true)
end
- it 'defines a SHA attribute for a binary column' do
+ it "defines a SHA attribute for a binary column" do
expect(model).to receive(:attribute)
.with(:sha1, an_instance_of(Gitlab::Database::ShaAttribute))
model.sha_attribute(:sha1)
end
- it 'raises ArgumentError when the column type is not :binary' do
+ it "raises ArgumentError when the column type is not :binary" do
expect { model.sha_attribute(:name) }.to raise_error(ArgumentError)
end
end
- context 'when the table does not exist' do
- it 'allows the attribute to be added and issues a warning' do
+ context "when the table does not exist" do
+ it "allows the attribute to be added and issues a warning" do
allow(model).to receive(:table_exists?).and_return(false)
expect(model).not_to receive(:columns)
@@ -47,8 +47,8 @@ describe ShaAttribute do
end
end
- context 'when the column does not exist' do
- it 'allows the attribute to be added and issues a warning' do
+ context "when the column does not exist" do
+ it "allows the attribute to be added and issues a warning" do
allow(model).to receive(:table_exists?).and_return(true)
expect(model).to receive(:columns)
@@ -59,9 +59,9 @@ describe ShaAttribute do
end
end
- context 'when other execeptions are raised' do
- it 'logs and re-rasises the error' do
- allow(model).to receive(:table_exists?).and_raise(ActiveRecord::NoDatabaseError.new('does not exist'))
+ context "when other execeptions are raised" do
+ it "logs and re-rasises the error" do
+ allow(model).to receive(:table_exists?).and_raise(ActiveRecord::NoDatabaseError.new("does not exist"))
expect(model).not_to receive(:columns)
expect(model).not_to receive(:attribute)
@@ -72,12 +72,12 @@ describe ShaAttribute do
end
end
- context 'when in production' do
+ context "when in production" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
- it 'defines a SHA attribute' do
+ it "defines a SHA attribute" do
expect(model).not_to receive(:table_exists?)
expect(model).not_to receive(:columns)
expect(model).to receive(:attribute).with(:sha1, an_instance_of(Gitlab::Database::ShaAttribute))
diff --git a/spec/models/concerns/sortable_spec.rb b/spec/models/concerns/sortable_spec.rb
index 0a9d2021a19..c253f465b88 100644
--- a/spec/models/concerns/sortable_spec.rb
+++ b/spec/models/concerns/sortable_spec.rb
@@ -1,118 +1,118 @@
-require 'spec_helper'
+require "spec_helper"
describe Sortable do
- describe '.order_by' do
+ describe ".order_by" do
let(:relation) { Group.all }
- describe 'ordering by id' do
- it 'ascending' do
+ describe "ordering by id" do
+ it "ascending" do
expect(relation).to receive(:reorder).with(id: :asc)
- relation.order_by('id_asc')
+ relation.order_by("id_asc")
end
- it 'descending' do
+ it "descending" do
expect(relation).to receive(:reorder).with(id: :desc)
- relation.order_by('id_desc')
+ relation.order_by("id_desc")
end
end
- describe 'ordering by created day' do
- it 'ascending' do
+ describe "ordering by created day" do
+ it "ascending" do
expect(relation).to receive(:reorder).with(created_at: :asc)
- relation.order_by('created_asc')
+ relation.order_by("created_asc")
end
- it 'descending' do
+ it "descending" do
expect(relation).to receive(:reorder).with(created_at: :desc)
- relation.order_by('created_desc')
+ relation.order_by("created_desc")
end
it 'order by "date"' do
expect(relation).to receive(:reorder).with(created_at: :desc)
- relation.order_by('created_date')
+ relation.order_by("created_date")
end
end
- describe 'ordering by name' do
- it 'ascending' do
+ describe "ordering by name" do
+ it "ascending" do
expect(relation).to receive(:reorder).once.and_call_original
table = Regexp.escape(ActiveRecord::Base.connection.quote_table_name(:namespaces))
column = Regexp.escape(ActiveRecord::Base.connection.quote_column_name(:name))
- sql = relation.order_by('name_asc').to_sql
+ sql = relation.order_by("name_asc").to_sql
expect(sql).to match /.+ORDER BY LOWER\(#{table}.#{column}\) ASC\z/
end
- it 'descending' do
+ it "descending" do
expect(relation).to receive(:reorder).once.and_call_original
table = Regexp.escape(ActiveRecord::Base.connection.quote_table_name(:namespaces))
column = Regexp.escape(ActiveRecord::Base.connection.quote_column_name(:name))
- sql = relation.order_by('name_desc').to_sql
+ sql = relation.order_by("name_desc").to_sql
expect(sql).to match /.+ORDER BY LOWER\(#{table}.#{column}\) DESC\z/
end
end
- describe 'ordering by Updated Time' do
- it 'ascending' do
+ describe "ordering by Updated Time" do
+ it "ascending" do
expect(relation).to receive(:reorder).with(updated_at: :asc)
- relation.order_by('updated_asc')
+ relation.order_by("updated_asc")
end
- it 'descending' do
+ it "descending" do
expect(relation).to receive(:reorder).with(updated_at: :desc)
- relation.order_by('updated_desc')
+ relation.order_by("updated_desc")
end
end
- it 'does not call reorder in case of unrecognized ordering' do
+ it "does not call reorder in case of unrecognized ordering" do
expect(relation).not_to receive(:reorder)
- relation.order_by('random_ordering')
+ relation.order_by("random_ordering")
end
end
- describe 'sorting groups' do
+ describe "sorting groups" do
def ordered_group_names(order)
Group.all.order_by(order).map(&:name)
end
- let!(:ref_time) { Time.parse('2018-05-01 00:00:00') }
- let!(:group1) { create(:group, name: 'aa', id: 1, created_at: ref_time - 15.seconds, updated_at: ref_time) }
- let!(:group2) { create(:group, name: 'AAA', id: 2, created_at: ref_time - 10.seconds, updated_at: ref_time - 5.seconds) }
- let!(:group3) { create(:group, name: 'BB', id: 3, created_at: ref_time - 5.seconds, updated_at: ref_time - 10.seconds) }
- let!(:group4) { create(:group, name: 'bbb', id: 4, created_at: ref_time, updated_at: ref_time - 15.seconds) }
+ let!(:ref_time) { Time.parse("2018-05-01 00:00:00") }
+ let!(:group1) { create(:group, name: "aa", id: 1, created_at: ref_time - 15.seconds, updated_at: ref_time) }
+ let!(:group2) { create(:group, name: "AAA", id: 2, created_at: ref_time - 10.seconds, updated_at: ref_time - 5.seconds) }
+ let!(:group3) { create(:group, name: "BB", id: 3, created_at: ref_time - 5.seconds, updated_at: ref_time - 10.seconds) }
+ let!(:group4) { create(:group, name: "bbb", id: 4, created_at: ref_time, updated_at: ref_time - 15.seconds) }
- it 'sorts groups by id' do
- expect(ordered_group_names('id_asc')).to eq(%w(aa AAA BB bbb))
- expect(ordered_group_names('id_desc')).to eq(%w(bbb BB AAA aa))
+ it "sorts groups by id" do
+ expect(ordered_group_names("id_asc")).to eq(%w[aa AAA BB bbb])
+ expect(ordered_group_names("id_desc")).to eq(%w[bbb BB AAA aa])
end
- it 'sorts groups by name via case-insensitive comparision' do
- expect(ordered_group_names('name_asc')).to eq(%w(aa AAA BB bbb))
- expect(ordered_group_names('name_desc')).to eq(%w(bbb BB AAA aa))
+ it "sorts groups by name via case-insensitive comparision" do
+ expect(ordered_group_names("name_asc")).to eq(%w[aa AAA BB bbb])
+ expect(ordered_group_names("name_desc")).to eq(%w[bbb BB AAA aa])
end
- it 'sorts groups by created_at' do
- expect(ordered_group_names('created_asc')).to eq(%w(aa AAA BB bbb))
- expect(ordered_group_names('created_desc')).to eq(%w(bbb BB AAA aa))
- expect(ordered_group_names('created_date')).to eq(%w(bbb BB AAA aa))
+ it "sorts groups by created_at" do
+ expect(ordered_group_names("created_asc")).to eq(%w[aa AAA BB bbb])
+ expect(ordered_group_names("created_desc")).to eq(%w[bbb BB AAA aa])
+ expect(ordered_group_names("created_date")).to eq(%w[bbb BB AAA aa])
end
- it 'sorts groups by updated_at' do
- expect(ordered_group_names('updated_asc')).to eq(%w(bbb BB AAA aa))
- expect(ordered_group_names('updated_desc')).to eq(%w(aa AAA BB bbb))
+ it "sorts groups by updated_at" do
+ expect(ordered_group_names("updated_asc")).to eq(%w[bbb BB AAA aa])
+ expect(ordered_group_names("updated_desc")).to eq(%w[aa AAA BB bbb])
end
end
end
diff --git a/spec/models/concerns/spammable_spec.rb b/spec/models/concerns/spammable_spec.rb
index e698207166c..d9bc03f651d 100644
--- a/spec/models/concerns/spammable_spec.rb
+++ b/spec/models/concerns/spammable_spec.rb
@@ -1,40 +1,40 @@
-require 'spec_helper'
+require "spec_helper"
describe Spammable do
- let(:issue) { create(:issue, description: 'Test Desc.') }
+ let(:issue) { create(:issue, description: "Test Desc.") }
- describe 'Associations' do
+ describe "Associations" do
subject { build(:issue) }
it { is_expected.to have_one(:user_agent_detail).dependent(:destroy) }
end
- describe 'ClassMethods' do
- it 'should return correct attr_spammable' do
+ describe "ClassMethods" do
+ it "should return correct attr_spammable" do
expect(issue.spammable_text).to eq("#{issue.title}\n#{issue.description}")
end
end
- describe 'InstanceMethods' do
+ describe "InstanceMethods" do
let(:issue) { build(:issue, spam: true) }
- it 'should be invalid if spam' do
+ it "should be invalid if spam" do
expect(issue.valid?).to be_falsey
end
- describe '#check_for_spam?' do
- it 'returns true for public project' do
+ describe "#check_for_spam?" do
+ it "returns true for public project" do
issue.project.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PUBLIC)
expect(issue.check_for_spam?).to eq(true)
end
- it 'returns false for other visibility levels' do
+ it "returns false for other visibility levels" do
expect(issue.check_for_spam?).to eq(false)
end
end
- describe '#submittable_as_spam_by?' do
+ describe "#submittable_as_spam_by?" do
let(:admin) { build(:admin) }
let(:user) { build(:user) }
@@ -42,7 +42,7 @@ describe Spammable do
allow(issue).to receive(:submittable_as_spam?).and_return(true)
end
- it 'tests if the user can submit spam' do
+ it "tests if the user can submit spam" do
expect(issue.submittable_as_spam_by?(admin)).to be(true)
expect(issue.submittable_as_spam_by?(user)).to be(false)
expect(issue.submittable_as_spam_by?(nil)).to be_nil
diff --git a/spec/models/concerns/strip_attribute_spec.rb b/spec/models/concerns/strip_attribute_spec.rb
index 8c945686b66..93e2ff3a2bf 100644
--- a/spec/models/concerns/strip_attribute_spec.rb
+++ b/spec/models/concerns/strip_attribute_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe StripAttribute do
let(:milestone) { create(:milestone) }
@@ -10,10 +10,10 @@ describe StripAttribute do
describe "#strip_attributes" do
before do
- milestone.title = ' 8.3 '
+ milestone.title = " 8.3 "
milestone.valid?
end
- it { expect(milestone.title).to eq('8.3') }
+ it { expect(milestone.title).to eq("8.3") }
end
end
diff --git a/spec/models/concerns/subscribable_spec.rb b/spec/models/concerns/subscribable_spec.rb
index 45dfb136aea..7bdeabbef9a 100644
--- a/spec/models/concerns/subscribable_spec.rb
+++ b/spec/models/concerns/subscribable_spec.rb
@@ -1,47 +1,47 @@
-require 'spec_helper'
+require "spec_helper"
-describe Subscribable, 'Subscribable' do
+describe Subscribable, "Subscribable" do
let(:project) { create(:project) }
let(:resource) { create(:issue, project: project) }
let(:user_1) { create(:user) }
- describe '#subscribed?' do
- context 'without user' do
- it 'returns false' do
+ describe "#subscribed?" do
+ context "without user" do
+ it "returns false" do
expect(resource.subscribed?(nil, project)).to be_falsey
end
end
- context 'without project' do
- it 'returns false when no subscription exists' do
+ context "without project" do
+ it "returns false when no subscription exists" do
expect(resource.subscribed?(user_1)).to be_falsey
end
- it 'returns true when a subcription exists and subscribed is true' do
+ it "returns true when a subcription exists and subscribed is true" do
resource.subscriptions.create(user: user_1, subscribed: true)
expect(resource.subscribed?(user_1)).to be_truthy
end
- it 'returns false when a subcription exists and subscribed is false' do
+ it "returns false when a subcription exists and subscribed is false" do
resource.subscriptions.create(user: user_1, subscribed: false)
expect(resource.subscribed?(user_1)).to be_falsey
end
end
- context 'with project' do
- it 'returns false when no subscription exists' do
+ context "with project" do
+ it "returns false when no subscription exists" do
expect(resource.subscribed?(user_1, project)).to be_falsey
end
- it 'returns true when a subcription exists and subscribed is true' do
+ it "returns true when a subcription exists and subscribed is true" do
resource.subscriptions.create(user: user_1, project: project, subscribed: true)
expect(resource.subscribed?(user_1, project)).to be_truthy
end
- it 'returns false when a subcription exists and subscribed is false' do
+ it "returns false when a subcription exists and subscribed is false" do
resource.subscriptions.create(user: user_1, project: project, subscribed: false)
expect(resource.subscribed?(user_1, project)).to be_falsey
@@ -49,12 +49,12 @@ describe Subscribable, 'Subscribable' do
end
end
- describe '#subscribers' do
- it 'returns [] when no subcribers exists' do
+ describe "#subscribers" do
+ it "returns [] when no subcribers exists" do
expect(resource.subscribers(project)).to be_empty
end
- it 'returns the subscribed users' do
+ it "returns the subscribed users" do
user_2 = create(:user)
resource.subscriptions.create(user: user_1, subscribed: true)
resource.subscriptions.create(user: user_2, project: project, subscribed: true)
@@ -64,9 +64,9 @@ describe Subscribable, 'Subscribable' do
end
end
- describe '#toggle_subscription' do
- context 'without project' do
- it 'toggles the current subscription state for the given user' do
+ describe "#toggle_subscription" do
+ context "without project" do
+ it "toggles the current subscription state for the given user" do
expect(resource.subscribed?(user_1)).to be_falsey
resource.toggle_subscription(user_1)
@@ -75,8 +75,8 @@ describe Subscribable, 'Subscribable' do
end
end
- context 'with project' do
- it 'toggles the current subscription state for the given user' do
+ context "with project" do
+ it "toggles the current subscription state for the given user" do
expect(resource.subscribed?(user_1, project)).to be_falsey
resource.toggle_subscription(user_1, project)
@@ -86,9 +86,9 @@ describe Subscribable, 'Subscribable' do
end
end
- describe '#subscribe' do
- context 'without project' do
- it 'subscribes the given user' do
+ describe "#subscribe" do
+ context "without project" do
+ it "subscribes the given user" do
expect(resource.subscribed?(user_1)).to be_falsey
resource.subscribe(user_1)
@@ -97,8 +97,8 @@ describe Subscribable, 'Subscribable' do
end
end
- context 'with project' do
- it 'subscribes the given user' do
+ context "with project" do
+ it "subscribes the given user" do
expect(resource.subscribed?(user_1, project)).to be_falsey
resource.subscribe(user_1, project)
@@ -108,9 +108,9 @@ describe Subscribable, 'Subscribable' do
end
end
- describe '#unsubscribe' do
- context 'without project' do
- it 'unsubscribes the given current user' do
+ describe "#unsubscribe" do
+ context "without project" do
+ it "unsubscribes the given current user" do
resource.subscriptions.create(user: user_1, subscribed: true)
expect(resource.subscribed?(user_1)).to be_truthy
@@ -120,8 +120,8 @@ describe Subscribable, 'Subscribable' do
end
end
- context 'with project' do
- it 'unsubscribes the given current user' do
+ context "with project" do
+ it "unsubscribes the given current user" do
resource.subscriptions.create(user: user_1, project: project, subscribed: true)
expect(resource.subscribed?(user_1, project)).to be_truthy
diff --git a/spec/models/concerns/token_authenticatable_spec.rb b/spec/models/concerns/token_authenticatable_spec.rb
index 40cb4eef60a..77fed825132 100644
--- a/spec/models/concerns/token_authenticatable_spec.rb
+++ b/spec/models/concerns/token_authenticatable_spec.rb
@@ -1,7 +1,7 @@
-require 'spec_helper'
+require "spec_helper"
-shared_examples 'TokenAuthenticatable' do
- describe 'dynamically defined methods' do
+shared_examples "TokenAuthenticatable" do
+ describe "dynamically defined methods" do
it { expect(described_class).to respond_to("find_by_#{token_field}") }
it { is_expected.to respond_to("ensure_#{token_field}") }
it { is_expected.to respond_to("set_#{token_field}") }
@@ -9,25 +9,25 @@ shared_examples 'TokenAuthenticatable' do
end
end
-describe User, 'TokenAuthenticatable' do
+describe User, "TokenAuthenticatable" do
let(:token_field) { :feed_token }
- it_behaves_like 'TokenAuthenticatable'
+ it_behaves_like "TokenAuthenticatable"
- describe 'ensures authentication token' do
+ describe "ensures authentication token" do
subject { create(:user).send(token_field) }
it { is_expected.to be_a String }
end
end
-describe ApplicationSetting, 'TokenAuthenticatable' do
+describe ApplicationSetting, "TokenAuthenticatable" do
let(:token_field) { :runners_registration_token }
let(:settings) { described_class.new }
- it_behaves_like 'TokenAuthenticatable'
+ it_behaves_like "TokenAuthenticatable"
- describe 'generating new token' do
- context 'token is not generated yet' do
- describe 'token field accessor' do
+ describe "generating new token" do
+ context "token is not generated yet" do
+ describe "token field accessor" do
subject { settings.send(token_field) }
it { is_expected.not_to be_blank }
@@ -39,46 +39,46 @@ describe ApplicationSetting, 'TokenAuthenticatable' do
it { is_expected.to be_a String }
it { is_expected.not_to be_blank }
- it 'does not persist token' do
+ it "does not persist token" do
expect(settings).not_to be_persisted
end
end
- describe 'ensure_runners_registration_token!' do
+ describe "ensure_runners_registration_token!" do
subject { settings.send("ensure_#{token_field}!") }
- it 'persists new token as an encrypted string' do
+ it "persists new token as an encrypted string" do
expect(subject).to eq settings.reload.runners_registration_token
- expect(settings.read_attribute('runners_registration_token_encrypted'))
+ expect(settings.read_attribute("runners_registration_token_encrypted"))
.to eq Gitlab::CryptoHelper.aes256_gcm_encrypt(subject)
expect(settings).to be_persisted
end
- it 'does not persist token in a clear text' do
+ it "does not persist token in a clear text" do
expect(subject).not_to eq settings.reload
- .read_attribute('runners_registration_token_encrypted')
+ .read_attribute("runners_registration_token_encrypted")
end
end
end
- context 'token is generated' do
+ context "token is generated" do
before do
settings.send("reset_#{token_field}!")
end
- it 'persists a new token' do
+ it "persists a new token" do
expect(settings.runners_registration_token).to be_a String
end
end
end
- describe 'setting new token' do
- subject { settings.send("set_#{token_field}", '0123456789') }
+ describe "setting new token" do
+ subject { settings.send("set_#{token_field}", "0123456789") }
- it { is_expected.to eq '0123456789' }
+ it { is_expected.to eq "0123456789" }
end
- describe 'multiple token fields' do
+ describe "multiple token fields" do
before(:all) do
described_class.send(:add_authentication_token_field, :yet_another_token)
end
@@ -87,18 +87,18 @@ describe ApplicationSetting, 'TokenAuthenticatable' do
it { is_expected.to respond_to(:ensure_yet_another_token) }
end
- describe 'setting same token field multiple times' do
+ describe "setting same token field multiple times" do
subject { described_class.send(:add_authentication_token_field, :runners_registration_token) }
- it 'raises error' do
+ it "raises error" do
expect {subject}.to raise_error(ArgumentError)
end
end
end
-describe PersonalAccessToken, 'TokenAuthenticatable' do
- shared_examples 'changes personal access token' do
- it 'sets new token' do
+describe PersonalAccessToken, "TokenAuthenticatable" do
+ shared_examples "changes personal access token" do
+ it "sets new token" do
subject
expect(personal_access_token.token).to eq(token_value)
@@ -106,8 +106,8 @@ describe PersonalAccessToken, 'TokenAuthenticatable' do
end
end
- shared_examples 'does not change personal access token' do
- it 'sets new token' do
+ shared_examples "does not change personal access token" do
+ it "sets new token" do
subject
expect(personal_access_token.token).to be(nil)
@@ -115,11 +115,11 @@ describe PersonalAccessToken, 'TokenAuthenticatable' do
end
end
- let(:token_value) { 'token' }
+ let(:token_value) { "token" }
let(:token_digest) { Gitlab::CryptoHelper.sha256(token_value) }
let(:user) { create(:user) }
let(:personal_access_token) do
- described_class.new(name: 'test-pat-01',
+ described_class.new(name: "test-pat-01",
user_id: user.id,
scopes: [:api],
token_digest: token_digest)
@@ -129,22 +129,22 @@ describe PersonalAccessToken, 'TokenAuthenticatable' do
allow(Devise).to receive(:friendly_token).and_return(token_value)
end
- describe '.find_by_token' do
+ describe ".find_by_token" do
subject { PersonalAccessToken.find_by_token(token_value) }
- it 'finds the token' do
+ it "finds the token" do
personal_access_token.save
expect(subject).to eq(personal_access_token)
end
end
- describe '#set_token' do
- let(:new_token_value) { 'new-token' }
+ describe "#set_token" do
+ let(:new_token_value) { "new-token" }
subject { personal_access_token.set_token(new_token_value) }
- it 'sets new token' do
+ it "sets new token" do
subject
expect(personal_access_token.token).to eq(new_token_value)
@@ -152,65 +152,65 @@ describe PersonalAccessToken, 'TokenAuthenticatable' do
end
end
- describe '#ensure_token' do
+ describe "#ensure_token" do
subject { personal_access_token.ensure_token }
- context 'token_digest does not exist' do
+ context "token_digest does not exist" do
let(:token_digest) { nil }
- it_behaves_like 'changes personal access token'
+ it_behaves_like "changes personal access token"
end
- context 'token_digest already generated' do
- let(:token_digest) { 's3cr3t' }
+ context "token_digest already generated" do
+ let(:token_digest) { "s3cr3t" }
- it_behaves_like 'does not change personal access token'
+ it_behaves_like "does not change personal access token"
end
end
- describe '#ensure_token!' do
+ describe "#ensure_token!" do
subject { personal_access_token.ensure_token! }
- context 'token_digest does not exist' do
+ context "token_digest does not exist" do
let(:token_digest) { nil }
- it_behaves_like 'changes personal access token'
+ it_behaves_like "changes personal access token"
end
- context 'token_digest already generated' do
- let(:token_digest) { 's3cr3t' }
+ context "token_digest already generated" do
+ let(:token_digest) { "s3cr3t" }
- it_behaves_like 'does not change personal access token'
+ it_behaves_like "does not change personal access token"
end
end
- describe '#reset_token!' do
+ describe "#reset_token!" do
subject { personal_access_token.reset_token! }
- context 'token_digest does not exist' do
+ context "token_digest does not exist" do
let(:token_digest) { nil }
- it_behaves_like 'changes personal access token'
+ it_behaves_like "changes personal access token"
end
- context 'token_digest already generated' do
- let(:token_digest) { 's3cr3t' }
+ context "token_digest already generated" do
+ let(:token_digest) { "s3cr3t" }
- it_behaves_like 'changes personal access token'
+ it_behaves_like "changes personal access token"
end
end
end
-describe Ci::Build, 'TokenAuthenticatable' do
+describe Ci::Build, "TokenAuthenticatable" do
let(:token_field) { :token }
let(:build) { FactoryBot.build(:ci_build) }
- it_behaves_like 'TokenAuthenticatable'
+ it_behaves_like "TokenAuthenticatable"
- describe 'generating new token' do
- context 'token is not generated yet' do
- describe 'token field accessor' do
- it 'makes it possible to access token' do
+ describe "generating new token" do
+ context "token is not generated yet" do
+ describe "token field accessor" do
+ it "makes it possible to access token" do
expect(build.token).to be_nil
build.save!
@@ -225,35 +225,35 @@ describe Ci::Build, 'TokenAuthenticatable' do
it { is_expected.to be_a String }
it { is_expected.not_to be_blank }
- it 'does not persist token' do
+ it "does not persist token" do
expect(build).not_to be_persisted
end
end
- describe 'ensure_token!' do
- it 'persists a new token' do
+ describe "ensure_token!" do
+ it "persists a new token" do
expect(build.ensure_token!).to eq build.reload.token
expect(build).to be_persisted
end
- it 'persists new token as an encrypted string' do
+ it "persists new token as an encrypted string" do
build.ensure_token!
encrypted = Gitlab::CryptoHelper.aes256_gcm_encrypt(build.token)
- expect(build.read_attribute('token_encrypted')).to eq encrypted
+ expect(build.read_attribute("token_encrypted")).to eq encrypted
end
- it 'does not persist a token in a clear text' do
+ it "does not persist a token in a clear text" do
build.ensure_token!
- expect(build.read_attribute('token')).to be_nil
+ expect(build.read_attribute("token")).to be_nil
end
end
end
- describe '#reset_token!' do
- it 'persists a new token' do
+ describe "#reset_token!" do
+ it "persists a new token" do
build.save!
build.token.yield_self do |previous_token|
@@ -266,23 +266,23 @@ describe Ci::Build, 'TokenAuthenticatable' do
end
end
- describe 'setting a new token' do
- subject { build.set_token('0123456789') }
+ describe "setting a new token" do
+ subject { build.set_token("0123456789") }
- it 'returns the token' do
- expect(subject).to eq '0123456789'
+ it "returns the token" do
+ expect(subject).to eq "0123456789"
end
- it 'writes a new encrypted token' do
- expect(build.read_attribute('token_encrypted')).to be_nil
- expect(subject).to eq '0123456789'
- expect(build.read_attribute('token_encrypted')).to be_present
+ it "writes a new encrypted token" do
+ expect(build.read_attribute("token_encrypted")).to be_nil
+ expect(subject).to eq "0123456789"
+ expect(build.read_attribute("token_encrypted")).to be_present
end
- it 'does not write a new cleartext token' do
- expect(build.read_attribute('token')).to be_nil
- expect(subject).to eq '0123456789'
- expect(build.read_attribute('token')).to be_nil
+ it "does not write a new cleartext token" do
+ expect(build.read_attribute("token")).to be_nil
+ expect(subject).to eq "0123456789"
+ expect(build.read_attribute("token")).to be_nil
end
end
end
diff --git a/spec/models/concerns/token_authenticatable_strategies/base_spec.rb b/spec/models/concerns/token_authenticatable_strategies/base_spec.rb
index 6605f1f5a5f..2208c325a0b 100644
--- a/spec/models/concerns/token_authenticatable_strategies/base_spec.rb
+++ b/spec/models/concerns/token_authenticatable_strategies/base_spec.rb
@@ -1,61 +1,61 @@
-require 'spec_helper'
+require "spec_helper"
describe TokenAuthenticatableStrategies::Base do
let(:instance) { double(:instance) }
let(:field) { double(:field) }
- describe '.fabricate' do
- context 'when digest stragegy is specified' do
- it 'fabricates digest strategy object' do
+ describe ".fabricate" do
+ context "when digest stragegy is specified" do
+ it "fabricates digest strategy object" do
strategy = described_class.fabricate(instance, field, digest: true)
expect(strategy).to be_a TokenAuthenticatableStrategies::Digest
end
end
- context 'when encrypted strategy is specified' do
- it 'fabricates encrypted strategy object' do
+ context "when encrypted strategy is specified" do
+ it "fabricates encrypted strategy object" do
strategy = described_class.fabricate(instance, field, encrypted: true)
expect(strategy).to be_a TokenAuthenticatableStrategies::Encrypted
end
end
- context 'when no strategy is specified' do
- it 'fabricates insecure strategy object' do
+ context "when no strategy is specified" do
+ it "fabricates insecure strategy object" do
strategy = described_class.fabricate(instance, field, something: true)
expect(strategy).to be_a TokenAuthenticatableStrategies::Insecure
end
end
- context 'when incompatible options are provided' do
- it 'raises an error' do
+ context "when incompatible options are provided" do
+ it "raises an error" do
expect { described_class.fabricate(instance, field, digest: true, encrypted: true) }
.to raise_error ArgumentError
end
end
end
- describe '#fallback?' do
- context 'when fallback is set' do
- it 'recognizes fallback setting' do
+ describe "#fallback?" do
+ context "when fallback is set" do
+ it "recognizes fallback setting" do
strategy = described_class.new(instance, field, fallback: true)
expect(strategy.fallback?).to be true
end
end
- context 'when fallback is not a valid value' do
- it 'raises an error' do
- strategy = described_class.new(instance, field, fallback: 'something')
+ context "when fallback is not a valid value" do
+ it "raises an error" do
+ strategy = described_class.new(instance, field, fallback: "something")
expect { strategy.fallback? }.to raise_error ArgumentError
end
end
- context 'when fallback is not set' do
- it 'raises an error' do
+ context "when fallback is not set" do
+ it "raises an error" do
strategy = described_class.new(instance, field, {})
expect(strategy.fallback?).to eq false
diff --git a/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb b/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
index 93cab80cb1f..630227fe149 100644
--- a/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
+++ b/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
@@ -1,155 +1,155 @@
-require 'spec_helper'
+require "spec_helper"
describe TokenAuthenticatableStrategies::Encrypted do
let(:model) { double(:model) }
let(:instance) { double(:instance) }
let(:encrypted) do
- Gitlab::CryptoHelper.aes256_gcm_encrypt('my-value')
+ Gitlab::CryptoHelper.aes256_gcm_encrypt("my-value")
end
subject do
- described_class.new(model, 'some_field', options)
+ described_class.new(model, "some_field", options)
end
- describe '.new' do
- context 'when fallback and migration strategies are set' do
- let(:options) { { fallback: true, migrating: true } }
+ describe ".new" do
+ context "when fallback and migration strategies are set" do
+ let(:options) { {fallback: true, migrating: true} }
- it 'raises an error' do
+ it "raises an error" do
expect { subject }.to raise_error ArgumentError, /not compatible/
end
end
end
- describe '#find_token_authenticatable' do
- context 'when using fallback strategy' do
- let(:options) { { fallback: true } }
+ describe "#find_token_authenticatable" do
+ context "when using fallback strategy" do
+ let(:options) { {fallback: true} }
- it 'finds the encrypted resource by cleartext' do
+ it "finds the encrypted resource by cleartext" do
allow(model).to receive(:find_by)
- .with('some_field_encrypted' => encrypted)
- .and_return('encrypted resource')
+ .with("some_field_encrypted" => encrypted)
+ .and_return("encrypted resource")
- expect(subject.find_token_authenticatable('my-value'))
- .to eq 'encrypted resource'
+ expect(subject.find_token_authenticatable("my-value"))
+ .to eq "encrypted resource"
end
- it 'uses insecure strategy when encrypted token cannot be found' do
+ it "uses insecure strategy when encrypted token cannot be found" do
allow(subject.send(:insecure_strategy))
.to receive(:find_token_authenticatable)
- .and_return('plaintext resource')
+ .and_return("plaintext resource")
allow(model).to receive(:find_by)
- .with('some_field_encrypted' => encrypted)
+ .with("some_field_encrypted" => encrypted)
.and_return(nil)
- expect(subject.find_token_authenticatable('my-value'))
- .to eq 'plaintext resource'
+ expect(subject.find_token_authenticatable("my-value"))
+ .to eq "plaintext resource"
end
end
- context 'when using migration strategy' do
- let(:options) { { migrating: true } }
+ context "when using migration strategy" do
+ let(:options) { {migrating: true} }
- it 'finds the cleartext resource by cleartext' do
+ it "finds the cleartext resource by cleartext" do
allow(model).to receive(:find_by)
- .with('some_field' => 'my-value')
- .and_return('cleartext resource')
+ .with("some_field" => "my-value")
+ .and_return("cleartext resource")
- expect(subject.find_token_authenticatable('my-value'))
- .to eq 'cleartext resource'
+ expect(subject.find_token_authenticatable("my-value"))
+ .to eq "cleartext resource"
end
- it 'returns nil if resource cannot be found' do
+ it "returns nil if resource cannot be found" do
allow(model).to receive(:find_by)
- .with('some_field' => 'my-value')
+ .with("some_field" => "my-value")
.and_return(nil)
- expect(subject.find_token_authenticatable('my-value'))
+ expect(subject.find_token_authenticatable("my-value"))
.to be_nil
end
end
end
- describe '#get_token' do
- context 'when using fallback strategy' do
- let(:options) { { fallback: true } }
+ describe "#get_token" do
+ context "when using fallback strategy" do
+ let(:options) { {fallback: true} }
- it 'returns decrypted token when an encrypted token is present' do
+ it "returns decrypted token when an encrypted token is present" do
allow(instance).to receive(:read_attribute)
- .with('some_field_encrypted')
+ .with("some_field_encrypted")
.and_return(encrypted)
- expect(subject.get_token(instance)).to eq 'my-value'
+ expect(subject.get_token(instance)).to eq "my-value"
end
- it 'returns the plaintext token when encrypted token is not present' do
+ it "returns the plaintext token when encrypted token is not present" do
allow(instance).to receive(:read_attribute)
- .with('some_field_encrypted')
+ .with("some_field_encrypted")
.and_return(nil)
allow(instance).to receive(:read_attribute)
- .with('some_field')
- .and_return('cleartext value')
+ .with("some_field")
+ .and_return("cleartext value")
- expect(subject.get_token(instance)).to eq 'cleartext value'
+ expect(subject.get_token(instance)).to eq "cleartext value"
end
end
- context 'when using migration strategy' do
- let(:options) { { migrating: true } }
+ context "when using migration strategy" do
+ let(:options) { {migrating: true} }
- it 'returns cleartext token when an encrypted token is present' do
+ it "returns cleartext token when an encrypted token is present" do
allow(instance).to receive(:read_attribute)
- .with('some_field_encrypted')
+ .with("some_field_encrypted")
.and_return(encrypted)
allow(instance).to receive(:read_attribute)
- .with('some_field')
- .and_return('my-cleartext-value')
+ .with("some_field")
+ .and_return("my-cleartext-value")
- expect(subject.get_token(instance)).to eq 'my-cleartext-value'
+ expect(subject.get_token(instance)).to eq "my-cleartext-value"
end
- it 'returns the cleartext token when encrypted token is not present' do
+ it "returns the cleartext token when encrypted token is not present" do
allow(instance).to receive(:read_attribute)
- .with('some_field_encrypted')
+ .with("some_field_encrypted")
.and_return(nil)
allow(instance).to receive(:read_attribute)
- .with('some_field')
- .and_return('cleartext value')
+ .with("some_field")
+ .and_return("cleartext value")
- expect(subject.get_token(instance)).to eq 'cleartext value'
+ expect(subject.get_token(instance)).to eq "cleartext value"
end
end
end
- describe '#set_token' do
- context 'when using fallback strategy' do
- let(:options) { { fallback: true } }
+ describe "#set_token" do
+ context "when using fallback strategy" do
+ let(:options) { {fallback: true} }
- it 'writes encrypted token and removes plaintext token and returns it' do
+ it "writes encrypted token and removes plaintext token and returns it" do
expect(instance).to receive(:[]=)
- .with('some_field_encrypted', encrypted)
+ .with("some_field_encrypted", encrypted)
expect(instance).to receive(:[]=)
- .with('some_field', nil)
+ .with("some_field", nil)
- expect(subject.set_token(instance, 'my-value')).to eq 'my-value'
+ expect(subject.set_token(instance, "my-value")).to eq "my-value"
end
end
- context 'when using migration strategy' do
- let(:options) { { migrating: true } }
+ context "when using migration strategy" do
+ let(:options) { {migrating: true} }
- it 'writes encrypted token and writes plaintext token' do
+ it "writes encrypted token and writes plaintext token" do
expect(instance).to receive(:[]=)
- .with('some_field_encrypted', encrypted)
+ .with("some_field_encrypted", encrypted)
expect(instance).to receive(:[]=)
- .with('some_field', 'my-value')
+ .with("some_field", "my-value")
- expect(subject.set_token(instance, 'my-value')).to eq 'my-value'
+ expect(subject.set_token(instance, "my-value")).to eq "my-value"
end
end
end
diff --git a/spec/models/concerns/triggerable_hooks_spec.rb b/spec/models/concerns/triggerable_hooks_spec.rb
index 265abd6bd72..15eb162e89b 100644
--- a/spec/models/concerns/triggerable_hooks_spec.rb
+++ b/spec/models/concerns/triggerable_hooks_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
RSpec.describe TriggerableHooks do
before do
@@ -8,43 +8,43 @@ RSpec.describe TriggerableHooks do
end
end
- describe 'scopes' do
- it 'defines a scope for each of the requested triggers' do
+ describe "scopes" do
+ it "defines a scope for each of the requested triggers" do
expect(TestableHook).to respond_to :push_hooks
expect(TestableHook).not_to respond_to :tag_push_hooks
end
end
- describe '.hooks_for' do
- context 'the model has the required trigger scope' do
- it 'returns the record' do
- hook = TestableHook.create!(url: 'http://example.com', push_events: true)
+ describe ".hooks_for" do
+ context "the model has the required trigger scope" do
+ it "returns the record" do
+ hook = TestableHook.create!(url: "http://example.com", push_events: true)
expect(TestableHook.hooks_for(:push_hooks)).to eq [hook]
end
end
- context 'the model does not have the required trigger scope' do
- it 'returns an empty relation' do
- TestableHook.create!(url: 'http://example.com')
+ context "the model does not have the required trigger scope" do
+ it "returns an empty relation" do
+ TestableHook.create!(url: "http://example.com")
expect(TestableHook.hooks_for(:tag_push_hooks)).to eq []
end
end
context 'the stock scope ".all" is accepted' do
- it 'returns the record' do
- hook = TestableHook.create!(url: 'http://example.com')
+ it "returns the record" do
+ hook = TestableHook.create!(url: "http://example.com")
expect(TestableHook.hooks_for(:all)).to eq [hook]
end
end
end
- describe '.select_active' do
- it 'returns hooks that match the active filter' do
- TestableHook.create!(url: 'http://example1.com', push_events: true)
- TestableHook.create!(url: 'http://example2.com', push_events: true)
+ describe ".select_active" do
+ it "returns hooks that match the active filter" do
+ TestableHook.create!(url: "http://example1.com", push_events: true)
+ TestableHook.create!(url: "http://example2.com", push_events: true)
filter1 = double(:filter1)
filter2 = double(:filter2)
allow(ActiveHookFilter).to receive(:new).exactly(2).times.and_return(filter1, filter2)
@@ -55,8 +55,8 @@ RSpec.describe TriggerableHooks do
expect(hooks.select_active(:push_hooks, {})).to eq [hooks.first]
end
- it 'returns empty list if no hooks match the active filter' do
- TestableHook.create!(url: 'http://example1.com', push_events: true)
+ it "returns empty list if no hooks match the active filter" do
+ TestableHook.create!(url: "http://example1.com", push_events: true)
filter = double(:filter)
allow(ActiveHookFilter).to receive(:new).and_return(filter)
expect(filter).to receive(:matches?).and_return(false)
diff --git a/spec/models/concerns/uniquify_spec.rb b/spec/models/concerns/uniquify_spec.rb
index 6cd2de6dcce..0da6f5a4d0d 100644
--- a/spec/models/concerns/uniquify_spec.rb
+++ b/spec/models/concerns/uniquify_spec.rb
@@ -1,42 +1,42 @@
-require 'spec_helper'
+require "spec_helper"
describe Uniquify do
let(:uniquify) { described_class.new }
describe "#string" do
- it 'returns the given string if it does not exist' do
- result = uniquify.string('test_string') { |s| false }
+ it "returns the given string if it does not exist" do
+ result = uniquify.string("test_string") { |s| false }
- expect(result).to eq('test_string')
+ expect(result).to eq("test_string")
end
- it 'returns the given string with a counter attached if the string exists' do
- result = uniquify.string('test_string') { |s| s == 'test_string' }
+ it "returns the given string with a counter attached if the string exists" do
+ result = uniquify.string("test_string") { |s| s == "test_string" }
- expect(result).to eq('test_string1')
+ expect(result).to eq("test_string1")
end
- it 'increments the counter for each candidate string that also exists' do
- result = uniquify.string('test_string') { |s| s == 'test_string' || s == 'test_string1' }
+ it "increments the counter for each candidate string that also exists" do
+ result = uniquify.string("test_string") { |s| s == "test_string" || s == "test_string1" }
- expect(result).to eq('test_string2')
+ expect(result).to eq("test_string2")
end
- it 'allows to pass an initial value for the counter' do
+ it "allows to pass an initial value for the counter" do
start_counting_from = 2
uniquify = described_class.new(start_counting_from)
- result = uniquify.string('test_string') { |s| s == 'test_string' }
+ result = uniquify.string("test_string") { |s| s == "test_string" }
- expect(result).to eq('test_string2')
+ expect(result).to eq("test_string2")
end
- it 'allows passing in a base function that defines the location of the counter' do
- result = uniquify.string(-> (counter) { "test_#{counter}_string" }) do |s|
- s == 'test__string'
- end
+ it "allows passing in a base function that defines the location of the counter" do
+ result = uniquify.string(->(counter) { "test_#{counter}_string" }) { |s|
+ s == "test__string"
+ }
- expect(result).to eq('test_1_string')
+ expect(result).to eq("test_1_string")
end
end
end
diff --git a/spec/models/container_repository_spec.rb b/spec/models/container_repository_spec.rb
index e46945e301e..818a5f73468 100644
--- a/spec/models/container_repository_spec.rb
+++ b/spec/models/container_repository_spec.rb
@@ -1,87 +1,88 @@
-require 'spec_helper'
+require "spec_helper"
describe ContainerRepository do
- let(:group) { create(:group, name: 'group') }
- let(:project) { create(:project, path: 'test', group: group) }
+ let(:group) { create(:group, name: "group") }
+ let(:project) { create(:project, path: "test", group: group) }
let(:repository) do
- create(:container_repository, name: 'my_image', project: project)
+ create(:container_repository, name: "my_image", project: project)
end
before do
stub_container_registry_config(enabled: true,
- api_url: 'http://registry.gitlab',
- host_port: 'registry.gitlab')
+ api_url: "http://registry.gitlab",
+ host_port: "registry.gitlab")
- stub_request(:get, 'http://registry.gitlab/v2/group/test/my_image/tags/list')
- .with(headers: { 'Accept' => 'application/vnd.docker.distribution.manifest.v2+json' })
+ stub_request(:get, "http://registry.gitlab/v2/group/test/my_image/tags/list")
+ .with(headers: {"Accept" => "application/vnd.docker.distribution.manifest.v2+json"})
.to_return(
status: 200,
- body: JSON.dump(tags: ['test_tag']),
- headers: { 'Content-Type' => 'application/json' })
+ body: JSON.dump(tags: ["test_tag"]),
+ headers: {"Content-Type" => "application/json"}
+ )
end
- describe 'associations' do
- it 'belongs to the project' do
+ describe "associations" do
+ it "belongs to the project" do
expect(repository).to belong_to(:project)
end
end
- describe '#tag' do
- it 'has a test tag' do
- expect(repository.tag('test')).not_to be_nil
+ describe "#tag" do
+ it "has a test tag" do
+ expect(repository.tag("test")).not_to be_nil
end
end
- describe '#path' do
- context 'when project path does not contain uppercase letters' do
- it 'returns a full path to the repository' do
- expect(repository.path).to eq('group/test/my_image')
+ describe "#path" do
+ context "when project path does not contain uppercase letters" do
+ it "returns a full path to the repository" do
+ expect(repository.path).to eq("group/test/my_image")
end
end
- context 'when path contains uppercase letters' do
- let(:project) { create(:project, :repository, path: 'MY_PROJECT', group: group) }
+ context "when path contains uppercase letters" do
+ let(:project) { create(:project, :repository, path: "MY_PROJECT", group: group) }
- it 'returns a full path without capital letters' do
- expect(repository.path).to eq('group/my_project/my_image')
+ it "returns a full path without capital letters" do
+ expect(repository.path).to eq("group/my_project/my_image")
end
end
end
- describe '#manifest' do
- it 'returns non-empty manifest' do
+ describe "#manifest" do
+ it "returns non-empty manifest" do
expect(repository.manifest).not_to be_nil
end
end
- describe '#valid?' do
- it 'is a valid repository' do
+ describe "#valid?" do
+ it "is a valid repository" do
expect(repository).to be_valid
end
end
- describe '#tags' do
- it 'returns non-empty tags list' do
+ describe "#tags" do
+ it "returns non-empty tags list" do
expect(repository.tags).not_to be_empty
end
end
- describe '#has_tags?' do
- it 'has tags' do
+ describe "#has_tags?" do
+ it "has tags" do
expect(repository).to have_tags
end
end
- describe '#delete_tags!' do
+ describe "#delete_tags!" do
let(:repository) do
- create(:container_repository, name: 'my_image',
+ create(:container_repository, name: "my_image",
tags: %w[latest rc1],
project: project)
end
- context 'when action succeeds' do
- it 'returns status that indicates success' do
+ context "when action succeeds" do
+ it "returns status that indicates success" do
expect(repository.client)
.to receive(:delete_repository_tag)
.and_return(true)
@@ -90,8 +91,8 @@ describe ContainerRepository do
end
end
- context 'when action fails' do
- it 'returns status that indicates failure' do
+ context "when action fails" do
+ it "returns status that indicates failure" do
expect(repository.client)
.to receive(:delete_repository_tag)
.and_return(false)
@@ -101,133 +102,134 @@ describe ContainerRepository do
end
end
- describe '#location' do
- context 'when registry is running on a custom port' do
+ describe "#location" do
+ context "when registry is running on a custom port" do
before do
stub_container_registry_config(enabled: true,
- api_url: 'http://registry.gitlab:5000',
- host_port: 'registry.gitlab:5000')
+ api_url: "http://registry.gitlab:5000",
+ host_port: "registry.gitlab:5000")
end
- it 'returns a full location of the repository' do
+ it "returns a full location of the repository" do
expect(repository.location)
- .to eq 'registry.gitlab:5000/group/test/my_image'
+ .to eq "registry.gitlab:5000/group/test/my_image"
end
end
end
- describe '#root_repository?' do
- context 'when repository is a root repository' do
+ describe "#root_repository?" do
+ context "when repository is a root repository" do
let(:repository) { create(:container_repository, :root) }
- it 'returns true' do
+ it "returns true" do
expect(repository).to be_root_repository
end
end
- context 'when repository is not a root repository' do
- it 'returns false' do
+ context "when repository is not a root repository" do
+ it "returns false" do
expect(repository).not_to be_root_repository
end
end
end
- describe '.build_from_path' do
+ describe ".build_from_path" do
let(:registry_path) do
- ContainerRegistry::Path.new(project.full_path + '/some/image')
+ ContainerRegistry::Path.new(project.full_path + "/some/image")
end
let(:repository) do
described_class.build_from_path(registry_path)
end
- it 'fabricates repository assigned to a correct project' do
+ it "fabricates repository assigned to a correct project" do
expect(repository.project).to eq project
end
- it 'fabricates repository with a correct name' do
- expect(repository.name).to eq 'some/image'
+ it "fabricates repository with a correct name" do
+ expect(repository.name).to eq "some/image"
end
- it 'is not persisted' do
+ it "is not persisted" do
expect(repository).not_to be_persisted
end
end
- describe '.create_from_path!' do
+ describe ".create_from_path!" do
let(:repository) do
described_class.create_from_path!(ContainerRegistry::Path.new(path))
end
let(:repository_path) { ContainerRegistry::Path.new(path) }
- context 'when received multi-level repository path' do
- let(:path) { project.full_path + '/some/image' }
+ context "when received multi-level repository path" do
+ let(:path) { project.full_path + "/some/image" }
- it 'fabricates repository assigned to a correct project' do
+ it "fabricates repository assigned to a correct project" do
expect(repository.project).to eq project
end
- it 'fabricates repository with a correct name' do
- expect(repository.name).to eq 'some/image'
+ it "fabricates repository with a correct name" do
+ expect(repository.name).to eq "some/image"
end
end
- context 'when path is too long' do
+ context "when path is too long" do
let(:path) do
- project.full_path + '/a/b/c/d/e/f/g/h/i/j/k/l/n/o/p/s/t/u/x/y/z'
+ project.full_path + "/a/b/c/d/e/f/g/h/i/j/k/l/n/o/p/s/t/u/x/y/z"
end
- it 'does not create repository and raises error' do
+ it "does not create repository and raises error" do
expect { repository }.to raise_error(
- ContainerRegistry::Path::InvalidRegistryPathError)
+ ContainerRegistry::Path::InvalidRegistryPathError
+ )
end
end
- context 'when received multi-level repository with nested groups' do
- let(:group) { create(:group, :nested, name: 'nested') }
- let(:path) { project.full_path + '/some/image' }
+ context "when received multi-level repository with nested groups" do
+ let(:group) { create(:group, :nested, name: "nested") }
+ let(:path) { project.full_path + "/some/image" }
- it 'fabricates repository assigned to a correct project' do
+ it "fabricates repository assigned to a correct project" do
expect(repository.project).to eq project
end
- it 'fabricates repository with a correct name' do
- expect(repository.name).to eq 'some/image'
+ it "fabricates repository with a correct name" do
+ expect(repository.name).to eq "some/image"
end
- it 'has path including a nested group' do
- expect(repository.path).to include 'nested/test/some/image'
+ it "has path including a nested group" do
+ expect(repository.path).to include "nested/test/some/image"
end
end
- context 'when received root repository path' do
+ context "when received root repository path" do
let(:path) { project.full_path }
- it 'fabricates repository assigned to a correct project' do
+ it "fabricates repository assigned to a correct project" do
expect(repository.project).to eq project
end
- it 'fabricates repository with an empty name' do
+ it "fabricates repository with an empty name" do
expect(repository.name).to be_empty
end
end
end
- describe '.build_root_repository' do
+ describe ".build_root_repository" do
let(:repository) do
described_class.build_root_repository(project)
end
- it 'fabricates a root repository object' do
+ it "fabricates a root repository object" do
expect(repository).to be_root_repository
end
- it 'assignes it to the correct project' do
+ it "assignes it to the correct project" do
expect(repository.project).to eq project
end
- it 'does not persist it' do
+ it "does not persist it" do
expect(repository).not_to be_persisted
end
end
diff --git a/spec/models/conversational_development_index/metric_spec.rb b/spec/models/conversational_development_index/metric_spec.rb
index b3193619503..63c3c416232 100644
--- a/spec/models/conversational_development_index/metric_spec.rb
+++ b/spec/models/conversational_development_index/metric_spec.rb
@@ -1,11 +1,11 @@
-require 'rails_helper'
+require "rails_helper"
describe ConversationalDevelopmentIndex::Metric do
let(:conv_dev_index) { create(:conversational_development_index_metric) }
- describe '#percentage_score' do
- it 'returns stored percentage score' do
- expect(conv_dev_index.percentage_score('issues')).to eq(13.331)
+ describe "#percentage_score" do
+ it "returns stored percentage score" do
+ expect(conv_dev_index.percentage_score("issues")).to eq(13.331)
end
end
end
diff --git a/spec/models/cycle_analytics/code_spec.rb b/spec/models/cycle_analytics/code_spec.rb
index 6a6b58fb52b..49f473eefd2 100644
--- a/spec/models/cycle_analytics/code_spec.rb
+++ b/spec/models/cycle_analytics/code_spec.rb
@@ -1,6 +1,6 @@
-require 'spec_helper'
+require "spec_helper"
-describe 'CycleAnalytics#code' do
+describe "CycleAnalytics#code" do
extend CycleAnalyticsHelpers::TestGeneration
let(:project) { create(:project, :repository) }
@@ -8,22 +8,23 @@ describe 'CycleAnalytics#code' do
let(:user) { create(:user, :admin) }
subject { CycleAnalytics.new(project, from: from_date) }
- context 'with deployment' do
+ context "with deployment" do
generate_cycle_analytics_spec(
phase: :code,
- data_fn: -> (context) { { issue: context.create(:issue, project: context.project) } },
+ data_fn: ->(context) { {issue: context.create(:issue, project: context.project)} },
start_time_conditions: [["issue mentioned in a commit",
- -> (context, data) do
+ ->(context, data) do
context.create_commit_referencing_issue(data[:issue])
- end]],
+ end,]],
end_time_conditions: [["merge request that closes issue is created",
- -> (context, data) do
+ ->(context, data) do
context.create_merge_request_closing_issue(context.user, context.project, data[:issue])
- end]],
- post_fn: -> (context, data) do
+ end,]],
+ post_fn: ->(context, data) do
context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue])
context.deploy_master(context.user, context.project)
- end)
+ end
+ )
context "when a regular merge request (that doesn't close the issue) is created" do
it "returns nil" do
@@ -40,21 +41,22 @@ describe 'CycleAnalytics#code' do
end
end
- context 'without deployment' do
+ context "without deployment" do
generate_cycle_analytics_spec(
phase: :code,
- data_fn: -> (context) { { issue: context.create(:issue, project: context.project) } },
+ data_fn: ->(context) { {issue: context.create(:issue, project: context.project)} },
start_time_conditions: [["issue mentioned in a commit",
- -> (context, data) do
+ ->(context, data) do
context.create_commit_referencing_issue(data[:issue])
- end]],
+ end,]],
end_time_conditions: [["merge request that closes issue is created",
- -> (context, data) do
+ ->(context, data) do
context.create_merge_request_closing_issue(context.user, context.project, data[:issue])
- end]],
- post_fn: -> (context, data) do
+ end,]],
+ post_fn: ->(context, data) do
context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue])
- end)
+ end
+ )
context "when a regular merge request (that doesn't close the issue) is created" do
it "returns nil" do
diff --git a/spec/models/cycle_analytics/issue_spec.rb b/spec/models/cycle_analytics/issue_spec.rb
index 45f1b4fe8a3..fd2b02d8e5d 100644
--- a/spec/models/cycle_analytics/issue_spec.rb
+++ b/spec/models/cycle_analytics/issue_spec.rb
@@ -1,6 +1,6 @@
-require 'spec_helper'
+require "spec_helper"
-describe 'CycleAnalytics#issue' do
+describe "CycleAnalytics#issue" do
extend CycleAnalyticsHelpers::TestGeneration
let(:project) { create(:project, :repository) }
@@ -10,26 +10,27 @@ describe 'CycleAnalytics#issue' do
generate_cycle_analytics_spec(
phase: :issue,
- data_fn: -> (context) { { issue: context.build(:issue, project: context.project) } },
- start_time_conditions: [["issue created", -> (context, data) { data[:issue].save }]],
- end_time_conditions: [["issue associated with a milestone",
- -> (context, data) do
- if data[:issue].persisted?
- data[:issue].update(milestone: context.create(:milestone, project: context.project))
- end
- end],
- ["list label added to issue",
- -> (context, data) do
- if data[:issue].persisted?
- data[:issue].update(label_ids: [context.create(:label, lists: [context.create(:list)]).id])
- end
- end]],
- post_fn: -> (context, data) do
+ data_fn: ->(context) { {issue: context.build(:issue, project: context.project)} },
+ start_time_conditions: [["issue created", ->(context, data) { data[:issue].save }]],
+ end_time_conditions: [["issue associated with a milestone",
+ ->(context, data) do
+ if data[:issue].persisted?
+ data[:issue].update(milestone: context.create(:milestone, project: context.project))
+ end
+ end,],
+ ["list label added to issue",
+ ->(context, data) do
+ if data[:issue].persisted?
+ data[:issue].update(label_ids: [context.create(:label, lists: [context.create(:list)]).id])
+ end
+ end,],],
+ post_fn: ->(context, data) do
if data[:issue].persisted?
context.create_merge_request_closing_issue(context.user, context.project, data[:issue].reload)
context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue])
end
- end)
+ end
+ )
context "when a regular label (instead of a list label) is added to the issue" do
it "returns nil" do
diff --git a/spec/models/cycle_analytics/plan_spec.rb b/spec/models/cycle_analytics/plan_spec.rb
index d366e2b723a..f836691c75a 100644
--- a/spec/models/cycle_analytics/plan_spec.rb
+++ b/spec/models/cycle_analytics/plan_spec.rb
@@ -1,6 +1,6 @@
-require 'spec_helper'
+require "spec_helper"
-describe 'CycleAnalytics#plan' do
+describe "CycleAnalytics#plan" do
extend CycleAnalyticsHelpers::TestGeneration
let(:project) { create(:project, :repository) }
@@ -10,28 +10,29 @@ describe 'CycleAnalytics#plan' do
generate_cycle_analytics_spec(
phase: :plan,
- data_fn: -> (context) do
+ data_fn: ->(context) do
{
issue: context.create(:issue, project: context.project),
- branch_name: context.generate(:branch)
+ branch_name: context.generate(:branch),
}
end,
start_time_conditions: [["issue associated with a milestone",
- -> (context, data) do
+ ->(context, data) do
data[:issue].update(milestone: context.create(:milestone, project: context.project))
- end],
+ end,],
["list label added to issue",
- -> (context, data) do
+ ->(context, data) do
data[:issue].update(label_ids: [context.create(:label, lists: [context.create(:list)]).id])
- end]],
- end_time_conditions: [["issue mentioned in a commit",
- -> (context, data) do
- context.create_commit_referencing_issue(data[:issue], branch_name: data[:branch_name])
- end]],
- post_fn: -> (context, data) do
+ end,],],
+ end_time_conditions: [["issue mentioned in a commit",
+ ->(context, data) do
+ context.create_commit_referencing_issue(data[:issue], branch_name: data[:branch_name])
+ end,]],
+ post_fn: ->(context, data) do
context.create_merge_request_closing_issue(context.user, context.project, data[:issue], source_branch: data[:branch_name])
context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue])
- end)
+ end
+ )
context "when a regular label (instead of a list label) is added to the issue" do
it "returns nil" do
diff --git a/spec/models/cycle_analytics/production_spec.rb b/spec/models/cycle_analytics/production_spec.rb
index 156eb96cfce..51e1d1cefcb 100644
--- a/spec/models/cycle_analytics/production_spec.rb
+++ b/spec/models/cycle_analytics/production_spec.rb
@@ -1,6 +1,6 @@
-require 'spec_helper'
+require "spec_helper"
-describe 'CycleAnalytics#production' do
+describe "CycleAnalytics#production" do
extend CycleAnalyticsHelpers::TestGeneration
let(:project) { create(:project, :repository) }
@@ -10,27 +10,29 @@ describe 'CycleAnalytics#production' do
generate_cycle_analytics_spec(
phase: :production,
- data_fn: -> (context) { { issue: context.build(:issue, project: context.project) } },
- start_time_conditions: [["issue is created", -> (context, data) { data[:issue].save }]],
+ data_fn: ->(context) { {issue: context.build(:issue, project: context.project)} },
+ start_time_conditions: [["issue is created", ->(context, data) { data[:issue].save }]],
before_end_fn: lambda do |context, data|
context.create_merge_request_closing_issue(context.user, context.project, data[:issue])
context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue])
end,
end_time_conditions:
- [["merge request that closes issue is deployed to production", -> (context, data) { context.deploy_master(context.user, context.project) }],
+ [["merge request that closes issue is deployed to production", ->(context, data) { context.deploy_master(context.user, context.project) }],
["production deploy happens after merge request is merged (along with other changes)",
lambda do |context, data|
# Make other changes on master
sha = context.project.repository.create_file(
context.user,
context.generate(:branch),
- 'content',
- message: 'commit message',
- branch_name: 'master')
+ "content",
+ message: "commit message",
+ branch_name: "master"
+ )
context.project.repository.commit(sha)
context.deploy_master(context.user, context.project)
- end]])
+ end,],]
+ )
context "when a regular merge request (that doesn't close the issue) is merged and deployed" do
it "returns nil" do
@@ -47,7 +49,7 @@ describe 'CycleAnalytics#production' do
issue = create(:issue, project: project)
merge_request = create_merge_request_closing_issue(user, project, issue)
MergeRequests::MergeService.new(project, user).execute(merge_request)
- deploy_master(user, project, environment: 'staging')
+ deploy_master(user, project, environment: "staging")
expect(subject[:production].median).to be_nil
end
diff --git a/spec/models/cycle_analytics/review_spec.rb b/spec/models/cycle_analytics/review_spec.rb
index 0aedfb49cb5..359f47dc820 100644
--- a/spec/models/cycle_analytics/review_spec.rb
+++ b/spec/models/cycle_analytics/review_spec.rb
@@ -1,6 +1,6 @@
-require 'spec_helper'
+require "spec_helper"
-describe 'CycleAnalytics#review' do
+describe "CycleAnalytics#review" do
extend CycleAnalyticsHelpers::TestGeneration
let(:project) { create(:project, :repository) }
@@ -10,16 +10,17 @@ describe 'CycleAnalytics#review' do
generate_cycle_analytics_spec(
phase: :review,
- data_fn: -> (context) { { issue: context.create(:issue, project: context.project) } },
+ data_fn: ->(context) { {issue: context.create(:issue, project: context.project)} },
start_time_conditions: [["merge request that closes issue is created",
- -> (context, data) do
+ ->(context, data) do
context.create_merge_request_closing_issue(context.user, context.project, data[:issue])
- end]],
- end_time_conditions: [["merge request that closes issue is merged",
- -> (context, data) do
- context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue])
- end]],
- post_fn: nil)
+ end,]],
+ end_time_conditions: [["merge request that closes issue is merged",
+ ->(context, data) do
+ context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue])
+ end,]],
+ post_fn: nil
+ )
context "when a regular merge request (that doesn't close the issue) is created and merged" do
it "returns nil" do
diff --git a/spec/models/cycle_analytics/staging_spec.rb b/spec/models/cycle_analytics/staging_spec.rb
index 0cbda50c688..813cef5e079 100644
--- a/spec/models/cycle_analytics/staging_spec.rb
+++ b/spec/models/cycle_analytics/staging_spec.rb
@@ -1,6 +1,6 @@
-require 'spec_helper'
+require "spec_helper"
-describe 'CycleAnalytics#staging' do
+describe "CycleAnalytics#staging" do
extend CycleAnalyticsHelpers::TestGeneration
let(:project) { create(:project, :repository) }
@@ -13,29 +13,31 @@ describe 'CycleAnalytics#staging' do
phase: :staging,
data_fn: lambda do |context|
issue = context.create(:issue, project: context.project)
- { issue: issue, merge_request: context.create_merge_request_closing_issue(context.user, context.project, issue) }
+ {issue: issue, merge_request: context.create_merge_request_closing_issue(context.user, context.project, issue)}
end,
start_time_conditions: [["merge request that closes issue is merged",
- -> (context, data) do
+ ->(context, data) do
context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue])
- end]],
- end_time_conditions: [["merge request that closes issue is deployed to production",
- -> (context, data) do
- context.deploy_master(context.user, context.project)
- end],
- ["production deploy happens after merge request is merged (along with other changes)",
- lambda do |context, data|
- # Make other changes on master
- sha = context.project.repository.create_file(
- context.user,
- context.generate(:branch),
- 'content',
- message: 'commit message',
- branch_name: 'master')
- context.project.repository.commit(sha)
-
- context.deploy_master(context.user, context.project)
- end]])
+ end,]],
+ end_time_conditions: [["merge request that closes issue is deployed to production",
+ ->(context, data) do
+ context.deploy_master(context.user, context.project)
+ end,],
+ ["production deploy happens after merge request is merged (along with other changes)",
+ lambda do |context, data|
+ # Make other changes on master
+ sha = context.project.repository.create_file(
+ context.user,
+ context.generate(:branch),
+ "content",
+ message: "commit message",
+ branch_name: "master"
+ )
+ context.project.repository.commit(sha)
+
+ context.deploy_master(context.user, context.project)
+ end,],]
+ )
context "when a regular merge request (that doesn't close the issue) is merged and deployed" do
it "returns nil" do
@@ -52,7 +54,7 @@ describe 'CycleAnalytics#staging' do
issue = create(:issue, project: project)
merge_request = create_merge_request_closing_issue(user, project, issue)
MergeRequests::MergeService.new(project, user).execute(merge_request)
- deploy_master(user, project, environment: 'staging')
+ deploy_master(user, project, environment: "staging")
expect(subject[:staging].median).to be_nil
end
diff --git a/spec/models/cycle_analytics/test_spec.rb b/spec/models/cycle_analytics/test_spec.rb
index e58b8fdff58..5b2ea41396b 100644
--- a/spec/models/cycle_analytics/test_spec.rb
+++ b/spec/models/cycle_analytics/test_spec.rb
@@ -1,6 +1,6 @@
-require 'spec_helper'
+require "spec_helper"
-describe 'CycleAnalytics#test' do
+describe "CycleAnalytics#test" do
extend CycleAnalyticsHelpers::TestGeneration
let(:project) { create(:project, :repository) }
@@ -14,13 +14,14 @@ describe 'CycleAnalytics#test' do
issue = context.create(:issue, project: context.project)
merge_request = context.create_merge_request_closing_issue(context.user, context.project, issue)
pipeline = context.create(:ci_pipeline, ref: merge_request.source_branch, sha: merge_request.diff_head_sha, project: context.project, head_pipeline_of: merge_request)
- { pipeline: pipeline, issue: issue }
+ {pipeline: pipeline, issue: issue}
end,
- start_time_conditions: [["pipeline is started", -> (context, data) { data[:pipeline].run! }]],
- end_time_conditions: [["pipeline is finished", -> (context, data) { data[:pipeline].succeed! }]],
- post_fn: -> (context, data) do
+ start_time_conditions: [["pipeline is started", ->(context, data) { data[:pipeline].run! }]],
+ end_time_conditions: [["pipeline is finished", ->(context, data) { data[:pipeline].succeed! }]],
+ post_fn: ->(context, data) do
context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue])
- end)
+ end
+ )
context "when the pipeline is for a regular merge request (that doesn't close an issue)" do
it "returns nil" do
@@ -39,7 +40,7 @@ describe 'CycleAnalytics#test' do
context "when the pipeline is not for a merge request" do
it "returns nil" do
- pipeline = create(:ci_pipeline, ref: "refs/heads/master", sha: project.repository.commit('master').sha)
+ pipeline = create(:ci_pipeline, ref: "refs/heads/master", sha: project.repository.commit("master").sha)
pipeline.run!
pipeline.succeed!
diff --git a/spec/models/cycle_analytics_spec.rb b/spec/models/cycle_analytics_spec.rb
index 0fe24870f02..e5ec4a11ff1 100644
--- a/spec/models/cycle_analytics_spec.rb
+++ b/spec/models/cycle_analytics_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe CycleAnalytics do
let(:project) { create(:project, :repository) }
@@ -7,11 +7,11 @@ describe CycleAnalytics do
let(:issue) { create(:issue, project: project, created_at: 2.days.ago) }
let(:milestone) { create(:milestone, project: project) }
let(:mr) { create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") }
- let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) }
+ let(:pipeline) { create(:ci_empty_pipeline, status: "created", project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) }
subject { described_class.new(project, from: from_date) }
- describe '#all_medians_per_stage' do
+ describe "#all_medians_per_stage" do
before do
allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue])
@@ -19,10 +19,10 @@ describe CycleAnalytics do
deploy_master(user, project)
end
- it 'returns every median for each stage for a specific project' do
- values = described_class::STAGES.each_with_object({}) do |stage_name, hsh|
+ it "returns every median for each stage for a specific project" do
+ values = described_class::STAGES.each_with_object({}) { |stage_name, hsh|
hsh[stage_name] = subject[stage_name].median.presence
- end
+ }
expect(subject.all_medians_per_stage).to eq(values)
end
diff --git a/spec/models/deploy_key_spec.rb b/spec/models/deploy_key_spec.rb
index 41440c6d288..d03a3c051eb 100644
--- a/spec/models/deploy_key_spec.rb
+++ b/spec/models/deploy_key_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe DeployKey, :mailer do
describe "Associations" do
@@ -6,10 +6,10 @@ describe DeployKey, :mailer do
it { is_expected.to have_many(:projects) }
end
- describe 'notification' do
+ describe "notification" do
let(:user) { create(:user) }
- it 'does not send a notification' do
+ it "does not send a notification" do
perform_enqueued_jobs do
create(:deploy_key, user: user)
end
@@ -18,22 +18,22 @@ describe DeployKey, :mailer do
end
end
- describe '#user' do
+ describe "#user" do
let(:deploy_key) { create(:deploy_key) }
let(:user) { create(:user) }
- context 'when user is set' do
+ context "when user is set" do
before do
deploy_key.user = user
end
- it 'returns the user' do
+ it "returns the user" do
expect(deploy_key.user).to be(user)
end
end
- context 'when user is not set' do
- it 'returns the ghost user' do
+ context "when user is not set" do
+ it "returns the ghost user" do
expect(deploy_key.user).to eq(User.ghost)
end
end
diff --git a/spec/models/deploy_keys_project_spec.rb b/spec/models/deploy_keys_project_spec.rb
index fca3090ff4a..45fc8cfb128 100644
--- a/spec/models/deploy_keys_project_spec.rb
+++ b/spec/models/deploy_keys_project_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe DeployKeysProject do
describe "Associations" do
diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb
index 3435f93c999..06712fdccb2 100644
--- a/spec/models/deploy_token_spec.rb
+++ b/spec/models/deploy_token_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe DeployToken do
subject(:deploy_token) { create(:deploy_token) }
@@ -6,8 +6,8 @@ describe DeployToken do
it { is_expected.to have_many :project_deploy_tokens }
it { is_expected.to have_many(:projects).through(:project_deploy_tokens) }
- describe '#ensure_token' do
- it 'should ensure a token' do
+ describe "#ensure_token" do
+ it "should ensure a token" do
deploy_token.token = nil
deploy_token.save
@@ -15,15 +15,15 @@ describe DeployToken do
end
end
- describe '#ensure_at_least_one_scope' do
- context 'with at least one scope' do
- it 'should be valid' do
+ describe "#ensure_at_least_one_scope" do
+ context "with at least one scope" do
+ it "should be valid" do
is_expected.to be_valid
end
end
- context 'with no scopes' do
- it 'should be invalid' do
+ context "with no scopes" do
+ it "should be invalid" do
deploy_token = build(:deploy_token, read_repository: false, read_registry: false)
expect(deploy_token).not_to be_valid
@@ -32,23 +32,23 @@ describe DeployToken do
end
end
- describe '#scopes' do
- context 'with all the scopes' do
- it 'should return scopes assigned to DeployToken' do
+ describe "#scopes" do
+ context "with all the scopes" do
+ it "should return scopes assigned to DeployToken" do
expect(deploy_token.scopes).to eq([:read_repository, :read_registry])
end
end
- context 'with only one scope' do
- it 'should return scopes assigned to DeployToken' do
+ context "with only one scope" do
+ it "should return scopes assigned to DeployToken" do
deploy_token = create(:deploy_token, read_registry: false)
expect(deploy_token.scopes).to eq([:read_repository])
end
end
end
- describe '#revoke!' do
- it 'should update revoke attribute' do
+ describe "#revoke!" do
+ it "should update revoke attribute" do
deploy_token.revoke!
expect(deploy_token.revoked?).to be_truthy
end
@@ -56,20 +56,20 @@ describe DeployToken do
describe "#active?" do
context "when it has been revoked" do
- it 'should return false' do
+ it "should return false" do
deploy_token.revoke!
expect(deploy_token.active?).to be_falsy
end
end
context "when it hasn't been revoked and is not expired" do
- it 'should return true' do
+ it "should return true" do
expect(deploy_token.active?).to be_truthy
end
end
context "when it hasn't been revoked and is expired" do
- it 'should return true' do
+ it "should return true" do
deploy_token.update_attribute(:expires_at, Date.today - 5.days)
expect(deploy_token.active?).to be_falsy
end
@@ -78,100 +78,100 @@ describe DeployToken do
context "when it hasn't been revoked and has no expiry" do
let(:deploy_token) { create(:deploy_token, expires_at: nil) }
- it 'should return true' do
+ it "should return true" do
expect(deploy_token.active?).to be_truthy
end
end
end
- describe '#username' do
- it 'returns a harcoded username' do
+ describe "#username" do
+ it "returns a harcoded username" do
expect(deploy_token.username).to eq("gitlab+deploy-token-#{deploy_token.id}")
end
end
- describe '#has_access_to?' do
+ describe "#has_access_to?" do
let(:project) { create(:project) }
subject { deploy_token.has_access_to?(project) }
- context 'when deploy token is active and related to project' do
+ context "when deploy token is active and related to project" do
let(:deploy_token) { create(:deploy_token, projects: [project]) }
it { is_expected.to be_truthy }
end
- context 'when deploy token is active but not related to project' do
+ context "when deploy token is active but not related to project" do
let(:deploy_token) { create(:deploy_token) }
it { is_expected.to be_falsy }
end
- context 'when deploy token is revoked and related to project' do
+ context "when deploy token is revoked and related to project" do
let(:deploy_token) { create(:deploy_token, :revoked, projects: [project]) }
it { is_expected.to be_falsy }
end
- context 'when deploy token is revoked and not related to the project' do
+ context "when deploy token is revoked and not related to the project" do
let(:deploy_token) { create(:deploy_token, :revoked) }
it { is_expected.to be_falsy }
end
end
- describe '#expires_at' do
- context 'when using Forever.date' do
+ describe "#expires_at" do
+ context "when using Forever.date" do
let(:deploy_token) { create(:deploy_token, expires_at: nil) }
- it 'should return nil' do
+ it "should return nil" do
expect(deploy_token.expires_at).to be_nil
end
end
- context 'when using a personalized date' do
+ context "when using a personalized date" do
let(:expires_at) { Date.today + 5.months }
let(:deploy_token) { create(:deploy_token, expires_at: expires_at) }
- it 'should return the personalized date' do
+ it "should return the personalized date" do
expect(deploy_token.expires_at).to eq(expires_at)
end
end
end
- describe '#expires_at=' do
- context 'when passing nil' do
+ describe "#expires_at=" do
+ context "when passing nil" do
let(:deploy_token) { create(:deploy_token, expires_at: nil) }
- it 'should assign Forever.date' do
+ it "should assign Forever.date" do
expect(deploy_token.read_attribute(:expires_at)).to eq(Forever.date)
end
end
- context 'when passign a value' do
+ context "when passign a value" do
let(:expires_at) { Date.today + 5.months }
let(:deploy_token) { create(:deploy_token, expires_at: expires_at) }
- it 'should respect the value' do
+ it "should respect the value" do
expect(deploy_token.read_attribute(:expires_at)).to eq(expires_at)
end
end
end
- describe '.gitlab_deploy_token' do
- let(:project) { create(:project ) }
+ describe ".gitlab_deploy_token" do
+ let(:project) { create(:project) }
subject { project.deploy_tokens.gitlab_deploy_token }
- context 'with a gitlab deploy token associated' do
- it 'should return the gitlab deploy token' do
+ context "with a gitlab deploy token associated" do
+ it "should return the gitlab deploy token" do
deploy_token = create(:deploy_token, :gitlab_deploy_token, projects: [project])
is_expected.to eq(deploy_token)
end
end
- context 'with no gitlab deploy token associated' do
- it 'should return nil' do
+ context "with no gitlab deploy token associated" do
+ it "should return nil" do
is_expected.to be_nil
end
end
diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb
index a8d53cfcd7d..c2a590f9083 100644
--- a/spec/models/deployment_spec.rb
+++ b/spec/models/deployment_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Deployment do
subject { build(:deployment) }
@@ -16,9 +16,9 @@ describe Deployment do
it { is_expected.to validate_presence_of(:ref) }
it { is_expected.to validate_presence_of(:sha) }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe '#scheduled_actions' do
+ describe "#scheduled_actions" do
subject { deployment.scheduled_actions }
let(:project) { create(:project, :repository) }
@@ -26,7 +26,7 @@ describe Deployment do
let(:build) { create(:ci_build, :success, pipeline: pipeline) }
let(:deployment) { create(:deployment, deployable: build) }
- it 'delegates to other_scheduled_actions' do
+ it "delegates to other_scheduled_actions" do
expect_any_instance_of(Ci::Build)
.to receive(:other_scheduled_actions)
@@ -34,47 +34,47 @@ describe Deployment do
end
end
- describe 'modules' do
- it_behaves_like 'AtomicInternalId' do
+ describe "modules" do
+ it_behaves_like "AtomicInternalId" do
let(:internal_id_attribute) { :iid }
let(:instance) { build(:deployment) }
let(:scope) { :project }
- let(:scope_attrs) { { project: instance.project } }
+ let(:scope_attrs) { {project: instance.project} }
let(:usage) { :deployments }
end
end
- describe '.success' do
+ describe ".success" do
subject { described_class.success }
- context 'when deployment status is success' do
+ context "when deployment status is success" do
let(:deployment) { create(:deployment, :success) }
it { is_expected.to eq([deployment]) }
end
- context 'when deployment status is created' do
+ context "when deployment status is created" do
let(:deployment) { create(:deployment, :created) }
it { is_expected.to be_empty }
end
- context 'when deployment status is running' do
+ context "when deployment status is running" do
let(:deployment) { create(:deployment, :running) }
it { is_expected.to be_empty }
end
end
- describe 'state machine' do
- context 'when deployment runs' do
+ describe "state machine" do
+ context "when deployment runs" do
let(:deployment) { create(:deployment) }
before do
deployment.run!
end
- it 'starts running' do
+ it "starts running" do
Timecop.freeze do
expect(deployment).to be_running
expect(deployment.finished_at).to be_nil
@@ -82,10 +82,10 @@ describe Deployment do
end
end
- context 'when deployment succeeded' do
+ context "when deployment succeeded" do
let(:deployment) { create(:deployment, :running) }
- it 'has correct status' do
+ it "has correct status" do
Timecop.freeze do
deployment.succeed!
@@ -94,7 +94,7 @@ describe Deployment do
end
end
- it 'executes Deployments::SuccessWorker asynchronously' do
+ it "executes Deployments::SuccessWorker asynchronously" do
expect(Deployments::SuccessWorker)
.to receive(:perform_async).with(deployment.id)
@@ -102,10 +102,10 @@ describe Deployment do
end
end
- context 'when deployment failed' do
+ context "when deployment failed" do
let(:deployment) { create(:deployment, :running) }
- it 'has correct status' do
+ it "has correct status" do
Timecop.freeze do
deployment.drop!
@@ -115,10 +115,10 @@ describe Deployment do
end
end
- context 'when deployment was canceled' do
+ context "when deployment was canceled" do
let(:deployment) { create(:deployment, :running) }
- it 'has correct status' do
+ it "has correct status" do
Timecop.freeze do
deployment.cancel!
@@ -129,54 +129,54 @@ describe Deployment do
end
end
- describe '#success?' do
+ describe "#success?" do
subject { deployment.success? }
- context 'when deployment status is success' do
+ context "when deployment status is success" do
let(:deployment) { create(:deployment, :success) }
it { is_expected.to be_truthy }
end
- context 'when deployment status is failed' do
+ context "when deployment status is failed" do
let(:deployment) { create(:deployment, :failed) }
it { is_expected.to be_falsy }
end
end
- describe '#status_name' do
+ describe "#status_name" do
subject { deployment.status_name }
- context 'when deployment status is success' do
+ context "when deployment status is success" do
let(:deployment) { create(:deployment, :success) }
it { is_expected.to eq(:success) }
end
- context 'when deployment status is failed' do
+ context "when deployment status is failed" do
let(:deployment) { create(:deployment, :failed) }
it { is_expected.to eq(:failed) }
end
end
- describe '#finished_at' do
+ describe "#finished_at" do
subject { deployment.finished_at }
- context 'when deployment status is created' do
+ context "when deployment status is created" do
let(:deployment) { create(:deployment) }
it { is_expected.to be_nil }
end
- context 'when deployment status is success' do
+ context "when deployment status is success" do
let(:deployment) { create(:deployment, :success) }
it { is_expected.to eq(deployment.read_attribute(:finished_at)) }
end
- context 'when deployment status is success' do
+ context "when deployment status is success" do
let(:deployment) { create(:deployment, :success, finished_at: nil) }
before do
@@ -186,37 +186,37 @@ describe Deployment do
it { is_expected.to eq(deployment.read_attribute(:created_at)) }
end
- context 'when deployment status is running' do
+ context "when deployment status is running" do
let(:deployment) { create(:deployment, :running) }
it { is_expected.to be_nil }
end
end
- describe '#deployed_at' do
+ describe "#deployed_at" do
subject { deployment.deployed_at }
- context 'when deployment status is created' do
+ context "when deployment status is created" do
let(:deployment) { create(:deployment) }
it { is_expected.to be_nil }
end
- context 'when deployment status is success' do
+ context "when deployment status is success" do
let(:deployment) { create(:deployment, :success) }
it { is_expected.to eq(deployment.read_attribute(:finished_at)) }
end
- context 'when deployment status is running' do
+ context "when deployment status is running" do
let(:deployment) { create(:deployment, :running) }
it { is_expected.to be_nil }
end
end
- describe 'scopes' do
- describe 'last_for_environment' do
+ describe "scopes" do
+ describe "last_for_environment" do
let(:production) { create(:environment) }
let(:staging) { create(:environment) }
let(:testing) { create(:environment) }
@@ -225,11 +225,11 @@ describe Deployment do
[
create(:deployment, environment: production),
create(:deployment, environment: staging),
- create(:deployment, environment: production)
+ create(:deployment, environment: production),
]
end
- it 'retrieves last deployments for environments' do
+ it "retrieves last deployments for environments" do
last_deployments = described_class.last_for_environment([staging, production, testing])
expect(last_deployments.size).to eq(2)
@@ -238,31 +238,31 @@ describe Deployment do
end
end
- describe '#includes_commit?' do
+ describe "#includes_commit?" do
let(:project) { create(:project, :repository) }
let(:environment) { create(:environment, project: project) }
let(:deployment) do
create(:deployment, environment: environment, sha: project.commit.id)
end
- context 'when there is no project commit' do
- it 'returns false' do
- commit = project.commit('feature')
+ context "when there is no project commit" do
+ it "returns false" do
+ commit = project.commit("feature")
expect(deployment.includes_commit?(commit)).to be false
end
end
- context 'when they share the same tree branch' do
- it 'returns true' do
+ context "when they share the same tree branch" do
+ it "returns true" do
commit = project.commit
expect(deployment.includes_commit?(commit)).to be true
end
end
- context 'when the SHA for the deployment does not exist in the repo' do
- it 'returns false' do
+ context "when the SHA for the deployment does not exist in the repo" do
+ it "returns false" do
deployment.update(sha: Gitlab::Git::BLANK_SHA)
commit = project.commit
@@ -271,22 +271,22 @@ describe Deployment do
end
end
- describe '#metrics' do
+ describe "#metrics" do
let(:deployment) { create(:deployment, :success) }
- let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true) }
+ let(:prometheus_adapter) { double("prometheus_adapter", can_query?: true) }
subject { deployment.metrics }
- context 'metrics are disabled' do
+ context "metrics are disabled" do
it { is_expected.to eq({}) }
end
- context 'metrics are enabled' do
+ context "metrics are enabled" do
let(:simple_metrics) do
{
success: true,
metrics: {},
- last_update: 42
+ last_update: 42,
}
end
@@ -295,62 +295,62 @@ describe Deployment do
allow(prometheus_adapter).to receive(:query).with(:deployment, deployment).and_return(simple_metrics)
end
- it { is_expected.to eq(simple_metrics.merge({ deployment_time: deployment.created_at.to_i })) }
+ it { is_expected.to eq(simple_metrics.merge({deployment_time: deployment.created_at.to_i})) }
end
end
- describe '#additional_metrics' do
+ describe "#additional_metrics" do
let(:project) { create(:project, :repository) }
let(:deployment) { create(:deployment, :succeed, project: project) }
subject { deployment.additional_metrics }
- context 'metrics are disabled' do
+ context "metrics are disabled" do
it { is_expected.to eq({}) }
end
- context 'metrics are enabled' do
+ context "metrics are enabled" do
let(:simple_metrics) do
{
success: true,
metrics: {},
- last_update: 42
+ last_update: 42,
}
end
- let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true) }
+ let(:prometheus_adapter) { double("prometheus_adapter", can_query?: true) }
before do
allow(deployment).to receive(:prometheus_adapter).and_return(prometheus_adapter)
allow(prometheus_adapter).to receive(:query).with(:additional_metrics_deployment, deployment).and_return(simple_metrics)
end
- it { is_expected.to eq(simple_metrics.merge({ deployment_time: deployment.created_at.to_i })) }
+ it { is_expected.to eq(simple_metrics.merge({deployment_time: deployment.created_at.to_i})) }
end
end
- describe '#stop_action' do
+ describe "#stop_action" do
let(:build) { create(:ci_build) }
subject { deployment.stop_action }
- context 'when no other actions' do
+ context "when no other actions" do
let(:deployment) { FactoryBot.build(:deployment, deployable: build) }
it { is_expected.to be_nil }
end
- context 'with other actions' do
- let!(:close_action) { create(:ci_build, :manual, pipeline: build.pipeline, name: 'close_app') }
+ context "with other actions" do
+ let!(:close_action) { create(:ci_build, :manual, pipeline: build.pipeline, name: "close_app") }
- context 'when matching action is defined' do
- let(:deployment) { FactoryBot.build(:deployment, deployable: build, on_stop: 'close_other_app') }
+ context "when matching action is defined" do
+ let(:deployment) { FactoryBot.build(:deployment, deployable: build, on_stop: "close_other_app") }
it { is_expected.to be_nil }
end
- context 'when no matching action is defined' do
- let(:deployment) { FactoryBot.build(:deployment, deployable: build, on_stop: 'close_app') }
+ context "when no matching action is defined" do
+ let(:deployment) { FactoryBot.build(:deployment, deployable: build, on_stop: "close_app") }
it { is_expected.to eq(close_action) }
end
diff --git a/spec/models/diff_discussion_spec.rb b/spec/models/diff_discussion_spec.rb
index 50b19000799..b960bb76920 100644
--- a/spec/models/diff_discussion_spec.rb
+++ b/spec/models/diff_discussion_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe DiffDiscussion do
include RepoHelpers
@@ -9,27 +9,27 @@ describe DiffDiscussion do
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:diff_note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project) }
- describe '#reply_attributes' do
- it 'includes position and original_position' do
+ describe "#reply_attributes" do
+ it "includes position and original_position" do
attributes = subject.reply_attributes
expect(attributes[:position]).to eq(diff_note.position.to_json)
expect(attributes[:original_position]).to eq(diff_note.original_position.to_json)
end
end
- describe '#merge_request_version_params' do
+ describe "#merge_request_version_params" do
let(:merge_request) { create(:merge_request, source_project: project, target_project: project, importing: true) }
- let!(:merge_request_diff1) { merge_request.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
+ let!(:merge_request_diff1) { merge_request.merge_request_diffs.create(head_commit_sha: "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") }
let!(:merge_request_diff2) { merge_request.merge_request_diffs.create(head_commit_sha: nil) }
- let!(:merge_request_diff3) { merge_request.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
+ let!(:merge_request_diff3) { merge_request.merge_request_diffs.create(head_commit_sha: "5937ac0a7beb003549fc5fd26fc247adbce4a52e") }
- context 'when the discussion is active' do
- it 'returns an empty hash, which will end up showing the latest version' do
+ context "when the discussion is active" do
+ it "returns an empty hash, which will end up showing the latest version" do
expect(subject.merge_request_version_params).to eq({})
end
end
- context 'when the discussion is on an older merge request version' do
+ context "when the discussion is on an older merge request version" do
let(:position) do
Gitlab::Diff::Position.new(
old_path: ".gitmodules",
@@ -47,24 +47,24 @@ describe DiffDiscussion do
diff_note.save!
end
- context 'when commit_id is not present' do
- it 'returns the diff ID for the version to show' do
+ context "when commit_id is not present" do
+ it "returns the diff ID for the version to show" do
expect(subject.merge_request_version_params).to eq(diff_id: merge_request_diff1.id)
end
end
- context 'when commit_id is present' do
+ context "when commit_id is present" do
before do
- diff_note.update_attribute(:commit_id, 'commit_123')
+ diff_note.update_attribute(:commit_id, "commit_123")
end
- it 'includes the commit_id in the result' do
- expect(subject.merge_request_version_params).to eq(diff_id: merge_request_diff1.id, commit_id: 'commit_123')
+ it "includes the commit_id in the result" do
+ expect(subject.merge_request_version_params).to eq(diff_id: merge_request_diff1.id, commit_id: "commit_123")
end
end
end
- context 'when the discussion is on a comparison between merge request versions' do
+ context "when the discussion is on a comparison between merge request versions" do
let(:position) do
Gitlab::Diff::Position.new(
old_path: ".gitmodules",
@@ -82,24 +82,24 @@ describe DiffDiscussion do
diff_note.save!
end
- context 'when commit_id is not present' do
- it 'returns the diff ID and start sha of the versions to compare' do
+ context "when commit_id is not present" do
+ it "returns the diff ID and start sha of the versions to compare" do
expect(subject.merge_request_version_params).to eq(diff_id: merge_request_diff3.id, start_sha: merge_request_diff1.head_commit_sha)
end
end
- context 'when commit_id is present' do
+ context "when commit_id is present" do
before do
- diff_note.update_attribute(:commit_id, 'commit_123')
+ diff_note.update_attribute(:commit_id, "commit_123")
end
- it 'includes the commit_id in the result' do
- expect(subject.merge_request_version_params).to eq(diff_id: merge_request_diff3.id, start_sha: merge_request_diff1.head_commit_sha, commit_id: 'commit_123')
+ it "includes the commit_id in the result" do
+ expect(subject.merge_request_version_params).to eq(diff_id: merge_request_diff3.id, start_sha: merge_request_diff1.head_commit_sha, commit_id: "commit_123")
end
end
end
- context 'when the discussion does not have a merge request version' do
+ context "when the discussion does not have a merge request version" do
let(:diff_note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project, diff_refs: project.commit(sample_commit.id).diff_refs) }
before do
@@ -107,19 +107,19 @@ describe DiffDiscussion do
diff_note.save!
end
- context 'when commit_id is not present' do
- it 'returns empty hash' do
+ context "when commit_id is not present" do
+ it "returns empty hash" do
expect(subject.merge_request_version_params).to eq(nil)
end
end
- context 'when commit_id is present' do
+ context "when commit_id is present" do
before do
- diff_note.update_attribute(:commit_id, 'commit_123')
+ diff_note.update_attribute(:commit_id, "commit_123")
end
- it 'returns the commit_id' do
- expect(subject.merge_request_version_params).to eq(commit_id: 'commit_123')
+ it "returns the commit_id" do
+ expect(subject.merge_request_version_params).to eq(commit_id: "commit_123")
end
end
end
diff --git a/spec/models/diff_note_spec.rb b/spec/models/diff_note_spec.rb
index fda00a693f0..41781b167ba 100644
--- a/spec/models/diff_note_spec.rb
+++ b/spec/models/diff_note_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe DiffNote do
include RepoHelpers
@@ -84,40 +84,40 @@ describe DiffNote do
end
end
- describe '#create_diff_file callback' do
+ describe "#create_diff_file callback" do
let(:noteable) { create(:merge_request) }
let(:project) { noteable.project }
- context 'merge request' do
+ context "merge request" do
let!(:diff_note) { create(:diff_note_on_merge_request, project: project, noteable: noteable) }
- it 'creates a diff note file' do
+ it "creates a diff note file" do
expect(diff_note.reload.note_diff_file).to be_present
end
- it 'does not create diff note file if it is a reply' do
+ it "does not create diff note file if it is a reply" do
expect { create(:diff_note_on_merge_request, noteable: noteable, in_reply_to: diff_note) }
.not_to change(NoteDiffFile, :count)
end
end
- context 'commit' do
+ context "commit" do
let!(:diff_note) { create(:diff_note_on_commit, project: project) }
- it 'creates a diff note file' do
+ it "creates a diff note file" do
expect(diff_note.reload.note_diff_file).to be_present
end
- it 'does not create diff note file if it is a reply' do
+ it "does not create diff note file if it is a reply" do
expect { create(:diff_note_on_commit, in_reply_to: diff_note) }
.not_to change(NoteDiffFile, :count)
end
end
end
- describe '#diff_file', :clean_gitlab_redis_shared_state do
- context 'when note_diff_file association exists' do
- it 'returns persisted diff file data' do
+ describe "#diff_file", :clean_gitlab_redis_shared_state do
+ context "when note_diff_file association exists" do
+ it "returns persisted diff file data" do
diff_file = subject.diff_file
expect(diff_file.diff.to_hash.with_indifferent_access)
@@ -125,8 +125,8 @@ describe DiffNote do
end
end
- context 'when the discussion was created in the diff' do
- it 'returns correct diff file' do
+ context "when the discussion was created in the diff" do
+ it "returns correct diff file" do
diff_file = subject.diff_file
expect(diff_file.old_path).to eq(position.old_path)
@@ -135,7 +135,7 @@ describe DiffNote do
end
end
- context 'when discussion is outdated or not created in the diff' do
+ context "when discussion is outdated or not created in the diff" do
let(:diff_refs) { project.commit(sample_commit.id).diff_refs }
let(:position) do
Gitlab::Diff::Position.new(
@@ -147,7 +147,7 @@ describe DiffNote do
)
end
- it 'returns the correct diff file' do
+ it "returns the correct diff file" do
diff_file = subject.diff_file
expect(diff_file.old_path).to eq(position.old_path)
@@ -156,8 +156,8 @@ describe DiffNote do
end
end
- context 'note diff file creation enqueuing' do
- it 'enqueues CreateNoteDiffFileWorker if it is the first note of a discussion' do
+ context "note diff file creation enqueuing" do
+ it "enqueues CreateNoteDiffFileWorker if it is the first note of a discussion" do
subject.note_diff_file.destroy!
expect(CreateNoteDiffFileWorker).to receive(:perform_async).with(subject.id)
@@ -165,7 +165,7 @@ describe DiffNote do
subject.reload.diff_file
end
- it 'does not enqueues CreateNoteDiffFileWorker if not first note of a discussion' do
+ it "does not enqueues CreateNoteDiffFileWorker if not first note of a discussion" do
mr = create(:merge_request)
diff_note = create(:diff_note_on_merge_request, project: mr.project, noteable: mr)
reply_diff_note = create(:diff_note_on_merge_request, in_reply_to: diff_note)
@@ -283,7 +283,7 @@ describe DiffNote do
end
end
- describe '#created_at_diff?' do
+ describe "#created_at_diff?" do
let(:diff_refs) { project.commit(sample_commit.id).diff_refs }
let(:position) do
Gitlab::Diff::Position.new(
@@ -318,17 +318,17 @@ describe DiffNote do
end
end
- describe '#supports_suggestion?' do
- context 'when noteable does not support suggestions' do
- it 'returns false' do
+ describe "#supports_suggestion?" do
+ context "when noteable does not support suggestions" do
+ it "returns false" do
allow(subject.noteable).to receive(:supports_suggestion?) { false }
expect(subject.supports_suggestion?).to be(false)
end
end
- context 'when line is not suggestible' do
- it 'returns false' do
+ context "when line is not suggestible" do
+ it "returns false" do
allow_any_instance_of(Gitlab::Diff::Line).to receive(:suggestible?) { false }
expect(subject.supports_suggestion?).to be(false)
diff --git a/spec/models/diff_viewer/base_spec.rb b/spec/models/diff_viewer/base_spec.rb
index f4efe5a7b3a..c259c23f53a 100644
--- a/spec/models/diff_viewer/base_spec.rb
+++ b/spec/models/diff_viewer/base_spec.rb
@@ -1,17 +1,17 @@
-require 'spec_helper'
+require "spec_helper"
describe DiffViewer::Base do
include FakeBlobHelpers
let(:project) { create(:project, :repository) }
- let(:commit) { project.commit('570e7b2abdd848b95f2f578043fc23bd6f6fd24d') }
- let(:diff_file) { commit.diffs.diff_file_with_new_path('files/ruby/popen.rb') }
+ let(:commit) { project.commit("570e7b2abdd848b95f2f578043fc23bd6f6fd24d") }
+ let(:diff_file) { commit.diffs.diff_file_with_new_path("files/ruby/popen.rb") }
let(:viewer_class) do
Class.new(described_class) do
include DiffViewer::ServerSide
- self.extensions = %w(jpg)
+ self.extensions = %w[jpg]
self.binary = true
self.collapse_limit = 1.megabyte
self.size_limit = 5.megabytes
@@ -20,145 +20,145 @@ describe DiffViewer::Base do
let(:viewer) { viewer_class.new(diff_file) }
- describe '.can_render?' do
- context 'when the extension is supported' do
- let(:commit) { project.commit('2f63565e7aac07bcdadb654e253078b727143ec4') }
- let(:diff_file) { commit.diffs.diff_file_with_new_path('files/images/6049019_460s.jpg') }
+ describe ".can_render?" do
+ context "when the extension is supported" do
+ let(:commit) { project.commit("2f63565e7aac07bcdadb654e253078b727143ec4") }
+ let(:diff_file) { commit.diffs.diff_file_with_new_path("files/images/6049019_460s.jpg") }
- context 'when the binaryness matches' do
- it 'returns true' do
+ context "when the binaryness matches" do
+ it "returns true" do
expect(viewer_class.can_render?(diff_file)).to be_truthy
end
end
- context 'when the binaryness does not match' do
- let(:commit) { project.commit_by(oid: 'ae73cb07c9eeaf35924a10f713b364d32b2dd34f') }
- let(:diff_file) { commit.diffs.diff_file_with_new_path('Gemfile.zip') }
+ context "when the binaryness does not match" do
+ let(:commit) { project.commit_by(oid: "ae73cb07c9eeaf35924a10f713b364d32b2dd34f") }
+ let(:diff_file) { commit.diffs.diff_file_with_new_path("Gemfile.zip") }
- it 'returns false' do
+ it "returns false" do
expect(viewer_class.can_render?(diff_file)).to be_falsey
end
end
end
- context 'when the file type is supported' do
- let(:commit) { project.commit('1a0b36b3cdad1d2ee32457c102a8c0b7056fa863') }
- let(:diff_file) { commit.diffs.diff_file_with_new_path('LICENSE') }
+ context "when the file type is supported" do
+ let(:commit) { project.commit("1a0b36b3cdad1d2ee32457c102a8c0b7056fa863") }
+ let(:diff_file) { commit.diffs.diff_file_with_new_path("LICENSE") }
before do
- viewer_class.file_types = %i(license)
+ viewer_class.file_types = %i[license]
viewer_class.binary = false
end
- context 'when the binaryness matches' do
- it 'returns true' do
+ context "when the binaryness matches" do
+ it "returns true" do
expect(viewer_class.can_render?(diff_file)).to be_truthy
end
end
- context 'when the binaryness does not match' do
+ context "when the binaryness does not match" do
before do
allow_any_instance_of(Blob).to receive(:binary_in_repo?).and_return(true)
end
- it 'returns false' do
+ it "returns false" do
expect(viewer_class.can_render?(diff_file)).to be_falsey
end
end
end
- context 'when the extension and file type are not supported' do
- it 'returns false' do
+ context "when the extension and file type are not supported" do
+ it "returns false" do
expect(viewer_class.can_render?(diff_file)).to be_falsey
end
end
- context 'when the file was renamed and only the old blob is supported' do
- let(:commit) { project.commit_by(oid: '2f63565e7aac07bcdadb654e253078b727143ec4') }
- let(:diff_file) { commit.diffs.diff_file_with_new_path('files/images/6049019_460s.jpg') }
+ context "when the file was renamed and only the old blob is supported" do
+ let(:commit) { project.commit_by(oid: "2f63565e7aac07bcdadb654e253078b727143ec4") }
+ let(:diff_file) { commit.diffs.diff_file_with_new_path("files/images/6049019_460s.jpg") }
before do
allow(diff_file).to receive(:renamed_file?).and_return(true)
- viewer_class.extensions = %w(notjpg)
+ viewer_class.extensions = %w[notjpg]
end
- it 'returns false' do
+ it "returns false" do
expect(viewer_class.can_render?(diff_file)).to be_falsey
end
end
end
- describe '#collapsed?' do
- context 'when the combined blob size is larger than the collapse limit' do
+ describe "#collapsed?" do
+ context "when the combined blob size is larger than the collapse limit" do
before do
allow(diff_file).to receive(:raw_size).and_return(1025.kilobytes)
end
- it 'returns true' do
+ it "returns true" do
expect(viewer.collapsed?).to be_truthy
end
end
- context 'when the combined blob size is smaller than the collapse limit' do
- it 'returns false' do
+ context "when the combined blob size is smaller than the collapse limit" do
+ it "returns false" do
expect(viewer.collapsed?).to be_falsey
end
end
end
- describe '#too_large?' do
- context 'when the combined blob size is larger than the size limit' do
+ describe "#too_large?" do
+ context "when the combined blob size is larger than the size limit" do
before do
allow(diff_file).to receive(:raw_size).and_return(6.megabytes)
end
- it 'returns true' do
+ it "returns true" do
expect(viewer.too_large?).to be_truthy
end
end
- context 'when the blob size is smaller than the size limit' do
- it 'returns false' do
+ context "when the blob size is smaller than the size limit" do
+ it "returns false" do
expect(viewer.too_large?).to be_falsey
end
end
end
- describe '#render_error' do
- context 'when the combined blob size is larger than the size limit' do
+ describe "#render_error" do
+ context "when the combined blob size is larger than the size limit" do
before do
allow(diff_file).to receive(:raw_size).and_return(6.megabytes)
end
- it 'returns :too_large' do
+ it "returns :too_large" do
expect(viewer.render_error).to eq(:too_large)
end
end
- context 'when the combined blob size is smaller than the size limit' do
- it 'returns nil' do
+ context "when the combined blob size is smaller than the size limit" do
+ it "returns nil" do
expect(viewer.render_error).to be_nil
end
end
end
- describe '#render_error_message' do
- it 'returns nothing when no render_error' do
+ describe "#render_error_message" do
+ it "returns nothing when no render_error" do
expect(viewer.render_error).to be_nil
expect(viewer.render_error_message).to be_nil
end
- context 'when render_error error' do
+ context "when render_error error" do
before do
allow(viewer).to receive(:render_error).and_return(:too_large)
end
- it 'returns an error message' do
- expect(viewer.render_error_message).to include('it is too large')
+ it "returns an error message" do
+ expect(viewer.render_error_message).to include("it is too large")
end
it 'includes a "view the blob" link' do
- expect(viewer.render_error_message).to include('view the blob')
+ expect(viewer.render_error_message).to include("view the blob")
end
end
end
diff --git a/spec/models/diff_viewer/server_side_spec.rb b/spec/models/diff_viewer/server_side_spec.rb
index 86b14b6ebf3..36d44b7ffbc 100644
--- a/spec/models/diff_viewer/server_side_spec.rb
+++ b/spec/models/diff_viewer/server_side_spec.rb
@@ -1,9 +1,9 @@
-require 'spec_helper'
+require "spec_helper"
describe DiffViewer::ServerSide do
set(:project) { create(:project, :repository) }
- let(:commit) { project.commit_by(oid: '570e7b2abdd848b95f2f578043fc23bd6f6fd24d') }
- let!(:diff_file) { commit.diffs.diff_file_with_new_path('files/ruby/popen.rb') }
+ let(:commit) { project.commit_by(oid: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d") }
+ let!(:diff_file) { commit.diffs.diff_file_with_new_path("files/ruby/popen.rb") }
let(:viewer_class) do
Class.new(DiffViewer::Base) do
@@ -13,42 +13,42 @@ describe DiffViewer::ServerSide do
subject { viewer_class.new(diff_file) }
- describe '#prepare!' do
- it 'loads all diff file data' do
+ describe "#prepare!" do
+ it "loads all diff file data" do
expect(Blob).to receive(:lazy).at_least(:twice)
subject.prepare!
end
end
- describe '#render_error' do
- context 'when the diff file is stored externally' do
+ describe "#render_error" do
+ context "when the diff file is stored externally" do
before do
allow(diff_file).to receive(:stored_externally?).and_return(true)
end
- it 'return :server_side_but_stored_externally' do
+ it "return :server_side_but_stored_externally" do
expect(subject.render_error).to eq(:server_side_but_stored_externally)
end
end
end
- describe '#render_error_reason' do
- context 'when the diff file is stored externally' do
+ describe "#render_error_reason" do
+ context "when the diff file is stored externally" do
before do
allow(diff_file).to receive(:stored_externally?).and_return(true)
end
- it 'returns error message if stored in LFS' do
+ it "returns error message if stored in LFS" do
allow(diff_file).to receive(:external_storage).and_return(:lfs)
- expect(subject.render_error_message).to include('it is stored in LFS')
+ expect(subject.render_error_message).to include("it is stored in LFS")
end
- it 'returns error message if stored externally' do
+ it "returns error message if stored externally" do
allow(diff_file).to receive(:external_storage).and_return(:foo)
- expect(subject.render_error_message).to include('it is stored externally')
+ expect(subject.render_error_message).to include("it is stored externally")
end
end
end
diff --git a/spec/models/discussion_spec.rb b/spec/models/discussion_spec.rb
index a46f7ed6507..e059cf4b77a 100644
--- a/spec/models/discussion_spec.rb
+++ b/spec/models/discussion_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Discussion do
subject { described_class.new([first_note, second_note, third_note]) }
@@ -8,8 +8,8 @@ describe Discussion do
let(:second_note) { create(:diff_note_on_merge_request, in_reply_to: first_note) }
let(:third_note) { create(:diff_note_on_merge_request) }
- describe '.build' do
- it 'returns a discussion of the right type' do
+ describe ".build" do
+ it "returns a discussion of the right type" do
discussion = described_class.build([first_note, second_note], merge_request)
expect(discussion).to be_a(DiffDiscussion)
expect(discussion.notes.count).to be(2)
@@ -18,12 +18,12 @@ describe Discussion do
end
end
- describe '.build_collection' do
- it 'returns an array of discussions of the right type' do
+ describe ".build_collection" do
+ it "returns an array of discussions of the right type" do
discussions = described_class.build_collection([first_note, second_note, third_note], merge_request)
expect(discussions).to eq([
DiffDiscussion.new([first_note, second_note], merge_request),
- DiffDiscussion.new([third_note], merge_request)
+ DiffDiscussion.new([third_note], merge_request),
])
end
end
diff --git a/spec/models/email_spec.rb b/spec/models/email_spec.rb
index 47eb0717c0c..5172296abca 100644
--- a/spec/models/email_spec.rb
+++ b/spec/models/email_spec.rb
@@ -1,27 +1,27 @@
-require 'spec_helper'
+require "spec_helper"
describe Email do
- describe 'validations' do
- it_behaves_like 'an object with email-formated attributes', :email do
+ describe "validations" do
+ it_behaves_like "an object with email-formated attributes", :email do
subject { build(:email) }
end
end
- it 'normalize email value' do
- expect(described_class.new(email: ' inFO@exAMPLe.com ').email)
- .to eq 'info@example.com'
+ it "normalize email value" do
+ expect(described_class.new(email: " inFO@exAMPLe.com ").email)
+ .to eq "info@example.com"
end
- describe '#update_invalid_gpg_signatures' do
+ describe "#update_invalid_gpg_signatures" do
let(:user) do
- create(:user, email: 'tula.torphy@abshire.ca').tap do |user|
+ create(:user, email: "tula.torphy@abshire.ca").tap do |user|
user.skip_reconfirmation!
end
end
let(:user) { create(:user) }
- it 'synchronizes the gpg keys when the email is updated' do
- email = user.emails.create(email: 'new@email.com')
+ it "synchronizes the gpg keys when the email is updated" do
+ email = user.emails.create(email: "new@email.com")
expect(user).to receive(:update_invalid_gpg_signatures)
@@ -29,10 +29,10 @@ describe Email do
end
end
- describe 'scopes' do
+ describe "scopes" do
let(:user) { create(:user) }
- it 'scopes confirmed emails' do
+ it "scopes confirmed emails" do
create(:email, :confirmed, user: user)
create(:email, user: user)
@@ -41,10 +41,10 @@ describe Email do
end
end
- describe 'delegation' do
+ describe "delegation" do
let(:user) { create(:user) }
- it 'delegates to :user' do
+ it "delegates to :user" do
expect(build(:email, user: user).username).to eq user.username
end
end
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index ab1b306e597..705780bc143 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Environment do
let(:project) { create(:project, :stubbed_repository) }
@@ -19,7 +19,7 @@ describe Environment do
it { is_expected.to validate_length_of(:external_url).is_at_most(255) }
- describe '.order_by_last_deployed_at' do
+ describe ".order_by_last_deployed_at" do
let(:project) { create(:project, :repository) }
let!(:environment1) { create(:environment, project: project) }
let!(:environment2) { create(:environment, project: project) }
@@ -28,93 +28,93 @@ describe Environment do
let!(:deployment2) { create(:deployment, environment: environment2) }
let!(:deployment3) { create(:deployment, environment: environment1) }
- it 'returns the environments in order of having been last deployed' do
+ it "returns the environments in order of having been last deployed" do
expect(project.environments.order_by_last_deployed_at.to_a).to eq([environment3, environment2, environment1])
end
end
- describe 'state machine' do
- it 'invalidates the cache after a change' do
+ describe "state machine" do
+ it "invalidates the cache after a change" do
expect(environment).to receive(:expire_etag_cache)
environment.stop
end
end
- describe '.for_name_like' do
+ describe ".for_name_like" do
subject { project.environments.for_name_like(query, limit: limit) }
- let!(:environment) { create(:environment, name: 'production', project: project) }
- let(:query) { 'pro' }
+ let!(:environment) { create(:environment, name: "production", project: project) }
+ let(:query) { "pro" }
let(:limit) { 5 }
- it 'returns a found name' do
+ it "returns a found name" do
is_expected.to include(environment)
end
- context 'when query is production' do
- let(:query) { 'production' }
+ context "when query is production" do
+ let(:query) { "production" }
- it 'returns a found name' do
+ it "returns a found name" do
is_expected.to include(environment)
end
end
- context 'when query is productionA' do
- let(:query) { 'productionA' }
+ context "when query is productionA" do
+ let(:query) { "productionA" }
- it 'returns empty array' do
+ it "returns empty array" do
is_expected.to be_empty
end
end
- context 'when query is empty' do
- let(:query) { '' }
+ context "when query is empty" do
+ let(:query) { "" }
- it 'returns a found name' do
+ it "returns a found name" do
is_expected.to include(environment)
end
end
- context 'when query is nil' do
+ context "when query is nil" do
let(:query) { }
- it 'raises an error' do
+ it "raises an error" do
expect { subject }.to raise_error(NoMethodError)
end
end
- context 'when query is partially matched in the middle of environment name' do
- let(:query) { 'duction' }
+ context "when query is partially matched in the middle of environment name" do
+ let(:query) { "duction" }
- it 'returns empty array' do
+ it "returns empty array" do
is_expected.to be_empty
end
end
- context 'when query contains a wildcard character' do
- let(:query) { 'produc%' }
+ context "when query contains a wildcard character" do
+ let(:query) { "produc%" }
- it 'prevents wildcard injection' do
+ it "prevents wildcard injection" do
is_expected.to be_empty
end
end
end
- describe '.pluck_names' do
+ describe ".pluck_names" do
subject { described_class.pluck_names }
- let!(:environment) { create(:environment, name: 'production', project: project) }
+ let!(:environment) { create(:environment, name: "production", project: project) }
- it 'plucks names' do
+ it "plucks names" do
is_expected.to eq(%w[production])
end
end
- describe '#expire_etag_cache' do
+ describe "#expire_etag_cache" do
let(:store) { Gitlab::EtagCaching::Store.new }
- it 'changes the cached value' do
+ it "changes the cached value" do
old_value = store.get(environment.etag_cache_key)
environment.stop
@@ -123,71 +123,71 @@ describe Environment do
end
end
- describe '.with_deployment' do
+ describe ".with_deployment" do
subject { described_class.with_deployment(sha) }
let(:environment) { create(:environment) }
let(:sha) { RepoHelpers.sample_commit.id }
- context 'when deployment has the specified sha' do
+ context "when deployment has the specified sha" do
let!(:deployment) { create(:deployment, environment: environment, sha: sha) }
it { is_expected.to eq([environment]) }
end
- context 'when deployment does not have the specified sha' do
- let!(:deployment) { create(:deployment, environment: environment, sha: 'abc') }
+ context "when deployment does not have the specified sha" do
+ let!(:deployment) { create(:deployment, environment: environment, sha: "abc") }
it { is_expected.to be_empty }
end
end
- describe '#folder_name' do
- context 'when it is inside a folder' do
+ describe "#folder_name" do
+ context "when it is inside a folder" do
subject(:environment) do
- create(:environment, name: 'staging/review-1')
+ create(:environment, name: "staging/review-1")
end
- it 'returns a top-level folder name' do
- expect(environment.folder_name).to eq 'staging'
+ it "returns a top-level folder name" do
+ expect(environment.folder_name).to eq "staging"
end
end
- context 'when the environment if a top-level item itself' do
+ context "when the environment if a top-level item itself" do
subject(:environment) do
- create(:environment, name: 'production')
+ create(:environment, name: "production")
end
- it 'returns an environment name' do
- expect(environment.folder_name).to eq 'production'
+ it "returns an environment name" do
+ expect(environment.folder_name).to eq "production"
end
end
end
- describe '#name_without_type' do
- context 'when it is inside a folder' do
+ describe "#name_without_type" do
+ context "when it is inside a folder" do
subject(:environment) do
- create(:environment, name: 'staging/review-1')
+ create(:environment, name: "staging/review-1")
end
- it 'returns name without folder' do
- expect(environment.name_without_type).to eq 'review-1'
+ it "returns name without folder" do
+ expect(environment.name_without_type).to eq "review-1"
end
end
- context 'when the environment if a top-level item itself' do
+ context "when the environment if a top-level item itself" do
subject(:environment) do
- create(:environment, name: 'production')
+ create(:environment, name: "production")
end
- it 'returns full name' do
- expect(environment.name_without_type).to eq 'production'
+ it "returns full name" do
+ expect(environment.name_without_type).to eq "production"
end
end
end
- describe '#nullify_external_url' do
- it 'replaces a blank url with nil' do
+ describe "#nullify_external_url" do
+ it "replaces a blank url with nil" do
env = build(:environment, external_url: "")
expect(env.save).to be true
@@ -195,47 +195,47 @@ describe Environment do
end
end
- describe '#includes_commit?' do
+ describe "#includes_commit?" do
let(:project) { create(:project, :repository) }
- context 'without a last deployment' do
+ context "without a last deployment" do
it "returns false" do
- expect(environment.includes_commit?('HEAD')).to be false
+ expect(environment.includes_commit?("HEAD")).to be false
end
end
- context 'with a last deployment' do
+ context "with a last deployment" do
let!(:deployment) do
- create(:deployment, :success, environment: environment, sha: project.commit('master').id)
+ create(:deployment, :success, environment: environment, sha: project.commit("master").id)
end
- context 'in the same branch' do
- it 'returns true' do
+ context "in the same branch" do
+ it "returns true" do
expect(environment.includes_commit?(RepoHelpers.sample_commit)).to be true
end
end
- context 'not in the same branch' do
+ context "not in the same branch" do
before do
- deployment.update(sha: project.commit('feature').id)
+ deployment.update(sha: project.commit("feature").id)
end
- it 'returns false' do
+ it "returns false" do
expect(environment.includes_commit?(RepoHelpers.sample_commit)).to be false
end
end
end
end
- describe '#update_merge_request_metrics?' do
+ describe "#update_merge_request_metrics?" do
{
- 'production' => true,
- 'production/eu' => true,
- 'production/www.gitlab.com' => true,
- 'productioneu' => false,
- 'Production' => false,
- 'Production/eu' => false,
- 'test-production' => false
+ "production" => true,
+ "production/eu" => true,
+ "production/www.gitlab.com" => true,
+ "productioneu" => false,
+ "Production" => false,
+ "Production/eu" => false,
+ "test-production" => false,
}.each do |name, expected_value|
it "returns #{expected_value} for #{name}" do
env = create(:environment, name: name)
@@ -245,65 +245,65 @@ describe Environment do
end
end
- describe '#first_deployment_for' do
+ describe "#first_deployment_for" do
let(:project) { create(:project, :repository) }
let!(:deployment) { create(:deployment, :succeed, environment: environment, ref: commit.parent.id) }
let!(:deployment1) { create(:deployment, :succeed, environment: environment, ref: commit.id) }
let(:head_commit) { project.commit }
let(:commit) { project.commit.parent }
- it 'returns deployment id for the environment' do
+ it "returns deployment id for the environment" do
expect(environment.first_deployment_for(commit.id)).to eq deployment1
end
- it 'return nil when no deployment is found' do
+ it "return nil when no deployment is found" do
expect(environment.first_deployment_for(head_commit.id)).to eq nil
end
- it 'returns a UTF-8 ref' do
+ it "returns a UTF-8 ref" do
expect(environment.first_deployment_for(commit.id).ref).to be_utf8
end
end
- describe '#environment_type' do
+ describe "#environment_type" do
subject { environment.environment_type }
- it 'sets a environment type if name has multiple segments' do
- environment.update!(name: 'production/worker.gitlab.com')
+ it "sets a environment type if name has multiple segments" do
+ environment.update!(name: "production/worker.gitlab.com")
- is_expected.to eq('production')
+ is_expected.to eq("production")
end
- it 'nullifies a type if it\'s a simple name' do
- environment.update!(name: 'production')
+ it "nullifies a type if it's a simple name" do
+ environment.update!(name: "production")
is_expected.to be_nil
end
end
- describe '#stop_action_available?' do
+ describe "#stop_action_available?" do
subject { environment.stop_action_available? }
- context 'when no other actions' do
+ context "when no other actions" do
it { is_expected.to be_falsey }
end
- context 'when matching action is defined' do
+ context "when matching action is defined" do
let(:build) { create(:ci_build) }
let!(:deployment) do
create(:deployment, :success,
- environment: environment,
- deployable: build,
- on_stop: 'close_app')
+ environment: environment,
+ deployable: build,
+ on_stop: "close_app")
end
let!(:close_action) do
create(:ci_build, :manual, pipeline: build.pipeline,
- name: 'close_app')
+ name: "close_app")
end
- context 'when environment is available' do
+ context "when environment is available" do
before do
environment.start
end
@@ -311,7 +311,7 @@ describe Environment do
it { is_expected.to be_truthy }
end
- context 'when environment is stopped' do
+ context "when environment is stopped" do
before do
environment.stop
end
@@ -321,7 +321,7 @@ describe Environment do
end
end
- describe '#stop_with_action!' do
+ describe "#stop_with_action!" do
let(:user) { create(:user) }
subject { environment.stop_with_action!(user) }
@@ -330,8 +330,8 @@ describe Environment do
expect(environment).to receive(:available?).and_call_original
end
- context 'when no other actions' do
- context 'environment is available' do
+ context "when no other actions" do
+ context "environment is available" do
before do
environment.update(state: :available)
end
@@ -343,7 +343,7 @@ describe Environment do
end
end
- context 'environment is already stopped' do
+ context "environment is already stopped" do
before do
environment.update(state: :stopped)
end
@@ -356,53 +356,53 @@ describe Environment do
end
end
- context 'when matching action is defined' do
+ context "when matching action is defined" do
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, pipeline: pipeline) }
let!(:deployment) do
create(:deployment, :success,
- environment: environment,
- deployable: build,
- on_stop: 'close_app')
+ environment: environment,
+ deployable: build,
+ on_stop: "close_app")
end
- context 'when user is not allowed to stop environment' do
+ context "when user is not allowed to stop environment" do
let!(:close_action) do
- create(:ci_build, :manual, pipeline: pipeline, name: 'close_app')
+ create(:ci_build, :manual, pipeline: pipeline, name: "close_app")
end
- it 'raises an exception' do
+ it "raises an exception" do
expect { subject }.to raise_error(Gitlab::Access::AccessDeniedError)
end
end
- context 'when user is allowed to stop environment' do
+ context "when user is allowed to stop environment" do
before do
project.add_developer(user)
create(:protected_branch, :developers_can_merge,
- name: 'master', project: project)
+ name: "master", project: project)
end
- context 'when action did not yet finish' do
+ context "when action did not yet finish" do
let!(:close_action) do
- create(:ci_build, :manual, pipeline: pipeline, name: 'close_app')
+ create(:ci_build, :manual, pipeline: pipeline, name: "close_app")
end
- it 'returns the same action' do
+ it "returns the same action" do
expect(subject).to eq(close_action)
expect(subject.user).to eq(user)
end
end
- context 'if action did finish' do
+ context "if action did finish" do
let!(:close_action) do
create(:ci_build, :manual, :success,
- pipeline: pipeline, name: 'close_app')
+ pipeline: pipeline, name: "close_app")
end
- it 'returns a new action of the same type' do
+ it "returns a new action of the same type" do
expect(subject).to be_persisted
expect(subject.name).to eq(close_action.name)
expect(subject.user).to eq(user)
@@ -412,138 +412,138 @@ describe Environment do
end
end
- describe 'recently_updated_on_branch?' do
- subject { environment.recently_updated_on_branch?('feature') }
+ describe "recently_updated_on_branch?" do
+ subject { environment.recently_updated_on_branch?("feature") }
- context 'when last deployment to environment is the most recent one' do
+ context "when last deployment to environment is the most recent one" do
before do
- create(:deployment, :success, environment: environment, ref: 'feature')
+ create(:deployment, :success, environment: environment, ref: "feature")
end
it { is_expected.to be true }
end
- context 'when last deployment to environment is not the most recent' do
+ context "when last deployment to environment is not the most recent" do
before do
- create(:deployment, :success, environment: environment, ref: 'feature')
- create(:deployment, :success, environment: environment, ref: 'master')
+ create(:deployment, :success, environment: environment, ref: "feature")
+ create(:deployment, :success, environment: environment, ref: "master")
end
it { is_expected.to be false }
end
end
- describe '#actions_for' do
+ describe "#actions_for" do
let(:deployment) { create(:deployment, :success, environment: environment) }
let(:pipeline) { deployment.deployable.pipeline }
- let!(:review_action) { create(:ci_build, :manual, name: 'review-apps', pipeline: pipeline, environment: 'review/$CI_COMMIT_REF_NAME' )}
- let!(:production_action) { create(:ci_build, :manual, name: 'production', pipeline: pipeline, environment: 'production' )}
+ let!(:review_action) { create(:ci_build, :manual, name: "review-apps", pipeline: pipeline, environment: "review/$CI_COMMIT_REF_NAME")}
+ let!(:production_action) { create(:ci_build, :manual, name: "production", pipeline: pipeline, environment: "production")}
- it 'returns a list of actions with matching environment' do
- expect(environment.actions_for('review/master')).to contain_exactly(review_action)
+ it "returns a list of actions with matching environment" do
+ expect(environment.actions_for("review/master")).to contain_exactly(review_action)
end
end
- describe '.deployments' do
+ describe ".deployments" do
subject { environment.deployments }
- context 'when there is a deployment record with created status' do
+ context "when there is a deployment record with created status" do
let(:deployment) { create(:deployment, :created, environment: environment) }
- it 'does not return the record' do
+ it "does not return the record" do
is_expected.to be_empty
end
end
- context 'when there is a deployment record with running status' do
+ context "when there is a deployment record with running status" do
let(:deployment) { create(:deployment, :running, environment: environment) }
- it 'does not return the record' do
+ it "does not return the record" do
is_expected.to be_empty
end
end
- context 'when there is a deployment record with success status' do
+ context "when there is a deployment record with success status" do
let(:deployment) { create(:deployment, :success, environment: environment) }
- it 'returns the record' do
+ it "returns the record" do
is_expected.to eq([deployment])
end
end
end
- describe '.last_deployment' do
+ describe ".last_deployment" do
subject { environment.last_deployment }
before do
allow_any_instance_of(Deployment).to receive(:create_ref)
end
- context 'when there is an old deployment record' do
+ context "when there is an old deployment record" do
let!(:previous_deployment) { create(:deployment, :success, environment: environment) }
- context 'when there is a deployment record with created status' do
+ context "when there is a deployment record with created status" do
let!(:deployment) { create(:deployment, environment: environment) }
- it 'returns the previous deployment' do
+ it "returns the previous deployment" do
is_expected.to eq(previous_deployment)
end
end
- context 'when there is a deployment record with running status' do
+ context "when there is a deployment record with running status" do
let!(:deployment) { create(:deployment, :running, environment: environment) }
- it 'returns the previous deployment' do
+ it "returns the previous deployment" do
is_expected.to eq(previous_deployment)
end
end
- context 'when there is a deployment record with success status' do
+ context "when there is a deployment record with success status" do
let!(:deployment) { create(:deployment, :success, environment: environment) }
- it 'returns the latest successful deployment' do
+ it "returns the latest successful deployment" do
is_expected.to eq(deployment)
end
end
end
end
- describe '#has_terminals?' do
+ describe "#has_terminals?" do
subject { environment.has_terminals? }
- context 'when the environment is available' do
- context 'with a deployment service' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
- context 'and a deployment' do
+ context "when the environment is available" do
+ context "with a deployment service" do
+ shared_examples "same behavior between KubernetesService and Platform::Kubernetes" do
+ context "and a deployment" do
let!(:deployment) { create(:deployment, :success, environment: environment) }
it { is_expected.to be_truthy }
end
- context 'but no deployments' do
+ context "but no deployments" do
it { is_expected.to be_falsy }
end
end
- context 'when user configured kubernetes from Integration > Kubernetes' do
+ context "when user configured kubernetes from Integration > Kubernetes" do
let(:project) { create(:kubernetes_project) }
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
+ it_behaves_like "same behavior between KubernetesService and Platform::Kubernetes"
end
- context 'when user configured kubernetes from CI/CD > Clusters' do
+ context "when user configured kubernetes from CI/CD > Clusters" do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
+ it_behaves_like "same behavior between KubernetesService and Platform::Kubernetes"
end
end
- context 'without a deployment service' do
+ context "without a deployment service" do
it { is_expected.to be_falsy }
end
end
- context 'when the environment is unavailable' do
+ context "when the environment is unavailable" do
let(:project) { create(:kubernetes_project) }
before do
@@ -554,25 +554,25 @@ describe Environment do
end
end
- describe '#deployment_platform' do
- context 'when there is a deployment platform for environment' do
+ describe "#deployment_platform" do
+ context "when there is a deployment platform for environment" do
let!(:cluster) do
create(:cluster, :provided_by_gcp,
- environment_scope: '*', projects: [project])
+ environment_scope: "*", projects: [project])
end
- it 'finds a deployment platform' do
+ it "finds a deployment platform" do
expect(environment.deployment_platform).to eq cluster.platform
end
end
- context 'when there is no deployment platform for environment' do
- it 'returns nil' do
+ context "when there is no deployment platform for environment" do
+ it "returns nil" do
expect(environment.deployment_platform).to be_nil
end
end
- it 'checks deployment platforms associated with a project' do
+ it "checks deployment platforms associated with a project" do
expect(project).to receive(:deployment_platform)
.with(environment: environment.name)
@@ -580,16 +580,16 @@ describe Environment do
end
end
- describe '#terminals' do
+ describe "#terminals" do
subject { environment.terminals }
- context 'when the environment has terminals' do
+ context "when the environment has terminals" do
before do
allow(environment).to receive(:has_terminals?).and_return(true)
end
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
- it 'returns the terminals from the deployment service' do
+ shared_examples "same behavior between KubernetesService and Platform::Kubernetes" do
+ it "returns the terminals from the deployment service" do
expect(project.deployment_platform)
.to receive(:terminals).with(environment)
.and_return(:fake_terminals)
@@ -598,21 +598,21 @@ describe Environment do
end
end
- context 'when user configured kubernetes from Integration > Kubernetes' do
+ context "when user configured kubernetes from Integration > Kubernetes" do
let(:project) { create(:kubernetes_project) }
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
+ it_behaves_like "same behavior between KubernetesService and Platform::Kubernetes"
end
- context 'when user configured kubernetes from CI/CD > Clusters' do
+ context "when user configured kubernetes from CI/CD > Clusters" do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
+ it_behaves_like "same behavior between KubernetesService and Platform::Kubernetes"
end
end
- context 'when the environment does not have terminals' do
+ context "when the environment does not have terminals" do
before do
allow(environment).to receive(:has_terminals?).and_return(false)
end
@@ -621,29 +621,29 @@ describe Environment do
end
end
- describe '#has_metrics?' do
+ describe "#has_metrics?" do
subject { environment.has_metrics? }
- context 'when the environment is available' do
- context 'with a deployment service' do
+ context "when the environment is available" do
+ context "with a deployment service" do
let(:project) { create(:prometheus_project) }
- context 'and a deployment' do
+ context "and a deployment" do
let!(:deployment) { create(:deployment, environment: environment) }
it { is_expected.to be_truthy }
end
- context 'and no deployments' do
+ context "and no deployments" do
it { is_expected.to be_truthy }
end
end
- context 'without a monitoring service' do
+ context "without a monitoring service" do
it { is_expected.to be_falsy }
end
end
- context 'when the environment is unavailable' do
+ context "when the environment is unavailable" do
let(:project) { create(:prometheus_project) }
before do
@@ -654,16 +654,16 @@ describe Environment do
end
end
- describe '#metrics' do
+ describe "#metrics" do
let(:project) { create(:prometheus_project) }
subject { environment.metrics }
- context 'when the environment has metrics' do
+ context "when the environment has metrics" do
before do
allow(environment).to receive(:has_metrics?).and_return(true)
end
- it 'returns the metrics from the deployment service' do
+ it "returns the metrics from the deployment service" do
expect(environment.prometheus_adapter)
.to receive(:query).with(:environment, environment)
.and_return(:fake_metrics)
@@ -672,7 +672,7 @@ describe Environment do
end
end
- context 'when the environment does not have metrics' do
+ context "when the environment does not have metrics" do
before do
allow(environment).to receive(:has_metrics?).and_return(false)
end
@@ -681,25 +681,25 @@ describe Environment do
end
end
- describe '#additional_metrics' do
+ describe "#additional_metrics" do
let(:project) { create(:prometheus_project) }
subject { environment.additional_metrics }
- context 'when the environment has additional metrics' do
+ context "when the environment has additional metrics" do
before do
allow(environment).to receive(:has_metrics?).and_return(true)
end
- it 'returns the additional metrics from the deployment service' do
+ it "returns the additional metrics from the deployment service" do
expect(environment.prometheus_adapter).to receive(:query)
- .with(:additional_metrics_environment, environment)
- .and_return(:fake_metrics)
+ .with(:additional_metrics_environment, environment)
+ .and_return(:fake_metrics)
is_expected.to eq(:fake_metrics)
end
end
- context 'when the environment does not have metrics' do
+ context "when the environment does not have metrics" do
before do
allow(environment).to receive(:has_metrics?).and_return(false)
end
@@ -708,7 +708,7 @@ describe Environment do
end
end
- describe '#slug' do
+ describe "#slug" do
it "is automatically generated" do
expect(environment.slug).not_to be_nil
end
@@ -730,23 +730,23 @@ describe Environment do
end
end
- describe '#generate_slug' do
+ describe "#generate_slug" do
SUFFIX = "-[a-z0-9]{6}".freeze
{
"staging-12345678901234567" => "staging-123456789" + SUFFIX,
"9-staging-123456789012345" => "env-9-staging-123" + SUFFIX,
- "staging-1234567890123456" => "staging-1234567890123456",
- "production" => "production",
- "PRODUCTION" => "production" + SUFFIX,
- "review/1-foo" => "review-1-foo" + SUFFIX,
- "1-foo" => "env-1-foo" + SUFFIX,
- "1/foo" => "env-1-foo" + SUFFIX,
- "foo-" => "foo" + SUFFIX,
- "foo--bar" => "foo-bar" + SUFFIX,
- "foo**bar" => "foo-bar" + SUFFIX,
- "*-foo" => "env-foo" + SUFFIX,
- "staging-12345678-" => "staging-12345678" + SUFFIX,
- "staging-12345678-01234567" => "staging-12345678" + SUFFIX
+ "staging-1234567890123456" => "staging-1234567890123456",
+ "production" => "production",
+ "PRODUCTION" => "production" + SUFFIX,
+ "review/1-foo" => "review-1-foo" + SUFFIX,
+ "1-foo" => "env-1-foo" + SUFFIX,
+ "1/foo" => "env-1-foo" + SUFFIX,
+ "foo-" => "foo" + SUFFIX,
+ "foo--bar" => "foo-bar" + SUFFIX,
+ "foo**bar" => "foo-bar" + SUFFIX,
+ "*-foo" => "env-foo" + SUFFIX,
+ "staging-12345678-" => "staging-12345678" + SUFFIX,
+ "staging-12345678-01234567" => "staging-12345678" + SUFFIX,
}.each do |name, matcher|
it "returns a slug matching #{matcher}, given #{name}" do
slug = described_class.new(name: name).generate_slug
@@ -756,13 +756,13 @@ describe Environment do
end
end
- describe '#ref_path' do
+ describe "#ref_path" do
subject(:environment) do
- create(:environment, name: 'staging / review-1')
+ create(:environment, name: "staging / review-1")
end
- it 'returns a path that uses the slug and does not have spaces' do
- expect(environment.ref_path).to start_with('refs/environments/staging-review-1-')
+ it "returns a path that uses the slug and does not have spaces" do
+ expect(environment.ref_path).to start_with("refs/environments/staging-review-1-")
end
it "doesn't change when the slug is nil initially" do
@@ -772,37 +772,37 @@ describe Environment do
end
end
- describe '#external_url_for' do
- let(:source_path) { 'source/file.html' }
+ describe "#external_url_for" do
+ let(:source_path) { "source/file.html" }
let(:sha) { RepoHelpers.sample_commit.id }
before do
- environment.external_url = 'http://example.com'
+ environment.external_url = "http://example.com"
end
- context 'when the public path is not known' do
+ context "when the public path is not known" do
before do
allow(project).to receive(:public_path_for_source_path).with(source_path, sha).and_return(nil)
end
- it 'returns nil' do
+ it "returns nil" do
expect(environment.external_url_for(source_path, sha)).to be_nil
end
end
- context 'when the public path is known' do
+ context "when the public path is known" do
before do
- allow(project).to receive(:public_path_for_source_path).with(source_path, sha).and_return('file.html')
+ allow(project).to receive(:public_path_for_source_path).with(source_path, sha).and_return("file.html")
end
- it 'returns the full external URL' do
- expect(environment.external_url_for(source_path, sha)).to eq('http://example.com/file.html')
+ it "returns the full external URL" do
+ expect(environment.external_url_for(source_path, sha)).to eq("http://example.com/file.html")
end
end
end
- describe '#prometheus_adapter' do
- it 'calls prometheus adapter service' do
+ describe "#prometheus_adapter" do
+ it "calls prometheus adapter service" do
expect_any_instance_of(Prometheus::AdapterService).to receive(:prometheus_adapter)
subject.prometheus_adapter
diff --git a/spec/models/environment_status_spec.rb b/spec/models/environment_status_spec.rb
index 9da16dea929..127e00b0581 100644
--- a/spec/models/environment_status_spec.rb
+++ b/spec/models/environment_status_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe EnvironmentStatus do
include ProjectForksHelper
@@ -17,19 +17,19 @@ describe EnvironmentStatus do
it { is_expected.to delegate_method(:deployed_at).to(:deployment) }
it { is_expected.to delegate_method(:status).to(:deployment) }
- describe '#project' do
+ describe "#project" do
subject { environment_status.project }
it { is_expected.to eq(project) }
end
- describe '#merge_request' do
+ describe "#merge_request" do
subject { environment_status.merge_request }
it { is_expected.to eq(merge_request) }
end
- describe '#deployment' do
+ describe "#deployment" do
subject { environment_status.deployment }
it { is_expected.to eq(deployment) }
@@ -49,25 +49,25 @@ describe EnvironmentStatus do
#
# - source: /files\/(.+)/
# public: '\1'
- describe '#changes' do
- it 'contains only added and modified public pages' do
+ describe "#changes" do
+ it "contains only added and modified public pages" do
expect(environment_status.changes).to contain_exactly(
{
- path: 'ruby-style-guide.html',
- external_url: "#{environment.external_url}/ruby-style-guide.html"
+ path: "ruby-style-guide.html",
+ external_url: "#{environment.external_url}/ruby-style-guide.html",
}, {
- path: 'html/page.html',
- external_url: "#{environment.external_url}/html/page.html"
+ path: "html/page.html",
+ external_url: "#{environment.external_url}/html/page.html",
}
)
end
end
- describe '.for_merge_request' do
+ describe ".for_merge_request" do
let(:admin) { create(:admin) }
let(:pipeline) { create(:ci_pipeline, sha: sha) }
- it 'is based on merge_request.diff_head_sha' do
+ it "is based on merge_request.diff_head_sha" do
expect(merge_request).to receive(:diff_head_sha)
expect(merge_request).not_to receive(:merge_commit_sha)
@@ -75,7 +75,7 @@ describe EnvironmentStatus do
end
end
- describe '.after_merge_request' do
+ describe ".after_merge_request" do
let(:admin) { create(:admin) }
let(:pipeline) { create(:ci_pipeline, sha: sha) }
@@ -83,7 +83,7 @@ describe EnvironmentStatus do
merge_request.mark_as_merged!
end
- it 'is based on merge_request.merge_commit_sha' do
+ it "is based on merge_request.merge_commit_sha" do
expect(merge_request).to receive(:merge_commit_sha)
expect(merge_request).not_to receive(:diff_head_sha)
@@ -91,14 +91,14 @@ describe EnvironmentStatus do
end
end
- describe '.build_environments_status' do
+ describe ".build_environments_status" do
subject { described_class.send(:build_environments_status, merge_request, user, pipeline) }
let!(:build) { create(:ci_build, :deploy_to_production, pipeline: pipeline) }
let(:environment) { build.deployment.environment }
let(:user) { project.owner }
- context 'when environment is created on a forked project' do
+ context "when environment is created on a forked project" do
let(:project) { create(:project, :repository) }
let(:forked) { fork_project(project, user, repository: true) }
let(:sha) { forked.commit.sha }
@@ -106,13 +106,13 @@ describe EnvironmentStatus do
let(:merge_request) do
create(:merge_request,
- source_project: forked,
- target_project: project,
- target_branch: 'master',
- head_pipeline: pipeline)
+ source_project: forked,
+ target_project: project,
+ target_branch: "master",
+ head_pipeline: pipeline)
end
- it 'returns environment status' do
+ it "returns environment status" do
expect(subject.count).to eq(1)
expect(subject[0].environment).to eq(environment)
expect(subject[0].merge_request).to eq(merge_request)
@@ -120,48 +120,48 @@ describe EnvironmentStatus do
end
end
- context 'when environment is created on a target project' do
+ context "when environment is created on a target project" do
let(:project) { create(:project, :repository) }
let(:sha) { project.commit.sha }
let(:pipeline) { create(:ci_pipeline, sha: sha, project: project) }
let(:merge_request) do
create(:merge_request,
- source_project: project,
- source_branch: 'feature',
- target_project: project,
- target_branch: 'master',
- head_pipeline: pipeline)
+ source_project: project,
+ source_branch: "feature",
+ target_project: project,
+ target_branch: "master",
+ head_pipeline: pipeline)
end
- it 'returns environment status' do
+ it "returns environment status" do
expect(subject.count).to eq(1)
expect(subject[0].environment).to eq(environment)
expect(subject[0].merge_request).to eq(merge_request)
expect(subject[0].sha).to eq(sha)
end
- context 'when the build stops an environment' do
+ context "when the build stops an environment" do
let!(:build) { create(:ci_build, :stop_review_app, pipeline: pipeline) }
- it 'does not return environment status' do
+ it "does not return environment status" do
expect(subject.count).to eq(0)
end
end
- context 'when user does not have a permission to see the environment' do
+ context "when user does not have a permission to see the environment" do
let(:user) { create(:user) }
- it 'does not return environment status' do
+ it "does not return environment status" do
expect(subject.count).to eq(0)
end
end
- context 'when multiple deployments with the same SHA in different environments' do
+ context "when multiple deployments with the same SHA in different environments" do
let(:pipeline2) { create(:ci_pipeline, sha: sha, project: project) }
let!(:build2) { create(:ci_build, :start_review_app, pipeline: pipeline2) }
- it 'returns deployments related to the head pipeline' do
+ it "returns deployments related to the head pipeline" do
expect(subject.count).to eq(1)
expect(subject[0].environment).to eq(environment)
expect(subject[0].merge_request).to eq(merge_request)
@@ -169,10 +169,10 @@ describe EnvironmentStatus do
end
end
- context 'when multiple deployments in the same pipeline for the same environments' do
+ context "when multiple deployments in the same pipeline for the same environments" do
let!(:build2) { create(:ci_build, :deploy_to_production, pipeline: pipeline) }
- it 'returns unique entries' do
+ it "returns unique entries" do
expect(subject.count).to eq(1)
expect(subject[0].environment).to eq(environment)
expect(subject[0].merge_request).to eq(merge_request)
@@ -180,12 +180,12 @@ describe EnvironmentStatus do
end
end
- context 'when environment is stopped' do
+ context "when environment is stopped" do
before do
environment.stop!
end
- it 'does not return environment status' do
+ it "does not return environment status" do
expect(subject.count).to eq(0)
end
end
diff --git a/spec/models/error_tracking/project_error_tracking_setting_spec.rb b/spec/models/error_tracking/project_error_tracking_setting_spec.rb
index 076ccc96041..79f1d8a783c 100644
--- a/spec/models/error_tracking/project_error_tracking_setting_spec.rb
+++ b/spec/models/error_tracking/project_error_tracking_setting_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe ErrorTracking::ProjectErrorTrackingSetting do
include ReactiveCachingHelpers
@@ -9,35 +9,35 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
subject { create(:project_error_tracking_setting, project: project) }
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to(:project) }
end
- describe 'Validations' do
- context 'when api_url is over 255 chars' do
+ describe "Validations" do
+ context "when api_url is over 255 chars" do
before do
- subject.api_url = 'https://' + 'a' * 250
+ subject.api_url = "https://" + "a" * 250
end
- it 'fails validation' do
+ it "fails validation" do
expect(subject).not_to be_valid
- expect(subject.errors.messages[:api_url]).to include('is too long (maximum is 255 characters)')
+ expect(subject.errors.messages[:api_url]).to include("is too long (maximum is 255 characters)")
end
end
- context 'With unsafe url' do
- it 'fails validation' do
+ context "With unsafe url" do
+ it "fails validation" do
subject.api_url = "https://replaceme.com/'><script>alert(document.cookie)</script>"
expect(subject).not_to be_valid
end
end
- context 'presence validations' do
+ context "presence validations" do
using RSpec::Parameterized::TableSyntax
- valid_api_url = 'http://example.com/api/0/projects/org-slug/proj-slug/'
- valid_token = 'token'
+ valid_api_url = "http://example.com/api/0/projects/org-slug/proj-slug/"
+ valid_token = "token"
where(:enabled, :token, :api_url, :valid?) do
true | nil | nil | false
@@ -61,66 +61,66 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
end
end
- context 'URL path' do
- it 'fails validation with wrong path' do
- subject.api_url = 'http://gitlab.com/project1/something'
+ context "URL path" do
+ it "fails validation with wrong path" do
+ subject.api_url = "http://gitlab.com/project1/something"
expect(subject).not_to be_valid
- expect(subject.errors.messages[:api_url]).to include('path needs to start with /api/0/projects')
+ expect(subject.errors.messages[:api_url]).to include("path needs to start with /api/0/projects")
end
- it 'passes validation with correct path' do
- subject.api_url = 'http://gitlab.com/api/0/projects/project1/something'
+ it "passes validation with correct path" do
+ subject.api_url = "http://gitlab.com/api/0/projects/project1/something"
expect(subject).to be_valid
end
end
- context 'non ascii chars in api_url' do
+ context "non ascii chars in api_url" do
before do
- subject.api_url = 'http://gitlab.com/api/0/projects/project1/something€'
+ subject.api_url = "http://gitlab.com/api/0/projects/project1/something€"
end
- it 'fails validation' do
+ it "fails validation" do
expect(subject).not_to be_valid
end
end
end
- describe '#sentry_external_url' do
- let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project' }
+ describe "#sentry_external_url" do
+ let(:sentry_url) { "https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project" }
before do
subject.api_url = sentry_url
end
- it 'returns the correct url' do
+ it "returns the correct url" do
expect(subject.class).to receive(:extract_sentry_external_url).with(sentry_url).and_call_original
result = subject.sentry_external_url
- expect(result).to eq('https://sentrytest.gitlab.com/sentry-org/sentry-project')
+ expect(result).to eq("https://sentrytest.gitlab.com/sentry-org/sentry-project")
end
end
- describe '#sentry_client' do
- it 'returns sentry client' do
+ describe "#sentry_client" do
+ it "returns sentry client" do
expect(subject.sentry_client).to be_a(Sentry::Client)
end
end
- describe '#list_sentry_issues' do
+ describe "#list_sentry_issues" do
let(:issues) { [:list, :of, :issues] }
let(:opts) do
- { issue_status: 'unresolved', limit: 10 }
+ {issue_status: "unresolved", limit: 10}
end
let(:result) do
subject.list_sentry_issues(**opts)
end
- context 'when cached' do
+ context "when cached" do
let(:sentry_client) { spy(:sentry_client) }
before do
@@ -130,7 +130,7 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
expect(subject).to receive(:sentry_client).and_return(sentry_client)
end
- it 'returns cached issues' do
+ it "returns cached issues" do
expect(sentry_client).to receive(:list_issues).with(opts)
.and_return(issues)
@@ -138,15 +138,15 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
end
end
- context 'when not cached' do
- it 'returns nil' do
+ context "when not cached" do
+ it "returns nil" do
expect(subject).not_to receive(:sentry_client)
expect(result).to be_nil
end
end
- context 'when sentry client raises exception' do
+ context "when sentry client raises exception" do
let(:sentry_client) { spy(:sentry_client) }
before do
@@ -154,22 +154,22 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
allow(subject).to receive(:sentry_client).and_return(sentry_client)
allow(sentry_client).to receive(:list_issues).with(opts)
- .and_raise(Sentry::Client::Error, 'error message')
+ .and_raise(Sentry::Client::Error, "error message")
end
- it 'returns error' do
- expect(result).to eq(error: 'error message')
+ it "returns error" do
+ expect(result).to eq(error: "error message")
expect(subject).to have_received(:sentry_client)
expect(sentry_client).to have_received(:list_issues)
end
end
end
- describe '#list_sentry_projects' do
+ describe "#list_sentry_projects" do
let(:projects) { [:list, :of, :projects] }
let(:sentry_client) { spy(:sentry_client) }
- it 'calls sentry client' do
+ it "calls sentry client" do
expect(subject).to receive(:sentry_client).and_return(sentry_client)
expect(sentry_client).to receive(:list_projects).and_return(projects)
@@ -179,60 +179,60 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
end
end
- context 'slugs' do
- shared_examples_for 'slug from api_url' do |method, slug|
- context 'when api_url is correct' do
+ context "slugs" do
+ shared_examples_for "slug from api_url" do |method, slug|
+ context "when api_url is correct" do
before do
- subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug/'
+ subject.api_url = "http://gitlab.com/api/0/projects/org-slug/project-slug/"
end
- it 'returns slug' do
+ it "returns slug" do
expect(subject.public_send(method)).to eq(slug)
end
end
- context 'when api_url is blank' do
+ context "when api_url is blank" do
before do
subject.api_url = nil
end
- it 'returns nil' do
+ it "returns nil" do
expect(subject.public_send(method)).to be_nil
end
end
end
- it_behaves_like 'slug from api_url', :project_slug, 'project-slug'
- it_behaves_like 'slug from api_url', :organization_slug, 'org-slug'
+ it_behaves_like "slug from api_url", :project_slug, "project-slug"
+ it_behaves_like "slug from api_url", :organization_slug, "org-slug"
end
- context 'names from api_url' do
- shared_examples_for 'name from api_url' do |name, titleized_slug|
- context 'name is present in DB' do
- it 'returns name from DB' do
- subject[name] = 'Sentry name'
- subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug'
+ context "names from api_url" do
+ shared_examples_for "name from api_url" do |name, titleized_slug|
+ context "name is present in DB" do
+ it "returns name from DB" do
+ subject[name] = "Sentry name"
+ subject.api_url = "http://gitlab.com/api/0/projects/org-slug/project-slug"
- expect(subject.public_send(name)).to eq('Sentry name')
+ expect(subject.public_send(name)).to eq("Sentry name")
end
end
- context 'name is null in DB' do
- it 'titleizes and returns slug from api_url' do
+ context "name is null in DB" do
+ it "titleizes and returns slug from api_url" do
subject[name] = nil
- subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug'
+ subject.api_url = "http://gitlab.com/api/0/projects/org-slug/project-slug"
expect(subject.public_send(name)).to eq(titleized_slug)
end
- it 'returns nil when api_url is incorrect' do
+ it "returns nil when api_url is incorrect" do
subject[name] = nil
- subject.api_url = 'http://gitlab.com/api/0/projects/'
+ subject.api_url = "http://gitlab.com/api/0/projects/"
expect(subject.public_send(name)).to be_nil
end
- it 'returns nil when api_url is blank' do
+ it "returns nil when api_url is blank" do
subject[name] = nil
subject.api_url = nil
@@ -241,59 +241,59 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
end
end
- it_behaves_like 'name from api_url', :organization_name, 'Org Slug'
- it_behaves_like 'name from api_url', :project_name, 'Project Slug'
+ it_behaves_like "name from api_url", :organization_name, "Org Slug"
+ it_behaves_like "name from api_url", :project_name, "Project Slug"
end
- describe '.build_api_url_from' do
- it 'correctly builds api_url with slugs' do
+ describe ".build_api_url_from" do
+ it "correctly builds api_url with slugs" do
api_url = described_class.build_api_url_from(
- api_host: 'http://sentry.com/',
- organization_slug: 'org-slug',
- project_slug: 'proj-slug'
+ api_host: "http://sentry.com/",
+ organization_slug: "org-slug",
+ project_slug: "proj-slug"
)
- expect(api_url).to eq('http://sentry.com/api/0/projects/org-slug/proj-slug/')
+ expect(api_url).to eq("http://sentry.com/api/0/projects/org-slug/proj-slug/")
end
- it 'correctly builds api_url without slugs' do
+ it "correctly builds api_url without slugs" do
api_url = described_class.build_api_url_from(
- api_host: 'http://sentry.com/',
+ api_host: "http://sentry.com/",
organization_slug: nil,
project_slug: nil
)
- expect(api_url).to eq('http://sentry.com/api/0/projects/')
+ expect(api_url).to eq("http://sentry.com/api/0/projects/")
end
- it 'does not raise exception with invalid url' do
+ it "does not raise exception with invalid url" do
api_url = described_class.build_api_url_from(
- api_host: ':::',
- organization_slug: 'org-slug',
- project_slug: 'proj-slug'
+ api_host: ":::",
+ organization_slug: "org-slug",
+ project_slug: "proj-slug"
)
- expect(api_url).to eq(':::')
+ expect(api_url).to eq(":::")
end
end
- describe '#api_host' do
- context 'when api_url exists' do
+ describe "#api_host" do
+ context "when api_url exists" do
before do
- subject.api_url = 'https://example.com/api/0/projects/org-slug/proj-slug/'
+ subject.api_url = "https://example.com/api/0/projects/org-slug/proj-slug/"
end
- it 'extracts the api_host from api_url' do
- expect(subject.api_host).to eq('https://example.com/')
+ it "extracts the api_host from api_url" do
+ expect(subject.api_host).to eq("https://example.com/")
end
end
- context 'when api_url is nil' do
+ context "when api_url is nil" do
before do
subject.api_url = nil
end
- it 'returns nil' do
+ it "returns nil" do
expect(subject.api_url).to eq(nil)
end
end
diff --git a/spec/models/event_collection_spec.rb b/spec/models/event_collection_spec.rb
index 6078f429bdc..bd61bb45d4d 100644
--- a/spec/models/event_collection_spec.rb
+++ b/spec/models/event_collection_spec.rb
@@ -1,7 +1,7 @@
-require 'spec_helper'
+require "spec_helper"
describe EventCollection do
- describe '#to_a' do
+ describe "#to_a" do
let(:project) { create(:project_empty_repo) }
let(:projects) { Project.where(id: project.id) }
let(:user) { create(:user) }
@@ -16,31 +16,31 @@ describe EventCollection do
create(:closed_issue_event, project: project, author: user)
end
- it 'returns an Array of events' do
+ it "returns an Array of events" do
events = described_class.new(projects).to_a
expect(events).to be_an_instance_of(Array)
end
- it 'applies a limit to the number of events' do
+ it "applies a limit to the number of events" do
events = described_class.new(projects).to_a
expect(events.length).to eq(20)
end
- it 'can paginate through events' do
+ it "can paginate through events" do
events = described_class.new(projects, offset: 20).to_a
expect(events.length).to eq(1)
end
- it 'returns an empty Array when crossing the maximum page number' do
+ it "returns an empty Array when crossing the maximum page number" do
events = described_class.new(projects, limit: 1, offset: 15).to_a
expect(events).to be_empty
end
- it 'allows filtering of events using an EventFilter' do
+ it "allows filtering of events using an EventFilter" do
filter = EventFilter.new(EventFilter::ISSUE)
events = described_class.new(projects, filter: filter).to_a
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index ce4f8ee4705..92549b8bbd4 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Event do
describe "Associations" do
@@ -13,20 +13,20 @@ describe Event do
it { is_expected.to respond_to(:merge_request_title) }
end
- describe 'Callbacks' do
+ describe "Callbacks" do
let(:project) { create(:project) }
- describe 'after_create :reset_project_activity' do
- it 'calls the reset_project_activity method' do
+ describe "after_create :reset_project_activity" do
+ it "calls the reset_project_activity method" do
expect_any_instance_of(described_class).to receive(:reset_project_activity)
create_push_event(project, project.owner)
end
end
- describe 'after_create :set_last_repository_updated_at' do
- context 'with a push event' do
- it 'updates the project last_repository_updated_at' do
+ describe "after_create :set_last_repository_updated_at" do
+ context "with a push event" do
+ it "updates the project last_repository_updated_at" do
project.update(last_repository_updated_at: 1.year.ago)
create_push_event(project, project.owner)
@@ -37,8 +37,8 @@ describe Event do
end
end
- context 'without a push event' do
- it 'does not update the project last_repository_updated_at' do
+ context "without a push event" do
+ it "does not update the project last_repository_updated_at" do
project.update(last_repository_updated_at: 1.year.ago)
create(:closed_issue_event, project: project, author: project.owner)
@@ -50,29 +50,29 @@ describe Event do
end
end
- describe '#set_last_repository_updated_at' do
- it 'only updates once every Event::REPOSITORY_UPDATED_AT_INTERVAL minutes' do
+ describe "#set_last_repository_updated_at" do
+ it "only updates once every Event::REPOSITORY_UPDATED_AT_INTERVAL minutes" do
last_known_timestamp = (Event::REPOSITORY_UPDATED_AT_INTERVAL - 1.minute).ago
project.update(last_repository_updated_at: last_known_timestamp)
project.reload # a reload removes fractions of seconds
- expect do
+ expect {
create_push_event(project, project.owner)
project.reload
- end.not_to change { project.last_repository_updated_at }
+ }.not_to change { project.last_repository_updated_at }
end
end
- describe 'after_create :track_user_interacted_projects' do
+ describe "after_create :track_user_interacted_projects" do
let(:event) { build(:push_event, project: project, author: project.owner) }
- it 'passes event to UserInteractedProject.track' do
+ it "passes event to UserInteractedProject.track" do
expect(UserInteractedProject).to receive(:available?).and_return(true)
expect(UserInteractedProject).to receive(:track).with(event)
event.save
end
- it 'does not call UserInteractedProject.track if its not yet available' do
+ it "does not call UserInteractedProject.track if its not yet available" do
expect(UserInteractedProject).to receive(:available?).and_return(false)
expect(UserInteractedProject).not_to receive(:track)
event.save
@@ -95,7 +95,7 @@ describe Event do
end
end
- describe '#membership_changed?' do
+ describe "#membership_changed?" do
context "created" do
subject { build(:event, :created).membership_changed? }
it { is_expected.to be_falsey }
@@ -122,23 +122,23 @@ describe Event do
end
end
- describe '#note?' do
+ describe "#note?" do
subject { described_class.new(project: target.project, target: target) }
- context 'issue note event' do
+ context "issue note event" do
let(:target) { create(:note_on_issue) }
it { is_expected.to be_note }
end
- context 'merge request diff note event' do
+ context "merge request diff note event" do
let(:target) { create(:legacy_diff_note_on_merge_request) }
it { is_expected.to be_note }
end
end
- describe '#visible_to_user?' do
+ describe "#visible_to_user?" do
let(:project) { create(:project, :public) }
let(:non_member) { create(:user) }
let(:member) { create(:user) }
@@ -163,7 +163,7 @@ describe Event do
project.add_guest(guest)
end
- context 'commit note event' do
+ context "commit note event" do
let(:target) { note_on_commit }
it do
@@ -175,7 +175,7 @@ describe Event do
end
end
- context 'private project' do
+ context "private project" do
let(:project) { create(:project, :private) }
it do
@@ -189,8 +189,8 @@ describe Event do
end
end
- context 'issue event' do
- context 'for non confidential issues' do
+ context "issue event" do
+ context "for non confidential issues" do
let(:target) { issue }
it do
@@ -203,7 +203,7 @@ describe Event do
end
end
- context 'for confidential issues' do
+ context "for confidential issues" do
let(:target) { confidential_issue }
it do
@@ -217,8 +217,8 @@ describe Event do
end
end
- context 'issue note event' do
- context 'on non confidential issues' do
+ context "issue note event" do
+ context "on non confidential issues" do
let(:target) { note_on_issue }
it do
@@ -231,7 +231,7 @@ describe Event do
end
end
- context 'on confidential issues' do
+ context "on confidential issues" do
let(:target) { note_on_confidential_issue }
it do
@@ -244,7 +244,7 @@ describe Event do
end
end
- context 'private project' do
+ context "private project" do
let(:project) { create(:project, :private) }
let(:target) { note_on_issue }
@@ -259,7 +259,7 @@ describe Event do
end
end
- context 'merge request diff note event' do
+ context "merge request diff note event" do
let(:project) { create(:project, :public) }
let(:merge_request) { create(:merge_request, source_project: project, author: author, assignee: assignee) }
let(:note_on_merge_request) { create(:legacy_diff_note_on_merge_request, noteable: merge_request, project: project) }
@@ -274,7 +274,7 @@ describe Event do
expect(event.visible_to_user?(admin)).to eq true
end
- context 'private project' do
+ context "private project" do
let(:project) { create(:project, :private) }
it do
@@ -288,7 +288,7 @@ describe Event do
end
end
- context 'milestone event' do
+ context "milestone event" do
let(:target) { milestone_on_project }
it do
@@ -299,7 +299,7 @@ describe Event do
expect(event.visible_to_user?(admin)).to be_truthy
end
- context 'on public project with private issue tracker and merge requests' do
+ context "on public project with private issue tracker and merge requests" do
let(:project) { create(:project, :public, :issues_private, :merge_requests_private) }
it do
@@ -311,7 +311,7 @@ describe Event do
end
end
- context 'on private project' do
+ context "on private project" do
let(:project) { create(:project, :private) }
it do
@@ -324,7 +324,7 @@ describe Event do
end
end
- context 'project snippet note event' do
+ context "project snippet note event" do
let(:target) { note_on_project_snippet }
it do
@@ -336,7 +336,7 @@ describe Event do
expect(event.visible_to_user?(admin)).to be_truthy
end
- context 'on public project with private snippets' do
+ context "on public project with private snippets" do
let(:project) { create(:project, :public, :snippets_private) }
it do
@@ -353,7 +353,7 @@ describe Event do
end
end
- context 'on private project' do
+ context "on private project" do
let(:project) { create(:project, :private) }
it do
@@ -371,7 +371,7 @@ describe Event do
end
end
- context 'personal snippet note event' do
+ context "personal snippet note event" do
let(:target) { note_on_personal_snippet }
it do
@@ -381,7 +381,7 @@ describe Event do
expect(event.visible_to_user?(admin)).to be_truthy
end
- context 'on internal snippet' do
+ context "on internal snippet" do
let(:personal_snippet) { create(:personal_snippet, :internal, author: author) }
it do
@@ -392,7 +392,7 @@ describe Event do
end
end
- context 'on private snippet' do
+ context "on private snippet" do
let(:personal_snippet) { create(:personal_snippet, :private, author: author) }
it do
@@ -405,28 +405,28 @@ describe Event do
end
end
- describe '.limit_recent' do
+ describe ".limit_recent" do
let!(:event1) { create(:closed_issue_event) }
let!(:event2) { create(:closed_issue_event) }
- describe 'without an explicit limit' do
+ describe "without an explicit limit" do
subject { described_class.limit_recent }
it { is_expected.to eq([event2, event1]) }
end
- describe 'with an explicit limit' do
+ describe "with an explicit limit" do
subject { described_class.limit_recent(1) }
it { is_expected.to eq([event2]) }
end
end
- describe '#reset_project_activity' do
+ describe "#reset_project_activity" do
let(:project) { create(:project) }
- context 'when a project was updated less than 1 hour ago' do
- it 'does not update the project' do
+ context "when a project was updated less than 1 hour ago" do
+ it "does not update the project" do
project.update(last_activity_at: Time.now)
expect(project).not_to receive(:update_column)
@@ -436,8 +436,8 @@ describe Event do
end
end
- context 'when a project was updated more than 1 hour ago' do
- it 'updates the project' do
+ context "when a project was updated more than 1 hour ago" do
+ it "updates the project" do
project.update(last_activity_at: 1.year.ago)
create_push_event(project, project.owner)
@@ -449,25 +449,25 @@ describe Event do
end
end
- describe '#authored_by?' do
+ describe "#authored_by?" do
let(:event) { build(:event) }
- it 'returns true when the event author and user are the same' do
+ it "returns true when the event author and user are the same" do
expect(event.authored_by?(event.author)).to eq(true)
end
- it 'returns false when passing nil as an argument' do
+ it "returns false when passing nil as an argument" do
expect(event.authored_by?(nil)).to eq(false)
end
- it 'returns false when the given user is not the author of the event' do
+ it "returns false when the given user is not the author of the event" do
user = double(:user, id: -1)
expect(event.authored_by?(user)).to eq(false)
end
end
- describe '#body?' do
+ describe "#body?" do
let(:push_event) do
event = build(:push_event)
@@ -476,19 +476,19 @@ describe Event do
event
end
- it 'returns true for a push event with commits' do
+ it "returns true for a push event with commits" do
allow(push_event).to receive(:push_with_commits?).and_return(true)
expect(push_event).to be_body
end
- it 'returns false for a push event without a valid commit range' do
+ it "returns false for a push event without a valid commit range" do
allow(push_event).to receive(:push_with_commits?).and_return(false)
expect(push_event).not_to be_body
end
- it 'returns true for a Note event' do
+ it "returns true for a Note event" do
event = build(:event)
allow(event).to receive(:note?).and_return(true)
@@ -496,23 +496,23 @@ describe Event do
expect(event).to be_body
end
- it 'returns true if the target responds to #title' do
+ it "returns true if the target responds to #title" do
event = build(:event)
- allow(event).to receive(:target).and_return(double(:target, title: 'foo'))
+ allow(event).to receive(:target).and_return(double(:target, title: "foo"))
expect(event).to be_body
end
- it 'returns false for a regular event without a target' do
+ it "returns false for a regular event without a target" do
event = build(:event)
expect(event).not_to be_body
end
end
- describe '#target' do
- it 'eager loads the author of an event target' do
+ describe "#target" do
+ it "eager loads the author of an event target" do
create(:closed_issue_event)
events = described_class.preload(:target).all.to_a
@@ -531,10 +531,10 @@ describe Event do
event = create(:push_event, project: project, author: user)
create(:push_event_payload,
- event: event,
- commit_to: '1cf19a015df3523caf0a1f9d40c98a267d6a2fc2',
- commit_count: 0,
- ref: 'master')
+ event: event,
+ commit_to: "1cf19a015df3523caf0a1f9d40c98a267d6a2fc2",
+ commit_count: 0,
+ ref: "master")
event
end
diff --git a/spec/models/external_issue_spec.rb b/spec/models/external_issue_spec.rb
index 83ba22caa03..7f9b7014974 100644
--- a/spec/models/external_issue_spec.rb
+++ b/spec/models/external_issue_spec.rb
@@ -1,50 +1,50 @@
-require 'spec_helper'
+require "spec_helper"
describe ExternalIssue do
- let(:project) { double('project', id: 1, to_reference: 'namespace1/project1') }
- let(:issue) { described_class.new('EXT-1234', project) }
+ let(:project) { double("project", id: 1, to_reference: "namespace1/project1") }
+ let(:issue) { described_class.new("EXT-1234", project) }
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Referable) }
end
- describe '#to_reference' do
- it 'returns a String reference to the object' do
+ describe "#to_reference" do
+ it "returns a String reference to the object" do
expect(issue.to_reference).to eq issue.id
end
end
- describe '#title' do
- it 'returns a title' do
+ describe "#title" do
+ it "returns a title" do
expect(issue.title).to eq "External Issue #{issue}"
end
end
- describe '#reference_link_text' do
- context 'if issue id has a prefix' do
- it 'returns the issue ID' do
- expect(issue.reference_link_text).to eq 'EXT-1234'
+ describe "#reference_link_text" do
+ context "if issue id has a prefix" do
+ it "returns the issue ID" do
+ expect(issue.reference_link_text).to eq "EXT-1234"
end
end
- context 'if issue id is a number' do
- let(:issue) { described_class.new('1234', project) }
- it 'returns the issue ID prefixed by #' do
- expect(issue.reference_link_text).to eq '#1234'
+ context "if issue id is a number" do
+ let(:issue) { described_class.new("1234", project) }
+ it "returns the issue ID prefixed by #" do
+ expect(issue.reference_link_text).to eq "#1234"
end
end
end
- describe '#project_id' do
- it 'returns the ID of the project' do
+ describe "#project_id" do
+ it "returns the ID of the project" do
expect(issue.project_id).to eq(project.id)
end
end
- describe '#hash' do
- it 'returns the hash of its [class, to_s] pair' do
+ describe "#hash" do
+ it "returns the hash of its [class, to_s] pair" do
issue_2 = described_class.new(issue.to_s, project)
expect(issue.hash).to eq(issue_2.hash)
diff --git a/spec/models/fork_network_member_spec.rb b/spec/models/fork_network_member_spec.rb
index 60d04562e6c..25ed80f7fc8 100644
--- a/spec/models/fork_network_member_spec.rb
+++ b/spec/models/fork_network_member_spec.rb
@@ -1,22 +1,22 @@
-require 'spec_helper'
+require "spec_helper"
describe ForkNetworkMember do
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:fork_network) }
end
- describe 'destroying a ForkNetworkMember' do
+ describe "destroying a ForkNetworkMember" do
let(:fork_network_member) { create(:fork_network_member) }
let(:fork_network) { fork_network_member.fork_network }
- it 'removes the fork network if it was the last member' do
+ it "removes the fork network if it was the last member" do
fork_network.fork_network_members.destroy_all # rubocop: disable DestroyAll
expect(ForkNetwork.count).to eq(0)
end
- it 'does not destroy the fork network if there are members left' do
+ it "does not destroy the fork network if there are members left" do
fork_network_member.destroy!
# The root of the fork network is left
diff --git a/spec/models/fork_network_spec.rb b/spec/models/fork_network_spec.rb
index a43baf1820a..b39123bb6a9 100644
--- a/spec/models/fork_network_spec.rb
+++ b/spec/models/fork_network_spec.rb
@@ -1,10 +1,10 @@
-require 'spec_helper'
+require "spec_helper"
describe ForkNetwork do
include ProjectForksHelper
- describe '#add_root_as_member' do
- it 'adds the root project as a member when creating a new root network' do
+ describe "#add_root_as_member" do
+ it "adds the root project as a member when creating a new root network" do
project = create(:project)
fork_network = described_class.create(root_project: project)
@@ -12,20 +12,20 @@ describe ForkNetwork do
end
end
- describe '#find_fork_in' do
- it 'finds all fork of the current network in al collection' do
+ describe "#find_fork_in" do
+ it "finds all fork of the current network in al collection" do
network = create(:fork_network)
root_project = network.root_project
another_project = fork_project(root_project)
create(:project)
expect(network.find_forks_in(Project.all))
- .to contain_exactly(another_project, root_project)
+ .to contain_exactly(another_project, root_project)
end
end
- describe '#merge_requests' do
- it 'finds merge requests within the fork network' do
+ describe "#merge_requests" do
+ it "finds merge requests within the fork network" do
project = create(:project)
forked_project = fork_project(project)
merge_request = create(:merge_request, source_project: forked_project, target_project: project)
@@ -34,8 +34,8 @@ describe ForkNetwork do
end
end
- context 'for a deleted project' do
- it 'keeps the fork network' do
+ context "for a deleted project" do
+ it "keeps the fork network" do
project = create(:project, :public)
forked = fork_project(project)
project.destroy!
@@ -46,7 +46,7 @@ describe ForkNetwork do
expect(fork_network.root_project).to be_nil
end
- it 'allows multiple fork networks where the root project is deleted' do
+ it "allows multiple fork networks where the root project is deleted" do
first_project = create(:project)
second_project = create(:project)
first_fork = fork_project(first_project)
diff --git a/spec/models/generic_commit_status_spec.rb b/spec/models/generic_commit_status_spec.rb
index a3e68d2e646..72abab394df 100644
--- a/spec/models/generic_commit_status_spec.rb
+++ b/spec/models/generic_commit_status_spec.rb
@@ -1,85 +1,85 @@
-require 'spec_helper'
+require "spec_helper"
describe GenericCommitStatus do
let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, project: project) }
- let(:external_url) { 'http://example.gitlab.com/status' }
+ let(:external_url) { "http://example.gitlab.com/status" }
let(:generic_commit_status) do
create(:generic_commit_status, pipeline: pipeline,
target_url: external_url)
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_length_of(:target_url).is_at_most(255) }
it { is_expected.to allow_value(nil).for(:target_url) }
- it { is_expected.to allow_value('http://gitlab.com/s').for(:target_url) }
- it { is_expected.not_to allow_value('javascript:alert(1)').for(:target_url) }
+ it { is_expected.to allow_value("http://gitlab.com/s").for(:target_url) }
+ it { is_expected.not_to allow_value("javascript:alert(1)").for(:target_url) }
end
- describe '#context' do
+ describe "#context" do
subject { generic_commit_status.context }
before do
- generic_commit_status.context = 'my_context'
+ generic_commit_status.context = "my_context"
end
it { is_expected.to eq(generic_commit_status.name) }
end
- describe '#tags' do
+ describe "#tags" do
subject { generic_commit_status.tags }
it { is_expected.to eq([:external]) }
end
- describe '#detailed_status' do
+ describe "#detailed_status" do
let(:user) { create(:user) }
let(:status) { generic_commit_status.detailed_status(user) }
- it 'returns detailed status object' do
+ it "returns detailed status object" do
expect(status).to be_a Gitlab::Ci::Status::Success
end
- context 'when user has ability to see datails' do
+ context "when user has ability to see datails" do
before do
project.add_developer(user)
end
- it 'details path points to an external URL' do
+ it "details path points to an external URL" do
expect(status).to have_details
expect(status.details_path).to eq external_url
end
end
- context 'when user should not see details' do
- it 'does not have details' do
+ context "when user should not see details" do
+ it "does not have details" do
expect(status).not_to have_details
end
end
end
- describe 'set_default_values' do
+ describe "set_default_values" do
before do
generic_commit_status.context = nil
generic_commit_status.stage = nil
generic_commit_status.save
end
- describe '#context' do
+ describe "#context" do
subject { generic_commit_status.context }
it { is_expected.not_to be_nil }
end
- describe '#stage' do
+ describe "#stage" do
subject { generic_commit_status.stage }
it { is_expected.not_to be_nil }
end
end
- describe '#present' do
+ describe "#present" do
subject { generic_commit_status.present }
it { is_expected.to be_a(GenericCommitStatusPresenter) }
diff --git a/spec/models/global_milestone_spec.rb b/spec/models/global_milestone_spec.rb
index f93904065c7..de3ae4e9765 100644
--- a/spec/models/global_milestone_spec.rb
+++ b/spec/models/global_milestone_spec.rb
@@ -1,14 +1,14 @@
-require 'spec_helper'
+require "spec_helper"
describe GlobalMilestone do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:group) { create(:group) }
let(:project1) { create(:project, group: group) }
- let(:project2) { create(:project, path: 'gitlab-ci', group: group) }
- let(:project3) { create(:project, path: 'cookbook-gitlab', group: group) }
+ let(:project2) { create(:project, path: "gitlab-ci", group: group) }
+ let(:project3) { create(:project, path: "cookbook-gitlab", group: group) }
- describe '.build_collection' do
+ describe ".build_collection" do
let(:milestone1_due_date) { 2.weeks.from_now.to_date }
let!(:milestone1_project1) do
@@ -69,73 +69,73 @@ describe GlobalMilestone do
[
project1,
project2,
- project3
+ project3,
]
end
let!(:global_milestones) { described_class.build_collection(projects, {}) }
- context 'when building a collection of milestones' do
- it 'has all project milestones' do
+ context "when building a collection of milestones" do
+ it "has all project milestones" do
expect(global_milestones.count).to eq(6)
end
- it 'has all project milestones titles' do
- expect(global_milestones.map(&:title)).to match_array(['Milestone v1.2', 'Milestone v1.2', 'Milestone v1.2', 'VD-123', 'VD-123', 'VD-123'])
+ it "has all project milestones titles" do
+ expect(global_milestones.map(&:title)).to match_array(["Milestone v1.2", "Milestone v1.2", "Milestone v1.2", "VD-123", "VD-123", "VD-123"])
end
- it 'has all project milestones' do
+ it "has all project milestones" do
expect(global_milestones.size).to eq(6)
end
- it 'sorts collection by due date' do
+ it "sorts collection by due date" do
expect(global_milestones.map(&:due_date)).to eq [milestone1_due_date, milestone1_due_date, milestone1_due_date, nil, nil, nil]
end
- it 'filters milestones by search_title when params[:search_title] is present' do
- global_milestones = described_class.build_collection(projects, { search_title: 'v1.2' })
+ it "filters milestones by search_title when params[:search_title] is present" do
+ global_milestones = described_class.build_collection(projects, {search_title: "v1.2"})
- expect(global_milestones.map(&:title)).to match_array(['Milestone v1.2', 'Milestone v1.2', 'Milestone v1.2'])
+ expect(global_milestones.map(&:title)).to match_array(["Milestone v1.2", "Milestone v1.2", "Milestone v1.2"])
end
end
- context 'when adding new milestones' do
- it 'does not add more queries' do
- control_count = ActiveRecord::QueryRecorder.new do
+ context "when adding new milestones" do
+ it "does not add more queries" do
+ control_count = ActiveRecord::QueryRecorder.new {
described_class.build_collection(projects, {})
- end.count
+ }.count
create_list(:milestone, 3, project: project3)
- expect do
+ expect {
described_class.build_collection(projects, {})
- end.not_to exceed_all_query_limit(control_count)
+ }.not_to exceed_all_query_limit(control_count)
end
end
end
- describe '.states_count' do
- context 'when the projects have milestones' do
+ describe ".states_count" do
+ context "when the projects have milestones" do
before do
- create(:closed_milestone, title: 'Active Group Milestone', project: project3)
- create(:active_milestone, title: 'Active Group Milestone', project: project1)
- create(:active_milestone, title: 'Active Group Milestone', project: project2)
- create(:closed_milestone, title: 'Closed Group Milestone', project: project1)
- create(:closed_milestone, title: 'Closed Group Milestone', project: project2)
- create(:closed_milestone, title: 'Closed Group Milestone', project: project3)
- create(:closed_milestone, title: 'Closed Group Milestone 4', group: group)
+ create(:closed_milestone, title: "Active Group Milestone", project: project3)
+ create(:active_milestone, title: "Active Group Milestone", project: project1)
+ create(:active_milestone, title: "Active Group Milestone", project: project2)
+ create(:closed_milestone, title: "Closed Group Milestone", project: project1)
+ create(:closed_milestone, title: "Closed Group Milestone", project: project2)
+ create(:closed_milestone, title: "Closed Group Milestone", project: project3)
+ create(:closed_milestone, title: "Closed Group Milestone 4", group: group)
end
- it 'returns the quantity of global milestones and group milestones in each possible state' do
- expected_count = { opened: 2, closed: 5, all: 7 }
+ it "returns the quantity of global milestones and group milestones in each possible state" do
+ expected_count = {opened: 2, closed: 5, all: 7}
count = described_class.states_count(Project.all, group)
expect(count).to eq(expected_count)
end
- it 'returns the quantity of global milestones in each possible state' do
- expected_count = { opened: 2, closed: 4, all: 6 }
+ it "returns the quantity of global milestones in each possible state" do
+ expected_count = {opened: 2, closed: 4, all: 6}
count = described_class.states_count(Project.all)
@@ -143,13 +143,13 @@ describe GlobalMilestone do
end
end
- context 'when the projects do not have milestones' do
+ context "when the projects do not have milestones" do
before do
project1
end
- it 'returns 0 as the quantity of global milestones in each state' do
- expected_count = { opened: 0, closed: 0, all: 0 }
+ it "returns 0 as the quantity of global milestones in each state" do
+ expected_count = {opened: 0, closed: 0, all: 0}
count = described_class.states_count(Project.all)
@@ -158,47 +158,47 @@ describe GlobalMilestone do
end
end
- describe '#initialize' do
+ describe "#initialize" do
let(:milestone1_project1) { create(:milestone, title: "Milestone v1.2", project: project1) }
subject(:global_milestone) { described_class.new(milestone1_project1) }
- it 'has exactly one group milestone' do
- expect(global_milestone.title).to eq('Milestone v1.2')
+ it "has exactly one group milestone" do
+ expect(global_milestone.title).to eq("Milestone v1.2")
end
- it 'has all project milestones with the same title' do
+ it "has all project milestones with the same title" do
expect(global_milestone.milestone).to eq(milestone1_project1)
end
end
- describe '#safe_title' do
+ describe "#safe_title" do
let(:milestone) { create(:milestone, title: "git / test", project: project1) }
- it 'strips out slashes and spaces' do
+ it "strips out slashes and spaces" do
global_milestone = described_class.new(milestone)
- expect(global_milestone.safe_title).to eq('git-test')
+ expect(global_milestone.safe_title).to eq("git-test")
end
end
- describe '#state' do
- context 'when at least one milestone is active' do
- it 'returns active' do
- title = 'Active Group Milestone'
+ describe "#state" do
+ context "when at least one milestone is active" do
+ it "returns active" do
+ title = "Active Group Milestone"
global_milestone = described_class.new(create(:active_milestone, title: title))
- expect(global_milestone.state).to eq('active')
+ expect(global_milestone.state).to eq("active")
end
end
- context 'when all milestones are closed' do
- it 'returns closed' do
- title = 'Closed Group Milestone'
+ context "when all milestones are closed" do
+ it "returns closed" do
+ title = "Closed Group Milestone"
global_milestone = described_class.new(create(:closed_milestone, title: title))
- expect(global_milestone.state).to eq('closed')
+ expect(global_milestone.state).to eq("closed")
end
end
end
diff --git a/spec/models/gpg_key_spec.rb b/spec/models/gpg_key_spec.rb
index 58a1d2e4ea2..f88b16c45a5 100644
--- a/spec/models/gpg_key_spec.rb
+++ b/spec/models/gpg_key_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
describe GpgKey do
describe "associations" do
@@ -20,28 +20,28 @@ describe GpgKey do
it { is_expected.not_to allow_value("-----BEGIN PGP PUBLIC KEY BLOCK-----").for(:key) }
it { is_expected.not_to allow_value("-----END PGP PUBLIC KEY BLOCK-----").for(:key) }
it { is_expected.not_to allow_value("key\n-----END PGP PUBLIC KEY BLOCK-----").for(:key) }
- it { is_expected.not_to allow_value('BEGIN PGP').for(:key) }
+ it { is_expected.not_to allow_value("BEGIN PGP").for(:key) }
end
- context 'callbacks' do
- describe 'extract_fingerprint' do
- it 'extracts the fingerprint from the gpg key' do
+ context "callbacks" do
+ describe "extract_fingerprint" do
+ it "extracts the fingerprint from the gpg key" do
gpg_key = described_class.new(key: GpgHelpers::User1.public_key)
gpg_key.valid?
expect(gpg_key.fingerprint).to eq GpgHelpers::User1.fingerprint
end
end
- describe 'extract_primary_keyid' do
- it 'extracts the primary keyid from the gpg key' do
+ describe "extract_primary_keyid" do
+ it "extracts the primary keyid from the gpg key" do
gpg_key = described_class.new(key: GpgHelpers::User1.public_key)
gpg_key.valid?
expect(gpg_key.primary_keyid).to eq GpgHelpers::User1.primary_keyid
end
end
- describe 'generate_subkeys' do
- it 'extracts the subkeys from the gpg key' do
+ describe "generate_subkeys" do
+ it "extracts the subkeys from the gpg key" do
gpg_key = create(:gpg_key, key: GpgHelpers::User1.public_key_with_extra_signing_key)
expect(gpg_key.subkeys.count).to eq(2)
@@ -49,8 +49,8 @@ describe GpgKey do
end
end
- describe '#key=' do
- it 'strips white spaces' do
+ describe "#key=" do
+ it "strips white spaces" do
key = <<~KEY.strip
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
@@ -62,13 +62,13 @@ describe GpgKey do
expect(described_class.new(key: " #{key} ").key).to eq(key)
end
- it 'does not strip when the key is nil' do
+ it "does not strip when the key is nil" do
expect(described_class.new(key: nil).key).to be_nil
end
end
- describe '#user_infos' do
- it 'returns the user infos from the gpg key' do
+ describe "#user_infos" do
+ it "returns the user infos from the gpg key" do
gpg_key = create :gpg_key, key: GpgHelpers::User1.public_key
expect(Gitlab::Gpg).to receive(:user_infos_from_key).with(gpg_key.key)
@@ -76,98 +76,98 @@ describe GpgKey do
end
end
- describe '#verified_user_infos' do
- it 'returns the user infos if it is verified' do
+ describe "#verified_user_infos" do
+ it "returns the user infos if it is verified" do
user = create :user, email: GpgHelpers::User1.emails.first
gpg_key = create :gpg_key, key: GpgHelpers::User1.public_key, user: user
expect(gpg_key.verified_user_infos).to eq([{
name: GpgHelpers::User1.names.first,
- email: GpgHelpers::User1.emails.first
+ email: GpgHelpers::User1.emails.first,
}])
end
- it 'returns an empty array if the user info is not verified' do
- user = create :user, email: 'unrelated@example.com'
+ it "returns an empty array if the user info is not verified" do
+ user = create :user, email: "unrelated@example.com"
gpg_key = create :gpg_key, key: GpgHelpers::User1.public_key, user: user
expect(gpg_key.verified_user_infos).to eq([])
end
end
- describe '#emails_with_verified_status' do
- it 'email is verified if the user has the matching email' do
- user = create :user, email: 'bette.cartwright@example.com'
+ describe "#emails_with_verified_status" do
+ it "email is verified if the user has the matching email" do
+ user = create :user, email: "bette.cartwright@example.com"
gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user
create :email, user: user
user.reload
expect(gpg_key.emails_with_verified_status).to eq(
- 'bette.cartwright@example.com' => true,
- 'bette.cartwright@example.net' => false
+ "bette.cartwright@example.com" => true,
+ "bette.cartwright@example.net" => false
)
- create :email, :confirmed, user: user, email: 'bette.cartwright@example.net'
+ create :email, :confirmed, user: user, email: "bette.cartwright@example.net"
user.reload
expect(gpg_key.emails_with_verified_status).to eq(
- 'bette.cartwright@example.com' => true,
- 'bette.cartwright@example.net' => true
+ "bette.cartwright@example.com" => true,
+ "bette.cartwright@example.net" => true
)
end
end
- describe '#verified?' do
- it 'returns true if one of the email addresses in the key belongs to the user' do
- user = create :user, email: 'bette.cartwright@example.com'
+ describe "#verified?" do
+ it "returns true if one of the email addresses in the key belongs to the user" do
+ user = create :user, email: "bette.cartwright@example.com"
gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user
expect(gpg_key.verified?).to be_truthy
end
- it 'returns false if none of the email addresses in the key does not belong to the user' do
- user = create :user, email: 'someone.else@example.com'
+ it "returns false if none of the email addresses in the key does not belong to the user" do
+ user = create :user, email: "someone.else@example.com"
gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user
expect(gpg_key.verified?).to be_falsey
end
end
- describe 'verified_and_belongs_to_email?' do
- it 'returns false if none of the email addresses in the key does not belong to the user' do
- user = create :user, email: 'someone.else@example.com'
+ describe "verified_and_belongs_to_email?" do
+ it "returns false if none of the email addresses in the key does not belong to the user" do
+ user = create :user, email: "someone.else@example.com"
gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user
expect(gpg_key.verified?).to be_falsey
- expect(gpg_key.verified_and_belongs_to_email?('someone.else@example.com')).to be_falsey
+ expect(gpg_key.verified_and_belongs_to_email?("someone.else@example.com")).to be_falsey
end
- it 'returns false if one of the email addresses in the key belongs to the user and does not match the provided email' do
- user = create :user, email: 'bette.cartwright@example.com'
+ it "returns false if one of the email addresses in the key belongs to the user and does not match the provided email" do
+ user = create :user, email: "bette.cartwright@example.com"
gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user
expect(gpg_key.verified?).to be_truthy
- expect(gpg_key.verified_and_belongs_to_email?('bette.cartwright@example.net')).to be_falsey
+ expect(gpg_key.verified_and_belongs_to_email?("bette.cartwright@example.net")).to be_falsey
end
- it 'returns true if one of the email addresses in the key belongs to the user and matches the provided email' do
- user = create :user, email: 'bette.cartwright@example.com'
+ it "returns true if one of the email addresses in the key belongs to the user and matches the provided email" do
+ user = create :user, email: "bette.cartwright@example.com"
gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user
expect(gpg_key.verified?).to be_truthy
- expect(gpg_key.verified_and_belongs_to_email?('bette.cartwright@example.com')).to be_truthy
+ expect(gpg_key.verified_and_belongs_to_email?("bette.cartwright@example.com")).to be_truthy
end
- it 'returns true if one of the email addresses in the key belongs to the user and case-insensitively matches the provided email' do
- user = create :user, email: 'bette.cartwright@example.com'
+ it "returns true if one of the email addresses in the key belongs to the user and case-insensitively matches the provided email" do
+ user = create :user, email: "bette.cartwright@example.com"
gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user
expect(gpg_key.verified?).to be_truthy
- expect(gpg_key.verified_and_belongs_to_email?('Bette.Cartwright@example.com')).to be_truthy
+ expect(gpg_key.verified_and_belongs_to_email?("Bette.Cartwright@example.com")).to be_truthy
end
end
- describe '#revoke' do
- it 'invalidates all associated gpg signatures and destroys the key' do
+ describe "#revoke" do
+ it "invalidates all associated gpg signatures and destroys the key" do
gpg_key = create :gpg_key
gpg_signature = create :gpg_signature, verification_status: :verified, gpg_key: gpg_key
@@ -177,7 +177,7 @@ describe GpgKey do
gpg_key.revoke
expect(gpg_signature.reload).to have_attributes(
- verification_status: 'unknown_key',
+ verification_status: "unknown_key",
gpg_key: nil
)
@@ -185,14 +185,14 @@ describe GpgKey do
# unrelated signature is left untouched
expect(unrelated_gpg_signature.reload).to have_attributes(
- verification_status: 'verified',
+ verification_status: "verified",
gpg_key: unrelated_gpg_key
)
expect(unrelated_gpg_key.destroyed?).to be false
end
- it 'deletes all the associated subkeys' do
+ it "deletes all the associated subkeys" do
gpg_key = create :gpg_key, key: GpgHelpers::User3.public_key
expect(gpg_key.subkeys).to be_present
@@ -202,7 +202,7 @@ describe GpgKey do
expect(gpg_key.subkeys.reload).to be_blank
end
- it 'invalidates all signatures associated to the subkeys' do
+ it "invalidates all signatures associated to the subkeys" do
gpg_key = create :gpg_key, key: GpgHelpers::User3.public_key
gpg_key_subkey = gpg_key.subkeys.last
gpg_signature = create :gpg_signature, verification_status: :verified, gpg_key: gpg_key_subkey
@@ -210,7 +210,7 @@ describe GpgKey do
gpg_key.revoke
expect(gpg_signature.reload).to have_attributes(
- verification_status: 'unknown_key',
+ verification_status: "unknown_key",
gpg_key: nil,
gpg_key_subkey: nil
)
diff --git a/spec/models/gpg_key_subkey_spec.rb b/spec/models/gpg_key_subkey_spec.rb
index 3c86837f47f..3294a86a918 100644
--- a/spec/models/gpg_key_subkey_spec.rb
+++ b/spec/models/gpg_key_subkey_spec.rb
@@ -1,13 +1,13 @@
-require 'rails_helper'
+require "rails_helper"
describe GpgKeySubkey do
subject { build(:gpg_key_subkey) }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:gpg_key) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:gpg_key_id) }
it { is_expected.to validate_presence_of(:fingerprint) }
it { is_expected.to validate_presence_of(:keyid) }
diff --git a/spec/models/gpg_signature_spec.rb b/spec/models/gpg_signature_spec.rb
index e90319c39b1..44def2565c0 100644
--- a/spec/models/gpg_signature_spec.rb
+++ b/spec/models/gpg_signature_spec.rb
@@ -1,48 +1,48 @@
-require 'rails_helper'
+require "rails_helper"
RSpec.describe GpgSignature do
- let(:commit_sha) { '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' }
- let!(:project) { create(:project, :repository, path: 'sample-project') }
+ let(:commit_sha) { "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33" }
+ let!(:project) { create(:project, :repository, path: "sample-project") }
let!(:commit) { create(:commit, project: project, sha: commit_sha) }
let(:gpg_signature) { create(:gpg_signature, commit_sha: commit_sha) }
let(:gpg_key) { create(:gpg_key) }
let(:gpg_key_subkey) { create(:gpg_key_subkey) }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:gpg_key) }
it { is_expected.to belong_to(:gpg_key_subkey) }
end
- describe 'validation' do
+ describe "validation" do
subject { described_class.new }
it { is_expected.to validate_presence_of(:commit_sha) }
it { is_expected.to validate_presence_of(:project_id) }
it { is_expected.to validate_presence_of(:gpg_key_primary_keyid) }
end
- describe '.safe_create!' do
+ describe ".safe_create!" do
let(:attributes) do
{
commit_sha: commit_sha,
project: project,
- gpg_key_primary_keyid: gpg_key.keyid
+ gpg_key_primary_keyid: gpg_key.keyid,
}
end
- it 'finds a signature by commit sha if it existed' do
+ it "finds a signature by commit sha if it existed" do
gpg_signature
expect(described_class.safe_create!(commit_sha: commit_sha)).to eq(gpg_signature)
end
- it 'creates a new signature if it was not found' do
+ it "creates a new signature if it was not found" do
expect { described_class.safe_create!(attributes) }.to change { described_class.count }.by(1)
end
- it 'assigns the correct attributes when creating' do
+ it "assigns the correct attributes when creating" do
signature = described_class.safe_create!(attributes)
expect(signature.project).to eq(project)
@@ -50,7 +50,7 @@ RSpec.describe GpgSignature do
expect(signature.gpg_key_primary_keyid).to eq(gpg_key.keyid)
end
- it 'does not raise an error in case of a race condition' do
+ it "does not raise an error in case of a race condition" do
expect(described_class).to receive(:find_or_create_by).and_raise(ActiveRecord::RecordNotUnique)
allow(described_class).to receive(:find_or_create_by).and_call_original
@@ -58,28 +58,28 @@ RSpec.describe GpgSignature do
end
end
- describe '#commit' do
- it 'fetches the commit through the project' do
+ describe "#commit" do
+ it "fetches the commit through the project" do
expect_any_instance_of(Project).to receive(:commit).with(commit_sha).and_return(commit)
gpg_signature.commit
end
end
- describe '#gpg_key=' do
- it 'supports the assignment of a GpgKey' do
+ describe "#gpg_key=" do
+ it "supports the assignment of a GpgKey" do
gpg_signature = create(:gpg_signature, gpg_key: gpg_key)
expect(gpg_signature.gpg_key).to be_an_instance_of(GpgKey)
end
- it 'supports the assignment of a GpgKeySubkey' do
+ it "supports the assignment of a GpgKeySubkey" do
gpg_signature = create(:gpg_signature, gpg_key: gpg_key_subkey)
expect(gpg_signature.gpg_key).to be_an_instance_of(GpgKeySubkey)
end
- it 'clears gpg_key and gpg_key_subkey_id when passing nil' do
+ it "clears gpg_key and gpg_key_subkey_id when passing nil" do
gpg_signature.update_attribute(:gpg_key, nil)
expect(gpg_signature.gpg_key_id).to be_nil
@@ -87,17 +87,17 @@ RSpec.describe GpgSignature do
end
end
- describe '#gpg_commit' do
- context 'when commit does not exist' do
- it 'returns nil' do
+ describe "#gpg_commit" do
+ context "when commit does not exist" do
+ it "returns nil" do
allow(gpg_signature).to receive(:commit).and_return(nil)
expect(gpg_signature.gpg_commit).to be_nil
end
end
- context 'when commit exists' do
- it 'returns an instance of Gitlab::Gpg::Commit' do
+ context "when commit exists" do
+ it "returns an instance of Gitlab::Gpg::Commit" do
allow(gpg_signature).to receive(:commit).and_return(commit)
expect(gpg_signature.gpg_commit).to be_an_instance_of(Gitlab::Gpg::Commit)
diff --git a/spec/models/group_custom_attribute_spec.rb b/spec/models/group_custom_attribute_spec.rb
index 7ecb2022567..e911179493b 100644
--- a/spec/models/group_custom_attribute_spec.rb
+++ b/spec/models/group_custom_attribute_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe GroupCustomAttribute do
- describe 'assocations' do
+ describe "assocations" do
it { is_expected.to belong_to(:group) }
end
- describe 'validations' do
+ describe "validations" do
subject { build :group_custom_attribute }
it { is_expected.to validate_presence_of(:group) }
diff --git a/spec/models/group_label_spec.rb b/spec/models/group_label_spec.rb
index d0fc1eaa3ec..89a6ce2d728 100644
--- a/spec/models/group_label_spec.rb
+++ b/spec/models/group_label_spec.rb
@@ -1,54 +1,54 @@
-require 'spec_helper'
+require "spec_helper"
describe GroupLabel do
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:group) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:group) }
end
- describe '#subject' do
- it 'aliases group to subject' do
+ describe "#subject" do
+ it "aliases group to subject" do
subject = described_class.new(group: build(:group))
expect(subject.subject).to be(subject.group)
end
end
- describe '#to_reference' do
- let(:label) { create(:group_label, title: 'feature') }
+ describe "#to_reference" do
+ let(:label) { create(:group_label, title: "feature") }
- context 'using id' do
- it 'returns a String reference to the object' do
+ context "using id" do
+ it "returns a String reference to the object" do
expect(label.to_reference).to eq "~#{label.id}"
end
end
- context 'using name' do
- it 'returns a String reference to the object' do
+ context "using name" do
+ it "returns a String reference to the object" do
expect(label.to_reference(format: :name)).to eq %(~"#{label.name}")
end
- it 'uses id when name contains double quote' do
- label = create(:label, name: %q{"irony"})
+ it "uses id when name contains double quote" do
+ label = create(:label, name: '"irony"')
expect(label.to_reference(format: :name)).to eq "~#{label.id}"
end
end
- context 'cross-project' do
+ context "cross-project" do
let(:namespace) { build_stubbed(:namespace) }
- let(:source_project) { build_stubbed(:project, name: 'project-1', namespace: namespace) }
- let(:target_project) { build_stubbed(:project, name: 'project-2', namespace: namespace) }
+ let(:source_project) { build_stubbed(:project, name: "project-1", namespace: namespace) }
+ let(:target_project) { build_stubbed(:project, name: "project-2", namespace: namespace) }
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(label.to_reference(source_project, target_project: target_project)).to eq %(project-1~#{label.id})
end
end
- context 'using invalid format' do
- it 'raises error' do
+ context "using invalid format" do
+ it "raises error" do
expect { label.to_reference(format: :invalid) }
.to raise_error StandardError, /Unknown format/
end
diff --git a/spec/models/group_milestone_spec.rb b/spec/models/group_milestone_spec.rb
index fcc33cd95fe..174f5ebf732 100644
--- a/spec/models/group_milestone_spec.rb
+++ b/spec/models/group_milestone_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe GroupMilestone do
let(:group) { create(:group) }
@@ -7,8 +7,8 @@ describe GroupMilestone do
create(:milestone, title: "Milestone v1.2", project: project)
end
- describe '.build' do
- it 'returns milestone with group assigned' do
+ describe ".build" do
+ it "returns milestone with group assigned" do
milestone = described_class.build(
group,
[project],
@@ -19,36 +19,36 @@ describe GroupMilestone do
end
end
- describe '.build_collection' do
+ describe ".build_collection" do
let(:group) { create(:group) }
let(:project1) { create(:project, group: group) }
- let(:project2) { create(:project, path: 'gitlab-ci', group: group) }
- let(:project3) { create(:project, path: 'cookbook-gitlab', group: group) }
+ let(:project2) { create(:project, path: "gitlab-ci", group: group) }
+ let(:project3) { create(:project, path: "cookbook-gitlab", group: group) }
let!(:projects) do
[
- project1,
- project2,
- project3
+ project1,
+ project2,
+ project3,
]
end
- it 'returns array of milestones, each with group assigned' do
+ it "returns array of milestones, each with group assigned" do
milestones = described_class.build_collection(group, [project], {})
expect(milestones).to all(have_attributes(group: group))
end
- context 'when adding new milestones' do
- it 'does not add more queries' do
- control_count = ActiveRecord::QueryRecorder.new do
+ context "when adding new milestones" do
+ it "does not add more queries" do
+ control_count = ActiveRecord::QueryRecorder.new {
described_class.build_collection(group, projects, {})
- end.count
+ }.count
- create(:milestone, title: 'This title', project: project1)
+ create(:milestone, title: "This title", project: project1)
- expect do
+ expect {
described_class.build_collection(group, projects, {})
- end.not_to exceed_all_query_limit(control_count)
+ }.not_to exceed_all_query_limit(control_count)
end
end
end
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index 9dc32a815d8..e1346ab2a57 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -1,9 +1,9 @@
-require 'spec_helper'
+require "spec_helper"
describe Group do
let!(:group) { create(:group, :access_requestable) }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to have_many :projects }
it { is_expected.to have_many(:group_members).dependent(:destroy) }
it { is_expected.to have_many(:users).through(:group_members) }
@@ -13,16 +13,16 @@ describe Group do
it { is_expected.to have_many(:project_group_links).dependent(:destroy) }
it { is_expected.to have_many(:shared_projects).through(:project_group_links) }
it { is_expected.to have_many(:notification_settings).dependent(:destroy) }
- it { is_expected.to have_many(:labels).class_name('GroupLabel') }
- it { is_expected.to have_many(:variables).class_name('Ci::GroupVariable') }
+ it { is_expected.to have_many(:labels).class_name("GroupLabel") }
+ it { is_expected.to have_many(:variables).class_name("Ci::GroupVariable") }
it { is_expected.to have_many(:uploads) }
it { is_expected.to have_one(:chat_team) }
- it { is_expected.to have_many(:custom_attributes).class_name('GroupCustomAttribute') }
- it { is_expected.to have_many(:badges).class_name('GroupBadge') }
- it { is_expected.to have_many(:cluster_groups).class_name('Clusters::Group') }
- it { is_expected.to have_many(:clusters).class_name('Clusters::Cluster') }
+ it { is_expected.to have_many(:custom_attributes).class_name("GroupCustomAttribute") }
+ it { is_expected.to have_many(:badges).class_name("GroupBadge") }
+ it { is_expected.to have_many(:cluster_groups).class_name("Clusters::Group") }
+ it { is_expected.to have_many(:clusters).class_name("Clusters::Cluster") }
- describe '#members & #requesters' do
+ describe "#members & #requesters" do
let(:requester) { create(:user) }
let(:developer) { create(:user) }
before do
@@ -30,46 +30,46 @@ describe Group do
group.add_developer(developer)
end
- it_behaves_like 'members and requesters associations' do
+ it_behaves_like "members and requesters associations" do
let(:namespace) { group }
end
end
end
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Referable) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_presence_of :path }
it { is_expected.not_to validate_presence_of :owner }
it { is_expected.to validate_presence_of :two_factor_grace_period }
it { is_expected.to validate_numericality_of(:two_factor_grace_period).is_greater_than_or_equal_to(0) }
- describe 'path validation' do
- it 'rejects paths reserved on the root namespace when the group has no parent' do
- group = build(:group, path: 'api')
+ describe "path validation" do
+ it "rejects paths reserved on the root namespace when the group has no parent" do
+ group = build(:group, path: "api")
expect(group).not_to be_valid
end
- it 'allows root paths when the group has a parent' do
- group = build(:group, path: 'api', parent: create(:group))
+ it "allows root paths when the group has a parent" do
+ group = build(:group, path: "api", parent: create(:group))
expect(group).to be_valid
end
- it 'rejects any wildcard paths when not a top level group' do
- group = build(:group, path: 'tree', parent: create(:group))
+ it "rejects any wildcard paths when not a top level group" do
+ group = build(:group, path: "tree", parent: create(:group))
expect(group).not_to be_valid
end
end
- describe '#notification_settings', :nested_groups do
+ describe "#notification_settings", :nested_groups do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:sub_group) { create(:group, parent_id: group.id) }
@@ -79,44 +79,44 @@ describe Group do
sub_group.add_maintainer(user)
end
- it 'also gets notification settings from parent groups' do
+ it "also gets notification settings from parent groups" do
expect(sub_group.notification_settings.size).to eq(2)
expect(sub_group.notification_settings).to include(group.notification_settings.first)
end
- context 'when sub group is deleted' do
- it 'does not delete parent notification settings' do
- expect do
+ context "when sub group is deleted" do
+ it "does not delete parent notification settings" do
+ expect {
sub_group.destroy
- end.to change { NotificationSetting.count }.by(-1)
+ }.to change { NotificationSetting.count }.by(-1)
end
end
end
- describe '#visibility_level_allowed_by_parent' do
+ describe "#visibility_level_allowed_by_parent" do
let(:parent) { create(:group, :internal) }
let(:sub_group) { build(:group, parent_id: parent.id) }
- context 'without a parent' do
- it 'is valid' do
+ context "without a parent" do
+ it "is valid" do
sub_group.parent_id = nil
expect(sub_group).to be_valid
end
end
- context 'with a parent' do
- context 'when visibility of sub group is greater than the parent' do
- it 'is invalid' do
+ context "with a parent" do
+ context "when visibility of sub group is greater than the parent" do
+ it "is invalid" do
sub_group.visibility_level = Gitlab::VisibilityLevel::PUBLIC
expect(sub_group).to be_invalid
end
end
- context 'when visibility of sub group is lower or equal to the parent' do
+ context "when visibility of sub group is lower or equal to the parent" do
[Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PRIVATE].each do |level|
- it 'is valid' do
+ it "is valid" do
sub_group.visibility_level = level
expect(sub_group).to be_valid
@@ -126,21 +126,21 @@ describe Group do
end
end
- describe '#visibility_level_allowed_by_projects' do
+ describe "#visibility_level_allowed_by_projects" do
let!(:internal_group) { create(:group, :internal) }
let!(:internal_project) { create(:project, :internal, group: internal_group) }
- context 'when group has a lower visibility' do
- it 'is invalid' do
+ context "when group has a lower visibility" do
+ it "is invalid" do
internal_group.visibility_level = Gitlab::VisibilityLevel::PRIVATE
expect(internal_group).to be_invalid
- expect(internal_group.errors[:visibility_level]).to include('private is not allowed since this group contains projects with higher visibility.')
+ expect(internal_group.errors[:visibility_level]).to include("private is not allowed since this group contains projects with higher visibility.")
end
end
- context 'when group has a higher visibility' do
- it 'is valid' do
+ context "when group has a higher visibility" do
+ it "is valid" do
internal_group.visibility_level = Gitlab::VisibilityLevel::PUBLIC
expect(internal_group).to be_valid
@@ -148,21 +148,21 @@ describe Group do
end
end
- describe '#visibility_level_allowed_by_sub_groups' do
+ describe "#visibility_level_allowed_by_sub_groups" do
let!(:internal_group) { create(:group, :internal) }
let!(:internal_sub_group) { create(:group, :internal, parent: internal_group) }
- context 'when parent group has a lower visibility' do
- it 'is invalid' do
+ context "when parent group has a lower visibility" do
+ it "is invalid" do
internal_group.visibility_level = Gitlab::VisibilityLevel::PRIVATE
expect(internal_group).to be_invalid
- expect(internal_group.errors[:visibility_level]).to include('private is not allowed since there are sub-groups with higher visibility.')
+ expect(internal_group.errors[:visibility_level]).to include("private is not allowed since there are sub-groups with higher visibility.")
end
end
- context 'when parent group has a higher visibility' do
- it 'is valid' do
+ context "when parent group has a higher visibility" do
+ it "is valid" do
internal_group.visibility_level = Gitlab::VisibilityLevel::PUBLIC
expect(internal_group).to be_valid
@@ -171,26 +171,26 @@ describe Group do
end
end
- describe '.public_or_visible_to_user' do
+ describe ".public_or_visible_to_user" do
let!(:private_group) { create(:group, :private) }
let!(:internal_group) { create(:group, :internal) }
subject { described_class.public_or_visible_to_user(user) }
- context 'when user is nil' do
+ context "when user is nil" do
let!(:user) { nil }
it { is_expected.to match_array([group]) }
end
- context 'when user' do
+ context "when user" do
let!(:user) { create(:user) }
- context 'when user does not have access to any private group' do
+ context "when user does not have access to any private group" do
it { is_expected.to match_array([internal_group, group]) }
end
- context 'when user is a member of private group' do
+ context "when user is a member of private group" do
before do
private_group.add_user(user, Gitlab::Access::DEVELOPER)
end
@@ -198,7 +198,7 @@ describe Group do
it { is_expected.to match_array([private_group, internal_group, group]) }
end
- context 'when user is a member of private subgroup', :postgresql do
+ context "when user is a member of private subgroup", :postgresql do
let!(:private_subgroup) { create(:group, :private, parent: private_group) }
before do
@@ -210,44 +210,44 @@ describe Group do
end
end
- describe 'scopes' do
+ describe "scopes" do
let!(:private_group) { create(:group, :private) }
let!(:internal_group) { create(:group, :internal) }
- describe 'public_only' do
+ describe "public_only" do
subject { described_class.public_only.to_a }
it { is_expected.to eq([group]) }
end
- describe 'public_and_internal_only' do
+ describe "public_and_internal_only" do
subject { described_class.public_and_internal_only.to_a }
it { is_expected.to match_array([group, internal_group]) }
end
- describe 'non_public_only' do
+ describe "non_public_only" do
subject { described_class.non_public_only.to_a }
it { is_expected.to match_array([private_group, internal_group]) }
end
end
- describe '#to_reference' do
- it 'returns a String reference to the object' do
+ describe "#to_reference" do
+ it "returns a String reference to the object" do
expect(group.to_reference).to eq "@#{group.name}"
end
end
- describe '#users' do
+ describe "#users" do
it { expect(group.users).to eq(group.owners) }
end
- describe '#human_name' do
+ describe "#human_name" do
it { expect(group.human_name).to eq(group.name) }
end
- describe '#add_user' do
+ describe "#add_user" do
let(:user) { create(:user) }
before do
@@ -257,7 +257,7 @@ describe Group do
it { expect(group.group_members.maintainers.map(&:user)).to include(user) }
end
- describe '#add_users' do
+ describe "#add_users" do
let(:user) { create(:user) }
before do
@@ -272,7 +272,7 @@ describe Group do
end
end
- describe '#avatar_type' do
+ describe "#avatar_type" do
let(:user) { create(:user) }
before do
@@ -280,59 +280,59 @@ describe Group do
end
it "is true if avatar is image" do
- group.update_attribute(:avatar, 'uploads/avatar.png')
+ group.update_attribute(:avatar, "uploads/avatar.png")
expect(group.avatar_type).to be_truthy
end
it "is false if avatar is html page" do
- group.update_attribute(:avatar, 'uploads/avatar.html')
+ group.update_attribute(:avatar, "uploads/avatar.html")
expect(group.avatar_type).to eq(["file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico"])
end
end
- describe '#avatar_url' do
+ describe "#avatar_url" do
let!(:group) { create(:group, :access_requestable, :with_avatar) }
let(:user) { create(:user) }
- context 'when avatar file is uploaded' do
+ context "when avatar file is uploaded" do
before do
group.add_maintainer(user)
end
- it 'shows correct avatar url' do
+ it "shows correct avatar url" do
expect(group.avatar_url).to eq(group.avatar.url)
expect(group.avatar_url(only_path: false)).to eq([Gitlab.config.gitlab.url, group.avatar.url].join)
end
end
end
- describe '.search' do
- it 'returns groups with a matching name' do
+ describe ".search" do
+ it "returns groups with a matching name" do
expect(described_class.search(group.name)).to eq([group])
end
- it 'returns groups with a partially matching name' do
+ it "returns groups with a partially matching name" do
expect(described_class.search(group.name[0..2])).to eq([group])
end
- it 'returns groups with a matching name regardless of the casing' do
+ it "returns groups with a matching name regardless of the casing" do
expect(described_class.search(group.name.upcase)).to eq([group])
end
- it 'returns groups with a matching path' do
+ it "returns groups with a matching path" do
expect(described_class.search(group.path)).to eq([group])
end
- it 'returns groups with a partially matching path' do
+ it "returns groups with a partially matching path" do
expect(described_class.search(group.path[0..2])).to eq([group])
end
- it 'returns groups with a matching path regardless of the casing' do
+ it "returns groups with a matching path regardless of the casing" do
expect(described_class.search(group.path.upcase)).to eq([group])
end
end
- describe '#has_owner?' do
+ describe "#has_owner?" do
before do
@members = setup_group_members(group)
create(:group_member, :invited, :owner, group: group)
@@ -347,7 +347,7 @@ describe Group do
it { expect(group.has_owner?(nil)).to be_falsey }
end
- describe '#has_maintainer?' do
+ describe "#has_maintainer?" do
before do
@members = setup_group_members(group)
create(:group_member, :invited, :maintainer, group: group)
@@ -362,45 +362,45 @@ describe Group do
it { expect(group.has_maintainer?(nil)).to be_falsey }
end
- describe '#lfs_enabled?' do
- context 'LFS enabled globally' do
+ describe "#lfs_enabled?" do
+ context "LFS enabled globally" do
before do
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
end
- it 'returns true when nothing is set' do
+ it "returns true when nothing is set" do
expect(group.lfs_enabled?).to be_truthy
end
- it 'returns false when set to false' do
+ it "returns false when set to false" do
group.update_attribute(:lfs_enabled, false)
expect(group.lfs_enabled?).to be_falsey
end
- it 'returns true when set to true' do
+ it "returns true when set to true" do
group.update_attribute(:lfs_enabled, true)
expect(group.lfs_enabled?).to be_truthy
end
end
- context 'LFS disabled globally' do
+ context "LFS disabled globally" do
before do
allow(Gitlab.config.lfs).to receive(:enabled).and_return(false)
end
- it 'returns false when nothing is set' do
+ it "returns false when nothing is set" do
expect(group.lfs_enabled?).to be_falsey
end
- it 'returns false when set to false' do
+ it "returns false when set to false" do
group.update_attribute(:lfs_enabled, false)
expect(group.lfs_enabled?).to be_falsey
end
- it 'returns false when set to true' do
+ it "returns false when set to true" do
group.update_attribute(:lfs_enabled, true)
expect(group.lfs_enabled?).to be_falsey
@@ -408,11 +408,11 @@ describe Group do
end
end
- describe '#owners' do
+ describe "#owners" do
let(:owner) { create(:user) }
let(:developer) { create(:user) }
- it 'returns the owners of a Group' do
+ it "returns the owners of a Group" do
group.add_owner(owner)
group.add_developer(developer)
@@ -427,7 +427,7 @@ describe Group do
developer: create(:user),
reporter: create(:user),
guest: create(:user),
- requester: create(:user)
+ requester: create(:user),
}
group.add_user(members[:owner], GroupMember::OWNER)
@@ -440,54 +440,54 @@ describe Group do
members
end
- describe '#web_url' do
- it 'returns the canonical URL' do
+ describe "#web_url" do
+ it "returns the canonical URL" do
expect(group.web_url).to include("groups/#{group.name}")
end
- context 'nested group' do
+ context "nested group" do
let(:nested_group) { create(:group, :nested) }
it { expect(nested_group.web_url).to include("groups/#{nested_group.full_path}") }
end
end
- describe 'nested group' do
+ describe "nested group" do
subject { build(:group, :nested) }
it { is_expected.to be_valid }
it { expect(subject.parent).to be_kind_of(described_class) }
end
- describe '#members_with_parents', :nested_groups do
+ describe "#members_with_parents", :nested_groups do
let!(:group) { create(:group, :nested) }
let!(:maintainer) { group.parent.add_user(create(:user), GroupMember::MAINTAINER) }
let!(:developer) { group.add_user(create(:user), GroupMember::DEVELOPER) }
- it 'returns parents members' do
+ it "returns parents members" do
expect(group.members_with_parents).to include(developer)
expect(group.members_with_parents).to include(maintainer)
end
end
- describe '#direct_and_indirect_members', :nested_groups do
+ describe "#direct_and_indirect_members", :nested_groups do
let!(:group) { create(:group, :nested) }
let!(:sub_group) { create(:group, parent: group) }
let!(:maintainer) { group.parent.add_user(create(:user), GroupMember::MAINTAINER) }
let!(:developer) { group.add_user(create(:user), GroupMember::DEVELOPER) }
let!(:other_developer) { group.add_user(create(:user), GroupMember::DEVELOPER) }
- it 'returns parents members' do
+ it "returns parents members" do
expect(group.direct_and_indirect_members).to include(developer)
expect(group.direct_and_indirect_members).to include(maintainer)
end
- it 'returns descendant members' do
+ it "returns descendant members" do
expect(group.direct_and_indirect_members).to include(other_developer)
end
end
- describe '#users_with_descendants', :nested_groups do
+ describe "#users_with_descendants", :nested_groups do
let(:user_a) { create(:user) }
let(:user_b) { create(:user) }
@@ -495,7 +495,7 @@ describe Group do
let(:nested_group) { create(:group, parent: group) }
let(:deep_nested_group) { create(:group, parent: nested_group) }
- it 'returns member users on every nest level without duplication' do
+ it "returns member users on every nest level without duplication" do
group.add_developer(user_a)
nested_group.add_developer(user_b)
deep_nested_group.add_maintainer(user_a)
@@ -506,7 +506,7 @@ describe Group do
end
end
- describe '#direct_and_indirect_users', :nested_groups do
+ describe "#direct_and_indirect_users", :nested_groups do
let(:user_a) { create(:user) }
let(:user_b) { create(:user) }
let(:user_c) { create(:user) }
@@ -525,18 +525,18 @@ describe Group do
project.add_developer(user_d)
end
- it 'returns member users on every nest level without duplication' do
+ it "returns member users on every nest level without duplication" do
expect(group.direct_and_indirect_users).to contain_exactly(user_a, user_b, user_c, user_d)
expect(nested_group.direct_and_indirect_users).to contain_exactly(user_a, user_b, user_c)
expect(deep_nested_group.direct_and_indirect_users).to contain_exactly(user_a, user_b, user_c)
end
- it 'does not return members of projects belonging to ancestor groups' do
+ it "does not return members of projects belonging to ancestor groups" do
expect(nested_group.direct_and_indirect_users).not_to include(user_d)
end
end
- describe '#project_users_with_descendants', :nested_groups do
+ describe "#project_users_with_descendants", :nested_groups do
let(:user_a) { create(:user) }
let(:user_b) { create(:user) }
let(:user_c) { create(:user) }
@@ -548,7 +548,7 @@ describe Group do
let(:project_b) { create(:project, namespace: nested_group) }
let(:project_c) { create(:project, namespace: deep_nested_group) }
- it 'returns members of all projects in group and subgroups' do
+ it "returns members of all projects in group and subgroups" do
project_a.add_developer(user_a)
project_b.add_developer(user_b)
project_c.add_developer(user_c)
@@ -559,8 +559,8 @@ describe Group do
end
end
- describe '#user_ids_for_project_authorizations' do
- it 'returns the user IDs for which to refresh authorizations' do
+ describe "#user_ids_for_project_authorizations" do
+ it "returns the user IDs for which to refresh authorizations" do
maintainer = create(:user)
developer = create(:user)
@@ -572,32 +572,32 @@ describe Group do
end
end
- describe '#update_two_factor_requirement' do
+ describe "#update_two_factor_requirement" do
let(:user) { create(:user) }
before do
group.add_user(user, GroupMember::OWNER)
end
- it 'is called when require_two_factor_authentication is changed' do
+ it "is called when require_two_factor_authentication is changed" do
expect_any_instance_of(User).to receive(:update_two_factor_requirement)
group.update!(require_two_factor_authentication: true)
end
- it 'is called when two_factor_grace_period is changed' do
+ it "is called when two_factor_grace_period is changed" do
expect_any_instance_of(User).to receive(:update_two_factor_requirement)
group.update!(two_factor_grace_period: 23)
end
- it 'is not called when other attributes are changed' do
+ it "is not called when other attributes are changed" do
expect_any_instance_of(User).not_to receive(:update_two_factor_requirement)
- group.update!(description: 'foobar')
+ group.update!(description: "foobar")
end
- it 'calls #update_two_factor_requirement on each group member' do
+ it "calls #update_two_factor_requirement on each group member" do
other_user = create(:user)
group.add_user(other_user, GroupMember::OWNER)
@@ -612,30 +612,30 @@ describe Group do
end
end
- describe '#path_changed_hook' do
+ describe "#path_changed_hook" do
let(:system_hook_service) { SystemHooksService.new }
- context 'for a new group' do
+ context "for a new group" do
let(:group) { build(:group) }
before do
expect(group).to receive(:system_hook_service).and_return(system_hook_service)
end
- it 'does not trigger system hook' do
+ it "does not trigger system hook" do
expect(system_hook_service).to receive(:execute_hooks_for).with(group, :create)
group.save!
end
end
- context 'for an existing group' do
- let(:group) { create(:group, path: 'old-path') }
+ context "for an existing group" do
+ let(:group) { create(:group, path: "old-path") }
- context 'when the path is changed' do
- let(:new_path) { 'very-new-path' }
+ context "when the path is changed" do
+ let(:new_path) { "very-new-path" }
- it 'triggers the rename system hook' do
+ it "triggers the rename system hook" do
expect(group).to receive(:system_hook_service).and_return(system_hook_service)
expect(system_hook_service).to receive(:execute_hooks_for).with(group, :rename)
@@ -643,63 +643,64 @@ describe Group do
end
end
- context 'when the path is not changed' do
- it 'does not trigger system hook' do
+ context "when the path is not changed" do
+ it "does not trigger system hook" do
expect(group).not_to receive(:system_hook_service)
- group.update!(name: 'new name')
+ group.update!(name: "new name")
end
end
end
end
- describe '#ci_variables_for' do
+ describe "#ci_variables_for" do
let(:project) { create(:project, group: group) }
let!(:ci_variable) do
- create(:ci_group_variable, value: 'secret', group: group)
+ create(:ci_group_variable, value: "secret", group: group)
end
let!(:protected_variable) do
- create(:ci_group_variable, :protected, value: 'protected', group: group)
+ create(:ci_group_variable, :protected, value: "protected", group: group)
end
- subject { group.ci_variables_for('ref', project) }
+ subject { group.ci_variables_for("ref", project) }
- shared_examples 'ref is protected' do
- it 'contains all the variables' do
+ shared_examples "ref is protected" do
+ it "contains all the variables" do
is_expected.to contain_exactly(ci_variable, protected_variable)
end
end
- context 'when the ref is not protected' do
+ context "when the ref is not protected" do
before do
stub_application_setting(
- default_branch_protection: Gitlab::Access::PROTECTION_NONE)
+ default_branch_protection: Gitlab::Access::PROTECTION_NONE
+ )
end
- it 'contains only the CI variables' do
+ it "contains only the CI variables" do
is_expected.to contain_exactly(ci_variable)
end
end
- context 'when the ref is a protected branch' do
+ context "when the ref is a protected branch" do
before do
- allow(project).to receive(:protected_for?).with('ref').and_return(true)
+ allow(project).to receive(:protected_for?).with("ref").and_return(true)
end
- it_behaves_like 'ref is protected'
+ it_behaves_like "ref is protected"
end
- context 'when the ref is a protected tag' do
+ context "when the ref is a protected tag" do
before do
- allow(project).to receive(:protected_for?).with('ref').and_return(true)
+ allow(project).to receive(:protected_for?).with("ref").and_return(true)
end
- it_behaves_like 'ref is protected'
+ it_behaves_like "ref is protected"
end
- context 'when group has children', :postgresql do
+ context "when group has children", :postgresql do
let(:group_child) { create(:group, parent: group) }
let(:group_child_2) { create(:group, parent: group_child) }
let(:group_child_3) { create(:group, parent: group_child_2) }
@@ -708,13 +709,13 @@ describe Group do
let(:variable_child_3) { create(:ci_group_variable, group: group_child_3) }
before do
- allow(project).to receive(:protected_for?).with('ref').and_return(true)
+ allow(project).to receive(:protected_for?).with("ref").and_return(true)
end
- it 'returns all variables belong to the group and parent groups' do
+ it "returns all variables belong to the group and parent groups" do
expected_array1 = [protected_variable, ci_variable]
expected_array2 = [variable_child, variable_child_2, variable_child_3]
- got_array = group_child_3.ci_variables_for('ref', project).to_a
+ got_array = group_child_3.ci_variables_for("ref", project).to_a
expect(got_array.shift(2)).to contain_exactly(*expected_array1)
expect(got_array).to eq(expected_array2)
@@ -722,67 +723,67 @@ describe Group do
end
end
- describe '#highest_group_member', :nested_groups do
+ describe "#highest_group_member", :nested_groups do
let(:nested_group) { create(:group, parent: group) }
let(:nested_group_2) { create(:group, parent: nested_group) }
let(:user) { create(:user) }
subject(:highest_group_member) { nested_group_2.highest_group_member(user) }
- context 'when the user is not a member of any group in the hierarchy' do
- it 'returns nil' do
+ context "when the user is not a member of any group in the hierarchy" do
+ it "returns nil" do
expect(highest_group_member).to be_nil
end
end
- context 'when the user is only a member of one group in the hierarchy' do
+ context "when the user is only a member of one group in the hierarchy" do
before do
nested_group.add_developer(user)
end
- it 'returns that group member' do
+ it "returns that group member" do
expect(highest_group_member.access_level).to eq(Gitlab::Access::DEVELOPER)
end
end
- context 'when the user is a member of several groups in the hierarchy' do
+ context "when the user is a member of several groups in the hierarchy" do
before do
group.add_owner(user)
nested_group.add_developer(user)
nested_group_2.add_maintainer(user)
end
- it 'returns the group member with the highest access level' do
+ it "returns the group member with the highest access level" do
expect(highest_group_member.access_level).to eq(Gitlab::Access::OWNER)
end
end
end
- describe '#has_parent?' do
- context 'when the group has a parent' do
- it 'should be truthy' do
+ describe "#has_parent?" do
+ context "when the group has a parent" do
+ it "should be truthy" do
group = create(:group, :nested)
expect(group.has_parent?).to be_truthy
end
end
- context 'when the group has no parent' do
- it 'should be falsy' do
+ context "when the group has no parent" do
+ it "should be falsy" do
group = create(:group, parent: nil)
expect(group.has_parent?).to be_falsy
end
end
end
- context 'with uploads' do
- it_behaves_like 'model with uploads', true do
+ context "with uploads" do
+ it_behaves_like "model with uploads", true do
let(:model_object) { create(:group, :with_avatar) }
let(:upload_attribute) { :avatar }
let(:uploader_class) { AttachmentUploader }
end
end
- describe '#group_clusters_enabled?' do
+ describe "#group_clusters_enabled?" do
before do
# Override global stub in spec/spec_helper.rb
expect(Feature).to receive(:enabled?).and_call_original
@@ -792,7 +793,7 @@ describe Group do
it { is_expected.to be_truthy }
- context 'explicitly disabled for root ancestor' do
+ context "explicitly disabled for root ancestor" do
before do
feature = Feature.get(:group_clusters)
feature.disable(group.root_ancestor)
@@ -801,7 +802,7 @@ describe Group do
it { is_expected.to be_falsey }
end
- context 'explicitly disabled for root ancestor' do
+ context "explicitly disabled for root ancestor" do
before do
feature = Feature.get(:group_clusters)
feature.enable(group.root_ancestor)
diff --git a/spec/models/guest_spec.rb b/spec/models/guest_spec.rb
index fc30f3056e5..154ddec52fc 100644
--- a/spec/models/guest_spec.rb
+++ b/spec/models/guest_spec.rb
@@ -1,42 +1,42 @@
-require 'spec_helper'
+require "spec_helper"
describe Guest do
set(:public_project) { create(:project, :public) }
set(:private_project) { create(:project, :private) }
set(:internal_project) { create(:project, :internal) }
- describe '.can_pull?' do
- context 'when project is private' do
- it 'does not allow to pull the repo' do
+ describe ".can_pull?" do
+ context "when project is private" do
+ it "does not allow to pull the repo" do
expect(described_class.can?(:download_code, private_project)).to eq(false)
end
end
- context 'when project is internal' do
- it 'does not allow to pull the repo' do
+ context "when project is internal" do
+ it "does not allow to pull the repo" do
expect(described_class.can?(:download_code, internal_project)).to eq(false)
end
end
- context 'when project is public' do
- context 'when repository is disabled' do
- it 'does not allow to pull the repo' do
+ context "when project is public" do
+ context "when repository is disabled" do
+ it "does not allow to pull the repo" do
public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::DISABLED)
expect(described_class.can?(:download_code, public_project)).to eq(false)
end
end
- context 'when repository is accessible only by team members' do
- it 'does not allow to pull the repo' do
+ context "when repository is accessible only by team members" do
+ it "does not allow to pull the repo" do
public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::PRIVATE)
expect(described_class.can?(:download_code, public_project)).to eq(false)
end
end
- context 'when repository is enabled' do
- it 'allows to pull the repo' do
+ context "when repository is enabled" do
+ it "allows to pull the repo" do
expect(described_class.can?(:download_code, public_project)).to eq(true)
end
end
diff --git a/spec/models/hooks/active_hook_filter_spec.rb b/spec/models/hooks/active_hook_filter_spec.rb
index df7edda2213..4f36e1b5293 100644
--- a/spec/models/hooks/active_hook_filter_spec.rb
+++ b/spec/models/hooks/active_hook_filter_spec.rb
@@ -1,67 +1,67 @@
-require 'spec_helper'
+require "spec_helper"
describe ActiveHookFilter do
subject(:filter) { described_class.new(hook) }
- describe '#matches?' do
- context 'for push event hooks' do
+ describe "#matches?" do
+ context "for push event hooks" do
let(:hook) do
create(:project_hook, push_events: true, push_events_branch_filter: branch_filter)
end
- context 'branch filter is specified' do
- let(:branch_filter) { 'master' }
+ context "branch filter is specified" do
+ let(:branch_filter) { "master" }
- it 'returns true if branch matches' do
- expect(filter.matches?(:push_hooks, { ref: 'refs/heads/master' })).to be true
+ it "returns true if branch matches" do
+ expect(filter.matches?(:push_hooks, {ref: "refs/heads/master"})).to be true
end
- it 'returns false if branch does not match' do
- expect(filter.matches?(:push_hooks, { ref: 'refs/heads/my_branch' })).to be false
+ it "returns false if branch does not match" do
+ expect(filter.matches?(:push_hooks, {ref: "refs/heads/my_branch"})).to be false
end
- it 'returns false if ref is nil' do
+ it "returns false if ref is nil" do
expect(filter.matches?(:push_hooks, {})).to be false
end
- context 'branch filter contains wildcard' do
- let(:branch_filter) { 'features/*' }
+ context "branch filter contains wildcard" do
+ let(:branch_filter) { "features/*" }
- it 'returns true if branch matches' do
- expect(filter.matches?(:push_hooks, { ref: 'refs/heads/features/my-branch' })).to be true
- expect(filter.matches?(:push_hooks, { ref: 'refs/heads/features/my-branch/something' })).to be true
+ it "returns true if branch matches" do
+ expect(filter.matches?(:push_hooks, {ref: "refs/heads/features/my-branch"})).to be true
+ expect(filter.matches?(:push_hooks, {ref: "refs/heads/features/my-branch/something"})).to be true
end
- it 'returns false if branch does not match' do
- expect(filter.matches?(:push_hooks, { ref: 'refs/heads/master' })).to be false
+ it "returns false if branch does not match" do
+ expect(filter.matches?(:push_hooks, {ref: "refs/heads/master"})).to be false
end
end
end
- context 'branch filter is not specified' do
+ context "branch filter is not specified" do
let(:branch_filter) { nil }
- it 'returns true' do
- expect(filter.matches?(:push_hooks, { ref: 'refs/heads/master' })).to be true
+ it "returns true" do
+ expect(filter.matches?(:push_hooks, {ref: "refs/heads/master"})).to be true
end
end
- context 'branch filter is empty string' do
- let(:branch_filter) { '' }
+ context "branch filter is empty string" do
+ let(:branch_filter) { "" }
- it 'acts like branch is not specified' do
- expect(filter.matches?(:push_hooks, { ref: 'refs/heads/master' })).to be true
+ it "acts like branch is not specified" do
+ expect(filter.matches?(:push_hooks, {ref: "refs/heads/master"})).to be true
end
end
end
- context 'for non-push-events hooks' do
+ context "for non-push-events hooks" do
let(:hook) do
- create(:project_hook, issues_events: true, push_events: false, push_events_branch_filter: '')
+ create(:project_hook, issues_events: true, push_events: false, push_events_branch_filter: "")
end
- it 'returns true as branch filters are not yet supported for these' do
- expect(filter.matches?(:issues_events, { ref: 'refs/heads/master' })).to be true
+ it "returns true as branch filters are not yet supported for these" do
+ expect(filter.matches?(:issues_events, {ref: "refs/heads/master"})).to be true
end
end
end
diff --git a/spec/models/hooks/project_hook_spec.rb b/spec/models/hooks/project_hook_spec.rb
index 5dd31b1b5de..902120967cc 100644
--- a/spec/models/hooks/project_hook_spec.rb
+++ b/spec/models/hooks/project_hook_spec.rb
@@ -1,24 +1,24 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectHook do
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to :project }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:project) }
end
- describe '.push_hooks' do
- it 'returns hooks for push events only' do
+ describe ".push_hooks" do
+ it "returns hooks for push events only" do
hook = create(:project_hook, push_events: true)
create(:project_hook, push_events: false)
expect(described_class.push_hooks).to eq([hook])
end
end
- describe '.tag_push_hooks' do
- it 'returns hooks for tag push events only' do
+ describe ".tag_push_hooks" do
+ it "returns hooks for tag push events only" do
hook = create(:project_hook, tag_push_events: true)
create(:project_hook, tag_push_events: false)
expect(described_class.tag_push_hooks).to eq([hook])
diff --git a/spec/models/hooks/service_hook_spec.rb b/spec/models/hooks/service_hook_spec.rb
index e32eaafc13f..1beace50631 100644
--- a/spec/models/hooks/service_hook_spec.rb
+++ b/spec/models/hooks/service_hook_spec.rb
@@ -1,20 +1,20 @@
-require 'spec_helper'
+require "spec_helper"
describe ServiceHook do
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to :service }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:service) }
end
- describe 'execute' do
+ describe "execute" do
let(:hook) { build(:service_hook) }
- let(:data) { { key: 'value' } }
+ let(:data) { {key: "value"} }
- it '#execute' do
- expect(WebHookService).to receive(:new).with(hook, data, 'service_hook').and_call_original
+ it "#execute" do
+ expect(WebHookService).to receive(:new).with(hook, data, "service_hook").and_call_original
expect_any_instance_of(WebHookService).to receive(:execute)
hook.execute(data)
diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb
index edd1cb455af..9b030282436 100644
--- a/spec/models/hooks/system_hook_spec.rb
+++ b/spec/models/hooks/system_hook_spec.rb
@@ -1,14 +1,14 @@
require "spec_helper"
describe SystemHook do
- context 'default attributes' do
+ context "default attributes" do
let(:system_hook) { build(:system_hook) }
- it 'sets defined default parameters' do
+ it "sets defined default parameters" do
attrs = {
push_events: false,
repository_update_events: true,
- merge_requests_events: false
+ merge_requests_events: false,
}
expect(system_hook).to have_attributes(attrs)
end
@@ -20,7 +20,7 @@ describe SystemHook do
let(:project) { create(:project, namespace: user.namespace) }
let(:group) { create(:group) }
let(:params) do
- { name: 'John Doe', username: 'jduser', email: 'jg@example.com', password: 'mydummypass' }
+ {name: "John Doe", username: "jduser", email: "jg@example.com", password: "mydummypass"}
end
before do
@@ -28,10 +28,10 @@ describe SystemHook do
end
it "project_create hook" do
- Projects::CreateService.new(user, name: 'empty').execute
+ Projects::CreateService.new(user, name: "empty").execute
expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /project_create/,
- headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
+ headers: {"Content-Type" => "application/json", "X-Gitlab-Event" => "System Hook"}
).once
end
@@ -40,7 +40,7 @@ describe SystemHook do
expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /project_destroy/,
- headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
+ headers: {"Content-Type" => "application/json", "X-Gitlab-Event" => "System Hook"}
).once
end
@@ -49,7 +49,7 @@ describe SystemHook do
expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /user_create/,
- headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
+ headers: {"Content-Type" => "application/json", "X-Gitlab-Event" => "System Hook"}
).once
end
@@ -58,7 +58,7 @@ describe SystemHook do
expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /user_destroy/,
- headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
+ headers: {"Content-Type" => "application/json", "X-Gitlab-Event" => "System Hook"}
).once
end
@@ -67,7 +67,7 @@ describe SystemHook do
expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /user_add_to_team/,
- headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
+ headers: {"Content-Type" => "application/json", "X-Gitlab-Event" => "System Hook"}
).once
end
@@ -77,72 +77,72 @@ describe SystemHook do
expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /user_remove_from_team/,
- headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
+ headers: {"Content-Type" => "application/json", "X-Gitlab-Event" => "System Hook"}
).once
end
- it 'group create hook' do
+ it "group create hook" do
create(:group)
expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /group_create/,
- headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
+ headers: {"Content-Type" => "application/json", "X-Gitlab-Event" => "System Hook"}
).once
end
- it 'group destroy hook' do
+ it "group destroy hook" do
group.destroy
expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /group_destroy/,
- headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
+ headers: {"Content-Type" => "application/json", "X-Gitlab-Event" => "System Hook"}
).once
end
- it 'group member create hook' do
+ it "group member create hook" do
group.add_maintainer(user)
expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /user_add_to_group/,
- headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
+ headers: {"Content-Type" => "application/json", "X-Gitlab-Event" => "System Hook"}
).once
end
- it 'group member destroy hook' do
+ it "group member destroy hook" do
group.add_maintainer(user)
group.group_members.destroy_all # rubocop: disable DestroyAll
expect(WebMock).to have_requested(:post, system_hook.url).with(
body: /user_remove_from_group/,
- headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
+ headers: {"Content-Type" => "application/json", "X-Gitlab-Event" => "System Hook"}
).once
end
end
- describe '.repository_update_hooks' do
- it 'returns hooks for repository update events only' do
+ describe ".repository_update_hooks" do
+ it "returns hooks for repository update events only" do
hook = create(:system_hook, repository_update_events: true)
create(:system_hook, repository_update_events: false)
expect(described_class.repository_update_hooks).to eq([hook])
end
end
- describe 'execute WebHookService' do
+ describe "execute WebHookService" do
let(:hook) { build(:system_hook) }
- let(:data) { { key: 'value' } }
- let(:hook_name) { 'system_hook' }
+ let(:data) { {key: "value"} }
+ let(:hook_name) { "system_hook" }
before do
expect(WebHookService).to receive(:new).with(hook, data, hook_name).and_call_original
end
- it '#execute' do
+ it "#execute" do
expect_any_instance_of(WebHookService).to receive(:execute)
hook.execute(data, hook_name)
end
- it '#async_execute' do
+ it "#async_execute" do
expect_any_instance_of(WebHookService).to receive(:async_execute)
hook.async_execute(data, hook_name)
diff --git a/spec/models/hooks/web_hook_log_spec.rb b/spec/models/hooks/web_hook_log_spec.rb
index 744a6ccae8b..13ba8c042a1 100644
--- a/spec/models/hooks/web_hook_log_spec.rb
+++ b/spec/models/hooks/web_hook_log_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
describe WebHookLog do
it { is_expected.to belong_to(:web_hook) }
@@ -9,16 +9,16 @@ describe WebHookLog do
it { is_expected.to validate_presence_of(:web_hook) }
- describe '.recent' do
+ describe ".recent" do
let(:hook) { create(:project_hook) }
- it 'does not return web hook logs that are too old' do
+ it "does not return web hook logs that are too old" do
create(:web_hook_log, web_hook: hook, created_at: 91.days.ago)
expect(described_class.recent.size).to be_zero
end
- it 'returns the web hook logs in descending order' do
+ it "returns the web hook logs in descending order" do
hook1 = create(:web_hook_log, web_hook: hook, created_at: 2.hours.ago)
hook2 = create(:web_hook_log, web_hook: hook, created_at: 1.hour.ago)
hooks = described_class.recent.to_a
@@ -27,21 +27,21 @@ describe WebHookLog do
end
end
- describe '#success?' do
+ describe "#success?" do
let(:web_hook_log) { build(:web_hook_log, response_status: status) }
- describe '2xx' do
- let(:status) { '200' }
+ describe "2xx" do
+ let(:status) { "200" }
it { expect(web_hook_log.success?).to be_truthy }
end
- describe 'not 2xx' do
- let(:status) { '500' }
+ describe "not 2xx" do
+ let(:status) { "500" }
it { expect(web_hook_log.success?).to be_falsey }
end
- describe 'internal erorr' do
- let(:status) { 'internal error' }
+ describe "internal erorr" do
+ let(:status) { "internal error" }
it { expect(web_hook_log.success?).to be_falsey }
end
end
diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb
index a308ac6e33a..0d6e7939add 100644
--- a/spec/models/hooks/web_hook_spec.rb
+++ b/spec/models/hooks/web_hook_spec.rb
@@ -1,83 +1,83 @@
-require 'spec_helper'
+require "spec_helper"
describe WebHook do
let(:hook) { build(:project_hook) }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to have_many(:web_hook_logs).dependent(:destroy) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:url) }
- describe 'url' do
- it { is_expected.to allow_value('http://example.com').for(:url) }
- it { is_expected.to allow_value('https://example.com').for(:url) }
- it { is_expected.to allow_value(' https://example.com ').for(:url) }
- it { is_expected.to allow_value('http://test.com/api').for(:url) }
- it { is_expected.to allow_value('http://test.com/api?key=abc').for(:url) }
- it { is_expected.to allow_value('http://test.com/api?key=abc&type=def').for(:url) }
+ describe "url" do
+ it { is_expected.to allow_value("http://example.com").for(:url) }
+ it { is_expected.to allow_value("https://example.com").for(:url) }
+ it { is_expected.to allow_value(" https://example.com ").for(:url) }
+ it { is_expected.to allow_value("http://test.com/api").for(:url) }
+ it { is_expected.to allow_value("http://test.com/api?key=abc").for(:url) }
+ it { is_expected.to allow_value("http://test.com/api?key=abc&type=def").for(:url) }
- it { is_expected.not_to allow_value('example.com').for(:url) }
- it { is_expected.not_to allow_value('ftp://example.com').for(:url) }
- it { is_expected.not_to allow_value('herp-and-derp').for(:url) }
+ it { is_expected.not_to allow_value("example.com").for(:url) }
+ it { is_expected.not_to allow_value("ftp://example.com").for(:url) }
+ it { is_expected.not_to allow_value("herp-and-derp").for(:url) }
- it 'strips :url before saving it' do
- hook.url = ' https://example.com '
+ it "strips :url before saving it" do
+ hook.url = " https://example.com "
hook.save
- expect(hook.url).to eq('https://example.com')
+ expect(hook.url).to eq("https://example.com")
end
end
- describe 'token' do
+ describe "token" do
it { is_expected.to allow_value("foobar").for(:token) }
it { is_expected.not_to allow_values("foo\nbar", "foo\r\nbar").for(:token) }
end
- describe 'push_events_branch_filter' do
+ describe "push_events_branch_filter" do
it { is_expected.to allow_values("good_branch_name", "another/good-branch_name").for(:push_events_branch_filter) }
it { is_expected.to allow_values("").for(:push_events_branch_filter) }
it { is_expected.not_to allow_values("bad branch name", "bad~branchname").for(:push_events_branch_filter) }
- it 'gets rid of whitespace' do
- hook.push_events_branch_filter = ' branch '
+ it "gets rid of whitespace" do
+ hook.push_events_branch_filter = " branch "
hook.save
- expect(hook.push_events_branch_filter).to eq('branch')
+ expect(hook.push_events_branch_filter).to eq("branch")
end
- it 'stores whitespace only as empty' do
- hook.push_events_branch_filter = ' '
+ it "stores whitespace only as empty" do
+ hook.push_events_branch_filter = " "
hook.save
- expect(hook.push_events_branch_filter).to eq('')
+ expect(hook.push_events_branch_filter).to eq("")
end
end
end
- describe 'encrypted attributes' do
+ describe "encrypted attributes" do
subject { described_class.encrypted_attributes.keys }
it { is_expected.to contain_exactly(:token, :url) }
end
- describe 'execute' do
- let(:data) { { key: 'value' } }
- let(:hook_name) { 'project hook' }
+ describe "execute" do
+ let(:data) { {key: "value"} }
+ let(:hook_name) { "project hook" }
before do
expect(WebHookService).to receive(:new).with(hook, data, hook_name).and_call_original
end
- it '#execute' do
+ it "#execute" do
expect_any_instance_of(WebHookService).to receive(:execute)
hook.execute(data, hook_name)
end
- it '#async_execute' do
+ it "#async_execute" do
expect_any_instance_of(WebHookService).to receive(:async_execute)
hook.async_execute(data, hook_name)
diff --git a/spec/models/identity_spec.rb b/spec/models/identity_spec.rb
index e1a7a59dfd1..bb257acf498 100644
--- a/spec/models/identity_spec.rb
+++ b/spec/models/identity_spec.rb
@@ -1,95 +1,95 @@
-require 'spec_helper'
+require "spec_helper"
describe Identity do
- describe 'relations' do
+ describe "relations" do
it { is_expected.to belong_to(:user) }
end
- describe 'fields' do
+ describe "fields" do
it { is_expected.to respond_to(:provider) }
it { is_expected.to respond_to(:extern_uid) }
end
- describe 'validations' do
+ describe "validations" do
set(:user) { create(:user) }
- context 'with existing user and provider' do
+ context "with existing user and provider" do
before do
- create(:identity, provider: 'ldapmain', user_id: user.id)
+ create(:identity, provider: "ldapmain", user_id: user.id)
end
- it 'returns false for a duplicate entry' do
- identity = user.identities.build(provider: 'ldapmain', user_id: user.id)
+ it "returns false for a duplicate entry" do
+ identity = user.identities.build(provider: "ldapmain", user_id: user.id)
expect(identity.validate).to be_falsey
end
- it 'returns true when a different provider is used' do
- identity = user.identities.build(provider: 'gitlab', user_id: user.id)
+ it "returns true when a different provider is used" do
+ identity = user.identities.build(provider: "gitlab", user_id: user.id)
expect(identity.validate).to be_truthy
end
end
- context 'with newly-created user' do
+ context "with newly-created user" do
before do
- create(:identity, provider: 'ldapmain', user_id: nil)
+ create(:identity, provider: "ldapmain", user_id: nil)
end
- it 'successfully validates even with a nil user_id' do
- identity = user.identities.build(provider: 'ldapmain')
+ it "successfully validates even with a nil user_id" do
+ identity = user.identities.build(provider: "ldapmain")
expect(identity.validate).to be_truthy
end
end
end
- describe '#is_ldap?' do
- let(:ldap_identity) { create(:identity, provider: 'ldapmain') }
- let(:other_identity) { create(:identity, provider: 'twitter') }
+ describe "#is_ldap?" do
+ let(:ldap_identity) { create(:identity, provider: "ldapmain") }
+ let(:other_identity) { create(:identity, provider: "twitter") }
- it 'returns true if it is a ldap identity' do
+ it "returns true if it is a ldap identity" do
expect(ldap_identity.ldap?).to be_truthy
end
- it 'returns false if it is not a ldap identity' do
+ it "returns false if it is not a ldap identity" do
expect(other_identity.ldap?).to be_falsey
end
end
- describe '.with_extern_uid' do
- context 'LDAP identity' do
- let!(:ldap_identity) { create(:identity, provider: 'ldapmain', extern_uid: 'uid=john smith,ou=people,dc=example,dc=com') }
+ describe ".with_extern_uid" do
+ context "LDAP identity" do
+ let!(:ldap_identity) { create(:identity, provider: "ldapmain", extern_uid: "uid=john smith,ou=people,dc=example,dc=com") }
- it 'finds the identity when the DN is formatted differently' do
- identity = described_class.with_extern_uid('ldapmain', 'uid=John Smith, ou=People, dc=example, dc=com').first
+ it "finds the identity when the DN is formatted differently" do
+ identity = described_class.with_extern_uid("ldapmain", "uid=John Smith, ou=People, dc=example, dc=com").first
expect(identity).to eq(ldap_identity)
end
end
- context 'any other provider' do
- let!(:test_entity) { create(:identity, provider: 'test_provider', extern_uid: 'test_uid') }
+ context "any other provider" do
+ let!(:test_entity) { create(:identity, provider: "test_provider", extern_uid: "test_uid") }
- it 'the extern_uid lookup is case insensitive' do
- identity = described_class.with_extern_uid('test_provider', 'TEST_UID').first
+ it "the extern_uid lookup is case insensitive" do
+ identity = described_class.with_extern_uid("test_provider", "TEST_UID").first
expect(identity).to eq(test_entity)
end
end
end
- context 'callbacks' do
- context 'before_save' do
- describe 'normalizes extern uid' do
- let!(:ldap_identity) { create(:identity, provider: 'ldapmain', extern_uid: 'uid=john smith,ou=people,dc=example,dc=com') }
+ context "callbacks" do
+ context "before_save" do
+ describe "normalizes extern uid" do
+ let!(:ldap_identity) { create(:identity, provider: "ldapmain", extern_uid: "uid=john smith,ou=people,dc=example,dc=com") }
- it 'if extern_uid changes' do
+ it "if extern_uid changes" do
expect(ldap_identity).not_to receive(:ensure_normalized_extern_uid)
ldap_identity.save
end
- it 'if current_uid is nil' do
+ it "if current_uid is nil" do
expect(ldap_identity).to receive(:ensure_normalized_extern_uid)
ldap_identity.update(extern_uid: nil)
@@ -97,26 +97,26 @@ describe Identity do
expect(ldap_identity.extern_uid).to be_nil
end
- it 'if extern_uid changed and not nil' do
- ldap_identity.update(extern_uid: 'uid=john1,ou=PEOPLE,dc=example,dc=com')
+ it "if extern_uid changed and not nil" do
+ ldap_identity.update(extern_uid: "uid=john1,ou=PEOPLE,dc=example,dc=com")
- expect(ldap_identity.extern_uid).to eq 'uid=john1,ou=people,dc=example,dc=com'
+ expect(ldap_identity.extern_uid).to eq "uid=john1,ou=people,dc=example,dc=com"
end
end
end
- context 'after_destroy' do
+ context "after_destroy" do
let!(:user) { create(:user) }
- let(:ldap_identity) { create(:identity, provider: 'ldapmain', extern_uid: 'uid=john smith,ou=people,dc=example,dc=com', user: user) }
- let(:ldap_user_synced_attributes) { { provider: 'ldapmain', name_synced: true, email_synced: true } }
- let(:other_provider_user_synced_attributes) { { provider: 'other', name_synced: true, email_synced: true } }
+ let(:ldap_identity) { create(:identity, provider: "ldapmain", extern_uid: "uid=john smith,ou=people,dc=example,dc=com", user: user) }
+ let(:ldap_user_synced_attributes) { {provider: "ldapmain", name_synced: true, email_synced: true} }
+ let(:other_provider_user_synced_attributes) { {provider: "other", name_synced: true, email_synced: true} }
- describe 'if user synced attributes metadada provider' do
- context 'matches the identity provider ' do
- it 'removes the user synced attributes' do
+ describe "if user synced attributes metadada provider" do
+ context "matches the identity provider " do
+ it "removes the user synced attributes" do
user.create_user_synced_attributes_metadata(ldap_user_synced_attributes)
- expect(user.user_synced_attributes_metadata.provider).to eq 'ldapmain'
+ expect(user.user_synced_attributes_metadata.provider).to eq "ldapmain"
ldap_identity.destroy
@@ -124,15 +124,15 @@ describe Identity do
end
end
- context 'does not matche the identity provider' do
- it 'does not remove the user synced attributes' do
+ context "does not matche the identity provider" do
+ it "does not remove the user synced attributes" do
user.create_user_synced_attributes_metadata(other_provider_user_synced_attributes)
- expect(user.user_synced_attributes_metadata.provider).to eq 'other'
+ expect(user.user_synced_attributes_metadata.provider).to eq "other"
ldap_identity.destroy
- expect(user.reload.user_synced_attributes_metadata.provider).to eq 'other'
+ expect(user.reload.user_synced_attributes_metadata.provider).to eq "other"
end
end
end
diff --git a/spec/models/import_export_upload_spec.rb b/spec/models/import_export_upload_spec.rb
index 58af84b8a08..a8715ecce7c 100644
--- a/spec/models/import_export_upload_spec.rb
+++ b/spec/models/import_export_upload_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe ImportExportUpload do
subject { described_class.new(project: create(:project)) }
- shared_examples 'stores the Import/Export file' do |method|
- it 'stores the import file' do
- subject.public_send("#{method}=", fixture_file_upload('spec/fixtures/project_export.tar.gz'))
+ shared_examples "stores the Import/Export file" do |method|
+ it "stores the import file" do
+ subject.public_send("#{method}=", fixture_file_upload("spec/fixtures/project_export.tar.gz"))
subject.save!
@@ -15,11 +15,11 @@ describe ImportExportUpload do
end
end
- context 'import' do
- it_behaves_like 'stores the Import/Export file', :import_file
+ context "import" do
+ it_behaves_like "stores the Import/Export file", :import_file
end
- context 'export' do
- it_behaves_like 'stores the Import/Export file', :export_file
+ context "export" do
+ it_behaves_like "stores the Import/Export file", :export_file
end
end
diff --git a/spec/models/instance_configuration_spec.rb b/spec/models/instance_configuration_spec.rb
index cb3d6c7cda2..e7e81430c8c 100644
--- a/spec/models/instance_configuration_spec.rb
+++ b/spec/models/instance_configuration_spec.rb
@@ -1,27 +1,27 @@
-require 'spec_helper'
+require "spec_helper"
describe InstanceConfiguration do
- context 'without cache' do
- describe '#settings' do
- describe '#ssh_algorithms_hashes' do
- let(:md5) { '5a:65:6c:4d:d4:4c:6d:e6:59:25:b8:cf:ba:34:e7:64' }
- let(:sha256) { 'SHA256:2KJDT7xf2i68mBgJ3TVsjISntg4droLbXYLfQj0VvSY' }
+ context "without cache" do
+ describe "#settings" do
+ describe "#ssh_algorithms_hashes" do
+ let(:md5) { "5a:65:6c:4d:d4:4c:6d:e6:59:25:b8:cf:ba:34:e7:64" }
+ let(:sha256) { "SHA256:2KJDT7xf2i68mBgJ3TVsjISntg4droLbXYLfQj0VvSY" }
- it 'does not return anything if file does not exist' do
+ it "does not return anything if file does not exist" do
stub_pub_file(exist: false)
expect(subject.settings[:ssh_algorithms_hashes]).to be_empty
end
- it 'does not return anything if file is empty' do
+ it "does not return anything if file is empty" do
stub_pub_file
- allow(File).to receive(:read).and_return('')
+ allow(File).to receive(:read).and_return("")
expect(subject.settings[:ssh_algorithms_hashes]).to be_empty
end
- it 'returns the md5 and sha256 if file valid and exists' do
+ it "returns the md5 and sha256 if file valid and exists" do
stub_pub_file
result = subject.settings[:ssh_algorithms_hashes].select { |o| o[:md5] == md5 && o[:sha256] == sha256 }
@@ -30,62 +30,62 @@ describe InstanceConfiguration do
end
def stub_pub_file(exist: true)
- path = 'spec/fixtures/ssh_host_example_key.pub'
- path << 'random' unless exist
+ path = "spec/fixtures/ssh_host_example_key.pub"
+ path << "random" unless exist
allow(subject).to receive(:ssh_algorithm_file).and_return(Rails.root.join(path))
end
end
- describe '#host' do
- it 'returns current instance host' do
- allow(Settings.gitlab).to receive(:host).and_return('exampledomain')
+ describe "#host" do
+ it "returns current instance host" do
+ allow(Settings.gitlab).to receive(:host).and_return("exampledomain")
expect(subject.settings[:host]).to eq(Settings.gitlab.host)
end
end
- describe '#gitlab_pages' do
+ describe "#gitlab_pages" do
let(:gitlab_pages) { subject.settings[:gitlab_pages] }
- it 'returns Settings.pages' do
+ it "returns Settings.pages" do
gitlab_pages.delete(:ip_address)
expect(gitlab_pages).to eq(Settings.pages.symbolize_keys)
end
- it 'returns the GitLab\'s pages host ip address' do
+ it "returns the GitLab's pages host ip address" do
expect(gitlab_pages.keys).to include(:ip_address)
end
- it 'returns the ip address as nil if the domain is invalid' do
- allow(Settings.pages).to receive(:host).and_return('exampledomain')
+ it "returns the ip address as nil if the domain is invalid" do
+ allow(Settings.pages).to receive(:host).and_return("exampledomain")
expect(gitlab_pages[:ip_address]).to eq nil
end
- it 'returns the ip address of the domain' do
- allow(Settings.pages).to receive(:host).and_return('localhost')
+ it "returns the ip address of the domain" do
+ allow(Settings.pages).to receive(:host).and_return("localhost")
- expect(gitlab_pages[:ip_address]).to eq('127.0.0.1').or eq('::1')
+ expect(gitlab_pages[:ip_address]).to eq("127.0.0.1").or eq("::1")
end
end
- describe '#gitlab_ci' do
+ describe "#gitlab_ci" do
let(:gitlab_ci) { subject.settings[:gitlab_ci] }
- it 'returns Settings.gitalb_ci' do
+ it "returns Settings.gitalb_ci" do
gitlab_ci.delete(:artifacts_max_size)
expect(gitlab_ci).to eq(Settings.gitlab_ci.symbolize_keys)
end
- it 'returns the key artifacts_max_size' do
+ it "returns the key artifacts_max_size" do
expect(gitlab_ci.keys).to include(:artifacts_max_size)
end
end
end
end
- context 'with cache', :use_clean_rails_memory_store_caching do
- it 'caches settings content' do
+ context "with cache", :use_clean_rails_memory_store_caching do
+ it "caches settings content" do
expect(Rails.cache.read(described_class::CACHE_KEY)).to be_nil
settings = subject.settings
@@ -93,12 +93,12 @@ describe InstanceConfiguration do
expect(Rails.cache.read(described_class::CACHE_KEY)).to eq(settings)
end
- describe 'cached settings' do
+ describe "cached settings" do
before do
subject.settings
end
- it 'expires after EXPIRATION_TIME' do
+ it "expires after EXPIRATION_TIME" do
allow(Time).to receive(:now).and_return(Time.now + described_class::EXPIRATION_TIME)
Rails.cache.cleanup
diff --git a/spec/models/internal_id_spec.rb b/spec/models/internal_id_spec.rb
index d32f163f05b..c341b53cd57 100644
--- a/spec/models/internal_id_spec.rb
+++ b/spec/models/internal_id_spec.rb
@@ -1,19 +1,19 @@
-require 'spec_helper'
+require "spec_helper"
describe InternalId do
let(:project) { create(:project) }
let(:usage) { :issues }
let(:issue) { build(:issue, project: project) }
- let(:scope) { { project: project } }
+ let(:scope) { {project: project} }
let(:init) { ->(s) { s.project.issues.size } }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- context 'validations' do
+ context "validations" do
it { is_expected.to validate_presence_of(:usage) }
end
- describe '.flush_records!' do
+ describe ".flush_records!" do
subject { described_class.flush_records!(project: project) }
let(:another_project) { create(:project) }
@@ -23,28 +23,28 @@ describe InternalId do
create_list(:issue, 2, project: another_project)
end
- it 'deletes all records for the given project' do
+ it "deletes all records for the given project" do
expect { subject }.to change { described_class.where(project: project).count }.from(1).to(0)
end
- it 'retains records for other projects' do
+ it "retains records for other projects" do
expect { subject }.not_to change { described_class.where(project: another_project).count }
end
- it 'does not allow an empty filter' do
+ it "does not allow an empty filter" do
expect { described_class.flush_records!({}) }.to raise_error(/filter cannot be empty/)
end
end
- describe '.generate_next' do
+ describe ".generate_next" do
subject { described_class.generate_next(issue, scope, usage, init) }
- context 'in the absence of a record' do
- it 'creates a record if not yet present' do
+ context "in the absence of a record" do
+ it "creates a record if not yet present" do
expect { subject }.to change { described_class.count }.from(0).to(1)
end
- it 'stores record attributes' do
+ it "stores record attributes" do
subject
described_class.first.tap do |record|
@@ -53,24 +53,24 @@ describe InternalId do
end
end
- context 'with existing issues' do
+ context "with existing issues" do
before do
create_list(:issue, 2, project: project)
described_class.delete_all
end
- it 'calculates last_value values automatically' do
+ it "calculates last_value values automatically" do
expect(subject).to eq(project.issues.size + 1)
end
end
- context 'with concurrent inserts on table' do
- it 'looks up the record if it was created concurrently' do
- args = { **scope, usage: described_class.usages[usage.to_s] }
+ context "with concurrent inserts on table" do
+ it "looks up the record if it was created concurrently" do
+ args = {**scope, usage: described_class.usages[usage.to_s]}
record = double
expect(described_class).to receive(:find_by).with(args).and_return(nil) # first call, record not present
expect(described_class).to receive(:find_by).with(args).and_return(record) # second call, record was created by another process
- expect(described_class).to receive(:create!).and_raise(ActiveRecord::RecordNotUnique, 'record not unique')
+ expect(described_class).to receive(:create!).and_raise(ActiveRecord::RecordNotUnique, "record not unique")
expect(record).to receive(:increment_and_save!)
subject
@@ -78,25 +78,25 @@ describe InternalId do
end
end
- it 'generates a strictly monotone, gapless sequence' do
- seq = Array.new(10).map do
+ it "generates a strictly monotone, gapless sequence" do
+ seq = Array.new(10).map {
described_class.generate_next(issue, scope, usage, init)
- end
+ }
normalized = seq.map { |i| i - seq.min }
expect(normalized).to eq((0..seq.size - 1).to_a)
end
- context 'with an insufficient schema version' do
+ context "with an insufficient schema version" do
before do
described_class.reset_column_information
# Project factory will also call the current_version
expect(ActiveRecord::Migrator).to receive(:current_version).twice.and_return(InternalId::REQUIRED_SCHEMA_VERSION - 1)
end
- let(:init) { double('block') }
+ let(:init) { double("block") }
- it 'calculates next internal ids on the fly' do
+ it "calculates next internal ids on the fly" do
val = rand(1..100)
expect(init).to receive(:call).with(issue).and_return(val)
@@ -105,17 +105,17 @@ describe InternalId do
end
end
- describe '.track_greatest' do
+ describe ".track_greatest" do
let(:value) { 9001 }
subject { described_class.track_greatest(issue, scope, usage, value, init) }
- context 'in the absence of a record' do
- it 'creates a record if not yet present' do
+ context "in the absence of a record" do
+ it "creates a record if not yet present" do
expect { subject }.to change { described_class.count }.from(0).to(1)
end
end
- it 'stores record attributes' do
+ it "stores record attributes" do
subject
described_class.first.tap do |record|
@@ -125,19 +125,19 @@ describe InternalId do
end
end
- context 'with existing issues' do
+ context "with existing issues" do
before do
create(:issue, project: project)
described_class.delete_all
end
- it 'still returns the last value to that of the given value' do
+ it "still returns the last value to that of the given value" do
expect(subject).to eq(value)
end
end
- context 'when value is less than the current last_value' do
- it 'returns the current last_value' do
+ context "when value is less than the current last_value" do
+ it "returns the current last_value" do
described_class.create!(**scope, usage: usage, last_value: 10_001)
expect(subject).to eq 10_001
@@ -145,48 +145,48 @@ describe InternalId do
end
end
- describe '#increment_and_save!' do
+ describe "#increment_and_save!" do
let(:id) { create(:internal_id) }
subject { id.increment_and_save! }
- it 'returns incremented iid' do
+ it "returns incremented iid" do
value = id.last_value
expect(subject).to eq(value + 1)
end
- it 'saves the record' do
+ it "saves the record" do
subject
expect(id.changed?).to be_falsey
end
- context 'with last_value=nil' do
+ context "with last_value=nil" do
let(:id) { build(:internal_id, last_value: nil) }
- it 'returns 1' do
+ it "returns 1" do
expect(subject).to eq(1)
end
end
end
- describe '#track_greatest_and_save!' do
+ describe "#track_greatest_and_save!" do
let(:id) { create(:internal_id) }
let(:new_last_value) { 9001 }
subject { id.track_greatest_and_save!(new_last_value) }
- it 'returns new last value' do
+ it "returns new last value" do
expect(subject).to eq new_last_value
end
- it 'saves the record' do
+ it "saves the record" do
subject
expect(id.changed?).to be_falsey
end
- context 'when new last value is lower than the max' do
- it 'does not update the last value' do
+ context "when new last value is lower than the max" do
+ it "does not update the last value" do
id.update!(last_value: 10_001)
subject
diff --git a/spec/models/issue/metrics_spec.rb b/spec/models/issue/metrics_spec.rb
index 1bf0ecb98ad..211cb6c5093 100644
--- a/spec/models/issue/metrics_spec.rb
+++ b/spec/models/issue/metrics_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Issue::Metrics do
let(:project) { create(:project) }
diff --git a/spec/models/issue_collection_spec.rb b/spec/models/issue_collection_spec.rb
index 580a98193af..979f549eee5 100644
--- a/spec/models/issue_collection_spec.rb
+++ b/spec/models/issue_collection_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe IssueCollection do
let(:user) { create(:user) }
@@ -7,57 +7,57 @@ describe IssueCollection do
let(:issue2) { create(:issue, project: project) }
let(:collection) { described_class.new([issue1, issue2]) }
- describe '#collection' do
- it 'returns the issues in the same order as the input Array' do
+ describe "#collection" do
+ it "returns the issues in the same order as the input Array" do
expect(collection.collection).to eq([issue1, issue2])
end
end
- describe '#updatable_by_user' do
- context 'using an admin user' do
- it 'returns all issues' do
+ describe "#updatable_by_user" do
+ context "using an admin user" do
+ it "returns all issues" do
user = create(:admin)
expect(collection.updatable_by_user(user)).to eq([issue1, issue2])
end
end
- context 'using a user that has no access to the project' do
- it 'returns no issues when the user is not an assignee or author' do
+ context "using a user that has no access to the project" do
+ it "returns no issues when the user is not an assignee or author" do
expect(collection.updatable_by_user(user)).to be_empty
end
- it 'returns the issues the user is assigned to' do
+ it "returns the issues the user is assigned to" do
issue1.assignees << user
expect(collection.updatable_by_user(user)).to eq([issue1])
end
- it 'returns the issues for which the user is the author' do
+ it "returns the issues for which the user is the author" do
issue1.author = user
expect(collection.updatable_by_user(user)).to eq([issue1])
end
end
- context 'using a user that has reporter access to the project' do
- it 'returns the issues of the project' do
+ context "using a user that has reporter access to the project" do
+ it "returns the issues of the project" do
project.add_reporter(user)
expect(collection.updatable_by_user(user)).to eq([issue1, issue2])
end
end
- context 'using a user that is the owner of a project' do
- it 'returns the issues of the project' do
+ context "using a user that is the owner of a project" do
+ it "returns the issues of the project" do
expect(collection.updatable_by_user(project.namespace.owner))
.to eq([issue1, issue2])
end
end
end
- describe '#visible_to' do
- it 'is an alias for updatable_by_user' do
+ describe "#visible_to" do
+ it "is an alias for updatable_by_user" do
updatable_by_user = described_class.instance_method(:updatable_by_user)
visible_to = described_class.instance_method(:visible_to)
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 6101df2e099..42b01c9234e 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Issue do
describe "Associations" do
@@ -6,7 +6,7 @@ describe Issue do
it { is_expected.to have_many(:assignees) }
end
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Issuable) }
@@ -14,27 +14,27 @@ describe Issue do
it { is_expected.to include_module(Sortable) }
it { is_expected.to include_module(Taskable) }
- it_behaves_like 'AtomicInternalId' do
+ it_behaves_like "AtomicInternalId" do
let(:internal_id_attribute) { :iid }
let(:instance) { build(:issue) }
let(:scope) { :project }
- let(:scope_attrs) { { project: instance.project } }
+ let(:scope_attrs) { {project: instance.project} }
let(:usage) { :issues }
end
end
subject { create(:issue) }
- describe 'callbacks' do
- describe '#ensure_metrics' do
- it 'creates metrics after saving' do
+ describe "callbacks" do
+ describe "#ensure_metrics" do
+ it "creates metrics after saving" do
issue = create(:issue)
expect(issue.metrics).to be_persisted
expect(Issue::Metrics.count).to eq(1)
end
- it 'does not create duplicate metrics for an issue' do
+ it "does not create duplicate metrics for an issue" do
issue = create(:issue)
issue.close!
@@ -43,7 +43,7 @@ describe Issue do
expect(Issue::Metrics.count).to eq(1)
end
- it 'records current metrics' do
+ it "records current metrics" do
expect_any_instance_of(Issue::Metrics).to receive(:record!)
create(:issue)
@@ -51,170 +51,170 @@ describe Issue do
end
end
- describe '#order_by_position_and_priority' do
+ describe "#order_by_position_and_priority" do
let(:project) { create :project }
- let(:p1) { create(:label, title: 'P1', project: project, priority: 1) }
- let(:p2) { create(:label, title: 'P2', project: project, priority: 2) }
+ let(:p1) { create(:label, title: "P1", project: project, priority: 1) }
+ let(:p2) { create(:label, title: "P2", project: project, priority: 2) }
let!(:issue1) { create(:labeled_issue, project: project, labels: [p1]) }
let!(:issue2) { create(:labeled_issue, project: project, labels: [p2]) }
let!(:issue3) { create(:issue, project: project, relative_position: 100) }
let!(:issue4) { create(:issue, project: project, relative_position: 200) }
- it 'returns ordered list' do
+ it "returns ordered list" do
expect(project.issues.order_by_position_and_priority)
.to match [issue3, issue4, issue1, issue2]
end
end
- describe '#card_attributes' do
- it 'includes the author name' do
- allow(subject).to receive(:author).and_return(double(name: 'Robert'))
+ describe "#card_attributes" do
+ it "includes the author name" do
+ allow(subject).to receive(:author).and_return(double(name: "Robert"))
allow(subject).to receive(:assignees).and_return([])
expect(subject.card_attributes)
- .to eq({ 'Author' => 'Robert', 'Assignee' => '' })
+ .to eq({"Author" => "Robert", "Assignee" => ""})
end
- it 'includes the assignee name' do
- allow(subject).to receive(:author).and_return(double(name: 'Robert'))
- allow(subject).to receive(:assignees).and_return([double(name: 'Douwe')])
+ it "includes the assignee name" do
+ allow(subject).to receive(:author).and_return(double(name: "Robert"))
+ allow(subject).to receive(:assignees).and_return([double(name: "Douwe")])
expect(subject.card_attributes)
- .to eq({ 'Author' => 'Robert', 'Assignee' => 'Douwe' })
+ .to eq({"Author" => "Robert", "Assignee" => "Douwe"})
end
end
- describe '#close' do
- subject(:issue) { create(:issue, state: 'opened') }
+ describe "#close" do
+ subject(:issue) { create(:issue, state: "opened") }
- it 'sets closed_at to Time.now when an issue is closed' do
+ it "sets closed_at to Time.now when an issue is closed" do
expect { issue.close }.to change { issue.closed_at }.from(nil)
end
- it 'changes the state to closed' do
- expect { issue.close }.to change { issue.state }.from('opened').to('closed')
+ it "changes the state to closed" do
+ expect { issue.close }.to change { issue.state }.from("opened").to("closed")
end
end
- describe '#reopen' do
+ describe "#reopen" do
let(:user) { create(:user) }
- let(:issue) { create(:issue, state: 'closed', closed_at: Time.now, closed_by: user) }
+ let(:issue) { create(:issue, state: "closed", closed_at: Time.now, closed_by: user) }
- it 'sets closed_at to nil when an issue is reopend' do
+ it "sets closed_at to nil when an issue is reopend" do
expect { issue.reopen }.to change { issue.closed_at }.to(nil)
end
- it 'sets closed_by to nil when an issue is reopend' do
+ it "sets closed_by to nil when an issue is reopend" do
expect { issue.reopen }.to change { issue.closed_by }.from(user).to(nil)
end
- it 'changes the state to opened' do
- expect { issue.reopen }.to change { issue.state }.from('closed').to('opened')
+ it "changes the state to opened" do
+ expect { issue.reopen }.to change { issue.state }.from("closed").to("opened")
end
end
- describe '#to_reference' do
- let(:namespace) { build(:namespace, path: 'sample-namespace') }
- let(:project) { build(:project, name: 'sample-project', namespace: namespace) }
+ describe "#to_reference" do
+ let(:namespace) { build(:namespace, path: "sample-namespace") }
+ let(:project) { build(:project, name: "sample-project", namespace: namespace) }
let(:issue) { build(:issue, iid: 1, project: project) }
- let(:group) { create(:group, name: 'Group', path: 'sample-group') }
+ let(:group) { create(:group, name: "Group", path: "sample-group") }
- context 'when nil argument' do
- it 'returns issue id' do
+ context "when nil argument" do
+ it "returns issue id" do
expect(issue.to_reference).to eq "#1"
end
end
- context 'when full is true' do
- it 'returns complete path to the issue' do
- expect(issue.to_reference(full: true)).to eq 'sample-namespace/sample-project#1'
- expect(issue.to_reference(project, full: true)).to eq 'sample-namespace/sample-project#1'
- expect(issue.to_reference(group, full: true)).to eq 'sample-namespace/sample-project#1'
+ context "when full is true" do
+ it "returns complete path to the issue" do
+ expect(issue.to_reference(full: true)).to eq "sample-namespace/sample-project#1"
+ expect(issue.to_reference(project, full: true)).to eq "sample-namespace/sample-project#1"
+ expect(issue.to_reference(group, full: true)).to eq "sample-namespace/sample-project#1"
end
end
- context 'when same project argument' do
- it 'returns issue id' do
+ context "when same project argument" do
+ it "returns issue id" do
expect(issue.to_reference(project)).to eq("#1")
end
end
- context 'when cross namespace project argument' do
- let(:another_namespace_project) { create(:project, name: 'another-project') }
+ context "when cross namespace project argument" do
+ let(:another_namespace_project) { create(:project, name: "another-project") }
- it 'returns complete path to the issue' do
- expect(issue.to_reference(another_namespace_project)).to eq 'sample-namespace/sample-project#1'
+ it "returns complete path to the issue" do
+ expect(issue.to_reference(another_namespace_project)).to eq "sample-namespace/sample-project#1"
end
end
- it 'supports a cross-project reference' do
- another_project = build(:project, name: 'another-project', namespace: project.namespace)
+ it "supports a cross-project reference" do
+ another_project = build(:project, name: "another-project", namespace: project.namespace)
expect(issue.to_reference(another_project)).to eq "sample-project#1"
end
- context 'when same namespace / cross-project argument' do
+ context "when same namespace / cross-project argument" do
let(:another_project) { create(:project, namespace: namespace) }
- it 'returns path to the issue with the project name' do
- expect(issue.to_reference(another_project)).to eq 'sample-project#1'
+ it "returns path to the issue with the project name" do
+ expect(issue.to_reference(another_project)).to eq "sample-project#1"
end
end
- context 'when different namespace / cross-project argument' do
- let(:another_namespace) { create(:namespace, path: 'another-namespace') }
- let(:another_project) { create(:project, path: 'another-project', namespace: another_namespace) }
+ context "when different namespace / cross-project argument" do
+ let(:another_namespace) { create(:namespace, path: "another-namespace") }
+ let(:another_project) { create(:project, path: "another-project", namespace: another_namespace) }
- it 'returns full path to the issue' do
- expect(issue.to_reference(another_project)).to eq 'sample-namespace/sample-project#1'
+ it "returns full path to the issue" do
+ expect(issue.to_reference(another_project)).to eq "sample-namespace/sample-project#1"
end
end
- context 'when argument is a namespace' do
- context 'with same project path' do
- it 'returns path to the issue with the project name' do
- expect(issue.to_reference(namespace)).to eq 'sample-project#1'
+ context "when argument is a namespace" do
+ context "with same project path" do
+ it "returns path to the issue with the project name" do
+ expect(issue.to_reference(namespace)).to eq "sample-project#1"
end
end
- context 'with different project path' do
- it 'returns full path to the issue' do
- expect(issue.to_reference(group)).to eq 'sample-namespace/sample-project#1'
+ context "with different project path" do
+ it "returns full path to the issue" do
+ expect(issue.to_reference(group)).to eq "sample-namespace/sample-project#1"
end
end
end
end
- describe '#assignee_or_author?' do
+ describe "#assignee_or_author?" do
let(:user) { create(:user) }
let(:issue) { create(:issue) }
- it 'returns true for a user that is assigned to an issue' do
+ it "returns true for a user that is assigned to an issue" do
issue.assignees << user
expect(issue.assignee_or_author?(user)).to be_truthy
end
- it 'returns true for a user that is the author of an issue' do
+ it "returns true for a user that is the author of an issue" do
issue.update(author: user)
expect(issue.assignee_or_author?(user)).to be_truthy
end
- it 'returns false for a user that is not the assignee or author' do
+ it "returns false for a user that is not the assignee or author" do
expect(issue.assignee_or_author?(user)).to be_falsey
end
end
- describe '#can_move?' do
+ describe "#can_move?" do
let(:user) { create(:user) }
let(:issue) { create(:issue) }
subject { issue.can_move?(user) }
- context 'user is not a member of project issue belongs to' do
+ context "user is not a member of project issue belongs to" do
it { is_expected.to eq false}
end
- context 'user is reporter in project issue belongs to' do
+ context "user is reporter in project issue belongs to" do
let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) }
@@ -224,16 +224,16 @@ describe Issue do
it { is_expected.to eq true }
- context 'issue not persisted' do
+ context "issue not persisted" do
let(:issue) { build(:issue, project: project) }
it { is_expected.to eq false }
end
- context 'checking destination project also' do
+ context "checking destination project also" do
subject { issue.can_move?(user, to_project) }
let(:to_project) { create(:project) }
- context 'destination project allowed' do
+ context "destination project allowed" do
before do
to_project.add_reporter(user)
end
@@ -241,7 +241,7 @@ describe Issue do
it { is_expected.to eq true }
end
- context 'destination project not allowed' do
+ context "destination project not allowed" do
before do
to_project.add_guest(user)
end
@@ -252,15 +252,15 @@ describe Issue do
end
end
- describe '#moved?' do
+ describe "#moved?" do
let(:issue) { create(:issue) }
subject { issue.moved? }
- context 'issue not moved' do
+ context "issue not moved" do
it { is_expected.to eq false }
end
- context 'issue already moved' do
+ context "issue already moved" do
let(:moved_to_issue) { create(:issue) }
let(:issue) { create(:issue, moved_to: moved_to_issue) }
@@ -268,7 +268,7 @@ describe Issue do
end
end
- describe '#suggested_branch_name' do
+ describe "#suggested_branch_name" do
let(:repository) { double }
subject { build(:issue) }
@@ -277,44 +277,44 @@ describe Issue do
allow(subject.project).to receive(:repository).and_return(repository)
end
- context '#to_branch_name does not exists' do
+ context "#to_branch_name does not exists" do
before do
allow(repository).to receive(:branch_exists?).and_return(false)
end
- it 'returns #to_branch_name' do
+ it "returns #to_branch_name" do
expect(subject.suggested_branch_name).to eq(subject.to_branch_name)
end
end
- context '#to_branch_name exists not ending with -index' do
+ context "#to_branch_name exists not ending with -index" do
before do
allow(repository).to receive(:branch_exists?).and_return(true)
allow(repository).to receive(:branch_exists?).with(/#{subject.to_branch_name}-\d/).and_return(false)
end
- it 'returns #to_branch_name ending with -2' do
+ it "returns #to_branch_name ending with -2" do
expect(subject.suggested_branch_name).to eq("#{subject.to_branch_name}-2")
end
end
- context '#to_branch_name exists ending with -index' do
+ context "#to_branch_name exists ending with -index" do
before do
allow(repository).to receive(:branch_exists?).and_return(true)
allow(repository).to receive(:branch_exists?).with("#{subject.to_branch_name}-3").and_return(false)
end
- it 'returns #to_branch_name ending with max index + 1' do
+ it "returns #to_branch_name ending with max index + 1" do
expect(subject.suggested_branch_name).to eq("#{subject.to_branch_name}-3")
end
end
end
- describe '#has_related_branch?' do
+ describe "#has_related_branch?" do
let(:issue) { create(:issue, title: "Blue Bell Knoll") }
subject { issue.has_related_branch? }
- context 'branch found' do
+ context "branch found" do
before do
allow(issue.project.repository).to receive(:branch_names).and_return(["iceblink-luck", issue.to_branch_name])
end
@@ -322,7 +322,7 @@ describe Issue do
it { is_expected.to eq true }
end
- context 'branch not found' do
+ context "branch not found" do
before do
allow(issue.project.repository).to receive(:branch_names).and_return(["lazy-calm"])
end
@@ -331,21 +331,21 @@ describe Issue do
end
end
- it_behaves_like 'an editable mentionable' do
+ it_behaves_like "an editable mentionable" do
subject { create(:issue, project: create(:project, :repository)) }
let(:backref_text) { "issue #{subject.to_reference}" }
let(:set_mentionable_text) { ->(txt) { subject.description = txt } }
end
- it_behaves_like 'a Taskable' do
+ it_behaves_like "a Taskable" do
let(:subject) { create :issue }
end
describe "#to_branch_name" do
- let(:issue) { create(:issue, title: 'testing-issue') }
+ let(:issue) { create(:issue, title: "testing-issue") }
- it 'starts with the issue iid' do
+ it "starts with the issue iid" do
expect(issue.to_branch_name).to match /\A#{issue.iid}-[A-Za-z\-]+\z/
end
@@ -354,22 +354,22 @@ describe Issue do
end
it "does not contain the issue title if confidential" do
- issue = create(:issue, title: 'testing-issue', confidential: true)
+ issue = create(:issue, title: "testing-issue", confidential: true)
expect(issue.to_branch_name).to match /confidential-issue\z/
end
end
- describe '#can_be_worked_on?' do
+ describe "#can_be_worked_on?" do
let(:project) { build(:project) }
subject { build(:issue, :opened, project: project) }
- context 'is closed' do
+ context "is closed" do
subject { build(:issue, :closed) }
it { is_expected.not_to be_can_be_worked_on }
end
- context 'project is forked' do
+ context "project is forked" do
before do
allow(project).to receive(:forked?).and_return(true)
end
@@ -380,46 +380,46 @@ describe Issue do
it { is_expected.to be_can_be_worked_on }
end
- describe '#participants' do
- context 'using a public project' do
+ describe "#participants" do
+ context "using a public project" do
let(:project) { create(:project, :public) }
let(:issue) { create(:issue, project: project) }
let!(:note1) do
- create(:note_on_issue, noteable: issue, project: project, note: 'a')
+ create(:note_on_issue, noteable: issue, project: project, note: "a")
end
let!(:note2) do
- create(:note_on_issue, noteable: issue, project: project, note: 'b')
+ create(:note_on_issue, noteable: issue, project: project, note: "b")
end
- it 'includes the issue author' do
+ it "includes the issue author" do
expect(issue.participants).to include(issue.author)
end
- it 'includes the authors of the notes' do
+ it "includes the authors of the notes" do
expect(issue.participants).to include(note1.author, note2.author)
end
end
- context 'using a private project' do
- it 'does not include mentioned users that do not have access to the project' do
+ context "using a private project" do
+ it "does not include mentioned users that do not have access to the project" do
project = create(:project)
user = create(:user)
issue = create(:issue, project: project)
create(:note_on_issue,
- noteable: issue,
- project: project,
- note: user.to_reference)
+ noteable: issue,
+ project: project,
+ note: user.to_reference)
expect(issue.participants).not_to include(user)
end
end
end
- describe 'cached counts' do
- it 'updates when assignees change' do
+ describe "cached counts" do
+ it "updates when assignees change" do
user1 = create(:user)
user2 = create(:user)
project = create(:project)
@@ -438,40 +438,40 @@ describe Issue do
end
end
- describe '#visible_to_user?' do
- context 'without a user' do
+ describe "#visible_to_user?" do
+ context "without a user" do
let(:issue) { build(:issue) }
- it 'returns true when the issue is publicly visible' do
+ it "returns true when the issue is publicly visible" do
expect(issue).to receive(:publicly_visible?).and_return(true)
expect(issue.visible_to_user?).to eq(true)
end
- it 'returns false when the issue is not publicly visible' do
+ it "returns false when the issue is not publicly visible" do
expect(issue).to receive(:publicly_visible?).and_return(false)
expect(issue.visible_to_user?).to eq(false)
end
end
- context 'with a user' do
+ context "with a user" do
let(:user) { create(:user) }
let(:issue) { build(:issue) }
- it 'returns true when the issue is readable' do
+ it "returns true when the issue is readable" do
expect(issue).to receive(:readable_by?).with(user).and_return(true)
expect(issue.visible_to_user?(user)).to eq(true)
end
- it 'returns false when the issue is not readable' do
+ it "returns false when the issue is not readable" do
expect(issue).to receive(:readable_by?).with(user).and_return(false)
expect(issue.visible_to_user?(user)).to eq(false)
end
- it 'returns false when feature is disabled' do
+ it "returns false when feature is disabled" do
expect(issue).not_to receive(:readable_by?)
issue.project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED)
@@ -479,7 +479,7 @@ describe Issue do
expect(issue.visible_to_user?(user)).to eq(false)
end
- it 'returns false when restricted for members' do
+ it "returns false when restricted for members" do
expect(issue).not_to receive(:readable_by?)
issue.project.project_feature.update_attribute(:issues_access_level, ProjectFeature::PRIVATE)
@@ -488,54 +488,54 @@ describe Issue do
end
end
- describe 'with a regular user that is not a team member' do
+ describe "with a regular user that is not a team member" do
let(:user) { create(:user) }
- context 'using a public project' do
+ context "using a public project" do
let(:project) { create(:project, :public) }
- it 'returns true for a regular issue' do
+ it "returns true for a regular issue" do
issue = build(:issue, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
end
- it 'returns false for a confidential issue' do
+ it "returns false for a confidential issue" do
issue = build(:issue, project: project, confidential: true)
expect(issue.visible_to_user?(user)).to eq(false)
end
end
- context 'using an internal project' do
+ context "using an internal project" do
let(:project) { create(:project, :internal) }
- context 'using an internal user' do
- it 'returns true for a regular issue' do
+ context "using an internal user" do
+ it "returns true for a regular issue" do
issue = build(:issue, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
end
- it 'returns false for a confidential issue' do
+ it "returns false for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue.visible_to_user?(user)).to eq(false)
end
end
- context 'using an external user' do
+ context "using an external user" do
before do
allow(user).to receive(:external?).and_return(true)
end
- it 'returns false for a regular issue' do
+ it "returns false for a regular issue" do
issue = build(:issue, project: project)
expect(issue.visible_to_user?(user)).to eq(false)
end
- it 'returns false for a confidential issue' do
+ it "returns false for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue.visible_to_user?(user)).to eq(false)
@@ -543,33 +543,33 @@ describe Issue do
end
end
- context 'using a private project' do
+ context "using a private project" do
let(:project) { create(:project, :private) }
- it 'returns false for a regular issue' do
+ it "returns false for a regular issue" do
issue = build(:issue, project: project)
expect(issue.visible_to_user?(user)).to eq(false)
end
- it 'returns false for a confidential issue' do
+ it "returns false for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue.visible_to_user?(user)).to eq(false)
end
- context 'when the user is the project owner' do
+ context "when the user is the project owner" do
before do
project.add_maintainer(user)
end
- it 'returns true for a regular issue' do
+ it "returns true for a regular issue" do
issue = build(:issue, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
end
- it 'returns true for a confidential issue' do
+ it "returns true for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
@@ -578,62 +578,62 @@ describe Issue do
end
end
- context 'with a regular user that is a team member' do
+ context "with a regular user that is a team member" do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
- context 'using a public project' do
+ context "using a public project" do
before do
project.add_developer(user)
end
- it 'returns true for a regular issue' do
+ it "returns true for a regular issue" do
issue = build(:issue, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
end
- it 'returns true for a confidential issue' do
+ it "returns true for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
end
end
- context 'using an internal project' do
+ context "using an internal project" do
let(:project) { create(:project, :internal) }
before do
project.add_developer(user)
end
- it 'returns true for a regular issue' do
+ it "returns true for a regular issue" do
issue = build(:issue, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
end
- it 'returns true for a confidential issue' do
+ it "returns true for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
end
end
- context 'using a private project' do
+ context "using a private project" do
let(:project) { create(:project, :private) }
before do
project.add_developer(user)
end
- it 'returns true for a regular issue' do
+ it "returns true for a regular issue" do
issue = build(:issue, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
end
- it 'returns true for a confidential issue' do
+ it "returns true for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
@@ -641,17 +641,17 @@ describe Issue do
end
end
- context 'with an admin user' do
+ context "with an admin user" do
let(:project) { create(:project) }
let(:user) { create(:admin) }
- it 'returns true for a regular issue' do
+ it "returns true for a regular issue" do
issue = build(:issue, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
end
- it 'returns true for a confidential issue' do
+ it "returns true for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue.visible_to_user?(user)).to eq(true)
@@ -659,49 +659,49 @@ describe Issue do
end
end
- describe '#publicly_visible?' do
- context 'using a public project' do
+ describe "#publicly_visible?" do
+ context "using a public project" do
let(:project) { create(:project, :public) }
- it 'returns true for a regular issue' do
+ it "returns true for a regular issue" do
issue = build(:issue, project: project)
expect(issue).to be_truthy
end
- it 'returns false for a confidential issue' do
+ it "returns false for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue).not_to be_falsy
end
end
- context 'using an internal project' do
+ context "using an internal project" do
let(:project) { create(:project, :internal) }
- it 'returns false for a regular issue' do
+ it "returns false for a regular issue" do
issue = build(:issue, project: project)
expect(issue).not_to be_falsy
end
- it 'returns false for a confidential issue' do
+ it "returns false for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue).not_to be_falsy
end
end
- context 'using a private project' do
+ context "using a private project" do
let(:project) { create(:project, :private) }
- it 'returns false for a regular issue' do
+ it "returns false for a regular issue" do
issue = build(:issue, project: project)
expect(issue).not_to be_falsy
end
- it 'returns false for a confidential issue' do
+ it "returns false for a confidential issue" do
issue = build(:issue, :confidential, project: project)
expect(issue).not_to be_falsy
@@ -709,8 +709,8 @@ describe Issue do
end
end
- describe '#hook_attrs' do
- it 'delegates to Gitlab::HookData::IssueBuilder#build' do
+ describe "#hook_attrs" do
+ it "delegates to Gitlab::HookData::IssueBuilder#build" do
builder = double
expect(Gitlab::HookData::IssueBuilder)
@@ -721,24 +721,24 @@ describe Issue do
end
end
- describe '#check_for_spam?' do
+ describe "#check_for_spam?" do
using RSpec::Parameterized::TableSyntax
where(:visibility_level, :confidential, :new_attributes, :check_for_spam?) do
- Gitlab::VisibilityLevel::PUBLIC | false | { description: 'woo' } | true
- Gitlab::VisibilityLevel::PUBLIC | false | { title: 'woo' } | true
- Gitlab::VisibilityLevel::PUBLIC | true | { confidential: false } | true
- Gitlab::VisibilityLevel::PUBLIC | true | { description: 'woo' } | false
- Gitlab::VisibilityLevel::PUBLIC | false | { title: 'woo', confidential: true } | false
- Gitlab::VisibilityLevel::PUBLIC | false | { description: 'original description' } | false
- Gitlab::VisibilityLevel::INTERNAL | false | { description: 'woo' } | false
- Gitlab::VisibilityLevel::PRIVATE | false | { description: 'woo' } | false
+ Gitlab::VisibilityLevel::PUBLIC | false | {description: "woo"} | true
+ Gitlab::VisibilityLevel::PUBLIC | false | {title: "woo"} | true
+ Gitlab::VisibilityLevel::PUBLIC | true | {confidential: false} | true
+ Gitlab::VisibilityLevel::PUBLIC | true | {description: "woo"} | false
+ Gitlab::VisibilityLevel::PUBLIC | false | {title: "woo", confidential: true} | false
+ Gitlab::VisibilityLevel::PUBLIC | false | {description: "original description"} | false
+ Gitlab::VisibilityLevel::INTERNAL | false | {description: "woo"} | false
+ Gitlab::VisibilityLevel::PRIVATE | false | {description: "woo"} | false
end
with_them do
- it 'checks for spam on issues that can be seen anonymously' do
+ it "checks for spam on issues that can be seen anonymously" do
project = create(:project, visibility_level: visibility_level)
- issue = create(:issue, project: project, confidential: confidential, description: 'original description')
+ issue = create(:issue, project: project, confidential: confidential, description: "original description")
issue.assign_attributes(new_attributes)
@@ -747,8 +747,8 @@ describe Issue do
end
end
- describe 'removing an issue' do
- it 'refreshes the number of open issues of the project' do
+ describe "removing an issue" do
+ it "refreshes the number of open issues of the project" do
project = subject.project
expect { subject.destroy }
@@ -756,8 +756,8 @@ describe Issue do
end
end
- describe '.public_only' do
- it 'only returns public issues' do
+ describe ".public_only" do
+ it "only returns public issues" do
public_issue = create(:issue)
create(:issue, confidential: true)
@@ -765,8 +765,8 @@ describe Issue do
end
end
- describe '.confidential_only' do
- it 'only returns confidential_only issues' do
+ describe ".confidential_only" do
+ it "only returns confidential_only issues" do
create(:issue)
confidential_issue = create(:issue, confidential: true)
@@ -774,7 +774,7 @@ describe Issue do
end
end
- it_behaves_like 'throttled touch' do
+ it_behaves_like "throttled touch" do
subject { create(:issue, updated_at: 1.hour.ago) }
end
end
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb
index 06d26ef89f1..61ebbfe4e71 100644
--- a/spec/models/key_spec.rb
+++ b/spec/models/key_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Key, :mailer do
describe "Associations" do
@@ -18,7 +18,7 @@ describe Key, :mailer do
it { is_expected.to allow_value(attributes_for(:dsa_key_2048)[:key]).for(:key) }
it { is_expected.to allow_value(attributes_for(:ecdsa_key_256)[:key]).for(:key) }
it { is_expected.to allow_value(attributes_for(:ed25519_key_256)[:key]).for(:key) }
- it { is_expected.not_to allow_value('foo-bar').for(:key) }
+ it { is_expected.not_to allow_value("foo-bar").for(:key) }
end
describe "Methods" do
@@ -27,13 +27,13 @@ describe Key, :mailer do
it { is_expected.to respond_to :publishable_key }
describe "#publishable_keys" do
- it 'replaces SSH key comment with simple identifier of username + hostname' do
+ it "replaces SSH key comment with simple identifier of username + hostname" do
expect(build(:key, user: user).publishable_key).to include("#{user.name} (#{Gitlab.config.gitlab.host})")
end
end
describe "#update_last_used_at" do
- it 'updates the last used timestamp' do
+ it "updates the last used timestamp" do
key = build(:key)
service = double(:service)
@@ -64,7 +64,7 @@ describe Key, :mailer do
it "does not accept a duplicate key with a different comment" do
first_key = create(:key, user: user)
duplicate = build(:key, user: user, key: first_key.key)
- duplicate.key << ' extra comment'
+ duplicate.key << " extra comment"
expect(duplicate).not_to be_valid
end
@@ -75,15 +75,15 @@ describe Key, :mailer do
expect(build(:key)).to be_valid
end
- it 'rejects the unfingerprintable key (not a key)' do
- expect(build(:key, key: 'ssh-rsa an-invalid-key==')).not_to be_valid
+ it "rejects the unfingerprintable key (not a key)" do
+ expect(build(:key, key: "ssh-rsa an-invalid-key==")).not_to be_valid
end
where(:factory, :chars, :expected_sections) do
[
[:key, ["\n", "\r\n"], 3],
- [:key, [' ', ' '], 3],
- [:key_without_comment, [' ', ' '], 2]
+ [:key, [" ", " "], 3],
+ [:key_without_comment, [" ", " "], 2],
]
end
@@ -91,7 +91,7 @@ describe Key, :mailer do
let!(:key) { create(factory) }
let!(:original_fingerprint) { key.fingerprint }
- it 'accepts a key with blank space characters after stripping them' do
+ it "accepts a key with blank space characters after stripping them" do
modified_key = key.key.insert(100, chars.first).insert(40, chars.last)
_, content = modified_key.split
@@ -106,7 +106,7 @@ describe Key, :mailer do
end
end
- context 'validate it meets key restrictions' do
+ context "validate it meets key restrictions" do
where(:factory, :minimum, :result) do
forbidden = ApplicationSetting::FORBIDDEN_KEY_VALUE
@@ -133,7 +133,7 @@ describe Key, :mailer do
[:rsa_key_2048, forbidden, false],
[:dsa_key_2048, forbidden, false],
[:ecdsa_key_256, forbidden, false],
- [:ed25519_key_256, forbidden, false]
+ [:ed25519_key_256, forbidden, false],
]
end
@@ -148,30 +148,30 @@ describe Key, :mailer do
end
end
- context 'callbacks' do
- it 'adds new key to authorized_file' do
+ context "callbacks" do
+ it "adds new key to authorized_file" do
key = build(:personal_key, id: 7)
expect(GitlabShellWorker).to receive(:perform_async).with(:add_key, key.shell_id, key.key)
key.save!
end
- it 'removes key from authorized_file' do
+ it "removes key from authorized_file" do
key = create(:personal_key)
expect(GitlabShellWorker).to receive(:perform_async).with(:remove_key, key.shell_id, key.key)
key.destroy
end
end
- describe '#key=' do
+ describe "#key=" do
let(:valid_key) do
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= dummy@gitlab.com"
end
- it 'strips white spaces' do
+ it "strips white spaces" do
expect(described_class.new(key: " #{valid_key} ").key).to eq(valid_key)
end
- it 'invalidates the public_key attribute' do
+ it "invalidates the public_key attribute" do
key = build(:key)
original = key.public_key
@@ -182,9 +182,9 @@ describe Key, :mailer do
end
end
- describe '#refresh_user_cache', :use_clean_rails_memory_store_caching do
- context 'when the key belongs to a user' do
- it 'refreshes the keys count cache for the user' do
+ describe "#refresh_user_cache", :use_clean_rails_memory_store_caching do
+ context "when the key belongs to a user" do
+ it "refreshes the keys count cache for the user" do
expect_any_instance_of(Users::KeysCountService)
.to receive(:refresh_cache)
.and_call_original
@@ -195,8 +195,8 @@ describe Key, :mailer do
end
end
- context 'when the key does not belong to a user' do
- it 'does nothing' do
+ context "when the key does not belong to a user" do
+ it "does nothing" do
expect_any_instance_of(Users::KeysCountService)
.not_to receive(:refresh_cache)
diff --git a/spec/models/label_link_spec.rb b/spec/models/label_link_spec.rb
index e2b49bc2de7..14f3081df50 100644
--- a/spec/models/label_link_spec.rb
+++ b/spec/models/label_link_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe LabelLink do
it { expect(build(:label_link)).to be_valid }
diff --git a/spec/models/label_note_spec.rb b/spec/models/label_note_spec.rb
index dd2c702a7a9..ae2373a3325 100644
--- a/spec/models/label_note_spec.rb
+++ b/spec/models/label_note_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe LabelNote do
set(:project) { create(:project, :repository) }
@@ -9,15 +9,15 @@ describe LabelNote do
set(:label2) { create(:label, project: project) }
let(:resource_parent) { project }
- context 'when resource is issue' do
+ context "when resource is issue" do
set(:resource) { create(:issue, project: project) }
- it_behaves_like 'label note created from events'
+ it_behaves_like "label note created from events"
end
- context 'when resource is merge request' do
+ context "when resource is merge request" do
set(:resource) { create(:merge_request, source_project: project, target_project: project) }
- it_behaves_like 'label note created from events'
+ it_behaves_like "label note created from events"
end
end
diff --git a/spec/models/label_priority_spec.rb b/spec/models/label_priority_spec.rb
index 9dcb0f06b20..d1a436a4278 100644
--- a/spec/models/label_priority_spec.rb
+++ b/spec/models/label_priority_spec.rb
@@ -1,17 +1,17 @@
-require 'spec_helper'
+require "spec_helper"
describe LabelPriority do
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:label) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:label) }
it { is_expected.to validate_numericality_of(:priority).only_integer.is_greater_than_or_equal_to(0) }
- it 'validates uniqueness of label_id scoped to project_id' do
+ it "validates uniqueness of label_id scoped to project_id" do
create(:label_priority)
expect(subject).to validate_uniqueness_of(:label_id).scoped_to(:project_id)
diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb
index 3fc6c06b7fa..26370d012a9 100644
--- a/spec/models/label_spec.rb
+++ b/spec/models/label_spec.rb
@@ -1,64 +1,64 @@
-require 'spec_helper'
+require "spec_helper"
describe Label do
- describe 'modules' do
+ describe "modules" do
it { is_expected.to include_module(Referable) }
it { is_expected.to include_module(Subscribable) }
end
- describe 'associations' do
+ describe "associations" do
it { is_expected.to have_many(:issues).through(:label_links).source(:target) }
it { is_expected.to have_many(:label_links).dependent(:destroy) }
it { is_expected.to have_many(:lists).dependent(:destroy) }
- it { is_expected.to have_many(:priorities).class_name('LabelPriority') }
+ it { is_expected.to have_many(:priorities).class_name("LabelPriority") }
end
- describe 'validation' do
+ describe "validation" do
it { is_expected.to validate_uniqueness_of(:title).scoped_to([:group_id, :project_id]) }
- it 'validates color code' do
- is_expected.not_to allow_value('G-ITLAB').for(:color)
- is_expected.not_to allow_value('AABBCC').for(:color)
- is_expected.not_to allow_value('#AABBCCEE').for(:color)
- is_expected.not_to allow_value('GGHHII').for(:color)
- is_expected.not_to allow_value('#').for(:color)
- is_expected.not_to allow_value('').for(:color)
+ it "validates color code" do
+ is_expected.not_to allow_value("G-ITLAB").for(:color)
+ is_expected.not_to allow_value("AABBCC").for(:color)
+ is_expected.not_to allow_value("#AABBCCEE").for(:color)
+ is_expected.not_to allow_value("GGHHII").for(:color)
+ is_expected.not_to allow_value("#").for(:color)
+ is_expected.not_to allow_value("").for(:color)
- is_expected.to allow_value('#AABBCC').for(:color)
- is_expected.to allow_value('#abcdef').for(:color)
+ is_expected.to allow_value("#AABBCC").for(:color)
+ is_expected.to allow_value("#abcdef").for(:color)
end
- it 'validates title' do
- is_expected.not_to allow_value('G,ITLAB').for(:title)
- is_expected.not_to allow_value('').for(:title)
- is_expected.not_to allow_value('s' * 256).for(:title)
+ it "validates title" do
+ is_expected.not_to allow_value("G,ITLAB").for(:title)
+ is_expected.not_to allow_value("").for(:title)
+ is_expected.not_to allow_value("s" * 256).for(:title)
- is_expected.to allow_value('GITLAB').for(:title)
- is_expected.to allow_value('gitlab').for(:title)
- is_expected.to allow_value('G?ITLAB').for(:title)
- is_expected.to allow_value('G&ITLAB').for(:title)
+ is_expected.to allow_value("GITLAB").for(:title)
+ is_expected.to allow_value("gitlab").for(:title)
+ is_expected.to allow_value("G?ITLAB").for(:title)
+ is_expected.to allow_value("G&ITLAB").for(:title)
is_expected.to allow_value("customer's request").for(:title)
- is_expected.to allow_value('s' * 255).for(:title)
+ is_expected.to allow_value("s" * 255).for(:title)
end
end
- describe '#color' do
- it 'strips color' do
- label = described_class.new(color: ' #abcdef ')
+ describe "#color" do
+ it "strips color" do
+ label = described_class.new(color: " #abcdef ")
label.valid?
- expect(label.color).to eq('#abcdef')
+ expect(label.color).to eq("#abcdef")
end
- it 'uses default color if color is missing' do
+ it "uses default color if color is missing" do
label = described_class.new(color: nil)
expect(label.color).to be(Label::DEFAULT_COLOR)
end
end
- describe '#text_color' do
- it 'uses default color if color is missing' do
+ describe "#text_color" do
+ it "uses default color if color is missing" do
expect(LabelsHelper).to receive(:text_color_for_bg).with(Label::DEFAULT_COLOR)
.and_return(spy)
@@ -68,46 +68,46 @@ describe Label do
end
end
- describe '#title' do
- it 'sanitizes title' do
- label = described_class.new(title: '<b>foo & bar?</b>')
- expect(label.title).to eq('foo & bar?')
+ describe "#title" do
+ it "sanitizes title" do
+ label = described_class.new(title: "<b>foo & bar?</b>")
+ expect(label.title).to eq("foo & bar?")
end
- it 'strips title' do
- label = described_class.new(title: ' label ')
+ it "strips title" do
+ label = described_class.new(title: " label ")
label.valid?
- expect(label.title).to eq('label')
+ expect(label.title).to eq("label")
end
end
- describe 'priorization' do
+ describe "priorization" do
subject(:label) { create(:label) }
let(:project) { label.project }
- describe '#prioritize!' do
- context 'when label is not prioritized' do
- it 'creates a label priority' do
+ describe "#prioritize!" do
+ context "when label is not prioritized" do
+ it "creates a label priority" do
expect { label.prioritize!(project, 1) }.to change(label.priorities, :count).by(1)
end
- it 'sets label priority' do
+ it "sets label priority" do
label.prioritize!(project, 1)
expect(label.priorities.first.priority).to eq 1
end
end
- context 'when label is prioritized' do
+ context "when label is prioritized" do
let!(:priority) { create(:label_priority, project: project, label: label, priority: 0) }
- it 'does not create a label priority' do
+ it "does not create a label priority" do
expect { label.prioritize!(project, 1) }.not_to change(label.priorities, :count)
end
- it 'updates label priority' do
+ it "updates label priority" do
label.prioritize!(project, 1)
expect(priority.reload.priority).to eq 1
@@ -115,23 +115,23 @@ describe Label do
end
end
- describe '#unprioritize!' do
- it 'removes label priority' do
+ describe "#unprioritize!" do
+ it "removes label priority" do
create(:label_priority, project: project, label: label, priority: 0)
expect { label.unprioritize!(project) }.to change(label.priorities, :count).by(-1)
end
end
- describe '#priority' do
- context 'when label is not prioritized' do
- it 'returns nil' do
+ describe "#priority" do
+ context "when label is not prioritized" do
+ it "returns nil" do
expect(label.priority(project)).to be_nil
end
end
- context 'when label is prioritized' do
- it 'returns label priority' do
+ context "when label is prioritized" do
+ it "returns label priority" do
create(:label_priority, project: project, label: label, priority: 1)
expect(label.priority(project)).to eq 1
@@ -140,23 +140,23 @@ describe Label do
end
end
- describe '.search' do
- let(:label) { create(:label, title: 'bug', description: 'incorrect behavior') }
+ describe ".search" do
+ let(:label) { create(:label, title: "bug", description: "incorrect behavior") }
- it 'returns labels with a partially matching title' do
+ it "returns labels with a partially matching title" do
expect(described_class.search(label.title[0..2])).to eq([label])
end
- it 'returns labels with a partially matching description' do
+ it "returns labels with a partially matching description" do
expect(described_class.search(label.description[0..5])).to eq([label])
end
- it 'returns nothing' do
- expect(described_class.search('feature')).to be_empty
+ it "returns nothing" do
+ expect(described_class.search("feature")).to be_empty
end
end
- describe '.subscribed_by' do
+ describe ".subscribed_by" do
let!(:user) { create(:user) }
let!(:label) { create(:label) }
let!(:label2) { create(:label) }
@@ -165,16 +165,16 @@ describe Label do
label.subscribe(user)
end
- it 'returns subscribed labels' do
+ it "returns subscribed labels" do
expect(described_class.subscribed_by(user.id)).to eq([label])
end
- it 'returns nothing' do
+ it "returns nothing" do
expect(described_class.subscribed_by(0)).to be_empty
end
end
- describe '.optionally_subscribed_by' do
+ describe ".optionally_subscribed_by" do
let!(:user) { create(:user) }
let!(:label) { create(:label) }
let!(:label2) { create(:label) }
@@ -183,11 +183,11 @@ describe Label do
label.subscribe(user)
end
- it 'returns subscribed labels' do
+ it "returns subscribed labels" do
expect(described_class.optionally_subscribed_by(user.id)).to eq([label])
end
- it 'returns all labels if user_id is nil' do
+ it "returns all labels if user_id is nil" do
expect(described_class.optionally_subscribed_by(nil)).to match_array([label, label2])
end
end
diff --git a/spec/models/legacy_diff_discussion_spec.rb b/spec/models/legacy_diff_discussion_spec.rb
index dae97b69c84..22aa31cccdd 100644
--- a/spec/models/legacy_diff_discussion_spec.rb
+++ b/spec/models/legacy_diff_discussion_spec.rb
@@ -1,31 +1,31 @@
-require 'spec_helper'
+require "spec_helper"
describe LegacyDiffDiscussion do
subject { create(:legacy_diff_note_on_merge_request).to_discussion }
- describe '#reply_attributes' do
- it 'includes line_code' do
+ describe "#reply_attributes" do
+ it "includes line_code" do
expect(subject.reply_attributes[:line_code]).to eq(subject.line_code)
end
end
- describe '#merge_request_version_params' do
- context 'when the discussion is active' do
+ describe "#merge_request_version_params" do
+ context "when the discussion is active" do
before do
allow(subject).to receive(:active?).and_return(true)
end
- it 'returns an empty hash, which will end up showing the latest version' do
+ it "returns an empty hash, which will end up showing the latest version" do
expect(subject.merge_request_version_params).to eq({})
end
end
- context 'when the discussion is outdated' do
+ context "when the discussion is outdated" do
before do
allow(subject).to receive(:active?).and_return(false)
end
- it 'returns nil' do
+ it "returns nil" do
expect(subject.merge_request_version_params).to be_nil
end
end
diff --git a/spec/models/lfs_download_object_spec.rb b/spec/models/lfs_download_object_spec.rb
index 88838b127d2..b84947e2022 100644
--- a/spec/models/lfs_download_object_spec.rb
+++ b/spec/models/lfs_download_object_spec.rb
@@ -1,63 +1,63 @@
-require 'rails_helper'
+require "rails_helper"
describe LfsDownloadObject do
- let(:oid) { 'cd293be6cea034bd45a0352775a219ef5dc7825ce55d1f7dae9762d80ce64411' }
- let(:link) { 'http://www.example.com' }
+ let(:oid) { "cd293be6cea034bd45a0352775a219ef5dc7825ce55d1f7dae9762d80ce64411" }
+ let(:link) { "http://www.example.com" }
let(:size) { 1 }
subject { described_class.new(oid: oid, size: size, link: link) }
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_numericality_of(:size).is_greater_than_or_equal_to(0) }
- context 'oid attribute' do
- it 'must be 64 characters long' do
+ context "oid attribute" do
+ it "must be 64 characters long" do
aggregate_failures do
- expect(described_class.new(oid: 'a' * 63, size: size, link: link)).to be_invalid
- expect(described_class.new(oid: 'a' * 65, size: size, link: link)).to be_invalid
- expect(described_class.new(oid: 'a' * 64, size: size, link: link)).to be_valid
+ expect(described_class.new(oid: "a" * 63, size: size, link: link)).to be_invalid
+ expect(described_class.new(oid: "a" * 65, size: size, link: link)).to be_invalid
+ expect(described_class.new(oid: "a" * 64, size: size, link: link)).to be_valid
end
end
- it 'must contain only hexadecimal characters' do
+ it "must contain only hexadecimal characters" do
aggregate_failures do
expect(subject).to be_valid
- expect(described_class.new(oid: 'g' * 64, size: size, link: link)).to be_invalid
+ expect(described_class.new(oid: "g" * 64, size: size, link: link)).to be_invalid
end
end
end
- context 'link attribute' do
- it 'only http and https protocols are valid' do
+ context "link attribute" do
+ it "only http and https protocols are valid" do
aggregate_failures do
- expect(described_class.new(oid: oid, size: size, link: 'http://www.example.com')).to be_valid
- expect(described_class.new(oid: oid, size: size, link: 'https://www.example.com')).to be_valid
- expect(described_class.new(oid: oid, size: size, link: 'ftp://www.example.com')).to be_invalid
- expect(described_class.new(oid: oid, size: size, link: 'ssh://www.example.com')).to be_invalid
- expect(described_class.new(oid: oid, size: size, link: 'git://www.example.com')).to be_invalid
+ expect(described_class.new(oid: oid, size: size, link: "http://www.example.com")).to be_valid
+ expect(described_class.new(oid: oid, size: size, link: "https://www.example.com")).to be_valid
+ expect(described_class.new(oid: oid, size: size, link: "ftp://www.example.com")).to be_invalid
+ expect(described_class.new(oid: oid, size: size, link: "ssh://www.example.com")).to be_invalid
+ expect(described_class.new(oid: oid, size: size, link: "git://www.example.com")).to be_invalid
end
end
- it 'cannot be empty' do
- expect(described_class.new(oid: oid, size: size, link: '')).not_to be_valid
+ it "cannot be empty" do
+ expect(described_class.new(oid: oid, size: size, link: "")).not_to be_valid
end
- context 'when localhost or local network addresses' do
- subject { described_class.new(oid: oid, size: size, link: 'http://192.168.1.1') }
+ context "when localhost or local network addresses" do
+ subject { described_class.new(oid: oid, size: size, link: "http://192.168.1.1") }
before do
allow(ApplicationSetting)
.to receive(:current)
- .and_return(ApplicationSetting.build_from_defaults(allow_local_requests_from_hooks_and_services: setting))
+ .and_return(ApplicationSetting.build_from_defaults(allow_local_requests_from_hooks_and_services: setting))
end
- context 'are allowed' do
+ context "are allowed" do
let(:setting) { true }
it { expect(subject).to be_valid }
end
- context 'are not allowed' do
+ context "are not allowed" do
let(:setting) { false }
it { expect(subject).to be_invalid }
diff --git a/spec/models/lfs_file_lock_spec.rb b/spec/models/lfs_file_lock_spec.rb
index 41ca1578b94..0fd4a71d6d7 100644
--- a/spec/models/lfs_file_lock_spec.rb
+++ b/spec/models/lfs_file_lock_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
describe LfsFileLock do
set(:lfs_file_lock) { create(:lfs_file_lock) }
@@ -11,7 +11,7 @@ describe LfsFileLock do
it { is_expected.to validate_presence_of(:user_id) }
it { is_expected.to validate_presence_of(:path) }
- describe '#can_be_unlocked_by?' do
+ describe "#can_be_unlocked_by?" do
let(:developer) { create(:user) }
let(:maintainer) { create(:user) }
@@ -23,13 +23,13 @@ describe LfsFileLock do
end
context "when it's forced" do
- it 'can be unlocked by the author' do
+ it "can be unlocked by the author" do
user = lfs_file_lock.user
expect(lfs_file_lock.can_be_unlocked_by?(user, true)).to eq(true)
end
- it 'can be unlocked by a maintainer' do
+ it "can be unlocked by a maintainer" do
expect(lfs_file_lock.can_be_unlocked_by?(maintainer, true)).to eq(true)
end
@@ -39,7 +39,7 @@ describe LfsFileLock do
end
context "when it isn't forced" do
- it 'can be unlocked by the author' do
+ it "can be unlocked by the author" do
user = lfs_file_lock.user
expect(lfs_file_lock.can_be_unlocked_by?(user)).to eq(true)
diff --git a/spec/models/lfs_object_spec.rb b/spec/models/lfs_object_spec.rb
index 3f929710862..40782a03bbf 100644
--- a/spec/models/lfs_object_spec.rb
+++ b/spec/models/lfs_object_spec.rb
@@ -1,59 +1,59 @@
-require 'spec_helper'
+require "spec_helper"
describe LfsObject do
- describe '#local_store?' do
- it 'returns true when file_store is equal to LfsObjectUploader::Store::LOCAL' do
+ describe "#local_store?" do
+ it "returns true when file_store is equal to LfsObjectUploader::Store::LOCAL" do
subject.file_store = LfsObjectUploader::Store::LOCAL
expect(subject.local_store?).to eq true
end
- it 'returns false when file_store is equal to LfsObjectUploader::Store::REMOTE' do
+ it "returns false when file_store is equal to LfsObjectUploader::Store::REMOTE" do
subject.file_store = LfsObjectUploader::Store::REMOTE
expect(subject.local_store?).to eq false
end
end
- describe '#schedule_background_upload' do
+ describe "#schedule_background_upload" do
before do
stub_lfs_setting(enabled: true)
end
subject { create(:lfs_object, :with_file) }
- context 'when object storage is disabled' do
+ context "when object storage is disabled" do
before do
stub_lfs_object_storage(enabled: false)
end
- it 'does not schedule the migration' do
+ it "does not schedule the migration" do
expect(ObjectStorage::BackgroundMoveWorker).not_to receive(:perform_async)
subject
end
end
- context 'when object storage is enabled' do
- context 'when background upload is enabled' do
- context 'when is licensed' do
+ context "when object storage is enabled" do
+ context "when background upload is enabled" do
+ context "when is licensed" do
before do
stub_lfs_object_storage(background_upload: true)
end
- it 'schedules the model for migration' do
+ it "schedules the model for migration" do
expect(ObjectStorage::BackgroundMoveWorker)
.to receive(:perform_async)
- .with('LfsObjectUploader', described_class.name, :file, kind_of(Numeric))
+ .with("LfsObjectUploader", described_class.name, :file, kind_of(Numeric))
.once
subject
end
- it 'schedules the model for migration once' do
+ it "schedules the model for migration once" do
expect(ObjectStorage::BackgroundMoveWorker)
.to receive(:perform_async)
- .with('LfsObjectUploader', described_class.name, :file, kind_of(Numeric))
+ .with("LfsObjectUploader", described_class.name, :file, kind_of(Numeric))
.once
create(:lfs_object, :with_file)
@@ -61,12 +61,12 @@ describe LfsObject do
end
end
- context 'when background upload is disabled' do
+ context "when background upload is disabled" do
before do
stub_lfs_object_storage(background_upload: false)
end
- it 'schedules the model for migration' do
+ it "schedules the model for migration" do
expect(ObjectStorage::BackgroundMoveWorker).not_to receive(:perform_async)
subject
@@ -74,24 +74,24 @@ describe LfsObject do
end
end
- describe 'file is being stored' do
+ describe "file is being stored" do
let(:lfs_object) { create(:lfs_object, :with_file) }
- context 'when existing object has local store' do
- it 'is stored locally' do
+ context "when existing object has local store" do
+ it "is stored locally" do
expect(lfs_object.file_store).to be(ObjectStorage::Store::LOCAL)
expect(lfs_object.file).to be_file_storage
expect(lfs_object.file.object_store).to eq(ObjectStorage::Store::LOCAL)
end
end
- context 'when direct upload is enabled' do
+ context "when direct upload is enabled" do
before do
stub_lfs_object_storage(direct_upload: true)
end
- context 'when file is stored' do
- it 'is stored remotely' do
+ context "when file is stored" do
+ it "is stored remotely" do
expect(lfs_object.file_store).to eq(ObjectStorage::Store::REMOTE)
expect(lfs_object.file).not_to be_file_storage
expect(lfs_object.file.object_store).to eq(ObjectStorage::Store::REMOTE)
diff --git a/spec/models/lfs_objects_project_spec.rb b/spec/models/lfs_objects_project_spec.rb
index 0a3180f43e8..5c60a6c6351 100644
--- a/spec/models/lfs_objects_project_spec.rb
+++ b/spec/models/lfs_objects_project_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe LfsObjectsProject do
set(:project) { create(:project) }
@@ -7,31 +7,31 @@ describe LfsObjectsProject do
create(:lfs_objects_project, project: project)
end
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:lfs_object) }
end
- describe 'validation' do
+ describe "validation" do
it { is_expected.to validate_presence_of(:lfs_object_id) }
it { is_expected.to validate_presence_of(:project_id) }
- it 'validates object id' do
+ it "validates object id" do
is_expected.to validate_uniqueness_of(:lfs_object_id)
.scoped_to(:project_id)
.with_message("already exists in project")
end
end
- describe '#update_project_statistics' do
- it 'updates project statistics when the object is added' do
+ describe "#update_project_statistics" do
+ it "updates project statistics when the object is added" do
expect(ProjectCacheWorker).to receive(:perform_async)
.with(project.id, [], [:lfs_objects_size])
subject.save!
end
- it 'updates project statistics when the object is removed' do
+ it "updates project statistics when the object is removed" do
subject.save!
expect(ProjectCacheWorker).to receive(:perform_async)
diff --git a/spec/models/license_template_spec.rb b/spec/models/license_template_spec.rb
index dd912eefac1..686dcfe59e4 100644
--- a/spec/models/license_template_spec.rb
+++ b/spec/models/license_template_spec.rb
@@ -1,49 +1,45 @@
-require 'spec_helper'
+require "spec_helper"
describe LicenseTemplate do
- describe '#content' do
- it 'calls a proc exactly once if provided' do
- lazy = build_template(-> { 'bar' })
+ describe "#content" do
+ it "calls a proc exactly once if provided" do
+ lazy = build_template(-> { "bar" })
content = lazy.content
- expect(content).to eq('bar')
+ expect(content).to eq("bar")
expect(content.object_id).to eq(lazy.content.object_id)
- content.replace('foo')
- expect(lazy.content).to eq('foo')
+ content.replace("foo")
+ expect(lazy.content).to eq("foo")
end
- it 'returns a string if provided' do
- lazy = build_template('bar')
+ it "returns a string if provided" do
+ lazy = build_template("bar")
- expect(lazy.content).to eq('bar')
+ expect(lazy.content).to eq("bar")
end
end
- describe '#resolve!' do
+ describe "#resolve!" do
let(:content) do
<<~TEXT
- Pretend License
-
- [project]
-
- Copyright (c) [year] [fullname]
+ Pretend License
+ [project]
+ Copyright (c) [year] [fullname]
TEXT
end
let(:expected) do
<<~TEXT
- Pretend License
-
- Foo Project
-
- Copyright (c) 1985 Nick Thomas
+ Pretend License
+ Foo Project
+ Copyright (c) 1985 Nick Thomas
TEXT
end
let(:template) { build_template(content) }
- it 'updates placeholders in a copy of the template content' do
+ it "updates placeholders in a copy of the template content" do
expect(template.content.object_id).to eq(content.object_id)
template.resolve!(project_name: "Foo Project", fullname: "Nick Thomas", year: "1985")
@@ -54,6 +50,6 @@ describe LicenseTemplate do
end
def build_template(content)
- described_class.new(key: 'foo', name: 'foo', category: :Other, content: content)
+ described_class.new(key: "foo", name: "foo", category: :Other, content: content)
end
end
diff --git a/spec/models/list_spec.rb b/spec/models/list_spec.rb
index a51580f8292..13433d59dc2 100644
--- a/spec/models/list_spec.rb
+++ b/spec/models/list_spec.rb
@@ -1,21 +1,21 @@
-require 'rails_helper'
+require "rails_helper"
describe List do
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:board) }
it { is_expected.to belong_to(:label) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:board) }
it { is_expected.to validate_presence_of(:label) }
it { is_expected.to validate_presence_of(:list_type) }
it { is_expected.to validate_presence_of(:position) }
it { is_expected.to validate_numericality_of(:position).only_integer.is_greater_than_or_equal_to(0) }
- context 'when list_type is set to closed' do
+ context "when list_type is set to closed" do
subject { described_class.new(list_type: :closed) }
it { is_expected.not_to validate_presence_of(:label) }
@@ -23,60 +23,60 @@ describe List do
end
end
- describe '#destroy' do
- it 'can be destroyed when list_type is set to label' do
+ describe "#destroy" do
+ it "can be destroyed when list_type is set to label" do
subject = create(:list)
expect(subject.destroy).to be_truthy
end
- it 'can not be destroyed when list_type is set to closed' do
+ it "can not be destroyed when list_type is set to closed" do
subject = create(:closed_list)
expect(subject.destroy).to be_falsey
end
end
- describe '#destroyable?' do
- it 'returns true when list_type is set to label' do
+ describe "#destroyable?" do
+ it "returns true when list_type is set to label" do
subject.list_type = :label
expect(subject).to be_destroyable
end
- it 'returns false when list_type is set to closed' do
+ it "returns false when list_type is set to closed" do
subject.list_type = :closed
expect(subject).not_to be_destroyable
end
end
- describe '#movable?' do
- it 'returns true when list_type is set to label' do
+ describe "#movable?" do
+ it "returns true when list_type is set to label" do
subject.list_type = :label
expect(subject).to be_movable
end
- it 'returns false when list_type is set to closed' do
+ it "returns false when list_type is set to closed" do
subject.list_type = :closed
expect(subject).not_to be_movable
end
end
- describe '#title' do
- it 'returns label name when list_type is set to label' do
+ describe "#title" do
+ it "returns label name when list_type is set to label" do
subject.list_type = :label
- subject.label = Label.new(name: 'Development')
+ subject.label = Label.new(name: "Development")
- expect(subject.title).to eq 'Development'
+ expect(subject.title).to eq "Development"
end
- it 'returns Closed when list_type is set to closed' do
+ it "returns Closed when list_type is set to closed" do
subject.list_type = :closed
- expect(subject.title).to eq 'Closed'
+ expect(subject.title).to eq "Closed"
end
end
end
diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb
index 188beac1582..67b778d5eaa 100644
--- a/spec/models/member_spec.rb
+++ b/spec/models/member_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Member do
describe "Associations" do
@@ -12,7 +12,7 @@ describe Member do
it { is_expected.to validate_presence_of(:source) }
it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.all_values) }
- it_behaves_like 'an object with email-formated attributes', :invite_email do
+ it_behaves_like "an object with email-formated attributes", :invite_email do
subject { build(:project_member) }
end
@@ -78,7 +78,7 @@ describe Member do
end
end
- describe 'Scopes & finders' do
+ describe "Scopes & finders" do
before do
project = create(:project, :public, :access_requestable)
group = create(:group)
@@ -98,16 +98,16 @@ describe Member do
@blocked_developer = project.members.find_by(user_id: @blocked_user.id, access_level: Gitlab::Access::DEVELOPER)
@invited_member = create(:project_member, :developer,
- project: project,
- invite_token: '1234',
- invite_email: 'toto1@example.com')
+ project: project,
+ invite_token: "1234",
+ invite_email: "toto1@example.com")
accepted_invite_user = build(:user, state: :active)
@accepted_invite_member = create(:project_member, :developer,
- project: project,
- invite_token: '1234',
- invite_email: 'toto2@example.com')
- .tap { |u| u.accept_invite!(accepted_invite_user) }
+ project: project,
+ invite_token: "1234",
+ invite_email: "toto2@example.com")
+ .tap { |u| u.accept_invite!(accepted_invite_user) }
requested_user = create(:user).tap { |u| project.request_access(u) }
@requested_member = project.requesters.find_by(user_id: requested_user.id)
@@ -116,19 +116,19 @@ describe Member do
@accepted_request_member = project.requesters.find_by(user_id: accepted_request_user.id).tap { |m| m.accept_request }
end
- describe '.access_for_user_ids' do
- it 'returns the right access levels' do
+ describe ".access_for_user_ids" do
+ it "returns the right access levels" do
users = [@owner_user.id, @maintainer_user.id, @blocked_user.id]
expected = {
@owner_user.id => Gitlab::Access::OWNER,
- @maintainer_user.id => Gitlab::Access::MAINTAINER
+ @maintainer_user.id => Gitlab::Access::MAINTAINER,
}
expect(described_class.access_for_user_ids(users)).to eq(expected)
end
end
- describe '.invite' do
+ describe ".invite" do
it { expect(described_class.invite).not_to include @maintainer }
it { expect(described_class.invite).to include @invited_member }
it { expect(described_class.invite).not_to include @accepted_invite_member }
@@ -136,7 +136,7 @@ describe Member do
it { expect(described_class.invite).not_to include @accepted_request_member }
end
- describe '.non_invite' do
+ describe ".non_invite" do
it { expect(described_class.non_invite).to include @maintainer }
it { expect(described_class.non_invite).not_to include @invited_member }
it { expect(described_class.non_invite).to include @accepted_invite_member }
@@ -144,7 +144,7 @@ describe Member do
it { expect(described_class.non_invite).to include @accepted_request_member }
end
- describe '.request' do
+ describe ".request" do
it { expect(described_class.request).not_to include @maintainer }
it { expect(described_class.request).not_to include @invited_member }
it { expect(described_class.request).not_to include @accepted_invite_member }
@@ -152,7 +152,7 @@ describe Member do
it { expect(described_class.request).not_to include @accepted_request_member }
end
- describe '.non_request' do
+ describe ".non_request" do
it { expect(described_class.non_request).to include @maintainer }
it { expect(described_class.non_request).to include @invited_member }
it { expect(described_class.non_request).to include @accepted_invite_member }
@@ -160,7 +160,7 @@ describe Member do
it { expect(described_class.non_request).to include @accepted_request_member }
end
- describe '.developers' do
+ describe ".developers" do
subject { described_class.developers.to_a }
it { is_expected.not_to include @owner }
@@ -173,7 +173,7 @@ describe Member do
it { is_expected.not_to include @blocked_developer }
end
- describe '.owners_and_maintainers' do
+ describe ".owners_and_maintainers" do
it { expect(described_class.owners_and_maintainers).to include @owner }
it { expect(described_class.owners_and_maintainers).to include @maintainer }
it { expect(described_class.owners_and_maintainers).not_to include @invited_member }
@@ -183,7 +183,7 @@ describe Member do
it { expect(described_class.owners_and_maintainers).not_to include @blocked_maintainer }
end
- describe '.has_access' do
+ describe ".has_access" do
subject { described_class.has_access.to_a }
it { is_expected.to include @owner }
@@ -202,27 +202,27 @@ describe Member do
it { is_expected.to respond_to(:user_email) }
end
- describe '.add_user' do
+ describe ".add_user" do
%w[project group].each do |source_type|
context "when source is a #{source_type}" do
let!(:source) { create(source_type, :public, :access_requestable) }
let!(:user) { create(:user) }
let!(:admin) { create(:admin) }
- it 'returns a <Source>Member object' do
+ it "returns a <Source>Member object" do
member = described_class.add_user(source, user, :maintainer)
expect(member).to be_a "#{source_type.classify}Member".constantize
expect(member).to be_persisted
end
- it 'sets members.created_by to the given current_user' do
+ it "sets members.created_by to the given current_user" do
member = described_class.add_user(source, user, :maintainer, current_user: admin)
expect(member.created_by).to eq(admin)
end
- it 'sets members.expires_at to the given expires_at' do
+ it "sets members.expires_at to the given expires_at" do
member = described_class.add_user(source, user, :maintainer, expires_at: Date.new(2016, 9, 22))
expect(member.expires_at).to eq(Date.new(2016, 9, 22))
@@ -248,9 +248,9 @@ describe Member do
end
end
- context 'with no current_user' do
- context 'when called with a known user id' do
- it 'adds the user as a member' do
+ context "with no current_user" do
+ context "when called with a known user id" do
+ it "adds the user as a member" do
expect(source.users).not_to include(user)
described_class.add_user(source, user.id, :maintainer)
@@ -259,8 +259,8 @@ describe Member do
end
end
- context 'when called with an unknown user id' do
- it 'adds the user as a member' do
+ context "when called with an unknown user id" do
+ it "adds the user as a member" do
expect(source.users).not_to include(user)
described_class.add_user(source, 42, :maintainer)
@@ -269,8 +269,8 @@ describe Member do
end
end
- context 'when called with a user object' do
- it 'adds the user as a member' do
+ context "when called with a user object" do
+ it "adds the user as a member" do
expect(source.users).not_to include(user)
described_class.add_user(source, user, :maintainer)
@@ -279,12 +279,12 @@ describe Member do
end
end
- context 'when called with a requester user object' do
+ context "when called with a requester user object" do
before do
source.request_access(user)
end
- it 'adds the requester as a member' do
+ it "adds the requester as a member" do
expect(source.users).not_to include(user)
expect(source.requesters.exists?(user_id: user)).to be_truthy
@@ -296,8 +296,8 @@ describe Member do
end
end
- context 'when called with a known user email' do
- it 'adds the user as a member' do
+ context "when called with a known user email" do
+ it "adds the user as a member" do
expect(source.users).not_to include(user)
described_class.add_user(source, user.email, :maintainer)
@@ -306,19 +306,19 @@ describe Member do
end
end
- context 'when called with an unknown user email' do
- it 'creates an invited member' do
+ context "when called with an unknown user email" do
+ it "creates an invited member" do
expect(source.users).not_to include(user)
- described_class.add_user(source, 'user@example.com', :maintainer)
+ described_class.add_user(source, "user@example.com", :maintainer)
- expect(source.members.invite.pluck(:invite_email)).to include('user@example.com')
+ expect(source.members.invite.pluck(:invite_email)).to include("user@example.com")
end
end
end
- context 'when current_user can update member' do
- it 'creates the member' do
+ context "when current_user can update member" do
+ it "creates the member" do
expect(source.users).not_to include(user)
described_class.add_user(source, user, :maintainer, current_user: admin)
@@ -326,12 +326,12 @@ describe Member do
expect(source.users.reload).to include(user)
end
- context 'when called with a requester user object' do
+ context "when called with a requester user object" do
before do
source.request_access(user)
end
- it 'adds the requester as a member' do
+ it "adds the requester as a member" do
expect(source.users).not_to include(user)
expect(source.requesters.exists?(user_id: user)).to be_truthy
@@ -343,8 +343,8 @@ describe Member do
end
end
- context 'when current_user cannot update member' do
- it 'does not create the member' do
+ context "when current_user cannot update member" do
+ it "does not create the member" do
expect(source.users).not_to include(user)
member = described_class.add_user(source, user, :maintainer, current_user: user)
@@ -353,12 +353,12 @@ describe Member do
expect(member).not_to be_persisted
end
- context 'when called with a requester user object' do
+ context "when called with a requester user object" do
before do
source.request_access(user)
end
- it 'does not destroy the requester' do
+ it "does not destroy the requester" do
expect(source.users).not_to include(user)
expect(source.requesters.exists?(user_id: user)).to be_truthy
@@ -370,13 +370,13 @@ describe Member do
end
end
- context 'when member already exists' do
+ context "when member already exists" do
before do
source.add_user(user, :developer)
end
- context 'with no current_user' do
- it 'updates the member' do
+ context "with no current_user" do
+ it "updates the member" do
expect(source.users).to include(user)
described_class.add_user(source, user, :maintainer)
@@ -385,8 +385,8 @@ describe Member do
end
end
- context 'when current_user can update member' do
- it 'updates the member' do
+ context "when current_user can update member" do
+ it "updates the member" do
expect(source.users).to include(user)
described_class.add_user(source, user, :maintainer, current_user: admin)
@@ -395,8 +395,8 @@ describe Member do
end
end
- context 'when current_user cannot update member' do
- it 'does not update the member' do
+ context "when current_user cannot update member" do
+ it "does not update the member" do
expect(source.users).to include(user)
described_class.add_user(source, user, :maintainer, current_user: user)
@@ -409,7 +409,7 @@ describe Member do
end
end
- describe '.add_users' do
+ describe ".add_users" do
%w[project group].each do |source_type|
context "when source is a #{source_type}" do
let!(:source) { create(source_type, :public, :access_requestable) }
@@ -417,7 +417,7 @@ describe Member do
let(:user1) { create(:user) }
let(:user2) { create(:user) }
- it 'returns a <Source>Member objects' do
+ it "returns a <Source>Member objects" do
members = described_class.add_users(source, [user1, user2], :maintainer)
expect(members).to be_a Array
@@ -426,15 +426,15 @@ describe Member do
expect(members.first).to be_persisted
end
- it 'returns an empty array' do
+ it "returns an empty array" do
members = described_class.add_users(source, [], :maintainer)
expect(members).to be_a Array
expect(members).to be_empty
end
- it 'supports differents formats' do
- list = ['joe@local.test', admin, user1.id, user2.id.to_s]
+ it "supports differents formats" do
+ list = ["joe@local.test", admin, user1.id, user2.id.to_s]
members = described_class.add_users(source, list, :maintainer)
@@ -445,37 +445,37 @@ describe Member do
end
end
- describe '#accept_request' do
+ describe "#accept_request" do
let(:member) { create(:project_member, requested_at: Time.now.utc) }
it { expect(member.accept_request).to be_truthy }
- it 'clears requested_at' do
+ it "clears requested_at" do
member.accept_request
expect(member.requested_at).to be_nil
end
- it 'calls #after_accept_request' do
+ it "calls #after_accept_request" do
expect(member).to receive(:after_accept_request)
member.accept_request
end
end
- describe '#invite?' do
+ describe "#invite?" do
subject { create(:project_member, invite_email: "user@example.com", user: nil) }
it { is_expected.to be_invite }
end
- describe '#request?' do
+ describe "#request?" do
subject { create(:project_member, requested_at: Time.now.utc) }
it { is_expected.to be_request }
end
- describe '#pending?' do
+ describe "#pending?" do
let(:invited_member) { create(:project_member, invite_email: "user@example.com", user: nil) }
let(:requester) { create(:project_member, requested_at: Time.now.utc) }
diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb
index a3451c67bd8..1fbe0780960 100644
--- a/spec/models/members/group_member_spec.rb
+++ b/spec/models/members/group_member_spec.rb
@@ -1,20 +1,20 @@
-require 'spec_helper'
+require "spec_helper"
describe GroupMember do
- describe '.access_level_roles' do
- it 'returns Gitlab::Access.options_with_owner' do
+ describe ".access_level_roles" do
+ it "returns Gitlab::Access.options_with_owner" do
expect(described_class.access_level_roles).to eq(Gitlab::Access.options_with_owner)
end
end
- describe '.access_levels' do
- it 'returns Gitlab::Access.options_with_owner' do
+ describe ".access_levels" do
+ it "returns Gitlab::Access.options_with_owner" do
expect(described_class.access_levels).to eq(Gitlab::Access.sym_options_with_owner)
end
end
- describe '.add_users' do
- it 'adds the given users to the given group' do
+ describe ".add_users" do
+ it "adds the given users to the given group" do
group = create(:group)
users = create_list(:user, 2)
@@ -28,19 +28,19 @@ describe GroupMember do
end
end
- it_behaves_like 'members notifications', :group
+ it_behaves_like "members notifications", :group
- describe '#real_source_type' do
+ describe "#real_source_type" do
subject { create(:group_member).real_source_type }
- it { is_expected.to eq 'Group' }
+ it { is_expected.to eq "Group" }
end
- describe '#update_two_factor_requirement' do
+ describe "#update_two_factor_requirement" do
let(:user) { build :user }
let(:group_member) { build :group_member, user: user }
- it 'is called after creation and deletion' do
+ it "is called after creation and deletion" do
expect(user).to receive(:update_two_factor_requirement)
group_member.save
@@ -51,21 +51,21 @@ describe GroupMember do
end
end
- context 'access levels', :nested_groups do
- context 'with parent group' do
- it_behaves_like 'inherited access level as a member of entity' do
+ context "access levels", :nested_groups do
+ context "with parent group" do
+ it_behaves_like "inherited access level as a member of entity" do
let(:entity) { create(:group, parent: parent_entity) }
end
end
- context 'with parent group and a sub subgroup' do
- it_behaves_like 'inherited access level as a member of entity' do
+ context "with parent group and a sub subgroup" do
+ it_behaves_like "inherited access level as a member of entity" do
let(:subgroup) { create(:group, parent: parent_entity) }
let(:entity) { create(:group, parent: subgroup) }
end
- context 'when only the subgroup has the member' do
- it_behaves_like 'inherited access level as a member of entity' do
+ context "when only the subgroup has the member" do
+ it_behaves_like "inherited access level as a member of entity" do
let(:parent_entity) { create(:group, parent: create(:group)) }
let(:entity) { create(:group, parent: parent_entity) }
end
diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb
index 36bfff2c339..024185d05e1 100644
--- a/spec/models/members/project_member_spec.rb
+++ b/spec/models/members/project_member_spec.rb
@@ -1,24 +1,24 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectMember do
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project).with_foreign_key(:source_id) }
end
- describe 'validations' do
- it { is_expected.to allow_value('Project').for(:source_type) }
- it { is_expected.not_to allow_value('project').for(:source_type) }
+ describe "validations" do
+ it { is_expected.to allow_value("Project").for(:source_type) }
+ it { is_expected.not_to allow_value("project").for(:source_type) }
it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) }
end
- describe '.access_level_roles' do
- it 'returns Gitlab::Access.options' do
+ describe ".access_level_roles" do
+ it "returns Gitlab::Access.options" do
expect(described_class.access_level_roles).to eq(Gitlab::Access.options)
end
end
- describe '.add_user' do
- it 'adds the user as a member' do
+ describe ".add_user" do
+ it "adds the user as a member" do
user = create(:user)
project = create(:project)
@@ -30,10 +30,10 @@ describe ProjectMember do
end
end
- describe '#real_source_type' do
+ describe "#real_source_type" do
subject { create(:project_member).real_source_type }
- it { is_expected.to eq 'Project' }
+ it { is_expected.to eq "Project" }
end
describe "#destroy" do
@@ -53,7 +53,7 @@ describe ProjectMember do
end
end
- describe '.import_team' do
+ describe ".import_team" do
before do
@project_1 = create(:project)
@project_2 = create(:project)
@@ -69,7 +69,7 @@ describe ProjectMember do
it { expect(@status).to be_truthy }
- describe 'project 2 should get user 1 as developer. user_2 should not be changed' do
+ describe "project 2 should get user 1 as developer. user_2 should not be changed" do
it { expect(@project_2.users).to include(@user_1) }
it { expect(@project_2.users).to include(@user_2) }
@@ -77,21 +77,22 @@ describe ProjectMember do
it { expect(Ability.allowed?(@user_2, :read_project, @project_2)).to be_truthy }
end
- describe 'project 1 should not be changed' do
+ describe "project 1 should not be changed" do
it { expect(@project_1.users).to include(@user_1) }
it { expect(@project_1.users).not_to include(@user_2) }
end
end
- describe '.add_users_to_projects' do
- it 'adds the given users to the given projects' do
+ describe ".add_users_to_projects" do
+ it "adds the given users to the given projects" do
projects = create_list(:project, 2)
users = create_list(:user, 2)
described_class.add_users_to_projects(
[projects.first.id, projects.second.id],
[users.first.id, users.second],
- described_class::MAINTAINER)
+ described_class::MAINTAINER
+ )
expect(projects.first.users).to include(users.first)
expect(projects.first.users).to include(users.second)
@@ -101,7 +102,7 @@ describe ProjectMember do
end
end
- describe '.truncate_teams' do
+ describe ".truncate_teams" do
before do
@project_1 = create(:project)
@project_2 = create(:project)
@@ -119,17 +120,17 @@ describe ProjectMember do
it { expect(@project_2.users).to be_empty }
end
- it_behaves_like 'members notifications', :project
+ it_behaves_like "members notifications", :project
- context 'access levels' do
- context 'with parent group' do
- it_behaves_like 'inherited access level as a member of entity' do
+ context "access levels" do
+ context "with parent group" do
+ it_behaves_like "inherited access level as a member of entity" do
let(:entity) { create(:project, group: parent_entity) }
end
end
- context 'with parent group and a subgroup', :nested_groups do
- it_behaves_like 'inherited access level as a member of entity' do
+ context "with parent group and a subgroup", :nested_groups do
+ it_behaves_like "inherited access level as a member of entity" do
let(:subgroup) { create(:group, parent: parent_entity) }
let(:entity) { create(:project, group: subgroup) }
end
diff --git a/spec/models/merge_request/metrics_spec.rb b/spec/models/merge_request/metrics_spec.rb
index 02ff7839739..ed34adbf907 100644
--- a/spec/models/merge_request/metrics_spec.rb
+++ b/spec/models/merge_request/metrics_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe MergeRequest::Metrics do
subject { described_class.new }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:merge_request) }
- it { is_expected.to belong_to(:latest_closed_by).class_name('User') }
- it { is_expected.to belong_to(:merged_by).class_name('User') }
+ it { is_expected.to belong_to(:latest_closed_by).class_name("User") }
+ it { is_expected.to belong_to(:merged_by).class_name("User") }
end
end
diff --git a/spec/models/merge_request_diff_commit_spec.rb b/spec/models/merge_request_diff_commit_spec.rb
index 10487190a44..b88fe89af34 100644
--- a/spec/models/merge_request_diff_commit_spec.rb
+++ b/spec/models/merge_request_diff_commit_spec.rb
@@ -1,13 +1,13 @@
-require 'rails_helper'
+require "rails_helper"
describe MergeRequestDiffCommit do
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.project }
- describe '#to_hash' do
+ describe "#to_hash" do
subject { merge_request.commits.first }
- it 'returns the same results as Commit#to_hash, except for parent_ids' do
+ it "returns the same results as Commit#to_hash, except for parent_ids" do
commit_from_repo = project.repository.commit(subject.sha)
commit_from_repo_hash = commit_from_repo.to_hash.merge(parent_ids: [])
@@ -15,13 +15,13 @@ describe MergeRequestDiffCommit do
end
end
- describe '.create_bulk' do
+ describe ".create_bulk" do
let(:sha_attribute) { Gitlab::Database::ShaAttribute.new }
let(:merge_request_diff_id) { merge_request.merge_request_diff.id }
let(:commits) do
[
- project.commit('5937ac0a7beb003549fc5fd26fc247adbce4a52e'),
- project.commit('570e7b2abdd848b95f2f578043fc23bd6f6fd24d')
+ project.commit("5937ac0a7beb003549fc5fd26fc247adbce4a52e"),
+ project.commit("570e7b2abdd848b95f2f578043fc23bd6f6fd24d"),
]
end
let(:rows) do
@@ -36,7 +36,7 @@ describe MergeRequestDiffCommit do
"committer_email": "dmitriy.zaporozhets@gmail.com",
"merge_request_diff_id": merge_request_diff_id,
"relative_order": 0,
- "sha": sha_attribute.serialize("5937ac0a7beb003549fc5fd26fc247adbce4a52e")
+ "sha": sha_attribute.serialize("5937ac0a7beb003549fc5fd26fc247adbce4a52e"),
},
{
"message": "Change some files\n\nSigned-off-by: Dmitriy Zaporozhets \u003cdmitriy.zaporozhets@gmail.com\u003e\n",
@@ -48,24 +48,24 @@ describe MergeRequestDiffCommit do
"committer_email": "dmitriy.zaporozhets@gmail.com",
"merge_request_diff_id": merge_request_diff_id,
"relative_order": 1,
- "sha": sha_attribute.serialize("570e7b2abdd848b95f2f578043fc23bd6f6fd24d")
- }
+ "sha": sha_attribute.serialize("570e7b2abdd848b95f2f578043fc23bd6f6fd24d"),
+ },
]
end
subject { described_class.create_bulk(merge_request_diff_id, commits) }
- it 'inserts the commits into the database en masse' do
+ it "inserts the commits into the database en masse" do
expect(Gitlab::Database).to receive(:bulk_insert)
.with(described_class.table_name, rows)
subject
end
- context 'with dates larger than the DB limit' do
+ context "with dates larger than the DB limit" do
let(:commits) do
# This commit's date is "Sun Aug 17 07:12:55 292278994 +0000"
- [project.commit('ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69')]
+ [project.commit("ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69")]
end
let(:timestamp) { Time.at((1 << 31) - 1) }
let(:rows) do
@@ -79,11 +79,11 @@ describe MergeRequestDiffCommit do
"committer_email": "alejorro70@gmail.com",
"merge_request_diff_id": merge_request_diff_id,
"relative_order": 0,
- "sha": sha_attribute.serialize("ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69")
+ "sha": sha_attribute.serialize("ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69"),
}]
end
- it 'uses a sanitized date' do
+ it "uses a sanitized date" do
expect(Gitlab::Database).to receive(:bulk_insert)
.with(described_class.table_name, rows)
diff --git a/spec/models/merge_request_diff_file_spec.rb b/spec/models/merge_request_diff_file_spec.rb
index faa47660a74..9fc1c10af09 100644
--- a/spec/models/merge_request_diff_file_spec.rb
+++ b/spec/models/merge_request_diff_file_spec.rb
@@ -1,33 +1,33 @@
-require 'rails_helper'
+require "rails_helper"
describe MergeRequestDiffFile do
- describe '#diff' do
- let(:unpacked) { 'unpacked' }
- let(:packed) { [unpacked].pack('m0') }
+ describe "#diff" do
+ let(:unpacked) { "unpacked" }
+ let(:packed) { [unpacked].pack("m0") }
before do
subject.diff = packed
end
- context 'when the diff is marked as binary' do
+ context "when the diff is marked as binary" do
before do
subject.binary = true
end
- it 'unpacks from base 64' do
+ it "unpacks from base 64" do
expect(subject.diff).to eq(unpacked)
end
end
- context 'when the diff is not marked as binary' do
- it 'returns the raw diff' do
+ context "when the diff is not marked as binary" do
+ it "returns the raw diff" do
expect(subject.diff).to eq(packed)
end
end
end
- describe '#utf8_diff' do
- it 'does not raise error when the diff is binary' do
+ describe "#utf8_diff" do
+ it "does not raise error when the diff is binary" do
subject.diff = "\x05\x00\x68\x65\x6c\x6c\x6f"
expect { subject.utf8_diff }.not_to raise_error
diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb
index 1849d3bac12..2eba16db01e 100644
--- a/spec/models/merge_request_diff_spec.rb
+++ b/spec/models/merge_request_diff_spec.rb
@@ -1,43 +1,43 @@
-require 'spec_helper'
+require "spec_helper"
describe MergeRequestDiff do
let(:diff_with_commits) { create(:merge_request).merge_request_diff }
- describe 'create new record' do
+ describe "create new record" do
subject { diff_with_commits }
it { expect(subject).to be_valid }
it { expect(subject).to be_persisted }
it { expect(subject.commits.count).to eq(29) }
it { expect(subject.diffs.count).to eq(20) }
- it { expect(subject.head_commit_sha).to eq('b83d6e391c22777fca1ed3012fce84f633d7fed0') }
- it { expect(subject.base_commit_sha).to eq('ae73cb07c9eeaf35924a10f713b364d32b2dd34f') }
- it { expect(subject.start_commit_sha).to eq('0b4bc9a49b562e85de7cc9e834518ea6828729b9') }
+ it { expect(subject.head_commit_sha).to eq("b83d6e391c22777fca1ed3012fce84f633d7fed0") }
+ it { expect(subject.base_commit_sha).to eq("ae73cb07c9eeaf35924a10f713b364d32b2dd34f") }
+ it { expect(subject.start_commit_sha).to eq("0b4bc9a49b562e85de7cc9e834518ea6828729b9") }
end
- describe '.by_commit_sha' do
+ describe ".by_commit_sha" do
subject(:by_commit_sha) { described_class.by_commit_sha(sha) }
let!(:merge_request) { create(:merge_request, :with_diffs) }
- context 'with sha contained in' do
- let(:sha) { 'b83d6e391c22777fca1ed3012fce84f633d7fed0' }
+ context "with sha contained in" do
+ let(:sha) { "b83d6e391c22777fca1ed3012fce84f633d7fed0" }
- it 'returns merge request diffs' do
+ it "returns merge request diffs" do
expect(by_commit_sha).to eq([merge_request.merge_request_diff])
end
end
- context 'with sha not contained in' do
- let(:sha) { 'b83d6e3' }
+ context "with sha not contained in" do
+ let(:sha) { "b83d6e3" }
- it 'returns empty result' do
+ it "returns empty result" do
expect(by_commit_sha).to be_empty
end
end
end
- describe '#latest' do
+ describe "#latest" do
let!(:mr) { create(:merge_request, :with_diffs) }
let!(:first_diff) { mr.merge_request_diff }
let!(:last_diff) { mr.create_merge_request_diff }
@@ -46,44 +46,44 @@ describe MergeRequestDiff do
it { expect(first_diff.reload).not_to be_latest }
end
- shared_examples_for 'merge request diffs' do
+ shared_examples_for "merge request diffs" do
let(:merge_request) { create(:merge_request, :with_diffs) }
let!(:diff) { merge_request.merge_request_diff.reload }
- context 'when it was not cleaned by the system' do
- it 'returns persisted diffs' do
+ context "when it was not cleaned by the system" do
+ it "returns persisted diffs" do
expect(diff).to receive(:load_diffs).and_call_original
diff.diffs.diff_files
end
end
- context 'when diff was cleaned by the system' do
+ context "when diff was cleaned by the system" do
before do
diff.clean!
end
- it 'returns diffs from repository if can compare with current diff refs' do
+ it "returns diffs from repository if can compare with current diff refs" do
expect(diff).not_to receive(:load_diffs)
expect(Compare)
.to receive(:new)
.with(instance_of(Gitlab::Git::Compare), merge_request.target_project,
- base_sha: diff.base_commit_sha, straight: false)
+ base_sha: diff.base_commit_sha, straight: false)
.and_call_original
diff.diffs
end
- it 'returns persisted diffs if cannot compare with diff refs' do
+ it "returns persisted diffs if cannot compare with diff refs" do
expect(diff).to receive(:load_diffs).and_call_original
- diff.update!(head_commit_sha: 'invalid-sha')
+ diff.update!(head_commit_sha: "invalid-sha")
diff.diffs.diff_files
end
- it 'returns persisted diffs if diff refs does not exist' do
+ it "returns persisted diffs if diff refs does not exist" do
expect(diff).to receive(:load_diffs).and_call_original
diff.update!(start_commit_sha: nil, base_commit_sha: nil)
@@ -92,9 +92,9 @@ describe MergeRequestDiff do
end
end
- describe '#raw_diffs' do
- context 'when the :ignore_whitespace_change option is set' do
- it 'creates a new compare object instead of using preprocessed data' do
+ describe "#raw_diffs" do
+ context "when the :ignore_whitespace_change option is set" do
+ it "creates a new compare object instead of using preprocessed data" do
expect(diff_with_commits).not_to receive(:load_diffs)
expect(diff_with_commits.compare).to receive(:diffs).and_call_original
@@ -102,38 +102,38 @@ describe MergeRequestDiff do
end
end
- context 'when the raw diffs are empty' do
+ context "when the raw diffs are empty" do
before do
MergeRequestDiffFile.where(merge_request_diff_id: diff_with_commits.id).delete_all
end
- it 'returns an empty DiffCollection' do
+ it "returns an empty DiffCollection" do
expect(diff_with_commits.raw_diffs).to be_a(Gitlab::Git::DiffCollection)
expect(diff_with_commits.raw_diffs).to be_empty
end
end
- context 'when the raw diffs exist' do
- it 'returns the diffs' do
+ context "when the raw diffs exist" do
+ it "returns the diffs" do
expect(diff_with_commits.raw_diffs).to be_a(Gitlab::Git::DiffCollection)
expect(diff_with_commits.raw_diffs).not_to be_empty
end
- context 'when the :paths option is set' do
- let(:diffs) { diff_with_commits.raw_diffs(paths: ['files/ruby/popen.rb', 'files/ruby/popen.rb']) }
+ context "when the :paths option is set" do
+ let(:diffs) { diff_with_commits.raw_diffs(paths: ["files/ruby/popen.rb", "files/ruby/popen.rb"]) }
- it 'only returns diffs that match the (old path, new path) given' do
- expect(diffs.map(&:new_path)).to contain_exactly('files/ruby/popen.rb')
+ it "only returns diffs that match the (old path, new path) given" do
+ expect(diffs.map(&:new_path)).to contain_exactly("files/ruby/popen.rb")
end
- it 'only serializes diff files found by query' do
+ it "only serializes diff files found by query" do
expect(diff_with_commits.merge_request_diff_files.count).to be > 10
expect_any_instance_of(MergeRequestDiffFile).to receive(:to_hash).once
diffs
end
- it 'uses the preprocessed diffs' do
+ it "uses the preprocessed diffs" do
expect(diff_with_commits).to receive(:load_diffs)
diffs
@@ -142,14 +142,14 @@ describe MergeRequestDiff do
end
end
- describe '#save_diffs' do
- it 'saves collected state' do
+ describe "#save_diffs" do
+ it "saves collected state" do
mr_diff = create(:merge_request).merge_request_diff
expect(mr_diff.collected?).to be_truthy
end
- it 'saves overflow state' do
+ it "saves overflow state" do
allow(Commit).to receive(:max_diff_options)
.and_return(max_lines: 0, max_files: 0)
@@ -158,7 +158,7 @@ describe MergeRequestDiff do
expect(mr_diff.overflow?).to be_truthy
end
- it 'saves empty state' do
+ it "saves empty state" do
allow_any_instance_of(described_class).to receive_message_chain(:compare, :commits)
.and_return([])
@@ -167,16 +167,16 @@ describe MergeRequestDiff do
expect(mr_diff.empty?).to be_truthy
end
- it 'expands collapsed diffs before saving' do
- mr_diff = create(:merge_request, source_branch: 'expand-collapse-lines', target_branch: 'master').merge_request_diff
- diff_file = mr_diff.merge_request_diff_files.find_by(new_path: 'expand-collapse/file-5.txt')
+ it "expands collapsed diffs before saving" do
+ mr_diff = create(:merge_request, source_branch: "expand-collapse-lines", target_branch: "master").merge_request_diff
+ diff_file = mr_diff.merge_request_diff_files.find_by(new_path: "expand-collapse/file-5.txt")
expect(diff_file.diff).not_to be_empty
end
- it 'saves binary diffs correctly' do
- path = 'files/images/icn-time-tracking.pdf'
- mr_diff = create(:merge_request, source_branch: 'add-pdf-text-binary', target_branch: 'master').merge_request_diff
+ it "saves binary diffs correctly" do
+ path = "files/images/icn-time-tracking.pdf"
+ mr_diff = create(:merge_request, source_branch: "add-pdf-text-binary", target_branch: "master").merge_request_diff
diff_file = mr_diff.merge_request_diff_files.find_by(new_path: path)
expect(diff_file).to be_binary
@@ -185,59 +185,59 @@ describe MergeRequestDiff do
end
end
- describe 'internal diffs configured' do
- include_examples 'merge request diffs'
+ describe "internal diffs configured" do
+ include_examples "merge request diffs"
end
- describe 'external diffs configured' do
+ describe "external diffs configured" do
before do
stub_external_diffs_setting(enabled: true)
end
- include_examples 'merge request diffs'
+ include_examples "merge request diffs"
end
- describe '#commit_shas' do
- it 'returns all commit SHAs using commits from the DB' do
+ describe "#commit_shas" do
+ it "returns all commit SHAs using commits from the DB" do
expect(diff_with_commits.commit_shas).not_to be_empty
expect(diff_with_commits.commit_shas).to all(match(/\h{40}/))
end
end
- describe '#compare_with' do
- it 'delegates compare to the service' do
+ describe "#compare_with" do
+ it "delegates compare to the service" do
expect(CompareService).to receive(:new).and_call_original
diff_with_commits.compare_with(nil)
end
- it 'uses git diff A..B approach by default' do
- diffs = diff_with_commits.compare_with('0b4bc9a49b562e85de7cc9e834518ea6828729b9').diffs
+ it "uses git diff A..B approach by default" do
+ diffs = diff_with_commits.compare_with("0b4bc9a49b562e85de7cc9e834518ea6828729b9").diffs
expect(diffs.size).to eq(21)
end
end
- describe '#commits_count' do
- it 'returns number of commits using serialized commits' do
+ describe "#commits_count" do
+ it "returns number of commits using serialized commits" do
expect(diff_with_commits.commits_count).to eq(29)
end
end
- describe '#commits_by_shas' do
+ describe "#commits_by_shas" do
let(:commit_shas) { diff_with_commits.commit_shas }
- it 'returns empty if no SHAs were provided' do
+ it "returns empty if no SHAs were provided" do
expect(diff_with_commits.commits_by_shas([])).to be_empty
end
- it 'returns one SHA' do
+ it "returns one SHA" do
commits = diff_with_commits.commits_by_shas([commit_shas.first, Gitlab::Git::BLANK_SHA])
expect(commits.count).to eq(1)
end
- it 'returns all matching SHAs' do
+ it "returns all matching SHAs" do
commits = diff_with_commits.commits_by_shas(commit_shas)
expect(commits.count).to eq(commit_shas.count)
@@ -245,7 +245,7 @@ describe MergeRequestDiff do
end
end
- describe '#modified_paths' do
+ describe "#modified_paths" do
subject do
diff = create(:merge_request_diff)
create(:merge_request_diff_file, :new_file, merge_request_diff: diff)
@@ -253,24 +253,24 @@ describe MergeRequestDiff do
diff
end
- it 'returns affected file paths' do
- expect(subject.modified_paths).to eq(%w{foo bar baz})
+ it "returns affected file paths" do
+ expect(subject.modified_paths).to eq(%w[foo bar baz])
end
end
- describe '#opening_external_diff' do
+ describe "#opening_external_diff" do
subject(:diff) { diff_with_commits }
- context 'external diffs disabled' do
+ context "external diffs disabled" do
it { expect(diff.external_diff).not_to be_exists }
- it 'yields nil' do
+ it "yields nil" do
expect { |b| diff.opening_external_diff(&b) }.to yield_with_args(nil)
end
end
- context 'external diffs enabled' do
- let(:test_dir) { 'tmp/tests/external-diffs' }
+ context "external diffs enabled" do
+ let(:test_dir) { "tmp/tests/external-diffs" }
around do |example|
FileUtils.mkdir_p(test_dir)
@@ -288,19 +288,19 @@ describe MergeRequestDiff do
it { expect(diff.external_diff).to be_exists }
- it 'yields an open file' do
+ it "yields an open file" do
expect { |b| diff.opening_external_diff(&b) }.to yield_with_args(File)
end
- it 'is re-entrant' do
+ it "is re-entrant" do
outer_file_a =
- diff.opening_external_diff do |outer_file|
+ diff.opening_external_diff { |outer_file|
diff.opening_external_diff do |inner_file|
expect(outer_file).to eq(inner_file)
end
outer_file
- end
+ }
diff.opening_external_diff do |outer_file_b|
expect(outer_file_a).not_to eq(outer_file_b)
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 82a853a23b9..d00dc178886 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe MergeRequest do
include RepoHelpers
@@ -7,29 +7,29 @@ describe MergeRequest do
subject { create(:merge_request) }
- describe 'associations' do
- it { is_expected.to belong_to(:target_project).class_name('Project') }
- it { is_expected.to belong_to(:source_project).class_name('Project') }
+ describe "associations" do
+ it { is_expected.to belong_to(:target_project).class_name("Project") }
+ it { is_expected.to belong_to(:source_project).class_name("Project") }
it { is_expected.to belong_to(:merge_user).class_name("User") }
it { is_expected.to belong_to(:assignee) }
it { is_expected.to have_many(:merge_request_diffs) }
- context 'for forks' do
+ context "for forks" do
let!(:project) { create(:project) }
let!(:fork) { fork_project(project) }
let!(:merge_request) { create(:merge_request, target_project: project, source_project: fork) }
- it 'does not load another project due to inverse relationship' do
+ it "does not load another project due to inverse relationship" do
expect(project.merge_requests.first.target_project.object_id).to eq(project.object_id)
end
- it 'finds the associated merge request' do
+ it "finds the associated merge request" do
expect(project.merge_requests.find(merge_request.id)).to eq(merge_request)
end
end
end
- describe '#squash_in_progress?' do
+ describe "#squash_in_progress?" do
let(:repo_path) do
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
subject.source_project.repository.path
@@ -38,51 +38,51 @@ describe MergeRequest do
let(:squash_path) { File.join(repo_path, "gitlab-worktree", "squash-#{subject.id}") }
before do
- system(*%W(#{Gitlab.config.git.bin_path} -C #{repo_path} worktree add --detach #{squash_path} master))
+ system(Gitlab.config.git.bin_path.to_s, "-C", repo_path.to_s, "worktree", "add", "--detach", squash_path.to_s, "master")
end
- it 'returns true when there is a current squash directory' do
+ it "returns true when there is a current squash directory" do
expect(subject.squash_in_progress?).to be_truthy
end
- it 'returns false when there is no squash directory' do
+ it "returns false when there is no squash directory" do
FileUtils.rm_rf(squash_path)
expect(subject.squash_in_progress?).to be_falsey
end
- it 'returns false when the squash directory has expired' do
+ it "returns false when the squash directory has expired" do
time = 20.minutes.ago.to_time
File.utime(time, time, squash_path)
expect(subject.squash_in_progress?).to be_falsey
end
- it 'returns false when the source project has been removed' do
+ it "returns false when the source project has been removed" do
allow(subject).to receive(:source_project).and_return(nil)
expect(subject.squash_in_progress?).to be_falsey
end
end
- describe '#squash?' do
+ describe "#squash?" do
let(:merge_request) { build(:merge_request, squash: squash) }
subject { merge_request.squash? }
- context 'disabled in database' do
+ context "disabled in database" do
let(:squash) { false }
it { is_expected.to be_falsy }
end
- context 'enabled in database' do
+ context "enabled in database" do
let(:squash) { true }
it { is_expected.to be_truthy }
end
end
- describe '#default_squash_commit_message' do
+ describe "#default_squash_commit_message" do
let(:project) { subject.project }
def commit_collection(commit_hashes)
@@ -91,11 +91,11 @@ describe MergeRequest do
CommitCollection.new(project, raw_commits)
end
- it 'returns the oldest multiline commit message' do
+ it "returns the oldest multiline commit message" do
commits = commit_collection([
- { message: 'Singleline', parent_ids: [] },
- { message: "Second multiline\nCommit message", parent_ids: [] },
- { message: "First multiline\nCommit message", parent_ids: [] }
+ {message: "Singleline", parent_ids: []},
+ {message: "Second multiline\nCommit message", parent_ids: []},
+ {message: "First multiline\nCommit message", parent_ids: []},
])
expect(subject).to receive(:commits).and_return(commits)
@@ -103,9 +103,9 @@ describe MergeRequest do
expect(subject.default_squash_commit_message).to eq("First multiline\nCommit message")
end
- it 'returns the merge request title if there are no multiline commits' do
+ it "returns the merge request title if there are no multiline commits" do
commits = commit_collection([
- { message: 'Singleline', parent_ids: [] }
+ {message: "Singleline", parent_ids: []},
])
expect(subject).to receive(:commits).and_return(commits)
@@ -114,7 +114,7 @@ describe MergeRequest do
end
end
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Issuable) }
@@ -122,16 +122,16 @@ describe MergeRequest do
it { is_expected.to include_module(Sortable) }
it { is_expected.to include_module(Taskable) }
- it_behaves_like 'AtomicInternalId' do
+ it_behaves_like "AtomicInternalId" do
let(:internal_id_attribute) { :iid }
let(:instance) { build(:merge_request) }
let(:scope) { :target_project }
- let(:scope_attrs) { { project: instance.target_project } }
+ let(:scope_attrs) { {project: instance.target_project} }
let(:usage) { :merge_requests }
end
end
- describe 'validation' do
+ describe "validation" do
it { is_expected.to validate_presence_of(:target_branch) }
it { is_expected.to validate_presence_of(:source_branch) }
@@ -153,12 +153,12 @@ describe MergeRequest do
end
end
- context 'for forks' do
+ context "for forks" do
let(:project) { create(:project) }
let(:fork1) { fork_project(project) }
let(:fork2) { fork_project(project) }
- it 'allows merge requests for sibling-forks' do
+ it "allows merge requests for sibling-forks" do
subject.source_project = fork1
subject.target_project = fork2
@@ -167,16 +167,16 @@ describe MergeRequest do
end
end
- describe 'callbacks' do
- describe '#ensure_merge_request_metrics' do
- it 'creates metrics after saving' do
+ describe "callbacks" do
+ describe "#ensure_merge_request_metrics" do
+ it "creates metrics after saving" do
merge_request = create(:merge_request)
expect(merge_request.metrics).to be_persisted
expect(MergeRequest::Metrics.count).to eq(1)
end
- it 'does not duplicate metrics for a merge request' do
+ it "does not duplicate metrics for a merge request" do
merge_request = create(:merge_request)
merge_request.mark_as_merged!
@@ -186,7 +186,7 @@ describe MergeRequest do
end
end
- describe 'respond to' do
+ describe "respond to" do
it { is_expected.to respond_to(:unchecked?) }
it { is_expected.to respond_to(:can_be_merged?) }
it { is_expected.to respond_to(:cannot_be_merged?) }
@@ -194,52 +194,52 @@ describe MergeRequest do
it { is_expected.to respond_to(:merge_when_pipeline_succeeds) }
end
- describe '.by_commit_sha' do
+ describe ".by_commit_sha" do
subject(:by_commit_sha) { described_class.by_commit_sha(sha) }
let!(:merge_request) { create(:merge_request, :with_diffs) }
- context 'with sha contained in latest merge request diff' do
- let(:sha) { 'b83d6e391c22777fca1ed3012fce84f633d7fed0' }
+ context "with sha contained in latest merge request diff" do
+ let(:sha) { "b83d6e391c22777fca1ed3012fce84f633d7fed0" }
- it 'returns merge requests' do
+ it "returns merge requests" do
expect(by_commit_sha).to eq([merge_request])
end
end
- context 'with sha contained not in latest merge request diff' do
- let(:sha) { 'b83d6e391c22777fca1ed3012fce84f633d7fed0' }
+ context "with sha contained not in latest merge request diff" do
+ let(:sha) { "b83d6e391c22777fca1ed3012fce84f633d7fed0" }
- it 'returns empty requests' do
+ it "returns empty requests" do
latest_merge_request_diff = merge_request.merge_request_diffs.create
- latest_merge_request_diff.merge_request_diff_commits.where(sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0').delete_all
+ latest_merge_request_diff.merge_request_diff_commits.where(sha: "b83d6e391c22777fca1ed3012fce84f633d7fed0").delete_all
expect(by_commit_sha).to be_empty
end
end
- context 'with sha not contained in' do
- let(:sha) { 'b83d6e3' }
+ context "with sha not contained in" do
+ let(:sha) { "b83d6e3" }
- it 'returns empty result' do
+ it "returns empty result" do
expect(by_commit_sha).to be_empty
end
end
end
- describe '.in_projects' do
- it 'returns the merge requests for a set of projects' do
+ describe ".in_projects" do
+ it "returns the merge requests for a set of projects" do
expect(described_class.in_projects(Project.all)).to eq([subject])
end
end
- describe '.set_latest_merge_request_diff_ids!' do
+ describe ".set_latest_merge_request_diff_ids!" do
def create_merge_request_with_diffs(source_branch, diffs: 2)
params = {
target_project: project,
- target_branch: 'master',
+ target_branch: "master",
source_project: project,
- source_branch: source_branch
+ source_branch: source_branch,
}
create(:merge_request, params).tap do |mr|
@@ -249,105 +249,105 @@ describe MergeRequest do
let(:project) { create(:project) }
- it 'sets IDs for merge requests, whether they are already set or not' do
+ it "sets IDs for merge requests, whether they are already set or not" do
merge_requests = [
- create_merge_request_with_diffs('feature'),
- create_merge_request_with_diffs('feature-conflict'),
- create_merge_request_with_diffs('wip', diffs: 0),
- create_merge_request_with_diffs('csv')
+ create_merge_request_with_diffs("feature"),
+ create_merge_request_with_diffs("feature-conflict"),
+ create_merge_request_with_diffs("wip", diffs: 0),
+ create_merge_request_with_diffs("csv"),
]
merge_requests.take(2).each do |merge_request|
merge_request.update_column(:latest_merge_request_diff_id, nil)
end
- expected = merge_requests.map do |merge_request|
+ expected = merge_requests.map { |merge_request|
merge_request.merge_request_diffs.maximum(:id)
- end
+ }
expect { project.merge_requests.set_latest_merge_request_diff_ids! }
.to change { merge_requests.map { |mr| mr.reload.latest_merge_request_diff_id } }.to(expected)
end
end
- describe '#target_branch_sha' do
+ describe "#target_branch_sha" do
let(:project) { create(:project, :repository) }
subject { create(:merge_request, source_project: project, target_project: project) }
- context 'when the target branch does not exist' do
+ context "when the target branch does not exist" do
before do
project.repository.rm_branch(subject.author, subject.target_branch)
subject.clear_memoized_shas
end
- it 'returns nil' do
+ it "returns nil" do
expect(subject.target_branch_sha).to be_nil
end
end
- it 'returns memoized value' do
- subject.target_branch_sha = '8ffb3c15a5475e59ae909384297fede4badcb4c7'
+ it "returns memoized value" do
+ subject.target_branch_sha = "8ffb3c15a5475e59ae909384297fede4badcb4c7"
- expect(subject.target_branch_sha).to eq '8ffb3c15a5475e59ae909384297fede4badcb4c7'
+ expect(subject.target_branch_sha).to eq "8ffb3c15a5475e59ae909384297fede4badcb4c7"
end
end
- describe '#card_attributes' do
- it 'includes the author name' do
- allow(subject).to receive(:author).and_return(double(name: 'Robert'))
+ describe "#card_attributes" do
+ it "includes the author name" do
+ allow(subject).to receive(:author).and_return(double(name: "Robert"))
allow(subject).to receive(:assignee).and_return(nil)
expect(subject.card_attributes)
- .to eq({ 'Author' => 'Robert', 'Assignee' => nil })
+ .to eq({"Author" => "Robert", "Assignee" => nil})
end
- it 'includes the assignee name' do
- allow(subject).to receive(:author).and_return(double(name: 'Robert'))
- allow(subject).to receive(:assignee).and_return(double(name: 'Douwe'))
+ it "includes the assignee name" do
+ allow(subject).to receive(:author).and_return(double(name: "Robert"))
+ allow(subject).to receive(:assignee).and_return(double(name: "Douwe"))
expect(subject.card_attributes)
- .to eq({ 'Author' => 'Robert', 'Assignee' => 'Douwe' })
+ .to eq({"Author" => "Robert", "Assignee" => "Douwe"})
end
end
- describe '#assignee_ids' do
- it 'returns an array of the assigned user id' do
+ describe "#assignee_ids" do
+ it "returns an array of the assigned user id" do
subject.assignee_id = 123
expect(subject.assignee_ids).to eq([123])
end
end
- describe '#assignee_ids=' do
- it 'sets assignee_id to the last id in the array' do
+ describe "#assignee_ids=" do
+ it "sets assignee_id to the last id in the array" do
subject.assignee_ids = [123, 456]
expect(subject.assignee_id).to eq(456)
end
end
- describe '#assignee_or_author?' do
+ describe "#assignee_or_author?" do
let(:user) { create(:user) }
- it 'returns true for a user that is assigned to a merge request' do
+ it "returns true for a user that is assigned to a merge request" do
subject.assignee = user
expect(subject.assignee_or_author?(user)).to eq(true)
end
- it 'returns true for a user that is the author of a merge request' do
+ it "returns true for a user that is the author of a merge request" do
subject.author = user
expect(subject.assignee_or_author?(user)).to eq(true)
end
- it 'returns false for a user that is not the assignee or author' do
+ it "returns false for a user that is not the assignee or author" do
expect(subject.assignee_or_author?(user)).to eq(false)
end
end
- describe '#visible_closing_issues_for' do
+ describe "#visible_closing_issues_for" do
let(:guest) { create(:user) }
let(:developer) { create(:user) }
let(:issue_1) { create(:issue, project: subject.source_project) }
@@ -357,11 +357,11 @@ describe MergeRequest do
before do
subject.project.add_developer(subject.author)
subject.target_branch = subject.project.default_branch
- commit = double('commit1', safe_message: "Fixes #{issue_1.to_reference} #{issue_2.to_reference} #{confidential_issue.to_reference}")
+ commit = double("commit1", safe_message: "Fixes #{issue_1.to_reference} #{issue_2.to_reference} #{confidential_issue.to_reference}")
allow(subject).to receive(:commits).and_return([commit])
end
- it 'shows only allowed issues to guest' do
+ it "shows only allowed issues to guest" do
subject.project.add_guest(guest)
subject.cache_merge_request_closes_issues!
@@ -369,7 +369,7 @@ describe MergeRequest do
expect(subject.visible_closing_issues_for(guest)).to match_array([issue_1, issue_2])
end
- it 'shows only allowed issues to developer' do
+ it "shows only allowed issues to developer" do
subject.project.add_developer(developer)
subject.cache_merge_request_closes_issues!
@@ -377,13 +377,13 @@ describe MergeRequest do
expect(subject.visible_closing_issues_for(developer)).to match_array([issue_1, confidential_issue, issue_2])
end
- context 'when external issue tracker is enabled' do
+ context "when external issue tracker is enabled" do
before do
subject.project.has_external_issue_tracker = true
subject.project.save!
end
- it 'calls non #closes_issues to retrieve data' do
+ it "calls non #closes_issues to retrieve data" do
expect(subject).to receive(:closes_issues)
expect(subject).not_to receive(:cached_closes_issues)
@@ -392,23 +392,23 @@ describe MergeRequest do
end
end
- describe '#cache_merge_request_closes_issues!' do
+ describe "#cache_merge_request_closes_issues!" do
before do
subject.project.add_developer(subject.author)
subject.target_branch = subject.project.default_branch
end
- it 'caches closed issues' do
+ it "caches closed issues" do
issue = create :issue, project: subject.project
- commit = double('commit1', safe_message: "Fixes #{issue.to_reference}")
+ commit = double("commit1", safe_message: "Fixes #{issue.to_reference}")
allow(subject).to receive(:commits).and_return([commit])
expect { subject.cache_merge_request_closes_issues!(subject.author) }.to change(subject.merge_requests_closing_issues, :count).by(1)
end
- it 'does not cache closed issues when merge request is closed' do
+ it "does not cache closed issues when merge request is closed" do
issue = create :issue, project: subject.project
- commit = double('commit1', safe_message: "Fixes #{issue.to_reference}")
+ commit = double("commit1", safe_message: "Fixes #{issue.to_reference}")
allow(subject).to receive(:commits).and_return([commit])
allow(subject).to receive(:state).and_return("closed")
@@ -416,25 +416,25 @@ describe MergeRequest do
expect { subject.cache_merge_request_closes_issues!(subject.author) }.not_to change(subject.merge_requests_closing_issues, :count)
end
- it 'does not cache closed issues when merge request is merged' do
+ it "does not cache closed issues when merge request is merged" do
issue = create :issue, project: subject.project
- commit = double('commit1', safe_message: "Fixes #{issue.to_reference}")
+ commit = double("commit1", safe_message: "Fixes #{issue.to_reference}")
allow(subject).to receive(:commits).and_return([commit])
allow(subject).to receive(:state).and_return("merged")
expect { subject.cache_merge_request_closes_issues!(subject.author) }.not_to change(subject.merge_requests_closing_issues, :count)
end
- context 'when both internal and external issue trackers are enabled' do
+ context "when both internal and external issue trackers are enabled" do
before do
subject.project.has_external_issue_tracker = true
subject.project.save!
create(:jira_service, project: subject.project)
end
- it 'does not cache issues from external trackers' do
- issue = ExternalIssue.new('JIRA-123', subject.project)
- commit = double('commit1', safe_message: "Fixes #{issue.to_reference}")
+ it "does not cache issues from external trackers" do
+ issue = ExternalIssue.new("JIRA-123", subject.project)
+ commit = double("commit1", safe_message: "Fixes #{issue.to_reference}")
allow(subject).to receive(:commits).and_return([commit])
@@ -442,9 +442,9 @@ describe MergeRequest do
expect { subject.cache_merge_request_closes_issues!(subject.author) }.not_to change(subject.merge_requests_closing_issues, :count)
end
- it 'caches an internal issue' do
+ it "caches an internal issue" do
issue = create(:issue, project: subject.project)
- commit = double('commit1', safe_message: "Fixes #{issue.to_reference}")
+ commit = double("commit1", safe_message: "Fixes #{issue.to_reference}")
allow(subject).to receive(:commits).and_return([commit])
expect { subject.cache_merge_request_closes_issues!(subject.author) }
@@ -452,24 +452,24 @@ describe MergeRequest do
end
end
- context 'when only external issue tracker enabled' do
+ context "when only external issue tracker enabled" do
before do
subject.project.has_external_issue_tracker = true
subject.project.issues_enabled = false
subject.project.save!
end
- it 'does not cache issues from external trackers' do
- issue = ExternalIssue.new('JIRA-123', subject.project)
- commit = double('commit1', safe_message: "Fixes #{issue.to_reference}")
+ it "does not cache issues from external trackers" do
+ issue = ExternalIssue.new("JIRA-123", subject.project)
+ commit = double("commit1", safe_message: "Fixes #{issue.to_reference}")
allow(subject).to receive(:commits).and_return([commit])
expect { subject.cache_merge_request_closes_issues!(subject.author) }.not_to change(subject.merge_requests_closing_issues, :count)
end
- it 'does not cache an internal issue' do
+ it "does not cache an internal issue" do
issue = create(:issue, project: subject.project)
- commit = double('commit1', safe_message: "Fixes #{issue.to_reference}")
+ commit = double("commit1", safe_message: "Fixes #{issue.to_reference}")
allow(subject).to receive(:commits).and_return([commit])
expect { subject.cache_merge_request_closes_issues!(subject.author) }
@@ -478,30 +478,30 @@ describe MergeRequest do
end
end
- describe '#source_branch_sha' do
+ describe "#source_branch_sha" do
let(:last_branch_commit) { subject.source_project.repository.commit(Gitlab::Git::BRANCH_REF_PREFIX + subject.source_branch) }
- context 'with diffs' do
+ context "with diffs" do
subject { create(:merge_request, :with_diffs) }
- it 'returns the sha of the source branch last commit' do
+ it "returns the sha of the source branch last commit" do
expect(subject.source_branch_sha).to eq(last_branch_commit.sha)
end
end
- context 'without diffs' do
+ context "without diffs" do
subject { create(:merge_request, :without_diffs) }
- it 'returns the sha of the source branch last commit' do
+ it "returns the sha of the source branch last commit" do
expect(subject.source_branch_sha).to eq(last_branch_commit.sha)
end
- context 'when there is a tag name matching the branch name' do
+ context "when there is a tag name matching the branch name" do
let(:tag_name) { subject.source_branch }
- it 'returns the sha of the source branch last commit' do
+ it "returns the sha of the source branch last commit" do
subject.source_project.repository.add_tag(subject.author,
- tag_name,
- subject.target_branch_sha,
- 'Add a tag')
+ tag_name,
+ subject.target_branch_sha,
+ "Add a tag")
expect(subject.source_branch_sha).to eq(last_branch_commit.sha)
@@ -510,44 +510,44 @@ describe MergeRequest do
end
end
- context 'when the merge request is being created' do
+ context "when the merge request is being created" do
subject { build(:merge_request, source_branch: nil, compare_commits: []) }
- it 'returns nil' do
+ it "returns nil" do
expect(subject.source_branch_sha).to be_nil
end
end
- it 'returns memoized value' do
- subject.source_branch_sha = '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
+ it "returns memoized value" do
+ subject.source_branch_sha = "2e5d3239642f9161dcbbc4b70a211a68e5e45e2b"
- expect(subject.source_branch_sha).to eq '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
+ expect(subject.source_branch_sha).to eq "2e5d3239642f9161dcbbc4b70a211a68e5e45e2b"
end
end
- describe '#to_reference' do
- let(:project) { build(:project, name: 'sample-project') }
+ describe "#to_reference" do
+ let(:project) { build(:project, name: "sample-project") }
let(:merge_request) { build(:merge_request, target_project: project, iid: 1) }
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(merge_request.to_reference).to eq "!1"
end
- it 'supports a cross-project reference' do
- another_project = build(:project, name: 'another-project', namespace: project.namespace)
+ it "supports a cross-project reference" do
+ another_project = build(:project, name: "another-project", namespace: project.namespace)
expect(merge_request.to_reference(another_project)).to eq "sample-project!1"
end
- it 'returns a String reference with the full path' do
- expect(merge_request.to_reference(full: true)).to eq(project.full_path + '!1')
+ it "returns a String reference with the full path" do
+ expect(merge_request.to_reference(full: true)).to eq(project.full_path + "!1")
end
end
- describe '#raw_diffs' do
+ describe "#raw_diffs" do
let(:merge_request) { build(:merge_request) }
- let(:options) { { paths: ['a/b', 'b/a', 'c/*'] } }
+ let(:options) { {paths: ["a/b", "b/a", "c/*"]} }
- context 'when there are MR diffs' do
- it 'delegates to the MR diffs' do
+ context "when there are MR diffs" do
+ it "delegates to the MR diffs" do
merge_request.merge_request_diff = MergeRequestDiff.new
expect(merge_request.merge_request_diff).to receive(:raw_diffs).with(options)
@@ -556,8 +556,8 @@ describe MergeRequest do
end
end
- context 'when there are no MR diffs' do
- it 'delegates to the compare object' do
+ context "when there are no MR diffs" do
+ it "delegates to the compare object" do
merge_request.compare = double(:compare)
expect(merge_request.compare).to receive(:raw_diffs).with(options)
@@ -567,12 +567,12 @@ describe MergeRequest do
end
end
- describe '#diffs' do
+ describe "#diffs" do
let(:merge_request) { build(:merge_request) }
- let(:options) { { paths: ['a/b', 'b/a', 'c/*'] } }
+ let(:options) { {paths: ["a/b", "b/a", "c/*"]} }
- context 'when there are MR diffs' do
- it 'delegates to the MR diffs' do
+ context "when there are MR diffs" do
+ it "delegates to the MR diffs" do
merge_request.save
expect(merge_request.merge_request_diff).to receive(:raw_diffs).with(hash_including(options)).and_call_original
@@ -581,8 +581,8 @@ describe MergeRequest do
end
end
- context 'when there are no MR diffs' do
- it 'delegates to the compare object, setting expanded: true' do
+ context "when there are no MR diffs" do
+ it "delegates to the compare object, setting expanded: true" do
merge_request.compare = double(:compare)
expect(merge_request.compare).to receive(:diffs).with(options.merge(expanded: true))
@@ -592,10 +592,10 @@ describe MergeRequest do
end
end
- describe '#preload_discussions_diff_highlight' do
+ describe "#preload_discussions_diff_highlight" do
let(:merge_request) { create(:merge_request) }
- context 'with commit diff note' do
+ context "with commit diff note" do
let(:other_merge_request) { create(:merge_request) }
let!(:diff_note) do
@@ -606,7 +606,7 @@ describe MergeRequest do
create(:diff_note_on_commit, project: other_merge_request.project)
end
- it 'preloads diff highlighting' do
+ it "preloads diff highlighting" do
expect_next_instance_of(Gitlab::DiscussionsDiff::FileCollection) do |collection|
note_diff_file = diff_note.note_diff_file
@@ -619,7 +619,7 @@ describe MergeRequest do
end
end
- context 'with merge request diff note' do
+ context "with merge request diff note" do
let!(:unresolved_diff_note) do
create(:diff_note_on_merge_request, project: merge_request.project, noteable: merge_request)
end
@@ -628,7 +628,7 @@ describe MergeRequest do
create(:diff_note_on_merge_request, :resolved, project: merge_request.project, noteable: merge_request)
end
- it 'preloads diff highlighting' do
+ it "preloads diff highlighting" do
expect_next_instance_of(Gitlab::DiscussionsDiff::FileCollection) do |collection|
note_diff_file = unresolved_diff_note.note_diff_file
@@ -643,26 +643,26 @@ describe MergeRequest do
end
end
- describe '#diff_size' do
+ describe "#diff_size" do
let(:merge_request) do
- build(:merge_request, source_branch: 'expand-collapse-files', target_branch: 'master')
+ build(:merge_request, source_branch: "expand-collapse-files", target_branch: "master")
end
- context 'when there are MR diffs' do
- it 'returns the correct count' do
+ context "when there are MR diffs" do
+ it "returns the correct count" do
merge_request.save
- expect(merge_request.diff_size).to eq('105')
+ expect(merge_request.diff_size).to eq("105")
end
- it 'returns the correct overflow count' do
+ it "returns the correct overflow count" do
allow(Commit).to receive(:max_diff_options).and_return(max_files: 2)
merge_request.save
- expect(merge_request.diff_size).to eq('2+')
+ expect(merge_request.diff_size).to eq("2+")
end
- it 'does not perform highlighting' do
+ it "does not perform highlighting" do
merge_request.save
expect(Gitlab::Diff::Highlight).not_to receive(:new)
@@ -671,7 +671,7 @@ describe MergeRequest do
end
end
- context 'when there are no MR diffs' do
+ context "when there are no MR diffs" do
def set_compare(merge_request)
merge_request.compare = CompareService.new(
merge_request.source_project,
@@ -682,20 +682,20 @@ describe MergeRequest do
)
end
- it 'returns the correct count' do
+ it "returns the correct count" do
set_compare(merge_request)
- expect(merge_request.diff_size).to eq('105')
+ expect(merge_request.diff_size).to eq("105")
end
- it 'returns the correct overflow count' do
+ it "returns the correct overflow count" do
allow(Commit).to receive(:max_diff_options).and_return(max_files: 2)
set_compare(merge_request)
- expect(merge_request.diff_size).to eq('2+')
+ expect(merge_request.diff_size).to eq("2+")
end
- it 'does not perform highlighting' do
+ it "does not perform highlighting" do
set_compare(merge_request)
expect(Gitlab::Diff::Highlight).not_to receive(:new)
@@ -705,7 +705,7 @@ describe MergeRequest do
end
end
- describe '#modified_paths' do
+ describe "#modified_paths" do
let(:paths) { double(:paths) }
subject(:merge_request) { build(:merge_request) }
@@ -713,31 +713,31 @@ describe MergeRequest do
expect(diff).to receive(:modified_paths).and_return(paths)
end
- context 'when past_merge_request_diff is specified' do
+ context "when past_merge_request_diff is specified" do
let(:another_diff) { double(:merge_request_diff) }
let(:diff) { another_diff }
- it 'returns affected file paths from specified past_merge_request_diff' do
+ it "returns affected file paths from specified past_merge_request_diff" do
expect(merge_request.modified_paths(past_merge_request_diff: another_diff)).to eq(paths)
end
end
- context 'when compare is present' do
+ context "when compare is present" do
let(:compare) { double(:compare) }
let(:diff) { compare }
- it 'returns affected file paths from compare' do
+ it "returns affected file paths from compare" do
merge_request.compare = compare
expect(merge_request.modified_paths).to eq(paths)
end
end
- context 'when no arguments provided' do
+ context "when no arguments provided" do
let(:diff) { merge_request.merge_request_diff }
- subject(:merge_request) { create(:merge_request, source_branch: 'feature', target_branch: 'master') }
+ subject(:merge_request) { create(:merge_request, source_branch: "feature", target_branch: "master") }
- it 'returns affected file paths for merge_request_diff' do
+ it "returns affected file paths for merge_request_diff" do
expect(merge_request.modified_paths).to eq(paths)
end
end
@@ -767,33 +767,33 @@ describe MergeRequest do
end
end
- describe '#for_fork?' do
- it 'returns true if the merge request is for a fork' do
+ describe "#for_fork?" do
+ it "returns true if the merge request is for a fork" do
subject.source_project = build_stubbed(:project, namespace: create(:group))
subject.target_project = build_stubbed(:project, namespace: create(:group))
expect(subject.for_fork?).to be_truthy
end
- it 'returns false if is not for a fork' do
+ it "returns false if is not for a fork" do
expect(subject.for_fork?).to be_falsey
end
end
- describe '#closes_issues' do
+ describe "#closes_issues" do
let(:issue0) { create :issue, project: subject.project }
let(:issue1) { create :issue, project: subject.project }
- let(:commit0) { double('commit0', safe_message: "Fixes #{issue0.to_reference}") }
- let(:commit1) { double('commit1', safe_message: "Fixes #{issue0.to_reference}") }
- let(:commit2) { double('commit2', safe_message: "Fixes #{issue1.to_reference}") }
+ let(:commit0) { double("commit0", safe_message: "Fixes #{issue0.to_reference}") }
+ let(:commit1) { double("commit1", safe_message: "Fixes #{issue0.to_reference}") }
+ let(:commit2) { double("commit2", safe_message: "Fixes #{issue1.to_reference}") }
before do
subject.project.add_developer(subject.author)
allow(subject).to receive(:commits).and_return([commit0, commit1, commit2])
end
- it 'accesses the set of issues that will be closed on acceptance' do
+ it "accesses the set of issues that will be closed on acceptance" do
allow(subject.project).to receive(:default_branch)
.and_return(subject.target_branch)
@@ -802,21 +802,21 @@ describe MergeRequest do
expect(closed).to include(issue0, issue1)
end
- it 'only lists issues as to be closed if it targets the default branch' do
- allow(subject.project).to receive(:default_branch).and_return('master')
- subject.target_branch = 'something-else'
+ it "only lists issues as to be closed if it targets the default branch" do
+ allow(subject.project).to receive(:default_branch).and_return("master")
+ subject.target_branch = "something-else"
expect(subject.closes_issues).to be_empty
end
end
- describe '#issues_mentioned_but_not_closing' do
+ describe "#issues_mentioned_but_not_closing" do
let(:closing_issue) { create :issue, project: subject.project }
let(:mentioned_issue) { create :issue, project: subject.project }
- let(:commit) { double('commit', safe_message: "Fixes #{closing_issue.to_reference}") }
+ let(:commit) { double("commit", safe_message: "Fixes #{closing_issue.to_reference}") }
- it 'detects issues mentioned in description but not closed' do
+ it "detects issues mentioned in description but not closed" do
subject.project.add_developer(subject.author)
subject.description = "Is related to #{mentioned_issue.to_reference} and #{closing_issue.to_reference}"
@@ -828,28 +828,28 @@ describe MergeRequest do
expect(subject.issues_mentioned_but_not_closing(subject.author)).to match_array([mentioned_issue])
end
- context 'when the project has an external issue tracker' do
+ context "when the project has an external issue tracker" do
before do
subject.project.add_developer(subject.author)
- commit = double(:commit, safe_message: 'Fixes TEST-3')
+ commit = double(:commit, safe_message: "Fixes TEST-3")
create(:jira_service, project: subject.project)
allow(subject).to receive(:commits).and_return([commit])
- allow(subject).to receive(:description).and_return('Is related to TEST-2 and TEST-3')
+ allow(subject).to receive(:description).and_return("Is related to TEST-2 and TEST-3")
allow(subject.project).to receive(:default_branch).and_return(subject.target_branch)
end
- it 'detects issues mentioned in description but not closed' do
+ it "detects issues mentioned in description but not closed" do
subject.cache_merge_request_closes_issues!
- expect(subject.issues_mentioned_but_not_closing(subject.author).map(&:to_s)).to match_array(['TEST-2'])
+ expect(subject.issues_mentioned_but_not_closing(subject.author).map(&:to_s)).to match_array(["TEST-2"])
end
end
end
describe "#work_in_progress?" do
- ['WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP [WIP] WIP: WIP '].each do |wip_prefix|
+ ["WIP ", "WIP:", "WIP: ", "[WIP]", "[WIP] ", " [WIP] WIP [WIP] WIP: WIP "].each do |wip_prefix|
it "detects the '#{wip_prefix}' prefix" do
subject.title = "#{wip_prefix}#{subject.title}"
expect(subject.work_in_progress?).to eq true
@@ -872,7 +872,7 @@ describe MergeRequest do
end
describe "#wipless_title" do
- ['WIP ', 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', '[WIP] WIP [WIP] WIP: WIP '].each do |wip_prefix|
+ ["WIP ", "WIP:", "WIP: ", "[WIP]", "[WIP] ", "[WIP] WIP [WIP] WIP: WIP "].each do |wip_prefix|
it "removes the '#{wip_prefix}' prefix" do
wipless_title = subject.title
subject.title = "#{wip_prefix}#{subject.title}"
@@ -911,7 +911,7 @@ describe MergeRequest do
end
end
- describe '#can_remove_source_branch?' do
+ describe "#can_remove_source_branch?" do
set(:user) { create(:user) }
set(:merge_request) { create(:merge_request, :simple) }
@@ -928,7 +928,7 @@ describe MergeRequest do
end
it "can't remove a root ref" do
- subject.update(source_branch: 'master', target_branch: 'feature')
+ subject.update(source_branch: "master", target_branch: "feature")
expect(subject.can_remove_source_branch?(user)).to be_falsey
end
@@ -953,22 +953,22 @@ describe MergeRequest do
end
end
- describe '#default_merge_commit_message' do
- it 'includes merge information as the title' do
- request = build(:merge_request, source_branch: 'source', target_branch: 'target')
+ describe "#default_merge_commit_message" do
+ it "includes merge information as the title" do
+ request = build(:merge_request, source_branch: "source", target_branch: "target")
expect(request.default_merge_commit_message)
.to match("Merge branch 'source' into 'target'\n\n")
end
- it 'includes its title in the body' do
- request = build(:merge_request, title: 'Remove all technical debt')
+ it "includes its title in the body" do
+ request = build(:merge_request, title: "Remove all technical debt")
expect(request.default_merge_commit_message)
.to match("Remove all technical debt\n\n")
end
- it 'includes its closed issues in the body' do
+ it "includes its closed issues in the body" do
issue = create(:issue, project: subject.project)
subject.project.add_developer(subject.author)
@@ -980,28 +980,28 @@ describe MergeRequest do
.to match("Closes #{issue.to_reference}")
end
- it 'includes its reference in the body' do
+ it "includes its reference in the body" do
request = build_stubbed(:merge_request)
expect(request.default_merge_commit_message)
.to match("See merge request #{request.to_reference(full: true)}")
end
- it 'excludes multiple linebreak runs when description is blank' do
- request = build(:merge_request, title: 'Title', description: nil)
+ it "excludes multiple linebreak runs when description is blank" do
+ request = build(:merge_request, title: "Title", description: nil)
expect(request.default_merge_commit_message).not_to match("Title\n\n\n\n")
end
- it 'includes its description in the body' do
- request = build(:merge_request, description: 'By removing all code')
+ it "includes its description in the body" do
+ request = build(:merge_request, description: "By removing all code")
expect(request.default_merge_commit_message(include_description: true))
.to match("By removing all code\n\n")
end
- it 'does not includes its description in the body' do
- request = build(:merge_request, description: 'By removing all code')
+ it "does not includes its description in the body" do
+ request = build(:merge_request, description: "By removing all code")
expect(request.default_merge_commit_message)
.not_to match("By removing all code\n\n")
@@ -1011,7 +1011,7 @@ describe MergeRequest do
describe "#reset_merge_when_pipeline_succeeds" do
let(:merge_if_green) do
create :merge_request, merge_when_pipeline_succeeds: true, merge_user: create(:user),
- merge_params: { "should_remove_source_branch" => "1", "commit_message" => "msg" }
+ merge_params: {"should_remove_source_branch" => "1", "commit_message" => "msg"}
end
it "sets the item to false" do
@@ -1024,36 +1024,36 @@ describe MergeRequest do
end
end
- describe '#commit_authors' do
- it 'returns all the authors of every commit in the merge request' do
- users = subject.commits.map(&:author_email).uniq.map do |email|
+ describe "#commit_authors" do
+ it "returns all the authors of every commit in the merge request" do
+ users = subject.commits.map(&:author_email).uniq.map { |email|
create(:user, email: email)
- end
+ }
expect(subject.commit_authors).to match_array(users)
end
- it 'returns an empty array if no author is associated with a user' do
+ it "returns an empty array if no author is associated with a user" do
expect(subject.commit_authors).to be_empty
end
end
- describe '#authors' do
- it 'returns a list with all the commit authors in the merge request and author' do
- users = subject.commits.map(&:author_email).uniq.map do |email|
+ describe "#authors" do
+ it "returns a list with all the commit authors in the merge request and author" do
+ users = subject.commits.map(&:author_email).uniq.map { |email|
create(:user, email: email)
- end
+ }
expect(subject.authors).to match_array([subject.author, *users])
end
- it 'returns only the author if no committer is associated with a user' do
+ it "returns only the author if no committer is associated with a user" do
expect(subject.authors).to contain_exactly(subject.author)
end
end
- describe '#hook_attrs' do
- it 'delegates to Gitlab::HookData::MergeRequestBuilder#build' do
+ describe "#hook_attrs" do
+ it "delegates to Gitlab::HookData::MergeRequestBuilder#build" do
builder = double
expect(Gitlab::HookData::MergeRequestBuilder)
@@ -1064,11 +1064,11 @@ describe MergeRequest do
end
end
- describe '#diverged_commits_count' do
+ describe "#diverged_commits_count" do
let(:project) { create(:project, :repository) }
let(:forked_project) { fork_project(project, nil, repository: true) }
- context 'when the target branch does not exist anymore' do
+ context "when the target branch does not exist anymore" do
subject { create(:merge_request, source_project: project, target_project: project) }
before do
@@ -1076,45 +1076,45 @@ describe MergeRequest do
subject.clear_memoized_shas
end
- it 'does not crash' do
+ it "does not crash" do
expect { subject.diverged_commits_count }.not_to raise_error
end
- it 'returns 0' do
+ it "returns 0" do
expect(subject.diverged_commits_count).to eq(0)
end
end
- context 'diverged on same repository' do
+ context "diverged on same repository" do
subject(:merge_request_with_divergence) { create(:merge_request, :diverged, source_project: project, target_project: project) }
- it 'counts commits that are on target branch but not on source branch' do
+ it "counts commits that are on target branch but not on source branch" do
expect(subject.diverged_commits_count).to eq(29)
end
end
- context 'diverged on fork' do
+ context "diverged on fork" do
subject(:merge_request_fork_with_divergence) { create(:merge_request, :diverged, source_project: forked_project, target_project: project) }
- it 'counts commits that are on target branch but not on source branch' do
+ it "counts commits that are on target branch but not on source branch" do
expect(subject.diverged_commits_count).to eq(29)
end
end
- context 'rebased on fork' do
+ context "rebased on fork" do
subject(:merge_request_rebased) { create(:merge_request, :rebased, source_project: forked_project, target_project: project) }
- it 'counts commits that are on target branch but not on source branch' do
+ it "counts commits that are on target branch but not on source branch" do
expect(subject.diverged_commits_count).to eq(0)
end
end
- describe 'caching' do
+ describe "caching" do
before do
allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache::MemoryStore.new)
end
- it 'caches the output' do
+ it "caches the output" do
expect(subject).to receive(:compute_diverged_commits_count)
.once
.and_return(2)
@@ -1123,64 +1123,64 @@ describe MergeRequest do
subject.diverged_commits_count
end
- it 'invalidates the cache when the source sha changes' do
+ it "invalidates the cache when the source sha changes" do
expect(subject).to receive(:compute_diverged_commits_count)
.twice
.and_return(2)
subject.diverged_commits_count
- allow(subject).to receive(:source_branch_sha).and_return('123abc')
+ allow(subject).to receive(:source_branch_sha).and_return("123abc")
subject.diverged_commits_count
end
- it 'invalidates the cache when the target sha changes' do
+ it "invalidates the cache when the target sha changes" do
expect(subject).to receive(:compute_diverged_commits_count)
.twice
.and_return(2)
subject.diverged_commits_count
- allow(subject).to receive(:target_branch_sha).and_return('123abc')
+ allow(subject).to receive(:target_branch_sha).and_return("123abc")
subject.diverged_commits_count
end
end
end
- it_behaves_like 'an editable mentionable' do
+ it_behaves_like "an editable mentionable" do
subject { create(:merge_request, :simple) }
let(:backref_text) { "merge request #{subject.to_reference}" }
let(:set_mentionable_text) { ->(txt) { subject.description = txt } }
end
- it_behaves_like 'a Taskable' do
+ it_behaves_like "a Taskable" do
subject { create :merge_request, :simple }
end
- describe '#commit_shas' do
+ describe "#commit_shas" do
before do
allow(subject.merge_request_diff).to receive(:commit_shas)
- .and_return(['sha1'])
+ .and_return(["sha1"])
end
- it 'delegates to merge request diff' do
- expect(subject.commit_shas).to eq ['sha1']
+ it "delegates to merge request diff" do
+ expect(subject.commit_shas).to eq ["sha1"]
end
end
- context 'head pipeline' do
+ context "head pipeline" do
before do
- allow(subject).to receive(:diff_head_sha).and_return('lastsha')
+ allow(subject).to receive(:diff_head_sha).and_return("lastsha")
end
- describe '#head_pipeline' do
- it 'returns nil for MR without head_pipeline_id' do
+ describe "#head_pipeline" do
+ it "returns nil for MR without head_pipeline_id" do
subject.update_attribute(:head_pipeline_id, nil)
expect(subject.head_pipeline).to be_nil
end
- context 'when the source project does not exist' do
- it 'returns nil' do
+ context "when the source project does not exist" do
+ it "returns nil" do
allow(subject).to receive(:source_project).and_return(nil)
expect(subject.head_pipeline).to be_nil
@@ -1188,23 +1188,23 @@ describe MergeRequest do
end
end
- describe '#actual_head_pipeline' do
- it 'returns nil for MR with old pipeline' do
- pipeline = create(:ci_empty_pipeline, sha: 'notlatestsha')
+ describe "#actual_head_pipeline" do
+ it "returns nil for MR with old pipeline" do
+ pipeline = create(:ci_empty_pipeline, sha: "notlatestsha")
subject.update_attribute(:head_pipeline_id, pipeline.id)
expect(subject.actual_head_pipeline).to be_nil
end
- it 'returns the pipeline for MR with recent pipeline' do
- pipeline = create(:ci_empty_pipeline, sha: 'lastsha')
+ it "returns the pipeline for MR with recent pipeline" do
+ pipeline = create(:ci_empty_pipeline, sha: "lastsha")
subject.update_attribute(:head_pipeline_id, pipeline.id)
expect(subject.actual_head_pipeline).to eq(subject.head_pipeline)
expect(subject.actual_head_pipeline).to eq(pipeline)
end
- it 'returns nil when source project does not exist' do
+ it "returns nil when source project does not exist" do
allow(subject).to receive(:source_project).and_return(nil)
expect(subject.actual_head_pipeline).to be_nil
@@ -1212,12 +1212,12 @@ describe MergeRequest do
end
end
- describe '#merge_pipeline' do
- it 'returns nil when not merged' do
+ describe "#merge_pipeline" do
+ it "returns nil when not merged" do
expect(subject.merge_pipeline).to be_nil
end
- context 'when the MR is merged' do
+ context "when the MR is merged" do
let(:sha) { subject.target_project.commit.id }
let(:pipeline) { create(:ci_empty_pipeline, sha: sha, ref: subject.target_branch, project: subject.target_project) }
@@ -1226,17 +1226,17 @@ describe MergeRequest do
subject.update_attribute(:merge_commit_sha, pipeline.sha)
end
- it 'returns the post-merge pipeline' do
+ it "returns the post-merge pipeline" do
expect(subject.merge_pipeline).to eq(pipeline)
end
end
end
- describe '#has_ci?' do
+ describe "#has_ci?" do
let(:merge_request) { build_stubbed(:merge_request) }
- context 'has ci' do
- it 'returns true if MR has head_pipeline_id and commits' do
+ context "has ci" do
+ it "returns true if MR has head_pipeline_id and commits" do
allow(merge_request).to receive_message_chain(:source_project, :ci_service) { nil }
allow(merge_request).to receive(:head_pipeline_id) { double }
allow(merge_request).to receive(:has_no_commits?) { false }
@@ -1244,7 +1244,7 @@ describe MergeRequest do
expect(merge_request.has_ci?).to be(true)
end
- it 'returns true if MR has any pipeline and commits' do
+ it "returns true if MR has any pipeline and commits" do
allow(merge_request).to receive_message_chain(:source_project, :ci_service) { nil }
allow(merge_request).to receive(:head_pipeline_id) { nil }
allow(merge_request).to receive(:has_no_commits?) { false }
@@ -1253,7 +1253,7 @@ describe MergeRequest do
expect(merge_request.has_ci?).to be(true)
end
- it 'returns true if MR has CI service and commits' do
+ it "returns true if MR has CI service and commits" do
allow(merge_request).to receive_message_chain(:source_project, :ci_service) { double }
allow(merge_request).to receive(:head_pipeline_id) { nil }
allow(merge_request).to receive(:has_no_commits?) { false }
@@ -1263,8 +1263,8 @@ describe MergeRequest do
end
end
- context 'has no ci' do
- it 'returns false if MR has no CI service nor pipeline, and no commits' do
+ context "has no ci" do
+ it "returns false if MR has no CI service nor pipeline, and no commits" do
allow(merge_request).to receive_message_chain(:source_project, :ci_service) { nil }
allow(merge_request).to receive(:head_pipeline_id) { nil }
allow(merge_request).to receive(:all_pipelines) { [] }
@@ -1275,77 +1275,77 @@ describe MergeRequest do
end
end
- describe '#all_pipelines' do
- shared_examples 'returning pipelines with proper ordering' do
+ describe "#all_pipelines" do
+ shared_examples "returning pipelines with proper ordering" do
let!(:all_pipelines) do
subject.all_commit_shas.map do |sha|
create(:ci_empty_pipeline,
- project: subject.source_project,
- sha: sha,
- ref: subject.source_branch)
+ project: subject.source_project,
+ sha: sha,
+ ref: subject.source_branch)
end
end
- it 'returns all pipelines' do
+ it "returns all pipelines" do
expect(subject.all_pipelines).not_to be_empty
expect(subject.all_pipelines).to eq(all_pipelines.reverse)
end
end
- context 'with single merge_request_diffs' do
- it_behaves_like 'returning pipelines with proper ordering'
+ context "with single merge_request_diffs" do
+ it_behaves_like "returning pipelines with proper ordering"
end
- context 'with multiple irrelevant merge_request_diffs' do
+ context "with multiple irrelevant merge_request_diffs" do
before do
- subject.update(target_branch: 'v1.0.0')
+ subject.update(target_branch: "v1.0.0")
end
- it_behaves_like 'returning pipelines with proper ordering'
+ it_behaves_like "returning pipelines with proper ordering"
end
- context 'with unsaved merge request' do
+ context "with unsaved merge request" do
subject { build(:merge_request) }
let!(:pipeline) do
create(:ci_empty_pipeline,
- project: subject.project,
- sha: subject.diff_head_sha,
- ref: subject.source_branch)
+ project: subject.project,
+ sha: subject.diff_head_sha,
+ ref: subject.source_branch)
end
- it 'returns pipelines from diff_head_sha' do
+ it "returns pipelines from diff_head_sha" do
expect(subject.all_pipelines).to contain_exactly(pipeline)
end
end
- context 'when pipelines exist for the branch and merge request' do
- let(:source_ref) { 'feature' }
- let(:target_ref) { 'master' }
+ context "when pipelines exist for the branch and merge request" do
+ let(:source_ref) { "feature" }
+ let(:target_ref) { "master" }
let!(:branch_pipeline) do
create(:ci_pipeline,
- source: :push,
- project: project,
- ref: source_ref,
- sha: shas.second)
+ source: :push,
+ project: project,
+ ref: source_ref,
+ sha: shas.second)
end
let!(:merge_request_pipeline) do
create(:ci_pipeline,
- source: :merge_request,
- project: project,
- ref: source_ref,
- sha: shas.second,
- merge_request: merge_request)
+ source: :merge_request,
+ project: project,
+ ref: source_ref,
+ sha: shas.second,
+ merge_request: merge_request)
end
let(:merge_request) do
create(:merge_request,
- source_project: project,
- source_branch: source_ref,
- target_project: project,
- target_branch: target_ref)
+ source_project: project,
+ source_branch: source_ref,
+ target_project: project,
+ target_branch: target_ref)
end
let(:project) { create(:project, :repository) }
@@ -1355,114 +1355,114 @@ describe MergeRequest do
allow(merge_request).to receive(:all_commit_shas) { shas }
end
- it 'returns merge request pipeline first' do
+ it "returns merge request pipeline first" do
expect(merge_request.all_pipelines)
.to eq([merge_request_pipeline,
- branch_pipeline])
+ branch_pipeline,])
end
- context 'when there are a branch pipeline and a merge request pipeline' do
+ context "when there are a branch pipeline and a merge request pipeline" do
let!(:branch_pipeline_2) do
create(:ci_pipeline,
- source: :push,
- project: project,
- ref: source_ref,
- sha: shas.first)
+ source: :push,
+ project: project,
+ ref: source_ref,
+ sha: shas.first)
end
let!(:merge_request_pipeline_2) do
create(:ci_pipeline,
- source: :merge_request,
- project: project,
- ref: source_ref,
- sha: shas.first,
- merge_request: merge_request)
+ source: :merge_request,
+ project: project,
+ ref: source_ref,
+ sha: shas.first,
+ merge_request: merge_request)
end
- it 'returns merge request pipelines first' do
+ it "returns merge request pipelines first" do
expect(merge_request.all_pipelines)
.to eq([merge_request_pipeline_2,
merge_request_pipeline,
branch_pipeline_2,
- branch_pipeline])
+ branch_pipeline,])
end
end
- context 'when there are multiple merge request pipelines from the same branch' do
+ context "when there are multiple merge request pipelines from the same branch" do
let!(:branch_pipeline_2) do
create(:ci_pipeline,
- source: :push,
- project: project,
- ref: source_ref,
- sha: shas.first)
+ source: :push,
+ project: project,
+ ref: source_ref,
+ sha: shas.first)
end
let!(:merge_request_pipeline_2) do
create(:ci_pipeline,
- source: :merge_request,
- project: project,
- ref: source_ref,
- sha: shas.first,
- merge_request: merge_request_2)
+ source: :merge_request,
+ project: project,
+ ref: source_ref,
+ sha: shas.first,
+ merge_request: merge_request_2)
end
let(:merge_request_2) do
create(:merge_request,
- source_project: project,
- source_branch: source_ref,
- target_project: project,
- target_branch: 'stable')
+ source_project: project,
+ source_branch: source_ref,
+ target_project: project,
+ target_branch: "stable")
end
before do
allow(merge_request_2).to receive(:all_commit_shas) { shas }
end
- it 'returns only related merge request pipelines' do
+ it "returns only related merge request pipelines" do
expect(merge_request.all_pipelines)
.to eq([merge_request_pipeline,
branch_pipeline_2,
- branch_pipeline])
+ branch_pipeline,])
expect(merge_request_2.all_pipelines)
.to eq([merge_request_pipeline_2,
branch_pipeline_2,
- branch_pipeline])
+ branch_pipeline,])
end
end
end
end
- describe '#update_head_pipeline' do
+ describe "#update_head_pipeline" do
subject { merge_request.update_head_pipeline }
let(:merge_request) { create(:merge_request) }
- context 'when there is a pipeline with the diff head sha' do
+ context "when there is a pipeline with the diff head sha" do
let!(:pipeline) do
create(:ci_empty_pipeline,
- project: merge_request.project,
- sha: merge_request.diff_head_sha,
- ref: merge_request.source_branch)
+ project: merge_request.project,
+ sha: merge_request.diff_head_sha,
+ ref: merge_request.source_branch)
end
- it 'updates the head pipeline' do
+ it "updates the head pipeline" do
expect { subject }
.to change { merge_request.reload.head_pipeline }
.from(nil).to(pipeline)
end
- context 'when merge request has already had head pipeline' do
+ context "when merge request has already had head pipeline" do
before do
merge_request.update!(head_pipeline: pipeline)
end
- context 'when failed to find an actual head pipeline' do
+ context "when failed to find an actual head pipeline" do
before do
allow(merge_request).to receive(:find_actual_head_pipeline) { }
end
- it 'does not update the current head pipeline' do
+ it "does not update the current head pipeline" do
expect { subject }
.not_to change { merge_request.reload.head_pipeline }
end
@@ -1470,49 +1470,49 @@ describe MergeRequest do
end
end
- context 'when there are no pipelines with the diff head sha' do
- it 'does not update the head pipeline' do
+ context "when there are no pipelines with the diff head sha" do
+ it "does not update the head pipeline" do
expect { subject }
.not_to change { merge_request.reload.head_pipeline }
end
end
end
- describe '#has_test_reports?' do
+ describe "#has_test_reports?" do
subject { merge_request.has_test_reports? }
let(:project) { create(:project, :repository) }
- context 'when head pipeline has test reports' do
+ context "when head pipeline has test reports" do
let(:merge_request) { create(:merge_request, :with_test_reports, source_project: project) }
it { is_expected.to be_truthy }
end
- context 'when head pipeline does not have test reports' do
+ context "when head pipeline does not have test reports" do
let(:merge_request) { create(:merge_request, source_project: project) }
it { is_expected.to be_falsey }
end
end
- describe '#calculate_reactive_cache' do
+ describe "#calculate_reactive_cache" do
let(:project) { create(:project, :repository) }
let(:merge_request) { create(:merge_request, source_project: project) }
subject { merge_request.calculate_reactive_cache(service_class_name) }
- context 'when given an unknown service class name' do
- let(:service_class_name) { 'Integer' }
+ context "when given an unknown service class name" do
+ let(:service_class_name) { "Integer" }
- it 'raises a NameError exception' do
+ it "raises a NameError exception" do
expect { subject }.to raise_error(NameError, service_class_name)
end
end
- context 'when given a known service class name' do
- let(:service_class_name) { 'Ci::CompareTestReportsService' }
+ context "when given a known service class name" do
+ let(:service_class_name) { "Ci::CompareTestReportsService" }
- it 'does not raises a NameError exception' do
+ it "does not raises a NameError exception" do
allow_any_instance_of(service_class_name.constantize).to receive(:execute).and_return(nil)
expect { subject }.not_to raise_error
@@ -1520,7 +1520,7 @@ describe MergeRequest do
end
end
- describe '#compare_test_reports' do
+ describe "#compare_test_reports" do
subject { merge_request.compare_test_reports }
let(:project) { create(:project, :repository) }
@@ -1528,176 +1528,176 @@ describe MergeRequest do
let!(:base_pipeline) do
create(:ci_pipeline,
- :with_test_reports,
- project: project,
- ref: merge_request.target_branch,
- sha: merge_request.diff_base_sha)
+ :with_test_reports,
+ project: project,
+ ref: merge_request.target_branch,
+ sha: merge_request.diff_base_sha)
end
before do
merge_request.update!(head_pipeline_id: head_pipeline.id)
end
- context 'when head pipeline has test reports' do
+ context "when head pipeline has test reports" do
let!(:head_pipeline) do
create(:ci_pipeline,
- :with_test_reports,
- project: project,
- ref: merge_request.source_branch,
- sha: merge_request.diff_head_sha)
+ :with_test_reports,
+ project: project,
+ ref: merge_request.source_branch,
+ sha: merge_request.diff_head_sha)
end
- context 'when reactive cache worker is parsing asynchronously' do
- it 'returns status' do
+ context "when reactive cache worker is parsing asynchronously" do
+ it "returns status" do
expect(subject[:status]).to eq(:parsing)
end
end
- context 'when reactive cache worker is inline' do
+ context "when reactive cache worker is inline" do
before do
synchronous_reactive_cache(merge_request)
end
- it 'returns status and data' do
+ it "returns status and data" do
expect_any_instance_of(Ci::CompareTestReportsService)
.to receive(:execute).with(base_pipeline, head_pipeline).and_call_original
subject
end
- context 'when cached results is not latest' do
+ context "when cached results is not latest" do
before do
allow_any_instance_of(Ci::CompareTestReportsService)
.to receive(:latest?).and_return(false)
end
- it 'raises and InvalidateReactiveCache error' do
+ it "raises and InvalidateReactiveCache error" do
expect { subject }.to raise_error(ReactiveCaching::InvalidateReactiveCache)
end
end
end
end
- context 'when head pipeline does not have test reports' do
+ context "when head pipeline does not have test reports" do
let!(:head_pipeline) do
create(:ci_pipeline,
- project: project,
- ref: merge_request.source_branch,
- sha: merge_request.diff_head_sha)
+ project: project,
+ ref: merge_request.source_branch,
+ sha: merge_request.diff_head_sha)
end
- it 'returns status and error message' do
+ it "returns status and error message" do
expect(subject[:status]).to eq(:error)
- expect(subject[:status_reason]).to eq('This merge request does not have test reports')
+ expect(subject[:status_reason]).to eq("This merge request does not have test reports")
end
end
end
- describe '#all_commit_shas' do
- context 'when merge request is persisted' do
+ describe "#all_commit_shas" do
+ context "when merge request is persisted" do
let(:all_commit_shas) do
subject.merge_request_diffs.flat_map(&:commits).map(&:sha).uniq
end
- shared_examples 'returning all SHA' do
- it 'returns all SHAs from all merge_request_diffs' do
+ shared_examples "returning all SHA" do
+ it "returns all SHAs from all merge_request_diffs" do
expect(subject.merge_request_diffs.size).to eq(2)
expect(subject.all_commit_shas).to match_array(all_commit_shas)
end
end
- context 'with a completely different branch' do
+ context "with a completely different branch" do
before do
- subject.update(target_branch: 'csv')
+ subject.update(target_branch: "csv")
end
- it_behaves_like 'returning all SHA'
+ it_behaves_like "returning all SHA"
end
- context 'with a branch having no difference' do
+ context "with a branch having no difference" do
before do
- subject.update(target_branch: 'branch-merged')
+ subject.update(target_branch: "branch-merged")
subject.reload # make sure commits were not cached
end
- it_behaves_like 'returning all SHA'
+ it_behaves_like "returning all SHA"
end
end
- context 'when merge request is not persisted' do
- context 'when compare commits are set in the service' do
- let(:commit) { spy('commit') }
+ context "when merge request is not persisted" do
+ context "when compare commits are set in the service" do
+ let(:commit) { spy("commit") }
subject do
build(:merge_request, compare_commits: [commit, commit])
end
- it 'returns commits from compare commits temporary data' do
+ it "returns commits from compare commits temporary data" do
expect(subject.all_commit_shas).to eq [commit, commit]
end
end
- context 'when compare commits are not set in the service' do
+ context "when compare commits are not set in the service" do
subject { build(:merge_request) }
- it 'returns array with diff head sha element only' do
+ it "returns array with diff head sha element only" do
expect(subject.all_commit_shas).to eq [subject.diff_head_sha]
end
end
end
end
- describe '#short_merge_commit_sha' do
+ describe "#short_merge_commit_sha" do
let(:merge_request) { build_stubbed(:merge_request) }
- it 'returns short id when there is a merge_commit_sha' do
- merge_request.merge_commit_sha = 'f7ce827c314c9340b075657fd61c789fb01cf74d'
+ it "returns short id when there is a merge_commit_sha" do
+ merge_request.merge_commit_sha = "f7ce827c314c9340b075657fd61c789fb01cf74d"
- expect(merge_request.short_merge_commit_sha).to eq('f7ce827c')
+ expect(merge_request.short_merge_commit_sha).to eq("f7ce827c")
end
- it 'returns nil when there is no merge_commit_sha' do
+ it "returns nil when there is no merge_commit_sha" do
merge_request.merge_commit_sha = nil
expect(merge_request.short_merge_commit_sha).to be_nil
end
end
- describe '#can_be_reverted?' do
- context 'when there is no merge_commit for the MR' do
+ describe "#can_be_reverted?" do
+ context "when there is no merge_commit for the MR" do
before do
subject.metrics.update!(merged_at: Time.now.utc)
end
- it 'returns false' do
+ it "returns false" do
expect(subject.can_be_reverted?(nil)).to be_falsey
end
end
- context 'when the MR has been merged' do
+ context "when the MR has been merged" do
before do
MergeRequests::MergeService
.new(subject.target_project, subject.author)
.execute(subject)
end
- context 'when there is no revert commit' do
- it 'returns true' do
+ context "when there is no revert commit" do
+ it "returns true" do
expect(subject.can_be_reverted?(nil)).to be_truthy
end
end
- context 'when there is no merged_at for the MR' do
+ context "when there is no merged_at for the MR" do
before do
subject.metrics.update!(merged_at: nil)
end
- it 'returns true' do
+ it "returns true" do
expect(subject.can_be_reverted?(nil)).to be_truthy
end
end
- context 'when there is a revert commit' do
+ context "when there is a revert commit" do
let(:current_user) { subject.author }
let(:branch) { subject.target_branch }
let(:project) { subject.target_project }
@@ -1706,7 +1706,7 @@ describe MergeRequest do
params = {
commit: subject.merge_commit,
branch_name: branch,
- start_branch: branch
+ start_branch: branch,
}
Commits::RevertService.new(project, current_user, params).execute[:result]
@@ -1716,53 +1716,53 @@ describe MergeRequest do
project.add_maintainer(current_user)
ProcessCommitWorker.new.perform(project.id,
- current_user.id,
- project.commit(revert_commit_id).to_hash,
- project.default_branch == branch)
+ current_user.id,
+ project.commit(revert_commit_id).to_hash,
+ project.default_branch == branch)
end
- context 'but merged at timestamp cannot be found' do
+ context "but merged at timestamp cannot be found" do
before do
allow(subject).to receive(:merged_at) { nil }
end
- it 'returns false' do
+ it "returns false" do
expect(subject.can_be_reverted?(current_user)).to be_falsey
end
end
- context 'when the revert commit is mentioned in a note after the MR was merged' do
- it 'returns false' do
+ context "when the revert commit is mentioned in a note after the MR was merged" do
+ it "returns false" do
expect(subject.can_be_reverted?(current_user)).to be_falsey
end
end
- context 'when there is no merged_at for the MR' do
+ context "when there is no merged_at for the MR" do
before do
subject.metrics.update!(merged_at: nil)
end
- it 'returns false' do
+ it "returns false" do
expect(subject.can_be_reverted?(current_user)).to be_falsey
end
end
- context 'when the revert commit is mentioned in a note just before the MR was merged' do
+ context "when the revert commit is mentioned in a note just before the MR was merged" do
before do
subject.notes.last.update!(created_at: subject.metrics.merged_at - 30.seconds)
end
- it 'returns false' do
+ it "returns false" do
expect(subject.can_be_reverted?(current_user)).to be_falsey
end
end
- context 'when the revert commit is mentioned in a note long before the MR was merged' do
+ context "when the revert commit is mentioned in a note long before the MR was merged" do
before do
subject.notes.last.update!(created_at: subject.metrics.merged_at - 2.minutes)
end
- it 'returns true' do
+ it "returns true" do
expect(subject.can_be_reverted?(current_user)).to be_truthy
end
end
@@ -1770,28 +1770,28 @@ describe MergeRequest do
end
end
- describe '#merged_at' do
- context 'when MR is not merged' do
+ describe "#merged_at" do
+ context "when MR is not merged" do
let(:merge_request) { create(:merge_request, :closed) }
- it 'returns nil' do
+ it "returns nil" do
expect(merge_request.merged_at).to be_nil
end
end
- context 'when metrics has merged_at data' do
+ context "when metrics has merged_at data" do
let(:merge_request) { create(:merge_request, :merged) }
before do
merge_request.metrics.update!(merged_at: 1.day.ago)
end
- it 'returns metrics merged_at' do
+ it "returns metrics merged_at" do
expect(merge_request.merged_at).to eq(merge_request.metrics.merged_at)
end
end
- context 'when merged event is persisted, but no metrics merged_at is persisted' do
+ context "when merged event is persisted, but no metrics merged_at is persisted" do
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request, :merged) }
@@ -1799,13 +1799,13 @@ describe MergeRequest do
EventCreateService.new.merge_mr(merge_request, user)
end
- it 'returns merged event creation date' do
+ it "returns merged event creation date" do
expect(merge_request.merge_event).to be_persisted
expect(merge_request.merged_at).to eq(merge_request.merge_event.created_at)
end
end
- context 'when merging note is persisted, but no metrics or merge event exists' do
+ context "when merging note is persisted, but no metrics or merge event exists" do
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request, :merged) }
@@ -1813,12 +1813,12 @@ describe MergeRequest do
merge_request.metrics.destroy!
SystemNoteService.change_status(merge_request,
- merge_request.target_project,
- user,
- merge_request.state, nil)
+ merge_request.target_project,
+ user,
+ merge_request.state, nil)
end
- it 'returns merging note creation date' do
+ it "returns merging note creation date" do
expect(merge_request.reload.metrics).to be_nil
expect(merge_request.merge_event).to be_nil
expect(merge_request.notes.count).to eq(1)
@@ -1827,7 +1827,7 @@ describe MergeRequest do
end
end
- describe '#participants' do
+ describe "#participants" do
let(:project) { create(:project, :public) }
let(:mr) do
@@ -1835,24 +1835,24 @@ describe MergeRequest do
end
let!(:note1) do
- create(:note_on_merge_request, noteable: mr, project: project, note: 'a')
+ create(:note_on_merge_request, noteable: mr, project: project, note: "a")
end
let!(:note2) do
- create(:note_on_merge_request, noteable: mr, project: project, note: 'b')
+ create(:note_on_merge_request, noteable: mr, project: project, note: "b")
end
- it 'includes the merge request author' do
+ it "includes the merge request author" do
expect(mr.participants).to include(mr.author)
end
- it 'includes the authors of the notes' do
+ it "includes the authors of the notes" do
expect(mr.participants).to include(note1.author, note2.author)
end
end
- describe 'cached counts' do
- it 'updates when assignees change' do
+ describe "cached counts" do
+ it "updates when assignees change" do
user1 = create(:user)
user2 = create(:user)
mr = create(:merge_request, assignee: user1)
@@ -1870,12 +1870,12 @@ describe MergeRequest do
end
end
- describe '#merge_async' do
- it 'enqueues MergeWorker job and updates merge_jid' do
+ describe "#merge_async" do
+ it "enqueues MergeWorker job and updates merge_jid" do
merge_request = create(:merge_request)
user_id = double(:user_id)
params = {}
- merge_jid = 'hash-123'
+ merge_jid = "hash-123"
expect(MergeWorker).to receive(:perform_async).with(merge_request.id, user_id, params) do
merge_jid
@@ -1887,69 +1887,69 @@ describe MergeRequest do
end
end
- describe '#check_if_can_be_merged' do
+ describe "#check_if_can_be_merged" do
let(:project) { create(:project, only_allow_merge_if_pipeline_succeeds: true) }
- shared_examples 'checking if can be merged' do
- context 'when it is not broken and has no conflicts' do
+ shared_examples "checking if can be merged" do
+ context "when it is not broken and has no conflicts" do
before do
allow(subject).to receive(:broken?) { false }
allow(project.repository).to receive(:can_be_merged?).and_return(true)
end
- it 'is marked as mergeable' do
- expect { subject.check_if_can_be_merged }.to change { subject.merge_status }.to('can_be_merged')
+ it "is marked as mergeable" do
+ expect { subject.check_if_can_be_merged }.to change { subject.merge_status }.to("can_be_merged")
end
end
- context 'when broken' do
+ context "when broken" do
before do
allow(subject).to receive(:broken?) { true }
allow(project.repository).to receive(:can_be_merged?).and_return(false)
end
- it 'becomes unmergeable' do
- expect { subject.check_if_can_be_merged }.to change { subject.merge_status }.to('cannot_be_merged')
+ it "becomes unmergeable" do
+ expect { subject.check_if_can_be_merged }.to change { subject.merge_status }.to("cannot_be_merged")
end
end
- context 'when it has conflicts' do
+ context "when it has conflicts" do
before do
allow(subject).to receive(:broken?) { false }
allow(project.repository).to receive(:can_be_merged?).and_return(false)
end
- it 'becomes unmergeable' do
- expect { subject.check_if_can_be_merged }.to change { subject.merge_status }.to('cannot_be_merged')
+ it "becomes unmergeable" do
+ expect { subject.check_if_can_be_merged }.to change { subject.merge_status }.to("cannot_be_merged")
end
end
end
- context 'when merge_status is unchecked' do
+ context "when merge_status is unchecked" do
subject { create(:merge_request, source_project: project, merge_status: :unchecked) }
- it_behaves_like 'checking if can be merged'
+ it_behaves_like "checking if can be merged"
end
- context 'when merge_status is unchecked' do
+ context "when merge_status is unchecked" do
subject { create(:merge_request, source_project: project, merge_status: :cannot_be_merged_recheck) }
- it_behaves_like 'checking if can be merged'
+ it_behaves_like "checking if can be merged"
end
end
- describe '#mergeable?' do
+ describe "#mergeable?" do
let(:project) { create(:project) }
subject { create(:merge_request, source_project: project) }
- it 'returns false if #mergeable_state? is false' do
+ it "returns false if #mergeable_state? is false" do
expect(subject).to receive(:mergeable_state?) { false }
expect(subject.mergeable?).to be_falsey
end
- it 'return true if #mergeable_state? is true and the MR #can_be_merged? is true' do
+ it "return true if #mergeable_state? is true and the MR #can_be_merged? is true" do
allow(subject).to receive(:mergeable_state?) { true }
expect(subject).to receive(:check_if_can_be_merged)
expect(subject).to receive(:can_be_merged?) { true }
@@ -1958,110 +1958,110 @@ describe MergeRequest do
end
end
- describe '#mergeable_state?' do
+ describe "#mergeable_state?" do
let(:project) { create(:project, :repository) }
subject { create(:merge_request, source_project: project) }
- it 'checks if merge request can be merged' do
+ it "checks if merge request can be merged" do
allow(subject).to receive(:mergeable_ci_state?) { true }
expect(subject).to receive(:check_if_can_be_merged)
subject.mergeable?
end
- context 'when not open' do
+ context "when not open" do
before do
subject.close
end
- it 'returns false' do
+ it "returns false" do
expect(subject.mergeable_state?).to be_falsey
end
end
- context 'when working in progress' do
+ context "when working in progress" do
before do
- subject.title = 'WIP MR'
+ subject.title = "WIP MR"
end
- it 'returns false' do
+ it "returns false" do
expect(subject.mergeable_state?).to be_falsey
end
end
- context 'when broken' do
+ context "when broken" do
before do
allow(subject).to receive(:broken?) { true }
end
- it 'returns false' do
+ it "returns false" do
expect(subject.mergeable_state?).to be_falsey
end
end
- context 'when failed' do
- context 'when #mergeable_ci_state? is false' do
+ context "when failed" do
+ context "when #mergeable_ci_state? is false" do
before do
allow(subject).to receive(:mergeable_ci_state?) { false }
end
- it 'returns false' do
+ it "returns false" do
expect(subject.mergeable_state?).to be_falsey
end
end
- context 'when #mergeable_discussions_state? is false' do
+ context "when #mergeable_discussions_state? is false" do
before do
allow(subject).to receive(:mergeable_discussions_state?) { false }
end
- it 'returns false' do
+ it "returns false" do
expect(subject.mergeable_state?).to be_falsey
end
- it 'returns true when skipping discussions check' do
+ it "returns true when skipping discussions check" do
expect(subject.mergeable_state?(skip_discussions_check: true)).to be(true)
end
end
end
end
- describe '#mergeable_ci_state?' do
+ describe "#mergeable_ci_state?" do
let(:project) { create(:project, only_allow_merge_if_pipeline_succeeds: true) }
let(:pipeline) { create(:ci_empty_pipeline) }
subject { build(:merge_request, target_project: project) }
- context 'when it is only allowed to merge when build is green' do
- context 'and a failed pipeline is associated' do
+ context "when it is only allowed to merge when build is green" do
+ context "and a failed pipeline is associated" do
before do
- pipeline.update(status: 'failed', sha: subject.diff_head_sha)
+ pipeline.update(status: "failed", sha: subject.diff_head_sha)
allow(subject).to receive(:head_pipeline) { pipeline }
end
it { expect(subject.mergeable_ci_state?).to be_falsey }
end
- context 'and a successful pipeline is associated' do
+ context "and a successful pipeline is associated" do
before do
- pipeline.update(status: 'success', sha: subject.diff_head_sha)
+ pipeline.update(status: "success", sha: subject.diff_head_sha)
allow(subject).to receive(:head_pipeline) { pipeline }
end
it { expect(subject.mergeable_ci_state?).to be_truthy }
end
- context 'and a skipped pipeline is associated' do
+ context "and a skipped pipeline is associated" do
before do
- pipeline.update(status: 'skipped', sha: subject.diff_head_sha)
+ pipeline.update(status: "skipped", sha: subject.diff_head_sha)
allow(subject).to receive(:head_pipeline) { pipeline }
end
it { expect(subject.mergeable_ci_state?).to be_truthy }
end
- context 'when no pipeline is associated' do
+ context "when no pipeline is associated" do
before do
allow(subject).to receive(:head_pipeline) { nil }
end
@@ -2070,19 +2070,19 @@ describe MergeRequest do
end
end
- context 'when merges are not restricted to green builds' do
+ context "when merges are not restricted to green builds" do
subject { build(:merge_request, target_project: build(:project, only_allow_merge_if_pipeline_succeeds: false)) }
- context 'and a failed pipeline is associated' do
+ context "and a failed pipeline is associated" do
before do
- pipeline.statuses << create(:commit_status, status: 'failed', project: project)
+ pipeline.statuses << create(:commit_status, status: "failed", project: project)
allow(subject).to receive(:head_pipeline) { pipeline }
end
it { expect(subject.mergeable_ci_state?).to be_truthy }
end
- context 'when no pipeline is associated' do
+ context "when no pipeline is associated" do
before do
allow(subject).to receive(:head_pipeline) { nil }
end
@@ -2092,52 +2092,52 @@ describe MergeRequest do
end
end
- describe '#mergeable_discussions_state?' do
+ describe "#mergeable_discussions_state?" do
let(:merge_request) { create(:merge_request_with_diff_notes, source_project: project) }
- context 'when project.only_allow_merge_if_all_discussions_are_resolved == true' do
+ context "when project.only_allow_merge_if_all_discussions_are_resolved == true" do
let(:project) { create(:project, :repository, only_allow_merge_if_all_discussions_are_resolved: true) }
- context 'with all discussions resolved' do
+ context "with all discussions resolved" do
before do
merge_request.discussions.each { |d| d.resolve!(merge_request.author) }
end
- it 'returns true' do
+ it "returns true" do
expect(merge_request.mergeable_discussions_state?).to be_truthy
end
end
- context 'with unresolved discussions' do
+ context "with unresolved discussions" do
before do
merge_request.discussions.each(&:unresolve!)
end
- it 'returns false' do
+ it "returns false" do
expect(merge_request.mergeable_discussions_state?).to be_falsey
end
end
- context 'with no discussions' do
+ context "with no discussions" do
before do
merge_request.notes.destroy_all # rubocop: disable DestroyAll
end
- it 'returns true' do
+ it "returns true" do
expect(merge_request.mergeable_discussions_state?).to be_truthy
end
end
end
- context 'when project.only_allow_merge_if_all_discussions_are_resolved == false' do
+ context "when project.only_allow_merge_if_all_discussions_are_resolved == false" do
let(:project) { create(:project, :repository, only_allow_merge_if_all_discussions_are_resolved: false) }
- context 'with unresolved discussions' do
+ context "with unresolved discussions" do
before do
merge_request.discussions.each(&:unresolve!)
end
- it 'returns true' do
+ it "returns true" do
expect(merge_request.mergeable_discussions_state?).to be_truthy
end
end
@@ -2154,64 +2154,64 @@ describe MergeRequest do
merge_request.target_project.add_maintainer(user)
end
- context 'with multiple environments' do
+ context "with multiple environments" do
let(:environments) { create_list(:environment, 3, project: project) }
before do
- create(:deployment, :success, environment: environments.first, ref: 'master', sha: project.commit('master').id)
- create(:deployment, :success, environment: environments.second, ref: 'feature', sha: project.commit('feature').id)
+ create(:deployment, :success, environment: environments.first, ref: "master", sha: project.commit("master").id)
+ create(:deployment, :success, environment: environments.second, ref: "feature", sha: project.commit("feature").id)
end
- it 'selects deployed environments' do
+ it "selects deployed environments" do
expect(merge_request.environments_for(user)).to contain_exactly(environments.first)
end
end
- context 'with environments on source project' do
+ context "with environments on source project" do
let(:source_project) { fork_project(project, nil, repository: true) }
let(:merge_request) do
create(:merge_request,
- source_project: source_project, source_branch: 'feature',
- target_project: project)
+ source_project: source_project, source_branch: "feature",
+ target_project: project)
end
let(:source_environment) { create(:environment, project: source_project) }
before do
- create(:deployment, :success, environment: source_environment, ref: 'feature', sha: merge_request.diff_head_sha)
+ create(:deployment, :success, environment: source_environment, ref: "feature", sha: merge_request.diff_head_sha)
end
- it 'selects deployed environments' do
+ it "selects deployed environments" do
expect(merge_request.environments_for(user)).to contain_exactly(source_environment)
end
- context 'with environments on target project' do
+ context "with environments on target project" do
let(:target_environment) { create(:environment, project: project) }
before do
create(:deployment, :success, environment: target_environment, tag: true, sha: merge_request.diff_head_sha)
end
- it 'selects deployed environments' do
+ it "selects deployed environments" do
expect(merge_request.environments_for(user)).to contain_exactly(source_environment, target_environment)
end
end
end
- context 'without a diff_head_commit' do
+ context "without a diff_head_commit" do
before do
expect(merge_request).to receive(:diff_head_commit).and_return(nil)
end
- it 'returns an empty array' do
+ it "returns an empty array" do
expect(merge_request.environments_for(user)).to be_empty
end
end
end
describe "#reload_diff" do
- it 'calls MergeRequests::ReloadDiffsService#execute with correct params' do
+ it "calls MergeRequests::ReloadDiffsService#execute with correct params" do
user = create(:user)
service = instance_double(MergeRequests::ReloadDiffsService, execute: nil)
@@ -2224,9 +2224,9 @@ describe MergeRequest do
expect(service).to have_received(:execute)
end
- context 'when using the after_update hook to update' do
- context 'when the branches are updated' do
- it 'uses the new heads to generate the diff' do
+ context "when using the after_update hook to update" do
+ context "when the branches are updated" do
+ it "uses the new heads to generate the diff" do
expect { subject.update!(source_branch: subject.target_branch, target_branch: subject.source_branch) }
.to change { subject.merge_request_diff.start_commit_sha }
.and change { subject.merge_request_diff.head_commit_sha }
@@ -2235,7 +2235,7 @@ describe MergeRequest do
end
end
- describe '#update_diff_discussion_positions' do
+ describe "#update_diff_discussion_positions" do
let(:discussion) { create(:diff_note_on_merge_request, project: subject.project, noteable: subject).to_discussion }
let(:commit) { subject.project.commit(sample_commit.id) }
let(:old_diff_refs) { subject.diff_refs }
@@ -2270,14 +2270,14 @@ describe MergeRequest do
current_user: subject.author)
end
- context 'when resolve_outdated_diff_discussions is set' do
+ context "when resolve_outdated_diff_discussions is set" do
before do
discussion
subject.project.update!(resolve_outdated_diff_discussions: true)
end
- it 'calls MergeRequests::ResolvedDiscussionNotificationService' do
+ it "calls MergeRequests::ResolvedDiscussionNotificationService" do
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService)
.to receive(:execute).with(subject)
@@ -2288,19 +2288,19 @@ describe MergeRequest do
end
end
- describe '#branch_merge_base_commit' do
- context 'source and target branch exist' do
- it { expect(subject.branch_merge_base_commit.sha).to eq('ae73cb07c9eeaf35924a10f713b364d32b2dd34f') }
+ describe "#branch_merge_base_commit" do
+ context "source and target branch exist" do
+ it { expect(subject.branch_merge_base_commit.sha).to eq("ae73cb07c9eeaf35924a10f713b364d32b2dd34f") }
it { expect(subject.branch_merge_base_commit).to be_a(Commit) }
end
- context 'when the target branch does not exist' do
+ context "when the target branch does not exist" do
before do
subject.project.repository.rm_branch(subject.author, subject.target_branch)
subject.clear_memoized_shas
end
- it 'returns nil' do
+ it "returns nil" do
expect(subject.branch_merge_base_commit).to be_nil
end
end
@@ -2320,9 +2320,9 @@ describe MergeRequest do
it "returns expected diff_refs" do
expected_diff_refs = Gitlab::Diff::DiffRefs.new(
- base_sha: subject.merge_request_diff.base_commit_sha,
+ base_sha: subject.merge_request_diff.base_commit_sha,
start_sha: subject.merge_request_diff.start_commit_sha,
- head_sha: subject.merge_request_diff.head_commit_sha
+ head_sha: subject.merge_request_diff.head_commit_sha
)
expect(subject.diff_refs).to eq(expected_diff_refs)
@@ -2368,35 +2368,35 @@ describe MergeRequest do
end
end
- describe '#merge_ongoing?' do
- it 'returns true when the merge request is locked' do
+ describe "#merge_ongoing?" do
+ it "returns true when the merge request is locked" do
merge_request = build_stubbed(:merge_request, state: :locked)
expect(merge_request.merge_ongoing?).to be(true)
end
- it 'returns true when merge_id, MR is not merged and it has no running job' do
- merge_request = build_stubbed(:merge_request, state: :open, merge_jid: 'foo')
- allow(Gitlab::SidekiqStatus).to receive(:running?).with('foo') { true }
+ it "returns true when merge_id, MR is not merged and it has no running job" do
+ merge_request = build_stubbed(:merge_request, state: :open, merge_jid: "foo")
+ allow(Gitlab::SidekiqStatus).to receive(:running?).with("foo") { true }
expect(merge_request.merge_ongoing?).to be(true)
end
- it 'returns false when merge_jid is nil' do
+ it "returns false when merge_jid is nil" do
merge_request = build_stubbed(:merge_request, state: :open, merge_jid: nil)
expect(merge_request.merge_ongoing?).to be(false)
end
- it 'returns false if MR is merged' do
- merge_request = build_stubbed(:merge_request, state: :merged, merge_jid: 'foo')
+ it "returns false if MR is merged" do
+ merge_request = build_stubbed(:merge_request, state: :merged, merge_jid: "foo")
expect(merge_request.merge_ongoing?).to be(false)
end
- it 'returns false if there is no merge job running' do
- merge_request = build_stubbed(:merge_request, state: :open, merge_jid: 'foo')
- allow(Gitlab::SidekiqStatus).to receive(:running?).with('foo') { false }
+ it "returns false if there is no merge job running" do
+ merge_request = build_stubbed(:merge_request, state: :open, merge_jid: "foo")
+ allow(Gitlab::SidekiqStatus).to receive(:running?).with("foo") { false }
expect(merge_request.merge_ongoing?).to be(false)
end
@@ -2440,15 +2440,15 @@ describe MergeRequest do
end
end
- describe '#reopenable?' do
- context 'when the merge request is closed' do
- it 'returns true' do
+ describe "#reopenable?" do
+ context "when the merge request is closed" do
+ it "returns true" do
subject.close
expect(subject.reopenable?).to be_truthy
end
- context 'forked project' do
+ context "forked project" do
let(:project) { create(:project, :public) }
let(:user) { create(:user) }
let(:forked_project) { fork_project(project, user) }
@@ -2459,40 +2459,40 @@ describe MergeRequest do
target_project: project)
end
- it 'returns false if unforked' do
+ it "returns false if unforked" do
Projects::UnlinkForkService.new(forked_project, user).execute
expect(merge_request.reload.reopenable?).to be_falsey
end
- it 'returns false if the source project is deleted' do
+ it "returns false if the source project is deleted" do
Projects::DestroyService.new(forked_project, user).execute
expect(merge_request.reload.reopenable?).to be_falsey
end
- it 'returns false if the merge request is merged' do
- merge_request.update(state: 'merged')
+ it "returns false if the merge request is merged" do
+ merge_request.update(state: "merged")
expect(merge_request.reload.reopenable?).to be_falsey
end
end
end
- context 'when the merge request is opened' do
- it 'returns false' do
+ context "when the merge request is opened" do
+ it "returns false" do
expect(subject.reopenable?).to be_falsey
end
end
end
- describe '#mergeable_with_quick_action?' do
+ describe "#mergeable_with_quick_action?" do
def create_pipeline(status)
pipeline = create(:ci_pipeline_with_one_job,
project: project,
- ref: merge_request.source_branch,
- sha: merge_request.diff_head_sha,
- status: status,
+ ref: merge_request.source_branch,
+ sha: merge_request.diff_head_sha,
+ status: status,
head_pipeline_of: merge_request)
pipeline
@@ -2508,95 +2508,95 @@ describe MergeRequest do
project.add_developer(developer)
end
- context 'when autocomplete_precheck is set to true' do
- it 'is mergeable by developer' do
+ context "when autocomplete_precheck is set to true" do
+ it "is mergeable by developer" do
expect(merge_request.mergeable_with_quick_action?(developer, autocomplete_precheck: true)).to be_truthy
end
- it 'is not mergeable by normal user' do
+ it "is not mergeable by normal user" do
expect(merge_request.mergeable_with_quick_action?(user, autocomplete_precheck: true)).to be_falsey
end
end
- context 'when autocomplete_precheck is set to false' do
- it 'is mergeable by developer' do
+ context "when autocomplete_precheck is set to false" do
+ it "is mergeable by developer" do
expect(merge_request.mergeable_with_quick_action?(developer, last_diff_sha: mr_sha)).to be_truthy
end
- it 'is not mergeable by normal user' do
+ it "is not mergeable by normal user" do
expect(merge_request.mergeable_with_quick_action?(user, last_diff_sha: mr_sha)).to be_falsey
end
- context 'closed MR' do
+ context "closed MR" do
before do
merge_request.update_attribute(:state, :closed)
end
- it 'is not mergeable' do
+ it "is not mergeable" do
expect(merge_request.mergeable_with_quick_action?(developer, last_diff_sha: mr_sha)).to be_falsey
end
end
- context 'MR with WIP' do
+ context "MR with WIP" do
before do
- merge_request.update_attribute(:title, 'WIP: some MR')
+ merge_request.update_attribute(:title, "WIP: some MR")
end
- it 'is not mergeable' do
+ it "is not mergeable" do
expect(merge_request.mergeable_with_quick_action?(developer, last_diff_sha: mr_sha)).to be_falsey
end
end
- context 'sha differs from the MR diff_head_sha' do
- it 'is not mergeable' do
- expect(merge_request.mergeable_with_quick_action?(developer, last_diff_sha: 'some other sha')).to be_falsey
+ context "sha differs from the MR diff_head_sha" do
+ it "is not mergeable" do
+ expect(merge_request.mergeable_with_quick_action?(developer, last_diff_sha: "some other sha")).to be_falsey
end
end
- context 'sha is not provided' do
- it 'is not mergeable' do
+ context "sha is not provided" do
+ it "is not mergeable" do
expect(merge_request.mergeable_with_quick_action?(developer)).to be_falsey
end
end
- context 'with pipeline ok' do
+ context "with pipeline ok" do
before do
create_pipeline(:success)
end
- it 'is mergeable' do
+ it "is mergeable" do
expect(merge_request.mergeable_with_quick_action?(developer, last_diff_sha: mr_sha)).to be_truthy
end
end
- context 'with failing pipeline' do
+ context "with failing pipeline" do
before do
create_pipeline(:failed)
end
- it 'is not mergeable' do
+ it "is not mergeable" do
expect(merge_request.mergeable_with_quick_action?(developer, last_diff_sha: mr_sha)).to be_falsey
end
end
- context 'with running pipeline' do
+ context "with running pipeline" do
before do
create_pipeline(:running)
end
- it 'is mergeable' do
+ it "is mergeable" do
expect(merge_request.mergeable_with_quick_action?(developer, last_diff_sha: mr_sha)).to be_truthy
end
end
end
end
- describe '#base_pipeline' do
+ describe "#base_pipeline" do
let(:pipeline_arguments) do
{
project: project,
ref: merge_request.target_branch,
- sha: merge_request.diff_base_sha
+ sha: merge_request.diff_base_sha,
}
end
@@ -2605,54 +2605,54 @@ describe MergeRequest do
let!(:first_pipeline) { create(:ci_pipeline_without_jobs, pipeline_arguments) }
let!(:last_pipeline) { create(:ci_pipeline_without_jobs, pipeline_arguments) }
- let!(:last_pipeline_with_other_ref) { create(:ci_pipeline_without_jobs, pipeline_arguments.merge(ref: 'other')) }
+ let!(:last_pipeline_with_other_ref) { create(:ci_pipeline_without_jobs, pipeline_arguments.merge(ref: "other")) }
- it 'returns latest pipeline for the target branch' do
+ it "returns latest pipeline for the target branch" do
expect(merge_request.base_pipeline).to eq(last_pipeline)
end
end
- describe '#has_commits?' do
+ describe "#has_commits?" do
before do
allow(subject.merge_request_diff).to receive(:commits_count)
.and_return(2)
end
- it 'returns true when merge request diff has commits' do
+ it "returns true when merge request diff has commits" do
expect(subject.has_commits?).to be_truthy
end
end
- describe '#has_no_commits?' do
+ describe "#has_no_commits?" do
before do
allow(subject.merge_request_diff).to receive(:commits_count)
.and_return(0)
end
- it 'returns true when merge request diff has 0 commits' do
+ it "returns true when merge request diff has 0 commits" do
expect(subject.has_no_commits?).to be_truthy
end
end
- describe '#merge_request_diff_for' do
+ describe "#merge_request_diff_for" do
subject { create(:merge_request, importing: true) }
- let!(:merge_request_diff1) { subject.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
+ let!(:merge_request_diff1) { subject.merge_request_diffs.create(head_commit_sha: "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") }
let!(:merge_request_diff2) { subject.merge_request_diffs.create(head_commit_sha: nil) }
- let!(:merge_request_diff3) { subject.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
+ let!(:merge_request_diff3) { subject.merge_request_diffs.create(head_commit_sha: "5937ac0a7beb003549fc5fd26fc247adbce4a52e") }
- context 'with diff refs' do
- it 'returns the diffs' do
+ context "with diff refs" do
+ it "returns the diffs" do
expect(subject.merge_request_diff_for(merge_request_diff1.diff_refs)).to eq(merge_request_diff1)
end
end
- context 'with a commit SHA' do
- it 'returns the diffs' do
+ context "with a commit SHA" do
+ it "returns the diffs" do
expect(subject.merge_request_diff_for(merge_request_diff3.head_commit_sha)).to eq(merge_request_diff3)
end
end
- it 'runs a single query on the initial call, and none afterwards' do
+ it "runs a single query on the initial call, and none afterwards" do
expect { subject.merge_request_diff_for(merge_request_diff1.diff_refs) }
.not_to exceed_query_limit(1)
@@ -2664,40 +2664,40 @@ describe MergeRequest do
end
end
- describe '#version_params_for' do
+ describe "#version_params_for" do
subject { create(:merge_request, importing: true) }
let(:project) { subject.project }
- let!(:merge_request_diff1) { subject.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
+ let!(:merge_request_diff1) { subject.merge_request_diffs.create(head_commit_sha: "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") }
let!(:merge_request_diff2) { subject.merge_request_diffs.create(head_commit_sha: nil) }
- let!(:merge_request_diff3) { subject.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
+ let!(:merge_request_diff3) { subject.merge_request_diffs.create(head_commit_sha: "5937ac0a7beb003549fc5fd26fc247adbce4a52e") }
- context 'when the diff refs are for an older merge request version' do
+ context "when the diff refs are for an older merge request version" do
let(:diff_refs) { merge_request_diff1.diff_refs }
- it 'returns the diff ID for the version to show' do
+ it "returns the diff ID for the version to show" do
expect(subject.version_params_for(diff_refs)).to eq(diff_id: merge_request_diff1.id)
end
end
- context 'when the diff refs are for a comparison between merge request versions' do
+ context "when the diff refs are for a comparison between merge request versions" do
let(:diff_refs) { merge_request_diff3.compare_with(merge_request_diff1.head_commit_sha).diff_refs }
- it 'returns the diff ID and start sha of the versions to compare' do
+ it "returns the diff ID and start sha of the versions to compare" do
expect(subject.version_params_for(diff_refs)).to eq(diff_id: merge_request_diff3.id, start_sha: merge_request_diff1.head_commit_sha)
end
end
- context 'when the diff refs are not for a merge request version' do
+ context "when the diff refs are not for a merge request version" do
let(:diff_refs) { project.commit(sample_commit.id).diff_refs }
- it 'returns nil' do
+ it "returns nil" do
expect(subject.version_params_for(diff_refs)).to be_nil
end
end
end
- describe '#fetch_ref!' do
- it 'fetches the ref correctly' do
+ describe "#fetch_ref!" do
+ it "fetches the ref correctly" do
expect { subject.target_project.repository.delete_refs(subject.ref_path) }.not_to raise_error
subject.fetch_ref!
@@ -2705,8 +2705,8 @@ describe MergeRequest do
end
end
- describe 'removing a merge request' do
- it 'refreshes the number of open merge requests of the target project' do
+ describe "removing a merge request" do
+ it "refreshes the number of open merge requests of the target project" do
project = subject.target_project
expect { subject.destroy }
@@ -2714,15 +2714,15 @@ describe MergeRequest do
end
end
- it_behaves_like 'throttled touch' do
+ it_behaves_like "throttled touch" do
subject { create(:merge_request, updated_at: 1.hour.ago) }
end
- context 'state machine transitions' do
- describe '#unlock_mr' do
- subject { create(:merge_request, state: 'locked', merge_jid: 123) }
+ context "state machine transitions" do
+ describe "#unlock_mr" do
+ subject { create(:merge_request, state: "locked", merge_jid: 123) }
- it 'updates merge request head pipeline and sets merge_jid to nil' do
+ it "updates merge request head pipeline and sets merge_jid to nil" do
pipeline = create(:ci_empty_pipeline, project: subject.project, ref: subject.source_branch, sha: subject.source_branch_sha)
subject.unlock_mr
@@ -2733,7 +2733,7 @@ describe MergeRequest do
end
end
- describe 'transition to cannot_be_merged' do
+ describe "transition to cannot_be_merged" do
let(:notification_service) { double(:notification_service) }
let(:todo_service) { double(:todo_service) }
subject { create(:merge_request, state, merge_status: :unchecked) }
@@ -2749,7 +2749,7 @@ describe MergeRequest do
context state do
let(:state) { state }
- it 'notifies conflict, but does not notify again if rechecking still results in cannot_be_merged' do
+ it "notifies conflict, but does not notify again if rechecking still results in cannot_be_merged" do
expect(notification_service).to receive(:merge_request_unmergeable).with(subject).once
expect(todo_service).to receive(:merge_request_became_unmergeable).with(subject).once
@@ -2758,7 +2758,7 @@ describe MergeRequest do
subject.mark_as_unmergeable
end
- it 'notifies conflict, whenever newly unmergeable' do
+ it "notifies conflict, whenever newly unmergeable" do
expect(notification_service).to receive(:merge_request_unmergeable).with(subject).twice
expect(todo_service).to receive(:merge_request_became_unmergeable).with(subject).twice
@@ -2769,7 +2769,7 @@ describe MergeRequest do
subject.mark_as_unmergeable
end
- it 'does not notify whenever merge request is newly unmergeable due to other reasons' do
+ it "does not notify whenever merge request is newly unmergeable due to other reasons" do
allow(subject.project.repository).to receive(:can_be_merged?).and_return(true)
expect(notification_service).not_to receive(:merge_request_unmergeable)
@@ -2784,7 +2784,7 @@ describe MergeRequest do
let(:state) { state }
context state do
- it 'does not notify' do
+ it "does not notify" do
expect(notification_service).not_to receive(:merge_request_unmergeable)
expect(todo_service).not_to receive(:merge_request_became_unmergeable)
@@ -2793,14 +2793,14 @@ describe MergeRequest do
end
end
- context 'source branch is missing' do
- subject { create(:merge_request, :invalid, :opened, merge_status: :unchecked, target_branch: 'master') }
+ context "source branch is missing" do
+ subject { create(:merge_request, :invalid, :opened, merge_status: :unchecked, target_branch: "master") }
before do
allow(subject.project.repository).to receive(:can_be_merged?).and_call_original
end
- it 'does not raise error' do
+ it "does not raise error" do
expect(notification_service).not_to receive(:merge_request_unmergeable)
expect(todo_service).not_to receive(:merge_request_became_unmergeable)
@@ -2810,8 +2810,8 @@ describe MergeRequest do
end
end
- describe 'check_state?' do
- it 'indicates whether MR is still checking for mergeability' do
+ describe "check_state?" do
+ it "indicates whether MR is still checking for mergeability" do
state_machine = described_class.state_machines[:merge_status]
check_states = [:unchecked, :cannot_be_merged_recheck]
@@ -2826,18 +2826,18 @@ describe MergeRequest do
end
end
- describe '#should_be_rebased?' do
+ describe "#should_be_rebased?" do
let(:project) { create(:project, :repository) }
- it 'returns false for the same source and target branches' do
+ it "returns false for the same source and target branches" do
merge_request = create(:merge_request, source_project: project, target_project: project)
expect(merge_request.should_be_rebased?).to be_falsey
end
end
- describe '#rebase_in_progress?' do
- shared_examples 'checking whether a rebase is in progress' do
+ describe "#rebase_in_progress?" do
+ shared_examples "checking whether a rebase is in progress" do
let(:repo_path) do
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
subject.source_project.repository.path
@@ -2846,27 +2846,27 @@ describe MergeRequest do
let(:rebase_path) { File.join(repo_path, "gitlab-worktree", "rebase-#{subject.id}") }
before do
- system(*%W(#{Gitlab.config.git.bin_path} -C #{repo_path} worktree add --detach #{rebase_path} master))
+ system(Gitlab.config.git.bin_path.to_s, "-C", repo_path.to_s, "worktree", "add", "--detach", rebase_path.to_s, "master")
end
- it 'returns true when there is a current rebase directory' do
+ it "returns true when there is a current rebase directory" do
expect(subject.rebase_in_progress?).to be_truthy
end
- it 'returns false when there is no rebase directory' do
+ it "returns false when there is no rebase directory" do
FileUtils.rm_rf(rebase_path)
expect(subject.rebase_in_progress?).to be_falsey
end
- it 'returns false when the rebase directory has expired' do
+ it "returns false when the rebase directory has expired" do
time = 20.minutes.ago.to_time
File.utime(time, time, rebase_path)
expect(subject.rebase_in_progress?).to be_falsey
end
- it 'returns false when the source project has been removed' do
+ it "returns false when the source project has been removed" do
allow(subject).to receive(:source_project).and_return(nil)
expect(subject.rebase_in_progress?).to be_falsey
@@ -2874,96 +2874,96 @@ describe MergeRequest do
end
end
- describe '#allow_collaboration' do
+ describe "#allow_collaboration" do
let(:merge_request) do
- build(:merge_request, source_branch: 'fixes', allow_collaboration: true)
+ build(:merge_request, source_branch: "fixes", allow_collaboration: true)
end
- it 'is false when pushing by a maintainer is not possible' do
+ it "is false when pushing by a maintainer is not possible" do
expect(merge_request).to receive(:collaborative_push_possible?) { false }
expect(merge_request.allow_collaboration).to be_falsy
end
- it 'is true when pushing by a maintainer is possible' do
+ it "is true when pushing by a maintainer is possible" do
expect(merge_request).to receive(:collaborative_push_possible?) { true }
expect(merge_request.allow_collaboration).to be_truthy
end
end
- describe '#collaborative_push_possible?' do
+ describe "#collaborative_push_possible?" do
let(:merge_request) do
- build(:merge_request, source_branch: 'fixes')
+ build(:merge_request, source_branch: "fixes")
end
before do
allow(ProtectedBranch).to receive(:protected?) { false }
end
- it 'does not allow maintainer to push if the source project is the same as the target' do
+ it "does not allow maintainer to push if the source project is the same as the target" do
merge_request.target_project = merge_request.source_project = create(:project, :public)
expect(merge_request.collaborative_push_possible?).to be_falsy
end
- it 'allows maintainer to push when both source and target are public' do
+ it "allows maintainer to push when both source and target are public" do
merge_request.target_project = build(:project, :public)
merge_request.source_project = build(:project, :public)
expect(merge_request.collaborative_push_possible?).to be_truthy
end
- it 'is not available for protected branches' do
+ it "is not available for protected branches" do
merge_request.target_project = build(:project, :public)
merge_request.source_project = build(:project, :public)
expect(ProtectedBranch).to receive(:protected?)
- .with(merge_request.source_project, 'fixes')
- .and_return(true)
+ .with(merge_request.source_project, "fixes")
+ .and_return(true)
expect(merge_request.collaborative_push_possible?).to be_falsy
end
end
- describe '#includes_any_commits?' do
- it 'returns false' do
+ describe "#includes_any_commits?" do
+ it "returns false" do
expect(subject.includes_any_commits?([])).to be_falsey
end
- it 'returns false' do
+ it "returns false" do
expect(subject.includes_any_commits?([Gitlab::Git::BLANK_SHA])).to be_falsey
end
- it 'returns true' do
+ it "returns true" do
expect(subject.includes_any_commits?([subject.merge_request_diff.head_commit_sha])).to be_truthy
end
- it 'returns true even when there is a non-existent comit' do
+ it "returns true even when there is a non-existent comit" do
expect(subject.includes_any_commits?([Gitlab::Git::BLANK_SHA, subject.merge_request_diff.head_commit_sha])).to be_truthy
end
- context 'unpersisted merge request' do
+ context "unpersisted merge request" do
let(:new_mr) { build(:merge_request) }
- it 'returns false' do
+ it "returns false" do
expect(new_mr.includes_any_commits?([Gitlab::Git::BLANK_SHA])).to be_falsey
end
- it 'returns true' do
+ it "returns true" do
expect(new_mr.includes_any_commits?([subject.merge_request_diff.head_commit_sha])).to be_truthy
end
end
end
- describe '#can_allow_collaboration?' do
+ describe "#can_allow_collaboration?" do
let(:target_project) { create(:project, :public) }
let(:source_project) { fork_project(target_project) }
let(:merge_request) do
create(:merge_request,
- source_project: source_project,
- source_branch: 'fixes',
- target_project: target_project)
+ source_project: source_project,
+ source_branch: "fixes",
+ target_project: target_project)
end
let(:user) { create(:user) }
@@ -2971,46 +2971,46 @@ describe MergeRequest do
allow(merge_request).to receive(:collaborative_push_possible?) { true }
end
- it 'is false if the user does not have push access to the source project' do
+ it "is false if the user does not have push access to the source project" do
expect(merge_request.can_allow_collaboration?(user)).to be_falsy
end
- it 'is true when the user has push access to the source project' do
+ it "is true when the user has push access to the source project" do
source_project.add_developer(user)
expect(merge_request.can_allow_collaboration?(user)).to be_truthy
end
end
- describe '#merge_participants' do
- it 'contains author' do
+ describe "#merge_participants" do
+ it "contains author" do
expect(subject.merge_participants).to eq([subject.author])
end
- describe 'when merge_when_pipeline_succeeds? is true' do
- describe 'when merge user is author' do
+ describe "when merge_when_pipeline_succeeds? is true" do
+ describe "when merge user is author" do
let(:user) { create(:user) }
subject do
create(:merge_request,
- merge_when_pipeline_succeeds: true,
- merge_user: user,
- author: user)
+ merge_when_pipeline_succeeds: true,
+ merge_user: user,
+ author: user)
end
- it 'contains author only' do
+ it "contains author only" do
expect(subject.merge_participants).to eq([subject.author])
end
end
- describe 'when merge user and author are different users' do
+ describe "when merge user and author are different users" do
let(:merge_user) { create(:user) }
subject do
create(:merge_request,
- merge_when_pipeline_succeeds: true,
- merge_user: merge_user)
+ merge_when_pipeline_succeeds: true,
+ merge_user: merge_user)
end
- it 'contains author and merge user' do
+ it "contains author and merge user" do
expect(subject.merge_participants).to eq([subject.author, merge_user])
end
end
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb
index af7e3d3a6c9..9b4caf010ae 100644
--- a/spec/models/milestone_spec.rb
+++ b/spec/models/milestone_spec.rb
@@ -1,23 +1,23 @@
-require 'spec_helper'
+require "spec_helper"
describe Milestone do
- describe 'modules' do
- context 'with a project' do
- it_behaves_like 'AtomicInternalId' do
+ describe "modules" do
+ context "with a project" do
+ it_behaves_like "AtomicInternalId" do
let(:internal_id_attribute) { :iid }
let(:instance) { build(:milestone, project: build(:project), group: nil) }
let(:scope) { :project }
- let(:scope_attrs) { { project: instance.project } }
+ let(:scope_attrs) { {project: instance.project} }
let(:usage) { :milestones }
end
end
- context 'with a group' do
- it_behaves_like 'AtomicInternalId' do
+ context "with a group" do
+ it_behaves_like "AtomicInternalId" do
let(:internal_id_attribute) { :iid }
let(:instance) { build(:milestone, project: nil, group: build(:group)) }
let(:scope) { :group }
- let(:scope_attrs) { { namespace: instance.group } }
+ let(:scope_attrs) { {namespace: instance.group} }
let(:usage) { :milestones }
end
end
@@ -28,8 +28,8 @@ describe Milestone do
allow(subject).to receive(:set_iid).and_return(false)
end
- describe 'start_date' do
- it 'adds an error when start_date is greated then due_date' do
+ describe "start_date" do
+ it "adds an error when start_date is greated then due_date" do
milestone = build(:milestone, start_date: Date.tomorrow, due_date: Date.yesterday)
expect(milestone).not_to be_valid
@@ -95,17 +95,17 @@ describe Milestone do
end
end
- describe '.order_by_name_asc' do
- it 'sorts by name ascending' do
- milestone1 = create(:milestone, title: 'Foo')
- milestone2 = create(:milestone, title: 'Bar')
+ describe ".order_by_name_asc" do
+ it "sorts by name ascending" do
+ milestone1 = create(:milestone, title: "Foo")
+ milestone2 = create(:milestone, title: "Bar")
expect(described_class.order_by_name_asc).to eq([milestone2, milestone1])
end
end
- describe '.reorder_by_due_date_asc' do
- it 'reorders the input relation' do
+ describe ".reorder_by_due_date_asc" do
+ it "reorders the input relation" do
milestone1 = create(:milestone, due_date: Date.new(2018, 9, 30))
milestone2 = create(:milestone, due_date: Date.new(2018, 10, 20))
@@ -130,13 +130,13 @@ describe Milestone do
end
end
- describe '#expired?' do
+ describe "#expired?" do
context "expired" do
before do
allow(milestone).to receive(:due_date).and_return(Date.today.prev_year)
end
- it 'returns true when due_date is in the past' do
+ it "returns true when due_date is in the past" do
expect(milestone.expired?).to be_truthy
end
end
@@ -146,25 +146,25 @@ describe Milestone do
allow(milestone).to receive(:due_date).and_return(Date.today.next_year)
end
- it 'returns false when due_date is in the future' do
+ it "returns false when due_date is in the future" do
expect(milestone.expired?).to be_falsey
end
end
end
- describe '#upcoming?' do
- it 'returns true when start_date is in the future' do
+ describe "#upcoming?" do
+ it "returns true when start_date is in the future" do
milestone = build(:milestone, start_date: Time.now + 1.month)
expect(milestone.upcoming?).to be_truthy
end
- it 'returns false when start_date is in the past' do
+ it "returns false when start_date is in the past" do
milestone = build(:milestone, start_date: Date.today.prev_year)
expect(milestone.upcoming?).to be_falsey
end
end
- describe '#percent_complete' do
+ describe "#percent_complete" do
before do
allow(milestone).to receive_messages(
closed_items_count: 3,
@@ -175,22 +175,22 @@ describe Milestone do
it { expect(milestone.percent_complete(user)).to eq(75) }
end
- describe '#can_be_closed?' do
+ describe "#can_be_closed?" do
it { expect(milestone.can_be_closed?).to be_truthy }
end
- describe '#total_items_count' do
+ describe "#total_items_count" do
before do
create :closed_issue, milestone: milestone, project: project
create :merge_request, milestone: milestone
end
- it 'returns total count of issues and merge requests assigned to milestone' do
+ it "returns total count of issues and merge requests assigned to milestone" do
expect(milestone.total_items_count(user)).to eq 2
end
end
- describe '#can_be_closed?' do
+ describe "#can_be_closed?" do
before do
milestone = create :milestone
create :closed_issue, milestone: milestone
@@ -198,11 +198,11 @@ describe Milestone do
create :issue
end
- it 'returns true if milestone active and all nested issues closed' do
+ it "returns true if milestone active and all nested issues closed" do
expect(milestone.can_be_closed?).to be_truthy
end
- it 'returns false if milestone active and not all nested issues closed' do
+ it "returns false if milestone active and not all nested issues closed" do
issue.milestone = milestone
issue.save
@@ -210,60 +210,60 @@ describe Milestone do
end
end
- describe '.search' do
- let(:milestone) { create(:milestone, title: 'foo', description: 'bar') }
+ describe ".search" do
+ let(:milestone) { create(:milestone, title: "foo", description: "bar") }
- it 'returns milestones with a matching title' do
+ it "returns milestones with a matching title" do
expect(described_class.search(milestone.title)).to eq([milestone])
end
- it 'returns milestones with a partially matching title' do
+ it "returns milestones with a partially matching title" do
expect(described_class.search(milestone.title[0..2])).to eq([milestone])
end
- it 'returns milestones with a matching title regardless of the casing' do
+ it "returns milestones with a matching title regardless of the casing" do
expect(described_class.search(milestone.title.upcase)).to eq([milestone])
end
- it 'returns milestones with a matching description' do
+ it "returns milestones with a matching description" do
expect(described_class.search(milestone.description)).to eq([milestone])
end
- it 'returns milestones with a partially matching description' do
+ it "returns milestones with a partially matching description" do
expect(described_class.search(milestone.description[0..2]))
.to eq([milestone])
end
- it 'returns milestones with a matching description regardless of the casing' do
+ it "returns milestones with a matching description regardless of the casing" do
expect(described_class.search(milestone.description.upcase))
.to eq([milestone])
end
end
- describe '#search_title' do
- let(:milestone) { create(:milestone, title: 'foo', description: 'bar') }
+ describe "#search_title" do
+ let(:milestone) { create(:milestone, title: "foo", description: "bar") }
- it 'returns milestones with a matching title' do
+ it "returns milestones with a matching title" do
expect(described_class.search_title(milestone.title)) .to eq([milestone])
end
- it 'returns milestones with a partially matching title' do
+ it "returns milestones with a partially matching title" do
expect(described_class.search_title(milestone.title[0..2])).to eq([milestone])
end
- it 'returns milestones with a matching title regardless of the casing' do
+ it "returns milestones with a matching title regardless of the casing" do
expect(described_class.search_title(milestone.title.upcase))
.to eq([milestone])
end
- it 'searches only on the title and ignores milestones with a matching description' do
- create(:milestone, title: 'bar', description: 'foo')
+ it "searches only on the title and ignores milestones with a matching description" do
+ create(:milestone, title: "bar", description: "foo")
expect(described_class.search_title(milestone.title)) .to eq([milestone])
end
end
- describe '#for_projects_and_groups' do
+ describe "#for_projects_and_groups" do
let(:project) { create(:project) }
let(:project_other) { create(:project) }
let(:group) { create(:group) }
@@ -278,22 +278,22 @@ describe Milestone do
subject { described_class.for_projects_and_groups(projects, groups) }
- shared_examples 'filters by projects and groups' do
- it 'returns milestones filtered by project' do
+ shared_examples "filters by projects and groups" do
+ it "returns milestones filtered by project" do
milestones = described_class.for_projects_and_groups(projects, [])
expect(milestones.count).to eq(1)
expect(milestones.first.project_id).to eq(project.id)
end
- it 'returns milestones filtered by group' do
+ it "returns milestones filtered by group" do
milestones = described_class.for_projects_and_groups([], groups)
expect(milestones.count).to eq(1)
expect(milestones.first.group_id).to eq(group.id)
end
- it 'returns milestones filtered by both project and group' do
+ it "returns milestones filtered by both project and group" do
milestones = described_class.for_projects_and_groups(projects, groups)
expect(milestones.count).to eq(2)
@@ -301,35 +301,35 @@ describe Milestone do
end
end
- context 'ids as params' do
+ context "ids as params" do
let(:projects) { [project.id] }
let(:groups) { [group.id] }
- it_behaves_like 'filters by projects and groups'
+ it_behaves_like "filters by projects and groups"
end
- context 'relations as params' do
+ context "relations as params" do
let(:projects) { Project.where(id: project.id).select(:id) }
let(:groups) { Group.where(id: group.id).select(:id) }
- it_behaves_like 'filters by projects and groups'
+ it_behaves_like "filters by projects and groups"
end
- context 'objects as params' do
+ context "objects as params" do
let(:projects) { [project] }
let(:groups) { [group] }
- it_behaves_like 'filters by projects and groups'
+ it_behaves_like "filters by projects and groups"
end
- it 'returns no records if projects and groups are nil' do
+ it "returns no records if projects and groups are nil" do
milestones = described_class.for_projects_and_groups(nil, nil)
expect(milestones).to be_empty
end
end
- describe '.upcoming_ids' do
+ describe ".upcoming_ids" do
let(:group_1) { create(:group) }
let(:group_2) { create(:group) }
let(:group_3) { create(:group) }
@@ -362,7 +362,7 @@ describe Milestone do
let(:milestone_ids) { described_class.upcoming_ids(projects, groups).map(&:id) }
- it 'returns the next upcoming open milestone ID for each project and group' do
+ it "returns the next upcoming open milestone ID for each project and group" do
expect(milestone_ids).to contain_exactly(
current_milestone_project_1.id,
current_milestone_project_2.id,
@@ -371,73 +371,73 @@ describe Milestone do
)
end
- context 'when the projects and groups have no open upcoming milestones' do
+ context "when the projects and groups have no open upcoming milestones" do
let(:projects) { [project_3] }
let(:groups) { [group_3] }
- it 'returns no results' do
+ it "returns no results" do
expect(milestone_ids).to be_empty
end
end
end
- describe '#to_reference' do
+ describe "#to_reference" do
let(:group) { build_stubbed(:group) }
- let(:project) { build_stubbed(:project, name: 'sample-project') }
- let(:another_project) { build_stubbed(:project, name: 'another-project', namespace: project.namespace) }
+ let(:project) { build_stubbed(:project, name: "sample-project") }
+ let(:another_project) { build_stubbed(:project, name: "another-project", namespace: project.namespace) }
- context 'for a project milestone' do
- let(:milestone) { build_stubbed(:milestone, iid: 1, project: project, name: 'milestone') }
+ context "for a project milestone" do
+ let(:milestone) { build_stubbed(:milestone, iid: 1, project: project, name: "milestone") }
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(milestone.to_reference).to eq '%"milestone"'
end
- it 'returns a reference by name when the format is set to :name' do
+ it "returns a reference by name when the format is set to :name" do
expect(milestone.to_reference(format: :name)).to eq '%"milestone"'
end
- it 'supports a cross-project reference' do
+ it "supports a cross-project reference" do
expect(milestone.to_reference(another_project)).to eq 'sample-project%"milestone"'
end
end
- context 'for a group milestone' do
- let(:milestone) { build_stubbed(:milestone, iid: 1, group: group, name: 'milestone') }
+ context "for a group milestone" do
+ let(:milestone) { build_stubbed(:milestone, iid: 1, group: group, name: "milestone") }
- it 'returns a group milestone reference with a default format' do
+ it "returns a group milestone reference with a default format" do
expect(milestone.to_reference).to eq '%"milestone"'
end
- it 'returns a reference by name when the format is set to :name' do
+ it "returns a reference by name when the format is set to :name" do
expect(milestone.to_reference(format: :name)).to eq '%"milestone"'
end
- it 'does supports cross-project references within a group' do
+ it "does supports cross-project references within a group" do
expect(milestone.to_reference(another_project, format: :name)).to eq '%"milestone"'
end
- it 'raises an error when using iid format' do
+ it "raises an error when using iid format" do
expect { milestone.to_reference(format: :iid) }
- .to raise_error(ArgumentError, 'Cannot refer to a group milestone by an internal id!')
+ .to raise_error(ArgumentError, "Cannot refer to a group milestone by an internal id!")
end
end
end
- describe '#reference_link_text' do
- let(:project) { build_stubbed(:project, name: 'sample-project') }
- let(:milestone) { build_stubbed(:milestone, iid: 1, project: project, name: 'milestone') }
+ describe "#reference_link_text" do
+ let(:project) { build_stubbed(:project, name: "sample-project") }
+ let(:milestone) { build_stubbed(:milestone, iid: 1, project: project, name: "milestone") }
- it 'returns the title with the reference prefix' do
- expect(milestone.reference_link_text).to eq '%milestone'
+ it "returns the title with the reference prefix" do
+ expect(milestone.reference_link_text).to eq "%milestone"
end
end
- describe '#participants' do
- let(:project) { build(:project, name: 'sample-project') }
+ describe "#participants" do
+ let(:project) { build(:project, name: "sample-project") }
let(:milestone) { build(:milestone, iid: 1, project: project) }
- it 'returns participants without duplicates' do
+ it "returns participants without duplicates" do
user = create :user
create :issue, project: project, milestone: milestone, assignees: [user]
create :issue, project: project, milestone: milestone, assignees: [user]
@@ -446,55 +446,55 @@ describe Milestone do
end
end
- describe '.sort_by_attribute' do
- set(:milestone_1) { create(:milestone, title: 'Foo') }
- set(:milestone_2) { create(:milestone, title: 'Bar') }
- set(:milestone_3) { create(:milestone, title: 'Zoo') }
+ describe ".sort_by_attribute" do
+ set(:milestone_1) { create(:milestone, title: "Foo") }
+ set(:milestone_2) { create(:milestone, title: "Bar") }
+ set(:milestone_3) { create(:milestone, title: "Zoo") }
- context 'ordering by name ascending' do
- it 'sorts by title ascending' do
- expect(described_class.sort_by_attribute('name_asc'))
+ context "ordering by name ascending" do
+ it "sorts by title ascending" do
+ expect(described_class.sort_by_attribute("name_asc"))
.to eq([milestone_2, milestone_1, milestone_3])
end
end
- context 'ordering by name descending' do
- it 'sorts by title descending' do
- expect(described_class.sort_by_attribute('name_desc'))
+ context "ordering by name descending" do
+ it "sorts by title descending" do
+ expect(described_class.sort_by_attribute("name_desc"))
.to eq([milestone_3, milestone_1, milestone_2])
end
end
end
- describe '.states_count' do
- context 'when the projects have milestones' do
+ describe ".states_count" do
+ context "when the projects have milestones" do
before do
project_1 = create(:project)
project_2 = create(:project)
group_1 = create(:group)
group_2 = create(:group)
- create(:active_milestone, title: 'Active Group Milestone', project: project_1)
- create(:closed_milestone, title: 'Closed Group Milestone', project: project_1)
- create(:active_milestone, title: 'Active Group Milestone', project: project_2)
- create(:closed_milestone, title: 'Closed Group Milestone', project: project_2)
- create(:closed_milestone, title: 'Active Group Milestone', group: group_1)
- create(:closed_milestone, title: 'Closed Group Milestone', group: group_1)
- create(:closed_milestone, title: 'Active Group Milestone', group: group_2)
- create(:closed_milestone, title: 'Closed Group Milestone', group: group_2)
+ create(:active_milestone, title: "Active Group Milestone", project: project_1)
+ create(:closed_milestone, title: "Closed Group Milestone", project: project_1)
+ create(:active_milestone, title: "Active Group Milestone", project: project_2)
+ create(:closed_milestone, title: "Closed Group Milestone", project: project_2)
+ create(:closed_milestone, title: "Active Group Milestone", group: group_1)
+ create(:closed_milestone, title: "Closed Group Milestone", group: group_1)
+ create(:closed_milestone, title: "Active Group Milestone", group: group_2)
+ create(:closed_milestone, title: "Closed Group Milestone", group: group_2)
end
- it 'returns the quantity of milestones in each possible state' do
- expected_count = { opened: 5, closed: 6, all: 11 }
+ it "returns the quantity of milestones in each possible state" do
+ expected_count = {opened: 5, closed: 6, all: 11}
count = described_class.states_count(Project.all, Group.all)
expect(count).to eq(expected_count)
end
end
- context 'when the projects do not have milestones' do
- it 'returns 0 as the quantity of global milestones in each state' do
- expected_count = { opened: 0, closed: 0, all: 0 }
+ context "when the projects do not have milestones" do
+ it "returns 0 as the quantity of global milestones in each state" do
+ expected_count = {opened: 0, closed: 0, all: 0}
count = described_class.states_count([project])
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 475fbe56e4d..8cc303f5894 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Namespace do
include ProjectForksHelper
@@ -6,16 +6,16 @@ describe Namespace do
let!(:namespace) { create(:namespace) }
let(:gitlab_shell) { Gitlab::Shell.new }
- let(:repository_storage) { 'default' }
+ let(:repository_storage) { "default" }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to have_many :projects }
it { is_expected.to have_many :project_statistics }
it { is_expected.to belong_to :parent }
it { is_expected.to have_many :children }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_most(255) }
it { is_expected.to validate_length_of(:description).is_at_most(255) }
@@ -23,25 +23,25 @@ describe Namespace do
it { is_expected.to validate_length_of(:path).is_at_most(255) }
it { is_expected.to validate_presence_of(:owner) }
- it 'does not allow too deep nesting' do
+ it "does not allow too deep nesting" do
ancestors = (1..21).to_a
nested = build(:namespace, parent: namespace)
allow(nested).to receive(:ancestors).and_return(ancestors)
expect(nested).not_to be_valid
- expect(nested.errors[:parent_id].first).to eq('has too deep level of nesting')
+ expect(nested.errors[:parent_id].first).to eq("has too deep level of nesting")
end
- describe 'reserved path validation' do
- context 'nested group' do
- let(:group) { build(:group, :nested, path: 'tree') }
+ describe "reserved path validation" do
+ context "nested group" do
+ let(:group) { build(:group, :nested, path: "tree") }
it { expect(group).not_to be_valid }
- it 'rejects nested paths' do
- parent = create(:group, :nested, path: 'environments')
- namespace = build(:group, path: 'folders', parent: parent)
+ it "rejects nested paths" do
+ parent = create(:group, :nested, path: "environments")
+ namespace = build(:group, path: "folders", parent: parent)
expect(namespace).not_to be_valid
end
@@ -53,8 +53,8 @@ describe Namespace do
it { expect(group).not_to be_valid }
end
- context 'top-level group' do
- let(:group) { build(:group, path: 'tree') }
+ context "top-level group" do
+ let(:group) { build(:group, path: "tree") }
it { expect(group).to be_valid }
end
@@ -67,23 +67,23 @@ describe Namespace do
it { is_expected.to respond_to(:has_parent?) }
end
- describe 'inclusions' do
+ describe "inclusions" do
it { is_expected.to include_module(Gitlab::VisibilityLevel) }
end
- describe '#visibility_level_field' do
+ describe "#visibility_level_field" do
it { expect(namespace.visibility_level_field).to eq(:visibility_level) }
end
- describe '#to_param' do
+ describe "#to_param" do
it { expect(namespace.to_param).to eq(namespace.full_path) }
end
- describe '#human_name' do
+ describe "#human_name" do
it { expect(namespace.human_name).to eq(namespace.owner_name) }
end
- describe '#first_project_with_container_registry_tags' do
+ describe "#first_project_with_container_registry_tags" do
let(:container_repository) { create(:container_repository) }
let!(:project) { create(:project, namespace: namespace, container_repositories: [container_repository]) }
@@ -91,68 +91,68 @@ describe Namespace do
stub_container_registry_config(enabled: true)
end
- it 'returns the project' do
- stub_container_registry_tags(repository: :any, tags: ['tag'])
+ it "returns the project" do
+ stub_container_registry_tags(repository: :any, tags: ["tag"])
expect(namespace.first_project_with_container_registry_tags).to eq(project)
end
- it 'returns no project' do
+ it "returns no project" do
stub_container_registry_tags(repository: :any, tags: nil)
expect(namespace.first_project_with_container_registry_tags).to be_nil
end
end
- describe '.search' do
+ describe ".search" do
let(:namespace) { create(:namespace) }
- it 'returns namespaces with a matching name' do
+ it "returns namespaces with a matching name" do
expect(described_class.search(namespace.name)).to eq([namespace])
end
- it 'returns namespaces with a partially matching name' do
+ it "returns namespaces with a partially matching name" do
expect(described_class.search(namespace.name[0..2])).to eq([namespace])
end
- it 'returns namespaces with a matching name regardless of the casing' do
+ it "returns namespaces with a matching name regardless of the casing" do
expect(described_class.search(namespace.name.upcase)).to eq([namespace])
end
- it 'returns namespaces with a matching path' do
+ it "returns namespaces with a matching path" do
expect(described_class.search(namespace.path)).to eq([namespace])
end
- it 'returns namespaces with a partially matching path' do
+ it "returns namespaces with a partially matching path" do
expect(described_class.search(namespace.path[0..2])).to eq([namespace])
end
- it 'returns namespaces with a matching path regardless of the casing' do
+ it "returns namespaces with a matching path regardless of the casing" do
expect(described_class.search(namespace.path.upcase)).to eq([namespace])
end
end
- describe '.with_statistics' do
+ describe ".with_statistics" do
let(:namespace) { create :namespace }
let(:project1) do
create(:project,
- namespace: namespace,
- statistics: build(:project_statistics,
- storage_size: 606,
- repository_size: 101,
- lfs_objects_size: 202,
- build_artifacts_size: 303))
+ namespace: namespace,
+ statistics: build(:project_statistics,
+ storage_size: 606,
+ repository_size: 101,
+ lfs_objects_size: 202,
+ build_artifacts_size: 303))
end
let(:project2) do
create(:project,
- namespace: namespace,
- statistics: build(:project_statistics,
- storage_size: 60,
- repository_size: 10,
- lfs_objects_size: 20,
- build_artifacts_size: 30))
+ namespace: namespace,
+ statistics: build(:project_statistics,
+ storage_size: 60,
+ repository_size: 10,
+ lfs_objects_size: 20,
+ build_artifacts_size: 30))
end
it "sums all project storage counters in the namespace" do
@@ -176,72 +176,72 @@ describe Namespace do
end
end
- describe '#ancestors_upto', :nested_groups do
+ describe "#ancestors_upto", :nested_groups do
let(:parent) { create(:group) }
let(:child) { create(:group, parent: parent) }
let(:child2) { create(:group, parent: child) }
- it 'returns all ancestors when no namespace is given' do
+ it "returns all ancestors when no namespace is given" do
expect(child2.ancestors_upto).to contain_exactly(child, parent)
end
- it 'includes ancestors upto but excluding the given ancestor' do
+ it "includes ancestors upto but excluding the given ancestor" do
expect(child2.ancestors_upto(parent)).to contain_exactly(child)
end
end
- describe '#move_dir', :request_store do
+ describe "#move_dir", :request_store do
shared_examples "namespace restrictions" do
context "when any project has container images" do
let(:container_repository) { create(:container_repository) }
before do
stub_container_registry_config(enabled: true)
- stub_container_registry_tags(repository: :any, tags: ['tag'])
+ stub_container_registry_tags(repository: :any, tags: ["tag"])
create(:project, namespace: namespace, container_repositories: [container_repository])
allow(namespace).to receive(:path_was).and_return(namespace.path)
- allow(namespace).to receive(:path).and_return('new_path')
+ allow(namespace).to receive(:path).and_return("new_path")
end
- it 'raises an error about not movable project' do
+ it "raises an error about not movable project" do
expect { namespace.move_dir }.to raise_error(Gitlab::UpdatePathError,
- /Namespace .* cannot be moved/)
+ /Namespace .* cannot be moved/)
end
end
end
- context 'legacy storage' do
+ context "legacy storage" do
let(:namespace) { create(:namespace) }
let!(:project) { create(:project_empty_repo, :legacy_storage, namespace: namespace) }
- it_behaves_like 'namespace restrictions'
+ it_behaves_like "namespace restrictions"
it "raises error when directory exists" do
expect { namespace.move_dir }.to raise_error("namespace directory cannot be moved")
end
it "moves dir if path changed" do
- namespace.update(path: namespace.full_path + '_new')
+ namespace.update(path: namespace.full_path + "_new")
expect(gitlab_shell.exists?(project.repository_storage, "#{namespace.path}/#{project.path}.git")).to be_truthy
end
- context 'when #write_projects_repository_config raises an error' do
- context 'in test environment' do
- it 'raises an exception' do
- expect(namespace).to receive(:write_projects_repository_config).and_raise('foo')
+ context "when #write_projects_repository_config raises an error" do
+ context "in test environment" do
+ it "raises an exception" do
+ expect(namespace).to receive(:write_projects_repository_config).and_raise("foo")
- expect do
- namespace.update(path: namespace.full_path + '_new')
- end.to raise_error('foo')
+ expect {
+ namespace.update(path: namespace.full_path + "_new")
+ }.to raise_error("foo")
end
end
- context 'in production environment' do
- it 'does not cancel later callbacks' do
- expect(namespace).to receive(:write_projects_repository_config).and_raise('foo')
+ context "in production environment" do
+ it "does not cancel later callbacks" do
+ expect(namespace).to receive(:write_projects_repository_config).and_raise("foo")
expect(namespace).to receive(:move_dir).and_wrap_original do |m, *args|
move_dir_result = m.call(*args)
@@ -251,23 +251,23 @@ describe Namespace do
end
expect(Gitlab::Sentry).to receive(:should_raise_for_dev?).and_return(false) # like prod
- namespace.update(path: namespace.full_path + '_new')
+ namespace.update(path: namespace.full_path + "_new")
end
end
end
- context 'with subgroups', :nested_groups do
- let(:parent) { create(:group, name: 'parent', path: 'parent') }
- let(:new_parent) { create(:group, name: 'new_parent', path: 'new_parent') }
- let(:child) { create(:group, name: 'child', path: 'child', parent: parent) }
- let!(:project) { create(:project_empty_repo, :legacy_storage, path: 'the-project', namespace: child, skip_disk_validation: true) }
+ context "with subgroups", :nested_groups do
+ let(:parent) { create(:group, name: "parent", path: "parent") }
+ let(:new_parent) { create(:group, name: "new_parent", path: "new_parent") }
+ let(:child) { create(:group, name: "child", path: "child", parent: parent) }
+ let!(:project) { create(:project_empty_repo, :legacy_storage, path: "the-project", namespace: child, skip_disk_validation: true) }
let(:uploads_dir) { FileUploader.root }
let(:pages_dir) { File.join(TestEnv.pages_path) }
def expect_project_directories_at(namespace_path)
- expected_repository_path = File.join(TestEnv.repos_path, namespace_path, 'the-project.git')
- expected_upload_path = File.join(uploads_dir, namespace_path, 'the-project')
- expected_pages_path = File.join(pages_dir, namespace_path, 'the-project')
+ expected_repository_path = File.join(TestEnv.repos_path, namespace_path, "the-project.git")
+ expected_upload_path = File.join(uploads_dir, namespace_path, "the-project")
+ expected_pages_path = File.join(pages_dir, namespace_path, "the-project")
expect(File.directory?(expected_repository_path)).to be_truthy
expect(File.directory?(expected_upload_path)).to be_truthy
@@ -280,84 +280,84 @@ describe Namespace do
FileUtils.mkdir_p(File.join(pages_dir, project.full_path))
end
- context 'renaming child' do
- it 'correctly moves the repository, uploads and pages' do
- child.update!(path: 'renamed')
+ context "renaming child" do
+ it "correctly moves the repository, uploads and pages" do
+ child.update!(path: "renamed")
- expect_project_directories_at('parent/renamed')
+ expect_project_directories_at("parent/renamed")
end
end
- context 'renaming parent' do
- it 'correctly moves the repository, uploads and pages' do
- parent.update!(path: 'renamed')
+ context "renaming parent" do
+ it "correctly moves the repository, uploads and pages" do
+ parent.update!(path: "renamed")
- expect_project_directories_at('renamed/child')
+ expect_project_directories_at("renamed/child")
end
end
- context 'moving from one parent to another' do
- it 'correctly moves the repository, uploads and pages' do
+ context "moving from one parent to another" do
+ it "correctly moves the repository, uploads and pages" do
child.update!(parent: new_parent)
- expect_project_directories_at('new_parent/child')
+ expect_project_directories_at("new_parent/child")
end
end
- context 'moving from having a parent to root' do
- it 'correctly moves the repository, uploads and pages' do
+ context "moving from having a parent to root" do
+ it "correctly moves the repository, uploads and pages" do
child.update!(parent: nil)
- expect_project_directories_at('child')
+ expect_project_directories_at("child")
end
end
- context 'moving from root to having a parent' do
- it 'correctly moves the repository, uploads and pages' do
+ context "moving from root to having a parent" do
+ it "correctly moves the repository, uploads and pages" do
parent.update!(parent: new_parent)
- expect_project_directories_at('new_parent/parent/child')
+ expect_project_directories_at("new_parent/parent/child")
end
end
end
end
- context 'hashed storage' do
+ context "hashed storage" do
let(:namespace) { create(:namespace) }
let!(:project) { create(:project_empty_repo, namespace: namespace) }
- it_behaves_like 'namespace restrictions'
+ it_behaves_like "namespace restrictions"
it "repository directory remains unchanged if path changed" do
before_disk_path = project.disk_path
- namespace.update(path: namespace.full_path + '_new')
+ namespace.update(path: namespace.full_path + "_new")
expect(before_disk_path).to eq(project.disk_path)
expect(gitlab_shell.exists?(project.repository_storage, "#{project.disk_path}.git")).to be_truthy
end
end
- context 'for each project inside the namespace' do
- let!(:parent) { create(:group, name: 'mygroup', path: 'mygroup') }
- let!(:subgroup) { create(:group, name: 'mysubgroup', path: 'mysubgroup', parent: parent) }
- let!(:project_in_parent_group) { create(:project, :legacy_storage, :repository, namespace: parent, name: 'foo1') }
- let!(:hashed_project_in_subgroup) { create(:project, :repository, namespace: subgroup, name: 'foo2') }
- let!(:legacy_project_in_subgroup) { create(:project, :legacy_storage, :repository, namespace: subgroup, name: 'foo3') }
+ context "for each project inside the namespace" do
+ let!(:parent) { create(:group, name: "mygroup", path: "mygroup") }
+ let!(:subgroup) { create(:group, name: "mysubgroup", path: "mysubgroup", parent: parent) }
+ let!(:project_in_parent_group) { create(:project, :legacy_storage, :repository, namespace: parent, name: "foo1") }
+ let!(:hashed_project_in_subgroup) { create(:project, :repository, namespace: subgroup, name: "foo2") }
+ let!(:legacy_project_in_subgroup) { create(:project, :legacy_storage, :repository, namespace: subgroup, name: "foo3") }
- it 'updates project full path in .git/config' do
- parent.update(path: 'mygroup_new')
+ it "updates project full path in .git/config" do
+ parent.update(path: "mygroup_new")
- expect(project_rugged(project_in_parent_group).config['gitlab.fullpath']).to eq "mygroup_new/#{project_in_parent_group.path}"
- expect(project_rugged(hashed_project_in_subgroup).config['gitlab.fullpath']).to eq "mygroup_new/mysubgroup/#{hashed_project_in_subgroup.path}"
- expect(project_rugged(legacy_project_in_subgroup).config['gitlab.fullpath']).to eq "mygroup_new/mysubgroup/#{legacy_project_in_subgroup.path}"
+ expect(project_rugged(project_in_parent_group).config["gitlab.fullpath"]).to eq "mygroup_new/#{project_in_parent_group.path}"
+ expect(project_rugged(hashed_project_in_subgroup).config["gitlab.fullpath"]).to eq "mygroup_new/mysubgroup/#{hashed_project_in_subgroup.path}"
+ expect(project_rugged(legacy_project_in_subgroup).config["gitlab.fullpath"]).to eq "mygroup_new/mysubgroup/#{legacy_project_in_subgroup.path}"
end
- it 'updates the project storage location' do
+ it "updates the project storage location" do
repository_project_in_parent_group = create(:project_repository, project: project_in_parent_group)
repository_hashed_project_in_subgroup = create(:project_repository, project: hashed_project_in_subgroup)
repository_legacy_project_in_subgroup = create(:project_repository, project: legacy_project_in_subgroup)
- parent.update(path: 'mygroup_moved')
+ parent.update(path: "mygroup_moved")
expect(repository_project_in_parent_group.reload.disk_path).to eq "mygroup_moved/#{project_in_parent_group.path}"
expect(repository_hashed_project_in_subgroup.reload.disk_path).to eq hashed_project_in_subgroup.disk_path
@@ -374,7 +374,7 @@ describe Namespace do
end
end
- describe '#rm_dir', 'callback' do
+ describe "#rm_dir", "callback" do
let(:repository_storage_path) do
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
Gitlab.config.repositories.storages.default.legacy_disk_path
@@ -384,10 +384,10 @@ describe Namespace do
let(:deleted_path) { namespace.full_path.gsub(namespace.path, "#{namespace.full_path}+#{namespace.id}+deleted") }
let(:deleted_path_in_dir) { File.join(repository_storage_path, deleted_path) }
- context 'legacy storage' do
+ context "legacy storage" do
let!(:project) { create(:project_empty_repo, :legacy_storage, namespace: namespace) }
- it 'renames its dirs when deleted' do
+ it "renames its dirs when deleted" do
allow(GitlabShellWorker).to receive(:perform_in)
namespace.destroy
@@ -395,21 +395,21 @@ describe Namespace do
expect(File.exist?(deleted_path_in_dir)).to be(true)
end
- it 'schedules the namespace for deletion' do
+ it "schedules the namespace for deletion" do
expect(GitlabShellWorker).to receive(:perform_in).with(5.minutes, :rm_namespace, repository_storage, deleted_path)
namespace.destroy
end
- context 'in sub-groups' do
- let(:parent) { create(:group, path: 'parent') }
- let(:child) { create(:group, parent: parent, path: 'child') }
+ context "in sub-groups" do
+ let(:parent) { create(:group, path: "parent") }
+ let(:child) { create(:group, parent: parent, path: "child") }
let!(:project) { create(:project_empty_repo, :legacy_storage, namespace: child) }
- let(:path_in_dir) { File.join(repository_storage_path, 'parent', 'child') }
- let(:deleted_path) { File.join('parent', "child+#{child.id}+deleted") }
+ let(:path_in_dir) { File.join(repository_storage_path, "parent", "child") }
+ let(:deleted_path) { File.join("parent", "child+#{child.id}+deleted") }
let(:deleted_path_in_dir) { File.join(repository_storage_path, deleted_path) }
- it 'renames its dirs when deleted' do
+ it "renames its dirs when deleted" do
allow(GitlabShellWorker).to receive(:perform_in)
child.destroy
@@ -417,7 +417,7 @@ describe Namespace do
expect(File.exist?(deleted_path_in_dir)).to be(true)
end
- it 'schedules the namespace for deletion' do
+ it "schedules the namespace for deletion" do
expect(GitlabShellWorker).to receive(:perform_in).with(5.minutes, :rm_namespace, repository_storage, deleted_path)
child.destroy
@@ -425,10 +425,10 @@ describe Namespace do
end
end
- context 'hashed storage' do
+ context "hashed storage" do
let!(:project) { create(:project_empty_repo, namespace: namespace) }
- it 'has no repositories base directories to remove' do
+ it "has no repositories base directories to remove" do
allow(GitlabShellWorker).to receive(:perform_in)
expect(File.exist?(path_in_dir)).to be(false)
@@ -440,14 +440,14 @@ describe Namespace do
end
end
- describe '.find_by_path_or_name' do
+ describe ".find_by_path_or_name" do
before do
- @namespace = create(:namespace, name: 'WoW', path: 'woW')
+ @namespace = create(:namespace, name: "WoW", path: "woW")
end
- it { expect(described_class.find_by_path_or_name('wow')).to eq(@namespace) }
- it { expect(described_class.find_by_path_or_name('WOW')).to eq(@namespace) }
- it { expect(described_class.find_by_path_or_name('unknown')).to eq(nil) }
+ it { expect(described_class.find_by_path_or_name("wow")).to eq(@namespace) }
+ it { expect(described_class.find_by_path_or_name("WOW")).to eq(@namespace) }
+ it { expect(described_class.find_by_path_or_name("unknown")).to eq(nil) }
end
describe ".clean_path" do
@@ -460,28 +460,28 @@ describe Namespace do
end
end
- describe '#self_and_hierarchy', :nested_groups do
- let!(:group) { create(:group, path: 'git_lab') }
+ describe "#self_and_hierarchy", :nested_groups do
+ let!(:group) { create(:group, path: "git_lab") }
let!(:nested_group) { create(:group, parent: group) }
let!(:deep_nested_group) { create(:group, parent: nested_group) }
let!(:very_deep_nested_group) { create(:group, parent: deep_nested_group) }
- let!(:another_group) { create(:group, path: 'gitllab') }
- let!(:another_group_nested) { create(:group, path: 'foo', parent: another_group) }
+ let!(:another_group) { create(:group, path: "gitllab") }
+ let!(:another_group_nested) { create(:group, path: "foo", parent: another_group) }
- it 'returns the correct tree' do
+ it "returns the correct tree" do
expect(group.self_and_hierarchy).to contain_exactly(group, nested_group, deep_nested_group, very_deep_nested_group)
expect(nested_group.self_and_hierarchy).to contain_exactly(group, nested_group, deep_nested_group, very_deep_nested_group)
expect(very_deep_nested_group.self_and_hierarchy).to contain_exactly(group, nested_group, deep_nested_group, very_deep_nested_group)
end
end
- describe '#ancestors', :nested_groups do
+ describe "#ancestors", :nested_groups do
let(:group) { create(:group) }
let(:nested_group) { create(:group, parent: group) }
let(:deep_nested_group) { create(:group, parent: nested_group) }
let(:very_deep_nested_group) { create(:group, parent: deep_nested_group) }
- it 'returns the correct ancestors' do
+ it "returns the correct ancestors" do
expect(very_deep_nested_group.ancestors).to include(group, nested_group, deep_nested_group)
expect(deep_nested_group.ancestors).to include(group, nested_group)
expect(nested_group.ancestors).to include(group)
@@ -489,13 +489,13 @@ describe Namespace do
end
end
- describe '#self_and_ancestors', :nested_groups do
+ describe "#self_and_ancestors", :nested_groups do
let(:group) { create(:group) }
let(:nested_group) { create(:group, parent: group) }
let(:deep_nested_group) { create(:group, parent: nested_group) }
let(:very_deep_nested_group) { create(:group, parent: deep_nested_group) }
- it 'returns the correct ancestors' do
+ it "returns the correct ancestors" do
expect(very_deep_nested_group.self_and_ancestors).to contain_exactly(group, nested_group, deep_nested_group, very_deep_nested_group)
expect(deep_nested_group.self_and_ancestors).to contain_exactly(group, nested_group, deep_nested_group)
expect(nested_group.self_and_ancestors).to contain_exactly(group, nested_group)
@@ -503,15 +503,15 @@ describe Namespace do
end
end
- describe '#descendants', :nested_groups do
- let!(:group) { create(:group, path: 'git_lab') }
+ describe "#descendants", :nested_groups do
+ let!(:group) { create(:group, path: "git_lab") }
let!(:nested_group) { create(:group, parent: group) }
let!(:deep_nested_group) { create(:group, parent: nested_group) }
let!(:very_deep_nested_group) { create(:group, parent: deep_nested_group) }
- let!(:another_group) { create(:group, path: 'gitllab') }
- let!(:another_group_nested) { create(:group, path: 'foo', parent: another_group) }
+ let!(:another_group) { create(:group, path: "gitllab") }
+ let!(:another_group_nested) { create(:group, path: "foo", parent: another_group) }
- it 'returns the correct descendants' do
+ it "returns the correct descendants" do
expect(very_deep_nested_group.descendants.to_a).to eq([])
expect(deep_nested_group.descendants.to_a).to include(very_deep_nested_group)
expect(nested_group.descendants.to_a).to include(deep_nested_group, very_deep_nested_group)
@@ -519,15 +519,15 @@ describe Namespace do
end
end
- describe '#self_and_descendants', :nested_groups do
- let!(:group) { create(:group, path: 'git_lab') }
+ describe "#self_and_descendants", :nested_groups do
+ let!(:group) { create(:group, path: "git_lab") }
let!(:nested_group) { create(:group, parent: group) }
let!(:deep_nested_group) { create(:group, parent: nested_group) }
let!(:very_deep_nested_group) { create(:group, parent: deep_nested_group) }
- let!(:another_group) { create(:group, path: 'gitllab') }
- let!(:another_group_nested) { create(:group, path: 'foo', parent: another_group) }
+ let!(:another_group) { create(:group, path: "gitllab") }
+ let!(:another_group_nested) { create(:group, path: "foo", parent: another_group) }
- it 'returns the correct descendants' do
+ it "returns the correct descendants" do
expect(very_deep_nested_group.self_and_descendants).to contain_exactly(very_deep_nested_group)
expect(deep_nested_group.self_and_descendants).to contain_exactly(deep_nested_group, very_deep_nested_group)
expect(nested_group.self_and_descendants).to contain_exactly(nested_group, deep_nested_group, very_deep_nested_group)
@@ -535,7 +535,7 @@ describe Namespace do
end
end
- describe '#users_with_descendants', :nested_groups do
+ describe "#users_with_descendants", :nested_groups do
let(:user_a) { create(:user) }
let(:user_b) { create(:user) }
@@ -543,7 +543,7 @@ describe Namespace do
let(:nested_group) { create(:group, parent: group) }
let(:deep_nested_group) { create(:group, parent: nested_group) }
- it 'returns member users on every nest level without duplication' do
+ it "returns member users on every nest level without duplication" do
group.add_developer(user_a)
nested_group.add_developer(user_b)
deep_nested_group.add_maintainer(user_a)
@@ -554,14 +554,14 @@ describe Namespace do
end
end
- describe '#user_ids_for_project_authorizations' do
- it 'returns the user IDs for which to refresh authorizations' do
+ describe "#user_ids_for_project_authorizations" do
+ it "returns the user IDs for which to refresh authorizations" do
expect(namespace.user_ids_for_project_authorizations)
.to eq([namespace.owner_id])
end
end
- describe '#all_projects' do
+ describe "#all_projects" do
let(:group) { create(:group) }
let(:child) { create(:group, parent: group) }
let!(:project1) { create(:project_empty_repo, namespace: group) }
@@ -571,7 +571,7 @@ describe Namespace do
it { expect(child.all_projects.to_a).to match_array([project2]) }
end
- describe '#all_pipelines' do
+ describe "#all_pipelines" do
let(:group) { create(:group) }
let(:child) { create(:group, parent: group) }
let!(:project1) { create(:project_empty_repo, namespace: group) }
@@ -582,9 +582,9 @@ describe Namespace do
it { expect(group.all_pipelines.to_a).to match_array([pipeline1, pipeline2]) }
end
- describe '#share_with_group_lock with subgroups', :nested_groups do
- context 'when creating a subgroup' do
- let(:subgroup) { create(:group, parent: root_group )}
+ describe "#share_with_group_lock with subgroups", :nested_groups do
+ context "when creating a subgroup" do
+ let(:subgroup) { create(:group, parent: root_group)}
context 'under a parent with "Share with group lock" enabled' do
let(:root_group) { create(:group, share_with_group_lock: true) }
@@ -605,7 +605,7 @@ describe Namespace do
context 'when enabling the parent group "Share with group lock"' do
let(:root_group) { create(:group) }
- let!(:subgroup) { create(:group, parent: root_group )}
+ let!(:subgroup) { create(:group, parent: root_group)}
it 'the subgroup "Share with group lock" becomes enabled' do
root_group.update!(share_with_group_lock: true)
@@ -618,7 +618,7 @@ describe Namespace do
let(:root_group) { create(:group, share_with_group_lock: true) }
context 'and the subgroup "Share with group lock" is enabled' do
- let(:subgroup) { create(:group, parent: root_group, share_with_group_lock: true )}
+ let(:subgroup) { create(:group, parent: root_group, share_with_group_lock: true)}
it 'the subgroup "Share with group lock" does not change' do
root_group.update!(share_with_group_lock: false)
@@ -628,7 +628,7 @@ describe Namespace do
end
context 'but the subgroup "Share with group lock" is disabled' do
- let(:subgroup) { create(:group, parent: root_group )}
+ let(:subgroup) { create(:group, parent: root_group)}
it 'the subgroup "Share with group lock" does not change' do
root_group.update!(share_with_group_lock: false)
@@ -638,12 +638,12 @@ describe Namespace do
end
end
- context 'when a group is transferred into a root group' do
+ context "when a group is transferred into a root group" do
context 'when the root group "Share with group lock" is enabled' do
let(:root_group) { create(:group, share_with_group_lock: true) }
context 'when the subgroup "Share with group lock" is enabled' do
- let(:subgroup) { create(:group, share_with_group_lock: true )}
+ let(:subgroup) { create(:group, share_with_group_lock: true)}
it 'the subgroup "Share with group lock" does not change' do
subgroup.parent = root_group
@@ -669,7 +669,7 @@ describe Namespace do
let(:root_group) { create(:group) }
context 'when the subgroup "Share with group lock" is enabled' do
- let(:subgroup) { create(:group, share_with_group_lock: true )}
+ let(:subgroup) { create(:group, share_with_group_lock: true)}
it 'the subgroup "Share with group lock" does not change' do
subgroup.parent = root_group
@@ -693,7 +693,7 @@ describe Namespace do
end
end
- describe '#find_fork_of?' do
+ describe "#find_fork_of?" do
let(:project) { create(:project, :public) }
let!(:forked_project) { fork_project(project, namespace.owner, namespace: namespace) }
@@ -702,19 +702,19 @@ describe Namespace do
project.reload
end
- it 'knows if there is a direct fork in the namespace' do
+ it "knows if there is a direct fork in the namespace" do
expect(namespace.find_fork_of(project)).to eq(forked_project)
end
- it 'knows when there is as fork-of-fork in the namespace' do
+ it "knows when there is as fork-of-fork in the namespace" do
other_namespace = create(:namespace)
other_fork = fork_project(forked_project, other_namespace.owner, namespace: other_namespace)
expect(other_namespace.find_fork_of(project)).to eq(other_fork)
end
- context 'with request store enabled', :request_store do
- it 'only queries once' do
+ context "with request store enabled", :request_store do
+ it "only queries once" do
expect(project.fork_network).to receive(:find_forks_in).once.and_call_original
2.times { namespace.find_fork_of(project) }
@@ -722,8 +722,8 @@ describe Namespace do
end
end
- describe '#root_ancestor' do
- it 'returns the top most ancestor', :nested_groups do
+ describe "#root_ancestor" do
+ it "returns the top most ancestor", :nested_groups do
root_group = create(:group)
nested_group = create(:group, parent: root_group)
deep_nested_group = create(:group, parent: nested_group)
@@ -736,27 +736,27 @@ describe Namespace do
end
end
- describe '#full_path_was' do
- context 'when the group has no parent' do
- it 'should return the path was' do
+ describe "#full_path_was" do
+ context "when the group has no parent" do
+ it "should return the path was" do
group = create(:group, parent: nil)
expect(group.full_path_was).to eq(group.path_was)
end
end
- context 'when a parent is assigned to a group with no previous parent' do
- it 'should return the path was' do
+ context "when a parent is assigned to a group with no previous parent" do
+ it "should return the path was" do
group = create(:group, parent: nil)
parent = create(:group)
group.parent = parent
- expect(group.full_path_was).to eq("#{group.path_was}")
+ expect(group.full_path_was).to eq(group.path_was.to_s)
end
end
- context 'when a parent is removed from the group' do
- it 'should return the parent full path' do
+ context "when a parent is removed from the group" do
+ it "should return the parent full path" do
parent = create(:group)
group = create(:group, parent: parent)
group.parent = nil
@@ -765,8 +765,8 @@ describe Namespace do
end
end
- context 'when changing parents' do
- it 'should return the previous parent full path' do
+ context "when changing parents" do
+ it "should return the previous parent full path" do
parent = create(:group)
group = create(:group, parent: parent)
new_parent = create(:group)
diff --git a/spec/models/network/graph_spec.rb b/spec/models/network/graph_spec.rb
index c364dd6643b..662ed252b5e 100644
--- a/spec/models/network/graph_spec.rb
+++ b/spec/models/network/graph_spec.rb
@@ -1,26 +1,26 @@
-require 'spec_helper'
+require "spec_helper"
describe Network::Graph do
let(:project) { create(:project, :repository) }
let!(:note_on_commit) { create(:note_on_commit, project: project) }
- it '#initialize' do
- graph = described_class.new(project, 'refs/heads/master', project.repository.commit, nil)
+ it "#initialize" do
+ graph = described_class.new(project, "refs/heads/master", project.repository.commit, nil)
- expect(graph.notes).to eq( { note_on_commit.commit_id => 1 } )
+ expect(graph.notes).to eq({note_on_commit.commit_id => 1})
end
- describe '#commits' do
- let(:graph) { described_class.new(project, 'refs/heads/master', project.repository.commit, nil) }
+ describe "#commits" do
+ let(:graph) { described_class.new(project, "refs/heads/master", project.repository.commit, nil) }
- it 'returns a list of commits' do
+ it "returns a list of commits" do
commits = graph.commits
expect(commits).not_to be_empty
- expect(commits).to all( be_kind_of(Network::Commit) )
+ expect(commits).to all(be_kind_of(Network::Commit))
end
- it 'it the commits by commit date (descending)' do
+ it "it the commits by commit date (descending)" do
# Remove duplicate timestamps because they make it harder to
# assert that the commits are sorted as expected.
commits = graph.commits.uniq(&:date)
@@ -30,7 +30,7 @@ describe Network::Graph do
expect(commits.map(&:id)).to eq(sorted_commits.map(&:id))
end
- it 'sorts children before parents for commits with the same timestamp' do
+ it "sorts children before parents for commits with the same timestamp" do
commits_by_time = graph.commits.group_by(&:date)
commits_by_time.each do |time, commits|
@@ -40,7 +40,7 @@ describe Network::Graph do
parent_indexes = commit.parent_ids.map { |parent_id| commit_ids.find_index(parent_id) }.compact
# All parents of the current commit should appear after it
- expect(parent_indexes).to all( be > index )
+ expect(parent_indexes).to all(be > index)
end
end
end
diff --git a/spec/models/note_diff_file_spec.rb b/spec/models/note_diff_file_spec.rb
index 591c1a89748..c3676041018 100644
--- a/spec/models/note_diff_file_spec.rb
+++ b/spec/models/note_diff_file_spec.rb
@@ -1,11 +1,11 @@
-require 'rails_helper'
+require "rails_helper"
describe NoteDiffFile do
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:diff_note) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:diff_note) }
end
end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 385b8a7959f..4e3e6477455 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -1,17 +1,17 @@
-require 'spec_helper'
+require "spec_helper"
describe Note do
include RepoHelpers
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:noteable).touch(false) }
- it { is_expected.to belong_to(:author).class_name('User') }
+ it { is_expected.to belong_to(:author).class_name("User") }
it { is_expected.to have_many(:todos) }
end
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Participable) }
@@ -19,11 +19,11 @@ describe Note do
it { is_expected.to include_module(Awardable) }
end
- describe 'validation' do
+ describe "validation" do
it { is_expected.to validate_presence_of(:note) }
it { is_expected.to validate_presence_of(:project) }
- context 'when note is on commit' do
+ context "when note is on commit" do
before do
allow(subject).to receive(:for_commit?).and_return(true)
end
@@ -32,7 +32,7 @@ describe Note do
it { is_expected.not_to validate_presence_of(:noteable_id) }
end
- context 'when note is not on commit' do
+ context "when note is not on commit" do
before do
allow(subject).to receive(:for_commit?).and_return(false)
end
@@ -41,7 +41,7 @@ describe Note do
it { is_expected.to validate_presence_of(:noteable_id) }
end
- context 'when noteable and note project differ' do
+ context "when noteable and note project differ" do
subject do
build(:note, noteable: build_stubbed(:issue),
project: build_stubbed(:project))
@@ -50,20 +50,20 @@ describe Note do
it { is_expected.to be_invalid }
end
- context 'when noteable and note project are the same' do
+ context "when noteable and note project are the same" do
subject { create(:note) }
it { is_expected.to be_valid }
end
- context 'when project is missing for a project related note' do
+ context "when project is missing for a project related note" do
subject { build(:note, project: nil, noteable: build_stubbed(:issue)) }
it { is_expected.to be_invalid }
end
- context 'when noteable is a personal snippet' do
+ context "when noteable is a personal snippet" do
subject { build(:note_on_personal_snippet) }
- it 'is valid without project' do
+ it "is valid without project" do
is_expected.to be_valid
end
end
@@ -92,7 +92,7 @@ describe Note do
expect(note.project.repository.kept_around?(commit.id)).to be_truthy
end
- it 'does not generate N+1 queries for participants', :request_store do
+ it "does not generate N+1 queries for participants", :request_store do
def retrieve_participants
commit.notes_with_associations.map(&:participants).to_a
end
@@ -100,17 +100,17 @@ describe Note do
# Project authorization checks are cached, establish a baseline
retrieve_participants
- control_count = ActiveRecord::QueryRecorder.new do
+ control_count = ActiveRecord::QueryRecorder.new {
retrieve_participants
- end
+ }
- create(:note_on_commit, project: note.project, note: 'another note', noteable_id: commit.id)
+ create(:note_on_commit, project: note.project, note: "another note", noteable_id: commit.id)
expect { retrieve_participants }.not_to exceed_query_limit(control_count)
end
end
- describe 'authorization' do
+ describe "authorization" do
before do
@p1 = create(:project)
@p2 = create(:project)
@@ -119,7 +119,7 @@ describe Note do
@u3 = create(:user)
end
- describe 'read' do
+ describe "read" do
before do
@p1.project_members.create(user: @u2, access_level: ProjectMember::GUEST)
@p2.project_members.create(user: @u3, access_level: ProjectMember::GUEST)
@@ -130,7 +130,7 @@ describe Note do
it { expect(Ability.allowed?(@u3, :read_note, @p1)).to be_falsey }
end
- describe 'write' do
+ describe "write" do
before do
@p1.project_members.create(user: @u2, access_level: ProjectMember::DEVELOPER)
@p2.project_members.create(user: @u3, access_level: ProjectMember::DEVELOPER)
@@ -141,7 +141,7 @@ describe Note do
it { expect(Ability.allowed?(@u3, :create_note, @p1)).to be_falsey }
end
- describe 'admin' do
+ describe "admin" do
before do
@p1.project_members.create(user: @u1, access_level: ProjectMember::REPORTER)
@p1.project_members.create(user: @u2, access_level: ProjectMember::MAINTAINER)
@@ -154,7 +154,7 @@ describe Note do
end
end
- it_behaves_like 'an editable mentionable' do
+ it_behaves_like "an editable mentionable" do
subject { create :note, noteable: issue, project: issue.project }
let(:issue) { create(:issue, project: create(:project, :repository)) }
@@ -175,8 +175,8 @@ describe Note do
pipeline: :note,
cache_key: [note1, "note"],
project: note1.project,
- author: note1.author
- }
+ author: note1.author,
+ },
}]).and_call_original
expect(Banzai::Renderer).to receive(:cache_collection_render)
@@ -187,8 +187,8 @@ describe Note do
pipeline: :note,
cache_key: [note2, "note"],
project: note2.project,
- author: note2.author
- }
+ author: note2.author,
+ },
}]).and_call_original
note1.all_references.users
@@ -288,19 +288,19 @@ describe Note do
end
end
- describe '#cross_reference?' do
- it 'falsey for user-generated notes' do
+ describe "#cross_reference?" do
+ it "falsey for user-generated notes" do
note = create(:note, system: false)
expect(note.cross_reference?).to be_falsy
end
- context 'when the note might contain cross references' do
+ context "when the note might contain cross references" do
SystemNoteMetadata.new.cross_reference_types.each do |type|
let(:note) { create(:note, :system) }
let!(:metadata) { create(:system_note_metadata, note: note, action: type) }
- it 'delegates to the cross-reference regex' do
+ it "delegates to the cross-reference regex" do
expect(note).to receive(:matches_cross_reference_regex?).and_return(false)
note.cross_reference?
@@ -308,27 +308,27 @@ describe Note do
end
end
- context 'when the note cannot contain cross references' do
- let(:commit_note) { build(:note, note: 'mentioned in 1312312313 something else.', system: true) }
- let(:label_note) { build(:note, note: 'added ~2323232323', system: true) }
+ context "when the note cannot contain cross references" do
+ let(:commit_note) { build(:note, note: "mentioned in 1312312313 something else.", system: true) }
+ let(:label_note) { build(:note, note: "added ~2323232323", system: true) }
- it 'scan for a `mentioned in` prefix' do
+ it "scan for a `mentioned in` prefix" do
expect(commit_note.cross_reference?).to be_truthy
expect(label_note.cross_reference?).to be_falsy
end
end
end
- describe 'clear_blank_line_code!' do
- it 'clears a blank line code before validation' do
- note = build(:note, line_code: ' ')
+ describe "clear_blank_line_code!" do
+ it "clears a blank line code before validation" do
+ note = build(:note, line_code: " ")
expect { note.valid? }.to change(note, :line_code).to(nil)
end
end
- describe '#participants' do
- it 'includes the note author' do
+ describe "#participants" do
+ it "includes the note author" do
project = create(:project, :public)
issue = create(:issue, project: project)
note = create(:note_on_issue, noteable: issue, project: project)
@@ -337,12 +337,12 @@ describe Note do
end
end
- describe '.find_discussion' do
+ describe ".find_discussion" do
let!(:note) { create(:discussion_note_on_merge_request) }
let!(:note2) { create(:discussion_note_on_merge_request, in_reply_to: note) }
let(:merge_request) { note.noteable }
- it 'returns a discussion with multiple notes' do
+ it "returns a discussion with multiple notes" do
discussion = merge_request.notes.find_discussion(note.discussion_id)
expect(discussion).not_to be_nil
@@ -380,7 +380,7 @@ describe Note do
)
end
- context 'active diff discussions' do
+ context "active diff discussions" do
subject { merge_request.notes.grouped_diff_discussions }
it "includes active discussions" do
@@ -403,7 +403,7 @@ describe Note do
expect(subject[active_diff_note3.line_code].first.id).to eq(active_diff_note3.discussion_id)
end
- context 'with image discussions' do
+ context "with image discussions" do
let(:merge_request2) { create(:merge_request_with_diffs, :with_image_diffs, source_project: project, title: "Added images and changes") }
let(:image_path) { "files/images/ee_repo_logo.png" }
let(:text_path) { "bar/branch-test.txt" }
@@ -454,10 +454,10 @@ describe Note do
end
end
- context 'diff discussions for older diff refs' do
+ context "diff discussions for older diff refs" do
subject { merge_request.notes.grouped_diff_discussions(diff_refs) }
- context 'for diff refs a discussion was created at' do
+ context "for diff refs a discussion was created at" do
let(:diff_refs) { active_position2.diff_refs }
it "includes discussions that were created then" do
@@ -480,7 +480,7 @@ describe Note do
end
end
- context 'for diff refs a discussion was last active at' do
+ context "for diff refs a discussion was last active at" do
let(:diff_refs) { outdated_position.diff_refs }
it "includes discussions that were last active" do
@@ -505,123 +505,123 @@ describe Note do
end
end
- describe '#for_personal_snippet?' do
- it 'returns false for a project snippet note' do
+ describe "#for_personal_snippet?" do
+ it "returns false for a project snippet note" do
expect(build(:note_on_project_snippet).for_personal_snippet?).to be_falsy
end
- it 'returns true for a personal snippet note' do
+ it "returns true for a personal snippet note" do
expect(build(:note_on_personal_snippet).for_personal_snippet?).to be_truthy
end
end
- describe '#to_ability_name' do
- it 'returns snippet for a project snippet note' do
- expect(build(:note_on_project_snippet).to_ability_name).to eq('project_snippet')
+ describe "#to_ability_name" do
+ it "returns snippet for a project snippet note" do
+ expect(build(:note_on_project_snippet).to_ability_name).to eq("project_snippet")
end
- it 'returns personal_snippet for a personal snippet note' do
- expect(build(:note_on_personal_snippet).to_ability_name).to eq('personal_snippet')
+ it "returns personal_snippet for a personal snippet note" do
+ expect(build(:note_on_personal_snippet).to_ability_name).to eq("personal_snippet")
end
- it 'returns merge_request for an MR note' do
- expect(build(:note_on_merge_request).to_ability_name).to eq('merge_request')
+ it "returns merge_request for an MR note" do
+ expect(build(:note_on_merge_request).to_ability_name).to eq("merge_request")
end
- it 'returns issue for an issue note' do
- expect(build(:note_on_issue).to_ability_name).to eq('issue')
+ it "returns issue for an issue note" do
+ expect(build(:note_on_issue).to_ability_name).to eq("issue")
end
- it 'returns issue for a commit note' do
- expect(build(:note_on_commit).to_ability_name).to eq('commit')
+ it "returns issue for a commit note" do
+ expect(build(:note_on_commit).to_ability_name).to eq("commit")
end
end
- describe '#cache_markdown_field' do
- let(:html) { '<p>some html</p>'}
+ describe "#cache_markdown_field" do
+ let(:html) { "<p>some html</p>"}
- context 'note for a project snippet' do
+ context "note for a project snippet" do
let(:note) { build(:note_on_project_snippet) }
before do
expect(Banzai::Renderer).to receive(:cacheless_render_field)
- .with(note, :note, { skip_project_check: false }).and_return(html)
+ .with(note, :note, {skip_project_check: false}).and_return(html)
note.save
end
- it 'creates a note' do
+ it "creates a note" do
expect(note.note_html).to eq(html)
end
end
- context 'note for a personal snippet' do
+ context "note for a personal snippet" do
let(:note) { build(:note_on_personal_snippet) }
before do
expect(Banzai::Renderer).to receive(:cacheless_render_field)
- .with(note, :note, { skip_project_check: true }).and_return(html)
+ .with(note, :note, {skip_project_check: true}).and_return(html)
note.save
end
- it 'creates a note' do
+ it "creates a note" do
expect(note.note_html).to eq(html)
end
end
end
- describe '#can_be_discussion_note?' do
- context 'for a note on a merge request' do
- it 'returns true' do
+ describe "#can_be_discussion_note?" do
+ context "for a note on a merge request" do
+ it "returns true" do
note = build(:note_on_merge_request)
expect(note.can_be_discussion_note?).to be_truthy
end
end
- context 'for a note on an issue' do
- it 'returns true' do
+ context "for a note on an issue" do
+ it "returns true" do
note = build(:note_on_issue)
expect(note.can_be_discussion_note?).to be_truthy
end
end
- context 'for a note on a commit' do
- it 'returns true' do
+ context "for a note on a commit" do
+ it "returns true" do
note = build(:note_on_commit)
expect(note.can_be_discussion_note?).to be_truthy
end
end
- context 'for a note on a snippet' do
- it 'returns true' do
+ context "for a note on a snippet" do
+ it "returns true" do
note = build(:note_on_project_snippet)
expect(note.can_be_discussion_note?).to be_truthy
end
end
- context 'for a diff note on merge request' do
- it 'returns false' do
+ context "for a diff note on merge request" do
+ it "returns false" do
note = build(:diff_note_on_merge_request)
expect(note.can_be_discussion_note?).to be_falsey
end
end
- context 'for a diff note on commit' do
- it 'returns false' do
+ context "for a diff note on commit" do
+ it "returns false" do
note = build(:diff_note_on_commit)
expect(note.can_be_discussion_note?).to be_falsey
end
end
- context 'for a discussion note' do
- it 'returns false' do
+ context "for a discussion note" do
+ it "returns false" do
note = build(:discussion_note_on_merge_request)
expect(note.can_be_discussion_note?).to be_falsey
@@ -629,18 +629,18 @@ describe Note do
end
end
- describe '#discussion_class' do
+ describe "#discussion_class" do
let(:note) { build(:note_on_commit) }
let(:merge_request) { create(:merge_request) }
- context 'when the note is displayed out of context' do
- it 'returns OutOfContextDiscussion' do
+ context "when the note is displayed out of context" do
+ it "returns OutOfContextDiscussion" do
expect(note.discussion_class(merge_request)).to be(OutOfContextDiscussion)
end
end
- context 'when the note is displayed in the original context' do
- it 'returns IndividualNoteDiscussion' do
+ context "when the note is displayed in the original context" do
+ it "returns IndividualNoteDiscussion" do
expect(note.discussion_class(note.noteable)).to be(IndividualNoteDiscussion)
end
end
@@ -670,16 +670,16 @@ describe Note do
end
end
- context 'when the note is displayed out of context' do
+ context "when the note is displayed out of context" do
let(:merge_request) { create(:merge_request) }
- it 'overrides the discussion id' do
+ it "overrides the discussion id" do
expect(note.discussion_id(merge_request)).not_to eq(note.discussion_id)
end
end
end
- describe '#to_discussion' do
+ describe "#to_discussion" do
subject { create(:discussion_note_on_merge_request) }
let!(:note2) { create(:discussion_note_on_merge_request, project: subject.project, noteable: subject.noteable, in_reply_to: subject) }
@@ -695,7 +695,7 @@ describe Note do
let!(:note1) { create(:discussion_note_on_merge_request) }
let!(:note2) { create(:diff_note_on_merge_request, project: note1.project, noteable: note1.noteable) }
- context 'when the note is part of a discussion' do
+ context "when the note is part of a discussion" do
subject { create(:discussion_note_on_merge_request, project: note1.project, noteable: note1.noteable, in_reply_to: note1) }
it "returns the discussion this note is in" do
@@ -706,7 +706,7 @@ describe Note do
end
end
- context 'when the note is not part of a discussion' do
+ context "when the note is not part of a discussion" do
subject { create(:note) }
it "returns a discussion with just this note" do
@@ -719,38 +719,38 @@ describe Note do
end
describe "#part_of_discussion?" do
- context 'for a regular note' do
+ context "for a regular note" do
let(:note) { build(:note) }
- it 'returns false' do
+ it "returns false" do
expect(note.part_of_discussion?).to be_falsey
end
end
- context 'for a diff note' do
+ context "for a diff note" do
let(:note) { build(:diff_note_on_commit) }
- it 'returns true' do
+ it "returns true" do
expect(note.part_of_discussion?).to be_truthy
end
end
- context 'for a discussion note' do
+ context "for a discussion note" do
let(:note) { build(:discussion_note_on_merge_request) }
- it 'returns true' do
+ it "returns true" do
expect(note.part_of_discussion?).to be_truthy
end
end
end
- describe '#in_reply_to?' do
- context 'for a note' do
- context 'when part of a discussion' do
+ describe "#in_reply_to?" do
+ context "for a note" do
+ context "when part of a discussion" do
subject { create(:discussion_note_on_issue) }
let(:note) { create(:discussion_note_on_issue, in_reply_to: subject) }
- it 'checks if the note is in reply to the other discussion' do
+ it "checks if the note is in reply to the other discussion" do
expect(subject).to receive(:in_reply_to?).with(note).and_call_original
expect(subject).to receive(:in_reply_to?).with(note.noteable).and_call_original
expect(subject).to receive(:in_reply_to?).with(note.to_discussion).and_call_original
@@ -759,11 +759,11 @@ describe Note do
end
end
- context 'when not part of a discussion' do
+ context "when not part of a discussion" do
subject { create(:note) }
let(:note) { create(:note, in_reply_to: subject) }
- it 'checks if the note is in reply to the other noteable' do
+ it "checks if the note is in reply to the other noteable" do
expect(subject).to receive(:in_reply_to?).with(note).and_call_original
expect(subject).to receive(:in_reply_to?).with(note.noteable).and_call_original
@@ -772,50 +772,50 @@ describe Note do
end
end
- context 'for a discussion' do
- context 'when part of the same discussion' do
+ context "for a discussion" do
+ context "when part of the same discussion" do
subject { create(:diff_note_on_merge_request) }
let(:note) { create(:diff_note_on_merge_request, in_reply_to: subject) }
- it 'returns true' do
+ it "returns true" do
expect(subject.in_reply_to?(note.to_discussion)).to be_truthy
end
end
- context 'when not part of the same discussion' do
+ context "when not part of the same discussion" do
subject { create(:diff_note_on_merge_request) }
let(:note) { create(:diff_note_on_merge_request) }
- it 'returns false' do
+ it "returns false" do
expect(subject.in_reply_to?(note.to_discussion)).to be_falsey
end
end
end
- context 'for a noteable' do
- context 'when a comment on the same noteable' do
+ context "for a noteable" do
+ context "when a comment on the same noteable" do
subject { create(:note) }
let(:note) { create(:note, in_reply_to: subject) }
- it 'returns true' do
+ it "returns true" do
expect(subject.in_reply_to?(note.noteable)).to be_truthy
end
end
- context 'when not a comment on the same noteable' do
+ context "when not a comment on the same noteable" do
subject { create(:note) }
let(:note) { create(:note) }
- it 'returns false' do
+ it "returns false" do
expect(subject.in_reply_to?(note.noteable)).to be_falsey
end
end
end
end
- describe '#references' do
- context 'when part of a discussion' do
- it 'references all earlier notes in the discussion' do
+ describe "#references" do
+ context "when part of a discussion" do
+ it "references all earlier notes in the discussion" do
first_note = create(:discussion_note_on_issue)
second_note = create(:discussion_note_on_issue, in_reply_to: first_note)
third_note = create(:discussion_note_on_issue, in_reply_to: second_note)
@@ -825,17 +825,17 @@ describe Note do
end
end
- context 'when not part of a discussion' do
+ context "when not part of a discussion" do
subject { create(:note) }
let(:note) { create(:note, in_reply_to: subject) }
- it 'returns the noteable' do
+ it "returns the noteable" do
expect(note.references).to eq([note.noteable])
end
end
end
- describe 'expiring ETag cache' do
+ describe "expiring ETag cache" do
let(:note) { build(:note_on_issue) }
def expect_expiration(note)
@@ -856,8 +856,8 @@ describe Note do
note.destroy!
end
- context 'when issuable etag caching is disabled' do
- it 'does not store cache key' do
+ context "when issuable etag caching is disabled" do
+ it "does not store cache key" do
allow(note.noteable).to receive(:etag_caching_enabled?).and_return(false)
expect_any_instance_of(Gitlab::EtagCaching::Store).not_to receive(:touch)
@@ -866,23 +866,23 @@ describe Note do
end
end
- describe '#with_notes_filter' do
+ describe "#with_notes_filter" do
let!(:comment) { create(:note) }
let!(:system_note) { create(:note, system: true) }
- context 'when notes filter is nil' do
+ context "when notes filter is nil" do
subject { described_class.with_notes_filter(nil) }
it { is_expected.to include(comment, system_note) }
end
- context 'when notes filter is set to all notes' do
+ context "when notes filter is set to all notes" do
subject { described_class.with_notes_filter(UserPreference::NOTES_FILTERS[:all_notes]) }
it { is_expected.to include(comment, system_note) }
end
- context 'when notes filter is set to only comments' do
+ context "when notes filter is set to only comments" do
subject { described_class.with_notes_filter(UserPreference::NOTES_FILTERS[:only_comments]) }
it { is_expected.to include(comment) }
@@ -891,15 +891,15 @@ describe Note do
end
end
- describe '#parent' do
- it 'returns project for project notes' do
+ describe "#parent" do
+ it "returns project for project notes" do
project = create(:project)
note = create(:note_on_issue, project: project)
expect(note.parent).to eq(project)
end
- it 'returns nil for personal snippet note' do
+ it "returns nil for personal snippet note" do
note = create(:note_on_personal_snippet)
expect(note.parent).to be_nil
diff --git a/spec/models/notification_recipient_spec.rb b/spec/models/notification_recipient_spec.rb
index 13fe47799ed..b06f4558099 100644
--- a/spec/models/notification_recipient_spec.rb
+++ b/spec/models/notification_recipient_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe NotificationRecipient do
let(:user) { create(:user) }
@@ -7,15 +7,15 @@ describe NotificationRecipient do
subject(:recipient) { described_class.new(user, :watch, target: target, project: project) }
- it 'denies access to a target when cross project access is denied' do
+ it "denies access to a target when cross project access is denied" do
allow(Ability).to receive(:allowed?).and_call_original
expect(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(false)
expect(recipient.has_access?).to be_falsy
end
- context '#notification_setting' do
- context 'for child groups', :nested_groups do
+ context "#notification_setting" do
+ context "for child groups", :nested_groups do
let!(:moved_group) { create(:group) }
let(:group) { create(:group) }
let(:sub_group_1) { create(:group, parent: group) }
@@ -30,7 +30,7 @@ describe NotificationRecipient do
moved_group.reload
end
- context 'when notification setting is global' do
+ context "when notification setting is global" do
before do
user.notification_settings_for(group).global!
user.notification_settings_for(sub_group_1).mention!
@@ -38,12 +38,12 @@ describe NotificationRecipient do
user.notification_settings_for(moved_group).global!
end
- it 'considers notification setting from the first parent without global setting' do
+ it "considers notification setting from the first parent without global setting" do
expect(subject.notification_setting.source).to eq(sub_group_1)
end
end
- context 'when notification setting is not global' do
+ context "when notification setting is not global" do
before do
user.notification_settings_for(group).global!
user.notification_settings_for(sub_group_1).mention!
@@ -51,7 +51,7 @@ describe NotificationRecipient do
user.notification_settings_for(moved_group).disabled!
end
- it 'considers notification setting from lowest group member in hierarchy' do
+ it "considers notification setting from lowest group member in hierarchy" do
expect(subject.notification_setting.source).to eq(moved_group)
end
end
diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb
index c8ab564e3bc..40bd5bd2313 100644
--- a/spec/models/notification_setting_spec.rb
+++ b/spec/models/notification_setting_spec.rb
@@ -1,7 +1,7 @@
-require 'rails_helper'
+require "rails_helper"
RSpec.describe NotificationSetting do
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
describe "Associations" do
it { is_expected.to belong_to(:user) }
@@ -9,12 +9,12 @@ RSpec.describe NotificationSetting do
end
describe "Validation" do
- subject { described_class.new(source_id: 1, source_type: 'Project') }
+ subject { described_class.new(source_id: 1, source_type: "Project") }
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_presence_of(:level) }
- describe 'user_id' do
+ describe "user_id" do
before do
subject.user = create(:user)
end
@@ -24,7 +24,7 @@ RSpec.describe NotificationSetting do
context "events" do
let(:user) { create(:user) }
- let(:notification_setting) { described_class.new(source_id: 1, source_type: 'Project', user_id: user.id) }
+ let(:notification_setting) { described_class.new(source_id: 1, source_type: "Project", user_id: user.id) }
before do
notification_setting.level = "custom"
@@ -48,7 +48,7 @@ RSpec.describe NotificationSetting do
end
end
- describe '#for_projects' do
+ describe "#for_projects" do
let(:user) { create(:user) }
before do
@@ -59,42 +59,42 @@ RSpec.describe NotificationSetting do
end
end
- it 'excludes projects pending delete' do
+ it "excludes projects pending delete" do
expect(user.notification_settings.for_projects).to all(have_attributes(project: an_instance_of(Project)))
expect(user.notification_settings.for_projects.map(&:project)).to all(have_attributes(pending_delete: false))
end
end
- describe '#event_enabled?' do
+ describe "#event_enabled?" do
before do
subject.update!(user: create(:user))
end
- context 'for an event with a matching column name' do
- it 'returns the value of the column' do
+ context "for an event with a matching column name" do
+ it "returns the value of the column" do
subject.update!(new_note: true)
expect(subject.event_enabled?(:new_note)).to be(true)
end
- context 'when the column has a nil value' do
- it 'returns false' do
+ context "when the column has a nil value" do
+ it "returns false" do
expect(subject.event_enabled?(:new_note)).to be(false)
end
end
end
- context 'for an event without a matching column name' do
- it 'returns false' do
+ context "for an event without a matching column name" do
+ it "returns false" do
expect(subject.event_enabled?(:foo_event)).to be(false)
end
end
end
- describe '.email_events' do
+ describe ".email_events" do
subject { described_class.email_events }
- it 'returns email events' do
+ it "returns email events" do
expect(subject).to include(
:new_note,
:new_issue,
@@ -111,17 +111,17 @@ RSpec.describe NotificationSetting do
)
end
- it 'includes EXCLUDED_WATCHER_EVENTS' do
+ it "includes EXCLUDED_WATCHER_EVENTS" do
expect(subject).to include(*described_class::EXCLUDED_WATCHER_EVENTS)
end
end
- describe '#email_events' do
+ describe "#email_events" do
let(:source) { build(:group) }
subject { build(:notification_setting, source: source) }
- it 'calls email_events' do
+ it "calls email_events" do
expect(described_class).to receive(:email_events).with(source)
subject.email_events
end
diff --git a/spec/models/pages_domain_spec.rb b/spec/models/pages_domain_spec.rb
index 4b85c5e8720..4c776e2e6d9 100644
--- a/spec/models/pages_domain_spec.rb
+++ b/spec/models/pages_domain_spec.rb
@@ -1,37 +1,37 @@
-require 'spec_helper'
+require "spec_helper"
describe PagesDomain do
using RSpec::Parameterized::TableSyntax
subject(:pages_domain) { described_class.new }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
end
- describe 'validate domain' do
+ describe "validate domain" do
subject(:pages_domain) { build(:pages_domain, domain: domain) }
- context 'is unique' do
- let(:domain) { 'my.domain.com' }
+ context "is unique" do
+ let(:domain) { "my.domain.com" }
it { is_expected.to validate_uniqueness_of(:domain).case_insensitive }
end
describe "hostname" do
{
- 'my.domain.com' => true,
- '123.456.789' => true,
- '0x12345.com' => true,
- '0123123' => true,
- '_foo.com' => false,
- 'reserved.com' => false,
- 'a.reserved.com' => false,
- nil => false
+ "my.domain.com" => true,
+ "123.456.789" => true,
+ "0x12345.com" => true,
+ "0123123" => true,
+ "_foo.com" => false,
+ "reserved.com" => false,
+ "a.reserved.com" => false,
+ nil => false,
}.each do |value, validity|
context "domain #{value.inspect} validity" do
before do
- allow(Settings.pages).to receive(:host).and_return('reserved.com')
+ allow(Settings.pages).to receive(:host).and_return("reserved.com")
end
let(:domain) { value }
@@ -44,7 +44,7 @@ describe PagesDomain do
describe "HTTPS-only" do
using RSpec::Parameterized::TableSyntax
- let(:domain) { 'my.domain.com' }
+ let(:domain) { "my.domain.com" }
let(:project) do
instance_double(Project, pages_https_only?: pages_https_only)
@@ -61,13 +61,13 @@ describe PagesDomain do
attributes = attributes_for(:pages_domain)
cert, key = attributes.fetch_values(:certificate, :key)
- true | nil | nil | %i(certificate key)
- true | cert | nil | %i(key)
- true | nil | key | %i(certificate key)
+ true | nil | nil | %i[certificate key]
+ true | cert | nil | %i[key]
+ true | nil | key | %i[certificate key]
true | cert | key | []
false | nil | nil | []
- false | cert | nil | %i(key)
- false | nil | key | %i(key)
+ false | cert | nil | %i[key]
+ false | nil | key | %i[key]
false | cert | key | []
end
@@ -79,110 +79,110 @@ describe PagesDomain do
end
end
- describe 'validate certificate' do
+ describe "validate certificate" do
subject { domain }
- context 'with matching key' do
+ context "with matching key" do
let(:domain) { build(:pages_domain) }
it { is_expected.to be_valid }
end
- context 'when no certificate is specified' do
+ context "when no certificate is specified" do
let(:domain) { build(:pages_domain, :without_certificate) }
it { is_expected.not_to be_valid }
end
- context 'when no key is specified' do
+ context "when no key is specified" do
let(:domain) { build(:pages_domain, :without_key) }
it { is_expected.not_to be_valid }
end
- context 'for not matching key' do
+ context "for not matching key" do
let(:domain) { build(:pages_domain, :with_missing_chain) }
it { is_expected.not_to be_valid }
end
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:verification_code) }
end
- describe '#verification_code' do
+ describe "#verification_code" do
subject { pages_domain.verification_code }
- it 'is set automatically with 128 bits of SecureRandom data' do
- expect(SecureRandom).to receive(:hex).with(16) { 'verification code' }
+ it "is set automatically with 128 bits of SecureRandom data" do
+ expect(SecureRandom).to receive(:hex).with(16) { "verification code" }
- is_expected.to eq('verification code')
+ is_expected.to eq("verification code")
end
end
- describe '#keyed_verification_code' do
+ describe "#keyed_verification_code" do
subject { pages_domain.keyed_verification_code }
it { is_expected.to eq("gitlab-pages-verification-code=#{pages_domain.verification_code}") }
end
- describe '#verification_domain' do
+ describe "#verification_domain" do
subject { pages_domain.verification_domain }
it { is_expected.to be_nil }
- it 'is a well-known subdomain if the domain is present' do
- pages_domain.domain = 'example.com'
+ it "is a well-known subdomain if the domain is present" do
+ pages_domain.domain = "example.com"
- is_expected.to eq('_gitlab-pages-verification-code.example.com')
+ is_expected.to eq("_gitlab-pages-verification-code.example.com")
end
end
- describe '#url' do
+ describe "#url" do
subject { domain.url }
let(:domain) { build(:pages_domain) }
it { is_expected.to eq("https://#{domain.domain}") }
- context 'without the certificate' do
+ context "without the certificate" do
let(:domain) { build(:pages_domain, :without_certificate) }
it { is_expected.to eq("http://#{domain.domain}") }
end
end
- describe '#has_matching_key?' do
+ describe "#has_matching_key?" do
subject { domain.has_matching_key? }
let(:domain) { build(:pages_domain) }
it { is_expected.to be_truthy }
- context 'for invalid key' do
+ context "for invalid key" do
let(:domain) { build(:pages_domain, :with_missing_chain) }
it { is_expected.to be_falsey }
end
end
- describe '#has_intermediates?' do
+ describe "#has_intermediates?" do
subject { domain.has_intermediates? }
- context 'for self signed' do
+ context "for self signed" do
let(:domain) { build(:pages_domain) }
it { is_expected.to be_truthy }
end
- context 'for missing certificate chain' do
+ context "for missing certificate chain" do
let(:domain) { build(:pages_domain, :with_missing_chain) }
it { is_expected.to be_falsey }
end
- context 'for trusted certificate chain' do
+ context "for trusted certificate chain" do
# We only validate that we can to rebuild the trust chain, for certificates
# We assume that 'AddTrustExternalCARoot' needed to validate the chain is in trusted store.
# It will be if ca-certificates is installed on Debian/Ubuntu/Alpine
@@ -193,31 +193,31 @@ describe PagesDomain do
end
end
- describe '#expired?' do
+ describe "#expired?" do
subject { domain.expired? }
- context 'for valid' do
+ context "for valid" do
let(:domain) { build(:pages_domain) }
it { is_expected.to be_falsey }
end
- context 'for expired' do
+ context "for expired" do
let(:domain) { build(:pages_domain, :with_expired_certificate) }
it { is_expected.to be_truthy }
end
end
- describe '#subject' do
+ describe "#subject" do
let(:domain) { build(:pages_domain) }
subject { domain.subject }
- it { is_expected.to eq('/CN=test-certificate') }
+ it { is_expected.to eq("/CN=test-certificate") }
end
- describe '#certificate_text' do
+ describe "#certificate_text" do
let(:domain) { build(:pages_domain) }
subject { domain.certificate_text }
@@ -238,8 +238,8 @@ describe PagesDomain do
end
end
- describe '#update_daemon' do
- it 'runs when the domain is created' do
+ describe "#update_daemon" do
+ it "runs when the domain is created" do
domain = build(:pages_domain)
expect(domain).to receive(:update_daemon)
@@ -247,7 +247,7 @@ describe PagesDomain do
domain.save!
end
- it 'runs when the domain is destroyed' do
+ it "runs when the domain is destroyed" do
domain = create(:pages_domain)
expect(domain).to receive(:update_daemon)
@@ -255,15 +255,15 @@ describe PagesDomain do
domain.destroy!
end
- it 'delegates to Projects::UpdatePagesConfigurationService' do
- service = instance_double('Projects::UpdatePagesConfigurationService')
+ it "delegates to Projects::UpdatePagesConfigurationService" do
+ service = instance_double("Projects::UpdatePagesConfigurationService")
expect(Projects::UpdatePagesConfigurationService).to receive(:new) { service }
expect(service).to receive(:execute)
create(:pages_domain)
end
- context 'configuration updates when attributes change' do
+ context "configuration updates when attributes change" do
set(:project1) { create(:project) }
set(:project2) { create(:project) }
set(:domain) { create(:pages_domain) }
@@ -278,12 +278,12 @@ describe PagesDomain do
:project | :project1 | nil | true
# domain can't be set to nil
- :domain | 'a.com' | 'a.com' | false
- :domain | 'a.com' | 'b.com' | true
+ :domain | "a.com" | "a.com" | false
+ :domain | "a.com" | "b.com" | true
# verification_code can't be set to nil
- :verification_code | 'foo' | 'foo' | false
- :verification_code | 'foo' | 'bar' | false
+ :verification_code | "foo" | "foo" | false
+ :verification_code | "foo" | "bar" | false
:verified_at | nil | now | false
:verified_at | now | now | false
@@ -297,7 +297,7 @@ describe PagesDomain do
end
with_them do
- it 'runs if a relevant attribute has changed' do
+ it "runs if a relevant attribute has changed" do
a = old_value.is_a?(Symbol) ? send(old_value) : old_value
b = new_value.is_a?(Symbol) ? send(new_value) : new_value
@@ -313,28 +313,28 @@ describe PagesDomain do
end
end
- context 'TLS configuration' do
+ context "TLS configuration" do
set(:domain_without_tls) { create(:pages_domain, :without_certificate, :without_key) }
set(:domain) { create(:pages_domain) }
let(:cert1) { domain.certificate }
- let(:cert2) { cert1 + ' ' }
+ let(:cert2) { cert1 + " " }
let(:key1) { domain.key }
- let(:key2) { key1 + ' ' }
+ let(:key2) { key1 + " " }
- it 'updates when added' do
+ it "updates when added" do
expect(domain_without_tls).to receive(:update_daemon)
domain_without_tls.update!(key: key1, certificate: cert1)
end
- it 'updates when changed' do
+ it "updates when changed" do
expect(domain).to receive(:update_daemon)
domain.update!(key: key2, certificate: cert2)
end
- it 'updates when removed' do
+ it "updates when removed" do
expect(domain).to receive(:update_daemon)
domain.update!(key: nil, certificate: nil)
diff --git a/spec/models/personal_access_token_spec.rb b/spec/models/personal_access_token_spec.rb
index c82ab9c9e62..c0964c20a52 100644
--- a/spec/models/personal_access_token_spec.rb
+++ b/spec/models/personal_access_token_spec.rb
@@ -1,17 +1,17 @@
-require 'spec_helper'
+require "spec_helper"
describe PersonalAccessToken do
subject { described_class }
- describe '.build' do
+ describe ".build" do
let(:personal_access_token) { build(:personal_access_token) }
let(:invalid_personal_access_token) { build(:personal_access_token, :invalid) }
- it 'is a valid personal access token' do
+ it "is a valid personal access token" do
expect(personal_access_token).to be_valid
end
- it 'ensures that the token is generated' do
+ it "ensures that the token is generated" do
invalid_personal_access_token.save!
expect(invalid_personal_access_token).to be_valid
@@ -37,52 +37,52 @@ describe PersonalAccessToken do
end
end
- describe 'revoke!' do
+ describe "revoke!" do
let(:active_personal_access_token) { create(:personal_access_token) }
- it 'revokes the token' do
+ it "revokes the token" do
active_personal_access_token.revoke!
expect(active_personal_access_token).to be_revoked
end
end
- describe 'Redis storage' do
+ describe "Redis storage" do
let(:user_id) { 123 }
- let(:token) { 'KS3wegQYXBLYhQsciwsj' }
+ let(:token) { "KS3wegQYXBLYhQsciwsj" }
- context 'reading encrypted data' do
+ context "reading encrypted data" do
before do
subject.redis_store!(user_id, token)
end
- it 'returns stored data' do
+ it "returns stored data" do
expect(subject.redis_getdel(user_id)).to eq(token)
end
end
- context 'reading unencrypted data' do
+ context "reading unencrypted data" do
before do
Gitlab::Redis::SharedState.with do |redis|
redis.set(described_class.redis_shared_state_key(user_id),
- token,
- ex: PersonalAccessToken::REDIS_EXPIRY_TIME)
+ token,
+ ex: PersonalAccessToken::REDIS_EXPIRY_TIME)
end
end
- it 'returns stored data unmodified' do
+ it "returns stored data unmodified" do
expect(subject.redis_getdel(user_id)).to eq(token)
end
end
- context 'after deletion' do
+ context "after deletion" do
before do
subject.redis_store!(user_id, token)
expect(subject.redis_getdel(user_id)).to eq(token)
end
- it 'token is removed' do
+ it "token is removed" do
expect(subject.redis_getdel(user_id)).to be_nil
end
end
@@ -104,7 +104,7 @@ describe PersonalAccessToken do
expect(personal_access_token).to be_valid
end
- context 'when registry is disabled' do
+ context "when registry is disabled" do
before do
stub_container_registry_config(enabled: false)
end
@@ -125,7 +125,7 @@ describe PersonalAccessToken do
end
end
- context 'when registry is enabled' do
+ context "when registry is enabled" do
before do
stub_container_registry_config(enabled: true)
end
diff --git a/spec/models/pool_repository_spec.rb b/spec/models/pool_repository_spec.rb
index 112d4ab56fc..17f3a9b12ff 100644
--- a/spec/models/pool_repository_spec.rb
+++ b/spec/models/pool_repository_spec.rb
@@ -1,42 +1,42 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe PoolRepository do
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:shard) }
it { is_expected.to have_one(:source_project) }
it { is_expected.to have_many(:member_projects) }
end
- describe 'validations' do
+ describe "validations" do
let!(:pool_repository) { create(:pool_repository) }
it { is_expected.to validate_presence_of(:shard) }
it { is_expected.to validate_presence_of(:source_project) }
end
- describe '#disk_path' do
- it 'sets the hashed disk_path' do
+ describe "#disk_path" do
+ it "sets the hashed disk_path" do
pool = create(:pool_repository)
expect(pool.disk_path).to match(%r{\A@pools/\h{2}/\h{2}/\h{64}})
end
end
- describe '#unlink_repository' do
+ describe "#unlink_repository" do
let(:pool) { create(:pool_repository, :ready) }
- context 'when the last member leaves' do
- it 'schedules pool removal' do
+ context "when the last member leaves" do
+ it "schedules pool removal" do
expect(::ObjectPool::DestroyWorker).to receive(:perform_async).with(pool.id).and_call_original
pool.unlink_repository(pool.source_project.repository)
end
end
- context 'when the second member leaves' do
- it 'does not schedule pool removal' do
+ context "when the second member leaves" do
+ it "does not schedule pool removal" do
create(:project, :repository, pool_repository: pool)
expect(::ObjectPool::DestroyWorker).not_to receive(:perform_async).with(pool.id)
diff --git a/spec/models/postgresql/replication_slot_spec.rb b/spec/models/postgresql/replication_slot_spec.rb
index e100af7ddc7..0daceef67e4 100644
--- a/spec/models/postgresql/replication_slot_spec.rb
+++ b/spec/models/postgresql/replication_slot_spec.rb
@@ -1,30 +1,30 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe Postgresql::ReplicationSlot, :postgresql do
- describe '.in_use?' do
- it 'returns true when replication slots are present' do
+ describe ".in_use?" do
+ it "returns true when replication slots are present" do
expect(described_class).to receive(:exists?).and_return(true)
expect(described_class.in_use?).to be_truthy
end
- it 'returns false when replication slots are not present' do
+ it "returns false when replication slots are not present" do
expect(described_class.in_use?).to be_falsey
end
- it 'returns false if the existence check is invalid' do
- expect(described_class).to receive(:exists?).and_raise(ActiveRecord::StatementInvalid.new('PG::FeatureNotSupported'))
+ it "returns false if the existence check is invalid" do
+ expect(described_class).to receive(:exists?).and_raise(ActiveRecord::StatementInvalid.new("PG::FeatureNotSupported"))
expect(described_class.in_use?).to be_falsey
end
end
- describe '.lag_too_great?' do
+ describe ".lag_too_great?" do
before do
expect(described_class).to receive(:in_use?).and_return(true)
end
- it 'returns true when replication lag is too great' do
+ it "returns true when replication lag is too great" do
expect(described_class)
.to receive(:pluck)
.and_return([125.megabytes])
@@ -32,7 +32,7 @@ describe Postgresql::ReplicationSlot, :postgresql do
expect(described_class.lag_too_great?).to eq(true)
end
- it 'returns false when more than one replicas is up to date enough' do
+ it "returns false when more than one replicas is up to date enough" do
expect(described_class)
.to receive(:pluck)
.and_return([125.megabytes, 0.megabytes, 0.megabytes])
@@ -40,7 +40,7 @@ describe Postgresql::ReplicationSlot, :postgresql do
expect(described_class.lag_too_great?).to eq(false)
end
- it 'returns false when replication lag is not too great' do
+ it "returns false when replication lag is not too great" do
expect(described_class)
.to receive(:pluck)
.and_return([0.megabytes])
diff --git a/spec/models/programming_language_spec.rb b/spec/models/programming_language_spec.rb
index 99cd358f863..a37170f10b9 100644
--- a/spec/models/programming_language_spec.rb
+++ b/spec/models/programming_language_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ProgrammingLanguage do
it { is_expected.to respond_to(:name) }
diff --git a/spec/models/project_authorization_spec.rb b/spec/models/project_authorization_spec.rb
index c289ee0859a..1807bada4cc 100644
--- a/spec/models/project_authorization_spec.rb
+++ b/spec/models/project_authorization_spec.rb
@@ -1,22 +1,22 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectAuthorization do
let(:user) { create(:user) }
let(:project1) { create(:project) }
let(:project2) { create(:project) }
- describe '.insert_authorizations' do
- it 'inserts the authorizations' do
+ describe ".insert_authorizations" do
+ it "inserts the authorizations" do
described_class
.insert_authorizations([[user.id, project1.id, Gitlab::Access::MAINTAINER]])
expect(user.project_authorizations.count).to eq(1)
end
- it 'inserts rows in batches' do
+ it "inserts rows in batches" do
described_class.insert_authorizations([
[user.id, project1.id, Gitlab::Access::MAINTAINER],
- [user.id, project2.id, Gitlab::Access::MAINTAINER]
+ [user.id, project2.id, Gitlab::Access::MAINTAINER],
], 1)
expect(user.project_authorizations.count).to eq(2)
diff --git a/spec/models/project_auto_devops_spec.rb b/spec/models/project_auto_devops_spec.rb
index 7ff64c76e37..7c350444f71 100644
--- a/spec/models/project_auto_devops_spec.rb
+++ b/spec/models/project_auto_devops_spec.rb
@@ -1,9 +1,9 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectAutoDevops do
set(:project) { build(:project) }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
it { is_expected.to belong_to(:project) }
@@ -12,25 +12,25 @@ describe ProjectAutoDevops do
it { is_expected.to respond_to(:created_at) }
it { is_expected.to respond_to(:updated_at) }
- describe '#has_domain?' do
- context 'when domain is defined' do
- let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: 'domain.com') }
+ describe "#has_domain?" do
+ context "when domain is defined" do
+ let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: "domain.com") }
it { expect(auto_devops).to have_domain }
end
- context 'when domain is empty' do
- let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: '') }
+ context "when domain is empty" do
+ let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: "") }
- context 'when there is an instance domain specified' do
+ context "when there is an instance domain specified" do
before do
- allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com')
+ allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return("example.com")
end
it { expect(auto_devops).to have_domain }
end
- context 'when there is no instance domain specified' do
+ context "when there is no instance domain specified" do
before do
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil)
end
@@ -40,29 +40,29 @@ describe ProjectAutoDevops do
end
end
- describe '#predefined_variables' do
+ describe "#predefined_variables" do
let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: domain) }
- context 'when domain is defined' do
- let(:domain) { 'example.com' }
+ context "when domain is defined" do
+ let(:domain) { "example.com" }
- it 'returns AUTO_DEVOPS_DOMAIN' do
+ it "returns AUTO_DEVOPS_DOMAIN" do
expect(auto_devops.predefined_variables).to include(domain_variable)
end
end
- context 'when domain is not defined' do
+ context "when domain is not defined" do
let(:domain) { nil }
- context 'when there is an instance domain specified' do
+ context "when there is an instance domain specified" do
before do
- allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com')
+ allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return("example.com")
end
it { expect(auto_devops.predefined_variables).to include(domain_variable) }
end
- context 'when there is no instance domain specified' do
+ context "when there is no instance domain specified" do
before do
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil)
end
@@ -71,20 +71,20 @@ describe ProjectAutoDevops do
end
end
- context 'when deploy_strategy is manual' do
+ context "when deploy_strategy is manual" do
let(:auto_devops) { build_stubbed(:project_auto_devops, :manual_deployment, project: project) }
let(:expected_variables) do
[
- { key: 'INCREMENTAL_ROLLOUT_MODE', value: 'manual' },
- { key: 'STAGING_ENABLED', value: '1' },
- { key: 'INCREMENTAL_ROLLOUT_ENABLED', value: '1' }
+ {key: "INCREMENTAL_ROLLOUT_MODE", value: "manual"},
+ {key: "STAGING_ENABLED", value: "1"},
+ {key: "INCREMENTAL_ROLLOUT_ENABLED", value: "1"},
]
end
it { expect(auto_devops.predefined_variables).to include(*expected_variables) }
end
- context 'when deploy_strategy is continuous' do
+ context "when deploy_strategy is continuous" do
let(:auto_devops) { build_stubbed(:project_auto_devops, :continuous_deployment, project: project) }
it do
@@ -93,10 +93,10 @@ describe ProjectAutoDevops do
end
end
- context 'when deploy_strategy is timed_incremental' do
+ context "when deploy_strategy is timed_incremental" do
let(:auto_devops) { build_stubbed(:project_auto_devops, :timed_incremental_deployment, project: project) }
- it { expect(auto_devops.predefined_variables).to include(key: 'INCREMENTAL_ROLLOUT_MODE', value: 'timed') }
+ it { expect(auto_devops.predefined_variables).to include(key: "INCREMENTAL_ROLLOUT_MODE", value: "timed") }
it do
expect(auto_devops.predefined_variables.map { |var| var[:key] })
@@ -105,99 +105,99 @@ describe ProjectAutoDevops do
end
def domain_variable
- { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }
+ {key: "AUTO_DEVOPS_DOMAIN", value: "example.com", public: true}
end
end
- describe '#create_gitlab_deploy_token' do
+ describe "#create_gitlab_deploy_token" do
let(:auto_devops) { build(:project_auto_devops, project: project) }
- context 'when the project is public' do
+ context "when the project is public" do
let(:project) { create(:project, :repository, :public) }
- it 'should not create a gitlab deploy token' do
- expect do
+ it "should not create a gitlab deploy token" do
+ expect {
auto_devops.save
- end.not_to change { DeployToken.count }
+ }.not_to change { DeployToken.count }
end
end
- context 'when the project is internal' do
+ context "when the project is internal" do
let(:project) { create(:project, :repository, :internal) }
- it 'should create a gitlab deploy token' do
- expect do
+ it "should create a gitlab deploy token" do
+ expect {
auto_devops.save
- end.to change { DeployToken.count }.by(1)
+ }.to change { DeployToken.count }.by(1)
end
end
- context 'when the project is private' do
+ context "when the project is private" do
let(:project) { create(:project, :repository, :private) }
- it 'should create a gitlab deploy token' do
- expect do
+ it "should create a gitlab deploy token" do
+ expect {
auto_devops.save
- end.to change { DeployToken.count }.by(1)
+ }.to change { DeployToken.count }.by(1)
end
end
- context 'when autodevops is enabled at project level' do
+ context "when autodevops is enabled at project level" do
let(:project) { create(:project, :repository, :internal) }
let(:auto_devops) { build(:project_auto_devops, project: project) }
- it 'should create a deploy token' do
- expect do
+ it "should create a deploy token" do
+ expect {
auto_devops.save
- end.to change { DeployToken.count }.by(1)
+ }.to change { DeployToken.count }.by(1)
end
end
- context 'when autodevops is enabled at instance level' do
+ context "when autodevops is enabled at instance level" do
let(:project) { create(:project, :repository, :internal) }
let(:auto_devops) { build(:project_auto_devops, enabled: nil, project: project) }
- it 'should create a deploy token' do
+ it "should create a deploy token" do
allow(Gitlab::CurrentSettings).to receive(:auto_devops_enabled?).and_return(true)
- expect do
+ expect {
auto_devops.save
- end.to change { DeployToken.count }.by(1)
+ }.to change { DeployToken.count }.by(1)
end
end
- context 'when autodevops is disabled' do
+ context "when autodevops is disabled" do
let(:project) { create(:project, :repository, :internal) }
let(:auto_devops) { build(:project_auto_devops, :disabled, project: project) }
- it 'should not create a deploy token' do
- expect do
+ it "should not create a deploy token" do
+ expect {
auto_devops.save
- end.not_to change { DeployToken.count }
+ }.not_to change { DeployToken.count }
end
end
- context 'when the project already has an active gitlab-deploy-token' do
+ context "when the project already has an active gitlab-deploy-token" do
let(:project) { create(:project, :repository, :internal) }
let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, projects: [project]) }
let(:auto_devops) { build(:project_auto_devops, project: project) }
- it 'should not create a deploy token' do
- expect do
+ it "should not create a deploy token" do
+ expect {
auto_devops.save
- end.not_to change { DeployToken.count }
+ }.not_to change { DeployToken.count }
end
end
- context 'when the project already has a revoked gitlab-deploy-token' do
+ context "when the project already has a revoked gitlab-deploy-token" do
let(:project) { create(:project, :repository, :internal) }
let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, :expired, projects: [project]) }
let(:auto_devops) { build(:project_auto_devops, project: project) }
- it 'should not create a deploy token' do
- expect do
+ it "should not create a deploy token" do
+ expect {
auto_devops.save
- end.not_to change { DeployToken.count }
+ }.not_to change { DeployToken.count }
end
end
end
diff --git a/spec/models/project_ci_cd_setting_spec.rb b/spec/models/project_ci_cd_setting_spec.rb
index 4aa62028169..d650ea6196e 100644
--- a/spec/models/project_ci_cd_setting_spec.rb
+++ b/spec/models/project_ci_cd_setting_spec.rb
@@ -1,18 +1,18 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe ProjectCiCdSetting do
- describe '.available?' do
+ describe ".available?" do
before do
described_class.reset_column_information
end
- it 'returns true' do
+ it "returns true" do
expect(described_class).to be_available
end
- it 'memoizes the schema version' do
+ it "memoizes the schema version" do
expect(ActiveRecord::Migrator)
.to receive(:current_version)
.and_call_original
diff --git a/spec/models/project_custom_attribute_spec.rb b/spec/models/project_custom_attribute_spec.rb
index 669de5506bc..838f9fe5964 100644
--- a/spec/models/project_custom_attribute_spec.rb
+++ b/spec/models/project_custom_attribute_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectCustomAttribute do
- describe 'assocations' do
+ describe "assocations" do
it { is_expected.to belong_to(:project) }
end
- describe 'validations' do
+ describe "validations" do
subject { build :project_custom_attribute }
it { is_expected.to validate_presence_of(:project) }
diff --git a/spec/models/project_daily_statistic_spec.rb b/spec/models/project_daily_statistic_spec.rb
index 86210af15d8..46256078dce 100644
--- a/spec/models/project_daily_statistic_spec.rb
+++ b/spec/models/project_daily_statistic_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe ProjectDailyStatistic do
it { is_expected.to belong_to(:project) }
diff --git a/spec/models/project_deploy_token_spec.rb b/spec/models/project_deploy_token_spec.rb
index 9e2e40c2e8f..6c239adcd94 100644
--- a/spec/models/project_deploy_token_spec.rb
+++ b/spec/models/project_deploy_token_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
RSpec.describe ProjectDeployToken, type: :model do
let(:project) { create(:project) }
diff --git a/spec/models/project_feature_spec.rb b/spec/models/project_feature_spec.rb
index fee7d65c217..4d0d9a6ff3a 100644
--- a/spec/models/project_feature_spec.rb
+++ b/spec/models/project_feature_spec.rb
@@ -1,25 +1,25 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectFeature do
let(:project) { create(:project) }
let(:user) { create(:user) }
- describe '.quoted_access_level_column' do
- it 'returns the table name and quoted column name for a feature' do
+ describe ".quoted_access_level_column" do
+ it "returns the table name and quoted column name for a feature" do
expected = if Gitlab::Database.postgresql?
- '"project_features"."issues_access_level"'
- else
- '`project_features`.`issues_access_level`'
- end
+ '"project_features"."issues_access_level"'
+ else
+ "`project_features`.`issues_access_level`"
+ end
expect(described_class.quoted_access_level_column(:issues)).to eq(expected)
end
end
- describe '#feature_available?' do
- let(:features) { %w(issues wiki builds merge_requests snippets repository pages) }
+ describe "#feature_available?" do
+ let(:features) { %w[issues wiki builds merge_requests snippets repository pages] }
- context 'when features are disabled' do
+ context "when features are disabled" do
it "returns false" do
features.each do |feature|
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::DISABLED)
@@ -28,7 +28,7 @@ describe ProjectFeature do
end
end
- context 'when features are enabled only for team members' do
+ context "when features are enabled only for team members" do
it "returns false when user is not a team member" do
features.each do |feature|
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::PRIVATE)
@@ -66,7 +66,7 @@ describe ProjectFeature do
end
end
- context 'when feature is enabled for everyone' do
+ context "when feature is enabled for everyone" do
it "returns true" do
features.each do |feature|
expect(project.feature_available?(:issues, user)).to eq(true)
@@ -74,16 +74,16 @@ describe ProjectFeature do
end
end
- context 'when feature is disabled by a feature flag' do
- it 'returns false' do
+ context "when feature is disabled by a feature flag" do
+ it "returns false" do
stub_feature_flags(issues: false)
expect(project.feature_available?(:issues, user)).to eq(false)
end
end
- context 'when feature is enabled by a feature flag' do
- it 'returns true' do
+ context "when feature is enabled by a feature flag" do
+ it "returns true" do
stub_feature_flags(issues: true)
expect(project.feature_available?(:issues, user)).to eq(true)
@@ -91,7 +91,7 @@ describe ProjectFeature do
end
end
- context 'repository related features' do
+ context "repository related features" do
before do
project.project_feature.update(
merge_requests_access_level: ProjectFeature::DISABLED,
@@ -101,7 +101,7 @@ describe ProjectFeature do
end
it "does not allow repository related features have higher level" do
- features = %w(builds merge_requests)
+ features = %w[builds merge_requests]
project_feature = project.project_feature
features.each do |feature|
@@ -112,9 +112,9 @@ describe ProjectFeature do
end
end
- context 'public features' do
+ context "public features" do
it "does not allow public for other than pages" do
- features = %w(issues wiki builds merge_requests snippets repository)
+ features = %w[issues wiki builds merge_requests snippets repository]
project_feature = project.project_feature
features.each do |feature|
@@ -125,8 +125,8 @@ describe ProjectFeature do
end
end
- describe '#*_enabled?' do
- let(:features) { %w(wiki builds merge_requests) }
+ describe "#*_enabled?" do
+ let(:features) { %w[wiki builds merge_requests] }
it "returns false when feature is disabled" do
features.each do |feature|
diff --git a/spec/models/project_group_link_spec.rb b/spec/models/project_group_link_spec.rb
index 5bea21427d4..9bbbf57ad01 100644
--- a/spec/models/project_group_link_spec.rb
+++ b/spec/models/project_group_link_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectGroupLink do
describe "Associations" do
diff --git a/spec/models/project_import_data_spec.rb b/spec/models/project_import_data_spec.rb
index fe47811f074..1d05272095a 100644
--- a/spec/models/project_import_data_spec.rb
+++ b/spec/models/project_import_data_spec.rb
@@ -1,50 +1,50 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe ProjectImportData do
- describe '#merge_data' do
- it 'writes the Hash to the attribute if it is nil' do
+ describe "#merge_data" do
+ it "writes the Hash to the attribute if it is nil" do
row = described_class.new
- row.merge_data('number' => 10)
+ row.merge_data("number" => 10)
- expect(row.data).to eq({ 'number' => 10 })
+ expect(row.data).to eq({"number" => 10})
end
- it 'merges the Hash into an existing Hash if one was present' do
- row = described_class.new(data: { 'number' => 10 })
+ it "merges the Hash into an existing Hash if one was present" do
+ row = described_class.new(data: {"number" => 10})
- row.merge_data('foo' => 'bar')
+ row.merge_data("foo" => "bar")
- expect(row.data).to eq({ 'number' => 10, 'foo' => 'bar' })
+ expect(row.data).to eq({"number" => 10, "foo" => "bar"})
end
end
- describe '#merge_credentials' do
- it 'writes the Hash to the attribute if it is nil' do
+ describe "#merge_credentials" do
+ it "writes the Hash to the attribute if it is nil" do
row = described_class.new
- row.merge_credentials('number' => 10)
+ row.merge_credentials("number" => 10)
- expect(row.credentials).to eq({ 'number' => 10 })
+ expect(row.credentials).to eq({"number" => 10})
end
- it 'merges the Hash into an existing Hash if one was present' do
+ it "merges the Hash into an existing Hash if one was present" do
row = described_class.new
- row.credentials = { 'number' => 10 }
- row.merge_credentials('foo' => 'bar')
+ row.credentials = {"number" => 10}
+ row.merge_credentials("foo" => "bar")
- expect(row.credentials).to eq({ 'number' => 10, 'foo' => 'bar' })
+ expect(row.credentials).to eq({"number" => 10, "foo" => "bar"})
end
end
- describe '#clear_credentials' do
- it 'clears out the Hash' do
+ describe "#clear_credentials" do
+ it "clears out the Hash" do
row = described_class.new
- row.merge_credentials('number' => 10)
+ row.merge_credentials("number" => 10)
row.clear_credentials
expect(row.credentials).to eq({})
diff --git a/spec/models/project_import_state_spec.rb b/spec/models/project_import_state_spec.rb
index e3b2d971419..bfd1b065a28 100644
--- a/spec/models/project_import_state_spec.rb
+++ b/spec/models/project_import_state_spec.rb
@@ -1,17 +1,17 @@
-require 'rails_helper'
+require "rails_helper"
describe ProjectImportState, type: :model do
subject { create(:import_state) }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:project) }
end
- describe 'Project import job' do
+ describe "Project import job" do
let(:import_state) { create(:import_state, import_url: generate(:url)) }
let(:project) { import_state.project }
@@ -25,17 +25,17 @@ describe ProjectImportState, type: :model do
expect(project.wiki.repository).to receive(:after_import).and_call_original
end
- it 'imports a project' do
+ it "imports a project" do
expect(RepositoryImportWorker).to receive(:perform_async).and_call_original
expect { import_state.schedule }.to change { import_state.jid }
- expect(import_state.status).to eq('finished')
+ expect(import_state.status).to eq("finished")
end
end
- describe '#human_status_name' do
- context 'when import_state exists' do
- it 'returns the humanized status name' do
+ describe "#human_status_name" do
+ context "when import_state exists" do
+ it "returns the humanized status name" do
import_state = build(:import_state, :started)
expect(import_state.human_status_name).to eq("started")
@@ -43,8 +43,8 @@ describe ProjectImportState, type: :model do
end
end
- describe 'import state transitions' do
- context 'state transition: [:started] => [:finished]' do
+ describe "import state transitions" do
+ context "state transition: [:started] => [:finished]" do
let(:after_import_service) { spy(:after_import_service) }
let(:housekeeping_service) { spy(:housekeeping_service) }
@@ -59,14 +59,14 @@ describe ProjectImportState, type: :model do
.to receive(:new) { housekeeping_service }
end
- it 'resets last_error' do
- error_message = 'Some error'
+ it "resets last_error" do
+ error_message = "Some error"
import_state = create(:import_state, :started, last_error: error_message)
expect { import_state.finish }.to change { import_state.last_error }.from(error_message).to(nil)
end
- it 'performs housekeeping when an import of a fresh project is completed' do
+ it "performs housekeeping when an import of a fresh project is completed" do
project = create(:project_empty_repo, :import_started, import_type: :github)
project.import_state.finish
@@ -75,7 +75,7 @@ describe ProjectImportState, type: :model do
expect(housekeeping_service).to have_received(:execute)
end
- it 'does not perform housekeeping when project repository does not exist' do
+ it "does not perform housekeeping when project repository does not exist" do
project = create(:project, :import_started, import_type: :github)
project.import_state.finish
@@ -83,7 +83,7 @@ describe ProjectImportState, type: :model do
expect(housekeeping_service).not_to have_received(:execute)
end
- it 'does not perform housekeeping when project does not have a valid import type' do
+ it "does not perform housekeeping when project does not have a valid import type" do
project = create(:project, :import_started, import_type: nil)
project.import_state.finish
@@ -93,11 +93,11 @@ describe ProjectImportState, type: :model do
end
end
- describe '#remove_jid', :clean_gitlab_redis_cache do
+ describe "#remove_jid", :clean_gitlab_redis_cache do
let(:project) { }
- context 'without an JID' do
- it 'does nothing' do
+ context "without an JID" do
+ it "does nothing" do
import_state = create(:import_state)
expect(Gitlab::SidekiqStatus)
@@ -107,13 +107,13 @@ describe ProjectImportState, type: :model do
end
end
- context 'with an JID' do
- it 'unsets the JID' do
- import_state = create(:import_state, jid: '123')
+ context "with an JID" do
+ it "unsets the JID" do
+ import_state = create(:import_state, jid: "123")
expect(Gitlab::SidekiqStatus)
.to receive(:unset)
- .with('123')
+ .with("123")
.and_call_original
import_state.remove_jid
diff --git a/spec/models/project_label_spec.rb b/spec/models/project_label_spec.rb
index 689d4e505e5..ba0a21bae33 100644
--- a/spec/models/project_label_spec.rb
+++ b/spec/models/project_label_spec.rb
@@ -1,50 +1,50 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectLabel do
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:project) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:project) }
- context 'validates if title must not exist at group level' do
- let(:group) { create(:group, name: 'gitlab-org') }
+ context "validates if title must not exist at group level" do
+ let(:group) { create(:group, name: "gitlab-org") }
let(:project) { create(:project, group: group) }
before do
- create(:group_label, group: group, title: 'Bug')
+ create(:group_label, group: group, title: "Bug")
end
- it 'returns error if title already exists at group level' do
- label = described_class.new(project: project, title: 'Bug')
+ it "returns error if title already exists at group level" do
+ label = described_class.new(project: project, title: "Bug")
label.valid?
- expect(label.errors[:title]).to include 'already exists at group level for gitlab-org. Please choose another one.'
+ expect(label.errors[:title]).to include "already exists at group level for gitlab-org. Please choose another one."
end
- it 'does not returns error if title does not exist at group level' do
- label = described_class.new(project: project, title: 'Security')
+ it "does not returns error if title does not exist at group level" do
+ label = described_class.new(project: project, title: "Security")
label.valid?
expect(label.errors[:title]).to be_empty
end
- it 'does not returns error if project does not belong to group' do
+ it "does not returns error if project does not belong to group" do
another_project = create(:project)
- label = described_class.new(project: another_project, title: 'Bug')
+ label = described_class.new(project: another_project, title: "Bug")
label.valid?
expect(label.errors[:title]).to be_empty
end
- it 'does not returns error when title does not change' do
- project_label = create(:label, project: project, name: 'Security')
- create(:group_label, group: group, name: 'Security')
- project_label.description = 'Security related stuff.'
+ it "does not returns error when title does not change" do
+ project_label = create(:label, project: project, name: "Security")
+ create(:group_label, group: group, name: "Security")
+ project_label.description = "Security related stuff."
project_label.valid?
@@ -52,67 +52,67 @@ describe ProjectLabel do
end
end
- context 'when attempting to add more than one priority to the project label' do
- it 'returns error' do
+ context "when attempting to add more than one priority to the project label" do
+ it "returns error" do
subject.priorities.build
subject.priorities.build
subject.valid?
- expect(subject.errors[:priorities]).to include 'Number of permitted priorities exceeded'
+ expect(subject.errors[:priorities]).to include "Number of permitted priorities exceeded"
end
end
end
- describe '#subject' do
- it 'aliases project to subject' do
+ describe "#subject" do
+ it "aliases project to subject" do
subject = described_class.new(project: build(:project))
expect(subject.subject).to be(subject.project)
end
end
- describe '#to_reference' do
+ describe "#to_reference" do
let(:label) { create(:label) }
- context 'using id' do
- it 'returns a String reference to the object' do
+ context "using id" do
+ it "returns a String reference to the object" do
expect(label.to_reference).to eq "~#{label.id}"
end
end
- context 'using name' do
- it 'returns a String reference to the object' do
+ context "using name" do
+ it "returns a String reference to the object" do
expect(label.to_reference(format: :name)).to eq %(~"#{label.name}")
end
- it 'uses id when name contains double quote' do
- label = create(:label, name: %q{"irony"})
+ it "uses id when name contains double quote" do
+ label = create(:label, name: '"irony"')
expect(label.to_reference(format: :name)).to eq "~#{label.id}"
end
end
- context 'using invalid format' do
- it 'raises error' do
+ context "using invalid format" do
+ it "raises error" do
expect { label.to_reference(format: :invalid) }
.to raise_error StandardError, /Unknown format/
end
end
- context 'cross project reference' do
+ context "cross project reference" do
let(:project) { create(:project) }
- context 'using name' do
- it 'returns cross reference with label name' do
+ context "using name" do
+ it "returns cross reference with label name" do
expect(label.to_reference(project, format: :name))
- .to eq %Q(#{label.project.full_path}~"#{label.name}")
+ .to eq %(#{label.project.full_path}~"#{label.name}")
end
end
- context 'using id' do
- it 'returns cross reference with label id' do
+ context "using id" do
+ it "returns cross reference with label id" do
expect(label.to_reference(project, format: :id))
- .to eq %Q(#{label.project.full_path}~#{label.id})
+ .to eq %(#{label.project.full_path}~#{label.id})
end
end
end
diff --git a/spec/models/project_repository_spec.rb b/spec/models/project_repository_spec.rb
index c966447fedc..78538ec38ed 100644
--- a/spec/models/project_repository_spec.rb
+++ b/spec/models/project_repository_spec.rb
@@ -1,23 +1,23 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe ProjectRepository do
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:shard) }
it { is_expected.to belong_to(:project) }
end
- describe '.find_project' do
- it 'finds project by disk path' do
+ describe ".find_project" do
+ it "finds project by disk path" do
project = create(:project)
project.track_project_repository
expect(described_class.find_project(project.disk_path)).to eq(project)
end
- it 'returns nil when it does not find the project' do
- expect(described_class.find_project('@@unexisting/path/to/project')).to be_nil
+ it "returns nil when it does not find the project" do
+ expect(described_class.find_project("@@unexisting/path/to/project")).to be_nil
end
end
end
diff --git a/spec/models/project_services/asana_service_spec.rb b/spec/models/project_services/asana_service_spec.rb
index e66109fd98f..c8e915fc949 100644
--- a/spec/models/project_services/asana_service_spec.rb
+++ b/spec/models/project_services/asana_service_spec.rb
@@ -1,13 +1,13 @@
-require 'spec_helper'
+require "spec_helper"
describe AsanaService do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'active' do
+ describe "Validations" do
+ context "active" do
before do
subject.active = true
end
@@ -16,21 +16,21 @@ describe AsanaService do
end
end
- describe 'Execute' do
+ describe "Execute" do
let(:user) { create(:user) }
let(:project) { create(:project) }
def create_data_for_commits(*messages)
{
- object_kind: 'push',
- ref: 'master',
+ object_kind: "push",
+ ref: "master",
user_name: user.name,
commits: messages.map do |m|
{
message: m,
- url: 'https://gitlab.com/'
+ url: "https://gitlab.com/",
}
- end
+ end,
}
end
@@ -40,70 +40,70 @@ describe AsanaService do
project: project,
project_id: project.id,
service_hook: true,
- api_key: 'verySecret',
- restrict_to_branch: 'master'
+ api_key: "verySecret",
+ restrict_to_branch: "master"
)
end
- it 'calls Asana service to create a story' do
- data = create_data_for_commits('Message from commit. related to #123456')
+ it "calls Asana service to create a story" do
+ data = create_data_for_commits("Message from commit. related to #123456")
expected_message = "#{data[:user_name]} pushed to branch #{data[:ref]} of #{project.full_name} ( #{data[:commits][0][:url]} ): #{data[:commits][0][:message]}"
- d1 = double('Asana::Task')
+ d1 = double("Asana::Task")
expect(d1).to receive(:add_comment).with(text: expected_message)
- expect(Asana::Task).to receive(:find_by_id).with(anything, '123456').once.and_return(d1)
+ expect(Asana::Task).to receive(:find_by_id).with(anything, "123456").once.and_return(d1)
@asana.execute(data)
end
- it 'calls Asana service to create a story and close a task' do
- data = create_data_for_commits('fix #456789')
- d1 = double('Asana::Task')
+ it "calls Asana service to create a story and close a task" do
+ data = create_data_for_commits("fix #456789")
+ d1 = double("Asana::Task")
expect(d1).to receive(:add_comment)
expect(d1).to receive(:update).with(completed: true)
- expect(Asana::Task).to receive(:find_by_id).with(anything, '456789').once.and_return(d1)
+ expect(Asana::Task).to receive(:find_by_id).with(anything, "456789").once.and_return(d1)
@asana.execute(data)
end
- it 'is able to close via url' do
- data = create_data_for_commits('closes https://app.asana.com/19292/956299/42')
- d1 = double('Asana::Task')
+ it "is able to close via url" do
+ data = create_data_for_commits("closes https://app.asana.com/19292/956299/42")
+ d1 = double("Asana::Task")
expect(d1).to receive(:add_comment)
expect(d1).to receive(:update).with(completed: true)
- expect(Asana::Task).to receive(:find_by_id).with(anything, '42').once.and_return(d1)
+ expect(Asana::Task).to receive(:find_by_id).with(anything, "42").once.and_return(d1)
@asana.execute(data)
end
- it 'allows multiple matches per line' do
+ it "allows multiple matches per line" do
message = <<-EOF
minor bigfix, refactoring, fixed #123 and Closes #456 work on #789
ref https://app.asana.com/19292/956299/42 and closing https://app.asana.com/19292/956299/12
EOF
data = create_data_for_commits(message)
- d1 = double('Asana::Task')
+ d1 = double("Asana::Task")
expect(d1).to receive(:add_comment)
expect(d1).to receive(:update).with(completed: true)
- expect(Asana::Task).to receive(:find_by_id).with(anything, '123').once.and_return(d1)
+ expect(Asana::Task).to receive(:find_by_id).with(anything, "123").once.and_return(d1)
- d2 = double('Asana::Task')
+ d2 = double("Asana::Task")
expect(d2).to receive(:add_comment)
expect(d2).to receive(:update).with(completed: true)
- expect(Asana::Task).to receive(:find_by_id).with(anything, '456').once.and_return(d2)
+ expect(Asana::Task).to receive(:find_by_id).with(anything, "456").once.and_return(d2)
- d3 = double('Asana::Task')
+ d3 = double("Asana::Task")
expect(d3).to receive(:add_comment)
- expect(Asana::Task).to receive(:find_by_id).with(anything, '789').once.and_return(d3)
+ expect(Asana::Task).to receive(:find_by_id).with(anything, "789").once.and_return(d3)
- d4 = double('Asana::Task')
+ d4 = double("Asana::Task")
expect(d4).to receive(:add_comment)
- expect(Asana::Task).to receive(:find_by_id).with(anything, '42').once.and_return(d4)
+ expect(Asana::Task).to receive(:find_by_id).with(anything, "42").once.and_return(d4)
- d5 = double('Asana::Task')
+ d5 = double("Asana::Task")
expect(d5).to receive(:add_comment)
expect(d5).to receive(:update).with(completed: true)
- expect(Asana::Task).to receive(:find_by_id).with(anything, '12').once.and_return(d5)
+ expect(Asana::Task).to receive(:find_by_id).with(anything, "12").once.and_return(d5)
@asana.execute(data)
end
diff --git a/spec/models/project_services/assembla_service_spec.rb b/spec/models/project_services/assembla_service_spec.rb
index 5cb6d63659e..26ee6c5e76a 100644
--- a/spec/models/project_services/assembla_service_spec.rb
+++ b/spec/models/project_services/assembla_service_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe AssemblaService do
describe "Associations" do
@@ -16,11 +16,11 @@ describe AssemblaService do
project_id: project.id,
project: project,
service_hook: true,
- token: 'verySecret',
- subdomain: 'project_name'
+ token: "verySecret",
+ subdomain: "project_name"
)
@sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
- @api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret'
+ @api_url = "https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret"
WebMock.stub_request(:post, @api_url)
end
diff --git a/spec/models/project_services/bamboo_service_spec.rb b/spec/models/project_services/bamboo_service_spec.rb
index b880d90d28f..09ba2c69d97 100644
--- a/spec/models/project_services/bamboo_service_spec.rb
+++ b/spec/models/project_services/bamboo_service_spec.rb
@@ -1,67 +1,67 @@
-require 'spec_helper'
+require "spec_helper"
describe BambooService, :use_clean_rails_memory_store_caching do
include ReactiveCachingHelpers
- let(:bamboo_url) { 'http://gitlab.com/bamboo' }
+ let(:bamboo_url) { "http://gitlab.com/bamboo" }
subject(:service) do
described_class.create(
project: create(:project),
properties: {
bamboo_url: bamboo_url,
- username: 'mic',
- password: 'password',
- build_key: 'foo'
+ username: "mic",
+ password: "password",
+ build_key: "foo",
}
)
end
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:build_key) }
it { is_expected.to validate_presence_of(:bamboo_url) }
- it_behaves_like 'issue tracker service URL attribute', :bamboo_url
+ it_behaves_like "issue tracker service URL attribute", :bamboo_url
- describe '#username' do
- it 'does not validate the presence of username if password is nil' do
+ describe "#username" do
+ it "does not validate the presence of username if password is nil" do
subject.password = nil
expect(subject).not_to validate_presence_of(:username)
end
- it 'validates the presence of username if password is present' do
- subject.password = 'secret'
+ it "validates the presence of username if password is present" do
+ subject.password = "secret"
expect(subject).to validate_presence_of(:username)
end
end
- describe '#password' do
- it 'does not validate the presence of password if username is nil' do
+ describe "#password" do
+ it "does not validate the presence of password if username is nil" do
subject.username = nil
expect(subject).not_to validate_presence_of(:password)
end
- it 'validates the presence of password if username is present' do
- subject.username = 'john'
+ it "validates the presence of password if username is present" do
+ subject.username = "john"
expect(subject).to validate_presence_of(:password)
end
end
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -73,114 +73,114 @@ describe BambooService, :use_clean_rails_memory_store_caching do
end
end
- describe 'Callbacks' do
- describe 'before_update :reset_password' do
- context 'when a password was previously set' do
- it 'resets password if url changed' do
+ describe "Callbacks" do
+ describe "before_update :reset_password" do
+ context "when a password was previously set" do
+ it "resets password if url changed" do
bamboo_service = service
- bamboo_service.bamboo_url = 'http://gitlab1.com'
+ bamboo_service.bamboo_url = "http://gitlab1.com"
bamboo_service.save
expect(bamboo_service.password).to be_nil
end
- it 'does not reset password if username changed' do
+ it "does not reset password if username changed" do
bamboo_service = service
- bamboo_service.username = 'some_name'
+ bamboo_service.username = "some_name"
bamboo_service.save
- expect(bamboo_service.password).to eq('password')
+ expect(bamboo_service.password).to eq("password")
end
it "does not reset password if new url is set together with password, even if it's the same password" do
bamboo_service = service
- bamboo_service.bamboo_url = 'http://gitlab_edited.com'
- bamboo_service.password = 'password'
+ bamboo_service.bamboo_url = "http://gitlab_edited.com"
+ bamboo_service.password = "password"
bamboo_service.save
- expect(bamboo_service.password).to eq('password')
- expect(bamboo_service.bamboo_url).to eq('http://gitlab_edited.com')
+ expect(bamboo_service.password).to eq("password")
+ expect(bamboo_service.bamboo_url).to eq("http://gitlab_edited.com")
end
end
- it 'saves password if new url is set together with password when no password was previously set' do
+ it "saves password if new url is set together with password when no password was previously set" do
bamboo_service = service
bamboo_service.password = nil
- bamboo_service.bamboo_url = 'http://gitlab_edited.com'
- bamboo_service.password = 'password'
+ bamboo_service.bamboo_url = "http://gitlab_edited.com"
+ bamboo_service.password = "password"
bamboo_service.save
- expect(bamboo_service.password).to eq('password')
- expect(bamboo_service.bamboo_url).to eq('http://gitlab_edited.com')
+ expect(bamboo_service.password).to eq("password")
+ expect(bamboo_service.bamboo_url).to eq("http://gitlab_edited.com")
end
end
end
- describe '#execute' do
- it 'runs update and build action' do
+ describe "#execute" do
+ it "runs update and build action" do
stub_update_and_build_request
subject.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
end
end
- describe '#build_page' do
- it 'returns the contents of the reactive cache' do
- stub_reactive_cache(service, { build_page: 'foo' }, 'sha', 'ref')
+ describe "#build_page" do
+ it "returns the contents of the reactive cache" do
+ stub_reactive_cache(service, {build_page: "foo"}, "sha", "ref")
- expect(service.build_page('sha', 'ref')).to eq('foo')
+ expect(service.build_page("sha", "ref")).to eq("foo")
end
end
- describe '#commit_status' do
- it 'returns the contents of the reactive cache' do
- stub_reactive_cache(service, { commit_status: 'foo' }, 'sha', 'ref')
+ describe "#commit_status" do
+ it "returns the contents of the reactive cache" do
+ stub_reactive_cache(service, {commit_status: "foo"}, "sha", "ref")
- expect(service.commit_status('sha', 'ref')).to eq('foo')
+ expect(service.commit_status("sha", "ref")).to eq("foo")
end
end
- shared_examples 'reactive cache calculation' do
- context '#build_page' do
- subject { service.calculate_reactive_cache('123', 'unused')[:build_page] }
+ shared_examples "reactive cache calculation" do
+ context "#build_page" do
+ subject { service.calculate_reactive_cache("123", "unused")[:build_page] }
- it 'returns a specific URL when status is 500' do
+ it "returns a specific URL when status is 500" do
stub_request(status: 500)
- is_expected.to eq('http://gitlab.com/bamboo/browse/foo')
+ is_expected.to eq("http://gitlab.com/bamboo/browse/foo")
end
- it 'returns a specific URL when response has no results' do
- stub_request(body: %q({"results":{"results":{"size":"0"}}}))
+ it "returns a specific URL when response has no results" do
+ stub_request(body: '{"results":{"results":{"size":"0"}}}')
- is_expected.to eq('http://gitlab.com/bamboo/browse/foo')
+ is_expected.to eq("http://gitlab.com/bamboo/browse/foo")
end
- it 'returns a build URL when bamboo_url has no trailing slash' do
+ it "returns a build URL when bamboo_url has no trailing slash" do
stub_request(body: bamboo_response)
- is_expected.to eq('http://gitlab.com/bamboo/browse/42')
+ is_expected.to eq("http://gitlab.com/bamboo/browse/42")
end
- context 'bamboo_url has trailing slash' do
- let(:bamboo_url) { 'http://gitlab.com/bamboo/' }
+ context "bamboo_url has trailing slash" do
+ let(:bamboo_url) { "http://gitlab.com/bamboo/" }
- it 'returns a build URL' do
+ it "returns a build URL" do
stub_request(body: bamboo_response)
- is_expected.to eq('http://gitlab.com/bamboo/browse/42')
+ is_expected.to eq("http://gitlab.com/bamboo/browse/42")
end
end
end
- context '#commit_status' do
- subject { service.calculate_reactive_cache('123', 'unused')[:commit_status] }
+ context "#commit_status" do
+ subject { service.calculate_reactive_cache("123", "unused")[:commit_status] }
- it 'sets commit status to :error when status is 500' do
+ it "sets commit status to :error when status is 500" do
stub_request(status: 500)
is_expected.to eq(:error)
@@ -189,67 +189,67 @@ describe BambooService, :use_clean_rails_memory_store_caching do
it 'sets commit status to "pending" when status is 404' do
stub_request(status: 404)
- is_expected.to eq('pending')
+ is_expected.to eq("pending")
end
it 'sets commit status to "pending" when response has no results' do
- stub_request(body: %q({"results":{"results":{"size":"0"}}}))
+ stub_request(body: '{"results":{"results":{"size":"0"}}}')
- is_expected.to eq('pending')
+ is_expected.to eq("pending")
end
it 'sets commit status to "success" when build state contains Success' do
- stub_request(body: bamboo_response(build_state: 'YAY Success!'))
+ stub_request(body: bamboo_response(build_state: "YAY Success!"))
- is_expected.to eq('success')
+ is_expected.to eq("success")
end
it 'sets commit status to "failed" when build state contains Failed' do
- stub_request(body: bamboo_response(build_state: 'NO Failed!'))
+ stub_request(body: bamboo_response(build_state: "NO Failed!"))
- is_expected.to eq('failed')
+ is_expected.to eq("failed")
end
it 'sets commit status to "pending" when build state contains Pending' do
- stub_request(body: bamboo_response(build_state: 'NO Pending!'))
+ stub_request(body: bamboo_response(build_state: "NO Pending!"))
- is_expected.to eq('pending')
+ is_expected.to eq("pending")
end
- it 'sets commit status to :error when build state is unknown' do
- stub_request(body: bamboo_response(build_state: 'FOO BAR!'))
+ it "sets commit status to :error when build state is unknown" do
+ stub_request(body: bamboo_response(build_state: "FOO BAR!"))
is_expected.to eq(:error)
end
end
end
- describe '#calculate_reactive_cache' do
- context 'when Bamboo API returns single result' do
+ describe "#calculate_reactive_cache" do
+ context "when Bamboo API returns single result" do
let(:bamboo_response_template) do
- %q({"results":{"results":{"size":"1","result":{"buildState":"%{build_state}","planResultKey":{"key":"42"}}}}})
+ '{"results":{"results":{"size":"1","result":{"buildState":"%{build_state}","planResultKey":{"key":"42"}}}}}'
end
- it_behaves_like 'reactive cache calculation'
+ it_behaves_like "reactive cache calculation"
end
- context 'when Bamboo API returns an array of results and we only consider the last one' do
+ context "when Bamboo API returns an array of results and we only consider the last one" do
let(:bamboo_response_template) do
- %q({"results":{"results":{"size":"2","result":[{"buildState":"%{build_state}","planResultKey":{"key":"41"}},{"buildState":"%{build_state}","planResultKey":{"key":"42"}}]}}})
+ '{"results":{"results":{"size":"2","result":[{"buildState":"%{build_state}","planResultKey":{"key":"41"}},{"buildState":"%{build_state}","planResultKey":{"key":"42"}}]}}}'
end
- it_behaves_like 'reactive cache calculation'
+ it_behaves_like "reactive cache calculation"
end
end
def stub_update_and_build_request(status: 200, body: nil)
- bamboo_full_url = 'http://gitlab.com/bamboo/updateAndBuild.action?buildKey=foo&os_authType=basic'
+ bamboo_full_url = "http://gitlab.com/bamboo/updateAndBuild.action?buildKey=foo&os_authType=basic"
stub_bamboo_request(bamboo_full_url, status, body)
end
def stub_request(status: 200, body: nil)
- bamboo_full_url = 'http://gitlab.com/bamboo/rest/api/latest/result/byChangeset/123?os_authType=basic'
+ bamboo_full_url = "http://gitlab.com/bamboo/rest/api/latest/result/byChangeset/123?os_authType=basic"
stub_bamboo_request(bamboo_full_url, status, body)
end
@@ -257,13 +257,13 @@ describe BambooService, :use_clean_rails_memory_store_caching do
def stub_bamboo_request(url, status, body)
WebMock.stub_request(:get, url).to_return(
status: status,
- headers: { 'Content-Type' => 'application/json' },
+ headers: {"Content-Type" => "application/json"},
body: body
- ).with(basic_auth: %w(mic password))
+ ).with(basic_auth: %w[mic password])
end
- def bamboo_response(build_state: 'success')
+ def bamboo_response(build_state: "success")
# reference: https://docs.atlassian.com/atlassian-bamboo/REST/6.2.5/#d2e786
- bamboo_response_template % { build_state: build_state }
+ bamboo_response_template % {build_state: build_state}
end
end
diff --git a/spec/models/project_services/bugzilla_service_spec.rb b/spec/models/project_services/bugzilla_service_spec.rb
index 43f7bcb1a19..7cfc8b8e262 100644
--- a/spec/models/project_services/bugzilla_service_spec.rb
+++ b/spec/models/project_services/bugzilla_service_spec.rb
@@ -1,13 +1,13 @@
-require 'spec_helper'
+require "spec_helper"
describe BugzillaService do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -15,12 +15,12 @@ describe BugzillaService do
it { is_expected.to validate_presence_of(:project_url) }
it { is_expected.to validate_presence_of(:issues_url) }
it { is_expected.to validate_presence_of(:new_issue_url) }
- it_behaves_like 'issue tracker service URL attribute', :project_url
- it_behaves_like 'issue tracker service URL attribute', :issues_url
- it_behaves_like 'issue tracker service URL attribute', :new_issue_url
+ it_behaves_like "issue tracker service URL attribute", :project_url
+ it_behaves_like "issue tracker service URL attribute", :issues_url
+ it_behaves_like "issue tracker service URL attribute", :new_issue_url
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
diff --git a/spec/models/project_services/buildkite_service_spec.rb b/spec/models/project_services/buildkite_service_spec.rb
index 1615a93a4ca..c37c3ca539f 100644
--- a/spec/models/project_services/buildkite_service_spec.rb
+++ b/spec/models/project_services/buildkite_service_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe BuildkiteService, :use_clean_rails_memory_store_caching do
include ReactiveCachingHelpers
@@ -10,29 +10,29 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do
project: project,
properties: {
service_hook: true,
- project_url: 'https://buildkite.com/account-name/example-project',
- token: 'secret-sauce-webhook-token:secret-sauce-status-token'
+ project_url: "https://buildkite.com/account-name/example-project",
+ token: "secret-sauce-webhook-token:secret-sauce-status-token",
}
)
end
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:project_url) }
it { is_expected.to validate_presence_of(:token) }
- it_behaves_like 'issue tracker service URL attribute', :project_url
+ it_behaves_like "issue tracker service URL attribute", :project_url
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -42,75 +42,75 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do
end
end
- describe 'commits methods' do
+ describe "commits methods" do
before do
- allow(project).to receive(:default_branch).and_return('default-brancho')
+ allow(project).to receive(:default_branch).and_return("default-brancho")
end
- describe '#webhook_url' do
- it 'returns the webhook url' do
+ describe "#webhook_url" do
+ it "returns the webhook url" do
expect(service.webhook_url).to eq(
- 'https://webhook.buildkite.com/deliver/secret-sauce-webhook-token'
+ "https://webhook.buildkite.com/deliver/secret-sauce-webhook-token"
)
end
end
- describe '#commit_status_path' do
- it 'returns the correct status page' do
- expect(service.commit_status_path('2ab7834c')).to eq(
- 'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=2ab7834c'
+ describe "#commit_status_path" do
+ it "returns the correct status page" do
+ expect(service.commit_status_path("2ab7834c")).to eq(
+ "https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=2ab7834c"
)
end
end
- describe '#build_page' do
- it 'returns the correct build page' do
- expect(service.build_page('2ab7834c', nil)).to eq(
- 'https://buildkite.com/account-name/example-project/builds?commit=2ab7834c'
+ describe "#build_page" do
+ it "returns the correct build page" do
+ expect(service.build_page("2ab7834c", nil)).to eq(
+ "https://buildkite.com/account-name/example-project/builds?commit=2ab7834c"
)
end
end
- describe '#commit_status' do
- it 'returns the contents of the reactive cache' do
- stub_reactive_cache(service, { commit_status: 'foo' }, 'sha', 'ref')
+ describe "#commit_status" do
+ it "returns the contents of the reactive cache" do
+ stub_reactive_cache(service, {commit_status: "foo"}, "sha", "ref")
- expect(service.commit_status('sha', 'ref')).to eq('foo')
+ expect(service.commit_status("sha", "ref")).to eq("foo")
end
end
- describe '#calculate_reactive_cache' do
- context '#commit_status' do
- subject { service.calculate_reactive_cache('123', 'unused')[:commit_status] }
+ describe "#calculate_reactive_cache" do
+ context "#commit_status" do
+ subject { service.calculate_reactive_cache("123", "unused")[:commit_status] }
- it 'sets commit status to :error when status is 500' do
+ it "sets commit status to :error when status is 500" do
stub_request(status: 500)
is_expected.to eq(:error)
end
- it 'sets commit status to :error when status is 404' do
+ it "sets commit status to :error when status is 404" do
stub_request(status: 404)
is_expected.to eq(:error)
end
- it 'passes through build status untouched when status is 200' do
- stub_request(body: %q({"status":"Great Success"}))
+ it "passes through build status untouched when status is 200" do
+ stub_request(body: '{"status":"Great Success"}')
- is_expected.to eq('Great Success')
+ is_expected.to eq("Great Success")
end
end
end
end
def stub_request(status: 200, body: nil)
- body ||= %q({"status":"success"})
- buildkite_full_url = 'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=123'
+ body ||= '{"status":"success"}'
+ buildkite_full_url = "https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=123"
WebMock.stub_request(:get, buildkite_full_url).to_return(
status: status,
- headers: { 'Content-Type' => 'application/json' },
+ headers: {"Content-Type" => "application/json"},
body: body
)
end
diff --git a/spec/models/project_services/campfire_service_spec.rb b/spec/models/project_services/campfire_service_spec.rb
index ed8347edffd..5115d1202a5 100644
--- a/spec/models/project_services/campfire_service_spec.rb
+++ b/spec/models/project_services/campfire_service_spec.rb
@@ -1,13 +1,13 @@
-require 'spec_helper'
+require "spec_helper"
describe CampfireService do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -15,7 +15,7 @@ describe CampfireService do
it { is_expected.to validate_presence_of(:token) }
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -34,26 +34,26 @@ describe CampfireService do
project_id: project.id,
project: project,
service_hook: true,
- token: 'verySecret',
- subdomain: 'project-name',
- room: 'test-room'
+ token: "verySecret",
+ subdomain: "project-name",
+ room: "test-room"
)
@sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
- @rooms_url = 'https://project-name.campfirenow.com/rooms.json'
- @auth = %w(verySecret X)
- @headers = { 'Content-Type' => 'application/json; charset=utf-8' }
+ @rooms_url = "https://project-name.campfirenow.com/rooms.json"
+ @auth = %w[verySecret X]
+ @headers = {"Content-Type" => "application/json; charset=utf-8"}
end
it "calls Campfire API to get a list of rooms and speak in a room" do
# make sure a valid list of rooms is returned
- body = File.read(Rails.root + 'spec/fixtures/project_services/campfire/rooms.json')
+ body = File.read(Rails.root + "spec/fixtures/project_services/campfire/rooms.json")
WebMock.stub_request(:get, @rooms_url).with(basic_auth: @auth).to_return(
body: body,
status: 200,
headers: @headers
)
# stub the speak request with the room id found in the previous request's response
- speak_url = 'https://project-name.campfirenow.com/room/123/speak.json'
+ speak_url = "https://project-name.campfirenow.com/room/123/speak.json"
WebMock.stub_request(:post, speak_url).with(basic_auth: @auth)
@campfire_service.execute(@sample_data)
@@ -66,7 +66,7 @@ describe CampfireService do
it "calls Campfire API to get a list of rooms but shouldn't speak in a room" do
# return a list of rooms that do not contain a room named 'test-room'
- body = File.read(Rails.root + 'spec/fixtures/project_services/campfire/rooms2.json')
+ body = File.read(Rails.root + "spec/fixtures/project_services/campfire/rooms2.json")
WebMock.stub_request(:get, @rooms_url).with(basic_auth: @auth).to_return(
body: body,
status: 200,
@@ -74,7 +74,7 @@ describe CampfireService do
)
# we want to make sure no request is sent to the /speak endpoint, here is a basic
# regexp that matches this endpoint
- speak_url = 'https://verySecret:X@project-name.campfirenow.com/room/.*/speak.json'
+ speak_url = "https://verySecret:X@project-name.campfirenow.com/room/.*/speak.json"
@campfire_service.execute(@sample_data)
diff --git a/spec/models/project_services/chat_message/issue_message_spec.rb b/spec/models/project_services/chat_message/issue_message_spec.rb
index f7a35fdc88a..fe03910e086 100644
--- a/spec/models/project_services/chat_message/issue_message_spec.rb
+++ b/spec/models/project_services/chat_message/issue_message_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ChatMessage::IssueMessage do
subject { described_class.new(args) }
@@ -6,115 +6,119 @@ describe ChatMessage::IssueMessage do
let(:args) do
{
user: {
- name: 'Test User',
- username: 'test.user',
- avatar_url: 'http://someavatar.com'
+ name: "Test User",
+ username: "test.user",
+ avatar_url: "http://someavatar.com",
},
- project_name: 'project_name',
- project_url: 'http://somewhere.com',
+ project_name: "project_name",
+ project_url: "http://somewhere.com",
object_attributes: {
- title: 'Issue title',
+ title: "Issue title",
id: 10,
iid: 100,
assignee_id: 1,
- url: 'http://url.com',
- action: 'open',
- state: 'opened',
- description: 'issue description'
- }
+ url: "http://url.com",
+ action: "open",
+ state: "opened",
+ description: "issue description",
+ },
}
end
- context 'without markdown' do
- let(:color) { '#C95823' }
+ context "without markdown" do
+ let(:color) { "#C95823" }
- context '#initialize' do
+ context "#initialize" do
before do
args[:object_attributes][:description] = nil
end
- it 'returns a non-null description' do
- expect(subject.description).to eq('')
+ it "returns a non-null description" do
+ expect(subject.description).to eq("")
end
end
- context 'open' do
- it 'returns a message regarding opening of issues' do
+ context "open" do
+ it "returns a message regarding opening of issues" do
expect(subject.pretext).to eq(
- '[<http://somewhere.com|project_name>] Issue opened by Test User (test.user)')
+ "[<http://somewhere.com|project_name>] Issue opened by Test User (test.user)"
+ )
expect(subject.attachments).to eq([
{
title: "#100 Issue title",
title_link: "http://url.com",
text: "issue description",
- color: color
- }
+ color: color,
+ },
])
end
end
- context 'close' do
+ context "close" do
before do
- args[:object_attributes][:action] = 'close'
- args[:object_attributes][:state] = 'closed'
+ args[:object_attributes][:action] = "close"
+ args[:object_attributes][:state] = "closed"
end
- it 'returns a message regarding closing of issues' do
+ it "returns a message regarding closing of issues" do
expect(subject.pretext). to eq(
- '[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> closed by Test User (test.user)')
+ "[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> closed by Test User (test.user)"
+ )
expect(subject.attachments).to be_empty
end
end
- context 'reopen' do
+ context "reopen" do
before do
- args[:object_attributes][:action] = 'reopen'
- args[:object_attributes][:state] = 'opened'
+ args[:object_attributes][:action] = "reopen"
+ args[:object_attributes][:state] = "opened"
end
- it 'returns a message regarding reopening of issues' do
+ it "returns a message regarding reopening of issues" do
expect(subject.pretext)
- .to eq('[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> opened by Test User (test.user)')
+ .to eq("[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> opened by Test User (test.user)")
expect(subject.attachments).to be_empty
end
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- context 'open' do
- it 'returns a message regarding opening of issues' do
+ context "open" do
+ it "returns a message regarding opening of issues" do
expect(subject.pretext).to eq(
- '[[project_name](http://somewhere.com)] Issue opened by Test User (test.user)')
- expect(subject.attachments).to eq('issue description')
+ "[[project_name](http://somewhere.com)] Issue opened by Test User (test.user)"
+ )
+ expect(subject.attachments).to eq("issue description")
expect(subject.activity).to eq({
- title: 'Issue opened by Test User (test.user)',
- subtitle: 'in [project_name](http://somewhere.com)',
- text: '[#100 Issue title](http://url.com)',
- image: 'http://someavatar.com'
+ title: "Issue opened by Test User (test.user)",
+ subtitle: "in [project_name](http://somewhere.com)",
+ text: "[#100 Issue title](http://url.com)",
+ image: "http://someavatar.com",
})
end
end
- context 'close' do
+ context "close" do
before do
- args[:object_attributes][:action] = 'close'
- args[:object_attributes][:state] = 'closed'
+ args[:object_attributes][:action] = "close"
+ args[:object_attributes][:state] = "closed"
end
- it 'returns a message regarding closing of issues' do
+ it "returns a message regarding closing of issues" do
expect(subject.pretext). to eq(
- '[[project_name](http://somewhere.com)] Issue [#100 Issue title](http://url.com) closed by Test User (test.user)')
+ "[[project_name](http://somewhere.com)] Issue [#100 Issue title](http://url.com) closed by Test User (test.user)"
+ )
expect(subject.attachments).to be_empty
expect(subject.activity).to eq({
- title: 'Issue closed by Test User (test.user)',
- subtitle: 'in [project_name](http://somewhere.com)',
- text: '[#100 Issue title](http://url.com)',
- image: 'http://someavatar.com'
+ title: "Issue closed by Test User (test.user)",
+ subtitle: "in [project_name](http://somewhere.com)",
+ text: "[#100 Issue title](http://url.com)",
+ image: "http://someavatar.com",
})
end
end
diff --git a/spec/models/project_services/chat_message/merge_message_spec.rb b/spec/models/project_services/chat_message/merge_message_spec.rb
index 7997b5bb6b9..e9129c39bef 100644
--- a/spec/models/project_services/chat_message/merge_message_spec.rb
+++ b/spec/models/project_services/chat_message/merge_message_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ChatMessage::MergeMessage do
subject { described_class.new(args) }
@@ -6,100 +6,104 @@ describe ChatMessage::MergeMessage do
let(:args) do
{
user: {
- name: 'Test User',
- username: 'test.user',
- avatar_url: 'http://someavatar.com'
+ name: "Test User",
+ username: "test.user",
+ avatar_url: "http://someavatar.com",
},
- project_name: 'project_name',
- project_url: 'http://somewhere.com',
+ project_name: "project_name",
+ project_url: "http://somewhere.com",
object_attributes: {
title: "Merge Request title\nSecond line",
id: 10,
iid: 100,
assignee_id: 1,
- url: 'http://url.com',
- state: 'opened',
- description: 'merge request description',
- source_branch: 'source_branch',
- target_branch: 'target_branch'
- }
+ url: "http://url.com",
+ state: "opened",
+ description: "merge request description",
+ source_branch: "source_branch",
+ target_branch: "target_branch",
+ },
}
end
# Integration point in EE
- context 'when state is overridden' do
- it 'respects the overridden state' do
- allow(subject).to receive(:state_or_action_text) { 'devoured' }
+ context "when state is overridden" do
+ it "respects the overridden state" do
+ allow(subject).to receive(:state_or_action_text) { "devoured" }
aggregate_failures do
- expect(subject.summary).not_to include('opened')
- expect(subject.summary).to include('devoured')
+ expect(subject.summary).not_to include("opened")
+ expect(subject.summary).to include("devoured")
activity_title = subject.activity[:title]
- expect(activity_title).not_to include('opened')
- expect(activity_title).to include('devoured')
+ expect(activity_title).not_to include("opened")
+ expect(activity_title).to include("devoured")
end
end
end
- context 'without markdown' do
- let(:color) { '#345' }
+ context "without markdown" do
+ let(:color) { "#345" }
- context 'open' do
- it 'returns a message regarding opening of merge requests' do
+ context "open" do
+ it "returns a message regarding opening of merge requests" do
expect(subject.pretext).to eq(
- 'Test User (test.user) opened <http://somewhere.com/merge_requests/100|!100 *Merge Request title*> in <http://somewhere.com|project_name>')
+ "Test User (test.user) opened <http://somewhere.com/merge_requests/100|!100 *Merge Request title*> in <http://somewhere.com|project_name>"
+ )
expect(subject.attachments).to be_empty
end
end
- context 'close' do
+ context "close" do
before do
- args[:object_attributes][:state] = 'closed'
+ args[:object_attributes][:state] = "closed"
end
- it 'returns a message regarding closing of merge requests' do
+ it "returns a message regarding closing of merge requests" do
expect(subject.pretext).to eq(
- 'Test User (test.user) closed <http://somewhere.com/merge_requests/100|!100 *Merge Request title*> in <http://somewhere.com|project_name>')
+ "Test User (test.user) closed <http://somewhere.com/merge_requests/100|!100 *Merge Request title*> in <http://somewhere.com|project_name>"
+ )
expect(subject.attachments).to be_empty
end
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- context 'open' do
- it 'returns a message regarding opening of merge requests' do
+ context "open" do
+ it "returns a message regarding opening of merge requests" do
expect(subject.pretext).to eq(
- 'Test User (test.user) opened [!100 *Merge Request title*](http://somewhere.com/merge_requests/100) in [project_name](http://somewhere.com)')
+ "Test User (test.user) opened [!100 *Merge Request title*](http://somewhere.com/merge_requests/100) in [project_name](http://somewhere.com)"
+ )
expect(subject.attachments).to be_empty
expect(subject.activity).to eq({
- title: 'Merge Request opened by Test User (test.user)',
- subtitle: 'in [project_name](http://somewhere.com)',
- text: '[!100 *Merge Request title*](http://somewhere.com/merge_requests/100)',
- image: 'http://someavatar.com'
+ title: "Merge Request opened by Test User (test.user)",
+ subtitle: "in [project_name](http://somewhere.com)",
+ text: "[!100 *Merge Request title*](http://somewhere.com/merge_requests/100)",
+ image: "http://someavatar.com",
})
end
end
- context 'close' do
+ context "close" do
before do
- args[:object_attributes][:state] = 'closed'
+ args[:object_attributes][:state] = "closed"
end
- it 'returns a message regarding closing of merge requests' do
+ it "returns a message regarding closing of merge requests" do
expect(subject.pretext).to eq(
- 'Test User (test.user) closed [!100 *Merge Request title*](http://somewhere.com/merge_requests/100) in [project_name](http://somewhere.com)')
+ "Test User (test.user) closed [!100 *Merge Request title*](http://somewhere.com/merge_requests/100) in [project_name](http://somewhere.com)"
+ )
expect(subject.attachments).to be_empty
expect(subject.activity).to eq({
- title: 'Merge Request closed by Test User (test.user)',
- subtitle: 'in [project_name](http://somewhere.com)',
- text: '[!100 *Merge Request title*](http://somewhere.com/merge_requests/100)',
- image: 'http://someavatar.com'
+ title: "Merge Request closed by Test User (test.user)",
+ subtitle: "in [project_name](http://somewhere.com)",
+ text: "[!100 *Merge Request title*](http://somewhere.com/merge_requests/100)",
+ image: "http://someavatar.com",
})
end
end
diff --git a/spec/models/project_services/chat_message/note_message_spec.rb b/spec/models/project_services/chat_message/note_message_spec.rb
index 5abbd7bec18..4416a1e87a7 100644
--- a/spec/models/project_services/chat_message/note_message_spec.rb
+++ b/spec/models/project_services/chat_message/note_message_spec.rb
@@ -1,189 +1,193 @@
-require 'spec_helper'
+require "spec_helper"
describe ChatMessage::NoteMessage do
subject { described_class.new(args) }
- let(:color) { '#345' }
+ let(:color) { "#345" }
let(:args) do
{
user: {
- name: 'Test User',
- username: 'test.user',
- avatar_url: 'http://fakeavatar'
+ name: "Test User",
+ username: "test.user",
+ avatar_url: "http://fakeavatar",
},
- project_name: 'project_name',
- project_url: 'http://somewhere.com',
+ project_name: "project_name",
+ project_url: "http://somewhere.com",
repository: {
- name: 'project_name',
- url: 'http://somewhere.com'
+ name: "project_name",
+ url: "http://somewhere.com",
},
object_attributes: {
id: 10,
- note: 'comment on a commit',
- url: 'http://url.com',
- noteable_type: 'Commit'
- }
+ note: "comment on a commit",
+ url: "http://url.com",
+ noteable_type: "Commit",
+ },
}
end
- context 'commit notes' do
+ context "commit notes" do
before do
- args[:object_attributes][:note] = 'comment on a commit'
- args[:object_attributes][:noteable_type] = 'Commit'
+ args[:object_attributes][:note] = "comment on a commit"
+ args[:object_attributes][:noteable_type] = "Commit"
args[:commit] = {
- id: '5f163b2b95e6f53cbd428f5f0b103702a52b9a23',
- message: "Added a commit message\ndetails\n123\n"
+ id: "5f163b2b95e6f53cbd428f5f0b103702a52b9a23",
+ message: "Added a commit message\ndetails\n123\n",
}
end
- context 'without markdown' do
- it 'returns a message regarding notes on commits' do
+ context "without markdown" do
+ it "returns a message regarding notes on commits" do
expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \
"commit 5f163b2b> in <http://somewhere.com|project_name>: " \
"*Added a commit message*")
expect(subject.attachments).to eq([{
- text: 'comment on a commit',
- color: color
+ text: "comment on a commit",
+ color: color,
}])
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- it 'returns a message regarding notes on commits' do
+ it "returns a message regarding notes on commits" do
expect(subject.pretext).to eq(
- 'Test User (test.user) [commented on commit 5f163b2b](http://url.com) in [project_name](http://somewhere.com): *Added a commit message*'
+ "Test User (test.user) [commented on commit 5f163b2b](http://url.com) in [project_name](http://somewhere.com): *Added a commit message*"
)
- expect(subject.attachments).to eq('comment on a commit')
+ expect(subject.attachments).to eq("comment on a commit")
expect(subject.activity).to eq({
- title: 'Test User (test.user) [commented on commit 5f163b2b](http://url.com)',
- subtitle: 'in [project_name](http://somewhere.com)',
- text: 'Added a commit message',
- image: 'http://fakeavatar'
+ title: "Test User (test.user) [commented on commit 5f163b2b](http://url.com)",
+ subtitle: "in [project_name](http://somewhere.com)",
+ text: "Added a commit message",
+ image: "http://fakeavatar",
})
end
end
end
- context 'merge request notes' do
+ context "merge request notes" do
before do
- args[:object_attributes][:note] = 'comment on a merge request'
- args[:object_attributes][:noteable_type] = 'MergeRequest'
+ args[:object_attributes][:note] = "comment on a merge request"
+ args[:object_attributes][:noteable_type] = "MergeRequest"
args[:merge_request] = {
id: 1,
iid: 30,
- title: "merge request title\ndetails\n"
+ title: "merge request title\ndetails\n",
}
end
- context 'without markdown' do
- it 'returns a message regarding notes on a merge request' do
+ context "without markdown" do
+ it "returns a message regarding notes on a merge request" do
expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \
"merge request !30> in <http://somewhere.com|project_name>: " \
"*merge request title*")
expect(subject.attachments).to eq([{
- text: 'comment on a merge request',
- color: color
+ text: "comment on a merge request",
+ color: color,
}])
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- it 'returns a message regarding notes on a merge request' do
+ it "returns a message regarding notes on a merge request" do
expect(subject.pretext).to eq(
- 'Test User (test.user) [commented on merge request !30](http://url.com) in [project_name](http://somewhere.com): *merge request title*')
- expect(subject.attachments).to eq('comment on a merge request')
+ "Test User (test.user) [commented on merge request !30](http://url.com) in [project_name](http://somewhere.com): *merge request title*"
+ )
+ expect(subject.attachments).to eq("comment on a merge request")
expect(subject.activity).to eq({
- title: 'Test User (test.user) [commented on merge request !30](http://url.com)',
- subtitle: 'in [project_name](http://somewhere.com)',
- text: 'merge request title',
- image: 'http://fakeavatar'
+ title: "Test User (test.user) [commented on merge request !30](http://url.com)",
+ subtitle: "in [project_name](http://somewhere.com)",
+ text: "merge request title",
+ image: "http://fakeavatar",
})
end
end
end
- context 'issue notes' do
+ context "issue notes" do
before do
- args[:object_attributes][:note] = 'comment on an issue'
- args[:object_attributes][:noteable_type] = 'Issue'
+ args[:object_attributes][:note] = "comment on an issue"
+ args[:object_attributes][:noteable_type] = "Issue"
args[:issue] = {
id: 1,
iid: 20,
- title: "issue title\ndetails\n"
+ title: "issue title\ndetails\n",
}
end
- context 'without markdown' do
- it 'returns a message regarding notes on an issue' do
+ context "without markdown" do
+ it "returns a message regarding notes on an issue" do
expect(subject.pretext).to eq(
"Test User (test.user) <http://url.com|commented on " \
"issue #20> in <http://somewhere.com|project_name>: " \
- "*issue title*")
+ "*issue title*"
+ )
expect(subject.attachments).to eq([{
- text: 'comment on an issue',
- color: color
+ text: "comment on an issue",
+ color: color,
}])
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- it 'returns a message regarding notes on an issue' do
+ it "returns a message regarding notes on an issue" do
expect(subject.pretext).to eq(
- 'Test User (test.user) [commented on issue #20](http://url.com) in [project_name](http://somewhere.com): *issue title*')
- expect(subject.attachments).to eq('comment on an issue')
+ "Test User (test.user) [commented on issue #20](http://url.com) in [project_name](http://somewhere.com): *issue title*"
+ )
+ expect(subject.attachments).to eq("comment on an issue")
expect(subject.activity).to eq({
- title: 'Test User (test.user) [commented on issue #20](http://url.com)',
- subtitle: 'in [project_name](http://somewhere.com)',
- text: 'issue title',
- image: 'http://fakeavatar'
+ title: "Test User (test.user) [commented on issue #20](http://url.com)",
+ subtitle: "in [project_name](http://somewhere.com)",
+ text: "issue title",
+ image: "http://fakeavatar",
})
end
end
end
- context 'project snippet notes' do
+ context "project snippet notes" do
before do
- args[:object_attributes][:note] = 'comment on a snippet'
- args[:object_attributes][:noteable_type] = 'Snippet'
+ args[:object_attributes][:note] = "comment on a snippet"
+ args[:object_attributes][:noteable_type] = "Snippet"
args[:snippet] = {
id: 5,
- title: "snippet title\ndetails\n"
+ title: "snippet title\ndetails\n",
}
end
- context 'without markdown' do
- it 'returns a message regarding notes on a project snippet' do
+ context "without markdown" do
+ it "returns a message regarding notes on a project snippet" do
expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \
"snippet $5> in <http://somewhere.com|project_name>: " \
"*snippet title*")
expect(subject.attachments).to eq([{
- text: 'comment on a snippet',
- color: color
+ text: "comment on a snippet",
+ color: color,
}])
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- it 'returns a message regarding notes on a project snippet' do
+ it "returns a message regarding notes on a project snippet" do
expect(subject.pretext).to eq(
- 'Test User (test.user) [commented on snippet $5](http://url.com) in [project_name](http://somewhere.com): *snippet title*')
- expect(subject.attachments).to eq('comment on a snippet')
+ "Test User (test.user) [commented on snippet $5](http://url.com) in [project_name](http://somewhere.com): *snippet title*"
+ )
+ expect(subject.attachments).to eq("comment on a snippet")
end
end
end
diff --git a/spec/models/project_services/chat_message/pipeline_message_spec.rb b/spec/models/project_services/chat_message/pipeline_message_spec.rb
index 0ff20400999..0281c454ca1 100644
--- a/spec/models/project_services/chat_message/pipeline_message_spec.rb
+++ b/spec/models/project_services/chat_message/pipeline_message_spec.rb
@@ -1,58 +1,58 @@
-require 'spec_helper'
+require "spec_helper"
describe ChatMessage::PipelineMessage do
subject { described_class.new(args) }
- let(:user) { { name: "The Hacker", username: 'hacker' } }
+ let(:user) { {name: "The Hacker", username: "hacker"} }
let(:duration) { 7210 }
let(:args) do
{
object_attributes: {
id: 123,
- sha: '97de212e80737a608d939f648d959671fb0a0142',
+ sha: "97de212e80737a608d939f648d959671fb0a0142",
tag: false,
- ref: 'develop',
+ ref: "develop",
status: status,
- duration: duration
+ duration: duration,
},
project: {
- path_with_namespace: 'project_name',
- web_url: 'http://example.gitlab.com'
+ path_with_namespace: "project_name",
+ web_url: "http://example.gitlab.com",
},
- user: user
+ user: user,
}
end
let(:combined_name) { "The Hacker (hacker)" }
- context 'without markdown' do
- context 'pipeline succeeded' do
- let(:status) { 'success' }
- let(:color) { 'good' }
- let(:message) { build_message('passed', combined_name) }
+ context "without markdown" do
+ context "pipeline succeeded" do
+ let(:status) { "success" }
+ let(:color) { "good" }
+ let(:message) { build_message("passed", combined_name) }
- it 'returns a message with information about succeeded build' do
+ it "returns a message with information about succeeded build" do
expect(subject.pretext).to be_empty
expect(subject.fallback).to eq(message)
expect(subject.attachments).to eq([text: message, color: color])
end
end
- context 'pipeline failed' do
- let(:status) { 'failed' }
- let(:color) { 'danger' }
+ context "pipeline failed" do
+ let(:status) { "failed" }
+ let(:color) { "danger" }
let(:message) { build_message(status, combined_name) }
- it 'returns a message with information about failed build' do
+ it "returns a message with information about failed build" do
expect(subject.pretext).to be_empty
expect(subject.fallback).to eq(message)
expect(subject.attachments).to eq([text: message, color: color])
end
- context 'when triggered by API therefore lacking user' do
+ context "when triggered by API therefore lacking user" do
let(:user) { nil }
- let(:message) { build_message(status, 'API') }
+ let(:message) { build_message(status, "API") }
- it 'returns a message stating it is by API' do
+ it "returns a message stating it is by API" do
expect(subject.pretext).to be_empty
expect(subject.fallback).to eq(message)
expect(subject.attachments).to eq([text: message, color: color])
@@ -68,56 +68,56 @@ describe ChatMessage::PipelineMessage do
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- context 'pipeline succeeded' do
- let(:status) { 'success' }
- let(:color) { 'good' }
- let(:message) { build_markdown_message('passed', combined_name) }
+ context "pipeline succeeded" do
+ let(:status) { "success" }
+ let(:color) { "good" }
+ let(:message) { build_markdown_message("passed", combined_name) }
- it 'returns a message with information about succeeded build' do
+ it "returns a message with information about succeeded build" do
expect(subject.pretext).to be_empty
expect(subject.attachments).to eq(message)
expect(subject.activity).to eq({
- title: 'Pipeline [#123](http://example.gitlab.com/pipelines/123) of branch [develop](http://example.gitlab.com/commits/develop) by The Hacker (hacker) passed',
- subtitle: 'in [project_name](http://example.gitlab.com)',
- text: 'in 02:00:10',
- image: ''
+ title: "Pipeline [#123](http://example.gitlab.com/pipelines/123) of branch [develop](http://example.gitlab.com/commits/develop) by The Hacker (hacker) passed",
+ subtitle: "in [project_name](http://example.gitlab.com)",
+ text: "in 02:00:10",
+ image: "",
})
end
end
- context 'pipeline failed' do
- let(:status) { 'failed' }
- let(:color) { 'danger' }
+ context "pipeline failed" do
+ let(:status) { "failed" }
+ let(:color) { "danger" }
let(:message) { build_markdown_message(status, combined_name) }
- it 'returns a message with information about failed build' do
+ it "returns a message with information about failed build" do
expect(subject.pretext).to be_empty
expect(subject.attachments).to eq(message)
expect(subject.activity).to eq({
- title: 'Pipeline [#123](http://example.gitlab.com/pipelines/123) of branch [develop](http://example.gitlab.com/commits/develop) by The Hacker (hacker) failed',
- subtitle: 'in [project_name](http://example.gitlab.com)',
- text: 'in 02:00:10',
- image: ''
+ title: "Pipeline [#123](http://example.gitlab.com/pipelines/123) of branch [develop](http://example.gitlab.com/commits/develop) by The Hacker (hacker) failed",
+ subtitle: "in [project_name](http://example.gitlab.com)",
+ text: "in 02:00:10",
+ image: "",
})
end
- context 'when triggered by API therefore lacking user' do
+ context "when triggered by API therefore lacking user" do
let(:user) { nil }
- let(:message) { build_markdown_message(status, 'API') }
+ let(:message) { build_markdown_message(status, "API") }
- it 'returns a message stating it is by API' do
+ it "returns a message stating it is by API" do
expect(subject.pretext).to be_empty
expect(subject.attachments).to eq(message)
expect(subject.activity).to eq({
- title: 'Pipeline [#123](http://example.gitlab.com/pipelines/123) of branch [develop](http://example.gitlab.com/commits/develop) by API failed',
- subtitle: 'in [project_name](http://example.gitlab.com)',
- text: 'in 02:00:10',
- image: ''
+ title: "Pipeline [#123](http://example.gitlab.com/pipelines/123) of branch [develop](http://example.gitlab.com/commits/develop) by API failed",
+ subtitle: "in [project_name](http://example.gitlab.com)",
+ text: "in 02:00:10",
+ image: "",
})
end
end
diff --git a/spec/models/project_services/chat_message/push_message_spec.rb b/spec/models/project_services/chat_message/push_message_spec.rb
index 973d6bdb2a0..68de0c4091e 100644
--- a/spec/models/project_services/chat_message/push_message_spec.rb
+++ b/spec/models/project_services/chat_message/push_message_spec.rb
@@ -1,205 +1,214 @@
-require 'spec_helper'
+require "spec_helper"
describe ChatMessage::PushMessage do
subject { described_class.new(args) }
let(:args) do
{
- after: 'after',
- before: 'before',
- project_name: 'project_name',
- ref: 'refs/heads/master',
- user_name: 'test.user',
- user_avatar: 'http://someavatar.com',
- project_url: 'http://url.com'
+ after: "after",
+ before: "before",
+ project_name: "project_name",
+ ref: "refs/heads/master",
+ user_name: "test.user",
+ user_avatar: "http://someavatar.com",
+ project_url: "http://url.com",
}
end
- let(:color) { '#345' }
+ let(:color) { "#345" }
- context 'push' do
+ context "push" do
before do
args[:commits] = [
- { message: 'message1', url: 'http://url1.com', id: 'abcdefghijkl', author: { name: 'author1' } },
- { message: 'message2', url: 'http://url2.com', id: '123456789012', author: { name: 'author2' } }
+ {message: "message1", url: "http://url1.com", id: "abcdefghijkl", author: {name: "author1"}},
+ {message: "message2", url: "http://url2.com", id: "123456789012", author: {name: "author2"}},
]
end
- context 'without markdown' do
- it 'returns a message regarding pushes' do
+ context "without markdown" do
+ it "returns a message regarding pushes" do
expect(subject.pretext).to eq(
- 'test.user pushed to branch <http://url.com/commits/master|master> of '\
- '<http://url.com|project_name> (<http://url.com/compare/before...after|Compare changes>)')
+ "test.user pushed to branch <http://url.com/commits/master|master> of "\
+ "<http://url.com|project_name> (<http://url.com/compare/before...after|Compare changes>)"
+ )
expect(subject.attachments).to eq([{
text: "<http://url1.com|abcdefgh>: message1 - author1\n\n"\
"<http://url2.com|12345678>: message2 - author2",
- color: color
+ color: color,
}])
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- it 'returns a message regarding pushes' do
+ it "returns a message regarding pushes" do
expect(subject.pretext).to eq(
- 'test.user pushed to branch [master](http://url.com/commits/master) of [project_name](http://url.com) ([Compare changes](http://url.com/compare/before...after))')
+ "test.user pushed to branch [master](http://url.com/commits/master) of [project_name](http://url.com) ([Compare changes](http://url.com/compare/before...after))"
+ )
expect(subject.attachments).to eq(
- "[abcdefgh](http://url1.com): message1 - author1\n\n[12345678](http://url2.com): message2 - author2")
+ "[abcdefgh](http://url1.com): message1 - author1\n\n[12345678](http://url2.com): message2 - author2"
+ )
expect(subject.activity).to eq(
- title: 'test.user pushed to branch [master](http://url.com/commits/master)',
- subtitle: 'in [project_name](http://url.com)',
- text: '[Compare changes](http://url.com/compare/before...after)',
- image: 'http://someavatar.com'
+ title: "test.user pushed to branch [master](http://url.com/commits/master)",
+ subtitle: "in [project_name](http://url.com)",
+ text: "[Compare changes](http://url.com/compare/before...after)",
+ image: "http://someavatar.com"
)
end
end
end
- context 'tag push' do
+ context "tag push" do
let(:args) do
{
- after: 'after',
+ after: "after",
before: Gitlab::Git::BLANK_SHA,
- project_name: 'project_name',
- ref: 'refs/tags/new_tag',
- user_name: 'test.user',
- user_avatar: 'http://someavatar.com',
- project_url: 'http://url.com'
+ project_name: "project_name",
+ ref: "refs/tags/new_tag",
+ user_name: "test.user",
+ user_avatar: "http://someavatar.com",
+ project_url: "http://url.com",
}
end
- context 'without markdown' do
- it 'returns a message regarding pushes' do
- expect(subject.pretext).to eq('test.user pushed new tag ' \
- '<http://url.com/commits/new_tag|new_tag> to ' \
- '<http://url.com|project_name>')
+ context "without markdown" do
+ it "returns a message regarding pushes" do
+ expect(subject.pretext).to eq("test.user pushed new tag " \
+ "<http://url.com/commits/new_tag|new_tag> to " \
+ "<http://url.com|project_name>")
expect(subject.attachments).to be_empty
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- it 'returns a message regarding pushes' do
+ it "returns a message regarding pushes" do
expect(subject.pretext).to eq(
- 'test.user pushed new tag [new_tag](http://url.com/commits/new_tag) to [project_name](http://url.com)')
+ "test.user pushed new tag [new_tag](http://url.com/commits/new_tag) to [project_name](http://url.com)"
+ )
expect(subject.attachments).to be_empty
expect(subject.activity).to eq(
- title: 'test.user pushed new tag [new_tag](http://url.com/commits/new_tag)',
- subtitle: 'in [project_name](http://url.com)',
- text: '[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)',
- image: 'http://someavatar.com'
+ title: "test.user pushed new tag [new_tag](http://url.com/commits/new_tag)",
+ subtitle: "in [project_name](http://url.com)",
+ text: "[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)",
+ image: "http://someavatar.com"
)
end
end
end
- context 'removed tag' do
+ context "removed tag" do
let(:args) do
{
after: Gitlab::Git::BLANK_SHA,
- before: 'before',
- project_name: 'project_name',
- ref: 'refs/tags/new_tag',
- user_name: 'test.user',
- user_avatar: 'http://someavatar.com',
- project_url: 'http://url.com'
+ before: "before",
+ project_name: "project_name",
+ ref: "refs/tags/new_tag",
+ user_name: "test.user",
+ user_avatar: "http://someavatar.com",
+ project_url: "http://url.com",
}
end
- context 'without markdown' do
- it 'returns a message regarding removal of tags' do
- expect(subject.pretext).to eq('test.user removed tag ' \
- 'new_tag from ' \
- '<http://url.com|project_name>')
+ context "without markdown" do
+ it "returns a message regarding removal of tags" do
+ expect(subject.pretext).to eq("test.user removed tag " \
+ "new_tag from " \
+ "<http://url.com|project_name>")
expect(subject.attachments).to be_empty
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- it 'returns a message regarding removal of tags' do
+ it "returns a message regarding removal of tags" do
expect(subject.pretext).to eq(
- 'test.user removed tag new_tag from [project_name](http://url.com)')
+ "test.user removed tag new_tag from [project_name](http://url.com)"
+ )
expect(subject.attachments).to be_empty
expect(subject.activity).to eq(
- title: 'test.user removed tag new_tag',
- subtitle: 'in [project_name](http://url.com)',
- text: '[Compare changes](http://url.com/compare/before...0000000000000000000000000000000000000000)',
- image: 'http://someavatar.com'
+ title: "test.user removed tag new_tag",
+ subtitle: "in [project_name](http://url.com)",
+ text: "[Compare changes](http://url.com/compare/before...0000000000000000000000000000000000000000)",
+ image: "http://someavatar.com"
)
end
end
end
- context 'new branch' do
+ context "new branch" do
before do
args[:before] = Gitlab::Git::BLANK_SHA
end
- context 'without markdown' do
- it 'returns a message regarding a new branch' do
+ context "without markdown" do
+ it "returns a message regarding a new branch" do
expect(subject.pretext).to eq(
- 'test.user pushed new branch <http://url.com/commits/master|master> to '\
- '<http://url.com|project_name>')
+ "test.user pushed new branch <http://url.com/commits/master|master> to "\
+ "<http://url.com|project_name>"
+ )
expect(subject.attachments).to be_empty
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- it 'returns a message regarding a new branch' do
+ it "returns a message regarding a new branch" do
expect(subject.pretext).to eq(
- 'test.user pushed new branch [master](http://url.com/commits/master) to [project_name](http://url.com)')
+ "test.user pushed new branch [master](http://url.com/commits/master) to [project_name](http://url.com)"
+ )
expect(subject.attachments).to be_empty
expect(subject.activity).to eq(
- title: 'test.user pushed new branch [master](http://url.com/commits/master)',
- subtitle: 'in [project_name](http://url.com)',
- text: '[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)',
- image: 'http://someavatar.com'
+ title: "test.user pushed new branch [master](http://url.com/commits/master)",
+ subtitle: "in [project_name](http://url.com)",
+ text: "[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)",
+ image: "http://someavatar.com"
)
end
end
end
- context 'removed branch' do
+ context "removed branch" do
before do
args[:after] = Gitlab::Git::BLANK_SHA
end
- context 'without markdown' do
- it 'returns a message regarding a removed branch' do
+ context "without markdown" do
+ it "returns a message regarding a removed branch" do
expect(subject.pretext).to eq(
- 'test.user removed branch master from <http://url.com|project_name>')
+ "test.user removed branch master from <http://url.com|project_name>"
+ )
expect(subject.attachments).to be_empty
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- it 'returns a message regarding a removed branch' do
+ it "returns a message regarding a removed branch" do
expect(subject.pretext).to eq(
- 'test.user removed branch master from [project_name](http://url.com)')
+ "test.user removed branch master from [project_name](http://url.com)"
+ )
expect(subject.attachments).to be_empty
expect(subject.activity).to eq(
- title: 'test.user removed branch master',
- subtitle: 'in [project_name](http://url.com)',
- text: '[Compare changes](http://url.com/compare/before...0000000000000000000000000000000000000000)',
- image: 'http://someavatar.com'
+ title: "test.user removed branch master",
+ subtitle: "in [project_name](http://url.com)",
+ text: "[Compare changes](http://url.com/compare/before...0000000000000000000000000000000000000000)",
+ image: "http://someavatar.com"
)
end
end
diff --git a/spec/models/project_services/chat_message/wiki_page_message_spec.rb b/spec/models/project_services/chat_message/wiki_page_message_spec.rb
index 7efcba9bcfd..888dd70510e 100644
--- a/spec/models/project_services/chat_message/wiki_page_message_spec.rb
+++ b/spec/models/project_services/chat_message/wiki_page_message_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ChatMessage::WikiPageMessage do
subject { described_class.new(args) }
@@ -6,160 +6,164 @@ describe ChatMessage::WikiPageMessage do
let(:args) do
{
user: {
- name: 'Test User',
- username: 'test.user',
- avatar_url: 'http://someavatar.com'
+ name: "Test User",
+ username: "test.user",
+ avatar_url: "http://someavatar.com",
},
- project_name: 'project_name',
- project_url: 'http://somewhere.com',
+ project_name: "project_name",
+ project_url: "http://somewhere.com",
object_attributes: {
- title: 'Wiki page title',
- url: 'http://url.com',
- content: 'Wiki page description'
- }
+ title: "Wiki page title",
+ url: "http://url.com",
+ content: "Wiki page description",
+ },
}
end
- context 'without markdown' do
- describe '#pretext' do
+ context "without markdown" do
+ describe "#pretext" do
context 'when :action == "create"' do
before do
- args[:object_attributes][:action] = 'create'
+ args[:object_attributes][:action] = "create"
end
- it 'returns a message that a new wiki page was created' do
+ it "returns a message that a new wiki page was created" do
expect(subject.pretext).to eq(
- 'Test User (test.user) created <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\
- '*Wiki page title*')
+ "Test User (test.user) created <http://url.com|wiki page> in <http://somewhere.com|project_name>: "\
+ "*Wiki page title*"
+ )
end
end
context 'when :action == "update"' do
before do
- args[:object_attributes][:action] = 'update'
+ args[:object_attributes][:action] = "update"
end
- it 'returns a message that a wiki page was updated' do
+ it "returns a message that a wiki page was updated" do
expect(subject.pretext).to eq(
- 'Test User (test.user) edited <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\
- '*Wiki page title*')
+ "Test User (test.user) edited <http://url.com|wiki page> in <http://somewhere.com|project_name>: "\
+ "*Wiki page title*"
+ )
end
end
end
- describe '#attachments' do
- let(:color) { '#345' }
+ describe "#attachments" do
+ let(:color) { "#345" }
context 'when :action == "create"' do
before do
- args[:object_attributes][:action] = 'create'
+ args[:object_attributes][:action] = "create"
end
- it 'returns the attachment for a new wiki page' do
+ it "returns the attachment for a new wiki page" do
expect(subject.attachments).to eq([
{
text: "Wiki page description",
- color: color
- }
+ color: color,
+ },
])
end
end
context 'when :action == "update"' do
before do
- args[:object_attributes][:action] = 'update'
+ args[:object_attributes][:action] = "update"
end
- it 'returns the attachment for an updated wiki page' do
+ it "returns the attachment for an updated wiki page" do
expect(subject.attachments).to eq([
{
text: "Wiki page description",
- color: color
- }
+ color: color,
+ },
])
end
end
end
end
- context 'with markdown' do
+ context "with markdown" do
before do
args[:markdown] = true
end
- describe '#pretext' do
+ describe "#pretext" do
context 'when :action == "create"' do
before do
- args[:object_attributes][:action] = 'create'
+ args[:object_attributes][:action] = "create"
end
- it 'returns a message that a new wiki page was created' do
+ it "returns a message that a new wiki page was created" do
expect(subject.pretext).to eq(
- 'Test User (test.user) created [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*')
+ "Test User (test.user) created [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*"
+ )
end
end
context 'when :action == "update"' do
before do
- args[:object_attributes][:action] = 'update'
+ args[:object_attributes][:action] = "update"
end
- it 'returns a message that a wiki page was updated' do
+ it "returns a message that a wiki page was updated" do
expect(subject.pretext).to eq(
- 'Test User (test.user) edited [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*')
+ "Test User (test.user) edited [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*"
+ )
end
end
end
- describe '#attachments' do
+ describe "#attachments" do
context 'when :action == "create"' do
before do
- args[:object_attributes][:action] = 'create'
+ args[:object_attributes][:action] = "create"
end
- it 'returns the attachment for a new wiki page' do
- expect(subject.attachments).to eq('Wiki page description')
+ it "returns the attachment for a new wiki page" do
+ expect(subject.attachments).to eq("Wiki page description")
end
end
context 'when :action == "update"' do
before do
- args[:object_attributes][:action] = 'update'
+ args[:object_attributes][:action] = "update"
end
- it 'returns the attachment for an updated wiki page' do
- expect(subject.attachments).to eq('Wiki page description')
+ it "returns the attachment for an updated wiki page" do
+ expect(subject.attachments).to eq("Wiki page description")
end
end
end
- describe '#activity' do
+ describe "#activity" do
context 'when :action == "create"' do
before do
- args[:object_attributes][:action] = 'create'
+ args[:object_attributes][:action] = "create"
end
- it 'returns the attachment for a new wiki page' do
+ it "returns the attachment for a new wiki page" do
expect(subject.activity).to eq({
- title: 'Test User (test.user) created [wiki page](http://url.com)',
- subtitle: 'in [project_name](http://somewhere.com)',
- text: 'Wiki page title',
- image: 'http://someavatar.com'
+ title: "Test User (test.user) created [wiki page](http://url.com)",
+ subtitle: "in [project_name](http://somewhere.com)",
+ text: "Wiki page title",
+ image: "http://someavatar.com",
})
end
end
context 'when :action == "update"' do
before do
- args[:object_attributes][:action] = 'update'
+ args[:object_attributes][:action] = "update"
end
- it 'returns the attachment for an updated wiki page' do
+ it "returns the attachment for an updated wiki page" do
expect(subject.activity).to eq({
- title: 'Test User (test.user) edited [wiki page](http://url.com)',
- subtitle: 'in [project_name](http://somewhere.com)',
- text: 'Wiki page title',
- image: 'http://someavatar.com'
+ title: "Test User (test.user) edited [wiki page](http://url.com)",
+ subtitle: "in [project_name](http://somewhere.com)",
+ text: "Wiki page title",
+ image: "http://someavatar.com",
})
end
end
diff --git a/spec/models/project_services/chat_notification_service_spec.rb b/spec/models/project_services/chat_notification_service_spec.rb
index 46713df77da..50646aa3de9 100644
--- a/spec/models/project_services/chat_notification_service_spec.rb
+++ b/spec/models/project_services/chat_notification_service_spec.rb
@@ -1,7 +1,7 @@
-require 'spec_helper'
+require "spec_helper"
describe ChatNotificationService do
- describe 'Associations' do
+ describe "Associations" do
before do
allow(subject).to receive(:activated?).and_return(true)
end
@@ -9,17 +9,17 @@ describe ChatNotificationService do
it { is_expected.to validate_presence_of :webhook }
end
- describe '#can_test?' do
- context 'with empty repository' do
- it 'returns true' do
+ describe "#can_test?" do
+ context "with empty repository" do
+ it "returns true" do
subject.project = create(:project, :empty_repo)
expect(subject.can_test?).to be true
end
end
- context 'with repository' do
- it 'returns true' do
+ context "with repository" do
+ it "returns true" do
subject.project = create(:project, :repository)
expect(subject.can_test?).to be true
@@ -27,11 +27,11 @@ describe ChatNotificationService do
end
end
- describe '#execute' do
+ describe "#execute" do
let(:chat_service) { described_class.new }
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
- let(:webhook_url) { 'https://example.gitlab.com/' }
+ let(:webhook_url) { "https://example.gitlab.com/" }
before do
allow(chat_service).to receive_messages(
@@ -46,31 +46,31 @@ describe ChatNotificationService do
subject.active = true
end
- context 'with a repository' do
- it 'returns true' do
+ context "with a repository" do
+ it "returns true" do
subject.project = project
data = Gitlab::DataBuilder::Push.build_sample(project, user)
expect(Slack::Notifier).to receive(:new)
- .with(webhook_url, {})
- .and_return(
- double(:slack_service).as_null_object
- )
+ .with(webhook_url, {})
+ .and_return(
+ double(:slack_service).as_null_object
+ )
expect(chat_service.execute(data)).to be true
end
end
- context 'with an empty repository' do
- it 'returns true' do
+ context "with an empty repository" do
+ it "returns true" do
subject.project = create(:project, :empty_repo)
data = Gitlab::DataBuilder::Push.build_sample(subject.project, user)
expect(Slack::Notifier).to receive(:new)
- .with(webhook_url, {})
- .and_return(
- double(:slack_service).as_null_object
- )
+ .with(webhook_url, {})
+ .and_return(
+ double(:slack_service).as_null_object
+ )
expect(chat_service.execute(data)).to be true
end
diff --git a/spec/models/project_services/custom_issue_tracker_service_spec.rb b/spec/models/project_services/custom_issue_tracker_service_spec.rb
index 7e1b1a4f2af..94facd7287b 100644
--- a/spec/models/project_services/custom_issue_tracker_service_spec.rb
+++ b/spec/models/project_services/custom_issue_tracker_service_spec.rb
@@ -1,13 +1,13 @@
-require 'spec_helper'
+require "spec_helper"
describe CustomIssueTrackerService do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -15,12 +15,12 @@ describe CustomIssueTrackerService do
it { is_expected.to validate_presence_of(:project_url) }
it { is_expected.to validate_presence_of(:issues_url) }
it { is_expected.to validate_presence_of(:new_issue_url) }
- it_behaves_like 'issue tracker service URL attribute', :project_url
- it_behaves_like 'issue tracker service URL attribute', :issues_url
- it_behaves_like 'issue tracker service URL attribute', :new_issue_url
+ it_behaves_like "issue tracker service URL attribute", :project_url
+ it_behaves_like "issue tracker service URL attribute", :issues_url
+ it_behaves_like "issue tracker service URL attribute", :new_issue_url
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -30,19 +30,19 @@ describe CustomIssueTrackerService do
it { is_expected.not_to validate_presence_of(:new_issue_url) }
end
- context 'title' do
+ context "title" do
let(:issue_tracker) { described_class.new(properties: {}) }
- it 'sets a default title' do
+ it "sets a default title" do
issue_tracker.title = nil
- expect(issue_tracker.title).to eq('Custom Issue Tracker')
+ expect(issue_tracker.title).to eq("Custom Issue Tracker")
end
- it 'sets the custom title' do
- issue_tracker.title = 'test title'
+ it "sets the custom title" do
+ issue_tracker.title = "test title"
- expect(issue_tracker.title).to eq('test title')
+ expect(issue_tracker.title).to eq("test title")
end
end
end
diff --git a/spec/models/project_services/discord_service_spec.rb b/spec/models/project_services/discord_service_spec.rb
index be82f223478..81af05f1c3b 100644
--- a/spec/models/project_services/discord_service_spec.rb
+++ b/spec/models/project_services/discord_service_spec.rb
@@ -5,7 +5,7 @@ require "spec_helper"
describe DiscordService do
it_behaves_like "chat service", "Discord notifications" do
let(:client) { Discordrb::Webhooks::Client }
- let(:client_arguments) { { url: webhook_url } }
+ let(:client_arguments) { {url: webhook_url} }
let(:content_key) { :content }
end
end
diff --git a/spec/models/project_services/drone_ci_service_spec.rb b/spec/models/project_services/drone_ci_service_spec.rb
index 26597d9b83c..4ba67693870 100644
--- a/spec/models/project_services/drone_ci_service_spec.rb
+++ b/spec/models/project_services/drone_ci_service_spec.rb
@@ -1,25 +1,25 @@
-require 'spec_helper'
+require "spec_helper"
describe DroneCiService, :use_clean_rails_memory_store_caching do
include ReactiveCachingHelpers
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
it { is_expected.to have_one(:service_hook) }
end
- describe 'validations' do
- context 'active' do
+ describe "validations" do
+ context "active" do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:token) }
it { is_expected.to validate_presence_of(:drone_url) }
- it_behaves_like 'issue tracker service URL attribute', :drone_url
+ it_behaves_like "issue tracker service URL attribute", :drone_url
end
- context 'inactive' do
+ context "inactive" do
before do
subject.active = false
end
@@ -31,12 +31,12 @@ describe DroneCiService, :use_clean_rails_memory_store_caching do
shared_context :drone_ci_service do
let(:drone) { DroneCiService.new }
- let(:project) { create(:project, :repository, name: 'project') }
+ let(:project) { create(:project, :repository, name: "project") }
let(:path) { project.full_path }
- let(:drone_url) { 'http://drone.example.com' }
- let(:sha) { '2ab7834c' }
- let(:branch) { 'dev' }
- let(:token) { 'secret' }
+ let(:drone_url) { "http://drone.example.com" }
+ let(:sha) { "2ab7834c" }
+ let(:branch) { "dev" }
+ let(:token) { "secret" }
let(:iid) { rand(1..9999) }
# URL's
@@ -54,11 +54,11 @@ describe DroneCiService, :use_clean_rails_memory_store_caching do
end
def stub_request(status: 200, body: nil)
- body ||= %q({"status":"success"})
+ body ||= '{"status":"success"}'
WebMock.stub_request(:get, commit_status_path).to_return(
status: status,
- headers: { 'Content-Type' => 'application/json' },
+ headers: {"Content-Type" => "application/json"},
body: body
)
end
@@ -71,42 +71,42 @@ describe DroneCiService, :use_clean_rails_memory_store_caching do
it { expect(drone.commit_status_path(sha, branch)).to eq(commit_status_path) }
end
- describe '#commit_status' do
+ describe "#commit_status" do
include_context :drone_ci_service
- it 'returns the contents of the reactive cache' do
- stub_reactive_cache(drone, { commit_status: 'foo' }, 'sha', 'ref')
+ it "returns the contents of the reactive cache" do
+ stub_reactive_cache(drone, {commit_status: "foo"}, "sha", "ref")
- expect(drone.commit_status('sha', 'ref')).to eq('foo')
+ expect(drone.commit_status("sha", "ref")).to eq("foo")
end
end
- describe '#calculate_reactive_cache' do
+ describe "#calculate_reactive_cache" do
include_context :drone_ci_service
- context '#commit_status' do
+ context "#commit_status" do
subject { drone.calculate_reactive_cache(sha, branch)[:commit_status] }
- it 'sets commit status to :error when status is 500' do
+ it "sets commit status to :error when status is 500" do
stub_request(status: 500)
is_expected.to eq(:error)
end
- it 'sets commit status to :error when status is 404' do
+ it "sets commit status to :error when status is 404" do
stub_request(status: 404)
is_expected.to eq(:error)
end
{
- "killed" => :canceled,
+ "killed" => :canceled,
"failure" => :failed,
- "error" => :failed,
- "success" => "success"
+ "error" => :failed,
+ "success" => "success",
}.each do |drone_status, our_status|
it "sets commit status to #{our_status.inspect} when returned status is #{drone_status.inspect}" do
- stub_request(body: %Q({"status":"#{drone_status}"}))
+ stub_request(body: %({"status":"#{drone_status}"}))
is_expected.to eq(our_status)
end
@@ -117,7 +117,7 @@ describe DroneCiService, :use_clean_rails_memory_store_caching do
describe "execute" do
include_context :drone_ci_service
- let(:user) { create(:user, username: 'username') }
+ let(:user) { create(:user, username: "username") }
let(:push_sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
diff --git a/spec/models/project_services/emails_on_push_service_spec.rb b/spec/models/project_services/emails_on_push_service_spec.rb
index d9b7010e5e5..bb882a543b9 100644
--- a/spec/models/project_services/emails_on_push_service_spec.rb
+++ b/spec/models/project_services/emails_on_push_service_spec.rb
@@ -1,8 +1,8 @@
-require 'spec_helper'
+require "spec_helper"
describe EmailsOnPushService do
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -10,7 +10,7 @@ describe EmailsOnPushService do
it { is_expected.to validate_presence_of(:recipients) }
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
diff --git a/spec/models/project_services/external_wiki_service_spec.rb b/spec/models/project_services/external_wiki_service_spec.rb
index 62fd97b038b..3848a165e97 100644
--- a/spec/models/project_services/external_wiki_service_spec.rb
+++ b/spec/models/project_services/external_wiki_service_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ExternalWikiService do
describe "Associations" do
@@ -6,17 +6,17 @@ describe ExternalWikiService do
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:external_wiki_url) }
- it_behaves_like 'issue tracker service URL attribute', :external_wiki_url
+ it_behaves_like "issue tracker service URL attribute", :external_wiki_url
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb
index fabcb142858..f3396aed013 100644
--- a/spec/models/project_services/flowdock_service_spec.rb
+++ b/spec/models/project_services/flowdock_service_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe FlowdockService do
describe "Associations" do
@@ -6,8 +6,8 @@ describe FlowdockService do
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -15,7 +15,7 @@ describe FlowdockService do
it { is_expected.to validate_presence_of(:token) }
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -34,10 +34,10 @@ describe FlowdockService do
project_id: project.id,
project: project,
service_hook: true,
- token: 'verySecret'
+ token: "verySecret"
)
@sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
- @api_url = 'https://api.flowdock.com/v1/messages'
+ @api_url = "https://api.flowdock.com/v1/messages"
WebMock.stub_request(:post, @api_url)
end
diff --git a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb
index 3237b660a16..e8f9cf3731a 100644
--- a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb
+++ b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe GitlabIssueTrackerService do
describe "Associations" do
@@ -6,43 +6,43 @@ describe GitlabIssueTrackerService do
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
subject { described_class.new(project: create(:project), active: true) }
it { is_expected.to validate_presence_of(:issues_url) }
- it_behaves_like 'issue tracker service URL attribute', :issues_url
+ it_behaves_like "issue tracker service URL attribute", :issues_url
end
- context 'when service is inactive' do
+ context "when service is inactive" do
subject { described_class.new(project: create(:project), active: false) }
it { is_expected.not_to validate_presence_of(:issues_url) }
end
end
- describe 'project and issue urls' do
+ describe "project and issue urls" do
let(:project) { create(:project) }
let(:service) { project.create_gitlab_issue_tracker_service(active: true) }
- context 'with absolute urls' do
+ context "with absolute urls" do
before do
allow(described_class).to receive(:default_url_options).and_return(script_name: "/gitlab/root")
end
- it 'gives the correct path' do
+ it "gives the correct path" do
expect(service.project_url).to eq("http://#{Gitlab.config.gitlab.host}/gitlab/root/#{project.full_path}/issues")
expect(service.new_issue_url).to eq("http://#{Gitlab.config.gitlab.host}/gitlab/root/#{project.full_path}/issues/new")
expect(service.issue_url(432)).to eq("http://#{Gitlab.config.gitlab.host}/gitlab/root/#{project.full_path}/issues/432")
end
end
- context 'with relative urls' do
+ context "with relative urls" do
before do
allow(described_class).to receive(:default_url_options).and_return(script_name: "/gitlab/root")
end
- it 'gives the correct path' do
+ it "gives the correct path" do
expect(service.issue_tracker_path).to eq("/gitlab/root/#{project.full_path}/issues")
expect(service.new_issue_path).to eq("/gitlab/root/#{project.full_path}/issues/new")
expect(service.issue_path(432)).to eq("/gitlab/root/#{project.full_path}/issues/432")
diff --git a/spec/models/project_services/irker_service_spec.rb b/spec/models/project_services/irker_service_spec.rb
index cb9ca76fc3f..3cf53487375 100644
--- a/spec/models/project_services/irker_service_spec.rb
+++ b/spec/models/project_services/irker_service_spec.rb
@@ -1,15 +1,15 @@
-require 'spec_helper'
-require 'socket'
-require 'json'
+require "spec_helper"
+require "socket"
+require "json"
describe IrkerService do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -17,7 +17,7 @@ describe IrkerService do
it { is_expected.to validate_presence_of(:recipients) }
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -26,7 +26,7 @@ describe IrkerService do
end
end
- describe 'Execute' do
+ describe "Execute" do
let(:irker) { described_class.new }
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
@@ -34,11 +34,11 @@ describe IrkerService do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
- let(:recipients) { '#commits irc://test.net/#test ftp://bad' }
- let(:colorize_messages) { '1' }
+ let(:recipients) { "#commits irc://test.net/#test ftp://bad" }
+ let(:colorize_messages) { "1" }
before do
- @irker_server = TCPServer.new 'localhost', 0
+ @irker_server = TCPServer.new "localhost", 0
allow(irker).to receive_messages(
active: true,
@@ -47,9 +47,10 @@ describe IrkerService do
service_hook: true,
server_host: @irker_server.addr[2],
server_port: @irker_server.addr[1],
- default_irc_uri: 'irc://chat.freenode.net/',
+ default_irc_uri: "irc://chat.freenode.net/",
recipients: recipients,
- colorize_messages: colorize_messages)
+ colorize_messages: colorize_messages
+ )
irker.valid?
end
@@ -58,15 +59,15 @@ describe IrkerService do
@irker_server.close
end
- it 'sends valid JSON messages to an Irker listener' do
+ it "sends valid JSON messages to an Irker listener" do
irker.execute(sample_data)
conn = @irker_server.accept
conn.readlines.each do |line|
msg = JSON.parse(line.chomp("\n"))
- expect(msg.keys).to match_array(%w(to privmsg))
- expect(msg['to']).to match_array(["irc://chat.freenode.net/#commits",
- "irc://test.net/#test"])
+ expect(msg.keys).to match_array(%w[to privmsg])
+ expect(msg["to"]).to match_array(["irc://chat.freenode.net/#commits",
+ "irc://test.net/#test",])
end
conn.close
end
diff --git a/spec/models/project_services/issue_tracker_service_spec.rb b/spec/models/project_services/issue_tracker_service_spec.rb
index e6a1752576b..a797533dea4 100644
--- a/spec/models/project_services/issue_tracker_service_spec.rb
+++ b/spec/models/project_services/issue_tracker_service_spec.rb
@@ -1,29 +1,29 @@
-require 'spec_helper'
+require "spec_helper"
describe IssueTrackerService do
- describe 'Validations' do
+ describe "Validations" do
let(:project) { create :project }
- describe 'only one issue tracker per project' do
+ describe "only one issue tracker per project" do
let(:service) { RedmineService.new(project: project, active: true) }
before do
create(:custom_issue_tracker_service, project: project)
end
- context 'when service is changed manually by user' do
- it 'executes the validation' do
+ context "when service is changed manually by user" do
+ it "executes the validation" do
valid = service.valid?(:manual_change)
expect(valid).to be_falsey
expect(service.errors[:base]).to include(
- 'Another issue tracker is already in use. Only one issue tracker service can be active at a time'
+ "Another issue tracker is already in use. Only one issue tracker service can be active at a time"
)
end
end
- context 'when service is changed internally' do
- it 'does not execute the validation' do
+ context "when service is changed internally" do
+ it "does not execute the validation" do
expect(service.valid?).to be_truthy
end
end
diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb
index 5428fcb1271..4840753e52b 100644
--- a/spec/models/project_services/jira_service_spec.rb
+++ b/spec/models/project_services/jira_service_spec.rb
@@ -1,52 +1,52 @@
-require 'spec_helper'
+require "spec_helper"
describe JiraService do
include Gitlab::Routing
include AssetsHelpers
- describe '#options' do
+ describe "#options" do
let(:service) do
described_class.new(
project: build_stubbed(:project),
active: true,
- username: 'username',
- password: 'test',
+ username: "username",
+ password: "test",
jira_issue_transition_id: 24,
- url: 'http://jira.test.com/path/'
+ url: "http://jira.test.com/path/"
)
end
- it 'sets the URL properly' do
+ it "sets the URL properly" do
# jira-ruby gem parses the URI and handles trailing slashes
# fine: https://github.com/sumoheavy/jira-ruby/blob/v1.4.1/lib/jira/http_client.rb#L59
- expect(service.options[:site]).to eq('http://jira.test.com/')
+ expect(service.options[:site]).to eq("http://jira.test.com/")
end
- it 'leaves out trailing slashes in context' do
- expect(service.options[:context_path]).to eq('/path')
+ it "leaves out trailing slashes in context" do
+ expect(service.options[:context_path]).to eq("/path")
end
end
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
it { is_expected.to allow_value(nil).for(:jira_issue_transition_id) }
- it { is_expected.to allow_value('1,2,3').for(:jira_issue_transition_id) }
- it { is_expected.to allow_value('1;2;3').for(:jira_issue_transition_id) }
- it { is_expected.not_to allow_value('a,b,cd').for(:jira_issue_transition_id) }
+ it { is_expected.to allow_value("1,2,3").for(:jira_issue_transition_id) }
+ it { is_expected.to allow_value("1;2;3").for(:jira_issue_transition_id) }
+ it { is_expected.not_to allow_value("a,b,cd").for(:jira_issue_transition_id) }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:url) }
- it_behaves_like 'issue tracker service URL attribute', :url
+ it_behaves_like "issue tracker service URL attribute", :url
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -56,108 +56,108 @@ describe JiraService do
it { is_expected.not_to validate_presence_of(:password) }
end
- context 'validating urls' do
+ context "validating urls" do
let(:service) do
described_class.new(
project: create(:project),
active: true,
- username: 'username',
- password: 'test',
+ username: "username",
+ password: "test",
jira_issue_transition_id: 24,
- url: 'http://jira.test.com'
+ url: "http://jira.test.com"
)
end
- it 'is valid when all fields have required values' do
+ it "is valid when all fields have required values" do
expect(service).to be_valid
end
- it 'is not valid when url is not a valid url' do
- service.url = 'not valid'
+ it "is not valid when url is not a valid url" do
+ service.url = "not valid"
expect(service).not_to be_valid
end
- it 'is not valid when api url is not a valid url' do
- service.api_url = 'not valid'
+ it "is not valid when api url is not a valid url" do
+ service.api_url = "not valid"
expect(service).not_to be_valid
end
- it 'is not valid when username is missing' do
+ it "is not valid when username is missing" do
service.username = nil
expect(service).not_to be_valid
end
- it 'is not valid when password is missing' do
+ it "is not valid when password is missing" do
service.password = nil
expect(service).not_to be_valid
end
- it 'is valid when api url is a valid url' do
- service.api_url = 'http://jira.test.com/api'
+ it "is valid when api url is a valid url" do
+ service.api_url = "http://jira.test.com/api"
expect(service).to be_valid
end
end
end
- describe '.reference_pattern' do
- it_behaves_like 'allows project key on reference pattern'
+ describe ".reference_pattern" do
+ it_behaves_like "allows project key on reference pattern"
- it 'does not allow # on the code' do
- expect(described_class.reference_pattern.match('#123')).to be_nil
- expect(described_class.reference_pattern.match('1#23#12')).to be_nil
+ it "does not allow # on the code" do
+ expect(described_class.reference_pattern.match("#123")).to be_nil
+ expect(described_class.reference_pattern.match("1#23#12")).to be_nil
end
end
- describe '#close_issue' do
- let(:custom_base_url) { 'http://custom_url' }
+ describe "#close_issue" do
+ let(:custom_base_url) { "http://custom_url" }
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
- shared_examples 'close_issue' do
+ shared_examples "close_issue" do
before do
@jira_service = described_class.new
allow(@jira_service).to receive_messages(
project_id: project.id,
project: project,
service_hook: true,
- url: 'http://jira.example.com',
- username: 'gitlab_jira_username',
- password: 'gitlab_jira_password',
- jira_issue_transition_id: '999'
+ url: "http://jira.example.com",
+ username: "gitlab_jira_username",
+ password: "gitlab_jira_password",
+ jira_issue_transition_id: "999"
)
# These stubs are needed to test JiraService#close_issue.
# We close the issue then do another request to API to check if it got closed.
# Here is stubbed the API return with a closed and an opened issues.
- open_issue = JIRA::Resource::Issue.new(@jira_service.client, attrs: { 'id' => 'JIRA-123' })
+ open_issue = JIRA::Resource::Issue.new(@jira_service.client, attrs: {"id" => "JIRA-123"})
closed_issue = open_issue.dup
allow(open_issue).to receive(:resolution).and_return(false)
allow(closed_issue).to receive(:resolution).and_return(true)
allow(JIRA::Resource::Issue).to receive(:find).and_return(open_issue, closed_issue)
- allow_any_instance_of(JIRA::Resource::Issue).to receive(:key).and_return('JIRA-123')
+ allow_any_instance_of(JIRA::Resource::Issue).to receive(:key).and_return("JIRA-123")
allow(JIRA::Resource::Remotelink).to receive(:all).and_return([])
@jira_service.save
- project_issues_url = 'http://jira.example.com/rest/api/2/issue/JIRA-123'
- @transitions_url = 'http://jira.example.com/rest/api/2/issue/JIRA-123/transitions'
- @comment_url = 'http://jira.example.com/rest/api/2/issue/JIRA-123/comment'
- @remote_link_url = 'http://jira.example.com/rest/api/2/issue/JIRA-123/remotelink'
+ project_issues_url = "http://jira.example.com/rest/api/2/issue/JIRA-123"
+ @transitions_url = "http://jira.example.com/rest/api/2/issue/JIRA-123/transitions"
+ @comment_url = "http://jira.example.com/rest/api/2/issue/JIRA-123/comment"
+ @remote_link_url = "http://jira.example.com/rest/api/2/issue/JIRA-123/remotelink"
- WebMock.stub_request(:get, project_issues_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password))
- WebMock.stub_request(:post, @transitions_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password))
- WebMock.stub_request(:post, @comment_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password))
- WebMock.stub_request(:post, @remote_link_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password))
+ WebMock.stub_request(:get, project_issues_url).with(basic_auth: %w[gitlab_jira_username gitlab_jira_password])
+ WebMock.stub_request(:post, @transitions_url).with(basic_auth: %w[gitlab_jira_username gitlab_jira_password])
+ WebMock.stub_request(:post, @comment_url).with(basic_auth: %w[gitlab_jira_username gitlab_jira_password])
+ WebMock.stub_request(:post, @remote_link_url).with(basic_auth: %w[gitlab_jira_username gitlab_jira_password])
end
- it 'calls JIRA API' do
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ it "calls JIRA API" do
+ @jira_service.close_issue(resource, ExternalIssue.new("JIRA-123", project))
expect(WebMock).to have_requested(:post, @comment_url).with(
body: /Issue solved with/
@@ -166,93 +166,93 @@ describe JiraService do
# Check https://developer.atlassian.com/jiradev/jira-platform/guides/other/guide-jira-remote-issue-links/fields-in-remote-issue-links
# for more information
- it 'creates Remote Link reference in JIRA for comment' do
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ it "creates Remote Link reference in JIRA for comment" do
+ @jira_service.close_issue(resource, ExternalIssue.new("JIRA-123", project))
- favicon_path = "http://localhost/assets/#{find_asset('favicon.png').digest_path}"
+ favicon_path = "http://localhost/assets/#{find_asset("favicon.png").digest_path}"
# Creates comment
expect(WebMock).to have_requested(:post, @comment_url)
# Creates Remote Link in JIRA issue fields
expect(WebMock).to have_requested(:post, @remote_link_url).with(
body: hash_including(
- GlobalID: 'GitLab',
- relationship: 'mentioned on',
+ GlobalID: "GitLab",
+ relationship: "mentioned on",
object: {
url: "#{Gitlab.config.gitlab.url}/#{project.full_path}/commit/#{commit_id}",
title: "Solved by commit #{commit_id}.",
- icon: { title: 'GitLab', url16x16: favicon_path },
- status: { resolved: true }
+ icon: {title: "GitLab", url16x16: favicon_path},
+ status: {resolved: true},
}
)
).once
end
- it 'does not send comment or remote links to issues already closed' do
+ it "does not send comment or remote links to issues already closed" do
allow_any_instance_of(JIRA::Resource::Issue).to receive(:resolution).and_return(true)
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ @jira_service.close_issue(resource, ExternalIssue.new("JIRA-123", project))
expect(WebMock).not_to have_requested(:post, @comment_url)
expect(WebMock).not_to have_requested(:post, @remote_link_url)
end
- it 'does not send comment or remote links to issues with unknown resolution' do
+ it "does not send comment or remote links to issues with unknown resolution" do
allow_any_instance_of(JIRA::Resource::Issue).to receive(:respond_to?).with(:resolution).and_return(false)
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ @jira_service.close_issue(resource, ExternalIssue.new("JIRA-123", project))
expect(WebMock).not_to have_requested(:post, @comment_url)
expect(WebMock).not_to have_requested(:post, @remote_link_url)
end
- it 'references the GitLab commit' do
+ it "references the GitLab commit" do
stub_config_setting(base_url: custom_base_url)
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ @jira_service.close_issue(resource, ExternalIssue.new("JIRA-123", project))
expect(WebMock).to have_requested(:post, @comment_url).with(
body: %r{#{custom_base_url}/#{project.full_path}/commit/#{commit_id}}
).once
end
- it 'references the GitLab commit' do
- stub_config_setting(relative_url_root: '/gitlab')
+ it "references the GitLab commit" do
+ stub_config_setting(relative_url_root: "/gitlab")
stub_config_setting(url: Settings.send(:build_gitlab_url))
allow(described_class).to receive(:default_url_options) do
- { script_name: '/gitlab' }
+ {script_name: "/gitlab"}
end
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ @jira_service.close_issue(resource, ExternalIssue.new("JIRA-123", project))
expect(WebMock).to have_requested(:post, @comment_url).with(
body: %r{#{Gitlab.config.gitlab.url}/#{project.full_path}/commit/#{commit_id}}
).once
end
- it 'logs exception when transition id is not valid' do
+ it "logs exception when transition id is not valid" do
allow(@jira_service).to receive(:log_error)
- WebMock.stub_request(:post, @transitions_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).and_raise("Bad Request")
+ WebMock.stub_request(:post, @transitions_url).with(basic_auth: %w[gitlab_jira_username gitlab_jira_password]).and_raise("Bad Request")
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ @jira_service.close_issue(resource, ExternalIssue.new("JIRA-123", project))
expect(@jira_service).to have_received(:log_error).with("Issue transition failed", error: "Bad Request", client_url: "http://jira.example.com")
end
- it 'calls the api with jira_issue_transition_id' do
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ it "calls the api with jira_issue_transition_id" do
+ @jira_service.close_issue(resource, ExternalIssue.new("JIRA-123", project))
expect(WebMock).to have_requested(:post, @transitions_url).with(
body: /999/
).once
end
- context 'when have multiple transition ids' do
- it 'calls the api with transition ids separated by comma' do
- allow(@jira_service).to receive_messages(jira_issue_transition_id: '1,2,3')
+ context "when have multiple transition ids" do
+ it "calls the api with transition ids separated by comma" do
+ allow(@jira_service).to receive_messages(jira_issue_transition_id: "1,2,3")
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ @jira_service.close_issue(resource, ExternalIssue.new("JIRA-123", project))
1.upto(3) do |transition_id|
expect(WebMock).to have_requested(:post, @transitions_url).with(
@@ -261,10 +261,10 @@ describe JiraService do
end
end
- it 'calls the api with transition ids separated by semicolon' do
- allow(@jira_service).to receive_messages(jira_issue_transition_id: '1;2;3')
+ it "calls the api with transition ids separated by semicolon" do
+ allow(@jira_service).to receive_messages(jira_issue_transition_id: "1;2;3")
- @jira_service.close_issue(resource, ExternalIssue.new('JIRA-123', project))
+ @jira_service.close_issue(resource, ExternalIssue.new("JIRA-123", project))
1.upto(3) do |transition_id|
expect(WebMock).to have_requested(:post, @transitions_url).with(
@@ -275,175 +275,175 @@ describe JiraService do
end
end
- context 'when resource is a merge request' do
+ context "when resource is a merge request" do
let(:resource) { create(:merge_request) }
let(:commit_id) { resource.diff_head_sha }
- it_behaves_like 'close_issue'
+ it_behaves_like "close_issue"
end
- context 'when resource is a commit' do
- let(:resource) { project.commit('master') }
+ context "when resource is a commit" do
+ let(:resource) { project.commit("master") }
let(:commit_id) { resource.id }
- it_behaves_like 'close_issue'
+ it_behaves_like "close_issue"
end
end
- describe '#test_settings' do
+ describe "#test_settings" do
let(:jira_service) do
described_class.new(
project: create(:project),
- url: 'http://jira.example.com',
- username: 'jira_username',
- password: 'jira_password'
+ url: "http://jira.example.com",
+ username: "jira_username",
+ password: "jira_password"
)
end
def test_settings(api_url = nil)
- api_url ||= 'jira.example.com'
+ api_url ||= "jira.example.com"
test_url = "http://#{api_url}/rest/api/2/serverInfo"
- WebMock.stub_request(:get, test_url).with(basic_auth: %w(jira_username jira_password)).to_return(body: { url: 'http://url' }.to_json )
+ WebMock.stub_request(:get, test_url).with(basic_auth: %w[jira_username jira_password]).to_return(body: {url: "http://url"}.to_json)
jira_service.test(nil)
end
- context 'when the test succeeds' do
- it 'tries to get JIRA project with URL when API URL not set' do
- test_settings('jira.example.com')
+ context "when the test succeeds" do
+ it "tries to get JIRA project with URL when API URL not set" do
+ test_settings("jira.example.com")
end
- it 'returns correct result' do
- expect(test_settings).to eq( { success: true, result: { 'url' => 'http://url' } })
+ it "returns correct result" do
+ expect(test_settings).to eq({success: true, result: {"url" => "http://url"}})
end
- it 'tries to get JIRA project with API URL if set' do
- jira_service.update(api_url: 'http://jira.api.com')
- test_settings('jira.api.com')
+ it "tries to get JIRA project with API URL if set" do
+ jira_service.update(api_url: "http://jira.api.com")
+ test_settings("jira.api.com")
end
end
- context 'when the test fails' do
- it 'returns result with the error' do
- test_url = 'http://jira.example.com/rest/api/2/serverInfo'
- WebMock.stub_request(:get, test_url).with(basic_auth: %w(jira_username jira_password))
- .to_raise(JIRA::HTTPError.new(double(message: 'Some specific failure.')))
+ context "when the test fails" do
+ it "returns result with the error" do
+ test_url = "http://jira.example.com/rest/api/2/serverInfo"
+ WebMock.stub_request(:get, test_url).with(basic_auth: %w[jira_username jira_password])
+ .to_raise(JIRA::HTTPError.new(double(message: "Some specific failure.")))
- expect(jira_service.test(nil)).to eq( { success: false, result: 'Some specific failure.' })
+ expect(jira_service.test(nil)).to eq({success: false, result: "Some specific failure."})
end
end
end
- describe 'Stored password invalidation' do
+ describe "Stored password invalidation" do
let(:project) { create(:project) }
- context 'when a password was previously set' do
+ context "when a password was previously set" do
before do
@jira_service = described_class.create!(
project: project,
properties: {
- url: 'http://jira.example.com/web',
- username: 'mic',
- password: 'password'
+ url: "http://jira.example.com/web",
+ username: "mic",
+ password: "password",
}
)
end
- context 'when only web url present' do
- it 'reset password if url changed' do
- @jira_service.url = 'http://jira_edited.example.com/rest/api/2'
+ context "when only web url present" do
+ it "reset password if url changed" do
+ @jira_service.url = "http://jira_edited.example.com/rest/api/2"
@jira_service.save
expect(@jira_service.password).to be_nil
end
- it 'reset password if url not changed but api url added' do
- @jira_service.api_url = 'http://jira_edited.example.com/rest/api/2'
+ it "reset password if url not changed but api url added" do
+ @jira_service.api_url = "http://jira_edited.example.com/rest/api/2"
@jira_service.save
expect(@jira_service.password).to be_nil
end
end
- context 'when both web and api url present' do
+ context "when both web and api url present" do
before do
- @jira_service.api_url = 'http://jira.example.com/rest/api/2'
- @jira_service.password = 'password'
+ @jira_service.api_url = "http://jira.example.com/rest/api/2"
+ @jira_service.password = "password"
@jira_service.save
end
- it 'reset password if api url changed' do
- @jira_service.api_url = 'http://jira_edited.example.com/rest/api/2'
+ it "reset password if api url changed" do
+ @jira_service.api_url = "http://jira_edited.example.com/rest/api/2"
@jira_service.save
expect(@jira_service.password).to be_nil
end
- it 'does not reset password if url changed' do
- @jira_service.url = 'http://jira_edited.example.com/rweb'
+ it "does not reset password if url changed" do
+ @jira_service.url = "http://jira_edited.example.com/rweb"
@jira_service.save
- expect(@jira_service.password).to eq('password')
+ expect(@jira_service.password).to eq("password")
end
- it 'reset password if api url set to empty' do
- @jira_service.api_url = ''
+ it "reset password if api url set to empty" do
+ @jira_service.api_url = ""
@jira_service.save
expect(@jira_service.password).to be_nil
end
end
- it 'does not reset password if username changed' do
- @jira_service.username = 'some_name'
+ it "does not reset password if username changed" do
+ @jira_service.username = "some_name"
@jira_service.save
- expect(@jira_service.password).to eq('password')
+ expect(@jira_service.password).to eq("password")
end
- it 'does not reset password if new url is set together with password, even if it\'s the same password' do
- @jira_service.url = 'http://jira_edited.example.com/rest/api/2'
- @jira_service.password = 'password'
+ it "does not reset password if new url is set together with password, even if it's the same password" do
+ @jira_service.url = "http://jira_edited.example.com/rest/api/2"
+ @jira_service.password = "password"
@jira_service.save
- expect(@jira_service.password).to eq('password')
- expect(@jira_service.url).to eq('http://jira_edited.example.com/rest/api/2')
+ expect(@jira_service.password).to eq("password")
+ expect(@jira_service.url).to eq("http://jira_edited.example.com/rest/api/2")
end
- it 'resets password if url changed, even if setter called multiple times' do
- @jira_service.url = 'http://jira1.example.com/rest/api/2'
- @jira_service.url = 'http://jira1.example.com/rest/api/2'
+ it "resets password if url changed, even if setter called multiple times" do
+ @jira_service.url = "http://jira1.example.com/rest/api/2"
+ @jira_service.url = "http://jira1.example.com/rest/api/2"
@jira_service.save
expect(@jira_service.password).to be_nil
end
end
- context 'when no password was previously set' do
+ context "when no password was previously set" do
before do
@jira_service = described_class.create(
project: project,
properties: {
- url: 'http://jira.example.com/rest/api/2',
- username: 'mic'
+ url: "http://jira.example.com/rest/api/2",
+ username: "mic",
}
)
end
- it 'saves password if new url is set together with password' do
- @jira_service.url = 'http://jira_edited.example.com/rest/api/2'
- @jira_service.password = 'password'
+ it "saves password if new url is set together with password" do
+ @jira_service.url = "http://jira_edited.example.com/rest/api/2"
+ @jira_service.password = "password"
@jira_service.save
- expect(@jira_service.password).to eq('password')
- expect(@jira_service.url).to eq('http://jira_edited.example.com/rest/api/2')
+ expect(@jira_service.password).to eq("password")
+ expect(@jira_service.url).to eq("http://jira_edited.example.com/rest/api/2")
end
end
end
- describe 'description and title' do
+ describe "description and title" do
let(:project) { create(:project) }
- context 'when it is not set' do
+ context "when it is not set" do
before do
@service = project.create_jira_service(active: true)
end
@@ -452,15 +452,15 @@ describe JiraService do
@service.destroy!
end
- it 'is initialized' do
- expect(@service.title).to eq('JIRA')
- expect(@service.description).to eq('Jira issue tracker')
+ it "is initialized" do
+ expect(@service.title).to eq("JIRA")
+ expect(@service.description).to eq("Jira issue tracker")
end
end
- context 'when it is set' do
+ context "when it is set" do
before do
- properties = { 'title' => 'Jira One', 'description' => 'Jira One issue tracker' }
+ properties = {"title" => "Jira One", "description" => "Jira One issue tracker"}
@service = project.create_jira_service(active: true, properties: properties)
end
@@ -468,44 +468,45 @@ describe JiraService do
@service.destroy!
end
- it 'is correct' do
- expect(@service.title).to eq('Jira One')
- expect(@service.description).to eq('Jira One issue tracker')
+ it "is correct" do
+ expect(@service.title).to eq("Jira One")
+ expect(@service.description).to eq("Jira One issue tracker")
end
end
end
- describe 'additional cookies' do
+ describe "additional cookies" do
let(:project) { create(:project) }
- context 'provides additional cookies to allow basic auth with oracle webgate' do
+ context "provides additional cookies to allow basic auth with oracle webgate" do
before do
@service = project.create_jira_service(
- active: true, properties: { url: 'http://jira.com' })
+ active: true, properties: {url: "http://jira.com"}
+ )
end
after do
@service.destroy!
end
- it 'is initialized' do
+ it "is initialized" do
expect(@service.options[:use_cookies]).to eq(true)
- expect(@service.options[:additional_cookies]).to eq(['OBBasicAuth=fromDialog'])
+ expect(@service.options[:additional_cookies]).to eq(["OBBasicAuth=fromDialog"])
end
end
end
- describe 'project and issue urls' do
+ describe "project and issue urls" do
let(:project) { create(:project) }
- context 'when gitlab.yml was initialized' do
+ context "when gitlab.yml was initialized" do
before do
settings = {
- 'jira' => {
- 'title' => 'Jira',
- 'url' => 'http://jira.sample/projects/project_a',
- 'api_url' => 'http://jira.sample/api'
- }
+ "jira" => {
+ "title" => "Jira",
+ "url" => "http://jira.sample/projects/project_a",
+ "api_url" => "http://jira.sample/api",
+ },
}
allow(Gitlab.config).to receive(:issues_tracker).and_return(settings)
@service = project.create_jira_service(active: true)
@@ -515,24 +516,24 @@ describe JiraService do
@service.destroy!
end
- it 'is prepopulated with the settings' do
- expect(@service.properties['title']).to eq('Jira')
- expect(@service.properties['url']).to eq('http://jira.sample/projects/project_a')
- expect(@service.properties['api_url']).to eq('http://jira.sample/api')
+ it "is prepopulated with the settings" do
+ expect(@service.properties["title"]).to eq("Jira")
+ expect(@service.properties["url"]).to eq("http://jira.sample/projects/project_a")
+ expect(@service.properties["api_url"]).to eq("http://jira.sample/api")
end
end
end
- describe 'favicon urls', :request_store do
- it 'includes the standard favicon' do
- props = described_class.new.send(:build_remote_link_props, url: 'http://example.com', title: 'title')
+ describe "favicon urls", :request_store do
+ it "includes the standard favicon" do
+ props = described_class.new.send(:build_remote_link_props, url: "http://example.com", title: "title")
expect(props[:object][:icon][:url16x16]).to match %r{^http://localhost/assets/favicon(?:-\h+).png$}
end
- it 'includes returns the custom favicon' do
- create :appearance, favicon: fixture_file_upload('spec/fixtures/dk.png')
+ it "includes returns the custom favicon" do
+ create :appearance, favicon: fixture_file_upload("spec/fixtures/dk.png")
- props = described_class.new.send(:build_remote_link_props, url: 'http://example.com', title: 'title')
+ props = described_class.new.send(:build_remote_link_props, url: "http://example.com", title: "title")
expect(props[:object][:icon][:url16x16]).to match %r{^http://localhost/uploads/-/system/appearance/favicon/\d+/dk.png$}
end
end
diff --git a/spec/models/project_services/kubernetes_service_spec.rb b/spec/models/project_services/kubernetes_service_spec.rb
index 9c27357ffaf..f3032309771 100644
--- a/spec/models/project_services/kubernetes_service_spec.rb
+++ b/spec/models/project_services/kubernetes_service_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe KubernetesService, :use_clean_rails_memory_store_caching do
include KubernetesHelpers
@@ -7,12 +7,12 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
let(:project) { create(:kubernetes_project) }
let(:service) { project.deployment_platform }
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -21,7 +21,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
it { is_expected.to validate_presence_of(:api_url) }
it { is_expected.to validate_presence_of(:token) }
- context 'namespace format' do
+ context "namespace format" do
before do
subject.project = project
subject.api_url = "http://example.com"
@@ -29,19 +29,19 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
end
{
- 'foo' => true,
- '1foo' => true,
- 'foo1' => true,
- 'foo-bar' => true,
- '-foo' => false,
- 'foo-' => false,
- 'a' * 63 => true,
- 'a' * 64 => false,
- 'a.b' => false,
- 'a*b' => false,
- 'FOO' => true
+ "foo" => true,
+ "1foo" => true,
+ "foo1" => true,
+ "foo-bar" => true,
+ "-foo" => false,
+ "foo-" => false,
+ "a" * 63 => true,
+ "a" * 64 => false,
+ "a.b" => false,
+ "a*b" => false,
+ "FOO" => true,
}.each do |namespace, validity|
- it "validates #{namespace} as #{validity ? 'valid' : 'invalid'}" do
+ it "validates #{namespace} as #{validity ? "valid" : "invalid"}" do
subject.namespace = namespace
expect(subject.valid?).to eq(validity)
@@ -50,7 +50,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
end
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.project = project
subject.active = false
@@ -60,162 +60,162 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
it { is_expected.not_to validate_presence_of(:token) }
end
- context 'with a deprecated service' do
+ context "with a deprecated service" do
let(:kubernetes_service) { create(:kubernetes_service) }
before do
kubernetes_service.update_attribute(:active, false)
- kubernetes_service.properties['namespace'] = "foo"
+ kubernetes_service.properties["namespace"] = "foo"
end
- it 'should not update attributes' do
+ it "should not update attributes" do
expect(kubernetes_service.save).to be_falsy
end
- it 'should include an error with a deprecation message' do
+ it "should include an error with a deprecation message" do
kubernetes_service.valid?
expect(kubernetes_service.errors[:base].first).to match(/Kubernetes service integration has been deprecated/)
end
end
- context 'with a non-deprecated service' do
+ context "with a non-deprecated service" do
let(:kubernetes_service) { create(:kubernetes_service) }
- it 'should update attributes' do
- kubernetes_service.properties['namespace'] = 'foo'
+ it "should update attributes" do
+ kubernetes_service.properties["namespace"] = "foo"
expect(kubernetes_service.save).to be_truthy
end
end
- context 'with an active and deprecated service' do
+ context "with an active and deprecated service" do
let(:kubernetes_service) { create(:kubernetes_service) }
before do
kubernetes_service.active = false
- kubernetes_service.properties['namespace'] = 'foo'
+ kubernetes_service.properties["namespace"] = "foo"
kubernetes_service.save
end
- it 'should deactive the service' do
+ it "should deactive the service" do
expect(kubernetes_service.active?).to be_falsy
end
- it 'should not include a deprecation message as error' do
+ it "should not include a deprecation message as error" do
expect(kubernetes_service.errors.messages.count).to eq(0)
end
- it 'should update attributes' do
- expect(kubernetes_service.properties['namespace']).to eq("foo")
+ it "should update attributes" do
+ expect(kubernetes_service.properties["namespace"]).to eq("foo")
end
end
- context 'with a template service' do
+ context "with a template service" do
let(:kubernetes_service) { create(:kubernetes_service, template: true, active: false) }
before do
- kubernetes_service.properties['namespace'] = 'foo'
+ kubernetes_service.properties["namespace"] = "foo"
end
- it 'should update attributes' do
+ it "should update attributes" do
expect(kubernetes_service.save).to be_truthy
- expect(kubernetes_service.properties['namespace']).to eq('foo')
+ expect(kubernetes_service.properties["namespace"]).to eq("foo")
end
end
end
- describe '#initialize_properties' do
- context 'without a project' do
- it 'leaves the namespace unset' do
+ describe "#initialize_properties" do
+ context "without a project" do
+ it "leaves the namespace unset" do
expect(described_class.new.namespace).to be_nil
end
end
end
- describe '#fields' do
+ describe "#fields" do
let(:kube_namespace) do
- subject.fields.find { |h| h[:name] == 'namespace' }
+ subject.fields.find { |h| h[:name] == "namespace" }
end
- context 'as template' do
+ context "as template" do
before do
subject.template = true
end
- it 'sets the namespace to the default' do
+ it "sets the namespace to the default" do
expect(kube_namespace).not_to be_nil
expect(kube_namespace[:placeholder]).to eq(subject.class::TEMPLATE_PLACEHOLDER)
end
end
- context 'with associated project' do
+ context "with associated project" do
before do
subject.project = project
end
- it 'sets the namespace to the default' do
+ it "sets the namespace to the default" do
expect(kube_namespace).not_to be_nil
expect(kube_namespace[:placeholder]).to match(/\A#{Gitlab::PathRegex::PATH_REGEX_STR}-\d+\z/)
end
end
end
- describe '#actual_namespace' do
+ describe "#actual_namespace" do
subject { service.actual_namespace }
- shared_examples 'a correctly formatted namespace' do
- it 'returns a valid Kubernetes namespace name' do
+ shared_examples "a correctly formatted namespace" do
+ it "returns a valid Kubernetes namespace name" do
expect(subject).to match(Gitlab::Regex.kubernetes_namespace_regex)
expect(subject).to eq(expected_namespace)
end
end
- it_behaves_like 'a correctly formatted namespace' do
+ it_behaves_like "a correctly formatted namespace" do
let(:expected_namespace) { service.send(:default_namespace) }
end
- context 'when the project path contains forbidden characters' do
+ context "when the project path contains forbidden characters" do
before do
- project.path = '-a_Strange.Path--forSure'
+ project.path = "-a_Strange.Path--forSure"
end
- it_behaves_like 'a correctly formatted namespace' do
+ it_behaves_like "a correctly formatted namespace" do
let(:expected_namespace) { "a-strange-path--forsure-#{project.id}" }
end
end
- context 'when namespace is specified' do
+ context "when namespace is specified" do
before do
- service.namespace = 'my-namespace'
+ service.namespace = "my-namespace"
end
- it_behaves_like 'a correctly formatted namespace' do
- let(:expected_namespace) { 'my-namespace' }
+ it_behaves_like "a correctly formatted namespace" do
+ let(:expected_namespace) { "my-namespace" }
end
end
- context 'when service is not assigned to project' do
+ context "when service is not assigned to project" do
before do
service.project = nil
end
- it 'does not return namespace' do
+ it "does not return namespace" do
is_expected.to be_nil
end
end
end
- describe '#test' do
- let(:discovery_url) { 'https://kubernetes.example.com/api/v1' }
+ describe "#test" do
+ let(:discovery_url) { "https://kubernetes.example.com/api/v1" }
before do
stub_kubeclient_discover(service.api_url)
end
- context 'with path prefix in api_url' do
- let(:discovery_url) { 'https://kubernetes.example.com/prefix/api/v1' }
+ context "with path prefix in api_url" do
+ let(:discovery_url) { "https://kubernetes.example.com/prefix/api/v1" }
- it 'tests with the prefix' do
- service.api_url = 'https://kubernetes.example.com/prefix'
+ it "tests with the prefix" do
+ service.api_url = "https://kubernetes.example.com/prefix"
stub_kubeclient_discover(service.api_url)
expect(service.test[:success]).to be_truthy
@@ -223,8 +223,8 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
end
end
- context 'with custom CA certificate' do
- it 'is added to the certificate store' do
+ context "with custom CA certificate" do
+ it "is added to the certificate store" do
service.ca_pem = "CA PEM DATA"
cert = double("certificate")
@@ -236,16 +236,16 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
end
end
- context 'success' do
- it 'reads the discovery endpoint' do
+ context "success" do
+ it "reads the discovery endpoint" do
expect(service.test[:success]).to be_truthy
expect(WebMock).to have_requested(:get, discovery_url).once
end
end
- context 'failure' do
- it 'fails to read the discovery endpoint' do
- WebMock.stub_request(:get, service.api_url + '/api/v1').to_return(status: 404)
+ context "failure" do
+ it "fails to read the discovery endpoint" do
+ WebMock.stub_request(:get, service.api_url + "/api/v1").to_return(status: 404)
expect(service.test[:success]).to be_falsy
expect(WebMock).to have_requested(:get, discovery_url).once
@@ -253,55 +253,55 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
end
end
- describe '#predefined_variable' do
+ describe "#predefined_variable" do
let(:kubeconfig) do
- config_file = expand_fixture_path('config/kubeconfig.yml')
+ config_file = expand_fixture_path("config/kubeconfig.yml")
config = YAML.load(File.read(config_file))
- config.dig('users', 0, 'user')['token'] = 'token'
- config.dig('contexts', 0, 'context')['namespace'] = namespace
- config.dig('clusters', 0, 'cluster')['certificate-authority-data'] =
- Base64.strict_encode64('CA PEM DATA')
+ config.dig("users", 0, "user")["token"] = "token"
+ config.dig("contexts", 0, "context")["namespace"] = namespace
+ config.dig("clusters", 0, "cluster")["certificate-authority-data"] =
+ Base64.strict_encode64("CA PEM DATA")
YAML.dump(config)
end
before do
- subject.api_url = 'https://kube.domain.com'
- subject.token = 'token'
- subject.ca_pem = 'CA PEM DATA'
+ subject.api_url = "https://kube.domain.com"
+ subject.token = "token"
+ subject.ca_pem = "CA PEM DATA"
subject.project = project
end
- shared_examples 'setting variables' do
- it 'sets the variables' do
+ shared_examples "setting variables" do
+ it "sets the variables" do
expect(subject.predefined_variables(project: project)).to include(
- { key: 'KUBE_URL', value: 'https://kube.domain.com', public: true },
- { key: 'KUBE_TOKEN', value: 'token', public: false },
- { key: 'KUBE_NAMESPACE', value: namespace, public: true },
- { key: 'KUBECONFIG', value: kubeconfig, public: false, file: true },
- { key: 'KUBE_CA_PEM', value: 'CA PEM DATA', public: true },
- { key: 'KUBE_CA_PEM_FILE', value: 'CA PEM DATA', public: true, file: true }
+ {key: "KUBE_URL", value: "https://kube.domain.com", public: true},
+ {key: "KUBE_TOKEN", value: "token", public: false},
+ {key: "KUBE_NAMESPACE", value: namespace, public: true},
+ {key: "KUBECONFIG", value: kubeconfig, public: false, file: true},
+ {key: "KUBE_CA_PEM", value: "CA PEM DATA", public: true},
+ {key: "KUBE_CA_PEM_FILE", value: "CA PEM DATA", public: true, file: true}
)
end
end
- context 'namespace is provided' do
- let(:namespace) { 'my-project' }
+ context "namespace is provided" do
+ let(:namespace) { "my-project" }
before do
subject.namespace = namespace
end
- it_behaves_like 'setting variables'
+ it_behaves_like "setting variables"
end
- context 'no namespace provided' do
+ context "no namespace provided" do
let(:namespace) { subject.actual_namespace }
- it_behaves_like 'setting variables'
+ it_behaves_like "setting variables"
- it 'sets the KUBE_NAMESPACE' do
- kube_namespace = subject.predefined_variables(project: project).find { |h| h[:key] == 'KUBE_NAMESPACE' }
+ it "sets the KUBE_NAMESPACE" do
+ kube_namespace = subject.predefined_variables(project: project).find { |h| h[:key] == "KUBE_NAMESPACE" }
expect(kube_namespace).not_to be_nil
expect(kube_namespace[:value]).to match(/\A#{Gitlab::PathRegex::PATH_REGEX_STR}-\d+\z/)
@@ -309,20 +309,20 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
end
end
- describe '#terminals' do
+ describe "#terminals" do
let(:environment) { build(:environment, project: project, name: "env", slug: "env-000000") }
subject { service.terminals(environment) }
- context 'with invalid pods' do
- it 'returns no terminals' do
- stub_reactive_cache(service, pods: [{ "bad" => "pod" }])
+ context "with invalid pods" do
+ it "returns no terminals" do
+ stub_reactive_cache(service, pods: [{"bad" => "pod"}])
is_expected.to be_empty
end
end
- context 'with valid pods' do
+ context "with valid pods" do
let(:pod) { kube_pod(app: environment.slug) }
let(:terminals) { kube_terminals(service, pod) }
@@ -333,11 +333,11 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
)
end
- it 'returns terminals' do
+ it "returns terminals" do
is_expected.to eq(terminals + terminals)
end
- it 'uses max session time from settings' do
+ it "uses max session time from settings" do
stub_application_setting(terminal_max_session_time: 600)
times = subject.map { |terminal| terminal[:max_session_time] }
@@ -346,10 +346,10 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
end
end
- describe '#calculate_reactive_cache' do
+ describe "#calculate_reactive_cache" do
subject { service.calculate_reactive_cache }
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
service.active = false
end
@@ -357,7 +357,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
it { is_expected.to be_nil }
end
- context 'when kubernetes responds with valid pods' do
+ context "when kubernetes responds with valid pods" do
before do
stub_kubeclient_pods
end
@@ -365,7 +365,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
it { is_expected.to eq(pods: [kube_pod]) }
end
- context 'when kubernetes responds with 500s' do
+ context "when kubernetes responds with 500s" do
before do
stub_kubeclient_pods(status: 500)
end
@@ -373,7 +373,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
it { expect { subject }.to raise_error(Kubeclient::HttpError) }
end
- context 'when kubernetes responds with 404s' do
+ context "when kubernetes responds with 404s" do
before do
stub_kubeclient_pods(status: 404)
end
@@ -385,14 +385,14 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
describe "#deprecated?" do
let(:kubernetes_service) { create(:kubernetes_service) }
- context 'with an active kubernetes service' do
- it 'should return false' do
+ context "with an active kubernetes service" do
+ it "should return false" do
expect(kubernetes_service.deprecated?).to be_falsy
end
end
- context 'with a inactive kubernetes service' do
- it 'should return true' do
+ context "with a inactive kubernetes service" do
+ it "should return true" do
kubernetes_service.update_attribute(:active, false)
expect(kubernetes_service.deprecated?).to be_truthy
end
@@ -402,18 +402,18 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
describe "#deprecation_message" do
let(:kubernetes_service) { create(:kubernetes_service) }
- it 'should indicate the service is deprecated' do
+ it "should indicate the service is deprecated" do
expect(kubernetes_service.deprecation_message).to match(/Kubernetes service integration has been deprecated/)
end
- context 'if the services is active' do
- it 'should return a message' do
+ context "if the services is active" do
+ it "should return a message" do
expect(kubernetes_service.deprecation_message).to match(/Your Kubernetes cluster information on this page is still editable/)
end
end
- context 'if the service is not active' do
- it 'should return a message' do
+ context "if the service is not active" do
+ it "should return a message" do
kubernetes_service.update_attribute(:active, false)
expect(kubernetes_service.deprecation_message).to match(/Fields on this page are now uneditable/)
end
diff --git a/spec/models/project_services/mattermost_service_spec.rb b/spec/models/project_services/mattermost_service_spec.rb
index 10c62ca55a7..61c236995b4 100644
--- a/spec/models/project_services/mattermost_service_spec.rb
+++ b/spec/models/project_services/mattermost_service_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe MattermostService do
it_behaves_like "slack or mattermost notifications"
diff --git a/spec/models/project_services/mattermost_slash_commands_service_spec.rb b/spec/models/project_services/mattermost_slash_commands_service_spec.rb
index 1983e0cc967..01b1eed9096 100644
--- a/spec/models/project_services/mattermost_slash_commands_service_spec.rb
+++ b/spec/models/project_services/mattermost_slash_commands_service_spec.rb
@@ -1,120 +1,120 @@
-require 'spec_helper'
+require "spec_helper"
describe MattermostSlashCommandsService do
it_behaves_like "chat slash commands service"
- context 'Mattermost API' do
+ context "Mattermost API" do
let(:project) { create(:project) }
let(:service) { project.build_mattermost_slash_commands_service }
let(:user) { create(:user) }
before do
session = Mattermost::Session.new(nil)
- session.base_uri = 'http://mattermost.example.com'
+ session.base_uri = "http://mattermost.example.com"
allow_any_instance_of(Mattermost::Client).to receive(:with_session)
.and_yield(session)
end
- describe '#configure' do
+ describe "#configure" do
subject do
- service.configure(user, team_id: 'abc',
- trigger: 'gitlab', url: 'http://trigger.url',
- icon_url: 'http://icon.url/icon.png')
+ service.configure(user, team_id: "abc",
+ trigger: "gitlab", url: "http://trigger.url",
+ icon_url: "http://icon.url/icon.png")
end
- context 'the requests succeeds' do
+ context "the requests succeeds" do
before do
- stub_request(:post, 'http://mattermost.example.com/api/v4/commands')
+ stub_request(:post, "http://mattermost.example.com/api/v4/commands")
.with(body: {
- team_id: 'abc',
- trigger: 'gitlab',
- url: 'http://trigger.url',
- icon_url: 'http://icon.url/icon.png',
+ team_id: "abc",
+ trigger: "gitlab",
+ url: "http://trigger.url",
+ icon_url: "http://icon.url/icon.png",
auto_complete: true,
auto_complete_desc: "Perform common operations on: #{project.full_name}",
- auto_complete_hint: '[help]',
+ auto_complete_hint: "[help]",
description: "Perform common operations on: #{project.full_name}",
display_name: "GitLab / #{project.full_name}",
- method: 'P',
- username: 'GitLab'
+ method: "P",
+ username: "GitLab",
}.to_json)
.to_return(
status: 200,
- headers: { 'Content-Type' => 'application/json' },
- body: { token: 'token' }.to_json
+ headers: {"Content-Type" => "application/json"},
+ body: {token: "token"}.to_json
)
end
- it 'saves the service' do
+ it "saves the service" do
expect { subject }.to change { project.services.count }.by(1)
end
- it 'saves the token' do
+ it "saves the token" do
subject
- expect(service.reload.token).to eq('token')
+ expect(service.reload.token).to eq("token")
end
end
- context 'an error is received' do
+ context "an error is received" do
before do
- stub_request(:post, 'http://mattermost.example.com/api/v4/commands')
+ stub_request(:post, "http://mattermost.example.com/api/v4/commands")
.to_return(
status: 500,
- headers: { 'Content-Type' => 'application/json' },
+ headers: {"Content-Type" => "application/json"},
body: {
- id: 'api.command.duplicate_trigger.app_error',
- message: 'This trigger word is already in use. Please choose another word.',
- detailed_error: '',
- request_id: 'obc374man7bx5r3dbc1q5qhf3r',
- status_code: 500
+ id: "api.command.duplicate_trigger.app_error",
+ message: "This trigger word is already in use. Please choose another word.",
+ detailed_error: "",
+ request_id: "obc374man7bx5r3dbc1q5qhf3r",
+ status_code: 500,
}.to_json
)
end
- it 'shows error messages' do
+ it "shows error messages" do
succeeded, message = subject
expect(succeeded).to be(false)
- expect(message).to eq('This trigger word is already in use. Please choose another word.')
+ expect(message).to eq("This trigger word is already in use. Please choose another word.")
end
end
end
- describe '#list_teams' do
+ describe "#list_teams" do
subject do
service.list_teams(user)
end
- context 'the requests succeeds' do
+ context "the requests succeeds" do
before do
- stub_request(:get, 'http://mattermost.example.com/api/v4/users/me/teams')
+ stub_request(:get, "http://mattermost.example.com/api/v4/users/me/teams")
.to_return(
status: 200,
- headers: { 'Content-Type' => 'application/json' },
- body: [{ id: 'test_team_id' }].to_json
+ headers: {"Content-Type" => "application/json"},
+ body: [{id: "test_team_id"}].to_json
)
end
- it 'returns a list of teams' do
+ it "returns a list of teams" do
expect(subject).not_to be_empty
end
end
- context 'an error is received' do
+ context "an error is received" do
before do
- stub_request(:get, 'http://mattermost.example.com/api/v4/users/me/teams')
+ stub_request(:get, "http://mattermost.example.com/api/v4/users/me/teams")
.to_return(
status: 500,
- headers: { 'Content-Type' => 'application/json' },
+ headers: {"Content-Type" => "application/json"},
body: {
- message: 'Failed to get team list.'
+ message: "Failed to get team list.",
}.to_json
)
end
- it 'shows error messages' do
+ it "shows error messages" do
expect(subject).to eq([[], "Failed to get team list."])
end
end
diff --git a/spec/models/project_services/microsoft_teams_service_spec.rb b/spec/models/project_services/microsoft_teams_service_spec.rb
index 3351c6280b4..15689065fca 100644
--- a/spec/models/project_services/microsoft_teams_service_spec.rb
+++ b/spec/models/project_services/microsoft_teams_service_spec.rb
@@ -1,25 +1,25 @@
-require 'spec_helper'
+require "spec_helper"
describe MicrosoftTeamsService do
let(:chat_service) { described_class.new }
- let(:webhook_url) { 'https://example.gitlab.com/' }
+ let(:webhook_url) { "https://example.gitlab.com/" }
describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:webhook) }
- it_behaves_like 'issue tracker service URL attribute', :webhook
+ it_behaves_like "issue tracker service URL attribute", :webhook
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -43,7 +43,7 @@ describe MicrosoftTeamsService do
WebMock.stub_request(:post, webhook_url)
end
- context 'with push events' do
+ context "with push events" do
let(:push_sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
@@ -54,19 +54,19 @@ describe MicrosoftTeamsService do
expect(WebMock).to have_requested(:post, webhook_url).once
end
- it 'specifies the webhook when it is configured' do
+ it "specifies the webhook when it is configured" do
expect(MicrosoftTeams::Notifier).to receive(:new).with(webhook_url).and_return(double(:microsoft_teams_service).as_null_object)
chat_service.execute(push_sample_data)
end
end
- context 'with issue events' do
- let(:opts) { { title: 'Awesome issue', description: 'please fix' } }
+ context "with issue events" do
+ let(:opts) { {title: "Awesome issue", description: "please fix"} }
let(:issues_sample_data) do
service = Issues::CreateService.new(project, user, opts)
issue = service.execute
- service.hook_data(issue, 'open')
+ service.hook_data(issue, "open")
end
it "calls Microsoft Teams API" do
@@ -76,20 +76,20 @@ describe MicrosoftTeamsService do
end
end
- context 'with merge events' do
+ context "with merge events" do
let(:opts) do
{
- title: 'Awesome merge_request',
- description: 'please fix',
- source_branch: 'feature',
- target_branch: 'master'
+ title: "Awesome merge_request",
+ description: "please fix",
+ source_branch: "feature",
+ target_branch: "master",
}
end
let(:merge_sample_data) do
service = MergeRequests::CreateService.new(project, user, opts)
merge_request = service.execute
- service.hook_data(merge_request, 'open')
+ service.hook_data(merge_request, "open")
end
before do
@@ -103,17 +103,17 @@ describe MicrosoftTeamsService do
end
end
- context 'with wiki page events' do
+ context "with wiki page events" do
let(:opts) do
{
title: "Awesome wiki_page",
content: "Some text describing some thing or another",
format: "md",
- message: "user created page: Awesome wiki_page"
+ message: "user created page: Awesome wiki_page",
}
end
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) }
- let(:wiki_page_sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, 'create') }
+ let(:wiki_page_sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, "create") }
it "calls Microsoft Teams API" do
chat_service.execute(wiki_page_sample_data)
@@ -138,12 +138,12 @@ describe MicrosoftTeamsService do
WebMock.stub_request(:post, webhook_url)
end
- context 'when commit comment event executed' do
+ context "when commit comment event executed" do
let(:commit_note) do
create(:note_on_commit, author: user,
project: project,
commit_id: project.repository.commit.id,
- note: 'a comment on a commit')
+ note: "a comment on a commit")
end
it "calls Microsoft Teams API for commit comment events" do
@@ -155,7 +155,7 @@ describe MicrosoftTeamsService do
end
end
- context 'when merge request comment event executed' do
+ context "when merge request comment event executed" do
let(:merge_request_note) do
create(:note_on_merge_request, project: project,
note: "merge request note")
@@ -170,7 +170,7 @@ describe MicrosoftTeamsService do
end
end
- context 'when issue comment event executed' do
+ context "when issue comment event executed" do
let(:issue_note) do
create(:note_on_issue, project: project, note: "issue note")
end
@@ -184,7 +184,7 @@ describe MicrosoftTeamsService do
end
end
- context 'when snippet comment event executed' do
+ context "when snippet comment event executed" do
let(:snippet_note) do
create(:note_on_project_snippet, project: project,
note: "snippet note")
@@ -200,14 +200,14 @@ describe MicrosoftTeamsService do
end
end
- describe 'Pipeline events' do
+ describe "Pipeline events" do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:pipeline) do
create(:ci_pipeline,
- project: project, status: status,
- sha: project.commit.sha, ref: project.default_branch)
+ project: project, status: status,
+ sha: project.commit.sha, ref: project.default_branch)
end
before do
@@ -218,12 +218,12 @@ describe MicrosoftTeamsService do
)
end
- shared_examples 'call Microsoft Teams API' do
+ shared_examples "call Microsoft Teams API" do
before do
WebMock.stub_request(:post, webhook_url)
end
- it 'calls Microsoft Teams API for pipeline events' do
+ it "calls Microsoft Teams API for pipeline events" do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
data[:markdown] = true
@@ -232,22 +232,22 @@ describe MicrosoftTeamsService do
message = ChatMessage::PipelineMessage.new(data)
expect(WebMock).to have_requested(:post, webhook_url)
- .with(body: hash_including({ summary: message.summary }))
+ .with(body: hash_including({summary: message.summary}))
.once
end
end
- context 'with failed pipeline' do
- let(:status) { 'failed' }
+ context "with failed pipeline" do
+ let(:status) { "failed" }
- it_behaves_like 'call Microsoft Teams API'
+ it_behaves_like "call Microsoft Teams API"
end
- context 'with succeeded pipeline' do
- let(:status) { 'success' }
+ context "with succeeded pipeline" do
+ let(:status) { "success" }
- context 'with default to notify_only_broken_pipelines' do
- it 'does not call Microsoft Teams API for pipeline events' do
+ context "with default to notify_only_broken_pipelines" do
+ it "does not call Microsoft Teams API for pipeline events" do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
@@ -255,26 +255,26 @@ describe MicrosoftTeamsService do
end
end
- context 'with setting notify_only_broken_pipelines to false' do
+ context "with setting notify_only_broken_pipelines to false" do
before do
chat_service.notify_only_broken_pipelines = false
end
- it_behaves_like 'call Microsoft Teams API'
+ it_behaves_like "call Microsoft Teams API"
end
end
- context 'only notify for the default branch' do
- context 'when enabled' do
+ context "only notify for the default branch" do
+ context "when enabled" do
let(:pipeline) do
- create(:ci_pipeline, project: project, status: 'failed', ref: 'not-the-default-branch')
+ create(:ci_pipeline, project: project, status: "failed", ref: "not-the-default-branch")
end
before do
chat_service.notify_only_default_branch = true
end
- it 'does not call the Microsoft Teams API for pipeline events' do
+ it "does not call the Microsoft Teams API for pipeline events" do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
diff --git a/spec/models/project_services/packagist_service_spec.rb b/spec/models/project_services/packagist_service_spec.rb
index 6acee311700..a71227a251b 100644
--- a/spec/models/project_services/packagist_service_spec.rb
+++ b/spec/models/project_services/packagist_service_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe PackagistService do
describe "Associations" do
@@ -8,26 +8,26 @@ describe PackagistService do
let(:project) { create(:project) }
- let(:packagist_server) { 'https://packagist.example.com' }
- let(:packagist_username) { 'theUser' }
- let(:packagist_token) { 'verySecret' }
+ let(:packagist_server) { "https://packagist.example.com" }
+ let(:packagist_username) { "theUser" }
+ let(:packagist_token) { "verySecret" }
let(:packagist_hook_url) do
"#{packagist_server}/api/update-package?username=#{packagist_username}&apiToken=#{packagist_token}"
end
let(:packagist_params) do
{
- active: true,
- project: project,
- properties: {
- username: packagist_username,
- token: packagist_token,
- server: packagist_server
- }
+ active: true,
+ project: project,
+ properties: {
+ username: packagist_username,
+ token: packagist_token,
+ server: packagist_server,
+ },
}
end
- describe '#execute' do
+ describe "#execute" do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:push_sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) }
@@ -37,7 +37,7 @@ describe PackagistService do
stub_request(:post, packagist_hook_url)
end
- it 'calls Packagist API' do
+ it "calls Packagist API" do
packagist_service.execute(push_sample_data)
expect(a_request(:post, packagist_hook_url)).to have_been_made.once
diff --git a/spec/models/project_services/pipelines_email_service_spec.rb b/spec/models/project_services/pipelines_email_service_spec.rb
index 75ae2207910..59f948da813 100644
--- a/spec/models/project_services/pipelines_email_service_spec.rb
+++ b/spec/models/project_services/pipelines_email_service_spec.rb
@@ -1,20 +1,20 @@
-require 'spec_helper'
+require "spec_helper"
describe PipelinesEmailService, :mailer do
let(:pipeline) do
- create(:ci_pipeline, project: project, sha: project.commit('master').sha)
+ create(:ci_pipeline, project: project, sha: project.commit("master").sha)
end
let(:project) { create(:project, :repository) }
- let(:recipients) { 'test@gitlab.com' }
+ let(:recipients) { "test@gitlab.com" }
let(:receivers) { [recipients] }
let(:data) do
Gitlab::DataBuilder::Pipeline.build(pipeline)
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -22,7 +22,7 @@ describe PipelinesEmailService, :mailer do
it { is_expected.to validate_presence_of(:recipients) }
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -31,7 +31,7 @@ describe PipelinesEmailService, :mailer do
end
end
- describe '#test_data' do
+ describe "#test_data" do
let(:build) { create(:ci_build) }
let(:project) { build.project }
let(:user) { create(:user) }
@@ -40,14 +40,14 @@ describe PipelinesEmailService, :mailer do
project.add_developer(user)
end
- it 'builds test data' do
+ it "builds test data" do
data = subject.test_data(project, user)
- expect(data[:object_kind]).to eq('pipeline')
+ expect(data[:object_kind]).to eq("pipeline")
end
end
- shared_examples 'sending email' do
+ shared_examples "sending email" do
before do
subject.recipients = recipients
@@ -56,14 +56,14 @@ describe PipelinesEmailService, :mailer do
end
end
- it 'sends email' do
+ it "sends email" do
emails = receivers.map { |r| double(notification_email: r) }
should_only_email(*emails, kind: :bcc)
end
end
- shared_examples 'not sending email' do
+ shared_examples "not sending email" do
before do
subject.recipients = recipients
@@ -72,108 +72,108 @@ describe PipelinesEmailService, :mailer do
end
end
- it 'does not send email' do
+ it "does not send email" do
should_not_email_anyone
end
end
- describe '#test' do
+ describe "#test" do
def run
subject.test(data)
end
- context 'when pipeline is failed' do
+ context "when pipeline is failed" do
before do
- data[:object_attributes][:status] = 'failed'
- pipeline.update(status: 'failed')
+ data[:object_attributes][:status] = "failed"
+ pipeline.update(status: "failed")
end
- it_behaves_like 'sending email'
+ it_behaves_like "sending email"
end
- context 'when pipeline is succeeded' do
+ context "when pipeline is succeeded" do
before do
- data[:object_attributes][:status] = 'success'
- pipeline.update(status: 'success')
+ data[:object_attributes][:status] = "success"
+ pipeline.update(status: "success")
end
- it_behaves_like 'sending email'
+ it_behaves_like "sending email"
end
end
- describe '#execute' do
+ describe "#execute" do
def run
subject.execute(data)
end
- context 'with recipients' do
- context 'with failed pipeline' do
+ context "with recipients" do
+ context "with failed pipeline" do
before do
- data[:object_attributes][:status] = 'failed'
- pipeline.update(status: 'failed')
+ data[:object_attributes][:status] = "failed"
+ pipeline.update(status: "failed")
end
- it_behaves_like 'sending email'
+ it_behaves_like "sending email"
end
- context 'with succeeded pipeline' do
+ context "with succeeded pipeline" do
before do
- data[:object_attributes][:status] = 'success'
- pipeline.update(status: 'success')
+ data[:object_attributes][:status] = "success"
+ pipeline.update(status: "success")
end
- it_behaves_like 'not sending email'
+ it_behaves_like "not sending email"
end
- context 'with notify_only_broken_pipelines on' do
+ context "with notify_only_broken_pipelines on" do
before do
subject.notify_only_broken_pipelines = true
end
- context 'with failed pipeline' do
+ context "with failed pipeline" do
before do
- data[:object_attributes][:status] = 'failed'
- pipeline.update(status: 'failed')
+ data[:object_attributes][:status] = "failed"
+ pipeline.update(status: "failed")
end
- it_behaves_like 'sending email'
+ it_behaves_like "sending email"
end
- context 'with succeeded pipeline' do
+ context "with succeeded pipeline" do
before do
- data[:object_attributes][:status] = 'success'
- pipeline.update(status: 'success')
+ data[:object_attributes][:status] = "success"
+ pipeline.update(status: "success")
end
- it_behaves_like 'not sending email'
+ it_behaves_like "not sending email"
end
end
end
- context 'with empty recipients list' do
- let(:recipients) { ' ,, ' }
+ context "with empty recipients list" do
+ let(:recipients) { " ,, " }
- context 'with failed pipeline' do
+ context "with failed pipeline" do
before do
- data[:object_attributes][:status] = 'failed'
- pipeline.update(status: 'failed')
+ data[:object_attributes][:status] = "failed"
+ pipeline.update(status: "failed")
end
- it_behaves_like 'not sending email'
+ it_behaves_like "not sending email"
end
end
- context 'with recipients list separating with newlines' do
+ context "with recipients list separating with newlines" do
let(:recipients) { "\ntest@gitlab.com, \r\nexample@gitlab.com" }
let(:receivers) { %w[test@gitlab.com example@gitlab.com] }
- context 'with failed pipeline' do
+ context "with failed pipeline" do
before do
- data[:object_attributes][:status] = 'failed'
- pipeline.update(status: 'failed')
+ data[:object_attributes][:status] = "failed"
+ pipeline.update(status: "failed")
end
- it_behaves_like 'sending email'
+ it_behaves_like "sending email"
end
end
end
diff --git a/spec/models/project_services/pivotaltracker_service_spec.rb b/spec/models/project_services/pivotaltracker_service_spec.rb
index f7d2372eca2..8496d9c6cbe 100644
--- a/spec/models/project_services/pivotaltracker_service_spec.rb
+++ b/spec/models/project_services/pivotaltracker_service_spec.rb
@@ -1,13 +1,13 @@
-require 'spec_helper'
+require "spec_helper"
describe PivotaltrackerService do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -15,7 +15,7 @@ describe PivotaltrackerService do
it { is_expected.to validate_presence_of(:token) }
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -24,29 +24,29 @@ describe PivotaltrackerService do
end
end
- describe 'Execute' do
+ describe "Execute" do
let(:service) do
described_class.new.tap do |service|
- service.token = 'secret_api_token'
+ service.token = "secret_api_token"
end
end
let(:url) { PivotaltrackerService::API_ENDPOINT }
- def push_data(branch: 'master')
+ def push_data(branch: "master")
{
- object_kind: 'push',
+ object_kind: "push",
ref: "refs/heads/#{branch}",
commits: [
{
- id: '21c12ea',
+ id: "21c12ea",
author: {
- name: 'Some User'
+ name: "Some User",
},
- url: 'https://example.com/commit',
- message: 'commit message'
- }
- ]
+ url: "https://example.com/commit",
+ message: "commit message",
+ },
+ ],
}
end
@@ -54,41 +54,41 @@ describe PivotaltrackerService do
WebMock.stub_request(:post, url)
end
- it 'should post correct message' do
+ it "should post correct message" do
service.execute(push_data)
expect(WebMock).to have_requested(:post, url).with(
body: {
- 'source_commit' => {
- 'commit_id' => '21c12ea',
- 'author' => 'Some User',
- 'url' => 'https://example.com/commit',
- 'message' => 'commit message'
- }
+ "source_commit" => {
+ "commit_id" => "21c12ea",
+ "author" => "Some User",
+ "url" => "https://example.com/commit",
+ "message" => "commit message",
+ },
},
headers: {
- 'Content-Type' => 'application/json',
- 'X-TrackerToken' => 'secret_api_token'
+ "Content-Type" => "application/json",
+ "X-TrackerToken" => "secret_api_token",
}
).once
end
- context 'when allowed branches is specified' do
+ context "when allowed branches is specified" do
let(:service) do
super().tap do |service|
- service.restrict_to_branch = 'master,v10'
+ service.restrict_to_branch = "master,v10"
end
end
- it 'should post message if branch is in the list' do
- service.execute(push_data(branch: 'master'))
- service.execute(push_data(branch: 'v10'))
+ it "should post message if branch is in the list" do
+ service.execute(push_data(branch: "master"))
+ service.execute(push_data(branch: "v10"))
expect(WebMock).to have_requested(:post, url).twice
end
- it 'should not post message if branch is not in the list' do
- service.execute(push_data(branch: 'mas'))
- service.execute(push_data(branch: 'v11'))
+ it "should not post message if branch is not in the list" do
+ service.execute(push_data(branch: "mas"))
+ service.execute(push_data(branch: "v11"))
expect(WebMock).not_to have_requested(:post, url)
end
diff --git a/spec/models/project_services/prometheus_service_spec.rb b/spec/models/project_services/prometheus_service_spec.rb
index b6cf4c72450..cd3890c4242 100644
--- a/spec/models/project_services/prometheus_service_spec.rb
+++ b/spec/models/project_services/prometheus_service_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe PrometheusService, :use_clean_rails_memory_store_caching do
include PrometheusHelpers
@@ -13,11 +13,11 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
it { is_expected.to belong_to :project }
end
- context 'redirects' do
- it 'does not follow redirects' do
- redirect_to = 'https://redirected.example.com'
- redirect_req_stub = stub_prometheus_request(prometheus_query_url('1'), status: 302, headers: { location: redirect_to })
- redirected_req_stub = stub_prometheus_request(redirect_to, body: { 'status': 'success' })
+ context "redirects" do
+ it "does not follow redirects" do
+ redirect_to = "https://redirected.example.com"
+ redirect_req_stub = stub_prometheus_request(prometheus_query_url("1"), status: 302, headers: {location: redirect_to})
+ redirected_req_stub = stub_prometheus_request(redirect_to, body: {'status': "success"})
result = service.test
@@ -30,8 +30,8 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
end
end
- describe 'Validations' do
- context 'when manual_configuration is enabled' do
+ describe "Validations" do
+ context "when manual_configuration is enabled" do
before do
subject.manual_configuration = true
end
@@ -39,7 +39,7 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
it { is_expected.to validate_presence_of(:api_url) }
end
- context 'when manual configuration is disabled' do
+ context "when manual configuration is disabled" do
before do
subject.manual_configuration = false
end
@@ -48,34 +48,34 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
end
end
- describe '#test' do
+ describe "#test" do
before do
service.manual_configuration = true
end
- let!(:req_stub) { stub_prometheus_request(prometheus_query_url('1'), body: prometheus_value_body('vector')) }
+ let!(:req_stub) { stub_prometheus_request(prometheus_query_url("1"), body: prometheus_value_body("vector")) }
- context 'success' do
- it 'reads the discovery endpoint' do
- expect(service.test[:result]).to eq('Checked API endpoint')
+ context "success" do
+ it "reads the discovery endpoint" do
+ expect(service.test[:result]).to eq("Checked API endpoint")
expect(service.test[:success]).to be_truthy
expect(req_stub).to have_been_requested.twice
end
end
- context 'failure' do
- let!(:req_stub) { stub_prometheus_request(prometheus_query_url('1'), status: 404) }
+ context "failure" do
+ let!(:req_stub) { stub_prometheus_request(prometheus_query_url("1"), status: 404) }
- it 'fails to read the discovery endpoint' do
+ it "fails to read the discovery endpoint" do
expect(service.test[:success]).to be_falsy
expect(req_stub).to have_been_requested
end
end
end
- describe '#prometheus_client' do
- context 'manual configuration is enabled' do
- let(:api_url) { 'http://some_url' }
+ describe "#prometheus_client" do
+ context "manual configuration is enabled" do
+ let(:api_url) { "http://some_url" }
before do
subject.active = true
@@ -83,128 +83,128 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
subject.api_url = api_url
end
- it 'returns rest client from api_url' do
+ it "returns rest client from api_url" do
expect(subject.prometheus_client.url).to eq(api_url)
end
end
- context 'manual configuration is disabled' do
- let(:api_url) { 'http://some_url' }
+ context "manual configuration is disabled" do
+ let(:api_url) { "http://some_url" }
before do
subject.manual_configuration = false
subject.api_url = api_url
end
- it 'no client provided' do
+ it "no client provided" do
expect(subject.prometheus_client).to be_nil
end
end
end
- describe '#prometheus_available?' do
- context 'clusters with installed prometheus' do
+ describe "#prometheus_available?" do
+ context "clusters with installed prometheus" do
let!(:cluster) { create(:cluster, projects: [project]) }
let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
- it 'returns true' do
+ it "returns true" do
expect(service.prometheus_available?).to be(true)
end
end
- context 'clusters with updated prometheus' do
+ context "clusters with updated prometheus" do
let!(:cluster) { create(:cluster, projects: [project]) }
let!(:prometheus) { create(:clusters_applications_prometheus, :updated, cluster: cluster) }
- it 'returns true' do
+ it "returns true" do
expect(service.prometheus_available?).to be(true)
end
end
- context 'clusters without prometheus installed' do
+ context "clusters without prometheus installed" do
let(:cluster) { create(:cluster, projects: [project]) }
let!(:prometheus) { create(:clusters_applications_prometheus, cluster: cluster) }
- it 'returns false' do
+ it "returns false" do
expect(service.prometheus_available?).to be(false)
end
end
- context 'clusters without prometheus' do
+ context "clusters without prometheus" do
let(:cluster) { create(:cluster, projects: [project]) }
- it 'returns false' do
+ it "returns false" do
expect(service.prometheus_available?).to be(false)
end
end
- context 'no clusters' do
- it 'returns false' do
+ context "no clusters" do
+ it "returns false" do
expect(service.prometheus_available?).to be(false)
end
end
end
- describe '#synchronize_service_state before_save callback' do
- context 'no clusters with prometheus are installed' do
- context 'when service is inactive' do
+ describe "#synchronize_service_state before_save callback" do
+ context "no clusters with prometheus are installed" do
+ context "when service is inactive" do
before do
service.active = false
end
- it 'activates service when manual_configuration is enabled' do
+ it "activates service when manual_configuration is enabled" do
expect { service.update!(manual_configuration: true) }.to change { service.active }.from(false).to(true)
end
- it 'keeps service inactive when manual_configuration is disabled' do
+ it "keeps service inactive when manual_configuration is disabled" do
expect { service.update!(manual_configuration: false) }.not_to change { service.active }.from(false)
end
end
- context 'when service is active' do
+ context "when service is active" do
before do
service.active = true
end
- it 'keeps the service active when manual_configuration is enabled' do
+ it "keeps the service active when manual_configuration is enabled" do
expect { service.update!(manual_configuration: true) }.not_to change { service.active }.from(true)
end
- it 'inactivates the service when manual_configuration is disabled' do
+ it "inactivates the service when manual_configuration is disabled" do
expect { service.update!(manual_configuration: false) }.to change { service.active }.from(true).to(false)
end
end
end
- context 'with prometheus installed in the cluster' do
+ context "with prometheus installed in the cluster" do
before do
allow(service).to receive(:prometheus_available?).and_return(true)
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
service.active = false
end
- it 'activates service when manual_configuration is enabled' do
+ it "activates service when manual_configuration is enabled" do
expect { service.update!(manual_configuration: true) }.to change { service.active }.from(false).to(true)
end
- it 'activates service when manual_configuration is disabled' do
+ it "activates service when manual_configuration is disabled" do
expect { service.update!(manual_configuration: false) }.to change { service.active }.from(false).to(true)
end
end
- context 'when service is active' do
+ context "when service is active" do
before do
service.active = true
end
- it 'keeps service active when manual_configuration is enabled' do
+ it "keeps service active when manual_configuration is enabled" do
expect { service.update!(manual_configuration: true) }.not_to change { service.active }.from(true)
end
- it 'keeps service active when manual_configuration is disabled' do
+ it "keeps service active when manual_configuration is disabled" do
expect { service.update!(manual_configuration: false) }.not_to change { service.active }.from(true)
end
end
diff --git a/spec/models/project_services/pushover_service_spec.rb b/spec/models/project_services/pushover_service_spec.rb
index 54b8c658ff6..58dfa66b2b4 100644
--- a/spec/models/project_services/pushover_service_spec.rb
+++ b/spec/models/project_services/pushover_service_spec.rb
@@ -1,13 +1,13 @@
-require 'spec_helper'
+require "spec_helper"
describe PushoverService do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -17,7 +17,7 @@ describe PushoverService do
it { is_expected.to validate_presence_of(:priority) }
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -28,7 +28,7 @@ describe PushoverService do
end
end
- describe 'Execute' do
+ describe "Execute" do
let(:pushover) { described_class.new }
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
@@ -36,12 +36,12 @@ describe PushoverService do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
- let(:api_key) { 'verySecret' }
- let(:user_key) { 'verySecret' }
- let(:device) { 'myDevice' }
+ let(:api_key) { "verySecret" }
+ let(:user_key) { "verySecret" }
+ let(:device) { "myDevice" }
let(:priority) { 0 }
- let(:sound) { 'bike' }
- let(:api_url) { 'https://api.pushover.net/1/messages.json' }
+ let(:sound) { "bike" }
+ let(:api_url) { "https://api.pushover.net/1/messages.json" }
before do
allow(pushover).to receive_messages(
@@ -58,7 +58,7 @@ describe PushoverService do
WebMock.stub_request(:post, api_url)
end
- it 'calls Pushover API' do
+ it "calls Pushover API" do
pushover.execute(sample_data)
expect(WebMock).to have_requested(:post, api_url).once
diff --git a/spec/models/project_services/redmine_service_spec.rb b/spec/models/project_services/redmine_service_spec.rb
index 2ac14eab5e1..11de94c39cd 100644
--- a/spec/models/project_services/redmine_service_spec.rb
+++ b/spec/models/project_services/redmine_service_spec.rb
@@ -1,13 +1,13 @@
-require 'spec_helper'
+require "spec_helper"
describe RedmineService do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
@@ -15,12 +15,12 @@ describe RedmineService do
it { is_expected.to validate_presence_of(:project_url) }
it { is_expected.to validate_presence_of(:issues_url) }
it { is_expected.to validate_presence_of(:new_issue_url) }
- it_behaves_like 'issue tracker service URL attribute', :project_url
- it_behaves_like 'issue tracker service URL attribute', :issues_url
- it_behaves_like 'issue tracker service URL attribute', :new_issue_url
+ it_behaves_like "issue tracker service URL attribute", :project_url
+ it_behaves_like "issue tracker service URL attribute", :issues_url
+ it_behaves_like "issue tracker service URL attribute", :new_issue_url
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -31,11 +31,11 @@ describe RedmineService do
end
end
- describe '.reference_pattern' do
- it_behaves_like 'allows project key on reference pattern'
+ describe ".reference_pattern" do
+ it_behaves_like "allows project key on reference pattern"
- it 'does allow # on the reference' do
- expect(described_class.reference_pattern.match('#123')[:issue]).to eq('123')
+ it "does allow # on the reference" do
+ expect(described_class.reference_pattern.match("#123")[:issue]).to eq("123")
end
end
end
diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb
index 13cf4d1915e..fc4cbd0827a 100644
--- a/spec/models/project_services/slack_service_spec.rb
+++ b/spec/models/project_services/slack_service_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe SlackService do
it_behaves_like "slack or mattermost notifications"
diff --git a/spec/models/project_services/slack_slash_commands_service_spec.rb b/spec/models/project_services/slack_slash_commands_service_spec.rb
index 5c4bce90ace..75d3c4b63eb 100644
--- a/spec/models/project_services/slack_slash_commands_service_spec.rb
+++ b/spec/models/project_services/slack_slash_commands_service_spec.rb
@@ -1,37 +1,37 @@
-require 'spec_helper'
+require "spec_helper"
describe SlackSlashCommandsService do
it_behaves_like "chat slash commands service"
- describe '#trigger' do
- context 'when an auth url is generated' do
+ describe "#trigger" do
+ context "when an auth url is generated" do
let(:project) { create(:project) }
let(:params) do
{
- team_domain: 'http://domain.tld',
- team_id: 'T3423423',
- user_id: 'U234234',
- user_name: 'mepmep',
- token: 'token'
+ team_domain: "http://domain.tld",
+ team_id: "T3423423",
+ user_id: "U234234",
+ user_name: "mepmep",
+ token: "token",
}
end
let(:service) do
project.create_slack_slash_commands_service(
- properties: { token: 'token' },
+ properties: {token: "token"},
active: true
)
end
let(:authorize_url) do
- 'http://authorize.example.com/'
+ "http://authorize.example.com/"
end
before do
allow(service).to receive(:authorize_chat_name_url).and_return(authorize_url)
end
- it 'uses slack compatible links' do
+ it "uses slack compatible links" do
response = service.trigger(params)
expect(response[:text]).to include("<#{authorize_url}|connect your GitLab account>")
@@ -39,8 +39,8 @@ describe SlackSlashCommandsService do
end
end
- describe '#chat_responder' do
- it 'returns the responder to use for Slack' do
+ describe "#chat_responder" do
+ it "returns the responder to use for Slack" do
expect(described_class.new.chat_responder)
.to eq(Gitlab::Chat::Responder::Slack)
end
diff --git a/spec/models/project_services/teamcity_service_spec.rb b/spec/models/project_services/teamcity_service_spec.rb
index 64b4efca43a..f98b98651e3 100644
--- a/spec/models/project_services/teamcity_service_spec.rb
+++ b/spec/models/project_services/teamcity_service_spec.rb
@@ -1,67 +1,67 @@
-require 'spec_helper'
+require "spec_helper"
describe TeamcityService, :use_clean_rails_memory_store_caching do
include ReactiveCachingHelpers
- let(:teamcity_url) { 'http://gitlab.com/teamcity' }
+ let(:teamcity_url) { "http://gitlab.com/teamcity" }
subject(:service) do
described_class.create(
project: create(:project),
properties: {
teamcity_url: teamcity_url,
- username: 'mic',
- password: 'password',
- build_type: 'foo'
+ username: "mic",
+ password: "password",
+ build_type: "foo",
}
)
end
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:build_type) }
it { is_expected.to validate_presence_of(:teamcity_url) }
- it_behaves_like 'issue tracker service URL attribute', :teamcity_url
+ it_behaves_like "issue tracker service URL attribute", :teamcity_url
- describe '#username' do
- it 'does not validate the presence of username if password is nil' do
+ describe "#username" do
+ it "does not validate the presence of username if password is nil" do
subject.password = nil
expect(subject).not_to validate_presence_of(:username)
end
- it 'validates the presence of username if password is present' do
- subject.password = 'secret'
+ it "validates the presence of username if password is present" do
+ subject.password = "secret"
expect(subject).to validate_presence_of(:username)
end
end
- describe '#password' do
- it 'does not validate the presence of password if username is nil' do
+ describe "#password" do
+ it "does not validate the presence of password if username is nil" do
subject.username = nil
expect(subject).not_to validate_presence_of(:password)
end
- it 'validates the presence of password if username is present' do
- subject.username = 'john'
+ it "validates the presence of password if username is present" do
+ subject.username = "john"
expect(subject).to validate_presence_of(:password)
end
end
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -73,100 +73,100 @@ describe TeamcityService, :use_clean_rails_memory_store_caching do
end
end
- describe 'Callbacks' do
- describe 'before_update :reset_password' do
- context 'when a password was previously set' do
- it 'resets password if url changed' do
+ describe "Callbacks" do
+ describe "before_update :reset_password" do
+ context "when a password was previously set" do
+ it "resets password if url changed" do
teamcity_service = service
- teamcity_service.teamcity_url = 'http://gitlab1.com'
+ teamcity_service.teamcity_url = "http://gitlab1.com"
teamcity_service.save
expect(teamcity_service.password).to be_nil
end
- it 'does not reset password if username changed' do
+ it "does not reset password if username changed" do
teamcity_service = service
- teamcity_service.username = 'some_name'
+ teamcity_service.username = "some_name"
teamcity_service.save
- expect(teamcity_service.password).to eq('password')
+ expect(teamcity_service.password).to eq("password")
end
it "does not reset password if new url is set together with password, even if it's the same password" do
teamcity_service = service
- teamcity_service.teamcity_url = 'http://gitlab_edited.com'
- teamcity_service.password = 'password'
+ teamcity_service.teamcity_url = "http://gitlab_edited.com"
+ teamcity_service.password = "password"
teamcity_service.save
- expect(teamcity_service.password).to eq('password')
- expect(teamcity_service.teamcity_url).to eq('http://gitlab_edited.com')
+ expect(teamcity_service.password).to eq("password")
+ expect(teamcity_service.teamcity_url).to eq("http://gitlab_edited.com")
end
end
- it 'saves password if new url is set together with password when no password was previously set' do
+ it "saves password if new url is set together with password when no password was previously set" do
teamcity_service = service
teamcity_service.password = nil
- teamcity_service.teamcity_url = 'http://gitlab_edited.com'
- teamcity_service.password = 'password'
+ teamcity_service.teamcity_url = "http://gitlab_edited.com"
+ teamcity_service.password = "password"
teamcity_service.save
- expect(teamcity_service.password).to eq('password')
- expect(teamcity_service.teamcity_url).to eq('http://gitlab_edited.com')
+ expect(teamcity_service.password).to eq("password")
+ expect(teamcity_service.teamcity_url).to eq("http://gitlab_edited.com")
end
end
end
- describe '#build_page' do
- it 'returns the contents of the reactive cache' do
- stub_reactive_cache(service, { build_page: 'foo' }, 'sha', 'ref')
+ describe "#build_page" do
+ it "returns the contents of the reactive cache" do
+ stub_reactive_cache(service, {build_page: "foo"}, "sha", "ref")
- expect(service.build_page('sha', 'ref')).to eq('foo')
+ expect(service.build_page("sha", "ref")).to eq("foo")
end
end
- describe '#commit_status' do
- it 'returns the contents of the reactive cache' do
- stub_reactive_cache(service, { commit_status: 'foo' }, 'sha', 'ref')
+ describe "#commit_status" do
+ it "returns the contents of the reactive cache" do
+ stub_reactive_cache(service, {commit_status: "foo"}, "sha", "ref")
- expect(service.commit_status('sha', 'ref')).to eq('foo')
+ expect(service.commit_status("sha", "ref")).to eq("foo")
end
end
- describe '#calculate_reactive_cache' do
- context 'build_page' do
- subject { service.calculate_reactive_cache('123', 'unused')[:build_page] }
+ describe "#calculate_reactive_cache" do
+ context "build_page" do
+ subject { service.calculate_reactive_cache("123", "unused")[:build_page] }
- it 'returns a specific URL when status is 500' do
+ it "returns a specific URL when status is 500" do
stub_request(status: 500)
- is_expected.to eq('http://gitlab.com/teamcity/viewLog.html?buildTypeId=foo')
+ is_expected.to eq("http://gitlab.com/teamcity/viewLog.html?buildTypeId=foo")
end
- it 'returns a build URL when teamcity_url has no trailing slash' do
- stub_request(body: %q({"build":{"id":"666"}}))
+ it "returns a build URL when teamcity_url has no trailing slash" do
+ stub_request(body: '{"build":{"id":"666"}}')
- is_expected.to eq('http://gitlab.com/teamcity/viewLog.html?buildId=666&buildTypeId=foo')
+ is_expected.to eq("http://gitlab.com/teamcity/viewLog.html?buildId=666&buildTypeId=foo")
end
- context 'teamcity_url has trailing slash' do
- let(:teamcity_url) { 'http://gitlab.com/teamcity/' }
+ context "teamcity_url has trailing slash" do
+ let(:teamcity_url) { "http://gitlab.com/teamcity/" }
- it 'returns a build URL' do
- stub_request(body: %q({"build":{"id":"666"}}))
+ it "returns a build URL" do
+ stub_request(body: '{"build":{"id":"666"}}')
- is_expected.to eq('http://gitlab.com/teamcity/viewLog.html?buildId=666&buildTypeId=foo')
+ is_expected.to eq("http://gitlab.com/teamcity/viewLog.html?buildId=666&buildTypeId=foo")
end
end
end
- context 'commit_status' do
- subject { service.calculate_reactive_cache('123', 'unused')[:commit_status] }
+ context "commit_status" do
+ subject { service.calculate_reactive_cache("123", "unused")[:commit_status] }
- it 'sets commit status to :error when status is 500' do
+ it "sets commit status to :error when status is 500" do
stub_request(status: 500)
is_expected.to eq(:error)
@@ -175,44 +175,44 @@ describe TeamcityService, :use_clean_rails_memory_store_caching do
it 'sets commit status to "pending" when status is 404' do
stub_request(status: 404)
- is_expected.to eq('pending')
+ is_expected.to eq("pending")
end
it 'sets commit status to "success" when build status contains SUCCESS' do
- stub_request(build_status: 'YAY SUCCESS!')
+ stub_request(build_status: "YAY SUCCESS!")
- is_expected.to eq('success')
+ is_expected.to eq("success")
end
it 'sets commit status to "failed" when build status contains FAILURE' do
- stub_request(build_status: 'NO FAILURE!')
+ stub_request(build_status: "NO FAILURE!")
- is_expected.to eq('failed')
+ is_expected.to eq("failed")
end
it 'sets commit status to "pending" when build status contains Pending' do
- stub_request(build_status: 'NO Pending!')
+ stub_request(build_status: "NO Pending!")
- is_expected.to eq('pending')
+ is_expected.to eq("pending")
end
- it 'sets commit status to :error when build status is unknown' do
- stub_request(build_status: 'FOO BAR!')
+ it "sets commit status to :error when build status is unknown" do
+ stub_request(build_status: "FOO BAR!")
is_expected.to eq(:error)
end
end
end
- def stub_request(status: 200, body: nil, build_status: 'success')
- teamcity_full_url = 'http://gitlab.com/teamcity/httpAuth/app/rest/builds/branch:unspecified:any,revision:123'
- auth = %w(mic password)
+ def stub_request(status: 200, body: nil, build_status: "success")
+ teamcity_full_url = "http://gitlab.com/teamcity/httpAuth/app/rest/builds/branch:unspecified:any,revision:123"
+ auth = %w[mic password]
- body ||= %Q({"build":{"status":"#{build_status}","id":"666"}})
+ body ||= %({"build":{"status":"#{build_status}","id":"666"}})
WebMock.stub_request(:get, teamcity_full_url).with(basic_auth: auth).to_return(
status: status,
- headers: { 'Content-Type' => 'application/json' },
+ headers: {"Content-Type" => "application/json"},
body: body
)
end
diff --git a/spec/models/project_services/youtrack_service_spec.rb b/spec/models/project_services/youtrack_service_spec.rb
index 9524b526a46..053ec2822da 100644
--- a/spec/models/project_services/youtrack_service_spec.rb
+++ b/spec/models/project_services/youtrack_service_spec.rb
@@ -1,24 +1,24 @@
-require 'spec_helper'
+require "spec_helper"
describe YoutrackService do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
- context 'when service is active' do
+ describe "Validations" do
+ context "when service is active" do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:project_url) }
it { is_expected.to validate_presence_of(:issues_url) }
- it_behaves_like 'issue tracker service URL attribute', :project_url
- it_behaves_like 'issue tracker service URL attribute', :issues_url
+ it_behaves_like "issue tracker service URL attribute", :project_url
+ it_behaves_like "issue tracker service URL attribute", :issues_url
end
- context 'when service is inactive' do
+ context "when service is inactive" do
before do
subject.active = false
end
@@ -28,11 +28,11 @@ describe YoutrackService do
end
end
- describe '.reference_pattern' do
- it_behaves_like 'allows project key on reference pattern'
+ describe ".reference_pattern" do
+ it_behaves_like "allows project key on reference pattern"
- it 'does allow project prefix on the reference' do
- expect(described_class.reference_pattern.match('YT-123')[:issue]).to eq('YT-123')
+ it "does allow project prefix on the reference" do
+ expect(described_class.reference_pattern.match("YT-123")[:issue]).to eq("YT-123")
end
end
end
diff --git a/spec/models/project_snippet_spec.rb b/spec/models/project_snippet_spec.rb
index 1b439bcfad1..cde6f68718f 100644
--- a/spec/models/project_snippet_spec.rb
+++ b/spec/models/project_snippet_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ProjectSnippet do
describe "Associations" do
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 9fb0d04ca9e..3f3b6196d23 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -1,15 +1,15 @@
-require 'spec_helper'
+require "spec_helper"
describe Project do
include ProjectForksHelper
include GitHelpers
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:group) }
it { is_expected.to belong_to(:namespace) }
- it { is_expected.to belong_to(:creator).class_name('User') }
+ it { is_expected.to belong_to(:creator).class_name("User") }
it { is_expected.to belong_to(:pool_repository) }
it { is_expected.to have_many(:users) }
it { is_expected.to have_many(:services) }
@@ -21,7 +21,7 @@ describe Project do
it { is_expected.to have_many(:users).through(:project_members) }
it { is_expected.to have_many(:requesters).dependent(:delete_all) }
it { is_expected.to have_many(:notes) }
- it { is_expected.to have_many(:snippets).class_name('ProjectSnippet') }
+ it { is_expected.to have_many(:snippets).class_name("ProjectSnippet") }
it { is_expected.to have_many(:deploy_keys_projects) }
it { is_expected.to have_many(:deploy_keys) }
it { is_expected.to have_many(:hooks) }
@@ -57,12 +57,12 @@ describe Project do
it { is_expected.to have_one(:external_wiki_service) }
it { is_expected.to have_one(:project_feature) }
it { is_expected.to have_one(:project_repository) }
- it { is_expected.to have_one(:statistics).class_name('ProjectStatistics') }
- it { is_expected.to have_one(:import_data).class_name('ProjectImportData') }
- it { is_expected.to have_one(:last_event).class_name('Event') }
+ it { is_expected.to have_one(:statistics).class_name("ProjectStatistics") }
+ it { is_expected.to have_one(:import_data).class_name("ProjectImportData") }
+ it { is_expected.to have_one(:last_event).class_name("Event") }
it { is_expected.to have_one(:forked_from_project).through(:fork_network_member) }
- it { is_expected.to have_one(:auto_devops).class_name('ProjectAutoDevops') }
- it { is_expected.to have_one(:error_tracking_setting).class_name('ErrorTracking::ProjectErrorTrackingSetting') }
+ it { is_expected.to have_one(:auto_devops).class_name("ProjectAutoDevops") }
+ it { is_expected.to have_one(:error_tracking_setting).class_name("ErrorTracking::ProjectErrorTrackingSetting") }
it { is_expected.to have_many(:commit_statuses) }
it { is_expected.to have_many(:ci_pipelines) }
it { is_expected.to have_many(:builds) }
@@ -72,7 +72,7 @@ describe Project do
it { is_expected.to have_many(:variables) }
it { is_expected.to have_many(:triggers) }
it { is_expected.to have_many(:pages_domains) }
- it { is_expected.to have_many(:labels).class_name('ProjectLabel') }
+ it { is_expected.to have_many(:labels).class_name("ProjectLabel") }
it { is_expected.to have_many(:users_star_projects) }
it { is_expected.to have_many(:repository_languages) }
it { is_expected.to have_many(:environments) }
@@ -82,31 +82,31 @@ describe Project do
it { is_expected.to have_many(:lfs_objects_projects) }
it { is_expected.to have_many(:project_group_links) }
it { is_expected.to have_many(:notification_settings).dependent(:delete_all) }
- it { is_expected.to have_many(:forked_to_members).class_name('ForkNetworkMember') }
+ it { is_expected.to have_many(:forked_to_members).class_name("ForkNetworkMember") }
it { is_expected.to have_many(:forks).through(:forked_to_members) }
it { is_expected.to have_many(:uploads) }
it { is_expected.to have_many(:pipeline_schedules) }
it { is_expected.to have_many(:members_and_requesters) }
it { is_expected.to have_many(:clusters) }
it { is_expected.to have_many(:kubernetes_namespaces) }
- it { is_expected.to have_many(:custom_attributes).class_name('ProjectCustomAttribute') }
- it { is_expected.to have_many(:project_badges).class_name('ProjectBadge') }
+ it { is_expected.to have_many(:custom_attributes).class_name("ProjectCustomAttribute") }
+ it { is_expected.to have_many(:project_badges).class_name("ProjectBadge") }
it { is_expected.to have_many(:lfs_file_locks) }
it { is_expected.to have_many(:project_deploy_tokens) }
it { is_expected.to have_many(:deploy_tokens).through(:project_deploy_tokens) }
- it 'has an inverse relationship with merge requests' do
+ it "has an inverse relationship with merge requests" do
expect(described_class.reflect_on_association(:merge_requests).has_inverse?).to eq(:target_project)
end
- context 'after initialized' do
+ context "after initialized" do
it "has a project_feature" do
expect(described_class.new.project_feature).to be_present
end
end
- context 'when creating a new project' do
- it 'automatically creates a CI/CD settings row' do
+ context "when creating a new project" do
+ it "automatically creates a CI/CD settings row" do
project = create(:project)
expect(project.ci_cd_settings).to be_an_instance_of(ProjectCiCdSetting)
@@ -114,15 +114,15 @@ describe Project do
end
end
- context 'updating cd_cd_settings' do
- it 'does not raise an error' do
+ context "updating cd_cd_settings" do
+ it "does not raise an error" do
project = create(:project)
expect { project.update(ci_cd_settings: nil) }.not_to raise_exception
end
end
- describe '#members & #requesters' do
+ describe "#members & #requesters" do
let(:project) { create(:project, :public, :access_requestable) }
let(:requester) { create(:user) }
let(:developer) { create(:user) }
@@ -131,22 +131,22 @@ describe Project do
project.add_developer(developer)
end
- it_behaves_like 'members and requesters associations' do
+ it_behaves_like "members and requesters associations" do
let(:namespace) { project }
end
end
- describe '#boards' do
- it 'raises an error when attempting to add more than one board to the project' do
+ describe "#boards" do
+ it "raises an error when attempting to add more than one board to the project" do
subject.boards.build
- expect { subject.boards.build }.to raise_error(Project::BoardLimitExceeded, 'Number of permitted boards exceeded')
+ expect { subject.boards.build }.to raise_error(Project::BoardLimitExceeded, "Number of permitted boards exceeded")
expect(subject.boards.size).to eq 1
end
end
- describe 'ci_pipelines association' do
- it 'returns only pipelines from ci_sources' do
+ describe "ci_pipelines association" do
+ it "returns only pipelines from ci_sources" do
expect(Ci::Pipeline).to receive(:ci_sources).and_call_original
subject.ci_pipelines
@@ -154,7 +154,7 @@ describe Project do
end
end
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Gitlab::ConfigHelper) }
@@ -164,7 +164,7 @@ describe Project do
it { is_expected.to include_module(Sortable) }
end
- describe '.missing_kubernetes_namespace' do
+ describe ".missing_kubernetes_namespace" do
let!(:project) { create(:project) }
let!(:cluster) { create(:cluster, :provided_by_user, :group) }
let(:kubernetes_namespaces) { project.kubernetes_namespaces }
@@ -173,7 +173,7 @@ describe Project do
it { is_expected.to contain_exactly(project) }
- context 'kubernetes namespace exists' do
+ context "kubernetes namespace exists" do
before do
create(:cluster_kubernetes_namespace, project: project, cluster: cluster)
end
@@ -182,7 +182,7 @@ describe Project do
end
end
- describe 'validation' do
+ describe "validation" do
let!(:project) { create(:project) }
it { is_expected.to validate_presence_of(:name) }
@@ -192,22 +192,22 @@ describe Project do
it { is_expected.to validate_length_of(:path).is_at_most(255) }
it { is_expected.to validate_length_of(:description).is_at_most(2000) }
it { is_expected.to validate_length_of(:ci_config_path).is_at_most(255) }
- it { is_expected.to allow_value('').for(:ci_config_path) }
- it { is_expected.not_to allow_value('test/../foo').for(:ci_config_path) }
- it { is_expected.not_to allow_value('/test/foo').for(:ci_config_path) }
+ it { is_expected.to allow_value("").for(:ci_config_path) }
+ it { is_expected.not_to allow_value("test/../foo").for(:ci_config_path) }
+ it { is_expected.not_to allow_value("/test/foo").for(:ci_config_path) }
it { is_expected.to validate_presence_of(:creator) }
it { is_expected.to validate_presence_of(:namespace) }
it { is_expected.to validate_presence_of(:repository_storage) }
- it 'validates build timeout constraints' do
+ it "validates build timeout constraints" do
is_expected.to validate_numericality_of(:build_timeout)
.only_integer
.is_greater_than_or_equal_to(10.minutes)
.is_less_than(1.month)
- .with_message('needs to be beetween 10 minutes and 1 month')
+ .with_message("needs to be beetween 10 minutes and 1 month")
end
- it 'does not allow new projects beyond user limits' do
+ it "does not allow new projects beyond user limits" do
project2 = build(:project)
allow(project2)
@@ -219,32 +219,32 @@ describe Project do
expect(project2).not_to be_valid
end
- describe 'wiki path conflict' do
+ describe "wiki path conflict" do
context "when the new path has been used by the wiki of other Project" do
- it 'has an error on the name attribute' do
+ it "has 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')
+ 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 'has 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')
+ it "has 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')
+ expect(new_project.errors[:name].first).to eq("has already been taken")
end
end
end
- context 'repository storages inclusion' do
- let(:project2) { build(:project, repository_storage: 'missing') }
+ context "repository storages inclusion" do
+ let(:project2) { build(:project, repository_storage: "missing") }
before do
- storages = { 'custom' => { 'path' => 'tmp/tests/custom_repositories' } }
+ storages = {"custom" => {"path" => "tmp/tests/custom_repositories"}}
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end
@@ -254,89 +254,89 @@ describe Project do
end
end
- describe 'import_url' do
- it 'does not allow an invalid URI as import_url' do
- project = build(:project, import_url: 'invalid://')
+ describe "import_url" do
+ it "does not allow an invalid URI as import_url" do
+ project = build(:project, import_url: "invalid://")
expect(project).not_to be_valid
end
- it 'does allow a SSH URI as import_url for persisted projects' do
+ it "does allow a SSH URI as import_url for persisted projects" do
project = create(:project)
- project.import_url = 'ssh://test@gitlab.com/project.git'
+ project.import_url = "ssh://test@gitlab.com/project.git"
expect(project).to be_valid
end
- it 'does not allow a SSH URI as import_url for new projects' do
- project = build(:project, import_url: 'ssh://test@gitlab.com/project.git')
+ it "does not allow a SSH URI as import_url for new projects" do
+ project = build(:project, import_url: "ssh://test@gitlab.com/project.git")
expect(project).not_to be_valid
end
- it 'does allow a valid URI as import_url' do
- project = build(:project, import_url: 'http://gitlab.com/project.git')
+ it "does allow a valid URI as import_url" do
+ project = build(:project, import_url: "http://gitlab.com/project.git")
expect(project).to be_valid
end
- it 'allows an empty URI' do
- project = build(:project, import_url: '')
+ it "allows an empty URI" do
+ project = build(:project, import_url: "")
expect(project).to be_valid
end
- it 'does not produce import data on an empty URI' do
- project = build(:project, import_url: '')
+ it "does not produce import data on an empty URI" do
+ project = build(:project, import_url: "")
expect(project.import_data).to be_nil
end
- it 'does not produce import data on an invalid URI' do
- project = build(:project, import_url: 'test://')
+ it "does not produce import data on an invalid URI" do
+ project = build(:project, import_url: "test://")
expect(project.import_data).to be_nil
end
it "does not allow import_url pointing to localhost" do
- project = build(:project, import_url: 'http://localhost:9000/t.git')
+ project = build(:project, import_url: "http://localhost:9000/t.git")
expect(project).to be_invalid
- expect(project.errors[:import_url].first).to include('Requests to localhost are not allowed')
+ expect(project.errors[:import_url].first).to include("Requests to localhost are not allowed")
end
- it 'does not allow import_url pointing to the local network' do
- project = build(:project, import_url: 'https://192.168.1.1')
+ it "does not allow import_url pointing to the local network" do
+ project = build(:project, import_url: "https://192.168.1.1")
expect(project).to be_invalid
- expect(project.errors[:import_url].first).to include('Requests to the local network are not allowed')
+ expect(project.errors[:import_url].first).to include("Requests to the local network are not allowed")
end
it "does not allow import_url with invalid ports for new projects" do
- project = build(:project, import_url: 'http://github.com:25/t.git')
+ project = build(:project, import_url: "http://github.com:25/t.git")
expect(project).to be_invalid
- expect(project.errors[:import_url].first).to include('Only allowed ports are 80, 443')
+ expect(project.errors[:import_url].first).to include("Only allowed ports are 80, 443")
end
it "does not allow import_url with invalid ports for persisted projects" do
project = create(:project)
- project.import_url = 'http://github.com:25/t.git'
+ project.import_url = "http://github.com:25/t.git"
expect(project).to be_invalid
- expect(project.errors[:import_url].first).to include('Only allowed ports are 22, 80, 443')
+ expect(project.errors[:import_url].first).to include("Only allowed ports are 22, 80, 443")
end
it "does not allow import_url with invalid user" do
- project = build(:project, import_url: 'http://$user:password@github.com/t.git')
+ project = build(:project, import_url: "http://$user:password@github.com/t.git")
expect(project).to be_invalid
- expect(project.errors[:import_url].first).to include('Username needs to start with an alphanumeric character')
+ expect(project.errors[:import_url].first).to include("Username needs to start with an alphanumeric character")
end
- include_context 'invalid urls'
+ include_context "invalid urls"
- it 'does not allow urls with CR or LF characters' do
+ it "does not allow urls with CR or LF characters" do
project = build(:project)
aggregate_failures do
@@ -350,122 +350,122 @@ describe Project do
end
end
- describe 'project pending deletion' do
+ describe "project pending deletion" do
let!(:project_pending_deletion) do
create(:project,
- pending_delete: true)
+ pending_delete: true)
end
let(:new_project) do
build(:project,
- name: project_pending_deletion.name,
- namespace: project_pending_deletion.namespace)
+ name: project_pending_deletion.name,
+ namespace: project_pending_deletion.namespace)
end
before do
new_project.validate
end
- it 'contains errors related to the project being deleted' do
- expect(new_project.errors.full_messages.first).to eq('The project is still being deleted. Please try again later.')
+ it "contains errors related to the project being deleted" do
+ expect(new_project.errors.full_messages.first).to eq("The project is still being deleted. Please try again later.")
end
end
- describe 'path validation' do
- it 'allows paths reserved on the root namespace' do
- project = build(:project, path: 'api')
+ describe "path validation" do
+ it "allows paths reserved on the root namespace" do
+ project = build(:project, path: "api")
expect(project).to be_valid
end
- it 'rejects paths reserved on another level' do
- project = build(:project, path: 'tree')
+ it "rejects paths reserved on another level" do
+ project = build(:project, path: "tree")
expect(project).not_to be_valid
end
- it 'rejects nested paths' do
- parent = create(:group, :nested, path: 'environments')
- project = build(:project, path: 'folders', namespace: parent)
+ it "rejects nested paths" do
+ parent = create(:group, :nested, path: "environments")
+ project = build(:project, path: "folders", namespace: parent)
expect(project).not_to be_valid
end
- it 'allows a reserved group name' do
+ it "allows a reserved group name" do
parent = create(:group)
- project = build(:project, path: 'avatar', namespace: parent)
+ project = build(:project, path: "avatar", namespace: parent)
expect(project).to be_valid
end
- it 'allows a path ending in a period' do
- project = build(:project, path: 'foo.')
+ it "allows a path ending in a period" do
+ project = build(:project, path: "foo.")
expect(project).to be_valid
end
end
end
- describe '#all_pipelines' do
+ describe "#all_pipelines" do
let(:project) { create(:project) }
before do
- create(:ci_pipeline, project: project, ref: 'master', source: :web)
- create(:ci_pipeline, project: project, ref: 'master', source: :external)
+ create(:ci_pipeline, project: project, ref: "master", source: :web)
+ create(:ci_pipeline, project: project, ref: "master", source: :external)
end
- it 'has all pipelines' do
+ it "has all pipelines" do
expect(project.all_pipelines.size).to eq(2)
end
- context 'when builds are disabled' do
+ context "when builds are disabled" do
before do
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::DISABLED)
end
- it 'should return .external pipelines' do
- expect(project.all_pipelines).to all(have_attributes(source: 'external'))
+ it "should return .external pipelines" do
+ expect(project.all_pipelines).to all(have_attributes(source: "external"))
expect(project.all_pipelines.size).to eq(1)
end
end
end
- describe '#ci_pipelines' do
+ describe "#ci_pipelines" do
let(:project) { create(:project) }
before do
- create(:ci_pipeline, project: project, ref: 'master', source: :web)
- create(:ci_pipeline, project: project, ref: 'master', source: :external)
+ create(:ci_pipeline, project: project, ref: "master", source: :web)
+ create(:ci_pipeline, project: project, ref: "master", source: :external)
end
- it 'has ci pipelines' do
+ it "has ci pipelines" do
expect(project.ci_pipelines.size).to eq(2)
end
- context 'when builds are disabled' do
+ context "when builds are disabled" do
before do
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::DISABLED)
end
- it 'should return .external pipelines' do
- expect(project.ci_pipelines).to all(have_attributes(source: 'external'))
+ it "should return .external pipelines" do
+ expect(project.ci_pipelines).to all(have_attributes(source: "external"))
expect(project.ci_pipelines.size).to eq(1)
end
end
end
- describe 'project token' do
- it 'sets an random token if none provided' do
- project = FactoryBot.create(:project, runners_token: '')
- expect(project.runners_token).not_to eq('')
+ describe "project token" do
+ it "sets an random token if none provided" do
+ project = FactoryBot.create(:project, runners_token: "")
+ expect(project.runners_token).not_to eq("")
end
- it 'does not set an random token if one provided' do
- project = FactoryBot.create(:project, runners_token: 'my-token')
- expect(project.runners_token).to eq('my-token')
+ it "does not set an random token if one provided" do
+ project = FactoryBot.create(:project, runners_token: "my-token")
+ expect(project.runners_token).to eq("my-token")
end
end
- describe 'Respond to' do
+ describe "Respond to" do
it { is_expected.to respond_to(:url_to_repo) }
it { is_expected.to respond_to(:repo_exists?) }
it { is_expected.to respond_to(:execute_hooks) }
@@ -474,7 +474,7 @@ describe Project do
it { is_expected.to respond_to(:full_path) }
end
- describe 'delegation' do
+ describe "delegation" do
[:add_guest, :add_reporter, :add_developer, :add_maintainer, :add_user, :add_users].each do |method|
it { is_expected.to delegate_method(method).to(:team) }
end
@@ -486,116 +486,116 @@ describe Project do
it { is_expected.to delegate_method(:last_pipeline).to(:commit).with_arguments(allow_nil: true) }
end
- describe '#to_reference_with_postfix' do
- it 'returns the full path with reference_postfix' do
- namespace = create(:namespace, path: 'sample-namespace')
- project = create(:project, path: 'sample-project', namespace: namespace)
+ describe "#to_reference_with_postfix" do
+ it "returns the full path with reference_postfix" do
+ namespace = create(:namespace, path: "sample-namespace")
+ project = create(:project, path: "sample-project", namespace: namespace)
- expect(project.to_reference_with_postfix).to eq 'sample-namespace/sample-project>'
+ expect(project.to_reference_with_postfix).to eq "sample-namespace/sample-project>"
end
end
- describe '#to_reference' do
- let(:owner) { create(:user, name: 'Gitlab') }
- let(:namespace) { create(:namespace, path: 'sample-namespace', owner: owner) }
- let(:project) { create(:project, path: 'sample-project', namespace: namespace) }
- let(:group) { create(:group, name: 'Group', path: 'sample-group') }
+ describe "#to_reference" do
+ let(:owner) { create(:user, name: "Gitlab") }
+ let(:namespace) { create(:namespace, path: "sample-namespace", owner: owner) }
+ let(:project) { create(:project, path: "sample-project", namespace: namespace) }
+ let(:group) { create(:group, name: "Group", path: "sample-group") }
- context 'when nil argument' do
- it 'returns nil' do
+ context "when nil argument" do
+ it "returns nil" do
expect(project.to_reference).to be_nil
end
end
- context 'when full is true' do
- it 'returns complete path to the project' do
- expect(project.to_reference(full: true)).to eq 'sample-namespace/sample-project'
- expect(project.to_reference(project, full: true)).to eq 'sample-namespace/sample-project'
- expect(project.to_reference(group, full: true)).to eq 'sample-namespace/sample-project'
+ context "when full is true" do
+ it "returns complete path to the project" do
+ expect(project.to_reference(full: true)).to eq "sample-namespace/sample-project"
+ expect(project.to_reference(project, full: true)).to eq "sample-namespace/sample-project"
+ expect(project.to_reference(group, full: true)).to eq "sample-namespace/sample-project"
end
end
- context 'when same project argument' do
- it 'returns nil' do
+ context "when same project argument" do
+ it "returns nil" do
expect(project.to_reference(project)).to be_nil
end
end
- context 'when cross namespace project argument' do
- let(:another_namespace_project) { create(:project, name: 'another-project') }
+ context "when cross namespace project argument" do
+ let(:another_namespace_project) { create(:project, name: "another-project") }
- it 'returns complete path to the project' do
- expect(project.to_reference(another_namespace_project)).to eq 'sample-namespace/sample-project'
+ it "returns complete path to the project" do
+ expect(project.to_reference(another_namespace_project)).to eq "sample-namespace/sample-project"
end
end
- context 'when same namespace / cross-project argument' do
+ context "when same namespace / cross-project argument" do
let(:another_project) { create(:project, namespace: namespace) }
- it 'returns path to the project' do
- expect(project.to_reference(another_project)).to eq 'sample-project'
+ it "returns path to the project" do
+ expect(project.to_reference(another_project)).to eq "sample-project"
end
end
- context 'when different namespace / cross-project argument' do
- let(:another_namespace) { create(:namespace, path: 'another-namespace', owner: owner) }
- let(:another_project) { create(:project, path: 'another-project', namespace: another_namespace) }
+ context "when different namespace / cross-project argument" do
+ let(:another_namespace) { create(:namespace, path: "another-namespace", owner: owner) }
+ let(:another_project) { create(:project, path: "another-project", namespace: another_namespace) }
- it 'returns full path to the project' do
- expect(project.to_reference(another_project)).to eq 'sample-namespace/sample-project'
+ it "returns full path to the project" do
+ expect(project.to_reference(another_project)).to eq "sample-namespace/sample-project"
end
end
- context 'when argument is a namespace' do
- context 'with same project path' do
- it 'returns path to the project' do
- expect(project.to_reference(namespace)).to eq 'sample-project'
+ context "when argument is a namespace" do
+ context "with same project path" do
+ it "returns path to the project" do
+ expect(project.to_reference(namespace)).to eq "sample-project"
end
end
- context 'with different project path' do
- it 'returns full path to the project' do
- expect(project.to_reference(group)).to eq 'sample-namespace/sample-project'
+ context "with different project path" do
+ it "returns full path to the project" do
+ expect(project.to_reference(group)).to eq "sample-namespace/sample-project"
end
end
end
end
- describe '#to_human_reference' do
- let(:owner) { create(:user, name: 'Gitlab') }
- let(:namespace) { create(:namespace, name: 'Sample namespace', owner: owner) }
- let(:project) { create(:project, name: 'Sample project', namespace: namespace) }
+ describe "#to_human_reference" do
+ let(:owner) { create(:user, name: "Gitlab") }
+ let(:namespace) { create(:namespace, name: "Sample namespace", owner: owner) }
+ let(:project) { create(:project, name: "Sample project", namespace: namespace) }
- context 'when nil argument' do
- it 'returns nil' do
+ context "when nil argument" do
+ it "returns nil" do
expect(project.to_human_reference).to be_nil
end
end
- context 'when same project argument' do
- it 'returns nil' do
+ context "when same project argument" do
+ it "returns nil" do
expect(project.to_human_reference(project)).to be_nil
end
end
- context 'when cross namespace project argument' do
- let(:another_namespace_project) { create(:project, name: 'another-project') }
+ context "when cross namespace project argument" do
+ let(:another_namespace_project) { create(:project, name: "another-project") }
- it 'returns complete name with namespace of the project' do
- expect(project.to_human_reference(another_namespace_project)).to eq 'Gitlab / Sample project'
+ it "returns complete name with namespace of the project" do
+ expect(project.to_human_reference(another_namespace_project)).to eq "Gitlab / Sample project"
end
end
- context 'when same namespace / cross-project argument' do
+ context "when same namespace / cross-project argument" do
let(:another_project) { create(:project, namespace: namespace) }
- it 'returns name of the project' do
- expect(project.to_human_reference(another_project)).to eq 'Sample project'
+ it "returns name of the project" do
+ expect(project.to_human_reference(another_project)).to eq "Sample project"
end
end
end
- describe '#merge_method' do
+ describe "#merge_method" do
using RSpec::Parameterized::TableSyntax
where(:ff, :rebase, :method) do
@@ -614,41 +614,41 @@ describe Project do
end
end
- it 'returns valid url to repo' do
- project = described_class.new(path: 'somewhere')
- expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git')
+ it "returns valid url to repo" do
+ project = described_class.new(path: "somewhere")
+ expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + "somewhere.git")
end
describe "#web_url" do
let(:project) { create(:project, path: "somewhere") }
- it 'returns the full web URL for this repo' do
+ it "returns the full web URL for this repo" do
expect(project.web_url).to eq("#{Gitlab.config.gitlab.url}/#{project.namespace.full_path}/somewhere")
end
end
describe "#readme_url" do
- context 'with a non-existing repository' do
+ context "with a non-existing repository" do
let(:project) { create(:project) }
- it 'returns nil' do
+ it "returns nil" do
expect(project.readme_url).to be_nil
end
end
- context 'with an existing repository' do
- context 'when no README exists' do
+ context "with an existing repository" do
+ context "when no README exists" do
let(:project) { create(:project, :empty_repo) }
- it 'returns nil' do
+ it "returns nil" do
expect(project.readme_url).to be_nil
end
end
- context 'when a README exists' do
+ context "when a README exists" do
let(:project) { create(:project, :repository) }
- it 'returns the README' do
+ it "returns the README" do
expect(project.readme_url).to eq("#{project.web_url}/blob/master/README.md")
end
end
@@ -659,69 +659,69 @@ describe Project do
let(:project) { create(:project, path: "somewhere") }
let(:user) { create(:user) }
- context 'incoming email enabled' do
+ context "incoming email enabled" do
before do
stub_incoming_email_setting(enabled: true, address: "p+%{key}@gl.ab")
end
- it 'returns the address to create a new issue' do
+ it "returns the address to create a new issue" do
address = "p+#{project.full_path_slug}-#{project.project_id}-#{user.incoming_email_token}-issue@gl.ab"
- expect(project.new_issuable_address(user, 'issue')).to eq(address)
+ expect(project.new_issuable_address(user, "issue")).to eq(address)
end
- it 'returns the address to create a new merge request' do
+ it "returns the address to create a new merge request" do
address = "p+#{project.full_path_slug}-#{project.project_id}-#{user.incoming_email_token}-merge-request@gl.ab"
- expect(project.new_issuable_address(user, 'merge_request')).to eq(address)
+ expect(project.new_issuable_address(user, "merge_request")).to eq(address)
end
- it 'returns nil with invalid address type' do
- expect(project.new_issuable_address(user, 'invalid_param')).to be_nil
+ it "returns nil with invalid address type" do
+ expect(project.new_issuable_address(user, "invalid_param")).to be_nil
end
end
- context 'incoming email disabled' do
+ context "incoming email disabled" do
before do
stub_incoming_email_setting(enabled: false)
end
- it 'returns nil' do
- expect(project.new_issuable_address(user, 'issue')).to be_nil
+ it "returns nil" do
+ expect(project.new_issuable_address(user, "issue")).to be_nil
end
- it 'returns nil' do
- expect(project.new_issuable_address(user, 'merge_request')).to be_nil
+ it "returns nil" do
+ expect(project.new_issuable_address(user, "merge_request")).to be_nil
end
end
end
- describe 'last_activity methods' do
+ describe "last_activity methods" do
let(:timestamp) { 2.hours.ago }
# last_activity_at gets set to created_at upon creation
let(:project) { create(:project, created_at: timestamp, updated_at: timestamp) }
- describe 'last_activity' do
- it 'alias last_activity to last_event' do
+ describe "last_activity" do
+ it "alias last_activity to last_event" do
last_event = create(:event, :closed, project: project)
expect(project.last_activity).to eq(last_event)
end
end
- describe 'last_activity_date' do
- it 'returns the creation date of the project\'s last event if present' do
+ describe "last_activity_date" do
+ it "returns the creation date of the project's last event if present" do
new_event = create(:event, :closed, project: project, created_at: Time.now)
project.reload
expect(project.last_activity_at.to_i).to eq(new_event.created_at.to_i)
end
- it 'returns the project\'s last update date if it has no events' do
+ it "returns the project's last update date if it has no events" do
expect(project.last_activity_date).to eq(project.updated_at)
end
- it 'returns the most recent timestamp' do
+ it "returns the most recent timestamp" do
project.update(updated_at: nil,
last_activity_at: timestamp,
last_repository_updated_at: timestamp - 1.hour)
@@ -737,7 +737,7 @@ describe Project do
end
end
- describe '#get_issue' do
+ describe "#get_issue" do
let(:project) { create(:project) }
let!(:issue) { create(:issue, project: project) }
let(:user) { create(:user) }
@@ -746,16 +746,16 @@ describe Project do
project.add_developer(user)
end
- context 'with default issues tracker' do
- it 'returns an issue' do
+ context "with default issues tracker" do
+ it "returns an issue" do
expect(project.get_issue(issue.iid, user)).to eq issue
end
- it 'returns count of open issues' do
+ it "returns count of open issues" do
expect(project.open_issues_count).to eq(1)
end
- it 'returns nil when no issue found' do
+ it "returns nil when no issue found" do
expect(project.get_issue(999, user)).to be_nil
end
@@ -765,14 +765,14 @@ describe Project do
end
end
- context 'with external issues tracker' do
+ context "with external issues tracker" do
let!(:internal_issue) { create(:issue, project: project) }
before do
allow(project).to receive(:external_issue_tracker).and_return(true)
end
- context 'when internal issues are enabled' do
- it 'returns interlan issue' do
+ context "when internal issues are enabled" do
+ it "returns interlan issue" do
issue = project.get_issue(internal_issue.iid, user)
expect(issue).to be_kind_of(Issue)
@@ -780,90 +780,90 @@ describe Project do
expect(issue.project).to eq(project)
end
- it 'returns an ExternalIssue when internal issue does not exists' do
- issue = project.get_issue('FOO-1234', user)
+ it "returns an ExternalIssue when internal issue does not exists" do
+ issue = project.get_issue("FOO-1234", user)
expect(issue).to be_kind_of(ExternalIssue)
- expect(issue.iid).to eq('FOO-1234')
+ expect(issue.iid).to eq("FOO-1234")
expect(issue.project).to eq(project)
end
end
- context 'when internal issues are disabled' do
+ context "when internal issues are disabled" do
before do
project.issues_enabled = false
project.save!
end
- it 'returns always an External issues' do
+ it "returns always an External issues" do
issue = project.get_issue(internal_issue.iid, user)
expect(issue).to be_kind_of(ExternalIssue)
expect(issue.iid).to eq(internal_issue.iid.to_s)
expect(issue.project).to eq(project)
end
- it 'returns an ExternalIssue when internal issue does not exists' do
- issue = project.get_issue('FOO-1234', user)
+ it "returns an ExternalIssue when internal issue does not exists" do
+ issue = project.get_issue("FOO-1234", user)
expect(issue).to be_kind_of(ExternalIssue)
- expect(issue.iid).to eq('FOO-1234')
+ expect(issue.iid).to eq("FOO-1234")
expect(issue.project).to eq(project)
end
end
end
end
- describe '#issue_exists?' do
+ describe "#issue_exists?" do
let(:project) { create(:project) }
- it 'is truthy when issue exists' do
+ it "is truthy when issue exists" do
expect(project).to receive(:get_issue).and_return(double)
expect(project.issue_exists?(1)).to be_truthy
end
- it 'is falsey when issue does not exist' do
+ it "is falsey when issue does not exist" do
expect(project).to receive(:get_issue).and_return(nil)
expect(project.issue_exists?(1)).to be_falsey
end
end
- describe '#to_param' do
- context 'with namespace' do
+ describe "#to_param" do
+ context "with namespace" do
before do
- @group = create(:group, name: 'gitlab')
- @project = create(:project, name: 'gitlabhq', namespace: @group)
+ @group = create(:group, name: "gitlab")
+ @project = create(:project, name: "gitlabhq", namespace: @group)
end
- it { expect(@project.to_param).to eq('gitlabhq') }
+ it { expect(@project.to_param).to eq("gitlabhq") }
end
- context 'with invalid path' do
- it 'returns previous path to keep project suitable for use in URLs when persisted' do
- project = create(:project, path: 'gitlab')
- project.path = 'foo&bar'
+ context "with invalid path" do
+ it "returns previous path to keep project suitable for use in URLs when persisted" do
+ project = create(:project, path: "gitlab")
+ project.path = "foo&bar"
expect(project).not_to be_valid
- expect(project.to_param).to eq 'gitlab'
+ expect(project.to_param).to eq "gitlab"
end
- it 'returns current path when new record' do
- project = build(:project, path: 'gitlab')
- project.path = 'foo&bar'
+ it "returns current path when new record" do
+ project = build(:project, path: "gitlab")
+ project.path = "foo&bar"
expect(project).not_to be_valid
- expect(project.to_param).to eq 'foo&bar'
+ expect(project.to_param).to eq "foo&bar"
end
end
end
- describe '#repository' do
+ describe "#repository" do
let(:project) { create(:project, :repository) }
- it 'returns valid repo' do
+ it "returns valid repo" do
expect(project.repository).to be_kind_of(Repository)
end
end
- describe '#default_issues_tracker?' do
+ describe "#default_issues_tracker?" do
it "is true if used internal tracker" do
project = build(:project)
@@ -878,16 +878,16 @@ describe Project do
end
end
- describe '#empty_repo?' do
- context 'when the repo does not exist' do
+ describe "#empty_repo?" do
+ context "when the repo does not exist" do
let(:project) { build_stubbed(:project) }
- it 'returns true' do
+ it "returns true" do
expect(project.empty_repo?).to be(true)
end
end
- context 'when the repo exists' do
+ context "when the repo exists" do
let(:project) { create(:project, :repository) }
let(:empty_project) { create(:project, :empty_repo) }
@@ -896,34 +896,34 @@ describe Project do
end
end
- describe '#external_issue_tracker' do
+ describe "#external_issue_tracker" do
let(:project) { create(:project) }
let(:ext_project) { create(:redmine_project) }
- context 'on existing projects with no value for has_external_issue_tracker' do
+ context "on existing projects with no value for has_external_issue_tracker" do
before do
project.update_column(:has_external_issue_tracker, nil)
ext_project.update_column(:has_external_issue_tracker, nil)
end
- it 'updates the has_external_issue_tracker boolean' do
- expect do
+ it "updates the has_external_issue_tracker boolean" do
+ expect {
project.external_issue_tracker
- end.to change { project.reload.has_external_issue_tracker }.to(false)
+ }.to change { project.reload.has_external_issue_tracker }.to(false)
- expect do
+ expect {
ext_project.external_issue_tracker
- end.to change { ext_project.reload.has_external_issue_tracker }.to(true)
+ }.to change { ext_project.reload.has_external_issue_tracker }.to(true)
end
end
- it 'returns nil and does not query services when there is no external issue tracker' do
+ it "returns nil and does not query services when there is no external issue tracker" do
expect(project).not_to receive(:services)
expect(project.external_issue_tracker).to eq(nil)
end
- it 'retrieves external_issue_tracker querying services and cache it when there is external issue tracker' do
+ it "retrieves external_issue_tracker querying services and cache it when there is external issue tracker" do
ext_project.reload # Factory returns a project with changed attributes
expect(ext_project).to receive(:services).once.and_call_original
@@ -931,92 +931,92 @@ describe Project do
end
end
- describe '#cache_has_external_issue_tracker' do
+ describe "#cache_has_external_issue_tracker" do
let(:project) { create(:project, has_external_issue_tracker: nil) }
- it 'stores true if there is any external_issue_tracker' do
+ it "stores true if there is any external_issue_tracker" do
services = double(:service, external_issue_trackers: [RedmineService.new])
expect(project).to receive(:services).and_return(services)
- expect do
+ expect {
project.cache_has_external_issue_tracker
- end.to change { project.has_external_issue_tracker}.to(true)
+ }.to change { project.has_external_issue_tracker}.to(true)
end
- it 'stores false if there is no external_issue_tracker' do
+ it "stores false if there is no external_issue_tracker" do
services = double(:service, external_issue_trackers: [])
expect(project).to receive(:services).and_return(services)
- expect do
+ expect {
project.cache_has_external_issue_tracker
- end.to change { project.has_external_issue_tracker}.to(false)
+ }.to change { project.has_external_issue_tracker}.to(false)
end
- it 'does not cache data when in a read-only GitLab instance' do
+ it "does not cache data when in a read-only GitLab instance" do
allow(Gitlab::Database).to receive(:read_only?) { true }
- expect do
+ expect {
project.cache_has_external_issue_tracker
- end.not_to change { project.has_external_issue_tracker }
+ }.not_to change { project.has_external_issue_tracker }
end
end
- describe '#cache_has_external_wiki' do
+ describe "#cache_has_external_wiki" do
let(:project) { create(:project, has_external_wiki: nil) }
- it 'stores true if there is any external_wikis' do
+ it "stores true if there is any external_wikis" do
services = double(:service, external_wikis: [ExternalWikiService.new])
expect(project).to receive(:services).and_return(services)
- expect do
+ expect {
project.cache_has_external_wiki
- end.to change { project.has_external_wiki}.to(true)
+ }.to change { project.has_external_wiki}.to(true)
end
- it 'stores false if there is no external_wikis' do
+ it "stores false if there is no external_wikis" do
services = double(:service, external_wikis: [])
expect(project).to receive(:services).and_return(services)
- expect do
+ expect {
project.cache_has_external_wiki
- end.to change { project.has_external_wiki}.to(false)
+ }.to change { project.has_external_wiki}.to(false)
end
- it 'does not cache data when in a read-only GitLab instance' do
+ it "does not cache data when in a read-only GitLab instance" do
allow(Gitlab::Database).to receive(:read_only?) { true }
- expect do
+ expect {
project.cache_has_external_wiki
- end.not_to change { project.has_external_wiki }
+ }.not_to change { project.has_external_wiki }
end
end
- describe '#has_wiki?' do
+ describe "#has_wiki?" do
let(:no_wiki_project) { create(:project, :wiki_disabled, has_external_wiki: false) }
let(:wiki_enabled_project) { create(:project) }
let(:external_wiki_project) { create(:project, has_external_wiki: true) }
- it 'returns true if project is wiki enabled or has external wiki' do
+ it "returns true if project is wiki enabled or has external wiki" do
expect(wiki_enabled_project).to have_wiki
expect(external_wiki_project).to have_wiki
expect(no_wiki_project).not_to have_wiki
end
end
- describe '#external_wiki' do
+ describe "#external_wiki" do
let(:project) { create(:project) }
- context 'with an active external wiki' do
+ context "with an active external wiki" do
before do
- create(:service, project: project, type: 'ExternalWikiService', active: true)
+ create(:service, project: project, type: "ExternalWikiService", active: true)
project.external_wiki
end
- it 'sets :has_external_wiki as true' do
+ it "sets :has_external_wiki as true" do
expect(project.has_external_wiki).to be(true)
end
- it 'sets :has_external_wiki as false if an external wiki service is destroyed later' do
+ it "sets :has_external_wiki as false if an external wiki service is destroyed later" do
expect(project.has_external_wiki).to be(true)
project.services.external_wikis.first.destroy
@@ -1025,37 +1025,37 @@ describe Project do
end
end
- context 'with an inactive external wiki' do
+ context "with an inactive external wiki" do
before do
- create(:service, project: project, type: 'ExternalWikiService', active: false)
+ create(:service, project: project, type: "ExternalWikiService", active: false)
end
- it 'sets :has_external_wiki as false' do
+ it "sets :has_external_wiki as false" do
expect(project.has_external_wiki).to be(false)
end
end
- context 'with no external wiki' do
+ context "with no external wiki" do
before do
project.external_wiki
end
- it 'sets :has_external_wiki as false' do
+ it "sets :has_external_wiki as false" do
expect(project.has_external_wiki).to be(false)
end
- it 'sets :has_external_wiki as true if an external wiki service is created later' do
+ it "sets :has_external_wiki as true if an external wiki service is created later" do
expect(project.has_external_wiki).to be(false)
- create(:service, project: project, type: 'ExternalWikiService', active: true)
+ create(:service, project: project, type: "ExternalWikiService", active: true)
expect(project.has_external_wiki).to be(true)
end
end
end
- describe '#star_count' do
- it 'counts stars from multiple users' do
+ describe "#star_count" do
+ it "counts stars from multiple users" do
user1 = create(:user)
user2 = create(:user)
project = create(:project, :public)
@@ -1078,7 +1078,7 @@ describe Project do
expect(project.reload.star_count).to eq(0)
end
- it 'counts stars on the right project' do
+ it "counts stars on the right project" do
user = create(:user)
project1 = create(:project, :public)
project2 = create(:project, :public)
@@ -1112,35 +1112,35 @@ describe Project do
end
end
- describe '#avatar_type' do
+ describe "#avatar_type" do
let(:project) { create(:project) }
- it 'is true if avatar is image' do
- project.update_attribute(:avatar, 'uploads/avatar.png')
+ it "is true if avatar is image" do
+ project.update_attribute(:avatar, "uploads/avatar.png")
expect(project.avatar_type).to be_truthy
end
- it 'is false if avatar is html page' do
- project.update_attribute(:avatar, 'uploads/avatar.html')
- expect(project.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico'])
+ it "is false if avatar is html page" do
+ project.update_attribute(:avatar, "uploads/avatar.html")
+ expect(project.avatar_type).to eq(["file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico"])
end
end
- describe '#avatar_url' do
+ describe "#avatar_url" do
subject { project.avatar_url }
let(:project) { create(:project) }
- context 'when avatar file is uploaded' do
+ context "when avatar file is uploaded" do
let(:project) { create(:project, :public, :with_avatar) }
- it 'shows correct url' do
+ it "shows correct url" do
expect(project.avatar_url).to eq(project.avatar.url)
expect(project.avatar_url(only_path: false)).to eq([Gitlab.config.gitlab.url, project.avatar.url].join)
end
end
- context 'when avatar file in git' do
+ context "when avatar file in git" do
before do
allow(project).to receive(:avatar_in_git) { true }
end
@@ -1150,41 +1150,41 @@ describe Project do
it { is_expected.to eq "http://#{Gitlab.config.gitlab.host}#{avatar_path}" }
end
- context 'when git repo is empty' do
+ context "when git repo is empty" do
let(:project) { create(:project) }
it { is_expected.to eq nil }
end
end
- describe '#pipeline_for' do
+ describe "#pipeline_for" do
let(:project) { create(:project, :repository) }
let!(:pipeline) { create_pipeline(project) }
- shared_examples 'giving the correct pipeline' do
+ shared_examples "giving the correct pipeline" do
it { is_expected.to eq(pipeline) }
- context 'return latest' do
+ context "return latest" do
let!(:pipeline2) { create_pipeline(project) }
it { is_expected.to eq(pipeline2) }
end
end
- context 'with explicit sha' do
- subject { project.pipeline_for('master', pipeline.sha) }
+ context "with explicit sha" do
+ subject { project.pipeline_for("master", pipeline.sha) }
- it_behaves_like 'giving the correct pipeline'
+ it_behaves_like "giving the correct pipeline"
end
- context 'with implicit sha' do
- subject { project.pipeline_for('master') }
+ context "with implicit sha" do
+ subject { project.pipeline_for("master") }
- it_behaves_like 'giving the correct pipeline'
+ it_behaves_like "giving the correct pipeline"
end
end
- describe '#builds_enabled' do
+ describe "#builds_enabled" do
let(:project) { create(:project) }
subject { project.builds_enabled }
@@ -1192,8 +1192,8 @@ describe Project do
it { expect(project.builds_enabled?).to be_truthy }
end
- describe '.sort_by_attribute' do
- it 'reorders the input relation by start count desc' do
+ describe ".sort_by_attribute" do
+ it "reorders the input relation by start count desc" do
project1 = create(:project, star_count: 2)
project2 = create(:project, star_count: 1)
project3 = create(:project)
@@ -1204,10 +1204,10 @@ describe Project do
end
end
- describe '.with_shared_runners' do
+ describe ".with_shared_runners" do
subject { described_class.with_shared_runners }
- context 'when shared runners are enabled for project' do
+ context "when shared runners are enabled for project" do
let!(:project) { create(:project, shared_runners_enabled: true) }
it "returns a project" do
@@ -1215,7 +1215,7 @@ describe Project do
end
end
- context 'when shared runners are disabled for project' do
+ context "when shared runners are disabled for project" do
let!(:project) { create(:project, shared_runners_enabled: false) }
it "returns an empty array" do
@@ -1224,12 +1224,12 @@ describe Project do
end
end
- describe '.cached_count', :use_clean_rails_memory_store_caching do
+ describe ".cached_count", :use_clean_rails_memory_store_caching do
let(:group) { create(:group, :public) }
let!(:project1) { create(:project, :public, group: group) }
let!(:project2) { create(:project, :public, group: group) }
- it 'returns total project count' do
+ it "returns total project count" do
expect(described_class).to receive(:count).once.and_call_original
3.times do
@@ -1238,7 +1238,7 @@ describe Project do
end
end
- describe '.trending' do
+ describe ".trending" do
let(:group) { create(:group, :public) }
let(:project1) { create(:project, :public, group: group) }
let(:project2) { create(:project, :public, group: group) }
@@ -1255,11 +1255,11 @@ describe Project do
subject { described_class.trending.to_a }
- it 'sorts projects by the amount of notes in descending order' do
+ it "sorts projects by the amount of notes in descending order" do
expect(subject).to eq([project1, project2])
end
- it 'does not take system notes into account' do
+ it "does not take system notes into account" do
10.times do
create(:note_on_commit, project: project2, system: true)
end
@@ -1268,8 +1268,8 @@ describe Project do
end
end
- describe '.starred_by' do
- it 'returns only projects starred by the given user' do
+ describe ".starred_by" do
+ it "returns only projects starred by the given user" do
user1 = create(:user)
user2 = create(:user)
project1 = create(:project)
@@ -1282,13 +1282,13 @@ describe Project do
end
end
- describe '.visible_to_user' do
+ describe ".visible_to_user" do
let!(:project) { create(:project, :private) }
let!(:user) { create(:user) }
subject { described_class.visible_to_user(user) }
- describe 'when a user has access to a project' do
+ describe "when a user has access to a project" do
before do
project.add_user(user, Gitlab::Access::MAINTAINER)
end
@@ -1296,35 +1296,35 @@ describe Project do
it { is_expected.to eq([project]) }
end
- describe 'when a user does not have access to any projects' do
+ describe "when a user does not have access to any projects" do
it { is_expected.to eq([]) }
end
end
- context 'repository storage by default' do
+ context "repository storage by default" do
let(:project) { build(:project) }
before do
storages = {
- 'default' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/repositories'),
- 'picked' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/repositories')
+ "default" => Gitlab::GitalyClient::StorageSettings.new("path" => "tmp/tests/repositories"),
+ "picked" => Gitlab::GitalyClient::StorageSettings.new("path" => "tmp/tests/repositories"),
}
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end
- it 'picks storage from ApplicationSetting' do
- expect_any_instance_of(ApplicationSetting).to receive(:pick_repository_storage).and_return('picked')
+ it "picks storage from ApplicationSetting" do
+ expect_any_instance_of(ApplicationSetting).to receive(:pick_repository_storage).and_return("picked")
- expect(project.repository_storage).to eq('picked')
+ expect(project.repository_storage).to eq("picked")
end
end
- context 'shared runners by default' do
+ context "shared runners by default" do
let(:project) { create(:project) }
subject { project.shared_runners_enabled }
- context 'are enabled' do
+ context "are enabled" do
before do
stub_application_setting(shared_runners_enabled: true)
end
@@ -1332,7 +1332,7 @@ describe Project do
it { is_expected.to be_truthy }
end
- context 'are disabled' do
+ context "are disabled" do
before do
stub_application_setting(shared_runners_enabled: false)
end
@@ -1341,60 +1341,60 @@ describe Project do
end
end
- describe '#any_runners?' do
- context 'shared runners' do
+ describe "#any_runners?" do
+ context "shared runners" do
let(:project) { create(:project, shared_runners_enabled: shared_runners_enabled) }
let(:specific_runner) { create(:ci_runner, :project, projects: [project]) }
let(:shared_runner) { create(:ci_runner, :instance) }
- context 'for shared runners disabled' do
+ context "for shared runners disabled" do
let(:shared_runners_enabled) { false }
- it 'has no runners available' do
+ it "has no runners available" do
expect(project.any_runners?).to be_falsey
end
- it 'has a specific runner' do
+ it "has a specific runner" do
specific_runner
expect(project.any_runners?).to be_truthy
end
- it 'has a shared runner, but they are prohibited to use' do
+ it "has a shared runner, but they are prohibited to use" do
shared_runner
expect(project.any_runners?).to be_falsey
end
- it 'checks the presence of specific runner' do
+ it "checks the presence of specific runner" do
specific_runner
expect(project.any_runners? { |runner| runner == specific_runner }).to be_truthy
end
- it 'returns false if match cannot be found' do
+ it "returns false if match cannot be found" do
specific_runner
expect(project.any_runners? { false }).to be_falsey
end
end
- context 'for shared runners enabled' do
+ context "for shared runners enabled" do
let(:shared_runners_enabled) { true }
- it 'has a shared runner' do
+ it "has a shared runner" do
shared_runner
expect(project.any_runners?).to be_truthy
end
- it 'checks the presence of shared runner' do
+ it "checks the presence of shared runner" do
shared_runner
expect(project.any_runners? { |runner| runner == shared_runner }).to be_truthy
end
- it 'returns false if match cannot be found' do
+ it "returns false if match cannot be found" do
shared_runner
expect(project.any_runners? { false }).to be_falsey
@@ -1402,41 +1402,41 @@ describe Project do
end
end
- context 'group runners' do
+ context "group runners" do
let(:project) { create(:project, group_runners_enabled: group_runners_enabled) }
let(:group) { create(:group, projects: [project]) }
let(:group_runner) { create(:ci_runner, :group, groups: [group]) }
- context 'for group runners disabled' do
+ context "for group runners disabled" do
let(:group_runners_enabled) { false }
- it 'has no runners available' do
+ it "has no runners available" do
expect(project.any_runners?).to be_falsey
end
- it 'has a group runner, but they are prohibited to use' do
+ it "has a group runner, but they are prohibited to use" do
group_runner
expect(project.any_runners?).to be_falsey
end
end
- context 'for group runners enabled' do
+ context "for group runners enabled" do
let(:group_runners_enabled) { true }
- it 'has a group runner' do
+ it "has a group runner" do
group_runner
expect(project.any_runners?).to be_truthy
end
- it 'checks the presence of group runner' do
+ it "checks the presence of group runner" do
group_runner
expect(project.any_runners? { |runner| runner == group_runner }).to be_truthy
end
- it 'returns false if match cannot be found' do
+ it "returns false if match cannot be found" do
group_runner
expect(project.any_runners? { false }).to be_falsey
@@ -1445,12 +1445,12 @@ describe Project do
end
end
- describe '#shared_runners' do
+ describe "#shared_runners" do
let!(:runner) { create(:ci_runner, :instance) }
subject { project.shared_runners }
- context 'when shared runners are enabled for project' do
+ context "when shared runners are enabled for project" do
let!(:project) { create(:project, shared_runners_enabled: true) }
it "returns a list of shared runners" do
@@ -1458,7 +1458,7 @@ describe Project do
end
end
- context 'when shared runners are disabled for project' do
+ context "when shared runners are disabled for project" do
let!(:project) { create(:project, shared_runners_enabled: false) }
it "returns a empty list" do
@@ -1467,16 +1467,16 @@ describe Project do
end
end
- describe '#visibility_level' do
+ describe "#visibility_level" do
let(:project) { build(:project) }
subject { project.visibility_level }
- context 'by default' do
+ context "by default" do
it { is_expected.to eq(Gitlab::VisibilityLevel::PRIVATE) }
end
- context 'when set to INTERNAL in application settings' do
+ context "when set to INTERNAL in application settings" do
before do
stub_application_setting(default_project_visibility: Gitlab::VisibilityLevel::INTERNAL)
end
@@ -1485,16 +1485,16 @@ describe Project do
end
end
- describe '#visibility_level_allowed?' do
+ describe "#visibility_level_allowed?" do
let(:project) { create(:project, :internal) }
- context 'when checking on non-forked project' do
+ context "when checking on non-forked project" do
it { expect(project.visibility_level_allowed?(Gitlab::VisibilityLevel::PRIVATE)).to be_truthy }
it { expect(project.visibility_level_allowed?(Gitlab::VisibilityLevel::INTERNAL)).to be_truthy }
it { expect(project.visibility_level_allowed?(Gitlab::VisibilityLevel::PUBLIC)).to be_truthy }
end
- context 'when checking on forked project' do
+ context "when checking on forked project" do
let(:project) { create(:project, :internal) }
let(:forked_project) { fork_project(project) }
@@ -1504,12 +1504,12 @@ describe Project do
end
end
- describe '#pages_deployed?' do
+ describe "#pages_deployed?" do
let(:project) { create(:project) }
subject { project.pages_deployed? }
- context 'if public folder does exist' do
+ context "if public folder does exist" do
before do
allow(Dir).to receive(:exist?).with(project.public_pages_path).and_return(true)
end
@@ -1522,37 +1522,37 @@ describe Project do
end
end
- describe '#pages_url' do
+ describe "#pages_url" do
let(:group) { create(:group, name: group_name) }
let(:project) { create(:project, namespace: group, name: project_name) }
- let(:domain) { 'Example.com' }
+ let(:domain) { "Example.com" }
subject { project.pages_url }
before do
allow(Settings.pages).to receive(:host).and_return(domain)
- allow(Gitlab.config.pages).to receive(:url).and_return('http://example.com')
+ allow(Gitlab.config.pages).to receive(:url).and_return("http://example.com")
end
- context 'group page' do
- let(:group_name) { 'Group' }
- let(:project_name) { 'group.example.com' }
+ context "group page" do
+ let(:group_name) { "Group" }
+ let(:project_name) { "group.example.com" }
it { is_expected.to eq("http://group.example.com") }
end
- context 'project page' do
- let(:group_name) { 'Group' }
- let(:project_name) { 'Project' }
+ context "project page" do
+ let(:group_name) { "Group" }
+ let(:project_name) { "Project" }
it { is_expected.to eq("http://group.example.com/project") }
end
end
- describe '#pages_group_url' do
+ describe "#pages_group_url" do
let(:group) { create(:group, name: group_name) }
let(:project) { create(:project, namespace: group, name: project_name) }
- let(:domain) { 'Example.com' }
+ let(:domain) { "Example.com" }
let(:port) { 1234 }
subject { project.pages_group_url }
@@ -1562,64 +1562,64 @@ describe Project do
allow(Gitlab.config.pages).to receive(:url).and_return("http://example.com:#{port}")
end
- context 'group page' do
- let(:group_name) { 'Group' }
- let(:project_name) { 'group.example.com' }
+ context "group page" do
+ let(:group_name) { "Group" }
+ let(:project_name) { "group.example.com" }
it { is_expected.to eq("http://group.example.com:#{port}") }
end
- context 'project page' do
- let(:group_name) { 'Group' }
- let(:project_name) { 'Project' }
+ context "project page" do
+ let(:group_name) { "Group" }
+ let(:project_name) { "Project" }
it { is_expected.to eq("http://group.example.com:#{port}") }
end
end
- describe '.search' do
- let(:project) { create(:project, description: 'kitten mittens') }
+ describe ".search" do
+ let(:project) { create(:project, description: "kitten mittens") }
- it 'returns projects with a matching name' do
+ it "returns projects with a matching name" do
expect(described_class.search(project.name)).to eq([project])
end
- it 'returns projects with a partially matching name' do
+ it "returns projects with a partially matching name" do
expect(described_class.search(project.name[0..2])).to eq([project])
end
- it 'returns projects with a matching name regardless of the casing' do
+ it "returns projects with a matching name regardless of the casing" do
expect(described_class.search(project.name.upcase)).to eq([project])
end
- it 'returns projects with a matching description' do
+ it "returns projects with a matching description" do
expect(described_class.search(project.description)).to eq([project])
end
- it 'returns projects with a partially matching description' do
- expect(described_class.search('kitten')).to eq([project])
+ it "returns projects with a partially matching description" do
+ expect(described_class.search("kitten")).to eq([project])
end
- it 'returns projects with a matching description regardless of the casing' do
- expect(described_class.search('KITTEN')).to eq([project])
+ it "returns projects with a matching description regardless of the casing" do
+ expect(described_class.search("KITTEN")).to eq([project])
end
- it 'returns projects with a matching path' do
+ it "returns projects with a matching path" do
expect(described_class.search(project.path)).to eq([project])
end
- it 'returns projects with a partially matching path' do
+ it "returns projects with a partially matching path" do
expect(described_class.search(project.path[0..2])).to eq([project])
end
- it 'returns projects with a matching path regardless of the casing' do
+ it "returns projects with a matching path regardless of the casing" do
expect(described_class.search(project.path.upcase)).to eq([project])
end
- describe 'with pending_delete project' do
+ describe "with pending_delete project" do
let(:pending_delete_project) { create(:project, pending_delete: true) }
- it 'shows pending deletion project' do
+ it "shows pending deletion project" do
search_result = described_class.search(pending_delete_project.name)
expect(search_result).to eq([pending_delete_project])
@@ -1627,44 +1627,44 @@ describe Project do
end
end
- describe '.optionally_search' do
+ describe ".optionally_search" do
let(:project) { create(:project) }
- it 'searches for projects matching the query if one is given' do
+ it "searches for projects matching the query if one is given" do
relation = described_class.optionally_search(project.name)
expect(relation).to eq([project])
end
- it 'returns the current relation if no search query is given' do
+ it "returns the current relation if no search query is given" do
relation = described_class.where(id: project.id)
expect(relation.optionally_search).to eq(relation)
end
end
- describe '.paginate_in_descending_order_using_id' do
+ describe ".paginate_in_descending_order_using_id" do
let!(:project1) { create(:project) }
let!(:project2) { create(:project) }
- it 'orders the relation in descending order' do
+ it "orders the relation in descending order" do
expect(described_class.paginate_in_descending_order_using_id)
.to eq([project2, project1])
end
- it 'applies a limit to the relation' do
+ it "applies a limit to the relation" do
expect(described_class.paginate_in_descending_order_using_id(limit: 1))
.to eq([project2])
end
- it 'limits projects by and ID when given' do
+ it "limits projects by and ID when given" do
expect(described_class.paginate_in_descending_order_using_id(before: project2.id))
.to eq([project1])
end
end
- describe '.including_namespace_and_owner' do
- it 'eager loads the namespace and namespace owner' do
+ describe ".including_namespace_and_owner" do
+ it "eager loads the namespace and namespace owner" do
create(:project)
row = described_class.eager_load_namespace_and_owner.to_a.first
@@ -1674,67 +1674,67 @@ describe Project do
end
end
- describe '#expire_caches_before_rename' do
+ describe "#expire_caches_before_rename" do
let(:project) { create(:project, :repository) }
let(:repo) { double(:repo, exists?: true) }
let(:wiki) { double(:wiki, exists?: true) }
- it 'expires the caches of the repository and wiki' do
+ it "expires the caches of the repository and wiki" do
allow(Repository).to receive(:new)
- .with('foo', project)
+ .with("foo", project)
.and_return(repo)
allow(Repository).to receive(:new)
- .with('foo.wiki', project)
+ .with("foo.wiki", project)
.and_return(wiki)
expect(repo).to receive(:before_delete)
expect(wiki).to receive(:before_delete)
- project.expire_caches_before_rename('foo')
+ project.expire_caches_before_rename("foo")
end
end
- describe '.search_by_title' do
- let(:project) { create(:project, name: 'kittens') }
+ describe ".search_by_title" do
+ let(:project) { create(:project, name: "kittens") }
- it 'returns projects with a matching name' do
+ it "returns projects with a matching name" do
expect(described_class.search_by_title(project.name)).to eq([project])
end
- it 'returns projects with a partially matching name' do
- expect(described_class.search_by_title('kitten')).to eq([project])
+ it "returns projects with a partially matching name" do
+ expect(described_class.search_by_title("kitten")).to eq([project])
end
- it 'returns projects with a matching name regardless of the casing' do
- expect(described_class.search_by_title('KITTENS')).to eq([project])
+ it "returns projects with a matching name regardless of the casing" do
+ expect(described_class.search_by_title("KITTENS")).to eq([project])
end
end
- context 'when checking projects from groups' do
+ context "when checking projects from groups" do
let(:private_group) { create(:group, visibility_level: 0) }
let(:internal_group) { create(:group, visibility_level: 10) }
let(:private_project) { create(:project, :private, group: private_group) }
let(:internal_project) { create(:project, :internal, group: internal_group) }
- context 'when group is private project can not be internal' do
+ context "when group is private project can not be internal" do
it { expect(private_project.visibility_level_allowed?(Gitlab::VisibilityLevel::INTERNAL)).to be_falsey }
end
- context 'when group is internal project can not be public' do
+ context "when group is internal project can not be public" do
it { expect(internal_project.visibility_level_allowed?(Gitlab::VisibilityLevel::PUBLIC)).to be_falsey }
end
end
- describe '#track_project_repository' do
- shared_examples 'tracks storage location' do
- context 'when a project repository entry does not exist' do
- it 'creates a new entry' do
+ describe "#track_project_repository" do
+ shared_examples "tracks storage location" do
+ context "when a project repository entry does not exist" do
+ it "creates a new entry" do
expect { project.track_project_repository }.to change(project, :project_repository)
end
- it 'tracks the project storage location' do
+ it "tracks the project storage location" do
project.track_project_repository
expect(project.project_repository).to have_attributes(
@@ -1744,42 +1744,42 @@ describe Project do
end
end
- context 'when a tracking entry exists' do
+ context "when a tracking entry exists" do
let!(:project_repository) { create(:project_repository, project: project) }
- let!(:shard) { create(:shard, name: 'foo') }
+ let!(:shard) { create(:shard, name: "foo") }
- it 'does not create a new entry in the database' do
+ it "does not create a new entry in the database" do
expect { project.track_project_repository }.not_to change(project, :project_repository)
end
- it 'updates the project storage location' do
- allow(project).to receive(:disk_path).and_return('fancy/new/path')
- allow(project).to receive(:repository_storage).and_return('foo')
+ it "updates the project storage location" do
+ allow(project).to receive(:disk_path).and_return("fancy/new/path")
+ allow(project).to receive(:repository_storage).and_return("foo")
project.track_project_repository
expect(project.project_repository).to have_attributes(
- disk_path: 'fancy/new/path',
- shard_name: 'foo'
+ disk_path: "fancy/new/path",
+ shard_name: "foo"
)
end
end
end
- context 'with projects on legacy storage' do
+ context "with projects on legacy storage" do
let(:project) { create(:project, :repository, :legacy_storage) }
- it_behaves_like 'tracks storage location'
+ it_behaves_like "tracks storage location"
end
- context 'with projects on hashed storage' do
+ context "with projects on hashed storage" do
let(:project) { create(:project, :repository) }
- it_behaves_like 'tracks storage location'
+ it_behaves_like "tracks storage location"
end
end
- describe '#create_repository' do
+ describe "#create_repository" do
let(:project) { create(:project, :repository) }
let(:shell) { Gitlab::Shell.new }
@@ -1787,8 +1787,8 @@ describe Project do
allow(project).to receive(:gitlab_shell).and_return(shell)
end
- context 'using a regular repository' do
- it 'creates the repository' do
+ context "using a regular repository" do
+ it "creates the repository" do
expect(shell).to receive(:create_repository)
.with(project.repository_storage, project.disk_path, project.full_path)
.and_return(true)
@@ -1798,7 +1798,7 @@ describe Project do
expect(project.create_repository).to eq(true)
end
- it 'adds an error if the repository could not be created' do
+ it "adds an error if the repository could not be created" do
expect(shell).to receive(:create_repository)
.with(project.repository_storage, project.disk_path, project.full_path)
.and_return(false)
@@ -1810,8 +1810,8 @@ describe Project do
end
end
- context 'using a forked repository' do
- it 'does nothing' do
+ context "using a forked repository" do
+ it "does nothing" do
expect(project).to receive(:forked?).and_return(true)
expect(shell).not_to receive(:create_repository)
@@ -1820,7 +1820,7 @@ describe Project do
end
end
- describe '#ensure_repository' do
+ describe "#ensure_repository" do
let(:project) { create(:project, :repository) }
let(:shell) { Gitlab::Shell.new }
@@ -1828,7 +1828,7 @@ describe Project do
allow(project).to receive(:gitlab_shell).and_return(shell)
end
- it 'creates the repository if it not exist' do
+ it "creates the repository if it not exist" do
allow(project).to receive(:repository_exists?)
.and_return(false)
@@ -1841,7 +1841,7 @@ describe Project do
project.ensure_repository
end
- it 'does not create the repository if it exists' do
+ it "does not create the repository if it exists" do
allow(project).to receive(:repository_exists?)
.and_return(true)
@@ -1850,7 +1850,7 @@ describe Project do
project.ensure_repository
end
- it 'creates the repository if it is a fork' do
+ it "creates the repository if it is a fork" do
expect(project).to receive(:forked?).and_return(true)
allow(project).to receive(:repository_exists?)
@@ -1864,17 +1864,17 @@ describe Project do
end
end
- describe 'handling import URL' do
- it 'returns the sanitized URL' do
- project = create(:project, :import_started, import_url: 'http://user:pass@test.com')
+ describe "handling import URL" do
+ it "returns the sanitized URL" do
+ project = create(:project, :import_started, import_url: "http://user:pass@test.com")
project.import_state.finish
- expect(project.reload.import_url).to eq('http://test.com')
+ expect(project.reload.import_url).to eq("http://test.com")
end
end
- describe '#container_registry_url' do
+ describe "#container_registry_url" do
let(:project) { create(:project) }
subject { project.container_registry_url }
@@ -1883,158 +1883,158 @@ describe Project do
stub_container_registry_config(**registry_settings)
end
- context 'for enabled registry' do
+ context "for enabled registry" do
let(:registry_settings) do
- { enabled: true,
- host_port: 'example.com' }
+ {enabled: true,
+ host_port: "example.com",}
end
it { is_expected.not_to be_nil }
end
- context 'for disabled registry' do
+ context "for disabled registry" do
let(:registry_settings) do
- { enabled: false }
+ {enabled: false}
end
it { is_expected.to be_nil }
end
end
- describe '#has_container_registry_tags?' do
+ describe "#has_container_registry_tags?" do
let(:project) { create(:project) }
- context 'when container registry is enabled' do
+ context "when container registry is enabled" do
before do
stub_container_registry_config(enabled: true)
end
- context 'when tags are present for multi-level registries' do
+ context "when tags are present for multi-level registries" do
before do
- create(:container_repository, project: project, name: 'image')
+ create(:container_repository, project: project, name: "image")
stub_container_registry_tags(repository: /image/,
tags: %w[latest rc1])
end
- it 'should have image tags' do
+ it "should have image tags" do
expect(project).to have_container_registry_tags
end
end
- context 'when tags are present for root repository' do
+ context "when tags are present for root repository" do
before do
stub_container_registry_tags(repository: project.full_path,
tags: %w[latest rc1 pre1])
end
- it 'should have image tags' do
+ it "should have image tags" do
expect(project).to have_container_registry_tags
end
end
- context 'when there are no tags at all' do
+ context "when there are no tags at all" do
before do
stub_container_registry_tags(repository: :any, tags: [])
end
- it 'should not have image tags' do
+ it "should not have image tags" do
expect(project).not_to have_container_registry_tags
end
end
end
- context 'when container registry is disabled' do
+ context "when container registry is disabled" do
before do
stub_container_registry_config(enabled: false)
end
- it 'should not have image tags' do
+ it "should not have image tags" do
expect(project).not_to have_container_registry_tags
end
- it 'should not check root repository tags' do
+ it "should not check root repository tags" do
expect(project).not_to receive(:full_path)
expect(project).not_to have_container_registry_tags
end
- it 'should iterate through container repositories' do
+ it "should iterate through container repositories" do
expect(project).to receive(:container_repositories)
expect(project).not_to have_container_registry_tags
end
end
end
- describe '#ci_config_path=' do
+ describe "#ci_config_path=" do
let(:project) { create(:project) }
- it 'sets nil' do
+ it "sets nil" do
project.update!(ci_config_path: nil)
expect(project.ci_config_path).to be_nil
end
- it 'sets a string' do
- project.update!(ci_config_path: 'foo/.gitlab_ci.yml')
+ it "sets a string" do
+ project.update!(ci_config_path: "foo/.gitlab_ci.yml")
- expect(project.ci_config_path).to eq('foo/.gitlab_ci.yml')
+ expect(project.ci_config_path).to eq("foo/.gitlab_ci.yml")
end
- it 'sets a string but removes all null characters' do
+ it "sets a string but removes all null characters" do
project.update!(ci_config_path: "f\0oo/\0/.gitlab_ci.yml")
- expect(project.ci_config_path).to eq('foo//.gitlab_ci.yml')
+ expect(project.ci_config_path).to eq("foo//.gitlab_ci.yml")
end
end
- describe '#latest_successful_build_for' do
+ describe "#latest_successful_build_for" do
let(:project) { create(:project, :repository) }
let(:pipeline) { create_pipeline(project) }
- context 'with many builds' do
- it 'gives the latest builds from latest pipeline' do
+ context "with many builds" do
+ it "gives the latest builds from latest pipeline" do
pipeline1 = create_pipeline(project)
pipeline2 = create_pipeline(project)
- create_build(pipeline1, 'test')
- create_build(pipeline1, 'test2')
- build1_p2 = create_build(pipeline2, 'test')
- create_build(pipeline2, 'test2')
+ create_build(pipeline1, "test")
+ create_build(pipeline1, "test2")
+ build1_p2 = create_build(pipeline2, "test")
+ create_build(pipeline2, "test2")
expect(project.latest_successful_build_for(build1_p2.name))
.to eq(build1_p2)
end
end
- context 'with succeeded pipeline' do
+ context "with succeeded pipeline" do
let!(:build) { create_build }
- context 'standalone pipeline' do
- it 'returns builds for ref for default_branch' do
+ context "standalone pipeline" do
+ it "returns builds for ref for default_branch" do
expect(project.latest_successful_build_for(build.name))
.to eq(build)
end
- it 'returns empty relation if the build cannot be found' do
- expect(project.latest_successful_build_for('TAIL'))
+ it "returns empty relation if the build cannot be found" do
+ expect(project.latest_successful_build_for("TAIL"))
.to be_nil
end
end
- context 'with some pending pipeline' do
+ context "with some pending pipeline" do
before do
- create_build(create_pipeline(project, 'pending'))
+ create_build(create_pipeline(project, "pending"))
end
- it 'gives the latest build from latest pipeline' do
+ it "gives the latest build from latest pipeline" do
expect(project.latest_successful_build_for(build.name))
.to eq(build)
end
end
end
- context 'with pending pipeline' do
- it 'returns empty relation' do
- pipeline.update(status: 'pending')
+ context "with pending pipeline" do
+ it "returns empty relation" do
+ pipeline.update(status: "pending")
pending_build = create_build(pipeline)
expect(project.latest_successful_build_for(pending_build.name)).to be_nil
@@ -2042,54 +2042,54 @@ describe Project do
end
end
- describe '#latest_successful_build_for!' do
+ describe "#latest_successful_build_for!" do
let(:project) { create(:project, :repository) }
let(:pipeline) { create_pipeline(project) }
- context 'with many builds' do
- it 'gives the latest builds from latest pipeline' do
+ context "with many builds" do
+ it "gives the latest builds from latest pipeline" do
pipeline1 = create_pipeline(project)
pipeline2 = create_pipeline(project)
- create_build(pipeline1, 'test')
- create_build(pipeline1, 'test2')
- build1_p2 = create_build(pipeline2, 'test')
- create_build(pipeline2, 'test2')
+ create_build(pipeline1, "test")
+ create_build(pipeline1, "test2")
+ build1_p2 = create_build(pipeline2, "test")
+ create_build(pipeline2, "test2")
expect(project.latest_successful_build_for(build1_p2.name))
.to eq(build1_p2)
end
end
- context 'with succeeded pipeline' do
+ context "with succeeded pipeline" do
let!(:build) { create_build }
- context 'standalone pipeline' do
- it 'returns builds for ref for default_branch' do
+ context "standalone pipeline" do
+ it "returns builds for ref for default_branch" do
expect(project.latest_successful_build_for!(build.name))
.to eq(build)
end
- it 'returns exception if the build cannot be found' do
- expect { project.latest_successful_build_for!(build.name, 'TAIL') }
+ it "returns exception if the build cannot be found" do
+ expect { project.latest_successful_build_for!(build.name, "TAIL") }
.to raise_error(ActiveRecord::RecordNotFound)
end
end
- context 'with some pending pipeline' do
+ context "with some pending pipeline" do
before do
- create_build(create_pipeline(project, 'pending'))
+ create_build(create_pipeline(project, "pending"))
end
- it 'gives the latest build from latest pipeline' do
+ it "gives the latest build from latest pipeline" do
expect(project.latest_successful_build_for!(build.name))
.to eq(build)
end
end
end
- context 'with pending pipeline' do
- it 'returns empty relation' do
- pipeline.update(status: 'pending')
+ context "with pending pipeline" do
+ it "returns empty relation" do
+ pipeline.update(status: "pending")
pending_build = create_build(pipeline)
expect { project.latest_successful_build_for!(pending_build.name) }
@@ -2098,46 +2098,46 @@ describe Project do
end
end
- describe '#import_status' do
- context 'with import_state' do
- it 'returns the right status' do
+ describe "#import_status" do
+ context "with import_state" do
+ it "returns the right status" do
project = create(:project, :import_started)
expect(project.import_status).to eq("started")
end
end
- context 'without import_state' do
- it 'returns none' do
+ context "without import_state" do
+ it "returns none" do
project = create(:project)
- expect(project.import_status).to eq('none')
+ expect(project.import_status).to eq("none")
end
end
end
- describe '#human_import_status_name' do
- context 'with import_state' do
- it 'returns the right human import status' do
+ describe "#human_import_status_name" do
+ context "with import_state" do
+ it "returns the right human import status" do
project = create(:project, :import_started)
- expect(project.human_import_status_name).to eq('started')
+ expect(project.human_import_status_name).to eq("started")
end
end
- context 'without import_state' do
- it 'returns none' do
+ context "without import_state" do
+ it "returns none" do
project = create(:project)
- expect(project.human_import_status_name).to eq('none')
+ expect(project.human_import_status_name).to eq("none")
end
end
end
- describe '#add_import_job' do
- let(:import_jid) { '123' }
+ describe "#add_import_job" do
+ let(:import_jid) { "123" }
- context 'forked' do
+ context "forked" do
let(:forked_from_project) { create(:project, :repository) }
let(:project) { create(:project) }
@@ -2145,15 +2145,15 @@ describe Project do
fork_project(forked_from_project, nil, target_project: project)
end
- it 'schedules a RepositoryForkWorker job' do
+ it "schedules a RepositoryForkWorker job" do
expect(RepositoryForkWorker).to receive(:perform_async).with(project.id).and_return(import_jid)
expect(project.add_import_job).to eq(import_jid)
end
end
- context 'not forked' do
- it 'schedules a RepositoryImportWorker job' do
+ context "not forked" do
+ it "schedules a RepositoryImportWorker job" do
project = create(:project, import_url: generate(:url))
expect(RepositoryImportWorker).to receive(:perform_async).with(project.id).and_return(import_jid)
@@ -2162,19 +2162,19 @@ describe Project do
end
end
- describe '#gitlab_project_import?' do
- subject(:project) { build(:project, import_type: 'gitlab_project') }
+ describe "#gitlab_project_import?" do
+ subject(:project) { build(:project, import_type: "gitlab_project") }
it { expect(project.gitlab_project_import?).to be true }
end
- describe '#gitea_import?' do
- subject(:project) { build(:project, import_type: 'gitea') }
+ describe "#gitea_import?" do
+ subject(:project) { build(:project, import_type: "gitea") }
it { expect(project.gitea_import?).to be true }
end
- describe '#has_remote_mirror?' do
+ describe "#has_remote_mirror?" do
let(:project) { create(:project, :remote_mirror, :import_started) }
subject { project.has_remote_mirror? }
@@ -2182,18 +2182,18 @@ describe Project do
allow_any_instance_of(RemoteMirror).to receive(:refresh_remote)
end
- it 'returns true when a remote mirror is enabled' do
+ it "returns true when a remote mirror is enabled" do
is_expected.to be_truthy
end
- it 'returns false when remote mirror is disabled' do
+ it "returns false when remote mirror is disabled" do
project.remote_mirrors.first.update(enabled: false)
is_expected.to be_falsy
end
end
- describe '#update_remote_mirrors' do
+ describe "#update_remote_mirrors" do
let(:project) { create(:project, :remote_mirror, :import_started) }
delegate :update_remote_mirrors, to: :project
@@ -2201,13 +2201,13 @@ describe Project do
allow_any_instance_of(RemoteMirror).to receive(:refresh_remote)
end
- it 'syncs enabled remote mirror' do
+ it "syncs enabled remote mirror" do
expect_any_instance_of(RemoteMirror).to receive(:sync)
update_remote_mirrors
end
- it 'does nothing when remote mirror is disabled globally and not overridden' do
+ it "does nothing when remote mirror is disabled globally and not overridden" do
stub_application_setting(mirror_available: false)
project.remote_mirror_available_overridden = false
@@ -2216,7 +2216,7 @@ describe Project do
update_remote_mirrors
end
- it 'does not sync disabled remote mirrors' do
+ it "does not sync disabled remote mirrors" do
project.remote_mirrors.first.update(enabled: false)
expect_any_instance_of(RemoteMirror).not_to receive(:sync)
@@ -2225,72 +2225,72 @@ describe Project do
end
end
- describe '#remote_mirror_available?' do
+ describe "#remote_mirror_available?" do
let(:project) { create(:project) }
- context 'when remote mirror global setting is enabled' do
- it 'returns true' do
+ context "when remote mirror global setting is enabled" do
+ it "returns true" do
expect(project.remote_mirror_available?).to be(true)
end
end
- context 'when remote mirror global setting is disabled' do
+ context "when remote mirror global setting is disabled" do
before do
stub_application_setting(mirror_available: false)
end
- it 'returns true when overridden' do
+ it "returns true when overridden" do
project.remote_mirror_available_overridden = true
expect(project.remote_mirror_available?).to be(true)
end
- it 'returns false when not overridden' do
+ it "returns false when not overridden" do
expect(project.remote_mirror_available?).to be(false)
end
end
end
- describe '#ancestors_upto', :nested_groups do
+ describe "#ancestors_upto", :nested_groups do
let(:parent) { create(:group) }
let(:child) { create(:group, parent: parent) }
let(:child2) { create(:group, parent: child) }
let(:project) { create(:project, namespace: child2) }
- it 'returns all ancestors when no namespace is given' do
+ it "returns all ancestors when no namespace is given" do
expect(project.ancestors_upto).to contain_exactly(child2, child, parent)
end
- it 'includes ancestors upto but excluding the given ancestor' do
+ it "includes ancestors upto but excluding the given ancestor" do
expect(project.ancestors_upto(parent)).to contain_exactly(child2, child)
end
- describe 'with hierarchy_order' do
- it 'returns ancestors ordered by descending hierarchy' do
+ describe "with hierarchy_order" do
+ it "returns ancestors ordered by descending hierarchy" do
expect(project.ancestors_upto(hierarchy_order: :desc)).to eq([parent, child, child2])
end
- it 'can be used with upto option' do
+ it "can be used with upto option" do
expect(project.ancestors_upto(parent, hierarchy_order: :desc)).to eq([child, child2])
end
end
end
- describe '#root_ancestor' do
+ describe "#root_ancestor" do
let(:project) { create(:project) }
subject { project.root_ancestor }
it { is_expected.to eq(project.namespace) }
- context 'in a group' do
+ context "in a group" do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
it { is_expected.to eq(group) }
end
- context 'in a nested group', :nested_groups do
+ context "in a nested group", :nested_groups do
let(:root) { create(:group) }
let(:child) { create(:group, parent: root) }
let(:project) { create(:project, group: child) }
@@ -2299,233 +2299,233 @@ describe Project do
end
end
- describe '#lfs_enabled?' do
+ describe "#lfs_enabled?" do
let(:project) { create(:project) }
- shared_examples 'project overrides group' do
- it 'returns true when enabled in project' do
+ shared_examples "project overrides group" do
+ it "returns true when enabled in project" do
project.update_attribute(:lfs_enabled, true)
expect(project.lfs_enabled?).to be_truthy
end
- it 'returns false when disabled in project' do
+ it "returns false when disabled in project" do
project.update_attribute(:lfs_enabled, false)
expect(project.lfs_enabled?).to be_falsey
end
- it 'returns the value from the namespace, when no value is set in project' do
+ it "returns the value from the namespace, when no value is set in project" do
expect(project.lfs_enabled?).to eq(project.namespace.lfs_enabled?)
end
end
- context 'LFS disabled in group' do
+ context "LFS disabled in group" do
before do
project.namespace.update_attribute(:lfs_enabled, false)
enable_lfs
end
- it_behaves_like 'project overrides group'
+ it_behaves_like "project overrides group"
end
- context 'LFS enabled in group' do
+ context "LFS enabled in group" do
before do
project.namespace.update_attribute(:lfs_enabled, true)
enable_lfs
end
- it_behaves_like 'project overrides group'
+ it_behaves_like "project overrides group"
end
- describe 'LFS disabled globally' do
- shared_examples 'it always returns false' do
+ describe "LFS disabled globally" do
+ shared_examples "it always returns false" do
it do
expect(project.lfs_enabled?).to be_falsey
expect(project.namespace.lfs_enabled?).to be_falsey
end
end
- context 'when no values are set' do
- it_behaves_like 'it always returns false'
+ context "when no values are set" do
+ it_behaves_like "it always returns false"
end
- context 'when all values are set to true' do
+ context "when all values are set to true" do
before do
project.namespace.update_attribute(:lfs_enabled, true)
project.update_attribute(:lfs_enabled, true)
end
- it_behaves_like 'it always returns false'
+ it_behaves_like "it always returns false"
end
end
end
- describe '#daily_statistics_enabled?' do
+ describe "#daily_statistics_enabled?" do
it { is_expected.to be_daily_statistics_enabled }
- context 'when :project_daily_statistics is disabled for the project' do
+ context "when :project_daily_statistics is disabled for the project" do
before do
- stub_feature_flags(project_daily_statistics: { thing: subject, enabled: false })
+ stub_feature_flags(project_daily_statistics: {thing: subject, enabled: false})
end
it { is_expected.not_to be_daily_statistics_enabled }
end
end
- describe '#change_head' do
+ describe "#change_head" do
let(:project) { create(:project, :repository) }
- it 'returns error if branch does not exist' do
- expect(project.change_head('unexisted-branch')).to be false
+ it "returns error if branch does not exist" do
+ expect(project.change_head("unexisted-branch")).to be false
expect(project.errors.size).to eq(1)
end
- it 'calls the before_change_head and after_change_head methods' do
+ it "calls the before_change_head and after_change_head methods" do
expect(project.repository).to receive(:before_change_head)
expect(project.repository).to receive(:after_change_head)
project.change_head(project.default_branch)
end
- it 'copies the gitattributes' do
+ it "copies the gitattributes" do
expect(project.repository).to receive(:copy_gitattributes).with(project.default_branch)
project.change_head(project.default_branch)
end
- it 'reloads the default branch' do
+ it "reloads the default branch" do
expect(project).to receive(:reload_default_branch)
project.change_head(project.default_branch)
end
end
- context 'forks' do
+ context "forks" do
include ProjectForksHelper
let(:project) { create(:project, :public) }
let!(:forked_project) { fork_project(project) }
- describe '#fork_network' do
- it 'includes a fork of the project' do
+ describe "#fork_network" do
+ it "includes a fork of the project" do
expect(project.fork_network.projects).to include(forked_project)
end
- it 'includes a fork of a fork' do
+ it "includes a fork of a fork" do
other_fork = fork_project(forked_project)
expect(project.fork_network.projects).to include(other_fork)
end
- it 'includes sibling forks' do
+ it "includes sibling forks" do
other_fork = fork_project(project)
expect(forked_project.fork_network.projects).to include(other_fork)
end
- it 'includes the base project' do
+ it "includes the base project" do
expect(forked_project.fork_network.projects).to include(project.reload)
end
end
- describe '#in_fork_network_of?' do
- it 'is true for a real fork' do
+ describe "#in_fork_network_of?" do
+ it "is true for a real fork" do
expect(forked_project.in_fork_network_of?(project)).to be_truthy
end
- it 'is true for a fork of a fork', :postgresql do
+ it "is true for a fork of a fork", :postgresql do
other_fork = fork_project(forked_project)
expect(other_fork.in_fork_network_of?(project)).to be_truthy
end
- it 'is true for sibling forks' do
+ it "is true for sibling forks" do
sibling = fork_project(project)
expect(sibling.in_fork_network_of?(forked_project)).to be_truthy
end
- it 'is false when another project is given' do
+ it "is false when another project is given" do
other_project = build_stubbed(:project)
expect(forked_project.in_fork_network_of?(other_project)).to be_falsy
end
end
- describe '#fork_source' do
+ describe "#fork_source" do
let!(:second_fork) { fork_project(forked_project) }
- it 'returns the direct source if it exists' do
+ it "returns the direct source if it exists" do
expect(second_fork.fork_source).to eq(forked_project)
end
- it 'returns the root of the fork network when the directs source was deleted' do
+ it "returns the root of the fork network when the directs source was deleted" do
forked_project.destroy
expect(second_fork.fork_source).to eq(project)
end
- it 'returns nil if it is the root of the fork network' do
+ it "returns nil if it is the root of the fork network" do
expect(project.fork_source).to be_nil
end
end
- describe '#forks' do
- it 'includes direct forks of the project' do
+ describe "#forks" do
+ it "includes direct forks of the project" do
expect(project.forks).to contain_exactly(forked_project)
end
end
- describe '#lfs_storage_project' do
- it 'returns self for non-forks' do
+ describe "#lfs_storage_project" do
+ it "returns self for non-forks" do
expect(project.lfs_storage_project).to eq project
end
- it 'returns the fork network root for forks' do
+ it "returns the fork network root for forks" do
second_fork = fork_project(forked_project)
expect(second_fork.lfs_storage_project).to eq project
end
- it 'returns self when fork_source is nil' do
+ it "returns self when fork_source is nil" do
expect(forked_project).to receive(:fork_source).and_return(nil)
expect(forked_project.lfs_storage_project).to eq forked_project
end
end
- describe '#all_lfs_objects' do
+ describe "#all_lfs_objects" do
let(:lfs_object) { create(:lfs_object) }
before do
project.lfs_objects << lfs_object
end
- it 'returns the lfs object for a project' do
+ it "returns the lfs object for a project" do
expect(project.all_lfs_objects).to contain_exactly(lfs_object)
end
- it 'returns the lfs object for a fork' do
+ it "returns the lfs object for a fork" do
expect(forked_project.all_lfs_objects).to contain_exactly(lfs_object)
end
end
end
- describe '#set_repository_read_only!' do
+ describe "#set_repository_read_only!" do
let(:project) { create(:project) }
- it 'returns true when there is no existing git transfer in progress' do
+ it "returns true when there is no existing git transfer in progress" do
expect(project.set_repository_read_only!).to be_truthy
end
- it 'returns false when there is an existing git transfer in progress' do
+ it "returns false when there is an existing git transfer in progress" do
allow(project).to receive(:git_transfer_in_progress?) { true }
expect(project.set_repository_read_only!).to be_falsey
end
end
- describe '#set_repository_writable!' do
- it 'sets repository_read_only to false' do
+ describe "#set_repository_writable!" do
+ it "sets repository_read_only to false" do
project = create(:project, :read_only)
expect { project.set_repository_writable! }
@@ -2534,21 +2534,21 @@ describe Project do
end
end
- describe '#pushes_since_gc' do
+ describe "#pushes_since_gc" do
let(:project) { create(:project) }
after do
project.reset_pushes_since_gc
end
- context 'without any pushes' do
- it 'returns 0' do
+ context "without any pushes" do
+ it "returns 0" do
expect(project.pushes_since_gc).to eq(0)
end
end
- context 'with a number of pushes' do
- it 'returns the number of pushes' do
+ context "with a number of pushes" do
+ it "returns the number of pushes" do
3.times { project.increment_pushes_since_gc }
expect(project.pushes_since_gc).to eq(3)
@@ -2556,28 +2556,28 @@ describe Project do
end
end
- describe '#increment_pushes_since_gc' do
+ describe "#increment_pushes_since_gc" do
let(:project) { create(:project) }
after do
project.reset_pushes_since_gc
end
- it 'increments the number of pushes since the last GC' do
+ it "increments the number of pushes since the last GC" do
3.times { project.increment_pushes_since_gc }
expect(project.pushes_since_gc).to eq(3)
end
end
- describe '#reset_pushes_since_gc' do
+ describe "#reset_pushes_since_gc" do
let(:project) { create(:project) }
after do
project.reset_pushes_since_gc
end
- it 'resets the number of pushes since the last GC' do
+ it "resets the number of pushes since the last GC" do
3.times { project.increment_pushes_since_gc }
project.reset_pushes_since_gc
@@ -2586,140 +2586,141 @@ describe Project do
end
end
- describe '#deployment_variables' do
- context 'when project has no deployment service' do
+ describe "#deployment_variables" do
+ context "when project has no deployment service" do
let(:project) { create(:project) }
- it 'returns an empty array' do
+ it "returns an empty array" do
expect(project.deployment_variables).to eq []
end
end
- context 'when project uses mock deployment service' do
+ context "when project uses mock deployment service" do
let(:project) { create(:mock_deployment_project) }
- it 'returns an empty array' do
+ it "returns an empty array" do
expect(project.deployment_variables).to eq []
end
end
- context 'when project has a deployment service' do
- shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do
- it 'returns variables from this service' do
+ context "when project has a deployment service" do
+ shared_examples "same behavior between KubernetesService and Platform::Kubernetes" do
+ it "returns variables from this service" do
expect(project.deployment_variables).to include(
- { key: 'KUBE_TOKEN', value: project.deployment_platform.token, public: false }
+ {key: "KUBE_TOKEN", value: project.deployment_platform.token, public: false}
)
end
end
- context 'when user configured kubernetes from Integration > Kubernetes' do
+ context "when user configured kubernetes from Integration > Kubernetes" do
let(:project) { create(:kubernetes_project) }
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
+ it_behaves_like "same behavior between KubernetesService and Platform::Kubernetes"
end
- context 'when user configured kubernetes from CI/CD > Clusters and KubernetesNamespace migration has not been executed' do
+ context "when user configured kubernetes from CI/CD > Clusters and KubernetesNamespace migration has not been executed" do
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
- it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
+ it_behaves_like "same behavior between KubernetesService and Platform::Kubernetes"
end
- context 'when user configured kubernetes from CI/CD > Clusters and KubernetesNamespace migration has been executed' do
+ context "when user configured kubernetes from CI/CD > Clusters and KubernetesNamespace migration has been executed" do
let!(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, :with_token) }
let!(:cluster) { kubernetes_namespace.cluster }
let(:project) { kubernetes_namespace.project }
- it 'should return token from kubernetes namespace' do
+ it "should return token from kubernetes namespace" do
expect(project.deployment_variables).to include(
- { key: 'KUBE_TOKEN', value: kubernetes_namespace.service_account_token, public: false }
+ {key: "KUBE_TOKEN", value: kubernetes_namespace.service_account_token, public: false}
)
end
end
end
end
- describe '#default_environment' do
+ describe "#default_environment" do
let(:project) { create(:project) }
- it 'returns production environment when it exists' do
+ it "returns production environment when it exists" do
production = create(:environment, name: "production", project: project)
- create(:environment, name: 'staging', project: project)
+ create(:environment, name: "staging", project: project)
expect(project.default_environment).to eq(production)
end
- it 'returns first environment when no production environment exists' do
- create(:environment, name: 'staging', project: project)
- create(:environment, name: 'foo', project: project)
+ it "returns first environment when no production environment exists" do
+ create(:environment, name: "staging", project: project)
+ create(:environment, name: "foo", project: project)
expect(project.default_environment).to eq(project.environments.first)
end
- it 'returns nil when no available environment exists' do
+ it "returns nil when no available environment exists" do
expect(project.default_environment).to be_nil
end
end
- describe '#ci_variables_for' do
+ describe "#ci_variables_for" do
let(:project) { create(:project) }
let!(:ci_variable) do
- create(:ci_variable, value: 'secret', project: project)
+ create(:ci_variable, value: "secret", project: project)
end
let!(:protected_variable) do
- create(:ci_variable, :protected, value: 'protected', project: project)
+ create(:ci_variable, :protected, value: "protected", project: project)
end
- subject { project.reload.ci_variables_for(ref: 'ref') }
+ subject { project.reload.ci_variables_for(ref: "ref") }
before do
stub_application_setting(
- default_branch_protection: Gitlab::Access::PROTECTION_NONE)
+ default_branch_protection: Gitlab::Access::PROTECTION_NONE
+ )
end
- shared_examples 'ref is protected' do
- it 'contains all the variables' do
+ shared_examples "ref is protected" do
+ it "contains all the variables" do
is_expected.to contain_exactly(ci_variable, protected_variable)
end
end
- context 'when the ref is not protected' do
+ context "when the ref is not protected" do
before do
- allow(project).to receive(:protected_for?).with('ref').and_return(false)
+ allow(project).to receive(:protected_for?).with("ref").and_return(false)
end
- it 'contains only the CI variables' do
+ it "contains only the CI variables" do
is_expected.to contain_exactly(ci_variable)
end
end
- context 'when the ref is a protected branch' do
+ context "when the ref is a protected branch" do
before do
- allow(project).to receive(:protected_for?).with('ref').and_return(true)
+ allow(project).to receive(:protected_for?).with("ref").and_return(true)
end
- it_behaves_like 'ref is protected'
+ it_behaves_like "ref is protected"
end
- context 'when the ref is a protected tag' do
+ context "when the ref is a protected tag" do
before do
- allow(project).to receive(:protected_for?).with('ref').and_return(true)
+ allow(project).to receive(:protected_for?).with("ref").and_return(true)
end
- it_behaves_like 'ref is protected'
+ it_behaves_like "ref is protected"
end
end
- describe '#any_lfs_file_locks?', :request_store do
+ describe "#any_lfs_file_locks?", :request_store do
set(:project) { create(:project) }
- it 'returns false when there are no LFS file locks' do
+ it "returns false when there are no LFS file locks" do
expect(project.any_lfs_file_locks?).to be_falsey
end
- it 'returns a cached true when there are LFS file locks' do
+ it "returns a cached true when there are LFS file locks" do
create(:lfs_file_lock, project: project)
expect(project.lfs_file_locks).to receive(:any?).once.and_call_original
@@ -2728,145 +2729,146 @@ describe Project do
end
end
- describe '#protected_for?' do
+ describe "#protected_for?" do
let(:project) { create(:project, :repository) }
subject { project.protected_for?(ref) }
- shared_examples 'ref is not protected' do
+ shared_examples "ref is not protected" do
before do
stub_application_setting(
- default_branch_protection: Gitlab::Access::PROTECTION_NONE)
+ default_branch_protection: Gitlab::Access::PROTECTION_NONE
+ )
end
- it 'returns false' do
+ it "returns false" do
is_expected.to be false
end
end
- shared_examples 'ref is protected branch' do
+ shared_examples "ref is protected branch" do
before do
- create(:protected_branch, name: 'master', project: project)
+ create(:protected_branch, name: "master", project: project)
end
- it 'returns true' do
+ it "returns true" do
is_expected.to be true
end
end
- shared_examples 'ref is protected tag' do
+ shared_examples "ref is protected tag" do
before do
- create(:protected_tag, name: 'v1.0.0', project: project)
+ create(:protected_tag, name: "v1.0.0", project: project)
end
- it 'returns true' do
+ it "returns true" do
is_expected.to be true
end
end
- context 'when ref is nil' do
+ context "when ref is nil" do
let(:ref) { nil }
- it 'returns false' do
+ it "returns false" do
is_expected.to be false
end
end
- context 'when ref is ref name' do
- context 'when ref is ambiguous' do
- let(:ref) { 'ref' }
+ context "when ref is ref name" do
+ context "when ref is ambiguous" do
+ let(:ref) { "ref" }
before do
- project.repository.add_branch(project.creator, 'ref', 'master')
- project.repository.add_tag(project.creator, 'ref', 'master')
+ project.repository.add_branch(project.creator, "ref", "master")
+ project.repository.add_tag(project.creator, "ref", "master")
end
- it 'raises an error' do
+ it "raises an error" do
expect { subject }.to raise_error(Repository::AmbiguousRefError)
end
end
- context 'when the ref is not protected' do
- let(:ref) { 'master' }
+ context "when the ref is not protected" do
+ let(:ref) { "master" }
- it_behaves_like 'ref is not protected'
+ it_behaves_like "ref is not protected"
end
- context 'when the ref is a protected branch' do
- let(:ref) { 'master' }
+ context "when the ref is a protected branch" do
+ let(:ref) { "master" }
- it_behaves_like 'ref is protected branch'
+ it_behaves_like "ref is protected branch"
end
- context 'when the ref is a protected tag' do
- let(:ref) { 'v1.0.0' }
+ context "when the ref is a protected tag" do
+ let(:ref) { "v1.0.0" }
- it_behaves_like 'ref is protected tag'
+ it_behaves_like "ref is protected tag"
end
- context 'when ref does not exist' do
- let(:ref) { 'something' }
+ context "when ref does not exist" do
+ let(:ref) { "something" }
- it 'returns false' do
+ it "returns false" do
is_expected.to be false
end
end
end
- context 'when ref is full ref' do
- context 'when the ref is not protected' do
- let(:ref) { 'refs/heads/master' }
+ context "when ref is full ref" do
+ context "when the ref is not protected" do
+ let(:ref) { "refs/heads/master" }
- it_behaves_like 'ref is not protected'
+ it_behaves_like "ref is not protected"
end
- context 'when the ref is a protected branch' do
- let(:ref) { 'refs/heads/master' }
+ context "when the ref is a protected branch" do
+ let(:ref) { "refs/heads/master" }
- it_behaves_like 'ref is protected branch'
+ it_behaves_like "ref is protected branch"
end
- context 'when the ref is a protected tag' do
- let(:ref) { 'refs/tags/v1.0.0' }
+ context "when the ref is a protected tag" do
+ let(:ref) { "refs/tags/v1.0.0" }
- it_behaves_like 'ref is protected tag'
+ it_behaves_like "ref is protected tag"
end
- context 'when branch ref name is a full tag ref' do
- let(:ref) { 'refs/tags/something' }
+ context "when branch ref name is a full tag ref" do
+ let(:ref) { "refs/tags/something" }
before do
- project.repository.add_branch(project.creator, ref, 'master')
+ project.repository.add_branch(project.creator, ref, "master")
end
- context 'when ref is not protected' do
- it 'returns false' do
+ context "when ref is not protected" do
+ it "returns false" do
is_expected.to be false
end
end
- context 'when ref is a protected branch' do
+ context "when ref is a protected branch" do
before do
- create(:protected_branch, name: 'refs/tags/something', project: project)
+ create(:protected_branch, name: "refs/tags/something", project: project)
end
- it 'returns true' do
+ it "returns true" do
is_expected.to be true
end
end
end
- context 'when ref does not exist' do
- let(:ref) { 'refs/heads/something' }
+ context "when ref does not exist" do
+ let(:ref) { "refs/heads/something" }
- it 'returns false' do
+ it "returns false" do
is_expected.to be false
end
end
end
end
- describe '#update_project_statistics' do
+ describe "#update_project_statistics" do
let(:project) { create(:project) }
it "is called after creation" do
@@ -2886,18 +2888,18 @@ describe Project do
end
end
- describe 'inside_path' do
- let!(:project1) { create(:project, namespace: create(:namespace, path: 'name_pace')) }
+ describe "inside_path" do
+ let!(:project1) { create(:project, namespace: create(:namespace, path: "name_pace")) }
let!(:project2) { create(:project) }
- let!(:project3) { create(:project, namespace: create(:namespace, path: 'namespace')) }
+ let!(:project3) { create(:project, namespace: create(:namespace, path: "namespace")) }
let!(:path) { project1.namespace.full_path }
- it 'returns correct project' do
+ it "returns correct project" do
expect(described_class.inside_path(path)).to eq([project1])
end
end
- describe '#route_map_for' do
+ describe "#route_map_for" do
let(:project) { create(:project, :repository) }
let(:route_map) do
<<-MAP.strip_heredoc
@@ -2907,34 +2909,34 @@ describe Project do
end
before do
- project.repository.create_file(User.last, '.gitlab/route-map.yml', route_map, message: 'Add .gitlab/route-map.yml', branch_name: 'master')
+ project.repository.create_file(User.last, ".gitlab/route-map.yml", route_map, message: "Add .gitlab/route-map.yml", branch_name: "master")
end
- context 'when there is a .gitlab/route-map.yml at the commit' do
- context 'when the route map is valid' do
- it 'returns a route map' do
+ context "when there is a .gitlab/route-map.yml at the commit" do
+ context "when the route map is valid" do
+ it "returns a route map" do
map = project.route_map_for(project.commit.sha)
expect(map).to be_a_kind_of(Gitlab::RouteMap)
end
end
- context 'when the route map is invalid' do
- let(:route_map) { 'INVALID' }
+ context "when the route map is invalid" do
+ let(:route_map) { "INVALID" }
- it 'returns nil' do
+ it "returns nil" do
expect(project.route_map_for(project.commit.sha)).to be_nil
end
end
end
- context 'when there is no .gitlab/route-map.yml at the commit' do
- it 'returns nil' do
+ context "when there is no .gitlab/route-map.yml at the commit" do
+ it "returns nil" do
expect(project.route_map_for(project.commit.parent.sha)).to be_nil
end
end
end
- describe '#public_path_for_source_path' do
+ describe "#public_path_for_source_path" do
let(:project) { create(:project, :repository) }
let(:route_map) do
Gitlab::RouteMap.new(<<-MAP.strip_heredoc)
@@ -2944,48 +2946,48 @@ describe Project do
end
let(:sha) { project.commit.id }
- context 'when there is a route map' do
+ context "when there is a route map" do
before do
allow(project).to receive(:route_map_for).with(sha).and_return(route_map)
end
- context 'when the source path is mapped' do
- it 'returns the public path' do
- expect(project.public_path_for_source_path('source/file.html', sha)).to eq('file.html')
+ context "when the source path is mapped" do
+ it "returns the public path" do
+ expect(project.public_path_for_source_path("source/file.html", sha)).to eq("file.html")
end
end
- context 'when the source path is not mapped' do
- it 'returns nil' do
- expect(project.public_path_for_source_path('file.html', sha)).to be_nil
+ context "when the source path is not mapped" do
+ it "returns nil" do
+ expect(project.public_path_for_source_path("file.html", sha)).to be_nil
end
end
end
- context 'when there is no route map' do
+ context "when there is no route map" do
before do
allow(project).to receive(:route_map_for).with(sha).and_return(nil)
end
- it 'returns nil' do
- expect(project.public_path_for_source_path('source/file.html', sha)).to be_nil
+ it "returns nil" do
+ expect(project.public_path_for_source_path("source/file.html", sha)).to be_nil
end
end
end
- describe '#parent' do
+ describe "#parent" do
let(:project) { create(:project) }
it { expect(project.parent).to eq(project.namespace) }
end
- describe '#parent_id' do
+ describe "#parent_id" do
let(:project) { create(:project) }
it { expect(project.parent_id).to eq(project.namespace_id) }
end
- describe '#parent_changed?' do
+ describe "#parent_changed?" do
let(:project) { create(:project) }
before do
@@ -2999,95 +3001,95 @@ describe Project do
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
end
- describe '#pages_url' do
- let(:group) { create(:group, name: 'Group') }
+ describe "#pages_url" do
+ let(:group) { create(:group, name: "Group") }
let(:nested_group) { create(:group, parent: group) }
- let(:domain) { 'Example.com' }
+ let(:domain) { "Example.com" }
subject { project.pages_url }
before do
allow(Settings.pages).to receive(:host).and_return(domain)
- allow(Gitlab.config.pages).to receive(:url).and_return('http://example.com')
+ allow(Gitlab.config.pages).to receive(:url).and_return("http://example.com")
end
- context 'top-level group' do
+ context "top-level group" do
let(:project) { create(:project, namespace: group, name: project_name) }
- context 'group page' do
- let(:project_name) { 'group.example.com' }
+ context "group page" do
+ let(:project_name) { "group.example.com" }
it { is_expected.to eq("http://group.example.com") }
end
- context 'project page' do
- let(:project_name) { 'Project' }
+ context "project page" do
+ let(:project_name) { "Project" }
it { is_expected.to eq("http://group.example.com/project") }
end
end
- context 'nested group' do
+ context "nested group" do
let(:project) { create(:project, namespace: nested_group, name: project_name) }
let(:expected_url) { "http://group.example.com/#{nested_group.path}/#{project.path}" }
- context 'group page' do
- let(:project_name) { 'group.example.com' }
+ context "group page" do
+ let(:project_name) { "group.example.com" }
it { is_expected.to eq(expected_url) }
end
- context 'project page' do
- let(:project_name) { 'Project' }
+ context "project page" do
+ let(:project_name) { "Project" }
it { is_expected.to eq(expected_url) }
end
end
end
- describe '#http_url_to_repo' do
+ describe "#http_url_to_repo" do
let(:project) { create(:project) }
- it 'returns the url to the repo without a username' do
+ it "returns the url to the repo without a username" do
expect(project.http_url_to_repo).to eq("#{project.web_url}.git")
- expect(project.http_url_to_repo).not_to include('@')
+ expect(project.http_url_to_repo).not_to include("@")
end
end
- describe '#lfs_http_url_to_repo' do
+ describe "#lfs_http_url_to_repo" do
let(:project) { create(:project) }
- it 'returns the url to the repo without a username' do
- lfs_http_url_to_repo = project.lfs_http_url_to_repo('operation_that_doesnt_matter')
+ it "returns the url to the repo without a username" do
+ lfs_http_url_to_repo = project.lfs_http_url_to_repo("operation_that_doesnt_matter")
expect(lfs_http_url_to_repo).to eq("#{project.web_url}.git")
- expect(lfs_http_url_to_repo).not_to include('@')
+ expect(lfs_http_url_to_repo).not_to include("@")
end
end
- describe '#pipeline_status' do
+ describe "#pipeline_status" do
let(:project) { create(:project, :repository) }
- it 'builds a pipeline status' do
+ it "builds a pipeline status" do
expect(project.pipeline_status).to be_a(Gitlab::Cache::Ci::ProjectPipelineStatus)
end
- it 'hase a loaded pipeline status' do
+ it "hase a loaded pipeline status" do
expect(project.pipeline_status).to be_loaded
end
end
- describe '#append_or_update_attribute' do
+ describe "#append_or_update_attribute" do
let(:project) { create(:project) }
- it 'shows full error updating an invalid MR' do
- error_message = 'Failed to replace merge_requests because one or more of the new records could not be saved.'\
- ' Validate fork Source project is not a fork of the target project'
+ it "shows full error updating an invalid MR" do
+ error_message = "Failed to replace merge_requests because one or more of the new records could not be saved."\
+ " Validate fork Source project is not a fork of the target project"
expect { project.append_or_update_attribute(:merge_requests, [create(:merge_request)]) }
.to raise_error(ActiveRecord::RecordNotSaved, error_message)
end
- it 'updates the project successfully' do
+ it "updates the project successfully" do
merge_request = create(:merge_request, target_project: project, source_project: project)
expect { project.append_or_update_attribute(:merge_requests, [merge_request]) }
@@ -3095,17 +3097,17 @@ describe Project do
end
end
- describe '#update' do
+ describe "#update" do
let(:project) { create(:project) }
- it 'validates the visibility' do
+ it "validates the visibility" do
expect(project).to receive(:visibility_level_allowed_as_fork).and_call_original
expect(project).to receive(:visibility_level_allowed_by_group).and_call_original
project.update(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
end
- it 'does not validate the visibility' do
+ it "does not validate the visibility" do
expect(project).not_to receive(:visibility_level_allowed_as_fork).and_call_original
expect(project).not_to receive(:visibility_level_allowed_by_group).and_call_original
@@ -3113,15 +3115,15 @@ describe Project do
end
end
- describe '#last_repository_updated_at' do
- it 'sets to created_at upon creation' do
+ describe "#last_repository_updated_at" do
+ it "sets to created_at upon creation" do
project = create(:project, created_at: 2.hours.ago)
expect(project.last_repository_updated_at.to_i).to eq(project.created_at.to_i)
end
end
- describe '.public_or_visible_to_user' do
+ describe ".public_or_visible_to_user" do
let!(:user) { create(:user) }
let!(:private_project) do
@@ -3130,22 +3132,22 @@ describe Project do
let!(:public_project) { create(:project, :public) }
- context 'with a user' do
+ context "with a user" do
let(:projects) do
described_class.all.public_or_visible_to_user(user)
end
- it 'includes projects the user has access to' do
+ it "includes projects the user has access to" do
expect(projects).to include(private_project)
end
- it 'includes projects the user can see' do
+ it "includes projects the user can see" do
expect(projects).to include(public_project)
end
end
- context 'without a user' do
- it 'only includes public projects' do
+ context "without a user" do
+ it "only includes public projects" do
projects = described_class.all.public_or_visible_to_user
expect(projects).to eq([public_project])
@@ -3153,67 +3155,67 @@ describe Project do
end
end
- describe '.with_feature_available_for_user' do
+ describe ".with_feature_available_for_user" do
let!(:user) { create(:user) }
let!(:feature) { MergeRequest }
let!(:project) { create(:project, :public, :merge_requests_enabled) }
subject { described_class.with_feature_available_for_user(feature, user) }
- context 'when user has access to project' do
+ context "when user has access to project" do
subject { described_class.with_feature_available_for_user(feature, user) }
before do
project.add_guest(user)
end
- context 'when public project' do
- context 'when feature is public' do
- it 'returns project' do
+ context "when public project" do
+ context "when feature is public" do
+ it "returns project" do
is_expected.to include(project)
end
end
- context 'when feature is private' do
+ context "when feature is private" do
let!(:project) { create(:project, :public, :merge_requests_private) }
- it 'returns project when user has access to the feature' do
+ it "returns project when user has access to the feature" do
project.add_maintainer(user)
is_expected.to include(project)
end
- it 'does not return project when user does not have the minimum access level required' do
+ it "does not return project when user does not have the minimum access level required" do
is_expected.not_to include(project)
end
end
end
- context 'when private project' do
+ context "when private project" do
let!(:project) { create(:project) }
- it 'returns project when user has access to the feature' do
+ it "returns project when user has access to the feature" do
project.add_maintainer(user)
is_expected.to include(project)
end
- it 'does not return project when user does not have the minimum access level required' do
+ it "does not return project when user does not have the minimum access level required" do
is_expected.not_to include(project)
end
end
end
- context 'when user does not have access to project' do
+ context "when user does not have access to project" do
let!(:project) { create(:project) }
- it 'does not return project when user cant access project' do
+ it "does not return project when user cant access project" do
is_expected.not_to include(project)
end
end
end
- describe '#pages_available?' do
+ describe "#pages_available?" do
let(:project) { create(:project, group: group) }
subject { project.pages_available? }
@@ -3222,41 +3224,41 @@ describe Project do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
end
- context 'when the project is in a top level namespace' do
+ context "when the project is in a top level namespace" do
let(:group) { create(:group) }
it { is_expected.to be(true) }
end
- context 'when the project is in a subgroup' do
+ context "when the project is in a subgroup" do
let(:group) { create(:group, :nested) }
it { is_expected.to be(true) }
end
end
- describe '#remove_private_deploy_keys' do
+ describe "#remove_private_deploy_keys" do
let!(:project) { create(:project) }
- context 'for a private deploy key' do
+ context "for a private deploy key" do
let!(:key) { create(:deploy_key, public: false) }
let!(:deploy_keys_project) { create(:deploy_keys_project, deploy_key: key, project: project) }
- context 'when the key is not linked to another project' do
- it 'removes the key' do
+ context "when the key is not linked to another project" do
+ it "removes the key" do
project.remove_private_deploy_keys
expect(project.deploy_keys).not_to include(key)
end
end
- context 'when the key is linked to another project' do
+ context "when the key is linked to another project" do
before do
another_project = create(:project)
create(:deploy_keys_project, deploy_key: key, project: another_project)
end
- it 'does not remove the key' do
+ it "does not remove the key" do
project.remove_private_deploy_keys
expect(project.deploy_keys).to include(key)
@@ -3264,11 +3266,11 @@ describe Project do
end
end
- context 'for a public deploy key' do
+ context "for a public deploy key" do
let!(:key) { create(:deploy_key, public: true) }
let!(:deploy_keys_project) { create(:deploy_keys_project, deploy_key: key, project: project) }
- it 'does not remove the key' do
+ it "does not remove the key" do
project.remove_private_deploy_keys
expect(project.deploy_keys).to include(key)
@@ -3276,7 +3278,7 @@ describe Project do
end
end
- describe '#remove_pages' do
+ describe "#remove_pages" do
let(:project) { create(:project) }
let(:namespace) { project.namespace }
let(:pages_path) { project.pages_path }
@@ -3290,7 +3292,7 @@ describe Project do
end
end
- it 'removes the pages directory' do
+ it "removes the pages directory" do
expect_any_instance_of(Projects::UpdatePagesConfigurationService).to receive(:execute)
expect_any_instance_of(Gitlab::PagesTransfer).to receive(:rename_project).and_return(true)
expect(PagesWorker).to receive(:perform_in).with(5.minutes, :remove, namespace.full_path, anything)
@@ -3298,7 +3300,7 @@ describe Project do
project.remove_pages
end
- it 'is a no-op when there is no namespace' do
+ it "is a no-op when there is no namespace" do
project.namespace.delete
project.reload
@@ -3308,25 +3310,25 @@ describe Project do
project.remove_pages
end
- it 'is run when the project is destroyed' do
+ it "is run when the project is destroyed" do
expect(project).to receive(:remove_pages).and_call_original
project.destroy
end
end
- describe '#remove_export' do
+ describe "#remove_export" do
let(:project) { create(:project, :with_export) }
- it 'removes the export' do
+ it "removes the export" do
project.remove_exports
expect(project.export_file_exists?).to be_falsey
end
end
- describe '#forks_count' do
- it 'returns the number of forks' do
+ describe "#forks_count" do
+ it "returns the number of forks" do
project = build(:project)
expect_any_instance_of(Projects::ForksCountService).to receive(:count).and_return(1)
@@ -3335,26 +3337,26 @@ describe Project do
end
end
- describe '#git_transfer_in_progress?' do
+ describe "#git_transfer_in_progress?" do
let(:project) { build(:project) }
subject { project.git_transfer_in_progress? }
- it 'returns false when repo_reference_count and wiki_reference_count are 0' do
+ it "returns false when repo_reference_count and wiki_reference_count are 0" do
allow(project).to receive(:repo_reference_count) { 0 }
allow(project).to receive(:wiki_reference_count) { 0 }
expect(subject).to be_falsey
end
- it 'returns true when repo_reference_count is > 0' do
+ it "returns true when repo_reference_count is > 0" do
allow(project).to receive(:repo_reference_count) { 2 }
allow(project).to receive(:wiki_reference_count) { 0 }
expect(subject).to be_truthy
end
- it 'returns true when wiki_reference_count is > 0' do
+ it "returns true when wiki_reference_count is > 0" do
allow(project).to receive(:repo_reference_count) { 0 }
allow(project).to receive(:wiki_reference_count) { 2 }
@@ -3362,7 +3364,7 @@ describe Project do
end
end
- context 'legacy storage' do
+ context "legacy storage" do
set(:project) { create(:project, :repository, :legacy_storage) }
let(:gitlab_shell) { Gitlab::Shell.new }
let(:project_storage) { project.send(:storage) }
@@ -3371,66 +3373,66 @@ describe Project do
allow(project).to receive(:gitlab_shell).and_return(gitlab_shell)
end
- describe '#base_dir' do
- it 'returns base_dir based on namespace only' do
+ describe "#base_dir" do
+ it "returns base_dir based on namespace only" do
expect(project.base_dir).to eq(project.namespace.full_path)
end
end
- describe '#disk_path' do
- it 'returns disk_path based on namespace and project path' do
+ describe "#disk_path" do
+ it "returns disk_path based on namespace and project path" do
expect(project.disk_path).to eq("#{project.namespace.full_path}/#{project.path}")
end
end
- describe '#ensure_storage_path_exists' do
- it 'delegates to gitlab_shell to ensure namespace is created' do
+ describe "#ensure_storage_path_exists" do
+ it "delegates to gitlab_shell to ensure namespace is created" do
expect(gitlab_shell).to receive(:add_namespace).with(project.repository_storage, project.base_dir)
project.ensure_storage_path_exists
end
end
- describe '#legacy_storage?' do
- it 'returns true when storage_version is nil' do
+ describe "#legacy_storage?" do
+ it "returns true when storage_version is nil" do
project = build(:project, storage_version: nil)
expect(project.legacy_storage?).to be_truthy
end
- it 'returns true when the storage_version is 0' do
+ it "returns true when the storage_version is 0" do
project = build(:project, storage_version: 0)
expect(project.legacy_storage?).to be_truthy
end
end
- describe '#hashed_storage?' do
- it 'returns false' do
+ describe "#hashed_storage?" do
+ it "returns false" do
expect(project.hashed_storage?(:repository)).to be_falsey
end
end
- describe '#pages_path' do
- it 'returns a path where pages are stored' do
+ describe "#pages_path" do
+ it "returns a path where pages are stored" do
expect(project.pages_path).to eq(File.join(Settings.pages.path, project.namespace.full_path, project.path))
end
end
- describe '#migrate_to_hashed_storage!' do
+ describe "#migrate_to_hashed_storage!" do
let(:project) { create(:project, :empty_repo, :legacy_storage) }
- it 'returns true' do
+ it "returns true" do
expect(project.migrate_to_hashed_storage!).to be_truthy
end
- it 'does not run validation' do
+ it "does not run validation" do
expect(project).not_to receive(:valid?)
project.migrate_to_hashed_storage!
end
- it 'schedules ProjectMigrateHashedStorageWorker with delayed start when the project repo is in use' do
+ it "schedules ProjectMigrateHashedStorageWorker with delayed start when the project repo is in use" do
Gitlab::ReferenceCounter.new(project.gl_repository(is_wiki: false)).increase
expect(ProjectMigrateHashedStorageWorker).to receive(:perform_in)
@@ -3438,7 +3440,7 @@ describe Project do
project.migrate_to_hashed_storage!
end
- it 'schedules ProjectMigrateHashedStorageWorker with delayed start when the wiki repo is in use' do
+ it "schedules ProjectMigrateHashedStorageWorker with delayed start when the wiki repo is in use" do
Gitlab::ReferenceCounter.new(project.gl_repository(is_wiki: true)).increase
expect(ProjectMigrateHashedStorageWorker).to receive(:perform_in)
@@ -3446,7 +3448,7 @@ describe Project do
project.migrate_to_hashed_storage!
end
- it 'schedules ProjectMigrateHashedStorageWorker' do
+ it "schedules ProjectMigrateHashedStorageWorker" do
expect(ProjectMigrateHashedStorageWorker).to receive(:perform_async).with(project.id)
project.migrate_to_hashed_storage!
@@ -3454,49 +3456,49 @@ describe Project do
end
end
- context 'hashed storage' do
+ context "hashed storage" do
set(:project) { create(:project, :repository, skip_disk_validation: true) }
let(:gitlab_shell) { Gitlab::Shell.new }
let(:hash) { Digest::SHA2.hexdigest(project.id.to_s) }
- let(:hashed_prefix) { File.join('@hashed', hash[0..1], hash[2..3]) }
+ let(:hashed_prefix) { File.join("@hashed", hash[0..1], hash[2..3]) }
let(:hashed_path) { File.join(hashed_prefix, hash) }
before do
stub_application_setting(hashed_storage_enabled: true)
end
- describe '#legacy_storage?' do
- it 'returns false' do
+ describe "#legacy_storage?" do
+ it "returns false" do
expect(project.legacy_storage?).to be_falsey
end
end
- describe '#hashed_storage?' do
- it 'returns true if rolled out' do
+ describe "#hashed_storage?" do
+ it "returns true if rolled out" do
expect(project.hashed_storage?(:attachments)).to be_truthy
end
- it 'returns false when not rolled out yet' do
+ it "returns false when not rolled out yet" do
project.storage_version = 1
expect(project.hashed_storage?(:attachments)).to be_falsey
end
end
- describe '#base_dir' do
- it 'returns base_dir based on hash of project id' do
+ describe "#base_dir" do
+ it "returns base_dir based on hash of project id" do
expect(project.base_dir).to eq(hashed_prefix)
end
end
- describe '#disk_path' do
- it 'returns disk_path based on hash of project id' do
+ describe "#disk_path" do
+ it "returns disk_path based on hash of project id" do
expect(project.disk_path).to eq(hashed_path)
end
end
- describe '#ensure_storage_path_exists' do
- it 'delegates to gitlab_shell to ensure namespace is created' do
+ describe "#ensure_storage_path_exists" do
+ it "delegates to gitlab_shell to ensure namespace is created" do
allow(project).to receive(:gitlab_shell).and_return(gitlab_shell)
expect(gitlab_shell).to receive(:add_namespace).with(project.repository_storage, hashed_prefix)
@@ -3505,25 +3507,25 @@ describe Project do
end
end
- describe '#pages_path' do
- it 'returns a path where pages are stored' do
+ describe "#pages_path" do
+ it "returns a path where pages are stored" do
expect(project.pages_path).to eq(File.join(Settings.pages.path, project.namespace.full_path, project.path))
end
end
- describe '#migrate_to_hashed_storage!' do
+ describe "#migrate_to_hashed_storage!" do
let(:project) { create(:project, :repository, skip_disk_validation: true) }
- it 'returns nil' do
+ it "returns nil" do
expect(project.migrate_to_hashed_storage!).to be_nil
end
- it 'does not flag as read-only' do
+ it "does not flag as read-only" do
expect { project.migrate_to_hashed_storage! }.not_to change { project.repository_read_only }
end
- context 'when partially migrated' do
- it 'enqueues a job' do
+ context "when partially migrated" do
+ it "enqueues a job" do
project = create(:project, storage_version: 1, skip_disk_validation: true)
Sidekiq::Testing.fake! do
@@ -3534,17 +3536,17 @@ describe Project do
end
end
- describe '#gl_repository' do
+ describe "#gl_repository" do
let(:project) { create(:project) }
- it 'delegates to Gitlab::GlRepository.gl_repository' do
+ it "delegates to Gitlab::GlRepository.gl_repository" do
expect(Gitlab::GlRepository).to receive(:gl_repository).with(project, true)
project.gl_repository(is_wiki: true)
end
end
- describe '#has_ci?' do
+ describe "#has_ci?" do
set(:project) { create(:project) }
let(:repository) { double }
@@ -3552,9 +3554,9 @@ describe Project do
expect(project).to receive(:repository) { repository }
end
- context 'when has .gitlab-ci.yml' do
+ context "when has .gitlab-ci.yml" do
before do
- expect(repository).to receive(:gitlab_ci_yml) { 'content' }
+ expect(repository).to receive(:gitlab_ci_yml) { "content" }
end
it "CI is available" do
@@ -3562,7 +3564,7 @@ describe Project do
end
end
- context 'when there is no .gitlab-ci.yml' do
+ context "when there is no .gitlab-ci.yml" do
before do
expect(repository).to receive(:gitlab_ci_yml) { nil }
end
@@ -3571,7 +3573,7 @@ describe Project do
expect(project).to have_ci
end
- context 'when auto devops is disabled' do
+ context "when auto devops is disabled" do
before do
stub_application_setting(auto_devops_enabled: false)
end
@@ -3583,7 +3585,7 @@ describe Project do
end
end
- describe '#auto_devops_enabled?' do
+ describe "#auto_devops_enabled?" do
before do
allow(Feature).to receive(:enabled?).and_call_original
Feature.get(:force_autodevops_on_by_default).enable_percentage_of_actors(0)
@@ -3593,14 +3595,14 @@ describe Project do
subject { project.auto_devops_enabled? }
- context 'when enabled in settings' do
+ context "when enabled in settings" do
before do
stub_application_setting(auto_devops_enabled: true)
end
it { is_expected.to be_truthy }
- context 'when explicitly enabled' do
+ context "when explicitly enabled" do
before do
create(:project_auto_devops, project: project)
end
@@ -3608,7 +3610,7 @@ describe Project do
it { is_expected.to be_truthy }
end
- context 'when explicitly disabled' do
+ context "when explicitly disabled" do
before do
create(:project_auto_devops, project: project, enabled: false)
end
@@ -3617,14 +3619,14 @@ describe Project do
end
end
- context 'when disabled in settings' do
+ context "when disabled in settings" do
before do
stub_application_setting(auto_devops_enabled: false)
end
it { is_expected.to be_falsey }
- context 'when explicitly enabled' do
+ context "when explicitly enabled" do
before do
create(:project_auto_devops, project: project)
end
@@ -3632,7 +3634,7 @@ describe Project do
it { is_expected.to be_truthy }
end
- context 'when force_autodevops_on_by_default is enabled for the project' do
+ context "when force_autodevops_on_by_default is enabled for the project" do
before do
Feature.get(:force_autodevops_on_by_default).enable_percentage_of_actors(100)
end
@@ -3642,51 +3644,51 @@ describe Project do
end
end
- describe '#has_auto_devops_implicitly_enabled?' do
+ describe "#has_auto_devops_implicitly_enabled?" do
set(:project) { create(:project) }
- context 'when disabled in settings' do
+ context "when disabled in settings" do
before do
stub_application_setting(auto_devops_enabled: false)
end
- it 'does not have auto devops implicitly disabled' do
+ it "does not have auto devops implicitly disabled" do
expect(project).not_to have_auto_devops_implicitly_enabled
end
end
- context 'when enabled in settings' do
+ context "when enabled in settings" do
before do
stub_application_setting(auto_devops_enabled: true)
end
- it 'auto devops is implicitly disabled' do
+ it "auto devops is implicitly disabled" do
expect(project).to have_auto_devops_implicitly_enabled
end
- context 'when explicitly disabled' do
+ context "when explicitly disabled" do
before do
create(:project_auto_devops, project: project, enabled: false)
end
- it 'does not have auto devops implicitly disabled' do
+ it "does not have auto devops implicitly disabled" do
expect(project).not_to have_auto_devops_implicitly_enabled
end
end
- context 'when explicitly enabled' do
+ context "when explicitly enabled" do
before do
create(:project_auto_devops, project: project, enabled: true)
end
- it 'does not have auto devops implicitly disabled' do
+ it "does not have auto devops implicitly disabled" do
expect(project).not_to have_auto_devops_implicitly_enabled
end
end
end
end
- describe '#has_auto_devops_implicitly_disabled?' do
+ describe "#has_auto_devops_implicitly_disabled?" do
before do
allow(Feature).to receive(:enabled?).and_call_original
Feature.get(:force_autodevops_on_by_default).enable_percentage_of_actors(0)
@@ -3694,148 +3696,148 @@ describe Project do
set(:project) { create(:project) }
- context 'when enabled in settings' do
+ context "when enabled in settings" do
before do
stub_application_setting(auto_devops_enabled: true)
end
- it 'does not have auto devops implicitly disabled' do
+ it "does not have auto devops implicitly disabled" do
expect(project).not_to have_auto_devops_implicitly_disabled
end
end
- context 'when disabled in settings' do
+ context "when disabled in settings" do
before do
stub_application_setting(auto_devops_enabled: false)
end
- it 'auto devops is implicitly disabled' do
+ it "auto devops is implicitly disabled" do
expect(project).to have_auto_devops_implicitly_disabled
end
- context 'when force_autodevops_on_by_default is enabled for the project' do
+ context "when force_autodevops_on_by_default is enabled for the project" do
before do
Feature.get(:force_autodevops_on_by_default).enable_percentage_of_actors(100)
end
- it 'does not have auto devops implicitly disabled' do
+ it "does not have auto devops implicitly disabled" do
expect(project).not_to have_auto_devops_implicitly_disabled
end
end
- context 'when explicitly disabled' do
+ context "when explicitly disabled" do
before do
create(:project_auto_devops, project: project, enabled: false)
end
- it 'does not have auto devops implicitly disabled' do
+ it "does not have auto devops implicitly disabled" do
expect(project).not_to have_auto_devops_implicitly_disabled
end
end
- context 'when explicitly enabled' do
+ context "when explicitly enabled" do
before do
create(:project_auto_devops, project: project, enabled: true)
end
- it 'does not have auto devops implicitly disabled' do
+ it "does not have auto devops implicitly disabled" do
expect(project).not_to have_auto_devops_implicitly_disabled
end
end
end
end
- describe '#api_variables' do
+ describe "#api_variables" do
set(:project) { create(:project) }
- it 'exposes API v4 URL' do
- expect(project.api_variables.first[:key]).to eq 'CI_API_V4_URL'
- expect(project.api_variables.first[:value]).to include '/api/v4'
+ it "exposes API v4 URL" do
+ expect(project.api_variables.first[:key]).to eq "CI_API_V4_URL"
+ expect(project.api_variables.first[:value]).to include "/api/v4"
end
- it 'contains a URL variable for every supported API version' do
+ it "contains a URL variable for every supported API version" do
# Ensure future API versions have proper variables defined. We're not doing this for v3.
- supported_versions = API::API.versions - ['v3']
- supported_versions = supported_versions.select do |version|
+ supported_versions = API::API.versions - ["v3"]
+ supported_versions = supported_versions.select { |version|
API::API.routes.select { |route| route.version == version }.many?
- end
+ }
- required_variables = supported_versions.map do |version|
+ required_variables = supported_versions.map { |version|
"CI_API_#{version.upcase}_URL"
- end
+ }
expect(project.api_variables.map { |variable| variable[:key] })
.to contain_exactly(*required_variables)
end
end
- describe '#auto_devops_variables' do
+ describe "#auto_devops_variables" do
set(:project) { create(:project) }
subject { project.auto_devops_variables }
- context 'when enabled in instance settings' do
+ context "when enabled in instance settings" do
before do
stub_application_setting(auto_devops_enabled: true)
end
- context 'when domain is empty' do
+ context "when domain is empty" do
before do
stub_application_setting(auto_devops_domain: nil)
end
- it 'variables does not include AUTO_DEVOPS_DOMAIN' do
+ it "variables does not include AUTO_DEVOPS_DOMAIN" do
is_expected.not_to include(domain_variable)
end
end
- context 'when domain is configured' do
+ context "when domain is configured" do
before do
- stub_application_setting(auto_devops_domain: 'example.com')
+ stub_application_setting(auto_devops_domain: "example.com")
end
- it 'variables includes AUTO_DEVOPS_DOMAIN' do
+ it "variables includes AUTO_DEVOPS_DOMAIN" do
is_expected.to include(domain_variable)
end
end
end
- context 'when explicitly enabled' do
- context 'when domain is empty' do
+ context "when explicitly enabled" do
+ context "when domain is empty" do
before do
create(:project_auto_devops, project: project, domain: nil)
end
- it 'variables does not include AUTO_DEVOPS_DOMAIN' do
+ it "variables does not include AUTO_DEVOPS_DOMAIN" do
is_expected.not_to include(domain_variable)
end
end
- context 'when domain is configured' do
+ context "when domain is configured" do
before do
- create(:project_auto_devops, project: project, domain: 'example.com')
+ create(:project_auto_devops, project: project, domain: "example.com")
end
- it 'variables includes AUTO_DEVOPS_DOMAIN' do
+ it "variables includes AUTO_DEVOPS_DOMAIN" do
is_expected.to include(domain_variable)
end
end
end
def domain_variable
- { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }
+ {key: "AUTO_DEVOPS_DOMAIN", value: "example.com", public: true}
end
end
- describe '#latest_successful_builds_for' do
+ describe "#latest_successful_builds_for" do
let(:project) { build(:project) }
before do
- allow(project).to receive(:default_branch).and_return('master')
+ allow(project).to receive(:default_branch).and_return("master")
end
- context 'without a ref' do
- it 'returns a pipeline for the default branch' do
+ context "without a ref" do
+ it "returns a pipeline for the default branch" do
expect(project)
.to receive(:latest_successful_pipeline_for_default_branch)
@@ -3843,8 +3845,8 @@ describe Project do
end
end
- context 'with the ref set to the default branch' do
- it 'returns a pipeline for the default branch' do
+ context "with the ref set to the default branch" do
+ it "returns a pipeline for the default branch" do
expect(project)
.to receive(:latest_successful_pipeline_for_default_branch)
@@ -3852,19 +3854,19 @@ describe Project do
end
end
- context 'with a ref that is not the default branch' do
- it 'returns the latest successful pipeline for the given ref' do
- expect(project.ci_pipelines).to receive(:latest_successful_for).with('foo')
+ context "with a ref that is not the default branch" do
+ it "returns the latest successful pipeline for the given ref" do
+ expect(project.ci_pipelines).to receive(:latest_successful_for).with("foo")
- project.latest_successful_pipeline_for('foo')
+ project.latest_successful_pipeline_for("foo")
end
end
end
- describe '#check_repository_path_availability' do
+ describe "#check_repository_path_availability" do
let(:project) { build(:project) }
- it 'skips gitlab-shell exists?' do
+ it "skips gitlab-shell exists?" do
project.skip_disk_validation = true
expect(project.gitlab_shell).not_to receive(:exists?)
@@ -3872,14 +3874,14 @@ describe Project do
end
end
- describe '#latest_successful_pipeline_for_default_branch' do
+ describe "#latest_successful_pipeline_for_default_branch" do
let(:project) { build(:project) }
before do
- allow(project).to receive(:default_branch).and_return('master')
+ allow(project).to receive(:default_branch).and_return("master")
end
- it 'memoizes and returns the latest successful pipeline for the default branch' do
+ it "memoizes and returns the latest successful pipeline for the default branch" do
pipeline = double(:pipeline)
expect(project.ci_pipelines).to receive(:latest_successful_for)
@@ -3894,11 +3896,11 @@ describe Project do
end
end
- describe '#after_import' do
+ describe "#after_import" do
let(:project) { create(:project) }
let(:import_state) { create(:import_state, project: project) }
- it 'runs the correct hooks' do
+ it "runs the correct hooks" do
expect(project.repository).to receive(:after_import)
expect(project.wiki.repository).to receive(:after_import)
expect(import_state).to receive(:finish)
@@ -3911,14 +3913,14 @@ describe Project do
project.after_import
end
- context 'branch protection' do
+ context "branch protection" do
let(:project) { create(:project, :repository) }
before do
create(:import_state, :started, project: project)
end
- it 'does not protect when branch protection is disabled' do
+ it "does not protect when branch protection is disabled" do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_NONE)
project.after_import
@@ -3946,7 +3948,7 @@ describe Project do
expect(project.protected_branches.first.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::DEVELOPER])
end
- it 'protects default branch' do
+ it "protects default branch" do
project.after_import
expect(project.protected_branches).not_to be_empty
@@ -3957,10 +3959,10 @@ describe Project do
end
end
- describe '#update_project_counter_caches' do
+ describe "#update_project_counter_caches" do
let(:project) { create(:project) }
- it 'updates all project counter caches' do
+ it "updates all project counter caches" do
expect_any_instance_of(Projects::OpenIssuesCountService)
.to receive(:refresh_cache)
.and_call_original
@@ -3973,45 +3975,45 @@ describe Project do
end
end
- describe '#wiki_repository_exists?' do
- it 'returns true when the wiki repository exists' do
+ describe "#wiki_repository_exists?" do
+ it "returns true when the wiki repository exists" do
project = create(:project, :wiki_repo)
expect(project.wiki_repository_exists?).to eq(true)
end
- it 'returns false when the wiki repository does not exist' do
+ it "returns false when the wiki repository does not exist" do
project = create(:project)
expect(project.wiki_repository_exists?).to eq(false)
end
end
- describe '#write_repository_config' do
+ describe "#write_repository_config" do
set(:project) { create(:project, :repository) }
- it 'writes full path in .git/config when key is missing' do
+ it "writes full path in .git/config when key is missing" do
project.write_repository_config
- expect(rugged_config['gitlab.fullpath']).to eq project.full_path
+ expect(rugged_config["gitlab.fullpath"]).to eq project.full_path
end
- it 'updates full path in .git/config when key is present' do
- project.write_repository_config(gl_full_path: 'old/path')
+ it "updates full path in .git/config when key is present" do
+ project.write_repository_config(gl_full_path: "old/path")
- expect { project.write_repository_config }.to change { rugged_config['gitlab.fullpath'] }.from('old/path').to(project.full_path)
+ expect { project.write_repository_config }.to change { rugged_config["gitlab.fullpath"] }.from("old/path").to(project.full_path)
end
- it 'does not raise an error with an empty repository' do
+ it "does not raise an error with an empty repository" do
project = create(:project_empty_repo)
expect { project.write_repository_config }.not_to raise_error
end
end
- describe '#execute_hooks' do
- let(:data) { { ref: 'refs/heads/master', data: 'data' } }
- it 'executes active projects hooks with the specified scope' do
+ describe "#execute_hooks" do
+ let(:data) { {ref: "refs/heads/master", data: "data"} }
+ it "executes active projects hooks with the specified scope" do
hook = create(:project_hook, merge_requests_events: false, push_events: true)
expect(ProjectHook).to receive(:select_active)
.with(:push_hooks, data)
@@ -4023,7 +4025,7 @@ describe Project do
project.execute_hooks(data, :push_hooks)
end
- it 'does not execute project hooks that dont match the specified scope' do
+ it "does not execute project hooks that dont match the specified scope" do
hook = create(:project_hook, merge_requests_events: true, push_events: false)
project = create(:project, hooks: [hook])
@@ -4032,7 +4034,7 @@ describe Project do
project.execute_hooks(data, :push_hooks)
end
- it 'does not execute project hooks which are not active' do
+ it "does not execute project hooks which are not active" do
hook = create(:project_hook, push_events: true)
expect(ProjectHook).to receive(:select_active)
.with(:push_hooks, data)
@@ -4044,14 +4046,14 @@ describe Project do
project.execute_hooks(data, :push_hooks)
end
- it 'executes the system hooks with the specified scope' do
+ it "executes the system hooks with the specified scope" do
expect_any_instance_of(SystemHooksService).to receive(:execute_hooks).with(data, :merge_request_hooks)
project = build(:project)
project.execute_hooks(data, :merge_request_hooks)
end
- it 'executes the system hooks when inside a transaction' do
+ it "executes the system hooks when inside a transaction" do
allow_any_instance_of(WebHookService).to receive(:execute)
create(:system_hook, merge_requests_events: true)
@@ -4061,24 +4063,24 @@ describe Project do
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
# but since the entire spec run takes place in a transaction, we never
# actually get to the `after_commit` hook that queues these jobs.
- expect do
+ expect {
project.transaction do
project.execute_hooks(data, :merge_request_hooks)
end
- end.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
+ }.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
end
end
- describe '#badges' do
+ describe "#badges" do
let(:project_group) { create(:group) }
- let(:project) { create(:project, path: 'avatar', namespace: project_group) }
+ let(:project) { create(:project, path: "avatar", namespace: project_group) }
before do
create_list(:project_badge, 2, project: project)
create(:group_badge, group: project_group)
end
- it 'returns the project and the project group badges' do
+ it "returns the project and the project group badges" do
create(:group_badge, group: create(:group))
expect(Badge.count).to eq 4
@@ -4086,7 +4088,7 @@ describe Project do
end
if Group.supports_nested_objects?
- context 'with nested_groups' do
+ context "with nested_groups" do
let(:parent_group) { create(:group) }
before do
@@ -4094,14 +4096,14 @@ describe Project do
project_group.update(parent: parent_group)
end
- it 'returns the project and the project nested groups badges' do
+ it "returns the project and the project nested groups badges" do
expect(project.badges.count).to eq 5
end
end
end
end
- context 'with cross project merge requests' do
+ context "with cross project merge requests" do
let(:user) { create(:user) }
let(:target_project) { create(:project, :repository) }
let(:project) { fork_project(target_project, nil, repository: true) }
@@ -4109,9 +4111,9 @@ describe Project do
create(
:merge_request,
target_project: project,
- target_branch: 'target-branch',
+ target_branch: "target-branch",
source_project: project,
- source_branch: 'awesome-feature-1',
+ source_branch: "awesome-feature-1",
allow_collaboration: true
)
end
@@ -4119,9 +4121,9 @@ describe Project do
create(
:merge_request,
target_project: target_project,
- target_branch: 'target-branch',
+ target_branch: "target-branch",
source_project: project,
- source_branch: 'awesome-feature-1',
+ source_branch: "awesome-feature-1",
allow_collaboration: true
)
end
@@ -4130,42 +4132,42 @@ describe Project do
target_project.add_developer(user)
end
- describe '#merge_requests_allowing_push_to_user' do
- it 'returns open merge requests for which the user has developer access to the target project' do
+ describe "#merge_requests_allowing_push_to_user" do
+ it "returns open merge requests for which the user has developer access to the target project" do
expect(project.merge_requests_allowing_push_to_user(user)).to include(merge_request)
end
- it 'does not include closed merge requests' do
+ it "does not include closed merge requests" do
merge_request.close
expect(project.merge_requests_allowing_push_to_user(user)).to be_empty
end
- it 'does not include merge requests for guest users' do
+ it "does not include merge requests for guest users" do
guest = create(:user)
target_project.add_guest(guest)
expect(project.merge_requests_allowing_push_to_user(guest)).to be_empty
end
- it 'does not include the merge request for other users' do
+ it "does not include the merge request for other users" do
other_user = create(:user)
expect(project.merge_requests_allowing_push_to_user(other_user)).to be_empty
end
- it 'is empty when no user is passed' do
+ it "is empty when no user is passed" do
expect(project.merge_requests_allowing_push_to_user(nil)).to be_empty
end
end
- describe '#any_branch_allows_collaboration?' do
- it 'allows access when there are merge requests open allowing collaboration' do
+ describe "#any_branch_allows_collaboration?" do
+ it "allows access when there are merge requests open allowing collaboration" do
expect(project.any_branch_allows_collaboration?(user))
.to be_truthy
end
- it 'does not allow access when there are no merge requests open allowing collaboration' do
+ it "does not allow access when there are no merge requests open allowing collaboration" do
merge_request.close!
expect(project.any_branch_allows_collaboration?(user))
@@ -4173,44 +4175,44 @@ describe Project do
end
end
- describe '#branch_allows_collaboration?' do
- it 'allows access if the user can merge the merge request' do
- expect(project.branch_allows_collaboration?(user, 'awesome-feature-1'))
+ describe "#branch_allows_collaboration?" do
+ it "allows access if the user can merge the merge request" do
+ expect(project.branch_allows_collaboration?(user, "awesome-feature-1"))
.to be_truthy
end
- it 'does not allow guest users access' do
+ it "does not allow guest users access" do
guest = create(:user)
target_project.add_guest(guest)
- expect(project.branch_allows_collaboration?(guest, 'awesome-feature-1'))
+ expect(project.branch_allows_collaboration?(guest, "awesome-feature-1"))
.to be_falsy
end
- it 'does not allow access to branches for which the merge request was closed' do
+ it "does not allow access to branches for which the merge request was closed" do
create(:merge_request, :closed,
- target_project: target_project,
- target_branch: 'target-branch',
- source_project: project,
- source_branch: 'rejected-feature-1',
- allow_collaboration: true)
+ target_project: target_project,
+ target_branch: "target-branch",
+ source_project: project,
+ source_branch: "rejected-feature-1",
+ allow_collaboration: true)
- expect(project.branch_allows_collaboration?(user, 'rejected-feature-1'))
+ expect(project.branch_allows_collaboration?(user, "rejected-feature-1"))
.to be_falsy
end
- it 'does not allow access if the user cannot merge the merge request' do
- create(:protected_branch, :maintainers_can_push, project: target_project, name: 'target-branch')
+ it "does not allow access if the user cannot merge the merge request" do
+ create(:protected_branch, :maintainers_can_push, project: target_project, name: "target-branch")
- expect(project.branch_allows_collaboration?(user, 'awesome-feature-1'))
+ expect(project.branch_allows_collaboration?(user, "awesome-feature-1"))
.to be_falsy
end
- context 'when the requeststore is active', :request_store do
- it 'only queries per project across instances' do
- control = ActiveRecord::QueryRecorder.new { project.branch_allows_collaboration?(user, 'awesome-feature-1') }
+ context "when the requeststore is active", :request_store do
+ it "only queries per project across instances" do
+ control = ActiveRecord::QueryRecorder.new { project.branch_allows_collaboration?(user, "awesome-feature-1") }
- expect { 2.times { described_class.find(project.id).branch_allows_collaboration?(user, 'awesome-feature-1') } }
+ expect { 2.times { described_class.find(project.id).branch_allows_collaboration?(user, "awesome-feature-1") } }
.not_to exceed_query_limit(control).with_threshold(2)
end
end
@@ -4262,8 +4264,8 @@ describe Project do
end
end
- describe '#toggle_ci_cd_settings!' do
- it 'toggles the value on #settings' do
+ describe "#toggle_ci_cd_settings!" do
+ it "toggles the value on #settings" do
project = create(:project, group_runners_enabled: false)
expect(project.group_runners_enabled).to be false
@@ -4274,39 +4276,39 @@ describe Project do
end
end
- describe '#gitlab_deploy_token' do
+ describe "#gitlab_deploy_token" do
let(:project) { create(:project) }
subject { project.gitlab_deploy_token }
- context 'when there is a gitlab deploy token associated' do
+ context "when there is a gitlab deploy token associated" do
let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, projects: [project]) }
it { is_expected.to eq(deploy_token) }
end
- context 'when there is no a gitlab deploy token associated' do
+ context "when there is no a gitlab deploy token associated" do
it { is_expected.to be_nil }
end
- context 'when there is a gitlab deploy token associated but is has been revoked' do
+ context "when there is a gitlab deploy token associated but is has been revoked" do
let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, :revoked, projects: [project]) }
it { is_expected.to be_nil }
end
- context 'when there is a gitlab deploy token associated but it is expired' do
+ context "when there is a gitlab deploy token associated but it is expired" do
let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, :expired, projects: [project]) }
it { is_expected.to be_nil }
end
- context 'when there is a deploy token associated with a different name' do
+ context "when there is a deploy token associated with a different name" do
let!(:deploy_token) { create(:deploy_token, projects: [project]) }
it { is_expected.to be_nil }
end
- context 'when there is a deploy token associated to a different project' do
+ context "when there is a deploy token associated to a different project" do
let(:project_2) { create(:project) }
let!(:deploy_token) { create(:deploy_token, projects: [project_2]) }
@@ -4314,25 +4316,25 @@ describe Project do
end
end
- context 'with uploads' do
- it_behaves_like 'model with uploads', true do
+ context "with uploads" do
+ it_behaves_like "model with uploads", true do
let(:model_object) { create(:project, :with_avatar) }
let(:upload_attribute) { :avatar }
let(:uploader_class) { AttachmentUploader }
end
end
- context '#commits_by' do
+ context "#commits_by" do
let(:project) { create(:project, :repository) }
- let(:commits) { project.repository.commits('HEAD', limit: 3).commits }
+ let(:commits) { project.repository.commits("HEAD", limit: 3).commits }
let(:commit_shas) { commits.map(&:id) }
- it 'retrieves several commits from the repository by oid' do
+ it "retrieves several commits from the repository by oid" do
expect(project.commits_by(oids: commit_shas)).to eq commits
end
end
- context '#members_among' do
+ context "#members_among" do
let(:users) { create_list(:user, 3) }
set(:group) { create(:group) }
set(:project) { create(:project, namespace: group) }
@@ -4342,31 +4344,31 @@ describe Project do
project.group.add_maintainer(users.last)
end
- context 'when users is an Array' do
- it 'returns project members among the users' do
+ context "when users is an Array" do
+ it "returns project members among the users" do
expect(project.members_among(users)).to eq([users.first, users.last])
end
- it 'maintains input order' do
+ it "maintains input order" do
expect(project.members_among(users.reverse)).to eq([users.last, users.first])
end
- it 'returns empty array if users is empty' do
+ it "returns empty array if users is empty" do
result = project.members_among([])
expect(result).to be_empty
end
end
- context 'when users is a relation' do
- it 'returns project members among the users' do
+ context "when users is a relation" do
+ it "returns project members among the users" do
result = project.members_among(User.where(id: users.map(&:id)))
expect(result).to be_a(ActiveRecord::Relation)
expect(result).to eq([users.first, users.last])
end
- it 'returns empty relation if users is empty' do
+ it "returns empty relation if users is empty" do
result = project.members_among(User.none)
expect(result).to be_a(ActiveRecord::Relation)
@@ -4378,9 +4380,9 @@ describe Project do
describe "#find_or_initialize_services" do
subject { build(:project) }
- it 'returns only enabled services' do
- allow(Service).to receive(:available_services_names).and_return(%w(prometheus pushover))
- allow(subject).to receive(:disabled_services).and_return(%w(prometheus))
+ it "returns only enabled services" do
+ allow(Service).to receive(:available_services_names).and_return(%w[prometheus pushover])
+ allow(subject).to receive(:disabled_services).and_return(%w[prometheus])
services = subject.find_or_initialize_services
@@ -4392,39 +4394,39 @@ describe Project do
describe "#find_or_initialize_service" do
subject { build(:project) }
- it 'avoids N+1 database queries' do
- allow(Service).to receive(:available_services_names).and_return(%w(prometheus pushover))
+ it "avoids N+1 database queries" do
+ allow(Service).to receive(:available_services_names).and_return(%w[prometheus pushover])
- control_count = ActiveRecord::QueryRecorder.new { subject.find_or_initialize_service('prometheus') }.count
+ control_count = ActiveRecord::QueryRecorder.new { subject.find_or_initialize_service("prometheus") }.count
allow(Service).to receive(:available_services_names).and_call_original
- expect { subject.find_or_initialize_service('prometheus') }.not_to exceed_query_limit(control_count)
+ expect { subject.find_or_initialize_service("prometheus") }.not_to exceed_query_limit(control_count)
end
- it 'returns nil if service is disabled' do
- allow(subject).to receive(:disabled_services).and_return(%w(prometheus))
+ it "returns nil if service is disabled" do
+ allow(subject).to receive(:disabled_services).and_return(%w[prometheus])
- expect(subject.find_or_initialize_service('prometheus')).to be_nil
+ expect(subject.find_or_initialize_service("prometheus")).to be_nil
end
end
- describe '.find_without_deleted' do
- it 'returns nil if the project is about to be removed' do
+ describe ".find_without_deleted" do
+ it "returns nil if the project is about to be removed" do
project = create(:project, pending_delete: true)
expect(described_class.find_without_deleted(project.id)).to be_nil
end
- it 'returns a project when it is not about to be removed' do
+ it "returns a project when it is not about to be removed" do
project = create(:project)
expect(described_class.find_without_deleted(project.id)).to eq(project)
end
end
- describe '.for_group' do
- it 'returns the projects for a given group' do
+ describe ".for_group" do
+ it "returns the projects for a given group" do
group = create(:group)
project = create(:project, namespace: group)
@@ -4432,7 +4434,7 @@ describe Project do
end
end
- describe '.deployments' do
+ describe ".deployments" do
subject { project.deployments }
let(:project) { create(:project) }
@@ -4441,46 +4443,46 @@ describe Project do
allow_any_instance_of(Deployment).to receive(:create_ref)
end
- context 'when there is a deployment record with created status' do
+ context "when there is a deployment record with created status" do
let(:deployment) { create(:deployment, :created, project: project) }
- it 'does not return the record' do
+ it "does not return the record" do
is_expected.to be_empty
end
end
- context 'when there is a deployment record with running status' do
+ context "when there is a deployment record with running status" do
let(:deployment) { create(:deployment, :running, project: project) }
- it 'does not return the record' do
+ it "does not return the record" do
is_expected.to be_empty
end
end
- context 'when there is a deployment record with success status' do
+ context "when there is a deployment record with success status" do
let(:deployment) { create(:deployment, :success, project: project) }
- it 'returns the record' do
+ it "returns the record" do
is_expected.to eq([deployment])
end
end
end
- describe '#snippets_visible?' do
- it 'returns true when a logged in user can read snippets' do
+ describe "#snippets_visible?" do
+ it "returns true when a logged in user can read snippets" do
project = create(:project, :public)
user = create(:user)
expect(project.snippets_visible?(user)).to eq(true)
end
- it 'returns true when an anonymous user can read snippets' do
+ it "returns true when an anonymous user can read snippets" do
project = create(:project, :public)
expect(project.snippets_visible?).to eq(true)
end
- it 'returns false when a user can not read snippets' do
+ it "returns false when a user can not read snippets" do
project = create(:project, :private)
user = create(:user)
@@ -4488,28 +4490,28 @@ describe Project do
end
end
- describe '#all_clusters' do
+ describe "#all_clusters" do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, cluster_type: :project_type, projects: [project]) }
subject { project.all_clusters }
- it 'returns project level cluster' do
+ it "returns project level cluster" do
expect(subject).to eq([cluster])
end
- context 'project belongs to a group' do
+ context "project belongs to a group" do
let(:group_cluster) { create(:cluster, :group) }
let(:group) { group_cluster.group }
let(:project) { create(:project, group: group) }
- it 'returns clusters for groups of this project' do
+ it "returns clusters for groups of this project" do
expect(subject).to contain_exactly(cluster, group_cluster)
end
end
end
- describe '#object_pool_params' do
+ describe "#object_pool_params" do
let(:project) { create(:project, :repository, :public) }
subject { project.object_pool_params }
@@ -4518,24 +4520,24 @@ describe Project do
stub_application_setting(hashed_storage_enabled: true)
end
- context 'when the objects cannot be pooled' do
+ context "when the objects cannot be pooled" do
let(:project) { create(:project, :repository, :private) }
it { is_expected.to be_empty }
end
- context 'when a pool is created' do
- it 'returns that pool repository' do
+ context "when a pool is created" do
+ it "returns that pool repository" do
expect(subject).not_to be_empty
expect(subject[:pool_repository]).to be_persisted
end
end
end
- describe '#git_objects_poolable?' do
+ describe "#git_objects_poolable?" do
subject { project }
- context 'when the feature flag is turned off' do
+ context "when the feature flag is turned off" do
before do
stub_feature_flags(object_pools: false)
end
@@ -4545,20 +4547,20 @@ describe Project do
it { is_expected.not_to be_git_objects_poolable }
end
- context 'when the feature flag is enabled' do
- context 'when not using hashed storage' do
+ context "when the feature flag is enabled" do
+ context "when not using hashed storage" do
let(:project) { create(:project, :legacy_storage, :public, :repository) }
it { is_expected.not_to be_git_objects_poolable }
end
- context 'when the project is not public' do
+ context "when the project is not public" do
let(:project) { create(:project, :private) }
it { is_expected.not_to be_git_objects_poolable }
end
- context 'when objects are poolable' do
+ context "when objects are poolable" do
let(:project) { create(:project, :repository, :public) }
before do
@@ -4570,20 +4572,20 @@ describe Project do
end
end
- describe '#leave_pool_repository' do
+ describe "#leave_pool_repository" do
let(:pool) { create(:pool_repository) }
let(:project) { create(:project, :repository, pool_repository: pool) }
- it 'removes the membership' do
+ it "removes the membership" do
project.leave_pool_repository
expect(pool.member_projects.reload).not_to include(project)
end
end
- describe '#check_personal_projects_limit' do
- context 'when creating a project for a group' do
- it 'does nothing' do
+ describe "#check_personal_projects_limit" do
+ context "when creating a project for a group" do
+ it "does nothing" do
creator = build(:user)
project = build(:project, namespace: build(:group), creator: creator)
@@ -4597,7 +4599,7 @@ describe Project do
end
end
- context 'when the user is not allowed to create a personal project' do
+ context "when the user is not allowed to create a personal project" do
let(:user) { build(:user) }
let(:project) { build(:project, creator: user) }
@@ -4607,8 +4609,8 @@ describe Project do
.and_return(false)
end
- context 'when the project limit is zero' do
- it 'adds a validation error' do
+ context "when the project limit is zero" do
+ it "adds a validation error" do
allow(user)
.to receive(:projects_limit)
.and_return(0)
@@ -4620,8 +4622,8 @@ describe Project do
end
end
- context 'when the project limit is greater than zero' do
- it 'adds a validation error' do
+ context "when the project limit is greater than zero" do
+ it "adds a validation error" do
allow(user)
.to receive(:projects_limit)
.and_return(5)
@@ -4634,8 +4636,8 @@ describe Project do
end
end
- context 'when the user is allowed to create personal projects' do
- it 'does nothing' do
+ context "when the user is allowed to create personal projects" do
+ it "does nothing" do
user = build(:user)
project = build(:project, creator: user)
@@ -4650,14 +4652,14 @@ describe Project do
end
end
- describe '#has_pool_repsitory?' do
- it 'returns false when it does not have a pool repository' do
+ describe "#has_pool_repsitory?" do
+ it "returns false when it does not have a pool repository" do
subject = create(:project, :repository)
expect(subject.has_pool_repository?).to be false
end
- it 'returns true when it has a pool repository' do
+ it "returns true when it has a pool repository" do
pool = create(:pool_repository, :ready)
subject = create(:project, :repository, pool_repository: pool)
@@ -4669,17 +4671,17 @@ describe Project do
rugged_repo(project.repository).config
end
- def create_pipeline(project, status = 'success')
+ def create_pipeline(project, status = "success")
create(:ci_pipeline, project: project,
sha: project.commit.sha,
ref: project.default_branch,
status: status)
end
- def create_build(new_pipeline = pipeline, name = 'test')
+ def create_build(new_pipeline = pipeline, name = "test")
create(:ci_build, :success, :artifacts,
- pipeline: new_pipeline,
- status: new_pipeline.status,
- name: name)
+ pipeline: new_pipeline,
+ status: new_pipeline.status,
+ name: name)
end
end
diff --git a/spec/models/project_statistics_spec.rb b/spec/models/project_statistics_spec.rb
index 64c39f09e33..d3dc62e53fa 100644
--- a/spec/models/project_statistics_spec.rb
+++ b/spec/models/project_statistics_spec.rb
@@ -1,15 +1,15 @@
-require 'rails_helper'
+require "rails_helper"
describe ProjectStatistics do
let(:project) { create :project }
let(:statistics) { project.statistics }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:namespace) }
end
- describe 'statistics columns' do
+ describe "statistics columns" do
it "support values up to 8 exabytes" do
statistics.update!(
commit_count: 8.exabytes - 1,
@@ -28,7 +28,7 @@ describe ProjectStatistics do
end
end
- describe '#total_repository_size' do
+ describe "#total_repository_size" do
it "sums repository and LFS object size" do
statistics.repository_size = 2
statistics.lfs_objects_size = 3
@@ -38,7 +38,7 @@ describe ProjectStatistics do
end
end
- describe '#refresh!' do
+ describe "#refresh!" do
before do
allow(statistics).to receive(:update_commit_count)
allow(statistics).to receive(:update_repository_size)
@@ -71,7 +71,7 @@ describe ProjectStatistics do
end
end
- describe '#update_commit_count' do
+ describe "#update_commit_count" do
before do
allow(project.repository).to receive(:commit_count).and_return(23)
statistics.update_commit_count
@@ -82,7 +82,7 @@ describe ProjectStatistics do
end
end
- describe '#update_repository_size' do
+ describe "#update_repository_size" do
before do
allow(project.repository).to receive(:size).and_return(12)
statistics.update_repository_size
@@ -93,7 +93,7 @@ describe ProjectStatistics do
end
end
- describe '#update_lfs_objects_size' do
+ describe "#update_lfs_objects_size" do
let!(:lfs_object1) { create(:lfs_object, size: 23.megabytes) }
let!(:lfs_object2) { create(:lfs_object, size: 34.megabytes) }
let!(:lfs_objects_project1) { create(:lfs_objects_project, project: project, lfs_object: lfs_object1) }
@@ -108,7 +108,7 @@ describe ProjectStatistics do
end
end
- describe '#update_storage_size' do
+ describe "#update_storage_size" do
it "sums all storage counters" do
statistics.update!(
repository_size: 2,
@@ -121,29 +121,29 @@ describe ProjectStatistics do
end
end
- describe '.increment_statistic' do
- it 'increases the statistic by that amount' do
+ describe ".increment_statistic" do
+ it "increases the statistic by that amount" do
expect { described_class.increment_statistic(project.id, :build_artifacts_size, 13) }
.to change { statistics.reload.build_artifacts_size }
.by(13)
end
- it 'increases also storage size by that amount' do
+ it "increases also storage size by that amount" do
expect { described_class.increment_statistic(project.id, :build_artifacts_size, 20) }
.to change { statistics.reload.storage_size }
.by(20)
end
- context 'when the amount is 0' do
- it 'does not execute a query' do
+ context "when the amount is 0" do
+ it "does not execute a query" do
project
expect { described_class.increment_statistic(project.id, :build_artifacts_size, 0) }
.not_to exceed_query_limit(0)
end
end
- context 'when using an invalid column' do
- it 'raises an error' do
+ context "when using an invalid column" do
+ it "raises an error" do
expect { described_class.increment_statistic(project.id, :id, 13) }
.to raise_error(ArgumentError, "Cannot increment attribute: id")
end
diff --git a/spec/models/project_team_spec.rb b/spec/models/project_team_spec.rb
index 3537dead5d1..97034c5e238 100644
--- a/spec/models/project_team_spec.rb
+++ b/spec/models/project_team_spec.rb
@@ -6,7 +6,7 @@ describe ProjectTeam do
let(:guest) { create(:user) }
let(:nonmember) { create(:user) }
- context 'personal project' do
+ context "personal project" do
let(:project) { create(:project) }
before do
@@ -15,14 +15,14 @@ describe ProjectTeam do
project.add_guest(guest)
end
- describe 'members collection' do
+ describe "members collection" do
it { expect(project.team.maintainers).to include(maintainer) }
it { expect(project.team.maintainers).not_to include(guest) }
it { expect(project.team.maintainers).not_to include(reporter) }
it { expect(project.team.maintainers).not_to include(nonmember) }
end
- describe 'access methods' do
+ describe "access methods" do
it { expect(project.team.maintainer?(maintainer)).to be_truthy }
it { expect(project.team.maintainer?(guest)).to be_falsey }
it { expect(project.team.maintainer?(reporter)).to be_falsey }
@@ -35,7 +35,7 @@ describe ProjectTeam do
end
end
- context 'group project' do
+ context "group project" do
let(:group) { create(:group) }
let!(:project) { create(:project, group: group) }
@@ -51,7 +51,7 @@ describe ProjectTeam do
project.add_guest(maintainer)
end
- describe 'members collection' do
+ describe "members collection" do
it { expect(project.team.reporters).to include(reporter) }
it { expect(project.team.maintainers).to include(maintainer) }
it { expect(project.team.maintainers).to include(guest) }
@@ -59,7 +59,7 @@ describe ProjectTeam do
it { expect(project.team.maintainers).not_to include(nonmember) }
end
- describe 'access methods' do
+ describe "access methods" do
it { expect(project.team.reporter?(reporter)).to be_truthy }
it { expect(project.team.maintainer?(maintainer)).to be_truthy }
it { expect(project.team.maintainer?(guest)).to be_truthy }
@@ -73,18 +73,18 @@ describe ProjectTeam do
end
end
- describe '#fetch_members' do
- context 'personal project' do
+ describe "#fetch_members" do
+ context "personal project" do
let(:project) { create(:project) }
- it 'returns project members' do
+ it "returns project members" do
user = create(:user)
project.add_guest(user)
expect(project.team.members).to contain_exactly(user, project.owner)
end
- it 'returns project members of a specified level' do
+ it "returns project members of a specified level" do
user = create(:user)
project.add_reporter(user)
@@ -92,7 +92,7 @@ describe ProjectTeam do
expect(project.team.reporters).to contain_exactly(user)
end
- it 'returns invited members of a group' do
+ it "returns invited members of a group" do
group_member = create(:group_member)
project.project_group_links.create!(
@@ -104,7 +104,7 @@ describe ProjectTeam do
.to contain_exactly(group_member.user, project.owner)
end
- it 'returns invited members of a group of a specified level' do
+ it "returns invited members of a group of a specified level" do
group_member = create(:group_member)
project.project_group_links.create!(
@@ -117,17 +117,17 @@ describe ProjectTeam do
end
end
- context 'group project' do
+ context "group project" do
let(:group) { create(:group) }
let!(:project) { create(:project, group: group) }
- it 'returns project members' do
+ it "returns project members" do
group_member = create(:group_member, group: group)
expect(project.team.members).to contain_exactly(group_member.user)
end
- it 'returns project members of a specified level' do
+ it "returns project members of a specified level" do
group_member = create(:group_member, :reporter, group: group)
expect(project.team.guests).to be_empty
@@ -136,8 +136,8 @@ describe ProjectTeam do
end
end
- describe '#find_member' do
- context 'personal project' do
+ describe "#find_member" do
+ context "personal project" do
let(:project) do
create(:project, :public, :access_requestable)
end
@@ -158,7 +158,7 @@ describe ProjectTeam do
it { expect(project.team.find_member(requester.id)).to be_nil }
end
- context 'group project' do
+ context "group project" do
let(:group) { create(:group, :access_requestable) }
let(:project) { create(:project, group: group) }
let(:requester) { create(:user) }
@@ -178,9 +178,9 @@ describe ProjectTeam do
end
end
- describe '#members_in_project_and_ancestors' do
- context 'group project' do
- it 'filters out users who are not members of the project' do
+ describe "#members_in_project_and_ancestors" do
+ context "group project" do
+ it "filters out users who are not members of the project" do
group = create(:group)
project = create(:project, group: group)
group_member = create(:group_member, group: group)
@@ -194,36 +194,36 @@ describe ProjectTeam do
end
describe "#human_max_access" do
- it 'returns Maintainer role' do
+ it "returns Maintainer role" do
user = create(:user)
group = create(:group)
project = create(:project, namespace: group)
group.add_maintainer(user)
- expect(project.team.human_max_access(user.id)).to eq 'Maintainer'
+ expect(project.team.human_max_access(user.id)).to eq "Maintainer"
end
- it 'returns Owner role' do
+ it "returns Owner role" do
user = create(:user)
group = create(:group)
project = create(:project, namespace: group)
group.add_owner(user)
- expect(project.team.human_max_access(user.id)).to eq 'Owner'
+ expect(project.team.human_max_access(user.id)).to eq "Owner"
end
end
- describe '#max_member_access' do
+ describe "#max_member_access" do
let(:requester) { create(:user) }
- context 'personal project' do
+ context "personal project" do
let(:project) do
create(:project, :public, :access_requestable)
end
- context 'when project is not shared with group' do
+ context "when project is not shared with group" do
before do
project.add_maintainer(maintainer)
project.add_reporter(reporter)
@@ -238,12 +238,13 @@ describe ProjectTeam do
it { expect(project.team.max_member_access(requester.id)).to eq(Gitlab::Access::NO_ACCESS) }
end
- context 'when project is shared with group' do
+ context "when project is shared with group" do
before do
group = create(:group)
project.project_group_links.create(
group: group,
- group_access: Gitlab::Access::DEVELOPER)
+ group_access: Gitlab::Access::DEVELOPER
+ )
group.add_maintainer(maintainer)
group.add_reporter(reporter)
@@ -254,7 +255,7 @@ describe ProjectTeam do
it { expect(project.team.max_member_access(nonmember.id)).to eq(Gitlab::Access::NO_ACCESS) }
it { expect(project.team.max_member_access(requester.id)).to eq(Gitlab::Access::NO_ACCESS) }
- context 'but share_with_group_lock is true' do
+ context "but share_with_group_lock is true" do
before do
project.namespace.update(share_with_group_lock: true)
end
@@ -265,7 +266,7 @@ describe ProjectTeam do
end
end
- context 'group project' do
+ context "group project" do
let(:group) { create(:group, :access_requestable) }
let!(:project) do
create(:project, group: group)
@@ -286,7 +287,7 @@ describe ProjectTeam do
end
end
- describe '#member?' do
+ describe "#member?" do
let(:group) { create(:group) }
let(:developer) { create(:user) }
let(:maintainer) { create(:user) }
@@ -312,27 +313,27 @@ describe ProjectTeam do
create(:project_group_link, project: shared_project, group: group)
end
- it 'returns false for no user' do
+ it "returns false for no user" do
expect(personal_project.team.member?(nil)).to be(false)
end
- it 'returns true for personal projects of the user' do
+ it "returns true for personal projects of the user" do
expect(personal_project.team.member?(developer)).to be(true)
end
- it 'returns true for projects of groups the user is a member of' do
+ it "returns true for projects of groups the user is a member of" do
expect(group_project.team.member?(developer)).to be(true)
end
- it 'returns true for projects for which the user is a member of' do
+ it "returns true for projects for which the user is a member of" do
expect(members_project.team.member?(developer)).to be(true)
end
- it 'returns true for projects shared on a group the user is a member of' do
+ it "returns true for projects shared on a group the user is a member of" do
expect(shared_project.team.member?(developer)).to be(true)
end
- it 'checks for the correct minimum level access' do
+ it "checks for the correct minimum level access" do
expect(group_project.team.member?(developer, Gitlab::Access::MAINTAINER)).to be(false)
expect(group_project.team.member?(maintainer, Gitlab::Access::MAINTAINER)).to be(true)
expect(members_project.team.member?(developer, Gitlab::Access::MAINTAINER)).to be(false)
@@ -344,7 +345,7 @@ describe ProjectTeam do
end
end
- shared_examples 'max member access for users' do
+ shared_examples "max member access for users" do
let(:project) { create(:project) }
let(:group) { create(:group) }
let(:second_group) { create(:group) }
@@ -373,7 +374,7 @@ describe ProjectTeam do
guest.id => Gitlab::Access::GUEST,
group_developer.id => Gitlab::Access::DEVELOPER,
second_developer.id => Gitlab::Access::MAINTAINER,
- user_without_access.id => Gitlab::Access::NO_ACCESS
+ user_without_access.id => Gitlab::Access::NO_ACCESS,
}
end
@@ -400,20 +401,20 @@ describe ProjectTeam do
second_group.add_maintainer(second_developer)
end
- it 'returns correct roles for different users' do
+ it "returns correct roles for different users" do
expect(project.team.max_member_access_for_user_ids(users)).to eq(expected)
end
end
- describe '#max_member_access_for_user_ids' do
- context 'with RequestStore enabled', :request_store do
- include_examples 'max member access for users'
+ describe "#max_member_access_for_user_ids" do
+ context "with RequestStore enabled", :request_store do
+ include_examples "max member access for users"
def access_levels(users)
project.team.max_member_access_for_user_ids(users)
end
- it 'does not perform extra queries when asked for users who have already been found' do
+ it "does not perform extra queries when asked for users who have already been found" do
access_levels(users)
expect { access_levels(users) }.not_to exceed_query_limit(0)
@@ -421,7 +422,7 @@ describe ProjectTeam do
expect(access_levels(users)).to eq(expected)
end
- it 'only requests the extra users when uncached users are passed' do
+ it "only requests the extra users when uncached users are passed" do
new_user = create(:user)
second_new_user = create(:user)
all_users = users + [new_user.id, second_new_user.id]
@@ -441,8 +442,8 @@ describe ProjectTeam do
end
end
- context 'with RequestStore disabled' do
- include_examples 'max member access for users'
+ context "with RequestStore disabled" do
+ include_examples "max member access for users"
end
end
end
diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb
index 3ccc706edf2..ac697be636b 100644
--- a/spec/models/project_wiki_spec.rb
+++ b/spec/models/project_wiki_spec.rb
@@ -1,4 +1,3 @@
-# coding: utf-8
require "spec_helper"
describe ProjectWiki do
@@ -7,7 +6,7 @@ describe ProjectWiki do
let(:repository) { project.repository }
let(:gitlab_shell) { Gitlab::Shell.new }
let(:project_wiki) { described_class.new(project, user) }
- let(:raw_repository) { Gitlab::Git::Repository.new(project.repository_storage, subject.disk_path + '.git', 'foo', 'group/project.wiki') }
+ let(:raw_repository) { Gitlab::Git::Repository.new(project.repository_storage, subject.disk_path + ".git", "foo", "group/project.wiki") }
let(:commit) { project_wiki.repository.head_commit }
subject { project_wiki }
@@ -17,16 +16,16 @@ describe ProjectWiki do
describe "#full_path" do
it "returns the project path with namespace with the .wiki extension" do
- expect(subject.full_path).to eq(project.full_path + '.wiki')
+ expect(subject.full_path).to eq(project.full_path + ".wiki")
end
- it 'returns the same value as #full_path' do
+ it "returns the same value as #full_path" do
expect(subject.full_path).to eq(subject.full_path)
end
end
- describe '#web_url' do
- it 'returns the full web URL to the wiki' do
+ describe "#web_url" do
+ it "returns the full web URL to the wiki" do
expect(subject.web_url).to eq("#{Gitlab.config.gitlab.url}/#{project.full_path}/wikis/home")
end
end
@@ -46,11 +45,11 @@ describe ProjectWiki do
describe "#http_url_to_repo" do
let(:project) { create :project }
- it 'returns the full http url to the repo' do
+ it "returns the full http url to the repo" do
expected_url = "#{Gitlab.config.gitlab.url}/#{subject.full_path}.git"
expect(project_wiki.http_url_to_repo).to eq(expected_url)
- expect(project_wiki.http_url_to_repo).not_to include('@')
+ expect(project_wiki.http_url_to_repo).not_to include("@")
end
end
@@ -84,7 +83,7 @@ describe ProjectWiki do
describe "#empty?" do
context "when the wiki repository is empty" do
- describe '#empty?' do
+ describe "#empty?" do
subject { super().empty? }
it { is_expected.to be_truthy }
end
@@ -96,12 +95,12 @@ describe ProjectWiki do
project_wiki.create_page("another-page", "This is another page")
end
- describe '#empty?' do
+ describe "#empty?" do
subject { super().empty? }
it { is_expected.to be_falsey }
# Re-enable this when https://gitlab.com/gitlab-org/gitaly/issues/1204 is fixed
- xit 'only instantiates a Wiki page once' do
+ xit "only instantiates a Wiki page once" do
expect(WikiPage).to receive(:new).once.and_call_original
subject
@@ -157,7 +156,7 @@ describe ProjectWiki do
expect(page).to be_a WikiPage
end
- context 'pages with multibyte-character title' do
+ context "pages with multibyte-character title" do
before do
create_page("autre pagé", "C'est un génial Gollum Wiki")
end
@@ -168,7 +167,7 @@ describe ProjectWiki do
end
end
- context 'pages with invalidly-encoded content' do
+ context "pages with invalidly-encoded content" do
before do
create_page("encoding is fun", "f\xFCr".b)
end
@@ -180,51 +179,51 @@ describe ProjectWiki do
end
end
- describe '#find_sidebar' do
+ describe "#find_sidebar" do
before do
- create_page(described_class::SIDEBAR, 'This is an awesome Sidebar')
+ create_page(described_class::SIDEBAR, "This is an awesome Sidebar")
end
after do
subject.pages.each { |page| destroy_page(page.page) }
end
- it 'finds the page defined as _sidebar' do
- page = subject.find_page('_sidebar')
+ it "finds the page defined as _sidebar" do
+ page = subject.find_page("_sidebar")
- expect(page.content).to eq('This is an awesome Sidebar')
+ expect(page.content).to eq("This is an awesome Sidebar")
end
end
- describe '#find_file' do
- let(:image) { File.open(Rails.root.join('spec', 'fixtures', 'big-image.png')) }
+ describe "#find_file" do
+ let(:image) { File.open(Rails.root.join("spec", "fixtures", "big-image.png")) }
before do
subject.wiki # Make sure the wiki repo exists
- repo_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ repo_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access {
subject.repository.path_to_repo
- end
+ }
- BareRepoOperations.new(repo_path).commit_file(image, 'image.png')
+ BareRepoOperations.new(repo_path).commit_file(image, "image.png")
end
- it 'returns the latest version of the file if it exists' do
- file = subject.find_file('image.png')
- expect(file.mime_type).to eq('image/png')
+ it "returns the latest version of the file if it exists" do
+ file = subject.find_file("image.png")
+ expect(file.mime_type).to eq("image/png")
end
- it 'returns nil if the page does not exist' do
- expect(subject.find_file('non-existent')).to eq(nil)
+ it "returns nil if the page does not exist" do
+ expect(subject.find_file("non-existent")).to eq(nil)
end
- it 'returns a Gitlab::Git::WikiFile instance' do
- file = subject.find_file('image.png')
+ it "returns a Gitlab::Git::WikiFile instance" do
+ file = subject.find_file("image.png")
expect(file).to be_a Gitlab::Git::WikiFile
end
- it 'returns the whole file' do
- file = subject.find_file('image.png')
+ it "returns the whole file" do
+ file = subject.find_file("image.png")
image.rewind
expect(file.raw_data.b).to eq(image.read.b)
@@ -256,16 +255,16 @@ describe ProjectWiki do
expect(subject.pages.first.page.version.message).to eq("commit message")
end
- it 'sets the correct commit email' do
- subject.create_page('test page', 'content')
+ it "sets the correct commit email" do
+ subject.create_page("test page", "content")
expect(user.commit_email).not_to eq(user.email)
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
- it 'updates project activity' do
- subject.create_page('Test Page', 'This is content')
+ it "updates project activity" do
+ subject.create_page("Test Page", "This is content")
project.reload
@@ -299,18 +298,18 @@ describe ProjectWiki do
expect(@page.version.message).to eq("updated page")
end
- it 'sets the correct commit email' do
+ it "sets the correct commit email" do
expect(user.commit_email).not_to eq(user.email)
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
- it 'updates project activity' do
+ it "updates project activity" do
subject.update_page(
@gitlab_git_wiki_page,
- content: 'Yet more content',
+ content: "Yet more content",
format: :markdown,
- message: 'Updated page again'
+ message: "Updated page again"
)
project.reload
@@ -331,7 +330,7 @@ describe ProjectWiki do
expect(subject.pages.count).to eq(0)
end
- it 'sets the correct commit email' do
+ it "sets the correct commit email" do
subject.delete_page(@page)
expect(user.commit_email).not_to eq(user.email)
@@ -339,7 +338,7 @@ describe ProjectWiki do
expect(commit.committer_email).to eq(user.commit_email)
end
- it 'updates project activity' do
+ it "updates project activity" do
subject.delete_page(@page)
project.reload
@@ -349,10 +348,10 @@ describe ProjectWiki do
end
end
- describe '#create_repo!' do
+ describe "#create_repo!" do
let(:project) { create(:project) }
- it 'creates a repository' do
+ it "creates a repository" do
expect(raw_repository.exists?).to eq(false)
expect(subject.repository).to receive(:after_create)
@@ -362,10 +361,10 @@ describe ProjectWiki do
end
end
- describe '#ensure_repository' do
+ describe "#ensure_repository" do
let(:project) { create(:project) }
- it 'creates the repository if it not exist' do
+ it "creates the repository if it not exist" do
expect(raw_repository.exists?).to eq(false)
expect(subject).to receive(:create_repo!).and_call_original
@@ -374,7 +373,7 @@ describe ProjectWiki do
expect(raw_repository.exists?).to eq(true)
end
- it 'does not create the repository if it exists' do
+ it "does not create the repository if it exists" do
subject.wiki
expect(raw_repository.exists?).to eq(true)
@@ -384,8 +383,8 @@ describe ProjectWiki do
end
end
- describe '#hook_attrs' do
- it 'returns a hash with values' do
+ describe "#hook_attrs" do
+ it "returns a hash with values" do
expect(subject.hook_attrs).to be_a Hash
expect(subject.hook_attrs.keys).to contain_exactly(:web_url, :git_ssh_url, :git_http_url, :path_with_namespace, :default_branch)
end
@@ -395,7 +394,7 @@ describe ProjectWiki do
def create_temp_repo(path)
FileUtils.mkdir_p path
- system(*%W(#{Gitlab.config.git.bin_path} init --quiet --bare -- #{path}))
+ system(Gitlab.config.git.bin_path.to_s, "init", "--quiet", "--bare", "--", path.to_s)
end
def remove_temp_repo(path)
diff --git a/spec/models/prometheus_metric_spec.rb b/spec/models/prometheus_metric_spec.rb
index 3610408c138..08d1c761f39 100644
--- a/spec/models/prometheus_metric_spec.rb
+++ b/spec/models/prometheus_metric_spec.rb
@@ -1,18 +1,18 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe PrometheusMetric do
subject { build(:prometheus_metric) }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
it { is_expected.to belong_to(:project) }
it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_presence_of(:query) }
it { is_expected.to validate_presence_of(:group) }
- describe 'common metrics' do
+ describe "common metrics" do
using RSpec::Parameterized::TableSyntax
where(:common, :with_project, :result) do
@@ -32,12 +32,12 @@ describe PrometheusMetric do
end
end
- describe '#query_series' do
+ describe "#query_series" do
using RSpec::Parameterized::TableSyntax
where(:legend, :type) do
- 'Some other legend' | NilClass
- 'Status Code' | Array
+ "Some other legend" | NilClass
+ "Status Code" | Array
end
with_them do
@@ -49,8 +49,8 @@ describe PrometheusMetric do
end
end
- describe '#group_title' do
- shared_examples 'group_title' do |group, title|
+ describe "#group_title" do
+ shared_examples "group_title" do |group, title|
subject { build(:prometheus_metric, group: group).group_title }
it "returns text #{title} for group #{group}" do
@@ -58,18 +58,18 @@ describe PrometheusMetric do
end
end
- it_behaves_like 'group_title', :nginx_ingress_vts, 'Response metrics (NGINX Ingress VTS)'
- it_behaves_like 'group_title', :nginx_ingress, 'Response metrics (NGINX Ingress)'
- it_behaves_like 'group_title', :ha_proxy, 'Response metrics (HA Proxy)'
- it_behaves_like 'group_title', :aws_elb, 'Response metrics (AWS ELB)'
- it_behaves_like 'group_title', :nginx, 'Response metrics (NGINX)'
- it_behaves_like 'group_title', :kubernetes, 'System metrics (Kubernetes)'
- it_behaves_like 'group_title', :business, 'Business metrics (Custom)'
- it_behaves_like 'group_title', :response, 'Response metrics (Custom)'
- it_behaves_like 'group_title', :system, 'System metrics (Custom)'
+ it_behaves_like "group_title", :nginx_ingress_vts, "Response metrics (NGINX Ingress VTS)"
+ it_behaves_like "group_title", :nginx_ingress, "Response metrics (NGINX Ingress)"
+ it_behaves_like "group_title", :ha_proxy, "Response metrics (HA Proxy)"
+ it_behaves_like "group_title", :aws_elb, "Response metrics (AWS ELB)"
+ it_behaves_like "group_title", :nginx, "Response metrics (NGINX)"
+ it_behaves_like "group_title", :kubernetes, "System metrics (Kubernetes)"
+ it_behaves_like "group_title", :business, "Business metrics (Custom)"
+ it_behaves_like "group_title", :response, "Response metrics (Custom)"
+ it_behaves_like "group_title", :system, "System metrics (Custom)"
end
- describe '#priority' do
+ describe "#priority" do
using RSpec::Parameterized::TableSyntax
where(:group, :priority) do
@@ -93,19 +93,19 @@ describe PrometheusMetric do
end
end
- describe '#required_metrics' do
+ describe "#required_metrics" do
using RSpec::Parameterized::TableSyntax
where(:group, :required_metrics) do
- :nginx_ingress_vts | %w(nginx_upstream_responses_total nginx_upstream_response_msecs_avg)
- :nginx_ingress | %w(nginx_ingress_controller_requests nginx_ingress_controller_ingress_upstream_latency_seconds_sum)
- :ha_proxy | %w(haproxy_frontend_http_requests_total haproxy_frontend_http_responses_total)
- :aws_elb | %w(aws_elb_request_count_sum aws_elb_latency_average aws_elb_httpcode_backend_5_xx_sum)
- :nginx | %w(nginx_server_requests nginx_server_requestMsec)
- :kubernetes | %w(container_memory_usage_bytes container_cpu_usage_seconds_total)
- :business | %w()
- :response | %w()
- :system | %w()
+ :nginx_ingress_vts | %w[nginx_upstream_responses_total nginx_upstream_response_msecs_avg]
+ :nginx_ingress | %w[nginx_ingress_controller_requests nginx_ingress_controller_ingress_upstream_latency_seconds_sum]
+ :ha_proxy | %w[haproxy_frontend_http_requests_total haproxy_frontend_http_responses_total]
+ :aws_elb | %w[aws_elb_request_count_sum aws_elb_latency_average aws_elb_httpcode_backend_5_xx_sum]
+ :nginx | %w[nginx_server_requests nginx_server_requestMsec]
+ :kubernetes | %w[container_memory_usage_bytes container_cpu_usage_seconds_total]
+ :business | %w[]
+ :response | %w[]
+ :system | %w[]
end
with_them do
@@ -117,34 +117,34 @@ describe PrometheusMetric do
end
end
- describe '#to_query_metric' do
- it 'converts to queryable metric object' do
+ describe "#to_query_metric" do
+ it "converts to queryable metric object" do
expect(subject.to_query_metric).to be_instance_of(Gitlab::Prometheus::Metric)
end
- it 'queryable metric object has title' do
+ it "queryable metric object has title" do
expect(subject.to_query_metric.title).to eq(subject.title)
end
- it 'queryable metric object has y_label' do
+ it "queryable metric object has y_label" do
expect(subject.to_query_metric.y_label).to eq(subject.y_label)
end
- it 'queryable metric has no required_metric' do
+ it "queryable metric has no required_metric" do
expect(subject.to_query_metric.required_metrics).to eq([])
end
- it 'queryable metric has weight 0' do
+ it "queryable metric has weight 0" do
expect(subject.to_query_metric.weight).to eq(0)
end
- it 'queryable metrics has query description' do
+ it "queryable metrics has query description" do
queries = [
{
query_range: subject.query,
unit: subject.unit,
- label: subject.legend
- }
+ label: subject.legend,
+ },
]
expect(subject.to_query_metric.queries).to eq(queries)
diff --git a/spec/models/protectable_dropdown_spec.rb b/spec/models/protectable_dropdown_spec.rb
index d4433a88a15..a498366638b 100644
--- a/spec/models/protectable_dropdown_spec.rb
+++ b/spec/models/protectable_dropdown_spec.rb
@@ -1,32 +1,32 @@
-require 'spec_helper'
+require "spec_helper"
describe ProtectableDropdown do
let(:project) { create(:project, :repository) }
let(:subject) { described_class.new(project, :branches) }
- describe 'initialize' do
- it 'raises ArgumentError for invalid ref type' do
+ describe "initialize" do
+ it "raises ArgumentError for invalid ref type" do
expect { described_class.new(double, :foo) }
.to raise_error(ArgumentError, "invalid ref type `foo`")
end
end
- describe '#protectable_ref_names' do
+ describe "#protectable_ref_names" do
before do
- project.protected_branches.create(name: 'master')
+ project.protected_branches.create(name: "master")
end
- it { expect(subject.protectable_ref_names).to include('feature') }
- it { expect(subject.protectable_ref_names).not_to include('master') }
+ it { expect(subject.protectable_ref_names).to include("feature") }
+ it { expect(subject.protectable_ref_names).not_to include("master") }
it "includes branches matching a protected branch wildcard" do
- expect(subject.protectable_ref_names).to include('feature')
+ expect(subject.protectable_ref_names).to include("feature")
- create(:protected_branch, name: 'feat*', project: project)
+ create(:protected_branch, name: "feat*", project: project)
subject = described_class.new(project.reload, :branches)
- expect(subject.protectable_ref_names).to include('feature')
+ expect(subject.protectable_ref_names).to include("feature")
end
end
end
diff --git a/spec/models/protected_branch/merge_access_level_spec.rb b/spec/models/protected_branch/merge_access_level_spec.rb
index 612e4a0e332..8ce021800b6 100644
--- a/spec/models/protected_branch/merge_access_level_spec.rb
+++ b/spec/models/protected_branch/merge_access_level_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ProtectedBranch::MergeAccessLevel do
it { is_expected.to validate_inclusion_of(:access_level).in_array([Gitlab::Access::MAINTAINER, Gitlab::Access::DEVELOPER, Gitlab::Access::NO_ACCESS]) }
diff --git a/spec/models/protected_branch/push_access_level_spec.rb b/spec/models/protected_branch/push_access_level_spec.rb
index 9ccdc22fd41..65af1b6fd44 100644
--- a/spec/models/protected_branch/push_access_level_spec.rb
+++ b/spec/models/protected_branch/push_access_level_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe ProtectedBranch::PushAccessLevel do
it { is_expected.to validate_inclusion_of(:access_level).in_array([Gitlab::Access::MAINTAINER, Gitlab::Access::DEVELOPER, Gitlab::Access::NO_ACCESS]) }
diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb
index 4c677200ae2..3efe1baf4f6 100644
--- a/spec/models/protected_branch_spec.rb
+++ b/spec/models/protected_branch_spec.rb
@@ -1,13 +1,13 @@
-require 'spec_helper'
+require "spec_helper"
describe ProtectedBranch do
subject { build_stubbed(:protected_branch) }
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to(:project) }
end
- describe 'Validation' do
+ describe "Validation" do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:name) }
end
@@ -135,58 +135,58 @@ describe ProtectedBranch do
end
end
- describe '#protected?' do
- context 'existing project' do
+ describe "#protected?" do
+ context "existing project" do
let(:project) { create(:project, :repository) }
- it 'returns true when the branch matches a protected branch via direct match' do
+ it "returns true when the branch matches a protected branch via direct match" do
create(:protected_branch, project: project, name: "foo")
- expect(described_class.protected?(project, 'foo')).to eq(true)
+ expect(described_class.protected?(project, "foo")).to eq(true)
end
- it 'returns true when the branch matches a protected branch via wildcard match' do
+ it "returns true when the branch matches a protected branch via wildcard match" do
create(:protected_branch, project: project, name: "production/*")
- expect(described_class.protected?(project, 'production/some-branch')).to eq(true)
+ expect(described_class.protected?(project, "production/some-branch")).to eq(true)
end
- it 'returns false when the branch does not match a protected branch via direct match' do
- expect(described_class.protected?(project, 'foo')).to eq(false)
+ it "returns false when the branch does not match a protected branch via direct match" do
+ expect(described_class.protected?(project, "foo")).to eq(false)
end
- it 'returns false when the branch does not match a protected branch via wildcard match' do
+ it "returns false when the branch does not match a protected branch via wildcard match" do
create(:protected_branch, project: project, name: "production/*")
- expect(described_class.protected?(project, 'staging/some-branch')).to eq(false)
+ expect(described_class.protected?(project, "staging/some-branch")).to eq(false)
end
end
context "new project" do
let(:project) { create(:project) }
- it 'returns false when default_protected_branch is unprotected' do
+ it "returns false when default_protected_branch is unprotected" do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_NONE)
- expect(described_class.protected?(project, 'master')).to be false
+ expect(described_class.protected?(project, "master")).to be false
end
- it 'returns false when default_protected_branch lets developers push' do
+ it "returns false when default_protected_branch lets developers push" do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_PUSH)
- expect(described_class.protected?(project, 'master')).to be false
+ expect(described_class.protected?(project, "master")).to be false
end
- it 'returns true when default_branch_protection does not let developers push but let developer merge branches' do
+ it "returns true when default_branch_protection does not let developers push but let developer merge branches" do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_MERGE)
- expect(described_class.protected?(project, 'master')).to be true
+ expect(described_class.protected?(project, "master")).to be true
end
- it 'returns true when default_branch_protection is in full protection' do
+ it "returns true when default_branch_protection is in full protection" do
stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_FULL)
- expect(described_class.protected?(project, 'master')).to be true
+ expect(described_class.protected?(project, "master")).to be true
end
end
end
diff --git a/spec/models/protected_tag_spec.rb b/spec/models/protected_tag_spec.rb
index e5a0f6ec23f..f88127904fb 100644
--- a/spec/models/protected_tag_spec.rb
+++ b/spec/models/protected_tag_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe ProtectedTag do
- describe 'Associations' do
+ describe "Associations" do
it { is_expected.to belong_to(:project) }
end
- describe 'Validation' do
+ describe "Validation" do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:name) }
end
diff --git a/spec/models/push_event_payload_spec.rb b/spec/models/push_event_payload_spec.rb
index 69a4922b6fd..29c1b226134 100644
--- a/spec/models/push_event_payload_spec.rb
+++ b/spec/models/push_event_payload_spec.rb
@@ -1,16 +1,16 @@
-require 'spec_helper'
+require "spec_helper"
describe PushEventPayload do
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe 'saving payloads' do
- it 'does not allow commit messages longer than 70 characters' do
+ describe "saving payloads" do
+ it "does not allow commit messages longer than 70 characters" do
event = create(:push_event)
payload = build(:push_event_payload, event: event)
expect(payload).to be_valid
- payload.commit_title = 'a' * 100
+ payload.commit_title = "a" * 100
expect(payload).not_to be_valid
end
diff --git a/spec/models/push_event_spec.rb b/spec/models/push_event_spec.rb
index bfe7a30b96a..65719bea80b 100644
--- a/spec/models/push_event_spec.rb
+++ b/spec/models/push_event_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe PushEvent do
let(:payload) { PushEventPayload.new }
@@ -11,7 +11,7 @@ describe PushEvent do
event
end
- describe '.created_or_pushed' do
+ describe ".created_or_pushed" do
let(:event1) { create(:push_event) }
let(:event2) { create(:push_event) }
let(:event3) { create(:push_event) }
@@ -24,20 +24,20 @@ describe PushEvent do
let(:relation) { described_class.created_or_pushed }
- it 'includes events for pushing to existing refs' do
+ it "includes events for pushing to existing refs" do
expect(relation).to include(event1)
end
- it 'includes events for creating new refs' do
+ it "includes events for creating new refs" do
expect(relation).to include(event2)
end
- it 'does not include events for removing refs' do
+ it "does not include events for removing refs" do
expect(relation).not_to include(event3)
end
end
- describe '.branch_events' do
+ describe ".branch_events" do
let(:event1) { create(:push_event) }
let(:event2) { create(:push_event) }
@@ -48,16 +48,16 @@ describe PushEvent do
let(:relation) { described_class.branch_events }
- it 'includes events for branches' do
+ it "includes events for branches" do
expect(relation).to include(event1)
end
- it 'does not include events for tags' do
+ it "does not include events for tags" do
expect(relation).not_to include(event2)
end
end
- describe '.without_existing_merge_requests' do
+ describe ".without_existing_merge_requests" do
let(:project) { create(:project, :repository) }
let(:event1) { create(:push_event, project: project) }
let(:event2) { create(:push_event, project: project) }
@@ -66,237 +66,237 @@ describe PushEvent do
let(:event5) { create(:push_event, project: project) }
before do
- create(:push_event_payload, event: event1, ref: 'foo', action: :created)
- create(:push_event_payload, event: event2, ref: 'bar', action: :created)
- create(:push_event_payload, event: event3, ref: 'qux', action: :created)
- create(:push_event_payload, event: event4, ref: 'baz', action: :removed)
- create(:push_event_payload, event: event5, ref: 'baz', ref_type: :tag)
+ create(:push_event_payload, event: event1, ref: "foo", action: :created)
+ create(:push_event_payload, event: event2, ref: "bar", action: :created)
+ create(:push_event_payload, event: event3, ref: "qux", action: :created)
+ create(:push_event_payload, event: event4, ref: "baz", action: :removed)
+ create(:push_event_payload, event: event5, ref: "baz", ref_type: :tag)
- project.repository.create_branch('bar', 'master')
+ project.repository.create_branch("bar", "master")
create(
:merge_request,
source_project: project,
target_project: project,
- source_branch: 'bar'
+ source_branch: "bar"
)
- project.repository.create_branch('qux', 'master')
+ project.repository.create_branch("qux", "master")
create(
:merge_request,
:closed,
source_project: project,
target_project: project,
- source_branch: 'qux'
+ source_branch: "qux"
)
end
let(:relation) { described_class.without_existing_merge_requests }
- it 'includes events that do not have a corresponding merge request' do
+ it "includes events that do not have a corresponding merge request" do
expect(relation).to include(event1)
end
- it 'does not include events that have a corresponding open merge request' do
+ it "does not include events that have a corresponding open merge request" do
expect(relation).not_to include(event2)
end
- it 'includes events that has corresponding closed/merged merge requests' do
+ it "includes events that has corresponding closed/merged merge requests" do
expect(relation).to include(event3)
end
- it 'does not include events for removed refs' do
+ it "does not include events for removed refs" do
expect(relation).not_to include(event4)
end
- it 'does not include events for pushing to tags' do
+ it "does not include events for pushing to tags" do
expect(relation).not_to include(event5)
end
end
- describe '.sti_name' do
- it 'returns Event::PUSHED' do
+ describe ".sti_name" do
+ it "returns Event::PUSHED" do
expect(described_class.sti_name).to eq(Event::PUSHED)
end
end
- describe '#push?' do
- it 'returns true' do
+ describe "#push?" do
+ it "returns true" do
expect(event).to be_push
end
end
- describe '#push_with_commits?' do
- it 'returns true when both the first and last commit are present' do
- allow(event).to receive(:commit_from).and_return('123')
- allow(event).to receive(:commit_to).and_return('456')
+ describe "#push_with_commits?" do
+ it "returns true when both the first and last commit are present" do
+ allow(event).to receive(:commit_from).and_return("123")
+ allow(event).to receive(:commit_to).and_return("456")
expect(event).to be_push_with_commits
end
- it 'returns false when the first commit is missing' do
- allow(event).to receive(:commit_to).and_return('456')
+ it "returns false when the first commit is missing" do
+ allow(event).to receive(:commit_to).and_return("456")
expect(event).not_to be_push_with_commits
end
- it 'returns false when the last commit is missing' do
- allow(event).to receive(:commit_from).and_return('123')
+ it "returns false when the last commit is missing" do
+ allow(event).to receive(:commit_from).and_return("123")
expect(event).not_to be_push_with_commits
end
end
- describe '#tag?' do
- it 'returns true when pushing to a tag' do
+ describe "#tag?" do
+ it "returns true when pushing to a tag" do
allow(payload).to receive(:tag?).and_return(true)
expect(event).to be_tag
end
- it 'returns false when pushing to a branch' do
+ it "returns false when pushing to a branch" do
allow(payload).to receive(:tag?).and_return(false)
expect(event).not_to be_tag
end
end
- describe '#branch?' do
- it 'returns true when pushing to a branch' do
+ describe "#branch?" do
+ it "returns true when pushing to a branch" do
allow(payload).to receive(:branch?).and_return(true)
expect(event).to be_branch
end
- it 'returns false when pushing to a tag' do
+ it "returns false when pushing to a tag" do
allow(payload).to receive(:branch?).and_return(false)
expect(event).not_to be_branch
end
end
- describe '#valid_push?' do
- it 'returns true if a ref exists' do
- allow(payload).to receive(:ref).and_return('master')
+ describe "#valid_push?" do
+ it "returns true if a ref exists" do
+ allow(payload).to receive(:ref).and_return("master")
expect(event).to be_valid_push
end
- it 'returns false when no ref is present' do
+ it "returns false when no ref is present" do
expect(event).not_to be_valid_push
end
end
- describe '#new_ref?' do
- it 'returns true when pushing a new ref' do
+ describe "#new_ref?" do
+ it "returns true when pushing a new ref" do
allow(payload).to receive(:created?).and_return(true)
expect(event).to be_new_ref
end
- it 'returns false when pushing to an existing ref' do
+ it "returns false when pushing to an existing ref" do
allow(payload).to receive(:created?).and_return(false)
expect(event).not_to be_new_ref
end
end
- describe '#rm_ref?' do
- it 'returns true when removing an existing ref' do
+ describe "#rm_ref?" do
+ it "returns true when removing an existing ref" do
allow(payload).to receive(:removed?).and_return(true)
expect(event).to be_rm_ref
end
- it 'returns false when pushing to an existing ref' do
+ it "returns false when pushing to an existing ref" do
allow(payload).to receive(:removed?).and_return(false)
expect(event).not_to be_rm_ref
end
end
- describe '#commit_from' do
- it 'returns the first commit SHA' do
- allow(payload).to receive(:commit_from).and_return('123')
+ describe "#commit_from" do
+ it "returns the first commit SHA" do
+ allow(payload).to receive(:commit_from).and_return("123")
- expect(event.commit_from).to eq('123')
+ expect(event.commit_from).to eq("123")
end
end
- describe '#commit_to' do
- it 'returns the last commit SHA' do
- allow(payload).to receive(:commit_to).and_return('123')
+ describe "#commit_to" do
+ it "returns the last commit SHA" do
+ allow(payload).to receive(:commit_to).and_return("123")
- expect(event.commit_to).to eq('123')
+ expect(event.commit_to).to eq("123")
end
end
- describe '#ref_name' do
- it 'returns the name of the ref' do
- allow(payload).to receive(:ref).and_return('master')
+ describe "#ref_name" do
+ it "returns the name of the ref" do
+ allow(payload).to receive(:ref).and_return("master")
- expect(event.ref_name).to eq('master')
+ expect(event.ref_name).to eq("master")
end
end
- describe '#ref_type' do
- it 'returns the type of the ref' do
- allow(payload).to receive(:ref_type).and_return('branch')
+ describe "#ref_type" do
+ it "returns the type of the ref" do
+ allow(payload).to receive(:ref_type).and_return("branch")
- expect(event.ref_type).to eq('branch')
+ expect(event.ref_type).to eq("branch")
end
end
- describe '#branch_name' do
- it 'returns the name of the branch' do
- allow(payload).to receive(:ref).and_return('master')
+ describe "#branch_name" do
+ it "returns the name of the branch" do
+ allow(payload).to receive(:ref).and_return("master")
- expect(event.branch_name).to eq('master')
+ expect(event.branch_name).to eq("master")
end
end
- describe '#tag_name' do
- it 'returns the name of the tag' do
- allow(payload).to receive(:ref).and_return('1.2')
+ describe "#tag_name" do
+ it "returns the name of the tag" do
+ allow(payload).to receive(:ref).and_return("1.2")
- expect(event.tag_name).to eq('1.2')
+ expect(event.tag_name).to eq("1.2")
end
end
- describe '#commit_title' do
- it 'returns the commit message' do
- allow(payload).to receive(:commit_title).and_return('foo')
+ describe "#commit_title" do
+ it "returns the commit message" do
+ allow(payload).to receive(:commit_title).and_return("foo")
- expect(event.commit_title).to eq('foo')
+ expect(event.commit_title).to eq("foo")
end
end
- describe '#commit_id' do
- it 'returns the SHA of the last commit if present' do
- allow(event).to receive(:commit_to).and_return('123')
+ describe "#commit_id" do
+ it "returns the SHA of the last commit if present" do
+ allow(event).to receive(:commit_to).and_return("123")
- expect(event.commit_id).to eq('123')
+ expect(event.commit_id).to eq("123")
end
- it 'returns the SHA of the first commit if the last commit is not present' do
+ it "returns the SHA of the first commit if the last commit is not present" do
allow(event).to receive(:commit_to).and_return(nil)
- allow(event).to receive(:commit_from).and_return('123')
+ allow(event).to receive(:commit_from).and_return("123")
- expect(event.commit_id).to eq('123')
+ expect(event.commit_id).to eq("123")
end
end
- describe '#commits_count' do
- it 'returns the number of commits' do
+ describe "#commits_count" do
+ it "returns the number of commits" do
allow(payload).to receive(:commit_count).and_return(1)
expect(event.commits_count).to eq(1)
end
end
- describe '#validate_push_action' do
- it 'adds an error when the action is not PUSHED' do
+ describe "#validate_push_action" do
+ it "adds an error when the action is not PUSHED" do
event.action = Event::CREATED
event.validate_push_action
diff --git a/spec/models/redirect_route_spec.rb b/spec/models/redirect_route_spec.rb
index 106ae59af29..0d4146448a9 100644
--- a/spec/models/redirect_route_spec.rb
+++ b/spec/models/redirect_route_spec.rb
@@ -1,34 +1,34 @@
-require 'rails_helper'
+require "rails_helper"
describe RedirectRoute do
let(:group) { create(:group) }
- let!(:redirect_route) { group.redirect_routes.create(path: 'gitlabb') }
+ let!(:redirect_route) { group.redirect_routes.create(path: "gitlabb") }
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:source) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:source) }
it { is_expected.to validate_presence_of(:path) }
it { is_expected.to validate_uniqueness_of(:path).case_insensitive }
end
- describe '.matching_path_and_descendants' do
- let!(:redirect2) { group.redirect_routes.create(path: 'gitlabb/test') }
- let!(:redirect3) { group.redirect_routes.create(path: 'gitlabb/test/foo') }
- let!(:redirect4) { group.redirect_routes.create(path: 'gitlabb/test/foo/bar') }
- let!(:redirect5) { group.redirect_routes.create(path: 'gitlabb/test/baz') }
+ describe ".matching_path_and_descendants" do
+ let!(:redirect2) { group.redirect_routes.create(path: "gitlabb/test") }
+ let!(:redirect3) { group.redirect_routes.create(path: "gitlabb/test/foo") }
+ let!(:redirect4) { group.redirect_routes.create(path: "gitlabb/test/foo/bar") }
+ let!(:redirect5) { group.redirect_routes.create(path: "gitlabb/test/baz") }
- context 'when the redirect route matches with same casing' do
- it 'returns correct routes' do
- expect(described_class.matching_path_and_descendants('gitlabb/test')).to match_array([redirect2, redirect3, redirect4, redirect5])
+ context "when the redirect route matches with same casing" do
+ it "returns correct routes" do
+ expect(described_class.matching_path_and_descendants("gitlabb/test")).to match_array([redirect2, redirect3, redirect4, redirect5])
end
end
- context 'when the redirect route matches with different casing' do
- it 'returns correct routes' do
- expect(described_class.matching_path_and_descendants('GitLABB/test')).to match_array([redirect2, redirect3, redirect4, redirect5])
+ context "when the redirect route matches with different casing" do
+ it "returns correct routes" do
+ expect(described_class.matching_path_and_descendants("GitLABB/test")).to match_array([redirect2, redirect3, redirect4, redirect5])
end
end
end
diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb
index 157c96c1f65..823a2becbfe 100644
--- a/spec/models/release_spec.rb
+++ b/spec/models/release_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
RSpec.describe Release do
let(:user) { create(:user) }
@@ -7,37 +7,37 @@ RSpec.describe Release do
it { expect(release).to be_valid }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
- it { is_expected.to belong_to(:author).class_name('User') }
- it { is_expected.to have_many(:links).class_name('Releases::Link') }
+ it { is_expected.to belong_to(:author).class_name("User") }
+ it { is_expected.to have_many(:links).class_name("Releases::Link") }
end
- describe 'validation' do
+ describe "validation" do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:description) }
end
- describe '#assets_count' do
+ describe "#assets_count" do
subject { release.assets_count }
- it 'returns the number of sources' do
+ it "returns the number of sources" do
is_expected.to eq(Releases::Source::FORMATS.count)
end
- context 'when a links exists' do
+ context "when a links exists" do
let!(:link) { create(:release_link, release: release) }
- it 'counts the link as an asset' do
+ it "counts the link as an asset" do
is_expected.to eq(1 + Releases::Source::FORMATS.count)
end
end
end
- describe '#sources' do
+ describe "#sources" do
subject { release.sources }
- it 'returns sources' do
+ it "returns sources" do
is_expected.to all(be_a(Releases::Source))
end
end
diff --git a/spec/models/releases/link_spec.rb b/spec/models/releases/link_spec.rb
index 4dd26c976cc..2b5c82cffcb 100644
--- a/spec/models/releases/link_spec.rb
+++ b/spec/models/releases/link_spec.rb
@@ -1,60 +1,60 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe Releases::Link do
let(:release) { create(:release, project: project) }
let(:project) { create(:project) }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:release) }
end
- describe 'validation' do
+ describe "validation" do
it { is_expected.to validate_presence_of(:url) }
it { is_expected.to validate_presence_of(:name) }
- context 'when url is invalid' do
- let(:link) { build(:release_link, url: 'hoge') }
+ context "when url is invalid" do
+ let(:link) { build(:release_link, url: "hoge") }
- it 'will be invalid' do
+ it "will be invalid" do
expect(link).to be_invalid
end
end
- context 'when duplicate name is added to a release' do
- let!(:link) { create(:release_link, name: 'alpha', release: release) }
+ context "when duplicate name is added to a release" do
+ let!(:link) { create(:release_link, name: "alpha", release: release) }
- it 'raises an error' do
- expect do
- create(:release_link, name: 'alpha', release: release)
- end.to raise_error(ActiveRecord::RecordInvalid)
+ it "raises an error" do
+ expect {
+ create(:release_link, name: "alpha", release: release)
+ }.to raise_error(ActiveRecord::RecordInvalid)
end
end
- context 'when duplicate url is added to a release' do
- let!(:link) { create(:release_link, url: 'http://gitlab.com', release: release) }
+ context "when duplicate url is added to a release" do
+ let!(:link) { create(:release_link, url: "http://gitlab.com", release: release) }
- it 'raises an error' do
- expect do
- create(:release_link, url: 'http://gitlab.com', release: release)
- end.to raise_error(ActiveRecord::RecordInvalid)
+ it "raises an error" do
+ expect {
+ create(:release_link, url: "http://gitlab.com", release: release)
+ }.to raise_error(ActiveRecord::RecordInvalid)
end
end
end
- describe '.sorted' do
+ describe ".sorted" do
subject { described_class.sorted }
- let!(:link_1) { create(:release_link, name: 'alpha', release: release, created_at: 1.day.ago) }
- let!(:link_2) { create(:release_link, name: 'beta', release: release, created_at: 2.days.ago) }
+ let!(:link_1) { create(:release_link, name: "alpha", release: release, created_at: 1.day.ago) }
+ let!(:link_2) { create(:release_link, name: "beta", release: release, created_at: 2.days.ago) }
- it 'returns a list of links by created_at order' do
+ it "returns a list of links by created_at order" do
is_expected.to eq([link_1, link_2])
end
end
- describe '#internal?' do
+ describe "#internal?" do
subject { link.internal? }
let(:link) { build(:release_link, release: release, url: url) }
@@ -62,41 +62,41 @@ describe Releases::Link do
it { is_expected.to be_truthy }
- context 'when link does not include project web url' do
- let(:url) { 'https://google.com/-/jobs/140463678/artifacts/download' }
+ context "when link does not include project web url" do
+ let(:url) { "https://google.com/-/jobs/140463678/artifacts/download" }
it { is_expected.to be_falsy }
end
end
- describe '#external?' do
+ describe "#external?" do
subject { link.external? }
let(:link) { build(:release_link, release: release, url: url) }
- let(:url) { 'https://google.com/-/jobs/140463678/artifacts/download' }
+ let(:url) { "https://google.com/-/jobs/140463678/artifacts/download" }
it { is_expected.to be_truthy }
end
- describe 'supported protocols' do
+ describe "supported protocols" do
where(:protocol) do
- %w(http https ftp)
+ %w[http https ftp]
end
with_them do
- let(:link) { build(:release_link, url: protocol + '://assets.com/download') }
+ let(:link) { build(:release_link, url: protocol + "://assets.com/download") }
- it 'will be valid' do
+ it "will be valid" do
expect(link).to be_valid
end
end
end
- describe 'unsupported protocol' do
- context 'for torrent' do
- let(:link) { build(:release_link, url: 'torrent://assets.com/download') }
+ describe "unsupported protocol" do
+ context "for torrent" do
+ let(:link) { build(:release_link, url: "torrent://assets.com/download") }
- it 'will be invalid' do
+ it "will be invalid" do
expect(link).to be_invalid
end
end
diff --git a/spec/models/releases/source_spec.rb b/spec/models/releases/source_spec.rb
index c5213196962..9259b770e50 100644
--- a/spec/models/releases/source_spec.rb
+++ b/spec/models/releases/source_spec.rb
@@ -1,38 +1,38 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe Releases::Source do
- set(:project) { create(:project, :repository, name: 'finance-cal') }
- let(:tag_name) { 'v1.0' }
+ set(:project) { create(:project, :repository, name: "finance-cal") }
+ let(:tag_name) { "v1.0" }
- describe '.all' do
+ describe ".all" do
subject { described_class.all(project, tag_name) }
- it 'returns all formats of sources' do
+ it "returns all formats of sources" do
expect(subject.map(&:format))
.to match_array(described_class::FORMATS)
end
end
- describe '#url' do
+ describe "#url" do
subject { source.url }
let(:source) do
described_class.new(project: project, tag_name: tag_name, format: format)
end
- let(:format) { 'zip' }
+ let(:format) { "zip" }
- it 'returns zip archived source url' do
+ it "returns zip archived source url" do
is_expected
.to eq("#{project.web_url}/-/archive/v1.0/finance-cal-v1.0.zip")
end
- context 'when ref is directory structure' do
- let(:tag_name) { 'beta/v1.0' }
+ context "when ref is directory structure" do
+ let(:tag_name) { "beta/v1.0" }
- it 'converts slash to dash' do
+ it "converts slash to dash" do
is_expected
.to eq("#{project.web_url}/-/archive/beta/v1.0/finance-cal-beta-v1.0.zip")
end
diff --git a/spec/models/remote_mirror_spec.rb b/spec/models/remote_mirror_spec.rb
index c06e9a08ab4..29be8bb52d4 100644
--- a/spec/models/remote_mirror_spec.rb
+++ b/spec/models/remote_mirror_spec.rb
@@ -1,113 +1,113 @@
-require 'rails_helper'
+require "rails_helper"
describe RemoteMirror, :mailer do
include GitHelpers
- describe 'URL validation' do
- context 'with a valid URL' do
- it 'should be valid' do
+ describe "URL validation" do
+ context "with a valid URL" do
+ it "should be valid" do
remote_mirror = build(:remote_mirror)
expect(remote_mirror).to be_valid
end
end
- context 'with an invalid URL' do
- it 'should not be valid' do
- remote_mirror = build(:remote_mirror, url: 'ftp://invalid.invalid')
+ context "with an invalid URL" do
+ it "should not be valid" do
+ remote_mirror = build(:remote_mirror, url: "ftp://invalid.invalid")
expect(remote_mirror).not_to be_valid
end
- it 'does not allow url with an invalid user' do
- remote_mirror = build(:remote_mirror, url: 'http://$user:password@invalid.invalid')
+ it "does not allow url with an invalid user" do
+ remote_mirror = build(:remote_mirror, url: "http://$user:password@invalid.invalid")
expect(remote_mirror).to be_invalid
- expect(remote_mirror.errors[:url].first).to include('Username needs to start with an alphanumeric character')
+ expect(remote_mirror.errors[:url].first).to include("Username needs to start with an alphanumeric character")
end
- it 'does not allow url pointing to localhost' do
- remote_mirror = build(:remote_mirror, url: 'http://127.0.0.2/t.git')
+ it "does not allow url pointing to localhost" do
+ remote_mirror = build(:remote_mirror, url: "http://127.0.0.2/t.git")
expect(remote_mirror).to be_invalid
- expect(remote_mirror.errors[:url].first).to include('Requests to loopback addresses are not allowed')
+ expect(remote_mirror.errors[:url].first).to include("Requests to loopback addresses are not allowed")
end
- it 'does not allow url pointing to the local network' do
- remote_mirror = build(:remote_mirror, url: 'https://192.168.1.1')
+ it "does not allow url pointing to the local network" do
+ remote_mirror = build(:remote_mirror, url: "https://192.168.1.1")
expect(remote_mirror).to be_invalid
- expect(remote_mirror.errors[:url].first).to include('Requests to the local network are not allowed')
+ expect(remote_mirror.errors[:url].first).to include("Requests to the local network are not allowed")
end
end
end
- describe 'encrypting credentials' do
- context 'when setting URL for a first time' do
- it 'stores the URL without credentials' do
- mirror = create_mirror(url: 'http://foo:bar@test.com')
+ describe "encrypting credentials" do
+ context "when setting URL for a first time" do
+ it "stores the URL without credentials" do
+ mirror = create_mirror(url: "http://foo:bar@test.com")
- expect(mirror.read_attribute(:url)).to eq('http://test.com')
+ expect(mirror.read_attribute(:url)).to eq("http://test.com")
end
- it 'stores the credentials on a separate field' do
- mirror = create_mirror(url: 'http://foo:bar@test.com')
+ it "stores the credentials on a separate field" do
+ mirror = create_mirror(url: "http://foo:bar@test.com")
- expect(mirror.credentials).to eq({ user: 'foo', password: 'bar' })
+ expect(mirror.credentials).to eq({user: "foo", password: "bar"})
end
- it 'handles credentials with large content' do
- mirror = create_mirror(url: 'http://bxnhm8dote33ct932r3xavslj81wxmr7o8yux8do10oozckkif:9ne7fuvjn40qjt35dgt8v86q9m9g9essryxj76sumg2ccl2fg26c0krtz2gzfpyq4hf22h328uhq6npuiq6h53tpagtsj7vsrz75@test.com')
+ it "handles credentials with large content" do
+ mirror = create_mirror(url: "http://bxnhm8dote33ct932r3xavslj81wxmr7o8yux8do10oozckkif:9ne7fuvjn40qjt35dgt8v86q9m9g9essryxj76sumg2ccl2fg26c0krtz2gzfpyq4hf22h328uhq6npuiq6h53tpagtsj7vsrz75@test.com")
expect(mirror.credentials).to eq({
- user: 'bxnhm8dote33ct932r3xavslj81wxmr7o8yux8do10oozckkif',
- password: '9ne7fuvjn40qjt35dgt8v86q9m9g9essryxj76sumg2ccl2fg26c0krtz2gzfpyq4hf22h328uhq6npuiq6h53tpagtsj7vsrz75'
+ user: "bxnhm8dote33ct932r3xavslj81wxmr7o8yux8do10oozckkif",
+ password: "9ne7fuvjn40qjt35dgt8v86q9m9g9essryxj76sumg2ccl2fg26c0krtz2gzfpyq4hf22h328uhq6npuiq6h53tpagtsj7vsrz75",
})
end
end
- context 'when updating the URL' do
- it 'allows a new URL without credentials' do
- mirror = create_mirror(url: 'http://foo:bar@test.com')
+ context "when updating the URL" do
+ it "allows a new URL without credentials" do
+ mirror = create_mirror(url: "http://foo:bar@test.com")
- mirror.update_attribute(:url, 'http://test.com')
+ mirror.update_attribute(:url, "http://test.com")
- expect(mirror.url).to eq('http://test.com')
- expect(mirror.credentials).to eq({ user: nil, password: nil })
+ expect(mirror.url).to eq("http://test.com")
+ expect(mirror.credentials).to eq({user: nil, password: nil})
end
- it 'allows a new URL with credentials' do
- mirror = create_mirror(url: 'http://test.com')
+ it "allows a new URL with credentials" do
+ mirror = create_mirror(url: "http://test.com")
- mirror.update_attribute(:url, 'http://foo:bar@test.com')
+ mirror.update_attribute(:url, "http://foo:bar@test.com")
- expect(mirror.url).to eq('http://foo:bar@test.com')
- expect(mirror.credentials).to eq({ user: 'foo', password: 'bar' })
+ expect(mirror.url).to eq("http://foo:bar@test.com")
+ expect(mirror.credentials).to eq({user: "foo", password: "bar"})
end
- it 'updates the remote config if credentials changed' do
- mirror = create_mirror(url: 'http://foo:bar@test.com')
+ it "updates the remote config if credentials changed" do
+ mirror = create_mirror(url: "http://foo:bar@test.com")
repo = mirror.project.repository
- mirror.update_attribute(:url, 'http://foo:baz@test.com')
+ mirror.update_attribute(:url, "http://foo:baz@test.com")
config = rugged_repo(repo).config
- expect(config["remote.#{mirror.remote_name}.url"]).to eq('http://foo:baz@test.com')
+ expect(config["remote.#{mirror.remote_name}.url"]).to eq("http://foo:baz@test.com")
end
- it 'removes previous remote' do
- mirror = create_mirror(url: 'http://foo:bar@test.com')
+ it "removes previous remote" do
+ mirror = create_mirror(url: "http://foo:bar@test.com")
expect(RepositoryRemoveRemoteWorker).to receive(:perform_async).with(mirror.project.id, mirror.remote_name).and_call_original
- mirror.update(url: 'http://test.com')
+ mirror.update(url: "http://test.com")
end
end
end
- describe '#remote_name' do
- context 'when remote name is persisted in the database' do
- it 'returns remote name with random value' do
- allow(SecureRandom).to receive(:hex).and_return('secret')
+ describe "#remote_name" do
+ context "when remote name is persisted in the database" do
+ it "returns remote name with random value" do
+ allow(SecureRandom).to receive(:hex).and_return("secret")
remote_mirror = create(:remote_mirror)
@@ -115,8 +115,8 @@ describe RemoteMirror, :mailer do
end
end
- context 'when remote name is not persisted in the database' do
- it 'returns remote name with remote mirror id' do
+ context "when remote name is not persisted in the database" do
+ it "returns remote name with remote mirror id" do
remote_mirror = create(:remote_mirror)
remote_mirror.remote_name = nil
@@ -124,8 +124,8 @@ describe RemoteMirror, :mailer do
end
end
- context 'when remote is not persisted in the database' do
- it 'returns nil' do
+ context "when remote is not persisted in the database" do
+ it "returns nil" do
remote_mirror = build(:remote_mirror, remote_name: nil)
expect(remote_mirror.remote_name).to be_nil
@@ -133,54 +133,54 @@ describe RemoteMirror, :mailer do
end
end
- describe '#safe_url' do
- context 'when URL contains credentials' do
- it 'masks the credentials' do
- mirror = create_mirror(url: 'http://foo:bar@test.com')
+ describe "#safe_url" do
+ context "when URL contains credentials" do
+ it "masks the credentials" do
+ mirror = create_mirror(url: "http://foo:bar@test.com")
- expect(mirror.safe_url).to eq('http://*****:*****@test.com')
+ expect(mirror.safe_url).to eq("http://*****:*****@test.com")
end
end
- context 'when URL does not contain credentials' do
- it 'shows the full URL' do
- mirror = create_mirror(url: 'http://test.com')
+ context "when URL does not contain credentials" do
+ it "shows the full URL" do
+ mirror = create_mirror(url: "http://test.com")
- expect(mirror.safe_url).to eq('http://test.com')
+ expect(mirror.safe_url).to eq("http://test.com")
end
end
end
- describe '#mark_as_failed' do
+ describe "#mark_as_failed" do
let(:remote_mirror) { create(:remote_mirror) }
- let(:error_message) { 'http://user:pass@test.com/root/repoC.git/' }
- let(:sanitized_error_message) { 'http://*****:*****@test.com/root/repoC.git/' }
+ let(:error_message) { "http://user:pass@test.com/root/repoC.git/" }
+ let(:sanitized_error_message) { "http://*****:*****@test.com/root/repoC.git/" }
subject do
remote_mirror.update_start
remote_mirror.mark_as_failed(error_message)
end
- it 'sets the update_status to failed' do
+ it "sets the update_status to failed" do
subject
- expect(remote_mirror.reload.update_status).to eq('failed')
+ expect(remote_mirror.reload.update_status).to eq("failed")
end
- it 'saves the sanitized error' do
+ it "saves the sanitized error" do
subject
expect(remote_mirror.last_error).to eq(sanitized_error_message)
end
- context 'notifications' do
+ context "notifications" do
let(:user) { create(:user) }
before do
remote_mirror.project.add_maintainer(user)
end
- it 'notifies the project maintainers' do
+ it "notifies the project maintainers" do
perform_enqueued_jobs { subject }
should_email(user)
@@ -188,9 +188,9 @@ describe RemoteMirror, :mailer do
end
end
- context 'when remote mirror gets destroyed' do
- it 'removes remote' do
- mirror = create_mirror(url: 'http://foo:bar@test.com')
+ context "when remote mirror gets destroyed" do
+ it "removes remote" do
+ mirror = create_mirror(url: "http://foo:bar@test.com")
expect(RepositoryRemoveRemoteWorker).to receive(:perform_async).with(mirror.project.id, mirror.remote_name).and_call_original
@@ -198,10 +198,10 @@ describe RemoteMirror, :mailer do
end
end
- context 'stuck mirrors' do
- it 'includes mirrors stuck in started with no last_update_at set' do
- mirror = create_mirror(url: 'http://cantbeblank',
- update_status: 'started',
+ context "stuck mirrors" do
+ it "includes mirrors stuck in started with no last_update_at set" do
+ mirror = create_mirror(url: "http://cantbeblank",
+ update_status: "started",
last_update_at: nil,
updated_at: 25.hours.ago)
@@ -209,41 +209,41 @@ describe RemoteMirror, :mailer do
end
end
- context '#sync' do
+ context "#sync" do
let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }
around do |example|
Timecop.freeze { example.run }
end
- context 'with remote mirroring disabled' do
- it 'returns nil' do
+ context "with remote mirroring disabled" do
+ it "returns nil" do
remote_mirror.update(enabled: false)
expect(remote_mirror.sync).to be_nil
end
end
- context 'with remote mirroring enabled' do
- it 'defaults to disabling only protected branches' do
+ context "with remote mirroring enabled" do
+ it "defaults to disabling only protected branches" do
expect(remote_mirror.only_protected_branches?).to be_falsey
end
- context 'with only protected branches enabled' do
+ context "with only protected branches enabled" do
before do
remote_mirror.only_protected_branches = true
end
- context 'when it did not update in the last minute' do
- it 'schedules a RepositoryUpdateRemoteMirrorWorker to run now' do
+ context "when it did not update in the last minute" do
+ it "schedules a RepositoryUpdateRemoteMirrorWorker to run now" do
expect(RepositoryUpdateRemoteMirrorWorker).to receive(:perform_async).with(remote_mirror.id, Time.now)
remote_mirror.sync
end
end
- context 'when it did update in the last minute' do
- it 'schedules a RepositoryUpdateRemoteMirrorWorker to run in the next minute' do
+ context "when it did update in the last minute" do
+ it "schedules a RepositoryUpdateRemoteMirrorWorker to run in the next minute" do
remote_mirror.last_update_started_at = Time.now - 30.seconds
expect(RepositoryUpdateRemoteMirrorWorker).to receive(:perform_in).with(RemoteMirror::PROTECTED_BACKOFF_DELAY, remote_mirror.id, Time.now)
@@ -253,21 +253,21 @@ describe RemoteMirror, :mailer do
end
end
- context 'with only protected branches disabled' do
+ context "with only protected branches disabled" do
before do
remote_mirror.only_protected_branches = false
end
- context 'when it did not update in the last 5 minutes' do
- it 'schedules a RepositoryUpdateRemoteMirrorWorker to run now' do
+ context "when it did not update in the last 5 minutes" do
+ it "schedules a RepositoryUpdateRemoteMirrorWorker to run now" do
expect(RepositoryUpdateRemoteMirrorWorker).to receive(:perform_async).with(remote_mirror.id, Time.now)
remote_mirror.sync
end
end
- context 'when it did update within the last 5 minutes' do
- it 'schedules a RepositoryUpdateRemoteMirrorWorker to run in the next 5 minutes' do
+ context "when it did update within the last 5 minutes" do
+ it "schedules a RepositoryUpdateRemoteMirrorWorker to run in the next 5 minutes" do
remote_mirror.last_update_started_at = Time.now - 30.seconds
expect(RepositoryUpdateRemoteMirrorWorker).to receive(:perform_in).with(RemoteMirror::UNPROTECTED_BACKOFF_DELAY, remote_mirror.id, Time.now)
@@ -279,12 +279,12 @@ describe RemoteMirror, :mailer do
end
end
- context '#ensure_remote!' do
+ context "#ensure_remote!" do
let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }
let(:project) { remote_mirror.project }
let(:repository) { project.repository }
- it 'adds a remote multiple times with no errors' do
+ it "adds a remote multiple times with no errors" do
expect(repository).to receive(:add_remote).with(remote_mirror.remote_name, remote_mirror.url).twice.and_call_original
2.times do
@@ -292,37 +292,37 @@ describe RemoteMirror, :mailer do
end
end
- context 'SSH public-key authentication' do
- it 'omits the password from the URL' do
- remote_mirror.update!(auth_method: 'ssh_public_key', url: 'ssh://git:pass@example.com')
+ context "SSH public-key authentication" do
+ it "omits the password from the URL" do
+ remote_mirror.update!(auth_method: "ssh_public_key", url: "ssh://git:pass@example.com")
- expect(repository).to receive(:add_remote).with(remote_mirror.remote_name, 'ssh://git@example.com')
+ expect(repository).to receive(:add_remote).with(remote_mirror.remote_name, "ssh://git@example.com")
remote_mirror.ensure_remote!
end
end
end
- context '#url=' do
+ context "#url=" do
let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }
- it 'resets all the columns when URL changes' do
+ it "resets all the columns when URL changes" do
remote_mirror.update(last_error: Time.now,
last_update_at: Time.now,
last_successful_update_at: Time.now,
- update_status: 'started',
+ update_status: "started",
error_notification_sent: true)
- expect { remote_mirror.update_attribute(:url, 'http://new.example.com') }
+ expect { remote_mirror.update_attribute(:url, "http://new.example.com") }
.to change { remote_mirror.last_error }.to(nil)
.and change { remote_mirror.last_update_at }.to(nil)
.and change { remote_mirror.last_successful_update_at }.to(nil)
- .and change { remote_mirror.update_status }.to('finished')
+ .and change { remote_mirror.update_status }.to("finished")
.and change { remote_mirror.error_notification_sent }.to(false)
end
end
- context '#updated_since?' do
+ context "#updated_since?" do
let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }
let(:timestamp) { Time.now - 5.minutes }
@@ -334,29 +334,29 @@ describe RemoteMirror, :mailer do
remote_mirror.update(last_update_started_at: Time.now)
end
- context 'when remote mirror does not have status failed' do
- it 'returns true when last update started after the timestamp' do
+ context "when remote mirror does not have status failed" do
+ it "returns true when last update started after the timestamp" do
expect(remote_mirror.updated_since?(timestamp)).to be true
end
- it 'returns false when last update started before the timestamp' do
+ it "returns false when last update started before the timestamp" do
expect(remote_mirror.updated_since?(Time.now + 5.minutes)).to be false
end
end
- context 'when remote mirror has status failed' do
- it 'returns false when last update started after the timestamp' do
- remote_mirror.update(update_status: 'failed')
+ context "when remote mirror has status failed" do
+ it "returns false when last update started after the timestamp" do
+ remote_mirror.update(update_status: "failed")
expect(remote_mirror.updated_since?(timestamp)).to be false
end
end
end
- context 'no project' do
- it 'includes mirror with a project in pending_delete' do
- mirror = create_mirror(url: 'http://cantbeblank',
- update_status: 'finished',
+ context "no project" do
+ it "includes mirror with a project in pending_delete" do
+ mirror = create_mirror(url: "http://cantbeblank",
+ update_status: "finished",
enabled: true,
last_update_at: nil,
updated_at: 25.hours.ago)
@@ -367,7 +367,7 @@ describe RemoteMirror, :mailer do
expect(mirror.sync).to be_nil
expect(mirror.valid?).to be_truthy
- expect(mirror.update_status).to eq('finished')
+ expect(mirror.update_status).to eq("finished")
end
end
diff --git a/spec/models/repository_language_spec.rb b/spec/models/repository_language_spec.rb
index e2e4beb512f..fc9be1b83a1 100644
--- a/spec/models/repository_language_spec.rb
+++ b/spec/models/repository_language_spec.rb
@@ -1,14 +1,14 @@
-require 'spec_helper'
+require "spec_helper"
describe RepositoryLanguage do
let(:repository_language) { build(:repository_language) }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:programming_language) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to allow_value(0).for(:share) }
it { is_expected.to allow_value(100.0).for(:share) }
it { is_expected.not_to allow_value(100.1).for(:share) }
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 17201d8b90a..88d72c90088 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Repository do
include RepoHelpers
@@ -12,21 +12,21 @@ describe Repository do
let(:user) { create(:user) }
let(:git_user) { Gitlab::Git::User.from_gitlab(user) }
- let(:message) { 'Test message' }
+ let(:message) { "Test message" }
let(:merge_commit) do
- merge_request = create(:merge_request, source_branch: 'feature', target_branch: 'master', source_project: project)
+ merge_request = create(:merge_request, source_branch: "feature", target_branch: "master", source_project: project)
merge_commit_id = repository.merge(user,
- merge_request.diff_head_sha,
- merge_request,
- message)
+ merge_request.diff_head_sha,
+ merge_request,
+ message)
repository.commit(merge_commit_id)
end
- let(:author_email) { 'user@example.org' }
- let(:author_name) { 'John Doe' }
+ let(:author_email) { "user@example.org" }
+ let(:author_name) { "John Doe" }
def expect_to_raise_storage_error
expect { yield }.to raise_error do |exception|
@@ -37,18 +37,18 @@ describe Repository do
end
end
- describe '#branch_names_contains' do
+ describe "#branch_names_contains" do
set(:project) { create(:project, :repository) }
let(:repository) { project.repository }
subject { repository.branch_names_contains(sample_commit.id) }
- it { is_expected.to include('master') }
- it { is_expected.not_to include('feature') }
- it { is_expected.not_to include('fix') }
+ it { is_expected.to include("master") }
+ it { is_expected.not_to include("feature") }
+ it { is_expected.not_to include("fix") }
- describe 'when storage is broken', :broken_storage do
- it 'should raise a storage error' do
+ describe "when storage is broken", :broken_storage do
+ it "should raise a storage error" do
expect_to_raise_storage_error do
broken_repository.branch_names_contains(sample_commit.id)
end
@@ -56,32 +56,32 @@ describe Repository do
end
end
- describe '#tag_names_contains' do
+ describe "#tag_names_contains" do
subject { repository.tag_names_contains(sample_commit.id) }
- it { is_expected.to include('v1.1.0') }
- it { is_expected.not_to include('v1.0.0') }
+ it { is_expected.to include("v1.1.0") }
+ it { is_expected.not_to include("v1.0.0") }
end
- describe 'tags_sorted_by' do
- context 'name_desc' do
- subject { repository.tags_sorted_by('name_desc').map(&:name) }
+ describe "tags_sorted_by" do
+ context "name_desc" do
+ subject { repository.tags_sorted_by("name_desc").map(&:name) }
- it { is_expected.to eq(['v1.1.0', 'v1.0.0']) }
+ it { is_expected.to eq(["v1.1.0", "v1.0.0"]) }
end
- context 'name_asc' do
- subject { repository.tags_sorted_by('name_asc').map(&:name) }
+ context "name_asc" do
+ subject { repository.tags_sorted_by("name_asc").map(&:name) }
- it { is_expected.to eq(['v1.0.0', 'v1.1.0']) }
+ it { is_expected.to eq(["v1.0.0", "v1.1.0"]) }
end
- context 'updated' do
- let(:tag_a) { repository.find_tag('v1.0.0') }
- let(:tag_b) { repository.find_tag('v1.1.0') }
+ context "updated" do
+ let(:tag_a) { repository.find_tag("v1.0.0") }
+ let(:tag_b) { repository.find_tag("v1.1.0") }
- context 'desc' do
- subject { repository.tags_sorted_by('updated_desc').map(&:name) }
+ context "desc" do
+ subject { repository.tags_sorted_by("updated_desc").map(&:name) }
before do
double_first = double(committed_date: Time.now)
@@ -92,11 +92,11 @@ describe Repository do
allow(repository).to receive(:tags).and_return([tag_a, tag_b])
end
- it { is_expected.to eq(['v1.0.0', 'v1.1.0']) }
+ it { is_expected.to eq(["v1.0.0", "v1.1.0"]) }
end
- context 'asc' do
- subject { repository.tags_sorted_by('updated_asc').map(&:name) }
+ context "asc" do
+ subject { repository.tags_sorted_by("updated_asc").map(&:name) }
before do
double_first = double(committed_date: Time.now - 1.second)
@@ -107,19 +107,19 @@ describe Repository do
allow(repository).to receive(:tags).and_return([tag_a, tag_b])
end
- it { is_expected.to eq(['v1.1.0', 'v1.0.0']) }
+ it { is_expected.to eq(["v1.1.0", "v1.0.0"]) }
end
- context 'annotated tag pointing to a blob' do
- let(:annotated_tag_name) { 'annotated-tag' }
+ context "annotated tag pointing to a blob" do
+ let(:annotated_tag_name) { "annotated-tag" }
- subject { repository.tags_sorted_by('updated_asc').map(&:name) }
+ subject { repository.tags_sorted_by("updated_asc").map(&:name) }
before do
- options = { message: 'test tag message\n',
- tagger: { name: 'John Smith', email: 'john@gmail.com' } }
+ options = {message: 'test tag message\n',
+ tagger: {name: "John Smith", email: "john@gmail.com"},}
- rugged_repo(repository).tags.create(annotated_tag_name, 'a48e4fc218069f68ef2e769dd8dfea3991362175', options)
+ rugged_repo(repository).tags.create(annotated_tag_name, "a48e4fc218069f68ef2e769dd8dfea3991362175", options)
double_first = double(committed_date: Time.now - 1.second)
double_last = double(committed_date: Time.now)
@@ -128,7 +128,7 @@ describe Repository do
allow(tag_b).to receive(:dereferenced_target).and_return(double_first)
end
- it { is_expected.to eq(['v1.1.0', 'v1.0.0', annotated_tag_name]) }
+ it { is_expected.to eq(["v1.1.0", "v1.0.0", annotated_tag_name]) }
after do
rugged_repo(repository).tags.delete(annotated_tag_name)
@@ -137,36 +137,36 @@ describe Repository do
end
end
- describe '#ref_name_for_sha' do
- it 'returns the ref' do
+ describe "#ref_name_for_sha" do
+ it "returns the ref" do
allow(repository.raw_repository).to receive(:ref_name_for_sha)
- .and_return('refs/environments/production/77')
+ .and_return("refs/environments/production/77")
- expect(repository.ref_name_for_sha('bla', '0' * 40)).to eq 'refs/environments/production/77'
+ expect(repository.ref_name_for_sha("bla", "0" * 40)).to eq "refs/environments/production/77"
end
end
- describe '#ref_exists?' do
- context 'when ref exists' do
- it 'returns true' do
- expect(repository.ref_exists?('refs/heads/master')).to be true
+ describe "#ref_exists?" do
+ context "when ref exists" do
+ it "returns true" do
+ expect(repository.ref_exists?("refs/heads/master")).to be true
end
end
- context 'when ref does not exist' do
- it 'returns false' do
- expect(repository.ref_exists?('refs/heads/non-existent')).to be false
+ context "when ref does not exist" do
+ it "returns false" do
+ expect(repository.ref_exists?("refs/heads/non-existent")).to be false
end
end
- context 'when ref format is incorrect' do
- it 'returns false' do
- expect(repository.ref_exists?('refs/heads/invalid:master')).to be false
+ context "when ref format is incorrect" do
+ it "returns false" do
+ expect(repository.ref_exists?("refs/heads/invalid:master")).to be false
end
end
end
- describe '#list_last_commits_for_tree' do
+ describe "#list_last_commits_for_tree" do
let(:path_to_commit) do
{
"encoding" => "913c66a37b4a45b9769037c55c2d238bd0942d2e",
@@ -182,14 +182,14 @@ describe Repository do
"README.md" => "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863",
"VERSION" => "913c66a37b4a45b9769037c55c2d238bd0942d2e",
"gitlab-shell" => "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9",
- "six" => "cfe32cf61b73a0d5e9f13e774abde7ff789b1660"
+ "six" => "cfe32cf61b73a0d5e9f13e774abde7ff789b1660",
}
end
- subject { repository.list_last_commits_for_tree(sample_commit.id, '.').id }
+ subject { repository.list_last_commits_for_tree(sample_commit.id, ".").id }
- it 'returns the last commits for every entry in the current path' do
- result = repository.list_last_commits_for_tree(sample_commit.id, '.')
+ it "returns the last commits for every entry in the current path" do
+ result = repository.list_last_commits_for_tree(sample_commit.id, ".")
result.each do |key, value|
result[key] = value.id
@@ -198,170 +198,170 @@ describe Repository do
expect(result).to include(path_to_commit)
end
- it 'returns the last commits for every entry in the current path starting from the offset' do
- result = repository.list_last_commits_for_tree(sample_commit.id, '.', offset: path_to_commit.size - 1)
+ it "returns the last commits for every entry in the current path starting from the offset" do
+ result = repository.list_last_commits_for_tree(sample_commit.id, ".", offset: path_to_commit.size - 1)
expect(result.size).to eq(1)
end
- it 'returns a limited number of last commits for every entry in the current path starting from the offset' do
- result = repository.list_last_commits_for_tree(sample_commit.id, '.', limit: 1)
+ it "returns a limited number of last commits for every entry in the current path starting from the offset" do
+ result = repository.list_last_commits_for_tree(sample_commit.id, ".", limit: 1)
expect(result.size).to eq(1)
end
- it 'returns an empty hash when offset is out of bounds' do
- result = repository.list_last_commits_for_tree(sample_commit.id, '.', offset: path_to_commit.size)
+ it "returns an empty hash when offset is out of bounds" do
+ result = repository.list_last_commits_for_tree(sample_commit.id, ".", offset: path_to_commit.size)
expect(result.size).to eq(0)
end
end
- describe '#last_commit_for_path' do
- subject { repository.last_commit_for_path(sample_commit.id, '.gitignore').id }
+ describe "#last_commit_for_path" do
+ subject { repository.last_commit_for_path(sample_commit.id, ".gitignore").id }
- it { is_expected.to eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') }
+ it { is_expected.to eq("c1acaa58bbcbc3eafe538cb8274ba387047b69f8") }
- describe 'when storage is broken', :broken_storage do
- it 'should raise a storage error' do
+ describe "when storage is broken", :broken_storage do
+ it "should raise a storage error" do
expect_to_raise_storage_error do
- broken_repository.last_commit_id_for_path(sample_commit.id, '.gitignore')
+ broken_repository.last_commit_id_for_path(sample_commit.id, ".gitignore")
end
end
end
end
- describe '#last_commit_id_for_path' do
- subject { repository.last_commit_id_for_path(sample_commit.id, '.gitignore') }
+ describe "#last_commit_id_for_path" do
+ subject { repository.last_commit_id_for_path(sample_commit.id, ".gitignore") }
it "returns last commit id for a given path" do
- is_expected.to eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8')
+ is_expected.to eq("c1acaa58bbcbc3eafe538cb8274ba387047b69f8")
end
it "caches last commit id for a given path" do
cache = repository.send(:cache)
- key = "last_commit_id_for_path:#{sample_commit.id}:#{Digest::SHA1.hexdigest('.gitignore')}"
+ key = "last_commit_id_for_path:#{sample_commit.id}:#{Digest::SHA1.hexdigest(".gitignore")}"
- expect(cache).to receive(:fetch).with(key).and_return('c1acaa5')
- is_expected.to eq('c1acaa5')
+ expect(cache).to receive(:fetch).with(key).and_return("c1acaa5")
+ is_expected.to eq("c1acaa5")
end
- describe 'when storage is broken', :broken_storage do
- it 'should raise a storage error' do
+ describe "when storage is broken", :broken_storage do
+ it "should raise a storage error" do
expect_to_raise_storage_error do
- broken_repository.last_commit_for_path(sample_commit.id, '.gitignore').id
+ broken_repository.last_commit_for_path(sample_commit.id, ".gitignore").id
end
end
end
end
- describe '#commits' do
- context 'when neither the all flag nor a ref are specified' do
- it 'returns every commit from default branch' do
+ describe "#commits" do
+ context "when neither the all flag nor a ref are specified" do
+ it "returns every commit from default branch" do
expect(repository.commits(limit: 60).size).to eq(37)
end
end
- context 'when ref is passed' do
- it 'returns every commit from the specified ref' do
- expect(repository.commits('master', limit: 60).size).to eq(37)
+ context "when ref is passed" do
+ it "returns every commit from the specified ref" do
+ expect(repository.commits("master", limit: 60).size).to eq(37)
end
- context 'when all' do
- it 'returns every commit from the repository' do
- expect(repository.commits('master', limit: 60, all: true).size).to eq(60)
+ context "when all" do
+ it "returns every commit from the repository" do
+ expect(repository.commits("master", limit: 60, all: true).size).to eq(60)
end
end
- context 'with path' do
- it 'sets follow when it is a single path' do
+ context "with path" do
+ it "sets follow when it is a single path" do
expect(Gitlab::Git::Commit).to receive(:where).with(a_hash_including(follow: true)).and_call_original.twice
- repository.commits('master', limit: 1, path: 'README.md')
- repository.commits('master', limit: 1, path: ['README.md'])
+ repository.commits("master", limit: 1, path: "README.md")
+ repository.commits("master", limit: 1, path: ["README.md"])
end
- it 'does not set follow when it is multiple paths' do
+ it "does not set follow when it is multiple paths" do
expect(Gitlab::Git::Commit).to receive(:where).with(a_hash_including(follow: false)).and_call_original
- repository.commits('master', limit: 1, path: ['README.md', 'CHANGELOG'])
+ repository.commits("master", limit: 1, path: ["README.md", "CHANGELOG"])
end
end
- context 'without path' do
- it 'does not set follow' do
+ context "without path" do
+ it "does not set follow" do
expect(Gitlab::Git::Commit).to receive(:where).with(a_hash_including(follow: false)).and_call_original
- repository.commits('master', limit: 1)
+ repository.commits("master", limit: 1)
end
end
end
context "when 'all' flag is set" do
- it 'returns every commit from the repository' do
+ it "returns every commit from the repository" do
expect(repository.commits(all: true, limit: 60).size).to eq(60)
end
end
end
- describe '#new_commits' do
+ describe "#new_commits" do
set(:project) { create(:project, :repository) }
let(:repository) { project.repository }
subject { repository.new_commits(rev) }
- context 'when there are no new commits' do
+ context "when there are no new commits" do
let(:rev) { repository.commit.id }
- it 'returns an empty array' do
+ it "returns an empty array" do
expect(subject).to eq([])
end
end
- context 'when new commits are found' do
- let(:branch) { 'orphaned-branch' }
+ context "when new commits are found" do
+ let(:branch) { "orphaned-branch" }
let!(:rev) { repository.commit(branch).id }
- it 'returns the commits' do
+ it "returns the commits" do
repository.delete_branch(branch)
expect(subject).not_to be_empty
- expect(subject).to all( be_a(::Commit) )
+ expect(subject).to all(be_a(::Commit))
expect(subject.size).to eq(1)
end
end
end
- describe '#commits_by' do
+ describe "#commits_by" do
set(:project) { create(:project, :repository) }
let(:oids) { TestEnv::BRANCH_SHA.values }
subject { project.repository.commits_by(oids: oids) }
- it 'finds each commit' do
+ it "finds each commit" do
expect(subject).not_to include(nil)
expect(subject.size).to eq(oids.size)
end
- it 'returns only Commit instances' do
- expect(subject).to all( be_a(Commit) )
+ it "returns only Commit instances" do
+ expect(subject).to all(be_a(Commit))
end
- context 'when some commits are not found ' do
+ context "when some commits are not found " do
let(:oids) do
- ['deadbeef'] + TestEnv::BRANCH_SHA.values.first(10)
+ ["deadbeef"] + TestEnv::BRANCH_SHA.values.first(10)
end
- it 'returns only found commits' do
+ it "returns only found commits" do
expect(subject).not_to include(nil)
expect(subject.size).to eq(10)
end
end
- context 'when no oids are passed' do
+ context "when no oids are passed" do
let(:oids) { [] }
- it 'does not call #batch_by_oid' do
+ it "does not call #batch_by_oid" do
expect(Gitlab::Git::Commit).not_to receive(:batch_by_oid)
subject
@@ -369,154 +369,154 @@ describe Repository do
end
end
- describe '#find_commits_by_message' do
- it 'returns commits with messages containing a given string' do
- commit_ids = repository.find_commits_by_message('submodule').map(&:id)
+ describe "#find_commits_by_message" do
+ it "returns commits with messages containing a given string" do
+ commit_ids = repository.find_commits_by_message("submodule").map(&:id)
expect(commit_ids).to include(
- '5937ac0a7beb003549fc5fd26fc247adbce4a52e',
- '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9',
- 'cfe32cf61b73a0d5e9f13e774abde7ff789b1660'
+ "5937ac0a7beb003549fc5fd26fc247adbce4a52e",
+ "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9",
+ "cfe32cf61b73a0d5e9f13e774abde7ff789b1660"
)
- expect(commit_ids).not_to include('913c66a37b4a45b9769037c55c2d238bd0942d2e')
+ expect(commit_ids).not_to include("913c66a37b4a45b9769037c55c2d238bd0942d2e")
end
- it 'is case insensitive' do
- commit_ids = repository.find_commits_by_message('SUBMODULE').map(&:id)
+ it "is case insensitive" do
+ commit_ids = repository.find_commits_by_message("SUBMODULE").map(&:id)
- expect(commit_ids).to include('5937ac0a7beb003549fc5fd26fc247adbce4a52e')
+ expect(commit_ids).to include("5937ac0a7beb003549fc5fd26fc247adbce4a52e")
end
- describe 'when storage is broken', :broken_storage do
- it 'should raise a storage error' do
- expect_to_raise_storage_error { broken_repository.find_commits_by_message('s') }
+ describe "when storage is broken", :broken_storage do
+ it "should raise a storage error" do
+ expect_to_raise_storage_error { broken_repository.find_commits_by_message("s") }
end
end
end
- describe '#blob_at' do
- context 'blank sha' do
- subject { repository.blob_at(Gitlab::Git::BLANK_SHA, '.gitignore') }
+ describe "#blob_at" do
+ context "blank sha" do
+ subject { repository.blob_at(Gitlab::Git::BLANK_SHA, ".gitignore") }
it { is_expected.to be_nil }
end
- context 'regular blob' do
- subject { repository.blob_at(repository.head_commit.sha, '.gitignore') }
+ context "regular blob" do
+ subject { repository.blob_at(repository.head_commit.sha, ".gitignore") }
it { is_expected.to be_an_instance_of(::Blob) }
end
- context 'readme blob on HEAD' do
- subject { repository.blob_at(repository.head_commit.sha, 'README.md') }
+ context "readme blob on HEAD" do
+ subject { repository.blob_at(repository.head_commit.sha, "README.md") }
it { is_expected.to be_an_instance_of(::ReadmeBlob) }
end
- context 'readme blob not on HEAD' do
- subject { repository.blob_at(repository.find_branch('feature').target, 'README.md') }
+ context "readme blob not on HEAD" do
+ subject { repository.blob_at(repository.find_branch("feature").target, "README.md") }
it { is_expected.to be_an_instance_of(::Blob) }
end
end
- describe '#merged_to_root_ref?' do
- context 'merged branch without ff' do
- subject { repository.merged_to_root_ref?('branch-merged') }
+ describe "#merged_to_root_ref?" do
+ context "merged branch without ff" do
+ subject { repository.merged_to_root_ref?("branch-merged") }
it { is_expected.to be_truthy }
end
# If the HEAD was ff then it will be false
- context 'merged with ff' do
- subject { repository.merged_to_root_ref?('improve/awesome') }
+ context "merged with ff" do
+ subject { repository.merged_to_root_ref?("improve/awesome") }
it { is_expected.to be_truthy }
end
- context 'not merged branch' do
- subject { repository.merged_to_root_ref?('not-merged-branch') }
+ context "not merged branch" do
+ subject { repository.merged_to_root_ref?("not-merged-branch") }
it { is_expected.to be_falsey }
end
- context 'default branch' do
- subject { repository.merged_to_root_ref?('master') }
+ context "default branch" do
+ subject { repository.merged_to_root_ref?("master") }
it { is_expected.to be_falsey }
end
- context 'non merged branch' do
- subject { repository.merged_to_root_ref?('fix') }
+ context "non merged branch" do
+ subject { repository.merged_to_root_ref?("fix") }
it { is_expected.to be_falsey }
end
- context 'non existent branch' do
- subject { repository.merged_to_root_ref?('non_existent_branch') }
+ context "non existent branch" do
+ subject { repository.merged_to_root_ref?("non_existent_branch") }
it { is_expected.to be_nil }
end
end
- describe '#can_be_merged?' do
- context 'mergeable branches' do
- subject { repository.can_be_merged?('0b4bc9a49b562e85de7cc9e834518ea6828729b9', 'master') }
+ describe "#can_be_merged?" do
+ context "mergeable branches" do
+ subject { repository.can_be_merged?("0b4bc9a49b562e85de7cc9e834518ea6828729b9", "master") }
it { is_expected.to be_truthy }
end
- context 'non-mergeable branches without conflict sides missing' do
- subject { repository.can_be_merged?('bb5206fee213d983da88c47f9cf4cc6caf9c66dc', 'feature') }
+ context "non-mergeable branches without conflict sides missing" do
+ subject { repository.can_be_merged?("bb5206fee213d983da88c47f9cf4cc6caf9c66dc", "feature") }
it { is_expected.to be_falsey }
end
- context 'non-mergeable branches with conflict sides missing' do
- subject { repository.can_be_merged?('conflict-missing-side', 'conflict-start') }
+ context "non-mergeable branches with conflict sides missing" do
+ subject { repository.can_be_merged?("conflict-missing-side", "conflict-start") }
it { is_expected.to be_falsey }
end
- context 'submodule changes that confuse rugged' do
- subject { repository.can_be_merged?('update-gitlab-shell-v-6-0-1', 'update-gitlab-shell-v-6-0-3') }
+ context "submodule changes that confuse rugged" do
+ subject { repository.can_be_merged?("update-gitlab-shell-v-6-0-1", "update-gitlab-shell-v-6-0-3") }
it { is_expected.to be_falsey }
end
end
- describe '#commit' do
- context 'when ref exists' do
- it 'returns commit object' do
- expect(repository.commit('master'))
+ describe "#commit" do
+ context "when ref exists" do
+ it "returns commit object" do
+ expect(repository.commit("master"))
.to be_an_instance_of Commit
end
end
- context 'when ref does not exist' do
- it 'returns nil' do
- expect(repository.commit('non-existent-ref')).to be_nil
+ context "when ref does not exist" do
+ it "returns nil" do
+ expect(repository.commit("non-existent-ref")).to be_nil
end
end
- context 'when ref is not specified' do
- it 'is using a root ref' do
- expect(repository).to receive(:find_commit).with('master')
+ context "when ref is not specified" do
+ it "is using a root ref" do
+ expect(repository).to receive(:find_commit).with("master")
repository.commit
end
end
- context 'when ref is not valid' do
- context 'when preceding tree element exists' do
- it 'returns nil' do
- expect(repository.commit('master:ref')).to be_nil
+ context "when ref is not valid" do
+ context "when preceding tree element exists" do
+ it "returns nil" do
+ expect(repository.commit("master:ref")).to be_nil
end
end
- context 'when preceding tree element does not exist' do
- it 'returns nil' do
- expect(repository.commit('non-existent:ref')).to be_nil
+ context "when preceding tree element does not exist" do
+ it "returns nil" do
+ expect(repository.commit("non-existent:ref")).to be_nil
end
end
end
@@ -524,41 +524,41 @@ describe Repository do
describe "#create_dir" do
it "commits a change that creates a new directory" do
- expect do
- repository.create_dir(user, 'newdir',
- message: 'Create newdir', branch_name: 'master')
- end.to change { repository.count_commits(ref: 'master') }.by(1)
+ expect {
+ repository.create_dir(user, "newdir",
+ message: "Create newdir", branch_name: "master")
+ }.to change { repository.count_commits(ref: "master") }.by(1)
- newdir = repository.tree('master', 'newdir')
- expect(newdir.path).to eq('newdir')
+ newdir = repository.tree("master", "newdir")
+ expect(newdir.path).to eq("newdir")
end
context "when committing to another project" do
let(:forked_project) { create(:project, :repository) }
it "creates a fork and commit to the forked project" do
- expect do
- repository.create_dir(user, 'newdir',
- message: 'Create newdir', branch_name: 'patch',
- start_branch_name: 'master', start_project: forked_project)
- end.to change { repository.count_commits(ref: 'master') }.by(0)
+ expect {
+ repository.create_dir(user, "newdir",
+ message: "Create newdir", branch_name: "patch",
+ start_branch_name: "master", start_project: forked_project)
+ }.to change { repository.count_commits(ref: "master") }.by(0)
- expect(repository.branch_exists?('patch')).to be_truthy
- expect(forked_project.repository.branch_exists?('patch')).to be_falsy
+ expect(repository.branch_exists?("patch")).to be_truthy
+ expect(forked_project.repository.branch_exists?("patch")).to be_falsy
- newdir = repository.tree('patch', 'newdir')
- expect(newdir.path).to eq('newdir')
+ newdir = repository.tree("patch", "newdir")
+ expect(newdir.path).to eq("newdir")
end
end
context "when an author is specified" do
it "uses the given email/name to set the commit's author" do
- expect do
- repository.create_dir(user, 'newdir',
- message: 'Add newdir',
- branch_name: 'master',
+ expect {
+ repository.create_dir(user, "newdir",
+ message: "Add newdir",
+ branch_name: "master",
author_email: author_email, author_name: author_name)
- end.to change { repository.count_commits(ref: 'master') }.by(1)
+ }.to change { repository.count_commits(ref: "master") }.by(1)
last_commit = repository.commit
@@ -569,48 +569,48 @@ describe Repository do
end
describe "#create_file" do
- it 'commits new file successfully' do
- expect do
- repository.create_file(user, 'NEWCHANGELOG', 'Changelog!',
- message: 'Create changelog',
- branch_name: 'master')
- end.to change { repository.count_commits(ref: 'master') }.by(1)
+ it "commits new file successfully" do
+ expect {
+ repository.create_file(user, "NEWCHANGELOG", "Changelog!",
+ message: "Create changelog",
+ branch_name: "master")
+ }.to change { repository.count_commits(ref: "master") }.by(1)
- blob = repository.blob_at('master', 'NEWCHANGELOG')
+ blob = repository.blob_at("master", "NEWCHANGELOG")
- expect(blob.data).to eq('Changelog!')
+ expect(blob.data).to eq("Changelog!")
end
- it 'creates new file and dir when file_path has a forward slash' do
- expect do
- repository.create_file(user, 'new_dir/new_file.txt', 'File!',
- message: 'Create new_file with new_dir',
- branch_name: 'master')
- end.to change { repository.count_commits(ref: 'master') }.by(1)
+ it "creates new file and dir when file_path has a forward slash" do
+ expect {
+ repository.create_file(user, "new_dir/new_file.txt", "File!",
+ message: "Create new_file with new_dir",
+ branch_name: "master")
+ }.to change { repository.count_commits(ref: "master") }.by(1)
- expect(repository.tree('master', 'new_dir').path).to eq('new_dir')
- expect(repository.blob_at('master', 'new_dir/new_file.txt').data).to eq('File!')
+ expect(repository.tree("master", "new_dir").path).to eq("new_dir")
+ expect(repository.blob_at("master", "new_dir/new_file.txt").data).to eq("File!")
end
- it 'respects the autocrlf setting' do
- repository.create_file(user, 'hello.txt', "Hello,\r\nWorld",
- message: 'Add hello world',
- branch_name: 'master')
+ it "respects the autocrlf setting" do
+ repository.create_file(user, "hello.txt", "Hello,\r\nWorld",
+ message: "Add hello world",
+ branch_name: "master")
- blob = repository.blob_at('master', 'hello.txt')
+ blob = repository.blob_at("master", "hello.txt")
expect(blob.data).to eq("Hello,\nWorld")
end
context "when an author is specified" do
it "uses the given email/name to set the commit's author" do
- expect do
- repository.create_file(user, 'NEWREADME', 'README!',
- message: 'Add README',
- branch_name: 'master',
- author_email: author_email,
- author_name: author_name)
- end.to change { repository.count_commits(ref: 'master') }.by(1)
+ expect {
+ repository.create_file(user, "NEWREADME", "README!",
+ message: "Add README",
+ branch_name: "master",
+ author_email: author_email,
+ author_name: author_name)
+ }.to change { repository.count_commits(ref: "master") }.by(1)
last_commit = repository.commit
@@ -621,42 +621,42 @@ describe Repository do
end
describe "#update_file" do
- it 'updates file successfully' do
- expect do
- repository.update_file(user, 'CHANGELOG', 'Changelog!',
- message: 'Update changelog',
- branch_name: 'master')
- end.to change { repository.count_commits(ref: 'master') }.by(1)
+ it "updates file successfully" do
+ expect {
+ repository.update_file(user, "CHANGELOG", "Changelog!",
+ message: "Update changelog",
+ branch_name: "master")
+ }.to change { repository.count_commits(ref: "master") }.by(1)
- blob = repository.blob_at('master', 'CHANGELOG')
+ blob = repository.blob_at("master", "CHANGELOG")
- expect(blob.data).to eq('Changelog!')
+ expect(blob.data).to eq("Changelog!")
end
- it 'updates filename successfully' do
- expect do
- repository.update_file(user, 'NEWLICENSE', 'Copyright!',
- branch_name: 'master',
- previous_path: 'LICENSE',
- message: 'Changes filename')
- end.to change { repository.count_commits(ref: 'master') }.by(1)
+ it "updates filename successfully" do
+ expect {
+ repository.update_file(user, "NEWLICENSE", "Copyright!",
+ branch_name: "master",
+ previous_path: "LICENSE",
+ message: "Changes filename")
+ }.to change { repository.count_commits(ref: "master") }.by(1)
- files = repository.ls_files('master')
+ files = repository.ls_files("master")
- expect(files).not_to include('LICENSE')
- expect(files).to include('NEWLICENSE')
+ expect(files).not_to include("LICENSE")
+ expect(files).to include("NEWLICENSE")
end
context "when an author is specified" do
it "uses the given email/name to set the commit's author" do
- expect do
- repository.update_file(user, 'README', 'Updated README!',
- branch_name: 'master',
- previous_path: 'README',
- message: 'Update README',
- author_email: author_email,
- author_name: author_name)
- end.to change { repository.count_commits(ref: 'master') }.by(1)
+ expect {
+ repository.update_file(user, "README", "Updated README!",
+ branch_name: "master",
+ previous_path: "README",
+ message: "Update README",
+ author_email: author_email,
+ author_name: author_name)
+ }.to change { repository.count_commits(ref: "master") }.by(1)
last_commit = repository.commit
@@ -667,22 +667,22 @@ describe Repository do
end
describe "#delete_file" do
- it 'removes file successfully' do
- expect do
- repository.delete_file(user, 'README',
- message: 'Remove README', branch_name: 'master')
- end.to change { repository.count_commits(ref: 'master') }.by(1)
+ it "removes file successfully" do
+ expect {
+ repository.delete_file(user, "README",
+ message: "Remove README", branch_name: "master")
+ }.to change { repository.count_commits(ref: "master") }.by(1)
- expect(repository.blob_at('master', 'README')).to be_nil
+ expect(repository.blob_at("master", "README")).to be_nil
end
context "when an author is specified" do
it "uses the given email/name to set the commit's author" do
- expect do
- repository.delete_file(user, 'README',
- message: 'Remove README', branch_name: 'master',
+ expect {
+ repository.delete_file(user, "README",
+ message: "Remove README", branch_name: "master",
author_email: author_email, author_name: author_name)
- end.to change { repository.count_commits(ref: 'master') }.by(1)
+ }.to change { repository.count_commits(ref: "master") }.by(1)
last_commit = repository.commit
@@ -693,45 +693,45 @@ describe Repository do
end
describe "search_files_by_content" do
- let(:results) { repository.search_files_by_content('feature', 'master') }
+ let(:results) { repository.search_files_by_content("feature", "master") }
subject { results }
it { is_expected.to be_an Array }
- it 'regex-escapes the query string' do
- results = repository.search_files_by_content("test\\", 'master')
+ it "regex-escapes the query string" do
+ results = repository.search_files_by_content("test\\", "master")
- expect(results.first).not_to start_with('fatal:')
+ expect(results.first).not_to start_with("fatal:")
end
- it 'properly handles an unmatched parenthesis' do
- results = repository.search_files_by_content("test(", 'master')
+ it "properly handles an unmatched parenthesis" do
+ results = repository.search_files_by_content("test(", "master")
- expect(results.first).not_to start_with('fatal:')
+ expect(results.first).not_to start_with("fatal:")
end
- it 'properly handles when query is not present' do
- results = repository.search_files_by_content('', 'master')
+ it "properly handles when query is not present" do
+ results = repository.search_files_by_content("", "master")
expect(results).to match_array([])
end
- it 'properly handles query when repo is empty' do
+ it "properly handles query when repo is empty" do
repository = create(:project, :empty_repo).repository
- results = repository.search_files_by_content('test', 'master')
+ results = repository.search_files_by_content("test", "master")
expect(results).to match_array([])
end
- describe 'when storage is broken', :broken_storage do
- it 'should raise a storage error' do
+ describe "when storage is broken", :broken_storage do
+ it "should raise a storage error" do
expect_to_raise_storage_error do
- broken_repository.search_files_by_content('feature', 'master')
+ broken_repository.search_files_by_content("feature", "master")
end
end
end
- describe 'result' do
+ describe "result" do
subject { results.first }
it { is_expected.to be_an String }
@@ -740,92 +740,92 @@ describe Repository do
end
describe "search_files_by_name" do
- let(:results) { repository.search_files_by_name('files', 'master') }
+ let(:results) { repository.search_files_by_name("files", "master") }
- it 'returns result' do
- expect(results.first).to eq('files/html/500.html')
+ it "returns result" do
+ expect(results.first).to eq("files/html/500.html")
end
- it 'ignores leading slashes' do
- results = repository.search_files_by_name('/files', 'master')
+ it "ignores leading slashes" do
+ results = repository.search_files_by_name("/files", "master")
- expect(results.first).to eq('files/html/500.html')
+ expect(results.first).to eq("files/html/500.html")
end
- it 'properly handles when query is only slashes' do
- results = repository.search_files_by_name('//', 'master')
+ it "properly handles when query is only slashes" do
+ results = repository.search_files_by_name("//", "master")
expect(results).to match_array([])
end
- it 'properly handles when query is not present' do
- results = repository.search_files_by_name('', 'master')
+ it "properly handles when query is not present" do
+ results = repository.search_files_by_name("", "master")
expect(results).to match_array([])
end
- it 'properly handles query when repo is empty' do
+ it "properly handles query when repo is empty" do
repository = create(:project, :empty_repo).repository
- results = repository.search_files_by_name('test', 'master')
+ results = repository.search_files_by_name("test", "master")
expect(results).to match_array([])
end
- describe 'when storage is broken', :broken_storage do
- it 'should raise a storage error' do
- expect_to_raise_storage_error { broken_repository.search_files_by_name('files', 'master') }
+ describe "when storage is broken", :broken_storage do
+ it "should raise a storage error" do
+ expect_to_raise_storage_error { broken_repository.search_files_by_name("files", "master") }
end
end
end
- describe '#async_remove_remote' do
+ describe "#async_remove_remote" do
before do
- masterrev = repository.find_branch('master').dereferenced_target
- create_remote_branch('joe', 'remote_branch', masterrev)
+ masterrev = repository.find_branch("master").dereferenced_target
+ create_remote_branch("joe", "remote_branch", masterrev)
end
- context 'when worker is scheduled successfully' do
+ context "when worker is scheduled successfully" do
before do
- masterrev = repository.find_branch('master').dereferenced_target
- create_remote_branch('remote_name', 'remote_branch', masterrev)
+ masterrev = repository.find_branch("master").dereferenced_target
+ create_remote_branch("remote_name", "remote_branch", masterrev)
- allow(RepositoryRemoveRemoteWorker).to receive(:perform_async).and_return('1234')
+ allow(RepositoryRemoveRemoteWorker).to receive(:perform_async).and_return("1234")
end
- it 'returns job_id' do
- expect(repository.async_remove_remote('joe')).to eq('1234')
+ it "returns job_id" do
+ expect(repository.async_remove_remote("joe")).to eq("1234")
end
end
- context 'when worker does not schedule successfully' do
+ context "when worker does not schedule successfully" do
before do
allow(RepositoryRemoveRemoteWorker).to receive(:perform_async).and_return(nil)
end
- it 'returns nil' do
+ it "returns nil" do
expect(Rails.logger).to receive(:info).with("Remove remote job failed to create for #{project.id} with remote name joe.")
- expect(repository.async_remove_remote('joe')).to be_nil
+ expect(repository.async_remove_remote("joe")).to be_nil
end
end
end
- describe '#fetch_ref' do
+ describe "#fetch_ref" do
let(:broken_repository) { create(:project, :broken_storage).repository }
- describe 'when storage is broken', :broken_storage do
- it 'should raise a storage error' do
+ describe "when storage is broken", :broken_storage do
+ it "should raise a storage error" do
expect_to_raise_storage_error do
- broken_repository.fetch_ref(broken_repository, source_ref: '1', target_ref: '2')
+ broken_repository.fetch_ref(broken_repository, source_ref: "1", target_ref: "2")
end
end
end
end
- describe '#create_ref' do
- it 'redirects the call to write_ref' do
- ref, ref_path = '1', '2'
+ describe "#create_ref" do
+ it "redirects the call to write_ref" do
+ ref, ref_path = "1", "2"
expect(repository.raw_repository).to receive(:write_ref).with(ref_path, ref)
@@ -834,241 +834,243 @@ describe Repository do
end
describe "#changelog", :use_clean_rails_memory_store_caching do
- it 'accepts changelog' do
- expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('changelog')])
+ it "accepts changelog" do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new("changelog")])
- expect(repository.changelog.path).to eq('changelog')
+ expect(repository.changelog.path).to eq("changelog")
end
- it 'accepts news instead of changelog' do
- expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('news')])
+ it "accepts news instead of changelog" do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new("news")])
- expect(repository.changelog.path).to eq('news')
+ expect(repository.changelog.path).to eq("news")
end
- it 'accepts history instead of changelog' do
- expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('history')])
+ it "accepts history instead of changelog" do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new("history")])
- expect(repository.changelog.path).to eq('history')
+ expect(repository.changelog.path).to eq("history")
end
- it 'accepts changes instead of changelog' do
- expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('changes')])
+ it "accepts changes instead of changelog" do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new("changes")])
- expect(repository.changelog.path).to eq('changes')
+ expect(repository.changelog.path).to eq("changes")
end
- it 'is case-insensitive' do
- expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('CHANGELOG')])
+ it "is case-insensitive" do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new("CHANGELOG")])
- expect(repository.changelog.path).to eq('CHANGELOG')
+ expect(repository.changelog.path).to eq("CHANGELOG")
end
end
describe "#license_blob", :use_clean_rails_memory_store_caching do
before do
repository.delete_file(
- user, 'LICENSE', message: 'Remove LICENSE', branch_name: 'master')
+ user, "LICENSE", message: "Remove LICENSE", branch_name: "master"
+ )
end
- it 'handles when HEAD points to non-existent ref' do
+ it "handles when HEAD points to non-existent ref" do
repository.create_file(
- user, 'LICENSE', 'Copyright!',
- message: 'Add LICENSE', branch_name: 'master')
+ user, "LICENSE", "Copyright!",
+ message: "Add LICENSE", branch_name: "master"
+ )
allow(repository).to receive(:root_ref).and_raise(Gitlab::Git::Repository::NoRepository)
expect(repository.license_blob).to be_nil
end
- it 'looks in the root_ref only' do
- repository.delete_file(user, 'LICENSE',
- message: 'Remove LICENSE', branch_name: 'markdown')
- repository.create_file(user, 'LICENSE',
- Licensee::License.new('mit').content,
- message: 'Add LICENSE', branch_name: 'markdown')
+ it "looks in the root_ref only" do
+ repository.delete_file(user, "LICENSE",
+ message: "Remove LICENSE", branch_name: "markdown")
+ repository.create_file(user, "LICENSE",
+ Licensee::License.new("mit").content,
+ message: "Add LICENSE", branch_name: "markdown")
expect(repository.license_blob).to be_nil
end
- it 'detects license file with no recognizable open-source license content' do
- repository.create_file(user, 'LICENSE', 'Copyright!',
- message: 'Add LICENSE', branch_name: 'master')
+ it "detects license file with no recognizable open-source license content" do
+ repository.create_file(user, "LICENSE", "Copyright!",
+ message: "Add LICENSE", branch_name: "master")
- expect(repository.license_blob.path).to eq('LICENSE')
+ expect(repository.license_blob.path).to eq("LICENSE")
end
%w[LICENSE LICENCE LiCensE LICENSE.md LICENSE.foo COPYING COPYING.md].each do |filename|
it "detects '#{filename}'" do
repository.create_file(user, filename,
- Licensee::License.new('mit').content,
- message: "Add #{filename}", branch_name: 'master')
+ Licensee::License.new("mit").content,
+ message: "Add #{filename}", branch_name: "master")
expect(repository.license_blob.name).to eq(filename)
end
end
end
- describe '#license_key', :use_clean_rails_memory_store_caching do
+ describe "#license_key", :use_clean_rails_memory_store_caching do
before do
- repository.delete_file(user, 'LICENSE',
- message: 'Remove LICENSE', branch_name: 'master')
+ repository.delete_file(user, "LICENSE",
+ message: "Remove LICENSE", branch_name: "master")
end
- it 'returns nil when no license is detected' do
+ it "returns nil when no license is detected" do
expect(repository.license_key).to be_nil
end
- it 'returns nil when the repository does not exist' do
+ it "returns nil when the repository does not exist" do
expect(repository).to receive(:exists?).and_return(false)
expect(repository.license_key).to be_nil
end
- it 'returns nil when the content is not recognizable' do
- repository.create_file(user, 'LICENSE', 'Gitlab B.V.',
- message: 'Add LICENSE', branch_name: 'master')
+ it "returns nil when the content is not recognizable" do
+ repository.create_file(user, "LICENSE", "Gitlab B.V.",
+ message: "Add LICENSE", branch_name: "master")
expect(repository.license_key).to be_nil
end
- it 'returns nil when the commit SHA does not exist' do
- allow(repository.head_commit).to receive(:sha).and_return('1' * 40)
+ it "returns nil when the commit SHA does not exist" do
+ allow(repository.head_commit).to receive(:sha).and_return("1" * 40)
expect(repository.license_key).to be_nil
end
- it 'returns nil when master does not exist' do
- repository.rm_branch(user, 'master')
+ it "returns nil when master does not exist" do
+ repository.rm_branch(user, "master")
expect(repository.license_key).to be_nil
end
- it 'returns the license key' do
- repository.create_file(user, 'LICENSE',
- Licensee::License.new('mit').content,
- message: 'Add LICENSE', branch_name: 'master')
+ it "returns the license key" do
+ repository.create_file(user, "LICENSE",
+ Licensee::License.new("mit").content,
+ message: "Add LICENSE", branch_name: "master")
- expect(repository.license_key).to eq('mit')
+ expect(repository.license_key).to eq("mit")
end
end
- describe '#license' do
+ describe "#license" do
before do
- repository.delete_file(user, 'LICENSE',
- message: 'Remove LICENSE', branch_name: 'master')
+ repository.delete_file(user, "LICENSE",
+ message: "Remove LICENSE", branch_name: "master")
end
- it 'returns nil when no license is detected' do
+ it "returns nil when no license is detected" do
expect(repository.license).to be_nil
end
- it 'returns nil when the repository does not exist' do
+ it "returns nil when the repository does not exist" do
expect(repository).to receive(:exists?).and_return(false)
expect(repository.license).to be_nil
end
- it 'returns nil when the content is not recognizable' do
- repository.create_file(user, 'LICENSE', 'Gitlab B.V.',
- message: 'Add LICENSE', branch_name: 'master')
+ it "returns nil when the content is not recognizable" do
+ repository.create_file(user, "LICENSE", "Gitlab B.V.",
+ message: "Add LICENSE", branch_name: "master")
expect(repository.license).to be_nil
end
- it 'returns the license' do
- license = Licensee::License.new('mit')
- repository.create_file(user, 'LICENSE',
+ it "returns the license" do
+ license = Licensee::License.new("mit")
+ repository.create_file(user, "LICENSE",
license.content,
- message: 'Add LICENSE', branch_name: 'master')
+ message: "Add LICENSE", branch_name: "master")
expect(repository.license).to eq(license)
end
end
describe "#gitlab_ci_yml", :use_clean_rails_memory_store_caching do
- it 'returns valid file' do
- files = [TestBlob.new('file'), TestBlob.new('.gitlab-ci.yml'), TestBlob.new('copying')]
+ it "returns valid file" do
+ files = [TestBlob.new("file"), TestBlob.new(".gitlab-ci.yml"), TestBlob.new("copying")]
expect(repository.tree).to receive(:blobs).and_return(files)
- expect(repository.gitlab_ci_yml.path).to eq('.gitlab-ci.yml')
+ expect(repository.gitlab_ci_yml.path).to eq(".gitlab-ci.yml")
end
- it 'returns nil if not exists' do
+ it "returns nil if not exists" do
expect(repository.tree).to receive(:blobs).and_return([])
expect(repository.gitlab_ci_yml).to be_nil
end
- it 'returns nil for empty repository' do
+ it "returns nil for empty repository" do
allow(repository).to receive(:root_ref).and_raise(Gitlab::Git::Repository::NoRepository)
expect(repository.gitlab_ci_yml).to be_nil
end
end
- describe '#ambiguous_ref?' do
- let(:ref) { 'ref' }
+ describe "#ambiguous_ref?" do
+ let(:ref) { "ref" }
subject { repository.ambiguous_ref?(ref) }
- context 'when ref is ambiguous' do
+ context "when ref is ambiguous" do
before do
- repository.add_tag(project.creator, ref, 'master')
- repository.add_branch(project.creator, ref, 'master')
+ repository.add_tag(project.creator, ref, "master")
+ repository.add_branch(project.creator, ref, "master")
end
- it 'should be true' do
+ it "should be true" do
is_expected.to eq(true)
end
end
- context 'when ref is not ambiguous' do
+ context "when ref is not ambiguous" do
before do
- repository.add_tag(project.creator, ref, 'master')
+ repository.add_tag(project.creator, ref, "master")
end
- it 'should be false' do
+ it "should be false" do
is_expected.to eq(false)
end
end
end
- describe '#expand_ref' do
- let(:ref) { 'ref' }
+ describe "#expand_ref" do
+ let(:ref) { "ref" }
subject { repository.expand_ref(ref) }
- context 'when ref is not tag or branch name' do
- let(:ref) { 'refs/heads/master' }
+ context "when ref is not tag or branch name" do
+ let(:ref) { "refs/heads/master" }
- it 'returns nil' do
+ it "returns nil" do
is_expected.to eq(nil)
end
end
- context 'when ref is tag name' do
+ context "when ref is tag name" do
before do
- repository.add_tag(project.creator, ref, 'master')
+ repository.add_tag(project.creator, ref, "master")
end
- it 'returns the tag ref' do
+ it "returns the tag ref" do
is_expected.to eq("refs/tags/#{ref}")
end
end
- context 'when ref is branch name' do
+ context "when ref is branch name" do
before do
- repository.add_branch(project.creator, ref, 'master')
+ repository.add_branch(project.creator, ref, "master")
end
- it 'returns the branch ref' do
+ it "returns the branch ref" do
is_expected.to eq("refs/heads/#{ref}")
end
end
end
- describe '#add_branch' do
- let(:branch_name) { 'new_feature' }
- let(:target) { 'master' }
+ describe "#add_branch" do
+ let(:branch_name) { "new_feature" }
+ let(:target) { "master" }
subject { repository.add_branch(user, branch_name, target) }
@@ -1080,13 +1082,13 @@ describe Repository do
subject
end
- it 'creates_the_branch' do
+ it "creates_the_branch" do
expect(subject.name).to eq(branch_name)
expect(repository.find_branch(branch_name)).not_to be_nil
end
- context 'with a non-existing target' do
- let(:target) { 'fake-target' }
+ context "with a non-existing target" do
+ let(:target) { "fake-target" }
it "returns false and doesn't create the branch" do
expect(subject).to be(false)
@@ -1095,66 +1097,66 @@ describe Repository do
end
end
- describe '#exists?' do
- it 'returns true when a repository exists' do
+ describe "#exists?" do
+ it "returns true when a repository exists" do
expect(repository.exists?).to be(true)
end
- it 'returns false if no full path can be constructed' do
+ it "returns false if no full path can be constructed" do
allow(repository).to receive(:full_path).and_return(nil)
expect(repository.exists?).to be(false)
end
- context 'with broken storage', :broken_storage do
- it 'should raise a storage error' do
+ context "with broken storage", :broken_storage do
+ it "should raise a storage error" do
expect_to_raise_storage_error { broken_repository.exists? }
end
end
- context 'asymmetric caching', :use_clean_rails_memory_store_caching, :request_store do
+ context "asymmetric caching", :use_clean_rails_memory_store_caching, :request_store do
let(:cache) { repository.send(:cache) }
let(:request_store_cache) { repository.send(:request_store_cache) }
- context 'when it returns true' do
+ context "when it returns true" do
before do
expect(repository.raw_repository).to receive(:exists?).once.and_return(true)
end
- it 'caches the output in RequestStore' do
- expect do
+ it "caches the output in RequestStore" do
+ expect {
repository.exists?
- end.to change { request_store_cache.read(:exists?) }.from(nil).to(true)
+ }.to change { request_store_cache.read(:exists?) }.from(nil).to(true)
end
- it 'caches the output in RepositoryCache' do
- expect do
+ it "caches the output in RepositoryCache" do
+ expect {
repository.exists?
- end.to change { cache.read(:exists?) }.from(nil).to(true)
+ }.to change { cache.read(:exists?) }.from(nil).to(true)
end
end
- context 'when it returns false' do
+ context "when it returns false" do
before do
expect(repository.raw_repository).to receive(:exists?).once.and_return(false)
end
- it 'caches the output in RequestStore' do
- expect do
+ it "caches the output in RequestStore" do
+ expect {
repository.exists?
- end.to change { request_store_cache.read(:exists?) }.from(nil).to(false)
+ }.to change { request_store_cache.read(:exists?) }.from(nil).to(false)
end
- it 'does NOT cache the output in RepositoryCache' do
- expect do
+ it "does NOT cache the output in RepositoryCache" do
+ expect {
repository.exists?
- end.not_to change { cache.read(:exists?) }.from(nil)
+ }.not_to change { cache.read(:exists?) }.from(nil)
end
end
end
end
- describe '#has_visible_content?' do
+ describe "#has_visible_content?" do
before do
# If raw_repository.has_visible_content? gets called more than once then
# caching is broken. We don't want that.
@@ -1163,20 +1165,20 @@ describe Repository do
.and_return(result)
end
- context 'when true' do
+ context "when true" do
let(:result) { true }
- it 'returns true and caches it' do
+ it "returns true and caches it" do
expect(repository.has_visible_content?).to eq(true)
# Second call hits the cache
expect(repository.has_visible_content?).to eq(true)
end
end
- context 'when false' do
+ context "when false" do
let(:result) { false }
- it 'returns false and caches it' do
+ it "returns false and caches it" do
expect(repository.has_visible_content?).to eq(false)
# Second call hits the cache
expect(repository.has_visible_content?).to eq(false)
@@ -1184,28 +1186,28 @@ describe Repository do
end
end
- describe '#branch_exists?' do
- it 'uses branch_names' do
- allow(repository).to receive(:branch_names).and_return(['foobar'])
+ describe "#branch_exists?" do
+ it "uses branch_names" do
+ allow(repository).to receive(:branch_names).and_return(["foobar"])
- expect(repository.branch_exists?('foobar')).to eq(true)
- expect(repository.branch_exists?('master')).to eq(false)
+ expect(repository.branch_exists?("foobar")).to eq(true)
+ expect(repository.branch_exists?("master")).to eq(false)
end
end
- describe '#tag_exists?' do
- it 'uses tag_names' do
- allow(repository).to receive(:tag_names).and_return(['foobar'])
+ describe "#tag_exists?" do
+ it "uses tag_names" do
+ allow(repository).to receive(:tag_names).and_return(["foobar"])
- expect(repository.tag_exists?('foobar')).to eq(true)
- expect(repository.tag_exists?('master')).to eq(false)
+ expect(repository.tag_exists?("foobar")).to eq(true)
+ expect(repository.tag_exists?("master")).to eq(false)
end
end
- describe '#branch_names', :use_clean_rails_memory_store_caching do
- let(:fake_branch_names) { ['foobar'] }
+ describe "#branch_names", :use_clean_rails_memory_store_caching do
+ let(:fake_branch_names) { ["foobar"] }
- it 'gets cached across Repository instances' do
+ it "gets cached across Repository instances" do
allow(repository.raw_repository).to receive(:branch_names).once.and_return(fake_branch_names)
expect(repository.branch_names).to eq(fake_branch_names)
@@ -1218,18 +1220,18 @@ describe Repository do
end
end
- describe '#empty?' do
+ describe "#empty?" do
let(:empty_repository) { create(:project_empty_repo).repository }
- it 'returns true for an empty repository' do
+ it "returns true for an empty repository" do
expect(empty_repository).to be_empty
end
- it 'returns false for a non-empty repository' do
+ it "returns false for a non-empty repository" do
expect(repository).not_to be_empty
end
- it 'caches the output' do
+ it "caches the output" do
expect(repository.raw_repository).to receive(:has_visible_content?).once
repository.empty?
@@ -1237,62 +1239,62 @@ describe Repository do
end
end
- describe '#blobs_at' do
+ describe "#blobs_at" do
let(:empty_repository) { create(:project_empty_repo).repository }
- it 'returns empty array for an empty repository' do
+ it "returns empty array for an empty repository" do
# rubocop:disable Style/WordArray
- expect(empty_repository.blobs_at(['master', 'foobar'])).to eq([])
+ expect(empty_repository.blobs_at(["master", "foobar"])).to eq([])
# rubocop:enable Style/WordArray
end
- it 'returns blob array for a non-empty repository' do
- repository.create_file(User.last, 'foobar', 'CONTENT', message: 'message', branch_name: 'master')
+ it "returns blob array for a non-empty repository" do
+ repository.create_file(User.last, "foobar", "CONTENT", message: "message", branch_name: "master")
# rubocop:disable Style/WordArray
- blobs = repository.blobs_at([['master', 'foobar']])
+ blobs = repository.blobs_at([["master", "foobar"]])
# rubocop:enable Style/WordArray
- expect(blobs.first.name).to eq('foobar')
+ expect(blobs.first.name).to eq("foobar")
expect(blobs.size).to eq(1)
end
end
- describe '#root_ref' do
- it 'returns a branch name' do
+ describe "#root_ref" do
+ it "returns a branch name" do
expect(repository.root_ref).to be_an_instance_of(String)
end
- it 'caches the output' do
+ it "caches the output" do
expect(repository.raw_repository).to receive(:root_ref)
.once
- .and_return('master')
+ .and_return("master")
repository.root_ref
repository.root_ref
end
end
- describe '#expire_root_ref_cache' do
- it 'expires the root reference cache' do
+ describe "#expire_root_ref_cache" do
+ it "expires the root reference cache" do
repository.root_ref
expect(repository.raw_repository).to receive(:root_ref)
.once
- .and_return('foo')
+ .and_return("foo")
repository.expire_root_ref_cache
- expect(repository.root_ref).to eq('foo')
+ expect(repository.root_ref).to eq("foo")
end
end
- describe '#expire_branch_cache' do
+ describe "#expire_branch_cache" do
# This method is private but we need it for testing purposes. Sadly there's
# no other proper way of testing caching operations.
let(:cache) { repository.send(:cache) }
- it 'expires the cache for all branches' do
+ it "expires the cache for all branches" do
expect(cache).to receive(:expire)
.at_least(repository.branches.length * 2)
.times
@@ -1300,7 +1302,7 @@ describe Repository do
repository.expire_branch_cache
end
- it 'expires the cache for all branches when the root branch is given' do
+ it "expires the cache for all branches when the root branch is given" do
expect(cache).to receive(:expire)
.at_least(repository.branches.length * 2)
.times
@@ -1308,17 +1310,17 @@ describe Repository do
repository.expire_branch_cache(repository.root_ref)
end
- it 'expires the cache for a specific branch' do
+ it "expires the cache for a specific branch" do
expect(cache).to receive(:expire).twice
- repository.expire_branch_cache('foo')
+ repository.expire_branch_cache("foo")
end
end
- describe '#expire_emptiness_caches' do
+ describe "#expire_emptiness_caches" do
let(:cache) { repository.send(:cache) }
- it 'expires the caches for an empty repository' do
+ it "expires the caches for an empty repository" do
allow(repository).to receive(:empty?).and_return(true)
expect(cache).to receive(:expire).with(:has_visible_content?)
@@ -1326,7 +1328,7 @@ describe Repository do
repository.expire_emptiness_caches
end
- it 'does not expire the cache for a non-empty repository' do
+ it "does not expire the cache for a non-empty repository" do
allow(repository).to receive(:empty?).and_return(false)
expect(cache).not_to receive(:expire).with(:has_visible_content?)
@@ -1334,35 +1336,35 @@ describe Repository do
repository.expire_emptiness_caches
end
- it 'expires the memoized repository cache' do
+ it "expires the memoized repository cache" do
allow(repository.raw_repository).to receive(:expire_has_local_branches_cache).and_call_original
repository.expire_emptiness_caches
end
end
- describe 'skip_merges option' do
+ describe "skip_merges option" do
subject { repository.commits(Gitlab::Git::BRANCH_REF_PREFIX + "'test'", limit: 100, skip_merges: true).map { |k| k.id } }
- it { is_expected.not_to include('e56497bb5f03a90a51293fc6d516788730953899') }
+ it { is_expected.not_to include("e56497bb5f03a90a51293fc6d516788730953899") }
end
- describe '#merge' do
- let(:merge_request) { create(:merge_request, source_branch: 'feature', target_branch: 'master', source_project: project) }
+ describe "#merge" do
+ let(:merge_request) { create(:merge_request, source_branch: "feature", target_branch: "master", source_project: project) }
let(:message) { 'Test \r\n\r\n message' }
- it 'merges the code and returns the commit id' do
+ it "merges the code and returns the commit id" do
expect(merge_commit).to be_present
- expect(repository.blob_at(merge_commit.id, 'files/ruby/feature.rb')).to be_present
+ expect(repository.blob_at(merge_commit.id, "files/ruby/feature.rb")).to be_present
end
- it 'sets the `in_progress_merge_commit_sha` flag for the given merge request' do
+ it "sets the `in_progress_merge_commit_sha` flag for the given merge request" do
merge_commit_id = merge(repository, user, merge_request, message)
expect(merge_request.in_progress_merge_commit_sha).to eq(merge_commit_id)
end
- it 'removes carriage returns from commit message' do
+ it "removes carriage returns from commit message" do
merge_commit_id = merge(repository, user, merge_request, message)
expect(repository.commit(merge_commit_id).message).to eq(message.delete("\r"))
@@ -1373,199 +1375,199 @@ describe Repository do
end
end
- describe '#merge_to_ref' do
+ describe "#merge_to_ref" do
let(:merge_request) do
- create(:merge_request, source_branch: 'feature',
- target_branch: 'master',
+ create(:merge_request, source_branch: "feature",
+ target_branch: "master",
source_project: project)
end
- it 'writes merge of source and target to MR merge_ref_path' do
+ it "writes merge of source and target to MR merge_ref_path" do
merge_commit_id = repository.merge_to_ref(user,
- merge_request.diff_head_sha,
- merge_request,
- merge_request.merge_ref_path,
- 'Custom message')
+ merge_request.diff_head_sha,
+ merge_request,
+ merge_request.merge_ref_path,
+ "Custom message")
merge_commit = repository.commit(merge_commit_id)
- expect(merge_commit.message).to eq('Custom message')
+ expect(merge_commit.message).to eq("Custom message")
expect(merge_commit.author_name).to eq(user.name)
expect(merge_commit.author_email).to eq(user.commit_email)
- expect(repository.blob_at(merge_commit.id, 'files/ruby/feature.rb')).to be_present
+ expect(repository.blob_at(merge_commit.id, "files/ruby/feature.rb")).to be_present
end
end
- describe '#ff_merge' do
+ describe "#ff_merge" do
before do
- repository.add_branch(user, 'ff-target', 'feature~5')
+ repository.add_branch(user, "ff-target", "feature~5")
end
- it 'merges the code and return the commit id' do
- merge_request = create(:merge_request, source_branch: 'feature', target_branch: 'ff-target', source_project: project)
+ it "merges the code and return the commit id" do
+ merge_request = create(:merge_request, source_branch: "feature", target_branch: "ff-target", source_project: project)
merge_commit_id = repository.ff_merge(user,
- merge_request.diff_head_sha,
- merge_request.target_branch,
- merge_request: merge_request)
+ merge_request.diff_head_sha,
+ merge_request.target_branch,
+ merge_request: merge_request)
merge_commit = repository.commit(merge_commit_id)
expect(merge_commit).to be_present
- expect(repository.blob_at(merge_commit.id, 'files/ruby/feature.rb')).to be_present
+ expect(repository.blob_at(merge_commit.id, "files/ruby/feature.rb")).to be_present
end
- it 'sets the `in_progress_merge_commit_sha` flag for the given merge request' do
- merge_request = create(:merge_request, source_branch: 'feature', target_branch: 'ff-target', source_project: project)
+ it "sets the `in_progress_merge_commit_sha` flag for the given merge request" do
+ merge_request = create(:merge_request, source_branch: "feature", target_branch: "ff-target", source_project: project)
merge_commit_id = repository.ff_merge(user,
- merge_request.diff_head_sha,
- merge_request.target_branch,
- merge_request: merge_request)
+ merge_request.diff_head_sha,
+ merge_request.target_branch,
+ merge_request: merge_request)
expect(merge_request.in_progress_merge_commit_sha).to eq(merge_commit_id)
end
end
- describe '#revert' do
- let(:new_image_commit) { repository.commit('33f3729a45c02fc67d00adb1b8bca394b0e761d9') }
- let(:update_image_commit) { repository.commit('2f63565e7aac07bcdadb654e253078b727143ec4') }
- let(:message) { 'revert message' }
+ describe "#revert" do
+ let(:new_image_commit) { repository.commit("33f3729a45c02fc67d00adb1b8bca394b0e761d9") }
+ let(:update_image_commit) { repository.commit("2f63565e7aac07bcdadb654e253078b727143ec4") }
+ let(:message) { "revert message" }
- context 'when there is a conflict' do
- it 'raises an error' do
- expect { repository.revert(user, new_image_commit, 'master', message) }.to raise_error(Gitlab::Git::Repository::CreateTreeError)
+ context "when there is a conflict" do
+ it "raises an error" do
+ expect { repository.revert(user, new_image_commit, "master", message) }.to raise_error(Gitlab::Git::Repository::CreateTreeError)
end
end
- context 'when commit was already reverted' do
- it 'raises an error' do
- repository.revert(user, update_image_commit, 'master', message)
+ context "when commit was already reverted" do
+ it "raises an error" do
+ repository.revert(user, update_image_commit, "master", message)
- expect { repository.revert(user, update_image_commit, 'master', message) }.to raise_error(Gitlab::Git::Repository::CreateTreeError)
+ expect { repository.revert(user, update_image_commit, "master", message) }.to raise_error(Gitlab::Git::Repository::CreateTreeError)
end
end
- context 'when commit can be reverted' do
- it 'reverts the changes' do
- expect(repository.revert(user, update_image_commit, 'master', message)).to be_truthy
+ context "when commit can be reverted" do
+ it "reverts the changes" do
+ expect(repository.revert(user, update_image_commit, "master", message)).to be_truthy
end
end
- context 'reverting a merge commit' do
- it 'reverts the changes' do
+ context "reverting a merge commit" do
+ it "reverts the changes" do
merge_commit
- expect(repository.blob_at_branch('master', 'files/ruby/feature.rb')).to be_present
+ expect(repository.blob_at_branch("master", "files/ruby/feature.rb")).to be_present
- repository.revert(user, merge_commit, 'master', message)
- expect(repository.blob_at_branch('master', 'files/ruby/feature.rb')).not_to be_present
+ repository.revert(user, merge_commit, "master", message)
+ expect(repository.blob_at_branch("master", "files/ruby/feature.rb")).not_to be_present
end
end
end
- describe '#cherry_pick' do
- let(:conflict_commit) { repository.commit('c642fe9b8b9f28f9225d7ea953fe14e74748d53b') }
- let(:pickable_commit) { repository.commit('7d3b0f7cff5f37573aea97cebfd5692ea1689924') }
- let(:pickable_merge) { repository.commit('e56497bb5f03a90a51293fc6d516788730953899') }
- let(:message) { 'cherry-pick message' }
+ describe "#cherry_pick" do
+ let(:conflict_commit) { repository.commit("c642fe9b8b9f28f9225d7ea953fe14e74748d53b") }
+ let(:pickable_commit) { repository.commit("7d3b0f7cff5f37573aea97cebfd5692ea1689924") }
+ let(:pickable_merge) { repository.commit("e56497bb5f03a90a51293fc6d516788730953899") }
+ let(:message) { "cherry-pick message" }
- context 'when there is a conflict' do
- it 'raises an error' do
- expect { repository.cherry_pick(user, conflict_commit, 'master', message) }.to raise_error(Gitlab::Git::Repository::CreateTreeError)
+ context "when there is a conflict" do
+ it "raises an error" do
+ expect { repository.cherry_pick(user, conflict_commit, "master", message) }.to raise_error(Gitlab::Git::Repository::CreateTreeError)
end
end
- context 'when commit was already cherry-picked' do
- it 'raises an error' do
- repository.cherry_pick(user, pickable_commit, 'master', message)
+ context "when commit was already cherry-picked" do
+ it "raises an error" do
+ repository.cherry_pick(user, pickable_commit, "master", message)
- expect { repository.cherry_pick(user, pickable_commit, 'master', message) }.to raise_error(Gitlab::Git::Repository::CreateTreeError)
+ expect { repository.cherry_pick(user, pickable_commit, "master", message) }.to raise_error(Gitlab::Git::Repository::CreateTreeError)
end
end
- context 'when commit can be cherry-picked' do
- it 'cherry-picks the changes' do
- expect(repository.cherry_pick(user, pickable_commit, 'master', message)).to be_truthy
+ context "when commit can be cherry-picked" do
+ it "cherry-picks the changes" do
+ expect(repository.cherry_pick(user, pickable_commit, "master", message)).to be_truthy
end
end
- context 'cherry-picking a merge commit' do
- it 'cherry-picks the changes' do
- expect(repository.blob_at_branch('improve/awesome', 'foo/bar/.gitkeep')).to be_nil
+ context "cherry-picking a merge commit" do
+ it "cherry-picks the changes" do
+ expect(repository.blob_at_branch("improve/awesome", "foo/bar/.gitkeep")).to be_nil
- cherry_pick_commit_sha = repository.cherry_pick(user, pickable_merge, 'improve/awesome', message)
+ cherry_pick_commit_sha = repository.cherry_pick(user, pickable_merge, "improve/awesome", message)
cherry_pick_commit_message = project.commit(cherry_pick_commit_sha).message
- expect(repository.blob_at_branch('improve/awesome', 'foo/bar/.gitkeep')).not_to be_nil
+ expect(repository.blob_at_branch("improve/awesome", "foo/bar/.gitkeep")).not_to be_nil
expect(cherry_pick_commit_message).to eq(message)
end
end
end
- describe '#before_delete' do
- describe 'when a repository does not exist' do
+ describe "#before_delete" do
+ describe "when a repository does not exist" do
before do
allow(repository).to receive(:exists?).and_return(false)
end
- it 'does not flush caches that depend on repository data' do
+ it "does not flush caches that depend on repository data" do
expect(repository).not_to receive(:expire_cache)
repository.before_delete
end
- it 'flushes the tags cache' do
+ it "flushes the tags cache" do
expect(repository).to receive(:expire_tags_cache)
repository.before_delete
end
- it 'flushes the branches cache' do
+ it "flushes the branches cache" do
expect(repository).to receive(:expire_branches_cache)
repository.before_delete
end
- it 'flushes the root ref cache' do
+ it "flushes the root ref cache" do
expect(repository).to receive(:expire_root_ref_cache)
repository.before_delete
end
- it 'flushes the emptiness caches' do
+ it "flushes the emptiness caches" do
expect(repository).to receive(:expire_emptiness_caches)
repository.before_delete
end
- it 'flushes the exists cache' do
+ it "flushes the exists cache" do
expect(repository).to receive(:expire_exists_cache).twice
repository.before_delete
end
end
- describe 'when a repository exists' do
+ describe "when a repository exists" do
before do
allow(repository).to receive(:exists?).and_return(true)
end
- it 'flushes the tags cache' do
+ it "flushes the tags cache" do
expect(repository).to receive(:expire_tags_cache)
repository.before_delete
end
- it 'flushes the branches cache' do
+ it "flushes the branches cache" do
expect(repository).to receive(:expire_branches_cache)
repository.before_delete
end
- it 'flushes the root ref cache' do
+ it "flushes the root ref cache" do
expect(repository).to receive(:expire_root_ref_cache)
repository.before_delete
end
- it 'flushes the emptiness caches' do
+ it "flushes the emptiness caches" do
expect(repository).to receive(:expire_emptiness_caches)
repository.before_delete
@@ -1573,22 +1575,22 @@ describe Repository do
end
end
- describe '#before_change_head' do
- it 'flushes the branch cache' do
+ describe "#before_change_head" do
+ it "flushes the branch cache" do
expect(repository).to receive(:expire_branch_cache)
repository.before_change_head
end
- it 'flushes the root ref cache' do
+ it "flushes the root ref cache" do
expect(repository).to receive(:expire_root_ref_cache)
repository.before_change_head
end
end
- describe '#after_change_head' do
- it 'flushes the method caches' do
+ describe "#after_change_head" do
+ it "flushes the method caches" do
expect(repository).to receive(:expire_method_caches).with([
:size,
:commit_count,
@@ -1610,15 +1612,15 @@ describe Repository do
:has_visible_content?,
:issue_template_names,
:merge_request_template_names,
- :xcode_project?
+ :xcode_project?,
])
repository.after_change_head
end
end
- describe '#before_push_tag' do
- it 'flushes the cache' do
+ describe "#before_push_tag" do
+ it "flushes the cache" do
expect(repository).to receive(:expire_statistics_caches)
expect(repository).to receive(:expire_emptiness_caches)
expect(repository).to receive(:expire_tags_cache)
@@ -1627,57 +1629,57 @@ describe Repository do
end
end
- describe '#after_import' do
- it 'flushes and builds the cache' do
+ describe "#after_import" do
+ it "flushes and builds the cache" do
expect(repository).to receive(:expire_content_cache)
repository.after_import
end
end
- describe '#after_push_commit' do
- it 'expires statistics caches' do
+ describe "#after_push_commit" do
+ it "expires statistics caches" do
expect(repository).to receive(:expire_statistics_caches)
.and_call_original
expect(repository).to receive(:expire_branch_cache)
- .with('master')
+ .with("master")
.and_call_original
- repository.after_push_commit('master')
+ repository.after_push_commit("master")
end
end
- describe '#after_create_branch' do
- it 'expires the branch caches' do
+ describe "#after_create_branch" do
+ it "expires the branch caches" do
expect(repository).to receive(:expire_branches_cache)
repository.after_create_branch
end
end
- describe '#after_remove_branch' do
- it 'expires the branch caches' do
+ describe "#after_remove_branch" do
+ it "expires the branch caches" do
expect(repository).to receive(:expire_branches_cache)
repository.after_remove_branch
end
end
- describe '#after_create' do
- it 'flushes the exists cache' do
+ describe "#after_create" do
+ it "flushes the exists cache" do
expect(repository).to receive(:expire_exists_cache)
repository.after_create
end
- it 'flushes the root ref cache' do
+ it "flushes the root ref cache" do
expect(repository).to receive(:expire_root_ref_cache)
repository.after_create
end
- it 'flushes the emptiness caches' do
+ it "flushes the emptiness caches" do
expect(repository).to receive(:expire_emptiness_caches)
repository.after_create
@@ -1685,17 +1687,17 @@ describe Repository do
end
describe "#copy_gitattributes" do
- it 'returns true with a valid ref' do
- expect(repository.copy_gitattributes('master')).to be_truthy
+ it "returns true with a valid ref" do
+ expect(repository.copy_gitattributes("master")).to be_truthy
end
- it 'returns false with an invalid ref' do
- expect(repository.copy_gitattributes('invalid')).to be_falsey
+ it "returns false with an invalid ref" do
+ expect(repository.copy_gitattributes("invalid")).to be_falsey
end
end
- describe '#before_remove_tag' do
- it 'flushes the tag cache' do
+ describe "#before_remove_tag" do
+ it "flushes the tag cache" do
expect(repository).to receive(:expire_tags_cache).and_call_original
expect(repository).to receive(:expire_statistics_caches).and_call_original
@@ -1703,8 +1705,8 @@ describe Repository do
end
end
- describe '#branch_count' do
- it 'returns the number of branches' do
+ describe "#branch_count" do
+ it "returns the number of branches" do
expect(repository.branch_count).to be_an(Integer)
rugged_count = rugged_repo(repository).branches.count
@@ -1713,8 +1715,8 @@ describe Repository do
end
end
- describe '#tag_count' do
- it 'returns the number of tags' do
+ describe "#tag_count" do
+ it "returns the number of tags" do
expect(repository.tag_count).to be_an(Integer)
rugged_count = rugged_repo(repository).tags.count
@@ -1723,154 +1725,154 @@ describe Repository do
end
end
- describe '#expire_branches_cache' do
- it 'expires the cache' do
+ describe "#expire_branches_cache" do
+ it "expires the cache" do
expect(repository).to receive(:expire_method_caches)
- .with(%i(branch_names branch_count has_visible_content?))
+ .with(%i[branch_names branch_count has_visible_content?])
.and_call_original
repository.expire_branches_cache
end
end
- describe '#expire_tags_cache' do
- it 'expires the cache' do
+ describe "#expire_tags_cache" do
+ it "expires the cache" do
expect(repository).to receive(:expire_method_caches)
- .with(%i(tag_names tag_count))
+ .with(%i[tag_names tag_count])
.and_call_original
repository.expire_tags_cache
end
end
- describe '#add_tag' do
+ describe "#add_tag" do
let(:user) { build_stubbed(:user) }
- context 'with a valid target' do
- it 'creates the tag' do
- repository.add_tag(user, '8.5', 'master', 'foo')
+ context "with a valid target" do
+ it "creates the tag" do
+ repository.add_tag(user, "8.5", "master", "foo")
- tag = repository.find_tag('8.5')
+ tag = repository.find_tag("8.5")
expect(tag).to be_present
- expect(tag.message).to eq('foo')
- expect(tag.dereferenced_target.id).to eq(repository.commit('master').id)
+ expect(tag.message).to eq("foo")
+ expect(tag.dereferenced_target.id).to eq(repository.commit("master").id)
end
- it 'returns a Gitlab::Git::Tag object' do
- tag = repository.add_tag(user, '8.5', 'master', 'foo')
+ it "returns a Gitlab::Git::Tag object" do
+ tag = repository.add_tag(user, "8.5", "master", "foo")
expect(tag).to be_a(Gitlab::Git::Tag)
end
end
- context 'with an invalid target' do
- it 'returns false' do
- expect(repository.add_tag(user, '8.5', 'bar', 'foo')).to be false
+ context "with an invalid target" do
+ it "returns false" do
+ expect(repository.add_tag(user, "8.5", "bar", "foo")).to be false
end
end
end
- describe '#rm_branch' do
- it 'removes a branch' do
+ describe "#rm_branch" do
+ it "removes a branch" do
expect(repository).to receive(:before_remove_branch)
expect(repository).to receive(:after_remove_branch)
- repository.rm_branch(user, 'feature')
+ repository.rm_branch(user, "feature")
end
- context 'when pre hooks failed' do
+ context "when pre hooks failed" do
before do
allow_any_instance_of(Gitlab::GitalyClient::OperationService)
.to receive(:user_delete_branch).and_raise(Gitlab::Git::PreReceiveError)
end
- it 'gets an error and does not delete the branch' do
- expect do
- repository.rm_branch(user, 'feature')
- end.to raise_error(Gitlab::Git::PreReceiveError)
+ it "gets an error and does not delete the branch" do
+ expect {
+ repository.rm_branch(user, "feature")
+ }.to raise_error(Gitlab::Git::PreReceiveError)
- expect(repository.find_branch('feature')).not_to be_nil
+ expect(repository.find_branch("feature")).not_to be_nil
end
end
end
- describe '#rm_tag' do
- it 'removes a tag' do
+ describe "#rm_tag" do
+ it "removes a tag" do
expect(repository).to receive(:before_remove_tag)
- repository.rm_tag(build_stubbed(:user), 'v1.1.0')
+ repository.rm_tag(build_stubbed(:user), "v1.1.0")
- expect(repository.find_tag('v1.1.0')).to be_nil
+ expect(repository.find_tag("v1.1.0")).to be_nil
end
end
- describe '#avatar' do
- it 'returns nil if repo does not exist' do
+ describe "#avatar" do
+ it "returns nil if repo does not exist" do
allow(repository).to receive(:root_ref).and_raise(Gitlab::Git::Repository::NoRepository)
expect(repository.avatar).to eq(nil)
end
- it 'returns the first avatar file found in the repository' do
+ it "returns the first avatar file found in the repository" do
expect(repository).to receive(:file_on_head)
.with(:avatar)
- .and_return(double(:tree, path: 'logo.png'))
+ .and_return(double(:tree, path: "logo.png"))
- expect(repository.avatar).to eq('logo.png')
+ expect(repository.avatar).to eq("logo.png")
end
- it 'caches the output' do
+ it "caches the output" do
expect(repository).to receive(:file_on_head)
.with(:avatar)
.once
- .and_return(double(:tree, path: 'logo.png'))
+ .and_return(double(:tree, path: "logo.png"))
- 2.times { expect(repository.avatar).to eq('logo.png') }
+ 2.times { expect(repository.avatar).to eq("logo.png") }
end
end
- describe '#expire_exists_cache' do
+ describe "#expire_exists_cache" do
let(:cache) { repository.send(:cache) }
let(:request_store_cache) { repository.send(:request_store_cache) }
- it 'expires the cache' do
+ it "expires the cache" do
expect(cache).to receive(:expire).with(:exists?)
repository.expire_exists_cache
end
- it 'expires the request store cache', :request_store do
+ it "expires the request store cache", :request_store do
expect(request_store_cache).to receive(:expire).with(:exists?)
repository.expire_exists_cache
end
end
- describe '#xcode_project?' do
+ describe "#xcode_project?" do
before do
allow(repository).to receive(:tree).with(:head).and_return(double(:tree, trees: [tree]))
end
- context 'when the root contains a *.xcodeproj directory' do
- let(:tree) { double(:tree, path: 'Foo.xcodeproj') }
+ context "when the root contains a *.xcodeproj directory" do
+ let(:tree) { double(:tree, path: "Foo.xcodeproj") }
- it 'returns true' do
+ it "returns true" do
expect(repository.xcode_project?).to be_truthy
end
end
- context 'when the root contains a *.xcworkspace directory' do
- let(:tree) { double(:tree, path: 'Foo.xcworkspace') }
+ context "when the root contains a *.xcworkspace directory" do
+ let(:tree) { double(:tree, path: "Foo.xcworkspace") }
- it 'returns true' do
+ it "returns true" do
expect(repository.xcode_project?).to be_truthy
end
end
- context 'when the root contains no Xcode config directory' do
- let(:tree) { double(:tree, path: 'Foo') }
+ context "when the root contains no Xcode config directory" do
+ let(:tree) { double(:tree, path: "Foo") }
- it 'returns false' do
+ it "returns false" do
expect(repository.xcode_project?).to be_falsey
end
end
@@ -1878,7 +1880,7 @@ describe Repository do
describe "#keep_around" do
it "does not fail if we attempt to reference bad commit" do
- expect(repository.kept_around?('abc1234')).to be_falsey
+ expect(repository.kept_around?("abc1234")).to be_falsey
end
it "stores a reference to the specified commit sha so it isn't garbage collected" do
@@ -1891,9 +1893,9 @@ describe Repository do
repository.keep_around(sample_commit.id)
ref = repository.send(:keep_around_ref_name, sample_commit.id)
- path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ path = Gitlab::GitalyClient::StorageSettings.allow_disk_access {
File.join(repository.path, ref)
- end
+ }
# Corrupt the reference
File.truncate(path, 0)
@@ -1906,14 +1908,14 @@ describe Repository do
File.delete(path)
end
- context 'for multiple SHAs' do
- it 'skips non-existent SHAs' do
- repository.keep_around('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', sample_commit.id)
+ context "for multiple SHAs" do
+ it "skips non-existent SHAs" do
+ repository.keep_around("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", sample_commit.id)
expect(repository.kept_around?(sample_commit.id)).to be_truthy
end
- it 'skips already-kept-around SHAs' do
+ it "skips already-kept-around SHAs" do
repository.keep_around(sample_commit.id)
expect(repository.raw_repository).to receive(:write_ref).exactly(1).and_call_original
@@ -1925,11 +1927,11 @@ describe Repository do
end
end
- describe '#contribution_guide', :use_clean_rails_memory_store_caching do
- it 'returns and caches the output' do
+ describe "#contribution_guide", :use_clean_rails_memory_store_caching do
+ it "returns and caches the output" do
expect(repository).to receive(:file_on_head)
.with(:contributing)
- .and_return(Gitlab::Git::Tree.new(path: 'CONTRIBUTING.md'))
+ .and_return(Gitlab::Git::Tree.new(path: "CONTRIBUTING.md"))
.once
2.times do
@@ -1939,11 +1941,11 @@ describe Repository do
end
end
- describe '#gitignore', :use_clean_rails_memory_store_caching do
- it 'returns and caches the output' do
+ describe "#gitignore", :use_clean_rails_memory_store_caching do
+ it "returns and caches the output" do
expect(repository).to receive(:file_on_head)
.with(:gitignore)
- .and_return(Gitlab::Git::Tree.new(path: '.gitignore'))
+ .and_return(Gitlab::Git::Tree.new(path: ".gitignore"))
.once
2.times do
@@ -1952,60 +1954,60 @@ describe Repository do
end
end
- describe '#readme', :use_clean_rails_memory_store_caching do
- context 'with a non-existing repository' do
+ describe "#readme", :use_clean_rails_memory_store_caching do
+ context "with a non-existing repository" do
let(:project) { create(:project) }
- it 'returns nil' do
+ it "returns nil" do
expect(repository.readme).to be_nil
end
end
- context 'with an existing repository' do
- context 'when no README exists' do
+ context "with an existing repository" do
+ context "when no README exists" do
let(:project) { create(:project, :empty_repo) }
- it 'returns nil' do
+ it "returns nil" do
expect(repository.readme).to be_nil
end
end
- context 'when a README exists' do
+ context "when a README exists" do
let(:project) { create(:project, :repository) }
- it 'returns the README' do
+ it "returns the README" do
expect(repository.readme).to be_an_instance_of(ReadmeBlob)
end
end
end
end
- describe '#readme_path', :use_clean_rails_memory_store_caching do
- context 'with a non-existing repository' do
+ describe "#readme_path", :use_clean_rails_memory_store_caching do
+ context "with a non-existing repository" do
let(:project) { create(:project) }
- it 'returns nil' do
+ it "returns nil" do
expect(repository.readme_path).to be_nil
end
end
- context 'with an existing repository' do
- context 'when no README exists' do
+ context "with an existing repository" do
+ context "when no README exists" do
let(:project) { create(:project, :empty_repo) }
- it 'returns nil' do
+ it "returns nil" do
expect(repository.readme_path).to be_nil
end
end
- context 'when a README exists' do
+ context "when a README exists" do
let(:project) { create(:project, :repository) }
- it 'returns the README' do
+ it "returns the README" do
expect(repository.readme_path).to eq("README.md")
end
- it 'caches the response' do
+ it "caches the response" do
expect(repository).to receive(:readme).and_call_original.once
2.times do
@@ -2016,67 +2018,67 @@ describe Repository do
end
end
- describe '#expire_statistics_caches' do
- it 'expires the caches' do
+ describe "#expire_statistics_caches" do
+ it "expires the caches" do
expect(repository).to receive(:expire_method_caches)
- .with(%i(size commit_count))
+ .with(%i[size commit_count])
repository.expire_statistics_caches
end
end
- describe '#expire_all_method_caches' do
- it 'expires the caches of all methods' do
+ describe "#expire_all_method_caches" do
+ it "expires the caches of all methods" do
expect(repository).to receive(:expire_method_caches)
.with(Repository::CACHED_METHODS)
repository.expire_all_method_caches
end
- it 'all cache_method definitions are in the lists of method caches' do
- methods = repository.methods.map do |method|
+ it "all cache_method definitions are in the lists of method caches" do
+ methods = repository.methods.map { |method|
match = /^_uncached_(.*)/.match(method)
match[1].to_sym if match
- end.compact
+ }.compact
expect(Repository::CACHED_METHODS + Repository::MEMOIZED_CACHED_METHODS).to include(*methods)
end
end
- describe '#file_on_head' do
- context 'with a non-existing repository' do
- it 'returns nil' do
+ describe "#file_on_head" do
+ context "with a non-existing repository" do
+ it "returns nil" do
expect(repository).to receive(:tree).with(:head).and_return(nil)
expect(repository.file_on_head(:readme)).to be_nil
end
end
- context 'with a repository that has no blobs' do
- it 'returns nil' do
+ context "with a repository that has no blobs" do
+ it "returns nil" do
expect_any_instance_of(Tree).to receive(:blobs).and_return([])
expect(repository.file_on_head(:readme)).to be_nil
end
end
- context 'with an existing repository' do
- it 'returns a Gitlab::Git::Tree' do
+ context "with an existing repository" do
+ it "returns a Gitlab::Git::Tree" do
expect(repository.file_on_head(:readme))
.to be_an_instance_of(Gitlab::Git::Tree)
end
end
end
- describe '#head_tree' do
- context 'with an existing repository' do
- it 'returns a Tree' do
+ describe "#head_tree" do
+ context "with an existing repository" do
+ it "returns a Tree" do
expect(repository.head_tree).to be_an_instance_of(Tree)
end
end
- context 'with a non-existing repository' do
- it 'returns nil' do
+ context "with a non-existing repository" do
+ it "returns nil" do
expect(repository).to receive(:head_commit).and_return(nil)
expect(repository.head_tree).to be_nil
@@ -2084,107 +2086,108 @@ describe Repository do
end
end
- describe '#tree' do
- context 'using a non-existing repository' do
+ describe "#tree" do
+ context "using a non-existing repository" do
before do
allow(repository).to receive(:head_commit).and_return(nil)
end
- it 'returns nil' do
+ it "returns nil" do
expect(repository.tree(:head)).to be_nil
end
- it 'returns nil when using a path' do
- expect(repository.tree(:head, 'README.md')).to be_nil
+ it "returns nil when using a path" do
+ expect(repository.tree(:head, "README.md")).to be_nil
end
end
- context 'using an existing repository' do
- it 'returns a Tree' do
+ context "using an existing repository" do
+ it "returns a Tree" do
expect(repository.tree(:head)).to be_an_instance_of(Tree)
end
end
end
- describe '#size' do
- context 'with a non-existing repository' do
- it 'returns 0' do
+ describe "#size" do
+ context "with a non-existing repository" do
+ it "returns 0" do
expect(repository).to receive(:exists?).and_return(false)
expect(repository.size).to eq(0.0)
end
end
- context 'with an existing repository' do
- it 'returns the repository size as a Float' do
+ context "with an existing repository" do
+ it "returns the repository size as a Float" do
expect(repository.size).to be_an_instance_of(Float)
end
end
end
- describe '#local_branches' do
- it 'returns the local branches' do
- masterrev = repository.find_branch('master').dereferenced_target
- create_remote_branch('joe', 'remote_branch', masterrev)
- repository.add_branch(user, 'local_branch', masterrev.id)
+ describe "#local_branches" do
+ it "returns the local branches" do
+ masterrev = repository.find_branch("master").dereferenced_target
+ create_remote_branch("joe", "remote_branch", masterrev)
+ repository.add_branch(user, "local_branch", masterrev.id)
- expect(repository.local_branches.any? { |branch| branch.name == 'remote_branch' }).to eq(false)
- expect(repository.local_branches.any? { |branch| branch.name == 'local_branch' }).to eq(true)
+ expect(repository.local_branches.any? { |branch| branch.name == "remote_branch" }).to eq(false)
+ expect(repository.local_branches.any? { |branch| branch.name == "local_branch" }).to eq(true)
end
end
- describe '#commit_count' do
- context 'with a non-existing repository' do
- it 'returns 0' do
+ describe "#commit_count" do
+ context "with a non-existing repository" do
+ it "returns 0" do
expect(repository).to receive(:root_ref).and_return(nil)
expect(repository.commit_count).to eq(0)
end
end
- context 'with an existing repository' do
- it 'returns the commit count' do
+ context "with an existing repository" do
+ it "returns the commit count" do
expect(repository.commit_count).to be_an(Integer)
end
end
end
- describe '#commit_count_for_ref' do
+ describe "#commit_count_for_ref" do
let(:project) { create :project }
- context 'with a non-existing repository' do
- it 'returns 0' do
- expect(project.repository.commit_count_for_ref('master')).to eq(0)
+ context "with a non-existing repository" do
+ it "returns 0" do
+ expect(project.repository.commit_count_for_ref("master")).to eq(0)
end
end
- context 'with empty repository' do
- it 'returns 0' do
+ context "with empty repository" do
+ it "returns 0" do
project.create_repository
- expect(project.repository.commit_count_for_ref('master')).to eq(0)
+ expect(project.repository.commit_count_for_ref("master")).to eq(0)
end
end
- context 'when searching for the root ref' do
- it 'returns the same count as #commit_count' do
+ context "when searching for the root ref" do
+ it "returns the same count as #commit_count" do
expect(repository.commit_count_for_ref(repository.root_ref)).to eq(repository.commit_count)
end
end
end
- describe '#diverging_commit_counts' do
- it 'returns the commit counts behind and ahead of default branch' do
+ describe "#diverging_commit_counts" do
+ it "returns the commit counts behind and ahead of default branch" do
result = repository.diverging_commit_counts(
- repository.find_branch('fix'))
+ repository.find_branch("fix")
+ )
expect(result).to eq(behind: 29, ahead: 2)
end
end
- describe '#refresh_method_caches' do
- it 'refreshes the caches of the given types' do
+ describe "#refresh_method_caches" do
+ it "refreshes the caches of the given types" do
expect(repository).to receive(:expire_method_caches)
- .with(%i(rendered_readme readme_path license_blob license_key license))
+ .with(%i[rendered_readme readme_path license_blob license_key license])
expect(repository).to receive(:rendered_readme)
expect(repository).to receive(:readme_path)
@@ -2192,41 +2195,41 @@ describe Repository do
expect(repository).to receive(:license_key)
expect(repository).to receive(:license)
- repository.refresh_method_caches(%i(readme license))
+ repository.refresh_method_caches(%i[readme license])
end
end
- describe '#gitlab_ci_yml_for' do
+ describe "#gitlab_ci_yml_for" do
before do
- repository.create_file(User.last, '.gitlab-ci.yml', 'CONTENT', message: 'Add .gitlab-ci.yml', branch_name: 'master')
+ repository.create_file(User.last, ".gitlab-ci.yml", "CONTENT", message: "Add .gitlab-ci.yml", branch_name: "master")
end
- context 'when there is a .gitlab-ci.yml at the commit' do
- it 'returns the content' do
- expect(repository.gitlab_ci_yml_for(repository.commit.sha)).to eq('CONTENT')
+ context "when there is a .gitlab-ci.yml at the commit" do
+ it "returns the content" do
+ expect(repository.gitlab_ci_yml_for(repository.commit.sha)).to eq("CONTENT")
end
end
- context 'when there is no .gitlab-ci.yml at the commit' do
- it 'returns nil' do
+ context "when there is no .gitlab-ci.yml at the commit" do
+ it "returns nil" do
expect(repository.gitlab_ci_yml_for(repository.commit.parent.sha)).to be_nil
end
end
end
- describe '#route_map_for' do
+ describe "#route_map_for" do
before do
- repository.create_file(User.last, '.gitlab/route-map.yml', 'CONTENT', message: 'Add .gitlab/route-map.yml', branch_name: 'master')
+ repository.create_file(User.last, ".gitlab/route-map.yml", "CONTENT", message: "Add .gitlab/route-map.yml", branch_name: "master")
end
- context 'when there is a .gitlab/route-map.yml at the commit' do
- it 'returns the content' do
- expect(repository.route_map_for(repository.commit.sha)).to eq('CONTENT')
+ context "when there is a .gitlab/route-map.yml at the commit" do
+ it "returns the content" do
+ expect(repository.route_map_for(repository.commit.sha)).to eq("CONTENT")
end
end
- context 'when there is no .gitlab/route-map.yml at the commit' do
- it 'returns nil' do
+ context "when there is no .gitlab/route-map.yml at the commit" do
+ it "returns nil" do
expect(repository.route_map_for(repository.commit.parent.sha)).to be_nil
end
end
@@ -2237,60 +2240,60 @@ describe Repository do
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", target.id)
end
- describe '#ancestor?' do
+ describe "#ancestor?" do
let(:commit) { repository.commit }
let(:ancestor) { commit.parents.first }
- it 'it is an ancestor' do
+ it "it is an ancestor" do
expect(repository.ancestor?(ancestor.id, commit.id)).to eq(true)
end
- it 'it is not an ancestor' do
+ it "it is not an ancestor" do
expect(repository.ancestor?(commit.id, ancestor.id)).to eq(false)
end
- it 'returns false on nil-values' do
+ it "returns false on nil-values" do
expect(repository.ancestor?(nil, commit.id)).to eq(false)
expect(repository.ancestor?(ancestor.id, nil)).to eq(false)
expect(repository.ancestor?(nil, nil)).to eq(false)
end
- it 'returns false for invalid commit IDs' do
+ it "returns false for invalid commit IDs" do
expect(repository.ancestor?(commit.id, Gitlab::Git::BLANK_SHA)).to eq(false)
- expect(repository.ancestor?( Gitlab::Git::BLANK_SHA, commit.id)).to eq(false)
+ expect(repository.ancestor?(Gitlab::Git::BLANK_SHA, commit.id)).to eq(false)
end
end
- describe '#archive_metadata' do
- let(:ref) { 'master' }
- let(:storage_path) { '/tmp' }
+ describe "#archive_metadata" do
+ let(:ref) { "master" }
+ let(:storage_path) { "/tmp" }
- let(:prefix) { [project.path, ref].join('-') }
- let(:filename) { prefix + '.tar.gz' }
+ let(:prefix) { [project.path, ref].join("-") }
+ let(:filename) { prefix + ".tar.gz" }
subject(:result) { repository.archive_metadata(ref, storage_path, append_sha: false) }
- context 'with hashed storage disabled' do
+ context "with hashed storage disabled" do
let(:project) { create(:project, :repository, :legacy_storage) }
- it 'uses the project path to generate the filename' do
- expect(result['ArchivePrefix']).to eq(prefix)
- expect(File.basename(result['ArchivePath'])).to eq(filename)
+ it "uses the project path to generate the filename" do
+ expect(result["ArchivePrefix"]).to eq(prefix)
+ expect(File.basename(result["ArchivePath"])).to eq(filename)
end
end
- context 'with hashed storage enabled' do
- it 'uses the project path to generate the filename' do
- expect(result['ArchivePrefix']).to eq(prefix)
- expect(File.basename(result['ArchivePath'])).to eq(filename)
+ context "with hashed storage enabled" do
+ it "uses the project path to generate the filename" do
+ expect(result["ArchivePrefix"]).to eq(prefix)
+ expect(File.basename(result["ArchivePath"])).to eq(filename)
end
end
end
- describe 'commit cache' do
+ describe "commit cache" do
set(:project) { create(:project, :repository) }
- it 'caches based on SHA' do
+ it "caches based on SHA" do
# Gets the commit oid, and warms the cache
oid = project.commit.id
@@ -2299,47 +2302,47 @@ describe Repository do
project.commit_by(oid: oid)
end
- it 'caches nil values' do
+ it "caches nil values" do
expect(Gitlab::Git::Commit).to receive(:find).once
- project.commit_by(oid: '1' * 40)
- project.commit_by(oid: '1' * 40)
+ project.commit_by(oid: "1" * 40)
+ project.commit_by(oid: "1" * 40)
end
end
- describe '#raw_repository' do
+ describe "#raw_repository" do
subject { repository.raw_repository }
- it 'returns a Gitlab::Git::Repository representation of the repository' do
+ it "returns a Gitlab::Git::Repository representation of the repository" do
expect(subject).to be_a(Gitlab::Git::Repository)
- expect(subject.relative_path).to eq(project.disk_path + '.git')
+ expect(subject.relative_path).to eq(project.disk_path + ".git")
expect(subject.gl_repository).to eq("project-#{project.id}")
expect(subject.gl_project_path).to eq(project.full_path)
end
- context 'with a wiki repository' do
+ context "with a wiki repository" do
let(:repository) { project.wiki.repository }
- it 'creates a Gitlab::Git::Repository with the proper attributes' do
+ it "creates a Gitlab::Git::Repository with the proper attributes" do
expect(subject).to be_a(Gitlab::Git::Repository)
- expect(subject.relative_path).to eq(project.disk_path + '.wiki.git')
+ expect(subject.relative_path).to eq(project.disk_path + ".wiki.git")
expect(subject.gl_repository).to eq("wiki-#{project.id}")
expect(subject.gl_project_path).to eq(project.full_path)
end
end
end
- describe '#contributors' do
- let(:author_a) { build(:author, email: 'tiagonbotelho@hotmail.com', name: 'tiagonbotelho') }
- let(:author_b) { build(:author, email: 'gitlab@winniehell.de', name: 'Winnie') }
- let(:author_c) { build(:author, email: 'douwe@gitlab.com', name: 'Douwe Maan') }
+ describe "#contributors" do
+ let(:author_a) { build(:author, email: "tiagonbotelho@hotmail.com", name: "tiagonbotelho") }
+ let(:author_b) { build(:author, email: "gitlab@winniehell.de", name: "Winnie") }
+ let(:author_c) { build(:author, email: "douwe@gitlab.com", name: "Douwe Maan") }
let(:stubbed_commits) do
[build(:commit, author: author_a),
build(:commit, author: author_a),
build(:commit, author: author_b),
build(:commit, author: author_c),
build(:commit, author: author_c),
- build(:commit, author: author_c)]
+ build(:commit, author: author_c),]
end
let(:order_by) { nil }
let(:sort) { nil }
@@ -2354,96 +2357,96 @@ describe Repository do
expect(subject.map(&:email)).to eq(contributors.map(&:email))
end
- it 'returns the array of Gitlab::Contributor for the repository' do
+ it "returns the array of Gitlab::Contributor for the repository" do
expect_contributors(author_a, author_b, author_c)
end
- context 'order_by email' do
- let(:order_by) { 'email' }
+ context "order_by email" do
+ let(:order_by) { "email" }
- context 'asc' do
- let(:sort) { 'asc' }
+ context "asc" do
+ let(:sort) { "asc" }
- it 'returns all the contributors ordered by email asc case insensitive' do
+ it "returns all the contributors ordered by email asc case insensitive" do
expect_contributors(author_c, author_b, author_a)
end
end
- context 'desc' do
- let(:sort) { 'desc' }
+ context "desc" do
+ let(:sort) { "desc" }
- it 'returns all the contributors ordered by email desc case insensitive' do
+ it "returns all the contributors ordered by email desc case insensitive" do
expect_contributors(author_a, author_b, author_c)
end
end
end
- context 'order_by name' do
- let(:order_by) { 'name' }
+ context "order_by name" do
+ let(:order_by) { "name" }
- context 'asc' do
- let(:sort) { 'asc' }
+ context "asc" do
+ let(:sort) { "asc" }
- it 'returns all the contributors ordered by name asc case insensitive' do
+ it "returns all the contributors ordered by name asc case insensitive" do
expect_contributors(author_c, author_a, author_b)
end
end
- context 'desc' do
- let(:sort) { 'desc' }
+ context "desc" do
+ let(:sort) { "desc" }
- it 'returns all the contributors ordered by name desc case insensitive' do
+ it "returns all the contributors ordered by name desc case insensitive" do
expect_contributors(author_b, author_a, author_c)
end
end
end
- context 'order_by commits' do
- let(:order_by) { 'commits' }
+ context "order_by commits" do
+ let(:order_by) { "commits" }
- context 'asc' do
- let(:sort) { 'asc' }
+ context "asc" do
+ let(:sort) { "asc" }
- it 'returns all the contributors ordered by commits asc' do
+ it "returns all the contributors ordered by commits asc" do
expect_contributors(author_b, author_a, author_c)
end
end
- context 'desc' do
- let(:sort) { 'desc' }
+ context "desc" do
+ let(:sort) { "desc" }
- it 'returns all the contributors ordered by commits desc' do
+ it "returns all the contributors ordered by commits desc" do
expect_contributors(author_c, author_a, author_b)
end
end
end
- context 'invalid ordering' do
- let(:order_by) { 'unknown' }
+ context "invalid ordering" do
+ let(:order_by) { "unknown" }
- it 'returns the contributors unsorted' do
+ it "returns the contributors unsorted" do
expect_contributors(author_a, author_b, author_c)
end
end
- context 'invalid sorting' do
- let(:order_by) { 'name' }
- let(:sort) { 'unknown' }
+ context "invalid sorting" do
+ let(:order_by) { "name" }
+ let(:sort) { "unknown" }
- it 'returns the contributors unsorted' do
+ it "returns the contributors unsorted" do
expect_contributors(author_a, author_b, author_c)
end
end
end
- describe '#merge_base' do
+ describe "#merge_base" do
set(:project) { create(:project, :repository) }
subject(:repository) { project.repository }
- it 'only makes one gitaly call' do
+ it "only makes one gitaly call" do
expect(Gitlab::GitalyClient).to receive(:call).once.and_call_original
- repository.merge_base('master', 'fix')
+ repository.merge_base("master", "fix")
end
end
end
diff --git a/spec/models/resource_label_event_spec.rb b/spec/models/resource_label_event_spec.rb
index 7eeb2fae57d..c8622b1fe7c 100644
--- a/spec/models/resource_label_event_spec.rb
+++ b/spec/models/resource_label_event_spec.rb
@@ -1,65 +1,65 @@
# frozen_string_literal: true
-require 'rails_helper'
+require "rails_helper"
RSpec.describe ResourceLabelEvent, type: :model do
subject { build(:resource_label_event, issue: issue) }
let(:issue) { create(:issue) }
let(:merge_request) { create(:merge_request) }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:issue) }
it { is_expected.to belong_to(:merge_request) }
it { is_expected.to belong_to(:label) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to be_valid }
- describe 'Issuable validation' do
- it 'is invalid if issue_id and merge_request_id are missing' do
- subject.attributes = { issue: nil, merge_request: nil }
+ describe "Issuable validation" do
+ it "is invalid if issue_id and merge_request_id are missing" do
+ subject.attributes = {issue: nil, merge_request: nil}
expect(subject).to be_invalid
end
- it 'is invalid if issue_id and merge_request_id are set' do
- subject.attributes = { issue: issue, merge_request: merge_request }
+ it "is invalid if issue_id and merge_request_id are set" do
+ subject.attributes = {issue: issue, merge_request: merge_request}
expect(subject).to be_invalid
end
- it 'is valid if only issue_id is set' do
- subject.attributes = { issue: issue, merge_request: nil }
+ it "is valid if only issue_id is set" do
+ subject.attributes = {issue: issue, merge_request: nil}
expect(subject).to be_valid
end
- it 'is valid if only merge_request_id is set' do
- subject.attributes = { merge_request: merge_request, issue: nil }
+ it "is valid if only merge_request_id is set" do
+ subject.attributes = {merge_request: merge_request, issue: nil}
expect(subject).to be_valid
end
end
end
- describe '#expire_etag_cache' do
+ describe "#expire_etag_cache" do
def expect_expiration(issue)
expect_any_instance_of(Gitlab::EtagCaching::Store)
.to receive(:touch)
.with("/#{issue.project.namespace.to_param}/#{issue.project.to_param}/noteable/issue/#{issue.id}/notes")
end
- it 'expires resource note etag cache on event save' do
+ it "expires resource note etag cache on event save" do
expect_expiration(subject.issuable)
subject.save!
end
- it 'expires resource note etag cache on event destroy' do
+ it "expires resource note etag cache on event destroy" do
subject.save!
expect_expiration(subject.issuable)
@@ -68,27 +68,27 @@ RSpec.describe ResourceLabelEvent, type: :model do
end
end
- describe '#outdated_markdown?' do
- it 'returns true if label is missing and reference is not empty' do
- subject.attributes = { reference: 'ref', label_id: nil }
+ describe "#outdated_markdown?" do
+ it "returns true if label is missing and reference is not empty" do
+ subject.attributes = {reference: "ref", label_id: nil}
expect(subject.outdated_markdown?).to be true
end
- it 'returns true if reference is not set yet' do
- subject.attributes = { reference: nil }
+ it "returns true if reference is not set yet" do
+ subject.attributes = {reference: nil}
expect(subject.outdated_markdown?).to be true
end
- it 'returns true if markdown is outdated' do
- subject.attributes = { cached_markdown_version: ((CacheMarkdownField::CACHE_COMMONMARK_VERSION - 1) << 16) | 0 }
+ it "returns true if markdown is outdated" do
+ subject.attributes = {cached_markdown_version: ((CacheMarkdownField::CACHE_COMMONMARK_VERSION - 1) << 16) | 0}
expect(subject.outdated_markdown?).to be true
end
- it 'returns false if label and reference are set' do
- subject.attributes = { reference: 'whatever', cached_markdown_version: CacheMarkdownField::CACHE_COMMONMARK_VERSION << 16 }
+ it "returns false if label and reference are set" do
+ subject.attributes = {reference: "whatever", cached_markdown_version: CacheMarkdownField::CACHE_COMMONMARK_VERSION << 16}
expect(subject.outdated_markdown?).to be false
end
diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb
index 48799781b87..9d7c3ca3c9f 100644
--- a/spec/models/route_spec.rb
+++ b/spec/models/route_spec.rb
@@ -1,14 +1,14 @@
-require 'spec_helper'
+require "spec_helper"
describe Route do
- let(:group) { create(:group, path: 'git_lab', name: 'git_lab') }
+ let(:group) { create(:group, path: "git_lab", name: "git_lab") }
let(:route) { group.route }
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:source) }
end
- describe 'validations' do
+ describe "validations" do
before do
expect(route).to be_persisted
end
@@ -18,28 +18,28 @@ describe Route do
it { is_expected.to validate_uniqueness_of(:path).case_insensitive }
end
- describe 'callbacks' do
- context 'before validation' do
- it 'calls #delete_conflicting_orphaned_routes' do
+ describe "callbacks" do
+ context "before validation" do
+ it "calls #delete_conflicting_orphaned_routes" do
expect(route).to receive(:delete_conflicting_orphaned_routes)
route.valid?
end
end
- context 'after update' do
- it 'calls #create_redirect_for_old_path' do
+ context "after update" do
+ it "calls #create_redirect_for_old_path" do
expect(route).to receive(:create_redirect_for_old_path)
- route.update(path: 'foo')
+ route.update(path: "foo")
end
- it 'calls #delete_conflicting_redirects' do
+ it "calls #delete_conflicting_redirects" do
expect(route).to receive(:delete_conflicting_redirects)
- route.update(path: 'foo')
+ route.update(path: "foo")
end
end
- context 'after create' do
- it 'calls #delete_conflicting_redirects' do
+ context "after create" do
+ it "calls #delete_conflicting_redirects" do
route.destroy
new_route = described_class.new(source: group, path: group.path)
expect(new_route).to receive(:delete_conflicting_redirects)
@@ -48,182 +48,182 @@ describe Route do
end
end
- describe '.inside_path' do
- let!(:nested_group) { create(:group, path: 'test', name: 'test', parent: group) }
- let!(:deep_nested_group) { create(:group, path: 'foo', name: 'foo', parent: nested_group) }
- let!(:another_group) { create(:group, path: 'other') }
- let!(:similar_group) { create(:group, path: 'gitllab') }
- let!(:another_group_nested) { create(:group, path: 'another', name: 'another', parent: similar_group) }
+ describe ".inside_path" do
+ let!(:nested_group) { create(:group, path: "test", name: "test", parent: group) }
+ let!(:deep_nested_group) { create(:group, path: "foo", name: "foo", parent: nested_group) }
+ let!(:another_group) { create(:group, path: "other") }
+ let!(:similar_group) { create(:group, path: "gitllab") }
+ let!(:another_group_nested) { create(:group, path: "another", name: "another", parent: similar_group) }
- it 'returns correct routes' do
- expect(described_class.inside_path('git_lab')).to match_array([nested_group.route, deep_nested_group.route])
+ it "returns correct routes" do
+ expect(described_class.inside_path("git_lab")).to match_array([nested_group.route, deep_nested_group.route])
end
end
- describe '#rename_descendants' do
- let!(:nested_group) { create(:group, path: 'test', name: 'test', parent: group) }
- let!(:deep_nested_group) { create(:group, path: 'foo', name: 'foo', parent: nested_group) }
- let!(:similar_group) { create(:group, path: 'gitlab-org', name: 'gitlab-org') }
- let!(:another_group) { create(:group, path: 'gittlab', name: 'gitllab') }
- let!(:another_group_nested) { create(:group, path: 'git_lab', name: 'git_lab', parent: another_group) }
+ describe "#rename_descendants" do
+ let!(:nested_group) { create(:group, path: "test", name: "test", parent: group) }
+ let!(:deep_nested_group) { create(:group, path: "foo", name: "foo", parent: nested_group) }
+ let!(:similar_group) { create(:group, path: "gitlab-org", name: "gitlab-org") }
+ let!(:another_group) { create(:group, path: "gittlab", name: "gitllab") }
+ let!(:another_group_nested) { create(:group, path: "git_lab", name: "git_lab", parent: another_group) }
- context 'path update' do
- context 'when route name is set' do
+ context "path update" do
+ context "when route name is set" do
before do
- route.update(path: 'bar')
+ route.update(path: "bar")
end
- it 'updates children routes with new path' do
- expect(described_class.exists?(path: 'bar')).to be_truthy
- expect(described_class.exists?(path: 'bar/test')).to be_truthy
- expect(described_class.exists?(path: 'bar/test/foo')).to be_truthy
- expect(described_class.exists?(path: 'gitlab-org')).to be_truthy
- expect(described_class.exists?(path: 'gittlab')).to be_truthy
- expect(described_class.exists?(path: 'gittlab/git_lab')).to be_truthy
+ it "updates children routes with new path" do
+ expect(described_class.exists?(path: "bar")).to be_truthy
+ expect(described_class.exists?(path: "bar/test")).to be_truthy
+ expect(described_class.exists?(path: "bar/test/foo")).to be_truthy
+ expect(described_class.exists?(path: "gitlab-org")).to be_truthy
+ expect(described_class.exists?(path: "gittlab")).to be_truthy
+ expect(described_class.exists?(path: "gittlab/git_lab")).to be_truthy
end
end
- context 'when route name is nil' do
+ context "when route name is nil" do
before do
route.update_column(:name, nil)
end
it "does not fail" do
- expect(route.update(path: 'bar')).to be_truthy
+ expect(route.update(path: "bar")).to be_truthy
end
end
- context 'when conflicting redirects exist' do
+ context "when conflicting redirects exist" do
let(:route) { create(:project).route }
- let!(:conflicting_redirect1) { route.create_redirect('bar/test') }
- let!(:conflicting_redirect2) { route.create_redirect('bar/test/foo') }
- let!(:conflicting_redirect3) { route.create_redirect('gitlab-org') }
+ let!(:conflicting_redirect1) { route.create_redirect("bar/test") }
+ let!(:conflicting_redirect2) { route.create_redirect("bar/test/foo") }
+ let!(:conflicting_redirect3) { route.create_redirect("gitlab-org") }
- it 'deletes the conflicting redirects' do
- route.update(path: 'bar')
+ it "deletes the conflicting redirects" do
+ route.update(path: "bar")
- expect(RedirectRoute.exists?(path: 'bar/test')).to be_falsey
- expect(RedirectRoute.exists?(path: 'bar/test/foo')).to be_falsey
- expect(RedirectRoute.exists?(path: 'gitlab-org')).to be_truthy
+ expect(RedirectRoute.exists?(path: "bar/test")).to be_falsey
+ expect(RedirectRoute.exists?(path: "bar/test/foo")).to be_falsey
+ expect(RedirectRoute.exists?(path: "gitlab-org")).to be_truthy
end
end
end
- context 'name update' do
- it 'updates children routes with new path' do
- route.update(name: 'bar')
+ context "name update" do
+ it "updates children routes with new path" do
+ route.update(name: "bar")
- expect(described_class.exists?(name: 'bar')).to be_truthy
- expect(described_class.exists?(name: 'bar / test')).to be_truthy
- expect(described_class.exists?(name: 'bar / test / foo')).to be_truthy
- expect(described_class.exists?(name: 'gitlab-org')).to be_truthy
+ expect(described_class.exists?(name: "bar")).to be_truthy
+ expect(described_class.exists?(name: "bar / test")).to be_truthy
+ expect(described_class.exists?(name: "bar / test / foo")).to be_truthy
+ expect(described_class.exists?(name: "gitlab-org")).to be_truthy
end
- it 'handles a rename from nil' do
+ it "handles a rename from nil" do
# Note: using `update_columns` to skip all validation and callbacks
route.update_columns(name: nil)
- expect { route.update(name: 'bar') }
- .to change { route.name }.from(nil).to('bar')
+ expect { route.update(name: "bar") }
+ .to change { route.name }.from(nil).to("bar")
end
end
end
- describe '#create_redirect_for_old_path' do
- context 'if the path changed' do
- it 'creates a RedirectRoute for the old path' do
- redirect_scope = route.source.redirect_routes.where(path: 'git_lab')
+ describe "#create_redirect_for_old_path" do
+ context "if the path changed" do
+ it "creates a RedirectRoute for the old path" do
+ redirect_scope = route.source.redirect_routes.where(path: "git_lab")
expect(redirect_scope.exists?).to be_falsey
- route.path = 'new-path'
+ route.path = "new-path"
route.save!
expect(redirect_scope.exists?).to be_truthy
end
end
end
- describe '#create_redirect' do
- it 'creates a RedirectRoute with the same source' do
- redirect_route = route.create_redirect('foo')
+ describe "#create_redirect" do
+ it "creates a RedirectRoute with the same source" do
+ redirect_route = route.create_redirect("foo")
expect(redirect_route).to be_a(RedirectRoute)
expect(redirect_route).to be_persisted
expect(redirect_route.source).to eq(route.source)
- expect(redirect_route.path).to eq('foo')
+ expect(redirect_route.path).to eq("foo")
end
- context 'when the source is a Project' do
- it 'creates a RedirectRoute' do
+ context "when the source is a Project" do
+ it "creates a RedirectRoute" do
project = create(:project)
route = project.route
- redirect_route = route.create_redirect('foo')
+ redirect_route = route.create_redirect("foo")
expect(redirect_route).not_to be_nil
end
end
- context 'when the source is not a project' do
- it 'creates a RedirectRoute' do
- redirect_route = route.create_redirect('foo')
+ context "when the source is not a project" do
+ it "creates a RedirectRoute" do
+ redirect_route = route.create_redirect("foo")
expect(redirect_route).not_to be_nil
end
end
end
- describe '#delete_conflicting_redirects' do
+ describe "#delete_conflicting_redirects" do
let(:route) { create(:project).route }
- it 'deletes the redirect' do
+ it "deletes the redirect" do
route.create_redirect("#{route.path}/foo")
- expect do
+ expect {
route.delete_conflicting_redirects
- end.to change { RedirectRoute.count }.by(-1)
+ }.to change { RedirectRoute.count }.by(-1)
end
- context 'when a redirect route with the same path exists' do
- context 'when the redirect route has matching case' do
+ context "when a redirect route with the same path exists" do
+ context "when the redirect route has matching case" do
let(:route) { create(:project).route }
let!(:redirect1) { route.create_redirect(route.path) }
- it 'deletes the redirect' do
- expect do
+ it "deletes the redirect" do
+ expect {
route.delete_conflicting_redirects
- end.to change { RedirectRoute.count }.by(-1)
+ }.to change { RedirectRoute.count }.by(-1)
end
- context 'when redirect routes with paths descending from the route path exists' do
+ context "when redirect routes with paths descending from the route path exists" do
let!(:redirect2) { route.create_redirect("#{route.path}/foo") }
let!(:redirect3) { route.create_redirect("#{route.path}/foo/bar") }
let!(:redirect4) { route.create_redirect("#{route.path}/baz/quz") }
let!(:other_redirect) { route.create_redirect("other") }
- it 'deletes all redirects with paths that descend from the route path' do
- expect do
+ it "deletes all redirects with paths that descend from the route path" do
+ expect {
route.delete_conflicting_redirects
- end.to change { RedirectRoute.count }.by(-4)
+ }.to change { RedirectRoute.count }.by(-4)
end
end
end
- context 'when the redirect route is differently cased' do
+ context "when the redirect route is differently cased" do
let(:route) { create(:project).route }
let!(:redirect1) { route.create_redirect(route.path.upcase) }
- it 'deletes the redirect' do
- expect do
+ it "deletes the redirect" do
+ expect {
route.delete_conflicting_redirects
- end.to change { RedirectRoute.count }.by(-1)
+ }.to change { RedirectRoute.count }.by(-1)
end
end
end
end
- describe '#conflicting_redirects' do
+ describe "#conflicting_redirects" do
let(:route) { create(:project).route }
- it 'returns an ActiveRecord::Relation' do
+ it "returns an ActiveRecord::Relation" do
expect(route.conflicting_redirects).to be_an(ActiveRecord::Relation)
end
- it 'returns the redirect routes' do
+ it "returns the redirect routes" do
redirect1 = route.create_redirect("#{route.path}/foo")
redirect2 = route.create_redirect("#{route.path}/foo/bar")
redirect3 = route.create_redirect("#{route.path}/baz/quz")
@@ -231,87 +231,87 @@ describe Route do
expect(route.conflicting_redirects).to match_array([redirect1, redirect2, redirect3])
end
- context 'when a redirect route with the same path exists' do
+ context "when a redirect route with the same path exists" do
let(:route) { create(:project).route }
- context 'when the redirect route has matching case' do
+ context "when the redirect route has matching case" do
let!(:redirect1) { route.create_redirect(route.path) }
- it 'returns the redirect route' do
+ it "returns the redirect route" do
expect(route.conflicting_redirects).to match_array([redirect1])
end
- context 'when redirect routes with paths descending from the route path exists' do
+ context "when redirect routes with paths descending from the route path exists" do
let!(:redirect2) { route.create_redirect("#{route.path}/foo") }
let!(:redirect3) { route.create_redirect("#{route.path}/foo/bar") }
let!(:redirect4) { route.create_redirect("#{route.path}/baz/quz") }
let!(:other_redirect) { route.create_redirect("other") }
- it 'returns the redirect routes' do
+ it "returns the redirect routes" do
expect(route.conflicting_redirects).to match_array([redirect1, redirect2, redirect3, redirect4])
end
end
end
- context 'when the redirect route is differently cased' do
+ context "when the redirect route is differently cased" do
let!(:redirect1) { route.create_redirect(route.path.upcase) }
- it 'returns the redirect route' do
+ it "returns the redirect route" do
expect(route.conflicting_redirects).to match_array([redirect1])
end
end
end
end
- describe '#delete_conflicting_orphaned_routes' do
- context 'when there is a conflicting route' do
- let!(:conflicting_group) { create(:group, path: 'foo') }
+ describe "#delete_conflicting_orphaned_routes" do
+ context "when there is a conflicting route" do
+ let!(:conflicting_group) { create(:group, path: "foo") }
before do
route.path = conflicting_group.route.path
end
- context 'when the route is orphaned' do
+ context "when the route is orphaned" do
let!(:offending_route) { conflicting_group.route }
before do
Group.delete(conflicting_group) # Orphan the route
end
- it 'deletes the orphaned route' do
- expect do
+ it "deletes the orphaned route" do
+ expect {
route.valid?
- end.to change { described_class.count }.from(2).to(1)
+ }.to change { described_class.count }.from(2).to(1)
end
- it 'passes validation, as usual' do
+ it "passes validation, as usual" do
expect(route.valid?).to be_truthy
end
end
- context 'when the route is not orphaned' do
- it 'does not delete the conflicting route' do
- expect do
+ context "when the route is not orphaned" do
+ it "does not delete the conflicting route" do
+ expect {
route.valid?
- end.not_to change { described_class.count }
+ }.not_to change { described_class.count }
end
- it 'fails validation, as usual' do
+ it "fails validation, as usual" do
expect(route.valid?).to be_falsey
end
end
end
- context 'when there are no conflicting routes' do
- it 'does not delete any routes' do
+ context "when there are no conflicting routes" do
+ it "does not delete any routes" do
route
- expect do
+ expect {
route.valid?
- end.not_to change { described_class.count }
+ }.not_to change { described_class.count }
end
- it 'passes validation, as usual' do
+ it "passes validation, as usual" do
expect(route.valid?).to be_truthy
end
end
diff --git a/spec/models/sent_notification_spec.rb b/spec/models/sent_notification_spec.rb
index 6c35ed8f649..09095bf2b62 100644
--- a/spec/models/sent_notification_spec.rb
+++ b/spec/models/sent_notification_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe SentNotification do
set(:user) { create(:user) }
set(:project) { create(:project) }
- describe 'validation' do
- describe 'note validity' do
+ describe "validation" do
+ describe "note validity" do
context "when the project doesn't match the noteable's project" do
subject { build(:sent_notification, noteable: create(:issue)) }
@@ -36,46 +36,46 @@ describe SentNotification do
end
end
- shared_examples 'a successful sent notification' do
- it 'creates a new SentNotification' do
+ shared_examples "a successful sent notification" do
+ it "creates a new SentNotification" do
expect { subject }.to change { described_class.count }.by(1)
end
end
- describe '.record' do
+ describe ".record" do
let(:issue) { create(:issue) }
subject { described_class.record(issue, user.id) }
- it_behaves_like 'a successful sent notification'
+ it_behaves_like "a successful sent notification"
end
- describe '.record_note' do
+ describe ".record_note" do
subject { described_class.record_note(note, note.author.id) }
- context 'for a discussion note' do
+ context "for a discussion note" do
let(:note) { create(:diff_note_on_merge_request) }
- it_behaves_like 'a successful sent notification'
+ it_behaves_like "a successful sent notification"
- it 'sets in_reply_to_discussion_id' do
+ it "sets in_reply_to_discussion_id" do
expect(subject.in_reply_to_discussion_id).to eq(note.discussion_id)
end
end
- context 'for an individual note' do
+ context "for an individual note" do
let(:note) { create(:note_on_merge_request) }
- it_behaves_like 'a successful sent notification'
+ it_behaves_like "a successful sent notification"
- it 'does not set in_reply_to_discussion_id' do
+ it "does not set in_reply_to_discussion_id" do
expect(subject.in_reply_to_discussion_id).to be_nil
end
end
end
- describe '#unsubscribable?' do
- shared_examples 'an unsubscribable notification' do |noteable_type|
+ describe "#unsubscribable?" do
+ shared_examples "an unsubscribable notification" do |noteable_type|
subject { described_class.record(noteable, user.id) }
context "for #{noteable_type}" do
@@ -83,7 +83,7 @@ describe SentNotification do
end
end
- shared_examples 'a non-unsubscribable notification' do |noteable_type|
+ shared_examples "a non-unsubscribable notification" do |noteable_type|
subject { described_class.record(noteable, user.id) }
context "for a #{noteable_type}" do
@@ -91,30 +91,30 @@ describe SentNotification do
end
end
- it_behaves_like 'an unsubscribable notification', 'issue' do
+ it_behaves_like "an unsubscribable notification", "issue" do
let(:noteable) { create(:issue, project: project) }
end
- it_behaves_like 'an unsubscribable notification', 'merge request' do
+ it_behaves_like "an unsubscribable notification", "merge request" do
let(:noteable) { create(:merge_request, source_project: project) }
end
- it_behaves_like 'a non-unsubscribable notification', 'commit' do
+ it_behaves_like "a non-unsubscribable notification", "commit" do
let(:project) { create(:project, :repository) }
let(:noteable) { project.commit }
end
- it_behaves_like 'a non-unsubscribable notification', 'personal snippet' do
+ it_behaves_like "a non-unsubscribable notification", "personal snippet" do
let(:noteable) { create(:personal_snippet, project: project) }
end
- it_behaves_like 'a non-unsubscribable notification', 'project snippet' do
+ it_behaves_like "a non-unsubscribable notification", "project snippet" do
let(:noteable) { create(:project_snippet, project: project) }
end
end
- describe '#for_commit?' do
- shared_examples 'a commit notification' do |noteable_type|
+ describe "#for_commit?" do
+ shared_examples "a commit notification" do |noteable_type|
subject { described_class.record(noteable, user.id) }
context "for #{noteable_type}" do
@@ -122,7 +122,7 @@ describe SentNotification do
end
end
- shared_examples 'a non-commit notification' do |noteable_type|
+ shared_examples "a non-commit notification" do |noteable_type|
subject { described_class.record(noteable, user.id) }
context "for a #{noteable_type}" do
@@ -130,30 +130,30 @@ describe SentNotification do
end
end
- it_behaves_like 'a non-commit notification', 'issue' do
+ it_behaves_like "a non-commit notification", "issue" do
let(:noteable) { create(:issue, project: project) }
end
- it_behaves_like 'a non-commit notification', 'merge request' do
+ it_behaves_like "a non-commit notification", "merge request" do
let(:noteable) { create(:merge_request, source_project: project) }
end
- it_behaves_like 'a commit notification', 'commit' do
+ it_behaves_like "a commit notification", "commit" do
let(:project) { create(:project, :repository) }
let(:noteable) { project.commit }
end
- it_behaves_like 'a non-commit notification', 'personal snippet' do
+ it_behaves_like "a non-commit notification", "personal snippet" do
let(:noteable) { create(:personal_snippet, project: project) }
end
- it_behaves_like 'a non-commit notification', 'project snippet' do
+ it_behaves_like "a non-commit notification", "project snippet" do
let(:noteable) { create(:project_snippet, project: project) }
end
end
- describe '#for_snippet?' do
- shared_examples 'a snippet notification' do |noteable_type|
+ describe "#for_snippet?" do
+ shared_examples "a snippet notification" do |noteable_type|
subject { described_class.record(noteable, user.id) }
context "for #{noteable_type}" do
@@ -161,7 +161,7 @@ describe SentNotification do
end
end
- shared_examples 'a non-snippet notification' do |noteable_type|
+ shared_examples "a non-snippet notification" do |noteable_type|
subject { described_class.record(noteable, user.id) }
context "for a #{noteable_type}" do
@@ -169,143 +169,143 @@ describe SentNotification do
end
end
- it_behaves_like 'a non-snippet notification', 'issue' do
+ it_behaves_like "a non-snippet notification", "issue" do
let(:noteable) { create(:issue, project: project) }
end
- it_behaves_like 'a non-snippet notification', 'merge request' do
+ it_behaves_like "a non-snippet notification", "merge request" do
let(:noteable) { create(:merge_request, source_project: project) }
end
- it_behaves_like 'a non-snippet notification', 'commit' do
+ it_behaves_like "a non-snippet notification", "commit" do
let(:project) { create(:project, :repository) }
let(:noteable) { project.commit }
end
- it_behaves_like 'a snippet notification', 'personal snippet' do
+ it_behaves_like "a snippet notification", "personal snippet" do
let(:noteable) { create(:personal_snippet, project: project) }
end
- it_behaves_like 'a snippet notification', 'project snippet' do
+ it_behaves_like "a snippet notification", "project snippet" do
let(:noteable) { create(:project_snippet, project: project) }
end
end
- describe '#create_reply' do
- context 'for issue' do
+ describe "#create_reply" do
+ context "for issue" do
let(:issue) { create(:issue) }
subject { described_class.record(issue, issue.author.id) }
- it 'creates a comment on the issue' do
- note = subject.create_reply('Test')
+ it "creates a comment on the issue" do
+ note = subject.create_reply("Test")
expect(note.in_reply_to?(issue)).to be_truthy
end
end
- context 'for issue comment' do
+ context "for issue comment" do
let(:note) { create(:note_on_issue) }
subject { described_class.record_note(note, note.author.id) }
- it 'creates a comment on the issue' do
- new_note = subject.create_reply('Test')
+ it "creates a comment on the issue" do
+ new_note = subject.create_reply("Test")
expect(new_note.in_reply_to?(note)).to be_truthy
expect(new_note.discussion_id).not_to eq(note.discussion_id)
end
end
- context 'for issue discussion' do
+ context "for issue discussion" do
let(:note) { create(:discussion_note_on_issue) }
subject { described_class.record_note(note, note.author.id) }
- it 'creates a reply on the discussion' do
- new_note = subject.create_reply('Test')
+ it "creates a reply on the discussion" do
+ new_note = subject.create_reply("Test")
expect(new_note.in_reply_to?(note)).to be_truthy
expect(new_note.discussion_id).to eq(note.discussion_id)
end
end
- context 'for merge request' do
+ context "for merge request" do
let(:merge_request) { create(:merge_request) }
subject { described_class.record(merge_request, merge_request.author.id) }
- it 'creates a comment on the merge_request' do
- note = subject.create_reply('Test')
+ it "creates a comment on the merge_request" do
+ note = subject.create_reply("Test")
expect(note.in_reply_to?(merge_request)).to be_truthy
end
end
- context 'for merge request comment' do
+ context "for merge request comment" do
let(:note) { create(:note_on_merge_request) }
subject { described_class.record_note(note, note.author.id) }
- it 'creates a comment on the merge request' do
- new_note = subject.create_reply('Test')
+ it "creates a comment on the merge request" do
+ new_note = subject.create_reply("Test")
expect(new_note.in_reply_to?(note)).to be_truthy
expect(new_note.discussion_id).not_to eq(note.discussion_id)
end
end
- context 'for merge request diff discussion' do
+ context "for merge request diff discussion" do
let(:note) { create(:diff_note_on_merge_request) }
subject { described_class.record_note(note, note.author.id) }
- it 'creates a reply on the discussion' do
- new_note = subject.create_reply('Test')
+ it "creates a reply on the discussion" do
+ new_note = subject.create_reply("Test")
expect(new_note.in_reply_to?(note)).to be_truthy
expect(new_note.discussion_id).to eq(note.discussion_id)
end
end
- context 'for merge request non-diff discussion' do
+ context "for merge request non-diff discussion" do
let(:note) { create(:discussion_note_on_merge_request) }
subject { described_class.record_note(note, note.author.id) }
- it 'creates a reply on the discussion' do
- new_note = subject.create_reply('Test')
+ it "creates a reply on the discussion" do
+ new_note = subject.create_reply("Test")
expect(new_note.in_reply_to?(note)).to be_truthy
expect(new_note.discussion_id).to eq(note.discussion_id)
end
end
- context 'for commit' do
+ context "for commit" do
let(:project) { create(:project, :repository) }
let(:commit) { project.commit }
subject { described_class.record(commit, project.creator.id) }
- it 'creates a comment on the commit' do
- note = subject.create_reply('Test')
+ it "creates a comment on the commit" do
+ note = subject.create_reply("Test")
expect(note.in_reply_to?(commit)).to be_truthy
end
end
- context 'for commit comment' do
+ context "for commit comment" do
let(:note) { create(:note_on_commit) }
subject { described_class.record_note(note, note.author.id) }
- it 'creates a comment on the commit' do
- new_note = subject.create_reply('Test')
+ it "creates a comment on the commit" do
+ new_note = subject.create_reply("Test")
expect(new_note.in_reply_to?(note)).to be_truthy
expect(new_note.discussion_id).not_to eq(note.discussion_id)
end
end
- context 'for commit diff discussion' do
+ context "for commit diff discussion" do
let(:note) { create(:diff_note_on_commit) }
subject { described_class.record_note(note, note.author.id) }
- it 'creates a reply on the discussion' do
- new_note = subject.create_reply('Test')
+ it "creates a reply on the discussion" do
+ new_note = subject.create_reply("Test")
expect(new_note.in_reply_to?(note)).to be_truthy
expect(new_note.discussion_id).to eq(note.discussion_id)
end
end
- context 'for commit non-diff discussion' do
+ context "for commit non-diff discussion" do
let(:note) { create(:discussion_note_on_commit) }
subject { described_class.record_note(note, note.author.id) }
- it 'creates a reply on the discussion' do
- new_note = subject.create_reply('Test')
+ it "creates a reply on the discussion" do
+ new_note = subject.create_reply("Test")
expect(new_note.in_reply_to?(note)).to be_truthy
expect(new_note.discussion_id).to eq(note.discussion_id)
end
diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb
index 25eecb3f909..69684623275 100644
--- a/spec/models/service_spec.rb
+++ b/spec/models/service_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe Service do
describe "Associations" do
@@ -6,19 +6,19 @@ describe Service do
it { is_expected.to have_one :service_hook }
end
- describe 'Validations' do
+ describe "Validations" do
it { is_expected.to validate_presence_of(:type) }
end
- describe 'Scopes' do
- describe '.confidential_note_hooks' do
- it 'includes services where confidential_note_events is true' do
+ describe "Scopes" do
+ describe ".confidential_note_hooks" do
+ it "includes services where confidential_note_events is true" do
create(:service, active: true, confidential_note_events: true)
expect(described_class.confidential_note_hooks.count).to eq 1
end
- it 'excludes services where confidential_note_events is false' do
+ it "excludes services where confidential_note_events is false" do
create(:service, active: true, confidential_note_events: false)
expect(described_class.confidential_note_hooks.count).to eq 0
@@ -27,44 +27,44 @@ describe Service do
end
describe "Test Button" do
- describe '#can_test?' do
+ describe "#can_test?" do
let(:service) { create(:service, project: project) }
- context 'when repository is not empty' do
+ context "when repository is not empty" do
let(:project) { create(:project, :repository) }
- it 'returns true' do
+ it "returns true" do
expect(service.can_test?).to be true
end
end
- context 'when repository is empty' do
+ context "when repository is empty" do
let(:project) { create(:project) }
- it 'returns true' do
+ it "returns true" do
expect(service.can_test?).to be true
end
end
end
- describe '#test' do
- let(:data) { 'test' }
+ describe "#test" do
+ let(:data) { "test" }
let(:service) { create(:service, project: project) }
- context 'when repository is not empty' do
+ context "when repository is not empty" do
let(:project) { create(:project, :repository) }
- it 'test runs execute' do
+ it "test runs execute" do
expect(service).to receive(:execute).with(data)
service.test(data)
end
end
- context 'when repository is empty' do
+ context "when repository is empty" do
let(:project) { create(:project) }
- it 'test runs execute' do
+ it "test runs execute" do
expect(service).to receive(:execute).with(data)
service.test(data)
@@ -74,9 +74,9 @@ describe Service do
end
describe "Template" do
- describe '.build_from_template' do
- context 'when template is invalid' do
- it 'sets service template to inactive when template is invalid' do
+ describe ".build_from_template" do
+ context "when template is invalid" do
+ it "sets service template to inactive when template is invalid" do
project = create(:project)
template = KubernetesService.new(template: true, active: true)
template.save(validate: false)
@@ -94,23 +94,24 @@ describe Service do
PushoverService.create(
template: true,
properties: {
- device: 'MyDevice',
- sound: 'mic',
+ device: "MyDevice",
+ sound: "mic",
priority: 4,
- api_key: '123456789'
- })
+ api_key: "123456789",
+ }
+ )
end
let(:project) { create(:project) }
- describe 'is prefilled for projects pushover service' do
+ describe "is prefilled for projects pushover service" do
it "has all fields prefilled" do
- service = project.find_or_initialize_service('pushover')
+ service = project.find_or_initialize_service("pushover")
expect(service.template).to eq(false)
- expect(service.device).to eq('MyDevice')
- expect(service.sound).to eq('mic')
+ expect(service.device).to eq("MyDevice")
+ expect(service.sound).to eq("mic")
expect(service.priority).to eq(4)
- expect(service.api_key).to eq('123456789')
+ expect(service.api_key).to eq("123456789")
end
end
end
@@ -121,9 +122,9 @@ describe Service do
BambooService.create(
project: create(:project),
properties: {
- bamboo_url: 'http://gitlab.com',
- username: 'mic',
- password: "password"
+ bamboo_url: "http://gitlab.com",
+ username: "mic",
+ password: "password",
}
)
end
@@ -145,12 +146,12 @@ describe Service do
end
it "returns false when the property has been re-assigned the same value" do
- service.bamboo_url = 'http://gitlab.com'
+ service.bamboo_url = "http://gitlab.com"
expect(service.bamboo_url_changed?).to be_falsy
end
it "returns false when the property has been assigned a new value then saved" do
- service.bamboo_url = 'http://example.com'
+ service.bamboo_url = "http://example.com"
service.save
expect(service.bamboo_url_changed?).to be_falsy
end
@@ -161,9 +162,9 @@ describe Service do
BambooService.create(
project: create(:project),
properties: {
- bamboo_url: 'http://gitlab.com',
- username: 'mic',
- password: "password"
+ bamboo_url: "http://gitlab.com",
+ username: "mic",
+ password: "password",
}
)
end
@@ -185,12 +186,12 @@ describe Service do
end
it "returns true when the property has been re-assigned the same value" do
- service.bamboo_url = 'http://gitlab.com'
+ service.bamboo_url = "http://gitlab.com"
expect(service.bamboo_url_touched?).to be_truthy
end
it "returns false when the property has been assigned a new value then saved" do
- service.bamboo_url = 'http://example.com'
+ service.bamboo_url = "http://example.com"
service.save
expect(service.bamboo_url_changed?).to be_falsy
end
@@ -201,9 +202,9 @@ describe Service do
BambooService.create(
project: create(:project),
properties: {
- bamboo_url: 'http://gitlab.com',
- username: 'mic',
- password: "password"
+ bamboo_url: "http://gitlab.com",
+ username: "mic",
+ password: "password",
}
)
end
@@ -215,41 +216,41 @@ describe Service do
it "returns the previous value when the property has been assigned a different value" do
service.bamboo_url = "http://example.com"
- expect(service.bamboo_url_was).to eq('http://gitlab.com')
+ expect(service.bamboo_url_was).to eq("http://gitlab.com")
end
it "returns initial value when the property has been re-assigned the same value" do
- service.bamboo_url = 'http://gitlab.com'
- expect(service.bamboo_url_was).to eq('http://gitlab.com')
+ service.bamboo_url = "http://gitlab.com"
+ expect(service.bamboo_url_was).to eq("http://gitlab.com")
end
it "returns initial value when the property has been assigned multiple values" do
service.bamboo_url = "http://example.com"
service.bamboo_url = "http://example2.com"
- expect(service.bamboo_url_was).to eq('http://gitlab.com')
+ expect(service.bamboo_url_was).to eq("http://gitlab.com")
end
it "returns nil when the property has been assigned a new value then saved" do
- service.bamboo_url = 'http://example.com'
+ service.bamboo_url = "http://example.com"
service.save
expect(service.bamboo_url_was).to be_nil
end
end
- describe 'initialize service with no properties' do
+ describe "initialize service with no properties" do
let(:service) do
GitlabIssueTrackerService.create(
project: create(:project),
- title: 'random title'
+ title: "random title"
)
end
- it 'does not raise error' do
+ it "does not raise error" do
expect { service }.not_to raise_error
end
- it 'creates the properties' do
- expect(service.properties).to eq({ "title" => "random title" })
+ it "creates the properties" do
+ expect(service.properties).to eq({"title" => "random title"})
end
end
@@ -260,18 +261,18 @@ describe Service do
project: project,
active: true,
properties: {
- project_url: 'http://redmine/projects/project_name_in_redmine',
+ project_url: "http://redmine/projects/project_name_in_redmine",
issues_url: "http://redmine/#{project.id}/project_name_in_redmine/:id",
- new_issue_url: 'http://redmine/projects/project_name_in_redmine/issues/new'
+ new_issue_url: "http://redmine/projects/project_name_in_redmine/issues/new",
}
)
end
describe "on create" do
it "updates the has_external_issue_tracker boolean" do
- expect do
+ expect {
service.save!
- end.to change { service.project.has_external_issue_tracker }.from(false).to(true)
+ }.to change { service.project.has_external_issue_tracker }.from(false).to(true)
end
end
@@ -279,9 +280,9 @@ describe Service do
it "updates the has_external_issue_tracker boolean" do
service.save!
- expect do
+ expect {
service.update(active: false)
- end.to change { service.project.has_external_issue_tracker }.from(true).to(false)
+ }.to change { service.project.has_external_issue_tracker }.from(true).to(false)
end
end
end
@@ -289,7 +290,7 @@ describe Service do
describe "#deprecated?" do
let(:project) { create(:project, :repository) }
- it 'should return false by default' do
+ it "should return false by default" do
service = create(:service, project: project)
expect(service.deprecated?).to be_falsy
end
@@ -298,32 +299,32 @@ describe Service do
describe "#deprecation_message" do
let(:project) { create(:project, :repository) }
- it 'should be empty by default' do
+ it "should be empty by default" do
service = create(:service, project: project)
expect(service.deprecation_message).to be_nil
end
end
- describe '.find_by_template' do
+ describe ".find_by_template" do
let!(:kubernetes_service) { create(:kubernetes_service, template: true) }
- it 'returns service template' do
+ it "returns service template" do
expect(KubernetesService.find_by_template).to eq(kubernetes_service)
end
end
- describe '#api_field_names' do
+ describe "#api_field_names" do
let(:fake_service) do
Class.new(Service) do
def fields
[
- { name: 'token' },
- { name: 'api_token' },
- { name: 'key' },
- { name: 'api_key' },
- { name: 'password' },
- { name: 'password_field' },
- { name: 'safe_field' }
+ {name: "token"},
+ {name: "api_token"},
+ {name: "key"},
+ {name: "api_key"},
+ {name: "password"},
+ {name: "password_field"},
+ {name: "safe_field"},
]
end
end
@@ -331,22 +332,22 @@ describe Service do
let(:service) do
fake_service.new(properties: [
- { token: 'token-value' },
- { api_token: 'api_token-value' },
- { key: 'key-value' },
- { api_key: 'api_key-value' },
- { password: 'password-value' },
- { password_field: 'password_field-value' },
- { safe_field: 'safe_field-value' }
+ {token: "token-value"},
+ {api_token: "api_token-value"},
+ {key: "key-value"},
+ {api_key: "api_key-value"},
+ {password: "password-value"},
+ {password_field: "password_field-value"},
+ {safe_field: "safe_field-value"},
])
end
- it 'filters out sensitive fields' do
- expect(service.api_field_names).to eq(['safe_field'])
+ it "filters out sensitive fields" do
+ expect(service.api_field_names).to eq(["safe_field"])
end
end
- context 'logging' do
+ context "logging" do
let(:project) { create(:project) }
let(:service) { create(:service, project: project) }
let(:test_message) { "test message" }
@@ -356,20 +357,20 @@ describe Service do
project_path: project.full_path,
project_id: project.id,
message: test_message,
- additional_argument: 'some argument'
+ additional_argument: "some argument",
}
end
- it 'logs info messages using json logger' do
+ it "logs info messages using json logger" do
expect(Gitlab::JsonLogger).to receive(:info).with(arguments)
- service.log_info(test_message, additional_argument: 'some argument')
+ service.log_info(test_message, additional_argument: "some argument")
end
- it 'logs error messages using json logger' do
+ it "logs error messages using json logger" do
expect(Gitlab::JsonLogger).to receive(:error).with(arguments)
- service.log_error(test_message, additional_argument: 'some argument')
+ service.log_error(test_message, additional_argument: "some argument")
end
end
end
diff --git a/spec/models/shard_spec.rb b/spec/models/shard_spec.rb
index 83104711b55..e4a2ccee7d0 100644
--- a/spec/models/shard_spec.rb
+++ b/spec/models/shard_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literals: true
-require 'spec_helper'
+require "spec_helper"
describe Shard do
- describe '.populate!' do
- it 'creates shards based on the config file' do
+ describe ".populate!" do
+ it "creates shards based on the config file" do
expect(described_class.all).to be_empty
stub_storage_settings(foo: {}, bar: {}, baz: {})
@@ -14,37 +14,37 @@ describe Shard do
end
end
- describe '.by_name' do
- let(:default_shard) { described_class.find_by(name: 'default') }
+ describe ".by_name" do
+ let(:default_shard) { described_class.find_by(name: "default") }
before do
described_class.populate!
end
- it 'returns an existing shard' do
- expect(described_class.by_name('default')).to eq(default_shard)
+ it "returns an existing shard" do
+ expect(described_class.by_name("default")).to eq(default_shard)
end
- it 'creates a new shard' do
- result = described_class.by_name('foo')
+ it "creates a new shard" do
+ result = described_class.by_name("foo")
expect(result).not_to eq(default_shard)
- expect(result.name).to eq('foo')
+ expect(result.name).to eq("foo")
end
- it 'retries if creation races' do
+ it "retries if creation races" do
expect(described_class)
.to receive(:find_or_create_by)
- .with(name: 'default')
- .and_raise(ActiveRecord::RecordNotUnique, 'fail')
+ .with(name: "default")
+ .and_raise(ActiveRecord::RecordNotUnique, "fail")
.once
expect(described_class)
.to receive(:find_or_create_by)
- .with(name: 'default')
+ .with(name: "default")
.and_call_original
- expect(described_class.by_name('default')).to eq(default_shard)
+ expect(described_class.by_name("default")).to eq(default_shard)
end
end
end
diff --git a/spec/models/snippet_blob_spec.rb b/spec/models/snippet_blob_spec.rb
index 7c71c458fcc..f7a4a2d1d5c 100644
--- a/spec/models/snippet_blob_spec.rb
+++ b/spec/models/snippet_blob_spec.rb
@@ -1,45 +1,45 @@
-require 'spec_helper'
+require "spec_helper"
describe SnippetBlob do
let(:snippet) { create(:snippet) }
subject { described_class.new(snippet) }
- describe '#id' do
- it 'returns the snippet ID' do
+ describe "#id" do
+ it "returns the snippet ID" do
expect(subject.id).to eq(snippet.id)
end
end
- describe '#name' do
- it 'returns the snippet file name' do
+ describe "#name" do
+ it "returns the snippet file name" do
expect(subject.name).to eq(snippet.file_name)
end
end
- describe '#size' do
- it 'returns the data size' do
+ describe "#size" do
+ it "returns the data size" do
expect(subject.size).to eq(subject.data.bytesize)
end
end
- describe '#data' do
- it 'returns the snippet content' do
+ describe "#data" do
+ it "returns the snippet content" do
expect(subject.data).to eq(snippet.content)
end
end
- describe '#rendered_markup' do
- context 'when the content is GFM' do
- let(:snippet) { create(:snippet, file_name: 'file.md') }
+ describe "#rendered_markup" do
+ context "when the content is GFM" do
+ let(:snippet) { create(:snippet, file_name: "file.md") }
- it 'returns the rendered GFM' do
+ it "returns the rendered GFM" do
expect(subject.rendered_markup).to eq(snippet.content_html)
end
end
- context 'when the content is not GFM' do
- it 'returns nil' do
+ context "when the content is not GFM" do
+ it "returns nil" do
expect(subject.rendered_markup).to be_nil
end
end
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index 664dc3fa145..7f1809e2ea2 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -1,7 +1,7 @@
-require 'spec_helper'
+require "spec_helper"
describe Snippet do
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Gitlab::VisibilityLevel) }
@@ -11,14 +11,14 @@ describe Snippet do
it { is_expected.to include_module(Awardable) }
end
- describe 'associations' do
- it { is_expected.to belong_to(:author).class_name('User') }
+ describe "associations" do
+ it { is_expected.to belong_to(:author).class_name("User") }
it { is_expected.to belong_to(:project) }
it { is_expected.to have_many(:notes).dependent(:destroy) }
it { is_expected.to have_many(:award_emoji).dependent(:destroy) }
end
- describe 'validation' do
+ describe "validation" do
it { is_expected.to validate_presence_of(:author) }
it { is_expected.to validate_presence_of(:title) }
@@ -31,51 +31,51 @@ describe Snippet do
it { is_expected.to validate_inclusion_of(:visibility_level).in_array(Gitlab::VisibilityLevel.values) }
end
- describe '#to_reference' do
- context 'when snippet belongs to a project' do
- let(:project) { build(:project, name: 'sample-project') }
+ describe "#to_reference" do
+ context "when snippet belongs to a project" do
+ let(:project) { build(:project, name: "sample-project") }
let(:snippet) { build(:snippet, id: 1, project: project) }
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(snippet.to_reference).to eq "$1"
end
- it 'supports a cross-project reference' do
- another_project = build(:project, name: 'another-project', namespace: project.namespace)
+ it "supports a cross-project reference" do
+ another_project = build(:project, name: "another-project", namespace: project.namespace)
expect(snippet.to_reference(another_project)).to eq "sample-project$1"
end
end
- context 'when snippet does not belong to a project' do
+ context "when snippet does not belong to a project" do
let(:snippet) { build(:snippet, id: 1, project: nil) }
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(snippet.to_reference).to eq "$1"
end
- it 'still returns shortest reference when project arg present' do
- another_project = build(:project, name: 'another-project')
+ it "still returns shortest reference when project arg present" do
+ another_project = build(:project, name: "another-project")
expect(snippet.to_reference(another_project)).to eq "$1"
end
end
end
- describe '#file_name' do
+ describe "#file_name" do
let(:project) { create(:project) }
- context 'file_name is nil' do
+ context "file_name is nil" do
let(:snippet) { create(:snippet, project: project, file_name: nil) }
- it 'returns an empty string' do
- expect(snippet.file_name).to eq ''
+ it "returns an empty string" do
+ expect(snippet.file_name).to eq ""
end
end
- context 'file_name is not nil' do
- let(:snippet) { create(:snippet, project: project, file_name: 'foo.txt') }
+ context "file_name is not nil" do
+ let(:snippet) { create(:snippet, project: project, file_name: "foo.txt") }
- it 'returns the file_name' do
- expect(snippet.file_name).to eq 'foo.txt'
+ it "returns the file_name" do
+ expect(snippet.file_name).to eq "foo.txt"
end
end
end
@@ -87,53 +87,53 @@ describe Snippet do
end
end
- describe '.search' do
- let(:snippet) { create(:snippet, title: 'test snippet') }
+ describe ".search" do
+ let(:snippet) { create(:snippet, title: "test snippet") }
- it 'returns snippets with a matching title' do
+ it "returns snippets with a matching title" do
expect(described_class.search(snippet.title)).to eq([snippet])
end
- it 'returns snippets with a partially matching title' do
+ it "returns snippets with a partially matching title" do
expect(described_class.search(snippet.title[0..2])).to eq([snippet])
end
- it 'returns snippets with a matching title regardless of the casing' do
+ it "returns snippets with a matching title regardless of the casing" do
expect(described_class.search(snippet.title.upcase)).to eq([snippet])
end
- it 'returns snippets with a matching file name' do
+ it "returns snippets with a matching file name" do
expect(described_class.search(snippet.file_name)).to eq([snippet])
end
- it 'returns snippets with a partially matching file name' do
+ it "returns snippets with a partially matching file name" do
expect(described_class.search(snippet.file_name[0..2])).to eq([snippet])
end
- it 'returns snippets with a matching file name regardless of the casing' do
+ it "returns snippets with a matching file name regardless of the casing" do
expect(described_class.search(snippet.file_name.upcase)).to eq([snippet])
end
end
- describe '.search_code' do
- let(:snippet) { create(:snippet, content: 'class Foo; end') }
+ describe ".search_code" do
+ let(:snippet) { create(:snippet, content: "class Foo; end") }
- it 'returns snippets with matching content' do
+ it "returns snippets with matching content" do
expect(described_class.search_code(snippet.content)).to eq([snippet])
end
- it 'returns snippets with partially matching content' do
- expect(described_class.search_code('class')).to eq([snippet])
+ it "returns snippets with partially matching content" do
+ expect(described_class.search_code("class")).to eq([snippet])
end
- it 'returns snippets with matching content regardless of the casing' do
- expect(described_class.search_code('FOO')).to eq([snippet])
+ it "returns snippets with matching content regardless of the casing" do
+ expect(described_class.search_code("FOO")).to eq([snippet])
end
end
- describe '.with_optional_visibility' do
- context 'when a visibility level is provided' do
- it 'returns snippets with the given visibility' do
+ describe ".with_optional_visibility" do
+ context "when a visibility level is provided" do
+ it "returns snippets with the given visibility" do
create(:snippet, :private)
snippet = create(:snippet, :public)
@@ -144,8 +144,8 @@ describe Snippet do
end
end
- context 'when a visibility level is not provided' do
- it 'returns all snippets' do
+ context "when a visibility level is not provided" do
+ it "returns all snippets" do
snippet1 = create(:snippet, :public)
snippet2 = create(:snippet, :private)
snippets = described_class.with_optional_visibility
@@ -155,8 +155,8 @@ describe Snippet do
end
end
- describe '.only_global_snippets' do
- it 'returns snippets not associated with any projects' do
+ describe ".only_global_snippets" do
+ it "returns snippets not associated with any projects" do
create(:project_snippet)
snippet = create(:snippet)
@@ -166,7 +166,7 @@ describe Snippet do
end
end
- describe '.only_include_projects_visible_to' do
+ describe ".only_include_projects_visible_to" do
let!(:project1) { create(:project, :public) }
let!(:project2) { create(:project, :internal) }
let!(:project3) { create(:project, :private) }
@@ -174,8 +174,8 @@ describe Snippet do
let!(:snippet2) { create(:project_snippet, project: project2) }
let!(:snippet3) { create(:project_snippet, project: project3) }
- context 'when a user is provided' do
- it 'returns snippets visible to the user' do
+ context "when a user is provided" do
+ it "returns snippets visible to the user" do
user = create(:user)
snippets = described_class.only_include_projects_visible_to(user)
@@ -185,8 +185,8 @@ describe Snippet do
end
end
- context 'when a user is not provided' do
- it 'returns snippets visible to anonymous users' do
+ context "when a user is not provided" do
+ it "returns snippets visible to anonymous users" do
snippets = described_class.only_include_projects_visible_to
expect(snippets).to include(snippet1)
@@ -195,9 +195,9 @@ describe Snippet do
end
end
- describe 'only_include_projects_with_snippets_enabled' do
- context 'when the include_private option is enabled' do
- it 'includes snippets for projects with snippets set to private' do
+ describe "only_include_projects_with_snippets_enabled" do
+ context "when the include_private option is enabled" do
+ it "includes snippets for projects with snippets set to private" do
project = create(:project)
project.project_feature
@@ -212,8 +212,8 @@ describe Snippet do
end
end
- context 'when the include_private option is not enabled' do
- it 'does not include snippets for projects that have snippets set to private' do
+ context "when the include_private option is not enabled" do
+ it "does not include snippets for projects that have snippets set to private" do
project = create(:project)
project.project_feature
@@ -227,7 +227,7 @@ describe Snippet do
end
end
- it 'includes snippets for projects with snippets enabled' do
+ it "includes snippets for projects with snippets enabled" do
project = create(:project)
project.project_feature
@@ -240,8 +240,8 @@ describe Snippet do
end
end
- describe '.only_include_authorized_projects' do
- it 'only includes snippets for projects the user is authorized to see' do
+ describe ".only_include_authorized_projects" do
+ it "only includes snippets for projects the user is authorized to see" do
user = create(:user)
project1 = create(:project, :private)
project2 = create(:project, :private)
@@ -257,9 +257,9 @@ describe Snippet do
end
end
- describe '.for_project_with_user' do
- context 'when a user is provided' do
- it 'returns an empty collection if the user can not view the snippets' do
+ describe ".for_project_with_user" do
+ context "when a user is provided" do
+ it "returns an empty collection if the user can not view the snippets" do
project = create(:project, :private)
user = create(:user)
@@ -271,7 +271,7 @@ describe Snippet do
expect(described_class.for_project_with_user(project, user)).to be_empty
end
- it 'returns the snippets if the user is a member of the project' do
+ it "returns the snippets if the user is a member of the project" do
project = create(:project, :private)
user = create(:user)
snippet = create(:project_snippet, project: project)
@@ -283,7 +283,7 @@ describe Snippet do
expect(snippets).to eq([snippet])
end
- it 'returns public snippets for a public project the user is not a member of' do
+ it "returns public snippets for a public project the user is not a member of" do
project = create(:project, :public)
project.project_feature
@@ -300,8 +300,8 @@ describe Snippet do
end
end
- context 'when a user is not provided' do
- it 'returns an empty collection for a private project' do
+ context "when a user is not provided" do
+ it "returns an empty collection for a private project" do
project = create(:project, :private)
project.project_feature
@@ -312,7 +312,7 @@ describe Snippet do
expect(described_class.for_project_with_user(project)).to be_empty
end
- it 'returns public snippets for a public project' do
+ it "returns public snippets for a public project" do
project = create(:project, :public)
snippet = create(:project_snippet, :public, project: project)
@@ -328,8 +328,8 @@ describe Snippet do
end
end
- describe '.visible_to_or_authored_by' do
- it 'returns snippets visible to the user' do
+ describe ".visible_to_or_authored_by" do
+ it "returns snippets visible to the user" do
user = create(:user)
snippet1 = create(:snippet, :public)
snippet2 = create(:snippet, :private, author: user)
@@ -342,34 +342,34 @@ describe Snippet do
end
end
- describe '#participants' do
+ describe "#participants" do
let(:project) { create(:project, :public) }
- let(:snippet) { create(:snippet, content: 'foo', project: project) }
+ let(:snippet) { create(:snippet, content: "foo", project: project) }
let!(:note1) do
create(:note_on_project_snippet,
- noteable: snippet,
- project: project,
- note: 'a')
+ noteable: snippet,
+ project: project,
+ note: "a")
end
let!(:note2) do
create(:note_on_project_snippet,
- noteable: snippet,
- project: project,
- note: 'b')
+ noteable: snippet,
+ project: project,
+ note: "b")
end
- it 'includes the snippet author' do
+ it "includes the snippet author" do
expect(snippet.participants).to include(snippet.author)
end
- it 'includes the note authors' do
+ it "includes the note authors" do
expect(snippet.participants).to include(note1.author, note2.author)
end
end
- describe '#check_for_spam' do
+ describe "#check_for_spam" do
let(:snippet) { create :snippet, visibility_level: visibility_level }
subject do
@@ -377,24 +377,24 @@ describe Snippet do
snippet.check_for_spam?
end
- context 'when public and spammable attributes changed' do
+ context "when public and spammable attributes changed" do
let(:visibility_level) { Snippet::PUBLIC }
- let(:title) { 'woo' }
+ let(:title) { "woo" }
- it 'returns true' do
+ it "returns true" do
is_expected.to be_truthy
end
end
- context 'when private' do
+ context "when private" do
let(:visibility_level) { Snippet::PRIVATE }
let(:title) { snippet.title }
- it 'returns false' do
+ it "returns false" do
is_expected.to be_falsey
end
- it 'returns true when switching to public' do
+ it "returns true when switching to public" do
snippet.save!
snippet.visibility_level = Snippet::PUBLIC
@@ -402,20 +402,20 @@ describe Snippet do
end
end
- context 'when spammable attributes have not changed' do
+ context "when spammable attributes have not changed" do
let(:visibility_level) { Snippet::PUBLIC }
let(:title) { snippet.title }
- it 'returns false' do
+ it "returns false" do
is_expected.to be_falsey
end
end
end
- describe '#blob' do
+ describe "#blob" do
let(:snippet) { create(:snippet) }
- it 'returns a blob representing the snippet data' do
+ it "returns a blob representing the snippet data" do
blob = snippet.blob
expect(blob).to be_a(Blob)
@@ -424,20 +424,20 @@ describe Snippet do
end
end
- describe '#embeddable?' do
- context 'project snippet' do
+ describe "#embeddable?" do
+ context "project snippet" do
[
- { project: :public, snippet: :public, embeddable: true },
- { project: :internal, snippet: :public, embeddable: false },
- { project: :private, snippet: :public, embeddable: false },
- { project: :public, snippet: :internal, embeddable: false },
- { project: :internal, snippet: :internal, embeddable: false },
- { project: :private, snippet: :internal, embeddable: false },
- { project: :public, snippet: :private, embeddable: false },
- { project: :internal, snippet: :private, embeddable: false },
- { project: :private, snippet: :private, embeddable: false }
+ {project: :public, snippet: :public, embeddable: true},
+ {project: :internal, snippet: :public, embeddable: false},
+ {project: :private, snippet: :public, embeddable: false},
+ {project: :public, snippet: :internal, embeddable: false},
+ {project: :internal, snippet: :internal, embeddable: false},
+ {project: :private, snippet: :internal, embeddable: false},
+ {project: :public, snippet: :private, embeddable: false},
+ {project: :internal, snippet: :private, embeddable: false},
+ {project: :private, snippet: :private, embeddable: false},
].each do |combination|
- it 'only returns true when both project and snippet are public' do
+ it "only returns true when both project and snippet are public" do
project = create(:project, combination[:project])
snippet = create(:project_snippet, combination[:snippet], project: project)
@@ -446,13 +446,13 @@ describe Snippet do
end
end
- context 'personal snippet' do
+ context "personal snippet" do
[
- { snippet: :public, embeddable: true },
- { snippet: :internal, embeddable: false },
- { snippet: :private, embeddable: false }
+ {snippet: :public, embeddable: true},
+ {snippet: :internal, embeddable: false},
+ {snippet: :private, embeddable: false},
].each do |combination|
- it 'only returns true when snippet is public' do
+ it "only returns true when snippet is public" do
snippet = create(:personal_snippet, combination[:snippet])
expect(snippet.embeddable?).to eq(combination[:embeddable])
diff --git a/spec/models/spam_log_spec.rb b/spec/models/spam_log_spec.rb
index 90a2caaeb88..0c3875c4cb5 100644
--- a/spec/models/spam_log_spec.rb
+++ b/spec/models/spam_log_spec.rb
@@ -1,24 +1,24 @@
-require 'spec_helper'
+require "spec_helper"
describe SpamLog do
let(:admin) { create(:admin) }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:user) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:user) }
end
- describe '#remove_user' do
- it 'blocks the user' do
+ describe "#remove_user" do
+ it "blocks the user" do
spam_log = build(:spam_log)
expect { spam_log.remove_user(deleted_by: admin) }.to change { spam_log.user.blocked? }.to(true)
end
- it 'removes the user' do
+ it "removes the user" do
spam_log = build(:spam_log)
user = spam_log.user
diff --git a/spec/models/ssh_host_key_spec.rb b/spec/models/ssh_host_key_spec.rb
index 4c677569561..e4b6cfdf2bd 100644
--- a/spec/models/ssh_host_key_spec.rb
+++ b/spec/models/ssh_host_key_spec.rb
@@ -1,25 +1,25 @@
-require 'spec_helper'
+require "spec_helper"
describe SshHostKey do
using RSpec::Parameterized::TableSyntax
include ReactiveCachingHelpers
let(:key1) do
- 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3UpyF2iLqy1d63M6k3jH1vuEnq/NWtE+o' \
- 'rJe1Xn7JoRbduKd6zpsJ0JhBGWgcQK0ph0aGW5PcudzzBSc+SlYfCc4GTaxDtmj41hW0o72m' \
- 'NiuDW3oKXXShOiVRde2ZOquH8Z865jGiZIC8BI/bXZD29IGUih0hPu7Rjp70VYiE+35QRf/p' \
- 'sD0Ddrz8QUIG3A/2dMzLI5F5ZORk3BIX2F3mJwJOvZxRhR/SqyphDMZ5eZ0EzqbFBCDE6HAB' \
- 'Woz9ck8RBGLvCIggmDHj3FmMLcQGMDiy6wKp7QdnBtxjCP6vtE6YPUM223AqsWt+9NTtCfB8' \
- 'YdNAH7YcHHOR1FgtSk1x'
+ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3UpyF2iLqy1d63M6k3jH1vuEnq/NWtE+o" \
+ "rJe1Xn7JoRbduKd6zpsJ0JhBGWgcQK0ph0aGW5PcudzzBSc+SlYfCc4GTaxDtmj41hW0o72m" \
+ "NiuDW3oKXXShOiVRde2ZOquH8Z865jGiZIC8BI/bXZD29IGUih0hPu7Rjp70VYiE+35QRf/p" \
+ "sD0Ddrz8QUIG3A/2dMzLI5F5ZORk3BIX2F3mJwJOvZxRhR/SqyphDMZ5eZ0EzqbFBCDE6HAB" \
+ "Woz9ck8RBGLvCIggmDHj3FmMLcQGMDiy6wKp7QdnBtxjCP6vtE6YPUM223AqsWt+9NTtCfB8" \
+ "YdNAH7YcHHOR1FgtSk1x"
end
let(:key2) do
- 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLIp+4ciR2YO9f9rpldc7InNQw/TBUtcNb' \
- 'J2XR0rr15/5ytz7YM16xXG0Qjx576PNSmqs4gbTrvTuFZak+v1Jx/9deHRq/yqp9f+tv33+i' \
- 'aJGCQCX/+OVY7aWgV2R9YsS7XQ4mnv4XlOTEssib/rGAIT+ATd/GcdYSEOO+dh4O09/6O/jI' \
- 'MGSeP+NNetgn1nPCnLOjrXFZUnUtNDi6EEKeIlrliJjSb7Jr4f7gjvZnv4RskWHHFo8FgAAq' \
- 't0gOMT6EmKrnypBe2vLGSAXbtkXr01q6/DNPH+n9VA1LTV6v1KN/W5CN5tQV11wRSKiM8g5O' \
- 'Ebi86VjJRi2sOuYoXQU1'
+ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLIp+4ciR2YO9f9rpldc7InNQw/TBUtcNb" \
+ "J2XR0rr15/5ytz7YM16xXG0Qjx576PNSmqs4gbTrvTuFZak+v1Jx/9deHRq/yqp9f+tv33+i" \
+ "aJGCQCX/+OVY7aWgV2R9YsS7XQ4mnv4XlOTEssib/rGAIT+ATd/GcdYSEOO+dh4O09/6O/jI" \
+ "MGSeP+NNetgn1nPCnLOjrXFZUnUtNDi6EEKeIlrliJjSb7Jr4f7gjvZnv4RskWHHFo8FgAAq" \
+ "t0gOMT6EmKrnypBe2vLGSAXbtkXr01q6/DNPH+n9VA1LTV6v1KN/W5CN5tQV11wRSKiM8g5O" \
+ "Ebi86VjJRi2sOuYoXQU1"
end
# Purposefully ordered so that `sort` will make changes
@@ -41,36 +41,36 @@ describe SshHostKey do
stderr = double(:stderr, read: stderr)
wait_thr = double(:wait_thr, value: double(success?: status))
- expect(Open3).to receive(:popen3).with({}, 'ssh-keyscan', *args).and_yield(stdin, stdout, stderr, wait_thr)
+ expect(Open3).to receive(:popen3).with({}, "ssh-keyscan", *args).and_yield(stdin, stdout, stderr, wait_thr)
stdin
end
let(:project) { build(:project) }
- subject(:ssh_host_key) { described_class.new(project: project, url: 'ssh://example.com:2222', compare_host_keys: compare_host_keys) }
+ subject(:ssh_host_key) { described_class.new(project: project, url: "ssh://example.com:2222", compare_host_keys: compare_host_keys) }
- describe '.primary_key' do
- it 'returns a symbol' do
+ describe ".primary_key" do
+ it "returns a symbol" do
expect(described_class.primary_key).to eq(:id)
end
end
- describe '.find_by' do
+ describe ".find_by" do
let(:project) { create(:project) }
- let(:url) { 'ssh://invalid.invalid:2222' }
+ let(:url) { "ssh://invalid.invalid:2222" }
- let(:finding_id) { [project.id, url].join(':') }
+ let(:finding_id) { [project.id, url].join(":") }
- it 'accepts a string key' do
- result = described_class.find_by('id' => finding_id)
+ it "accepts a string key" do
+ result = described_class.find_by("id" => finding_id)
expect(result).to be_a(described_class)
expect(result.project).to eq(project)
expect(result.url.to_s).to eq(url)
end
- it 'accepts a symbol key' do
+ it "accepts a symbol key" do
result = described_class.find_by(id: finding_id)
expect(result).to be_a(described_class)
@@ -79,52 +79,52 @@ describe SshHostKey do
end
end
- describe '#fingerprints', :use_clean_rails_memory_store_caching do
- it 'returns an array of indexed fingerprints when the cache is filled' do
+ describe "#fingerprints", :use_clean_rails_memory_store_caching do
+ it "returns an array of indexed fingerprints when the cache is filled" do
stub_reactive_cache(ssh_host_key, known_hosts: known_hosts)
expected = [key1, key2]
.map { |data| Gitlab::SSHPublicKey.new(data) }
.each_with_index
- .map { |key, i| { bits: key.bits, fingerprint: key.fingerprint, type: key.type, index: i } }
+ .map { |key, i| {bits: key.bits, fingerprint: key.fingerprint, type: key.type, index: i} }
expect(ssh_host_key.fingerprints.as_json).to eq(expected)
end
- it 'returns an empty array when the cache is empty' do
+ it "returns an empty array when the cache is empty" do
expect(ssh_host_key.fingerprints).to eq([])
end
end
- describe '#fingerprints', :use_clean_rails_memory_store_caching do
- it 'returns an array of indexed fingerprints when the cache is filled' do
+ describe "#fingerprints", :use_clean_rails_memory_store_caching do
+ it "returns an array of indexed fingerprints when the cache is filled" do
stub_reactive_cache(ssh_host_key, known_hosts: known_hosts)
expect(ssh_host_key.fingerprints.as_json).to eq(
[
- { bits: 2048, fingerprint: Gitlab::SSHPublicKey.new(key1).fingerprint, type: :rsa, index: 0 },
- { bits: 2048, fingerprint: Gitlab::SSHPublicKey.new(key2).fingerprint, type: :rsa, index: 1 }
+ {bits: 2048, fingerprint: Gitlab::SSHPublicKey.new(key1).fingerprint, type: :rsa, index: 0},
+ {bits: 2048, fingerprint: Gitlab::SSHPublicKey.new(key2).fingerprint, type: :rsa, index: 1},
]
)
end
- it 'returns an empty array when the cache is empty' do
+ it "returns an empty array when the cache is empty" do
expect(ssh_host_key.fingerprints).to eq([])
end
end
- describe '#host_keys_changed?' do
+ describe "#host_keys_changed?" do
where(:known_hosts_a, :known_hosts_b, :result) do
known_hosts | extra | true
known_hosts | "foo\n" | true
- known_hosts | '' | true
+ known_hosts | "" | true
known_hosts | nil | true
known_hosts | known_hosts | false
reversed | known_hosts | false
extra | "foo\n" | true
- '' | '' | false
+ "" | "" | false
nil | nil | false
- '' | nil | false
+ "" | nil | false
end
with_them do
@@ -132,7 +132,7 @@ describe SshHostKey do
subject { ssh_host_key.host_keys_changed? }
- context '(normal)' do
+ context "(normal)" do
let(:compare_host_keys) { known_hosts_b }
before do
@@ -143,7 +143,7 @@ describe SshHostKey do
end
# Comparisons should be symmetrical, so test the reverse too
- context '(reversed)' do
+ context "(reversed)" do
let(:compare_host_keys) { known_hosts_a }
before do
@@ -155,10 +155,10 @@ describe SshHostKey do
end
end
- describe '#calculate_reactive_cache' do
+ describe "#calculate_reactive_cache" do
subject(:cache) { ssh_host_key.calculate_reactive_cache }
- it 'writes the hostname to STDIN' do
+ it "writes the hostname to STDIN" do
stdin = stub_ssh_keyscan(%w[-T 5 -p 2222 -f-])
cache
@@ -166,27 +166,27 @@ describe SshHostKey do
expect(stdin.string).to eq("example.com\n")
end
- context 'successful key scan' do
- it 'stores the cleaned known_hosts data' do
+ context "successful key scan" do
+ it "stores the cleaned known_hosts data" do
stub_ssh_keyscan(%w[-T 5 -p 2222 -f-], stdout: "KEY 1\nKEY 1\n\n# comment\nKEY 2\n")
is_expected.to eq(known_hosts: "KEY 1\nKEY 2\n")
end
end
- context 'failed key scan (exit code 1)' do
- it 'returns a generic error' do
- stub_ssh_keyscan(%w[-T 5 -p 2222 -f-], stdout: 'blarg', status: false)
+ context "failed key scan (exit code 1)" do
+ it "returns a generic error" do
+ stub_ssh_keyscan(%w[-T 5 -p 2222 -f-], stdout: "blarg", status: false)
- is_expected.to eq(error: 'Failed to detect SSH host keys')
+ is_expected.to eq(error: "Failed to detect SSH host keys")
end
end
- context 'failed key scan (exit code 0)' do
- it 'returns a generic error' do
- stub_ssh_keyscan(%w[-T 5 -p 2222 -f-], stderr: 'Unknown host')
+ context "failed key scan (exit code 0)" do
+ it "returns a generic error" do
+ stub_ssh_keyscan(%w[-T 5 -p 2222 -f-], stderr: "Unknown host")
- is_expected.to eq(error: 'Failed to detect SSH host keys')
+ is_expected.to eq(error: "Failed to detect SSH host keys")
end
end
end
diff --git a/spec/models/subscription_spec.rb b/spec/models/subscription_spec.rb
index 9e4c2620d82..867e981a00b 100644
--- a/spec/models/subscription_spec.rb
+++ b/spec/models/subscription_spec.rb
@@ -1,17 +1,17 @@
-require 'spec_helper'
+require "spec_helper"
describe Subscription do
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:subscribable) }
it { is_expected.to belong_to(:user) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:subscribable) }
it { is_expected.to validate_presence_of(:user) }
- it 'validates uniqueness of project_id scoped to subscribable_id, subscribable_type, and user_id' do
+ it "validates uniqueness of project_id scoped to subscribable_id, subscribable_type, and user_id" do
create(:subscription)
expect(subject).to validate_uniqueness_of(:project_id).scoped_to([:subscribable_id, :subscribable_type, :user_id])
diff --git a/spec/models/suggestion_spec.rb b/spec/models/suggestion_spec.rb
index cafc725dddb..bd3dbd85acc 100644
--- a/spec/models/suggestion_spec.rb
+++ b/spec/models/suggestion_spec.rb
@@ -1,18 +1,18 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe Suggestion do
let(:suggestion) { create(:suggestion) }
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:note) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:note) }
- context 'when suggestion is applied' do
+ context "when suggestion is applied" do
before do
allow(subject).to receive(:applied?).and_return(true)
end
@@ -21,9 +21,9 @@ describe Suggestion do
end
end
- describe '#appliable?' do
- context 'when note does not support suggestions' do
- it 'returns false' do
+ describe "#appliable?" do
+ context "when note does not support suggestions" do
+ it "returns false" do
expect_next_instance_of(DiffNote) do |note|
allow(note).to receive(:supports_suggestion?) { false }
end
@@ -32,15 +32,15 @@ describe Suggestion do
end
end
- context 'when patch is already applied' do
+ context "when patch is already applied" do
let(:suggestion) { create(:suggestion, :applied) }
- it 'returns false' do
+ it "returns false" do
expect(suggestion).not_to be_appliable
end
end
- context 'when merge request is not opened' do
+ context "when merge request is not opened" do
let(:merge_request) { create(:merge_request, :merged) }
let(:note) do
create(:diff_note_on_merge_request, project: merge_request.project,
@@ -49,7 +49,7 @@ describe Suggestion do
let(:suggestion) { create(:suggestion, note: note) }
- it 'returns false' do
+ it "returns false" do
expect(suggestion).not_to be_appliable
end
end
diff --git a/spec/models/system_note_metadata_spec.rb b/spec/models/system_note_metadata_spec.rb
index 1e3f587e460..9ede4a0d024 100644
--- a/spec/models/system_note_metadata_spec.rb
+++ b/spec/models/system_note_metadata_spec.rb
@@ -1,24 +1,24 @@
-require 'spec_helper'
+require "spec_helper"
describe SystemNoteMetadata do
- describe 'associations' do
+ describe "associations" do
it { is_expected.to belong_to(:note) }
end
- describe 'validation' do
+ describe "validation" do
it { is_expected.to validate_presence_of(:note) }
- context 'when action type is invalid' do
+ context "when action type is invalid" do
subject do
- build(:system_note_metadata, note: build(:note), action: 'invalid_type' )
+ build(:system_note_metadata, note: build(:note), action: "invalid_type")
end
it { is_expected.to be_invalid }
end
- context 'when action type is valid' do
+ context "when action type is valid" do
subject do
- build(:system_note_metadata, note: build(:note), action: 'merge' )
+ build(:system_note_metadata, note: build(:note), action: "merge")
end
it { is_expected.to be_valid }
diff --git a/spec/models/term_agreement_spec.rb b/spec/models/term_agreement_spec.rb
index 950dfa09a6a..9a7e132f7bd 100644
--- a/spec/models/term_agreement_spec.rb
+++ b/spec/models/term_agreement_spec.rb
@@ -1,13 +1,13 @@
-require 'spec_helper'
+require "spec_helper"
describe TermAgreement do
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:term) }
it { is_expected.to validate_presence_of(:user) }
end
- describe '.accepted' do
- it 'only includes accepted terms' do
+ describe ".accepted" do
+ it "only includes accepted terms" do
accepted = create(:term_agreement, :accepted)
create(:term_agreement, :declined)
diff --git a/spec/models/timelog_spec.rb b/spec/models/timelog_spec.rb
index a0c93c531ea..ee6cc0138dc 100644
--- a/spec/models/timelog_spec.rb
+++ b/spec/models/timelog_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
RSpec.describe Timelog do
subject { build(:timelog) }
@@ -13,27 +13,27 @@ RSpec.describe Timelog do
it { is_expected.to validate_presence_of(:time_spent) }
it { is_expected.to validate_presence_of(:user) }
- describe 'Issuable validation' do
- it 'is invalid if issue_id and merge_request_id are missing' do
- subject.attributes = { issue: nil, merge_request: nil }
+ describe "Issuable validation" do
+ it "is invalid if issue_id and merge_request_id are missing" do
+ subject.attributes = {issue: nil, merge_request: nil}
expect(subject).to be_invalid
end
- it 'is invalid if issue_id and merge_request_id are set' do
- subject.attributes = { issue: issue, merge_request: merge_request }
+ it "is invalid if issue_id and merge_request_id are set" do
+ subject.attributes = {issue: issue, merge_request: merge_request}
expect(subject).to be_invalid
end
- it 'is valid if only issue_id is set' do
- subject.attributes = { issue: issue, merge_request: nil }
+ it "is valid if only issue_id is set" do
+ subject.attributes = {issue: issue, merge_request: nil}
expect(subject).to be_valid
end
- it 'is valid if only merge_request_id is set' do
- subject.attributes = { merge_request: merge_request, issue: nil }
+ it "is valid if only merge_request_id is set" do
+ subject.attributes = {merge_request: merge_request, issue: nil}
expect(subject).to be_valid
end
diff --git a/spec/models/todo_spec.rb b/spec/models/todo_spec.rb
index 3682e21ca40..66b5052760c 100644
--- a/spec/models/todo_spec.rb
+++ b/spec/models/todo_spec.rb
@@ -1,9 +1,9 @@
-require 'spec_helper'
+require "spec_helper"
describe Todo do
let(:issue) { create(:issue) }
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:author).class_name("User") }
it { is_expected.to belong_to(:note) }
it { is_expected.to belong_to(:project) }
@@ -12,25 +12,25 @@ describe Todo do
it { is_expected.to belong_to(:user) }
end
- describe 'respond to' do
+ describe "respond to" do
it { is_expected.to respond_to(:author_name) }
it { is_expected.to respond_to(:author_email) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:action) }
it { is_expected.to validate_presence_of(:target_type) }
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_presence_of(:author) }
- context 'for commits' do
- subject { described_class.new(target_type: 'Commit') }
+ context "for commits" do
+ subject { described_class.new(target_type: "Commit") }
it { is_expected.to validate_presence_of(:commit_id) }
it { is_expected.not_to validate_presence_of(:target_id) }
end
- context 'for issuables' do
+ context "for issuables" do
subject { described_class.new(target: issue) }
it { is_expected.to validate_presence_of(:target_id) }
@@ -38,117 +38,117 @@ describe Todo do
end
end
- describe '#body' do
+ describe "#body" do
before do
- subject.target = build(:issue, title: 'Bugfix')
+ subject.target = build(:issue, title: "Bugfix")
end
- it 'returns target title when note is blank' do
+ it "returns target title when note is blank" do
subject.note = nil
- expect(subject.body).to eq 'Bugfix'
+ expect(subject.body).to eq "Bugfix"
end
- it 'returns note when note is present' do
- subject.note = build(:note, note: 'quick fix')
+ it "returns note when note is present" do
+ subject.note = build(:note, note: "quick fix")
- expect(subject.body).to eq 'quick fix'
+ expect(subject.body).to eq "quick fix"
end
end
- describe '#done' do
- it 'changes state to done' do
+ describe "#done" do
+ it "changes state to done" do
todo = create(:todo, state: :pending)
- expect { todo.done }.to change(todo, :state).from('pending').to('done')
+ expect { todo.done }.to change(todo, :state).from("pending").to("done")
end
- it 'does not raise error when is already done' do
+ it "does not raise error when is already done" do
todo = create(:todo, state: :done)
expect { todo.done }.not_to raise_error
end
end
- describe '#for_commit?' do
- it 'returns true when target is a commit' do
- subject.target_type = 'Commit'
+ describe "#for_commit?" do
+ it "returns true when target is a commit" do
+ subject.target_type = "Commit"
expect(subject.for_commit?).to eq true
end
- it 'returns false when target is an issuable' do
- subject.target_type = 'Issue'
+ it "returns false when target is an issuable" do
+ subject.target_type = "Issue"
expect(subject.for_commit?).to eq false
end
end
- describe '#target' do
- context 'for commits' do
+ describe "#target" do
+ context "for commits" do
let(:project) { create(:project, :repository) }
let(:commit) { project.commit }
- it 'returns an instance of Commit when exists' do
+ it "returns an instance of Commit when exists" do
subject.project = project
- subject.target_type = 'Commit'
+ subject.target_type = "Commit"
subject.commit_id = commit.id
expect(subject.target).to be_a(Commit)
expect(subject.target).to eq commit
end
- it 'returns nil when does not exists' do
+ it "returns nil when does not exists" do
subject.project = project
- subject.target_type = 'Commit'
- subject.commit_id = 'xxxx'
+ subject.target_type = "Commit"
+ subject.commit_id = "xxxx"
expect(subject.target).to be_nil
end
end
- it 'returns the issuable for issuables' do
+ it "returns the issuable for issuables" do
subject.target_id = issue.id
subject.target_type = issue.class.name
expect(subject.target).to eq issue
end
end
- describe '#target_reference' do
- it 'returns commit full reference with short id' do
+ describe "#target_reference" do
+ it "returns commit full reference with short id" do
project = create(:project, :repository)
commit = project.commit
subject.project = project
- subject.target_type = 'Commit'
+ subject.target_type = "Commit"
subject.commit_id = commit.id
expect(subject.target_reference).to eq commit.reference_link_text(full: true)
end
- it 'returns full reference for issuables' do
+ it "returns full reference for issuables" do
subject.target = issue
expect(subject.target_reference).to eq issue.to_reference(full: true)
end
end
- describe '#self_added?' do
+ describe "#self_added?" do
let(:user_1) { build(:user) }
before do
subject.user = user_1
end
- it 'is true when the user is the author' do
+ it "is true when the user is the author" do
subject.author = user_1
expect(subject).to be_self_added
end
- it 'is false when the user is not the author' do
+ it "is false when the user is not the author" do
subject.author = build(:user)
expect(subject).not_to be_self_added
end
end
- describe '#self_assigned?' do
+ describe "#self_assigned?" do
let(:user_1) { build(:user) }
before do
@@ -157,25 +157,25 @@ describe Todo do
subject.action = Todo::ASSIGNED
end
- it 'is true when todo is ASSIGNED and self_added' do
+ it "is true when todo is ASSIGNED and self_added" do
expect(subject).to be_self_assigned
end
- it 'is false when the todo is not ASSIGNED' do
+ it "is false when the todo is not ASSIGNED" do
subject.action = Todo::MENTIONED
expect(subject).not_to be_self_assigned
end
- it 'is false when todo is not self_added' do
+ it "is false when todo is not self_added" do
subject.author = build(:user)
expect(subject).not_to be_self_assigned
end
end
- describe '.for_action' do
- it 'returns the todos for a given action' do
+ describe ".for_action" do
+ it "returns the todos for a given action" do
create(:todo, action: Todo::MENTIONED)
todo = create(:todo, action: Todo::ASSIGNED)
@@ -184,8 +184,8 @@ describe Todo do
end
end
- describe '.for_author' do
- it 'returns the todos for a given author' do
+ describe ".for_author" do
+ it "returns the todos for a given author" do
user1 = create(:user)
user2 = create(:user)
todo = create(:todo, author: user1)
@@ -196,8 +196,8 @@ describe Todo do
end
end
- describe '.for_project' do
- it 'returns the todos for a given project' do
+ describe ".for_project" do
+ it "returns the todos for a given project" do
project1 = create(:project)
project2 = create(:project)
todo = create(:todo, project: project1)
@@ -208,8 +208,8 @@ describe Todo do
end
end
- describe '.for_group' do
- it 'returns the todos for a given group' do
+ describe ".for_group" do
+ it "returns the todos for a given group" do
group1 = create(:group)
group2 = create(:group)
todo = create(:todo, group: group1)
@@ -220,8 +220,8 @@ describe Todo do
end
end
- describe '.for_type' do
- it 'returns the todos for a given target type' do
+ describe ".for_type" do
+ it "returns the todos for a given target type" do
todo = create(:todo, target: create(:issue))
create(:todo, target: create(:merge_request))
@@ -230,8 +230,8 @@ describe Todo do
end
end
- describe '.for_target' do
- it 'returns the todos for a given target' do
+ describe ".for_target" do
+ it "returns the todos for a given target" do
todo = create(:todo, target: create(:issue))
create(:todo, target: create(:merge_request))
@@ -241,18 +241,18 @@ describe Todo do
end
end
- describe '.for_commit' do
- it 'returns the todos for a commit ID' do
- todo = create(:todo, commit_id: '123')
+ describe ".for_commit" do
+ it "returns the todos for a commit ID" do
+ todo = create(:todo, commit_id: "123")
- create(:todo, commit_id: '456')
+ create(:todo, commit_id: "456")
- expect(described_class.for_commit('123')).to eq([todo])
+ expect(described_class.for_commit("123")).to eq([todo])
end
end
- describe '.for_group_and_descendants' do
- it 'returns the todos for a group and its descendants' do
+ describe ".for_group_and_descendants" do
+ it "returns the todos for a group and its descendants" do
parent_group = create(:group)
child_group = create(:group, parent: parent_group)
@@ -268,32 +268,32 @@ describe Todo do
end
end
- describe '.any_for_target?' do
- it 'returns true if there are todos for a given target' do
+ describe ".any_for_target?" do
+ it "returns true if there are todos for a given target" do
todo = create(:todo)
expect(described_class.any_for_target?(todo.target)).to eq(true)
end
- it 'returns false if there are no todos for a given target' do
+ it "returns false if there are no todos for a given target" do
issue = create(:issue)
expect(described_class.any_for_target?(issue)).to eq(false)
end
end
- describe '.update_state' do
- it 'updates the state of todos' do
+ describe ".update_state" do
+ it "updates the state of todos" do
todo = create(:todo, :pending)
ids = described_class.update_state(:done)
todo.reload
expect(ids).to eq([todo.id])
- expect(todo.state).to eq('done')
+ expect(todo.state).to eq("done")
end
- it 'does not update todos that already have the given state' do
+ it "does not update todos that already have the given state" do
create(:todo, :pending)
expect(described_class.update_state(:pending)).to be_empty
diff --git a/spec/models/tree_spec.rb b/spec/models/tree_spec.rb
index 6bdb62a0864..263dde639c4 100644
--- a/spec/models/tree_spec.rb
+++ b/spec/models/tree_spec.rb
@@ -1,12 +1,12 @@
-require 'spec_helper'
+require "spec_helper"
describe Tree do
let(:repository) { create(:project, :repository).repository }
let(:sha) { repository.root_ref }
- subject { described_class.new(repository, '54fcc214') }
+ subject { described_class.new(repository, "54fcc214") }
- describe '#readme' do
+ describe "#readme" do
class FakeBlob
attr_reader :name
@@ -19,46 +19,46 @@ describe Tree do
end
end
- it 'returns nil when repository does not contains a README file' do
- files = [FakeBlob.new('file'), FakeBlob.new('license'), FakeBlob.new('copying')]
+ it "returns nil when repository does not contains a README file" do
+ files = [FakeBlob.new("file"), FakeBlob.new("license"), FakeBlob.new("copying")]
expect(subject).to receive(:blobs).and_return(files)
expect(subject.readme).to eq nil
end
- it 'returns nil when repository does not contains a previewable README file' do
- files = [FakeBlob.new('file'), FakeBlob.new('README.pages'), FakeBlob.new('README.png')]
+ it "returns nil when repository does not contains a previewable README file" do
+ files = [FakeBlob.new("file"), FakeBlob.new("README.pages"), FakeBlob.new("README.png")]
expect(subject).to receive(:blobs).and_return(files)
expect(subject.readme).to eq nil
end
- it 'returns README when repository contains a previewable README file' do
- files = [FakeBlob.new('README.png'), FakeBlob.new('README'), FakeBlob.new('file')]
+ it "returns README when repository contains a previewable README file" do
+ files = [FakeBlob.new("README.png"), FakeBlob.new("README"), FakeBlob.new("file")]
expect(subject).to receive(:blobs).and_return(files)
- expect(subject.readme.name).to eq 'README'
+ expect(subject.readme.name).to eq "README"
end
- it 'returns first previewable README when repository contains more than one' do
- files = [FakeBlob.new('file'), FakeBlob.new('README.md'), FakeBlob.new('README.asciidoc')]
+ it "returns first previewable README when repository contains more than one" do
+ files = [FakeBlob.new("file"), FakeBlob.new("README.md"), FakeBlob.new("README.asciidoc")]
expect(subject).to receive(:blobs).and_return(files)
- expect(subject.readme.name).to eq 'README.md'
+ expect(subject.readme.name).to eq "README.md"
end
- it 'returns first plain text README when repository contains more than one' do
- files = [FakeBlob.new('file'), FakeBlob.new('README'), FakeBlob.new('README.txt')]
+ it "returns first plain text README when repository contains more than one" do
+ files = [FakeBlob.new("file"), FakeBlob.new("README"), FakeBlob.new("README.txt")]
expect(subject).to receive(:blobs).and_return(files)
- expect(subject.readme.name).to eq 'README'
+ expect(subject.readme.name).to eq "README"
end
- it 'prioritizes previewable README file over one in plain text' do
- files = [FakeBlob.new('file'), FakeBlob.new('README'), FakeBlob.new('README.md')]
+ it "prioritizes previewable README file over one in plain text" do
+ files = [FakeBlob.new("file"), FakeBlob.new("README"), FakeBlob.new("README.md")]
expect(subject).to receive(:blobs).and_return(files)
- expect(subject.readme.name).to eq 'README.md'
+ expect(subject.readme.name).to eq "README.md"
end
end
end
diff --git a/spec/models/trending_project_spec.rb b/spec/models/trending_project_spec.rb
index 3b5e7ca0d39..f21c7b32612 100644
--- a/spec/models/trending_project_spec.rb
+++ b/spec/models/trending_project_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require "spec_helper"
describe TrendingProject do
let(:user) { create(:user) }
@@ -22,33 +22,33 @@ describe TrendingProject do
create(:note_on_commit, project: internal_project)
end
- describe '.refresh!' do
+ describe ".refresh!" do
before do
described_class.refresh!
end
- it 'populates the trending projects table' do
+ it "populates the trending projects table" do
expect(described_class.count).to eq(2)
end
- it 'removes existing rows before populating the table' do
+ it "removes existing rows before populating the table" do
described_class.refresh!
expect(described_class.count).to eq(2)
end
- it 'stores the project IDs for every trending project' do
+ it "stores the project IDs for every trending project" do
rows = described_class.order(id: :asc).all
expect(rows[0].project_id).to eq(public_project1.id)
expect(rows[1].project_id).to eq(public_project2.id)
end
- it 'does not store projects that fall out of the trending time range' do
+ it "does not store projects that fall out of the trending time range" do
expect(described_class.where(project_id: public_project3).any?).to eq(false)
end
- it 'stores only public projects' do
+ it "stores only public projects" do
expect(described_class.where(project_id: [public_project1.id, public_project2.id]).count).to eq(2)
expect(described_class.where(project_id: [private_project.id, internal_project.id]).count).to eq(0)
end
diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb
index 5a0df9fbbb0..3098f71c5d7 100644
--- a/spec/models/upload_spec.rb
+++ b/spec/models/upload_spec.rb
@@ -1,27 +1,27 @@
-require 'rails_helper'
+require "rails_helper"
describe Upload do
- describe 'assocations' do
+ describe "assocations" do
it { is_expected.to belong_to(:model) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:size) }
it { is_expected.to validate_presence_of(:path) }
it { is_expected.to validate_presence_of(:model) }
it { is_expected.to validate_presence_of(:uploader) }
end
- describe 'callbacks' do
- context 'for a file above the checksum threshold' do
- it 'schedules checksum calculation' do
- stub_const('UploadChecksumWorker', spy)
+ describe "callbacks" do
+ context "for a file above the checksum threshold" do
+ it "schedules checksum calculation" do
+ stub_const("UploadChecksumWorker", spy)
upload = described_class.create(
path: __FILE__,
size: described_class::CHECKSUM_THRESHOLD + 1.kilobyte,
model: build_stubbed(:user),
- uploader: double('ExampleUploader'),
+ uploader: double("ExampleUploader"),
store: ObjectStorage::Store::LOCAL
)
@@ -30,13 +30,13 @@ describe Upload do
end
end
- context 'for a file at or below the checksum threshold' do
- it 'calculates checksum immediately before save' do
+ context "for a file at or below the checksum threshold" do
+ it "calculates checksum immediately before save" do
upload = described_class.new(
path: __FILE__,
size: described_class::CHECKSUM_THRESHOLD,
model: build_stubbed(:user),
- uploader: double('ExampleUploader'),
+ uploader: double("ExampleUploader"),
store: ObjectStorage::Store::LOCAL
)
@@ -46,11 +46,11 @@ describe Upload do
end
end
- describe 'after_destroy' do
- context 'uploader is FileUploader-based' do
+ describe "after_destroy" do
+ context "uploader is FileUploader-based" do
subject { create(:upload, :issuable_upload) }
- it 'calls delete_file!' do
+ it "calls delete_file!" do
is_expected.to receive(:delete_file!)
subject.destroy
@@ -59,9 +59,9 @@ describe Upload do
end
end
- describe '#absolute_path' do
- it 'returns the path directly when already absolute' do
- path = '/path/to/namespace/project/secret/file.jpg'
+ describe "#absolute_path" do
+ it "returns the path directly when already absolute" do
+ path = "/path/to/namespace/project/secret/file.jpg"
upload = described_class.new(path: path, store: ObjectStorage::Store::LOCAL)
expect(upload).not_to receive(:uploader_class)
@@ -70,8 +70,8 @@ describe Upload do
end
it "delegates to the uploader's absolute_path method" do
- uploader = spy('FakeUploader')
- upload = described_class.new(path: 'secret/file.jpg', store: ObjectStorage::Store::LOCAL)
+ uploader = spy("FakeUploader")
+ upload = described_class.new(path: "secret/file.jpg", store: ObjectStorage::Store::LOCAL)
expect(upload).to receive(:uploader_class).and_return(uploader)
upload.absolute_path
@@ -80,21 +80,21 @@ describe Upload do
end
end
- describe '#calculate_checksum!' do
+ describe "#calculate_checksum!" do
let(:upload) do
described_class.new(path: __FILE__,
size: described_class::CHECKSUM_THRESHOLD - 1.megabyte,
store: ObjectStorage::Store::LOCAL)
end
- it 'sets `checksum` to SHA256 sum of the file' do
+ it "sets `checksum` to SHA256 sum of the file" do
expected = Digest::SHA256.file(__FILE__).hexdigest
expect { upload.calculate_checksum! }
.to change { upload.checksum }.from(nil).to(expected)
end
- it 'sets `checksum` to nil for a non-existent file' do
+ it "sets `checksum` to nil for a non-existent file" do
expect(upload).to receive(:exist?).and_return(false)
checksum = Digest::SHA256.file(__FILE__).hexdigest
@@ -105,22 +105,22 @@ describe Upload do
end
end
- describe '#exist?' do
- it 'returns true when the file exists' do
+ describe "#exist?" do
+ it "returns true when the file exists" do
upload = described_class.new(path: __FILE__, store: ObjectStorage::Store::LOCAL)
expect(upload).to exist
end
- context 'when the file does not exist' do
- it 'returns false' do
+ context "when the file does not exist" do
+ it "returns false" do
upload = described_class.new(path: "#{__FILE__}-nope", store: ObjectStorage::Store::LOCAL)
expect(upload).not_to exist
end
- context 'when the record is persisted' do
- it 'sends a message to Sentry' do
+ context "when the record is persisted" do
+ it "sends a message to Sentry" do
upload = create(:upload, :issuable_upload)
expect(Gitlab::Sentry).to receive(:enabled?).and_return(true)
@@ -129,19 +129,19 @@ describe Upload do
upload.exist?
end
- it 'increments a metric counter to signal a problem' do
+ it "increments a metric counter to signal a problem" do
upload = create(:upload, :issuable_upload)
counter = double(:counter)
expect(counter).to receive(:increment)
- expect(Gitlab::Metrics).to receive(:counter).with(:upload_file_does_not_exist_total, 'The number of times an upload record could not find its file').and_return(counter)
+ expect(Gitlab::Metrics).to receive(:counter).with(:upload_file_does_not_exist_total, "The number of times an upload record could not find its file").and_return(counter)
upload.exist?
end
end
- context 'when the record is not persisted' do
- it 'does not send a message to Sentry' do
+ context "when the record is not persisted" do
+ it "does not send a message to Sentry" do
upload = described_class.new(path: "#{__FILE__}-nope", store: ObjectStorage::Store::LOCAL)
expect(Raven).not_to receive(:capture_message)
@@ -149,7 +149,7 @@ describe Upload do
upload.exist?
end
- it 'does not increment a metric counter' do
+ it "does not increment a metric counter" do
upload = described_class.new(path: "#{__FILE__}-nope", store: ObjectStorage::Store::LOCAL)
expect(Gitlab::Metrics).not_to receive(:counter)
@@ -161,8 +161,8 @@ describe Upload do
end
describe "#uploader_context" do
- subject { create(:upload, :issuable_upload, secret: 'secret', filename: 'file.txt') }
+ subject { create(:upload, :issuable_upload, secret: "secret", filename: "file.txt") }
- it { expect(subject.uploader_context).to match(a_hash_including(secret: 'secret', identifier: 'file.txt')) }
+ it { expect(subject.uploader_context).to match(a_hash_including(secret: "secret", identifier: "file.txt")) }
end
end
diff --git a/spec/models/uploads/fog_spec.rb b/spec/models/uploads/fog_spec.rb
index 4a44cf5ab0f..0449791e9c9 100644
--- a/spec/models/uploads/fog_spec.rb
+++ b/spec/models/uploads/fog_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe Uploads::Fog do
let(:data_store) { described_class.new }
@@ -9,14 +9,14 @@ describe Uploads::Fog do
stub_uploads_object_storage(FileUploader)
end
- describe '#available?' do
+ describe "#available?" do
subject { data_store.available? }
- context 'when object storage is enabled' do
+ context "when object storage is enabled" do
it { is_expected.to be_truthy }
end
- context 'when object storage is disabled' do
+ context "when object storage is disabled" do
before do
stub_uploads_object_storage(FileUploader, enabled: false)
end
@@ -25,20 +25,20 @@ describe Uploads::Fog do
end
end
- context 'model with uploads' do
+ context "model with uploads" do
let(:project) { create(:project) }
let(:relation) { project.uploads }
- describe '#keys' do
+ describe "#keys" do
let!(:uploads) { create_list(:upload, 2, :object_storage, uploader: FileUploader, model: project) }
subject { data_store.keys(relation) }
- it 'returns keys' do
+ it "returns keys" do
is_expected.to match_array(relation.pluck(:path))
end
end
- describe '#delete_keys' do
+ describe "#delete_keys" do
let(:keys) { data_store.keys(relation) }
let!(:uploads) { create_list(:upload, 2, :with_file, :issuable_upload, model: project) }
subject { data_store.delete_keys(keys) }
@@ -47,12 +47,12 @@ describe Uploads::Fog do
uploads.each { |upload| upload.build_uploader.migrate!(2) }
end
- it 'deletes multiple data' do
+ it "deletes multiple data" do
paths = relation.pluck(:path)
::Fog::Storage.new(FileUploader.object_store_credentials).tap do |connection|
paths.each do |path|
- expect(connection.get_object('uploads', path)[:body]).not_to be_nil
+ expect(connection.get_object("uploads", path)[:body]).not_to be_nil
end
end
@@ -60,7 +60,7 @@ describe Uploads::Fog do
::Fog::Storage.new(FileUploader.object_store_credentials).tap do |connection|
paths.each do |path|
- expect { connection.get_object('uploads', path)[:body] }.to raise_error(Excon::Error::NotFound)
+ expect { connection.get_object("uploads", path)[:body] }.to raise_error(Excon::Error::NotFound)
end
end
end
diff --git a/spec/models/uploads/local_spec.rb b/spec/models/uploads/local_spec.rb
index 3468399f370..7bdd1b1a436 100644
--- a/spec/models/uploads/local_spec.rb
+++ b/spec/models/uploads/local_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe Uploads::Local do
let(:data_store) { described_class.new }
@@ -9,25 +9,25 @@ describe Uploads::Local do
stub_uploads_object_storage(FileUploader)
end
- context 'model with uploads' do
+ context "model with uploads" do
let(:project) { create(:project) }
let(:relation) { project.uploads }
- describe '#keys' do
+ describe "#keys" do
let!(:uploads) { create_list(:upload, 2, uploader: FileUploader, model: project) }
subject { data_store.keys(relation) }
- it 'returns keys' do
+ it "returns keys" do
is_expected.to match_array(relation.map(&:absolute_path))
end
end
- describe '#delete_keys' do
+ describe "#delete_keys" do
let(:keys) { data_store.keys(relation) }
let!(:uploads) { create_list(:upload, 2, :with_file, :issuable_upload, model: project) }
subject { data_store.delete_keys(keys) }
- it 'deletes multiple data' do
+ it "deletes multiple data" do
paths = relation.map(&:absolute_path)
paths.each do |path|
diff --git a/spec/models/user_agent_detail_spec.rb b/spec/models/user_agent_detail_spec.rb
index b4669f8c1c2..1dc72f1fa30 100644
--- a/spec/models/user_agent_detail_spec.rb
+++ b/spec/models/user_agent_detail_spec.rb
@@ -1,28 +1,28 @@
-require 'rails_helper'
+require "rails_helper"
describe UserAgentDetail do
- describe '.submittable?' do
- it 'is submittable when not already submitted' do
+ describe ".submittable?" do
+ it "is submittable when not already submitted" do
detail = build(:user_agent_detail)
expect(detail.submittable?).to be_truthy
end
- it 'is not submittable when already submitted' do
+ it "is not submittable when already submitted" do
detail = build(:user_agent_detail, submitted: true)
expect(detail.submittable?).to be_falsey
end
end
- describe '.valid?' do
- it 'is valid with a subject' do
+ describe ".valid?" do
+ it "is valid with a subject" do
detail = build(:user_agent_detail)
expect(detail).to be_valid
end
- it 'is invalid without a subject' do
+ it "is invalid without a subject" do
detail = build(:user_agent_detail, subject: nil)
expect(detail).not_to be_valid
diff --git a/spec/models/user_callout_spec.rb b/spec/models/user_callout_spec.rb
index d54355afe12..55b3dfe0818 100644
--- a/spec/models/user_callout_spec.rb
+++ b/spec/models/user_callout_spec.rb
@@ -1,15 +1,15 @@
-require 'rails_helper'
+require "rails_helper"
describe UserCallout do
let!(:callout) { create(:user_callout) }
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe 'relationships' do
+ describe "relationships" do
it { is_expected.to belong_to(:user) }
end
- describe 'validations' do
+ describe "validations" do
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_presence_of(:feature_name) }
diff --git a/spec/models/user_custom_attribute_spec.rb b/spec/models/user_custom_attribute_spec.rb
index 37fc3cb64f0..ce6789184fa 100644
--- a/spec/models/user_custom_attribute_spec.rb
+++ b/spec/models/user_custom_attribute_spec.rb
@@ -1,11 +1,11 @@
-require 'spec_helper'
+require "spec_helper"
describe UserCustomAttribute do
- describe 'assocations' do
+ describe "assocations" do
it { is_expected.to belong_to(:user) }
end
- describe 'validations' do
+ describe "validations" do
subject { build :user_custom_attribute }
it { is_expected.to validate_presence_of(:user_id) }
diff --git a/spec/models/user_interacted_project_spec.rb b/spec/models/user_interacted_project_spec.rb
index cb4bb3372d4..ff03c80b7b6 100644
--- a/spec/models/user_interacted_project_spec.rb
+++ b/spec/models/user_interacted_project_spec.rb
@@ -1,51 +1,51 @@
-require 'spec_helper'
+require "spec_helper"
describe UserInteractedProject do
- describe '.track' do
+ describe ".track" do
subject { described_class.track(event) }
let(:event) { build(:event) }
Event::ACTIONS.each do |action|
context "for all actions (event types)" do
let(:event) { build(:event, action: action) }
- it 'creates a record' do
+ it "creates a record" do
expect { subject }.to change { described_class.count }.from(0).to(1)
end
end
end
- it 'sets project accordingly' do
+ it "sets project accordingly" do
subject
expect(described_class.first.project).to eq(event.project)
end
- it 'sets user accordingly' do
+ it "sets user accordingly" do
subject
expect(described_class.first.user).to eq(event.author)
end
- it 'only creates a record once per user/project' do
- expect do
+ it "only creates a record once per user/project" do
+ expect {
subject
described_class.track(event)
- end.to change { described_class.count }.from(0).to(1)
+ }.to change { described_class.count }.from(0).to(1)
end
- describe 'with an event without a project' do
+ describe "with an event without a project" do
let(:event) { build(:event, project: nil) }
- it 'ignores the event' do
+ it "ignores the event" do
expect { subject }.not_to change { described_class.count }
end
end
end
- describe '.available?' do
+ describe ".available?" do
before do
- described_class.instance_variable_set('@available_flag', nil)
+ described_class.instance_variable_set("@available_flag", nil)
end
- it 'checks schema version and properly caches positive result' do
+ it "checks schema version and properly caches positive result" do
expect(ActiveRecord::Migrator).to receive(:current_version).and_return(described_class::REQUIRED_SCHEMA_VERSION - 1 - rand(1000))
expect(described_class.available?).to be_falsey
expect(ActiveRecord::Migrator).to receive(:current_version).and_return(described_class::REQUIRED_SCHEMA_VERSION + rand(1000))
diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rb
index b2ef17a81d4..be30f233eae 100644
--- a/spec/models/user_preference_spec.rb
+++ b/spec/models/user_preference_spec.rb
@@ -1,50 +1,50 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe UserPreference do
let(:user_preference) { create(:user_preference) }
- describe '#set_notes_filter' do
+ describe "#set_notes_filter" do
let(:issuable) { build_stubbed(:issue) }
- shared_examples 'setting system notes' do
- it 'returns updated discussion filter' do
+ shared_examples "setting system notes" do
+ it "returns updated discussion filter" do
filter_name =
user_preference.set_notes_filter(filter, issuable)
expect(filter_name).to eq(filter)
end
- it 'updates discussion filter for issuable class' do
+ it "updates discussion filter for issuable class" do
user_preference.set_notes_filter(filter, issuable)
expect(user_preference.reload.issue_notes_filter).to eq(filter)
end
end
- context 'when filter is set to all notes' do
+ context "when filter is set to all notes" do
let(:filter) { described_class::NOTES_FILTERS[:all_notes] }
- it_behaves_like 'setting system notes'
+ it_behaves_like "setting system notes"
end
- context 'when filter is set to only comments' do
+ context "when filter is set to only comments" do
let(:filter) { described_class::NOTES_FILTERS[:only_comments] }
- it_behaves_like 'setting system notes'
+ it_behaves_like "setting system notes"
end
- context 'when filter is set to only activity' do
+ context "when filter is set to only activity" do
let(:filter) { described_class::NOTES_FILTERS[:only_activity] }
- it_behaves_like 'setting system notes'
+ it_behaves_like "setting system notes"
end
- context 'when notes_filter parameter is invalid' do
+ context "when notes_filter parameter is invalid" do
let(:only_comments) { described_class::NOTES_FILTERS[:only_comments] }
- it 'returns the current notes filter' do
+ it "returns the current notes filter" do
user_preference.set_notes_filter(only_comments, issuable)
expect(user_preference.set_notes_filter(9999, issuable)).to eq(only_comments)
@@ -52,25 +52,25 @@ describe UserPreference do
end
end
- describe 'sort_by preferences' do
- shared_examples_for 'a sort_by preference' do
- it 'allows nil sort fields' do
+ describe "sort_by preferences" do
+ shared_examples_for "a sort_by preference" do
+ it "allows nil sort fields" do
user_preference.update(attribute => nil)
expect(user_preference).to be_valid
end
end
- context 'merge_requests_sort attribute' do
+ context "merge_requests_sort attribute" do
let(:attribute) { :merge_requests_sort }
- it_behaves_like 'a sort_by preference'
+ it_behaves_like "a sort_by preference"
end
- context 'issues_sort attribute' do
+ context "issues_sort attribute" do
let(:attribute) { :issues_sort }
- it_behaves_like 'a sort_by preference'
+ it_behaves_like "a sort_by preference"
end
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 85b157a9435..eeec662d959 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1,12 +1,12 @@
-require 'spec_helper'
+require "spec_helper"
describe User do
include ProjectForksHelper
include TermsHelper
- it_behaves_like 'having unique enum values'
+ it_behaves_like "having unique enum values"
- describe 'modules' do
+ describe "modules" do
subject { described_class }
it { is_expected.to include_module(Gitlab::ConfigHelper) }
@@ -16,11 +16,11 @@ describe User do
it { is_expected.to include_module(BlocksJsonSerialization) }
end
- describe 'delegations' do
+ describe "delegations" do
it { is_expected.to delegate_method(:path).to(:namespace).with_prefix }
end
- describe 'associations' do
+ describe "associations" do
it { is_expected.to have_one(:namespace) }
it { is_expected.to have_one(:status) }
it { is_expected.to have_many(:snippets).dependent(:destroy) }
@@ -43,8 +43,8 @@ describe User do
it { is_expected.to have_many(:pipelines).dependent(:nullify) }
it { is_expected.to have_many(:chat_names).dependent(:destroy) }
it { is_expected.to have_many(:uploads) }
- it { is_expected.to have_many(:reported_abuse_reports).dependent(:destroy).class_name('AbuseReport') }
- it { is_expected.to have_many(:custom_attributes).class_name('UserCustomAttribute') }
+ it { is_expected.to have_many(:reported_abuse_reports).dependent(:destroy).class_name("AbuseReport") }
+ it { is_expected.to have_many(:custom_attributes).class_name("UserCustomAttribute") }
it { is_expected.to have_many(:releases).dependent(:nullify) }
describe "#abuse_report" do
@@ -74,8 +74,8 @@ describe User do
end
end
- describe '#group_members' do
- it 'does not include group memberships for which user is a requester' do
+ describe "#group_members" do
+ it "does not include group memberships for which user is a requester" do
user = create(:user)
group = create(:group, :public, :access_requestable)
group.request_access(user)
@@ -84,8 +84,8 @@ describe User do
end
end
- describe '#project_members' do
- it 'does not include project memberships for which user is a requester' do
+ describe "#project_members" do
+ it "does not include project memberships for which user is a requester" do
user = create(:user)
project = create(:project, :public, :access_requestable)
project.request_access(user)
@@ -95,63 +95,63 @@ describe User do
end
end
- describe 'validations' do
- describe 'username' do
- it 'validates presence' do
+ describe "validations" do
+ describe "username" do
+ it "validates presence" do
expect(subject).to validate_presence_of(:username)
end
- it 'rejects blacklisted names' do
- user = build(:user, username: 'dashboard')
+ it "rejects blacklisted names" do
+ user = build(:user, username: "dashboard")
expect(user).not_to be_valid
- expect(user.errors.messages[:username]).to eq ['dashboard is a reserved name']
+ expect(user.errors.messages[:username]).to eq ["dashboard is a reserved name"]
end
- it 'allows child names' do
- user = build(:user, username: 'avatar')
+ it "allows child names" do
+ user = build(:user, username: "avatar")
expect(user).to be_valid
end
- it 'allows wildcard names' do
- user = build(:user, username: 'blob')
+ it "allows wildcard names" do
+ user = build(:user, username: "blob")
expect(user).to be_valid
end
- context 'when username is changed' do
- let(:user) { build_stubbed(:user, username: 'old_path', namespace: build_stubbed(:namespace)) }
+ context "when username is changed" do
+ let(:user) { build_stubbed(:user, username: "old_path", namespace: build_stubbed(:namespace)) }
- it 'validates move_dir is allowed for the namespace' do
+ it "validates move_dir is allowed for the namespace" do
expect(user.namespace).to receive(:any_project_has_container_registry_tags?).and_return(true)
- user.username = 'new_path'
+ user.username = "new_path"
expect(user).to be_invalid
- expect(user.errors.messages[:username].first).to match('cannot be changed if a personal project has container registry tags')
+ expect(user.errors.messages[:username].first).to match("cannot be changed if a personal project has container registry tags")
end
end
- context 'when the username is in use by another user' do
- let(:username) { 'foo' }
+ context "when the username is in use by another user" do
+ let(:username) { "foo" }
let!(:other_user) { create(:user, username: username) }
- it 'is invalid' do
+ it "is invalid" do
user = build(:user, username: username)
expect(user).not_to be_valid
- expect(user.errors.full_messages).to eq(['Username has already been taken'])
+ expect(user.errors.full_messages).to eq(["Username has already been taken"])
end
end
end
- it 'has a DB-level NOT NULL constraint on projects_limit' do
+ it "has a DB-level NOT NULL constraint on projects_limit" do
user = create(:user)
expect(user.persisted?).to eq(true)
- expect do
+ expect {
user.update_columns(projects_limit: nil)
- end.to raise_error(ActiveRecord::StatementInvalid)
+ }.to raise_error(ActiveRecord::StatementInvalid)
end
it { is_expected.to validate_presence_of(:projects_limit) }
@@ -162,23 +162,23 @@ describe User do
it { is_expected.to validate_length_of(:bio).is_at_most(255) }
- it_behaves_like 'an object with email-formated attributes', :email do
+ it_behaves_like "an object with email-formated attributes", :email do
subject { build(:user) }
end
- it_behaves_like 'an object with email-formated attributes', :public_email, :notification_email do
+ it_behaves_like "an object with email-formated attributes", :public_email, :notification_email do
subject { build(:user).tap { |user| user.emails << build(:email, email: email_value) } }
end
- describe '#commit_email' do
+ describe "#commit_email" do
subject(:user) { create(:user) }
- it 'defaults to the primary email' do
+ it "defaults to the primary email" do
expect(user.email).to be_present
expect(user.commit_email).to eq(user.email)
end
- it 'defaults to the primary email when the column in the database is null' do
+ it "defaults to the primary email when the column in the database is null" do
user.update_column(:commit_email, nil)
found_user = described_class.find_by(id: user.id)
@@ -186,13 +186,13 @@ describe User do
expect(found_user.commit_email).to eq(user.email)
end
- it 'returns the private commit email when commit_email has _private' do
+ it "returns the private commit email when commit_email has _private" do
user.update_column(:commit_email, Gitlab::PrivateCommitEmail::TOKEN)
expect(user.commit_email).to eq(user.private_commit_email)
end
- it 'can be set to a confirmed email' do
+ it "can be set to a confirmed email" do
confirmed = create(:email, :confirmed, user: user)
user.commit_email = confirmed.email
@@ -200,7 +200,7 @@ describe User do
expect(user.commit_email).to eq(confirmed.email)
end
- it 'can not be set to an unconfirmed email' do
+ it "can not be set to an unconfirmed email" do
unconfirmed = create(:email, user: user)
user.commit_email = unconfirmed.email
@@ -209,168 +209,168 @@ describe User do
expect(user.commit_email).to eq(user.email)
end
- it 'can not be set to a non-existent email' do
- user.commit_email = 'non-existent-email@nonexistent.nonexistent'
+ it "can not be set to a non-existent email" do
+ user.commit_email = "non-existent-email@nonexistent.nonexistent"
# This should set the commit_email attribute to the primary email
expect(user).to be_valid
expect(user.commit_email).to eq(user.email)
end
- it 'can not be set to an invalid email, even if confirmed' do
- confirmed = create(:email, :confirmed, :skip_validate, user: user, email: 'invalid')
+ it "can not be set to an invalid email, even if confirmed" do
+ confirmed = create(:email, :confirmed, :skip_validate, user: user, email: "invalid")
user.commit_email = confirmed.email
expect(user).not_to be_valid
end
end
- describe 'email' do
- context 'when no signup domains whitelisted' do
+ describe "email" do
+ context "when no signup domains whitelisted" do
before do
allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return([])
end
- it 'accepts any email' do
+ it "accepts any email" do
user = build(:user, email: "info@example.com")
expect(user).to be_valid
end
end
- context 'when a signup domain is whitelisted and subdomains are allowed' do
+ context "when a signup domain is whitelisted and subdomains are allowed" do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['example.com', '*.example.com'])
+ allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(["example.com", "*.example.com"])
end
- it 'accepts info@example.com' do
+ it "accepts info@example.com" do
user = build(:user, email: "info@example.com")
expect(user).to be_valid
end
- it 'accepts info@test.example.com' do
+ it "accepts info@test.example.com" do
user = build(:user, email: "info@test.example.com")
expect(user).to be_valid
end
- it 'rejects example@test.com' do
+ it "rejects example@test.com" do
user = build(:user, email: "example@test.com")
expect(user).to be_invalid
end
end
- context 'when a signup domain is whitelisted and subdomains are not allowed' do
+ context "when a signup domain is whitelisted and subdomains are not allowed" do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['example.com'])
+ allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(["example.com"])
end
- it 'accepts info@example.com' do
+ it "accepts info@example.com" do
user = build(:user, email: "info@example.com")
expect(user).to be_valid
end
- it 'rejects info@test.example.com' do
+ it "rejects info@test.example.com" do
user = build(:user, email: "info@test.example.com")
expect(user).to be_invalid
end
- it 'rejects example@test.com' do
+ it "rejects example@test.com" do
user = build(:user, email: "example@test.com")
expect(user).to be_invalid
end
- it 'accepts example@test.com when added by another user' do
+ it "accepts example@test.com when added by another user" do
user = build(:user, email: "example@test.com", created_by_id: 1)
expect(user).to be_valid
end
end
- context 'domain blacklist' do
+ context "domain blacklist" do
before do
allow_any_instance_of(ApplicationSetting).to receive(:domain_blacklist_enabled?).and_return(true)
- allow_any_instance_of(ApplicationSetting).to receive(:domain_blacklist).and_return(['example.com'])
+ allow_any_instance_of(ApplicationSetting).to receive(:domain_blacklist).and_return(["example.com"])
end
- context 'when a signup domain is blacklisted' do
- it 'accepts info@test.com' do
- user = build(:user, email: 'info@test.com')
+ context "when a signup domain is blacklisted" do
+ it "accepts info@test.com" do
+ user = build(:user, email: "info@test.com")
expect(user).to be_valid
end
- it 'rejects info@example.com' do
- user = build(:user, email: 'info@example.com')
+ it "rejects info@example.com" do
+ user = build(:user, email: "info@example.com")
expect(user).not_to be_valid
end
- it 'accepts info@example.com when added by another user' do
- user = build(:user, email: 'info@example.com', created_by_id: 1)
+ it "accepts info@example.com when added by another user" do
+ user = build(:user, email: "info@example.com", created_by_id: 1)
expect(user).to be_valid
end
end
- context 'when a signup domain is blacklisted but a wildcard subdomain is allowed' do
+ context "when a signup domain is blacklisted but a wildcard subdomain is allowed" do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:domain_blacklist).and_return(['test.example.com'])
- allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['*.example.com'])
+ allow_any_instance_of(ApplicationSetting).to receive(:domain_blacklist).and_return(["test.example.com"])
+ allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(["*.example.com"])
end
- it 'gives priority to whitelist and allow info@test.example.com' do
- user = build(:user, email: 'info@test.example.com')
+ it "gives priority to whitelist and allow info@test.example.com" do
+ user = build(:user, email: "info@test.example.com")
expect(user).to be_valid
end
end
- context 'with both lists containing a domain' do
+ context "with both lists containing a domain" do
before do
- allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(['test.com'])
+ allow_any_instance_of(ApplicationSetting).to receive(:domain_whitelist).and_return(["test.com"])
end
- it 'accepts info@test.com' do
- user = build(:user, email: 'info@test.com')
+ it "accepts info@test.com" do
+ user = build(:user, email: "info@test.com")
expect(user).to be_valid
end
- it 'rejects info@example.com' do
- user = build(:user, email: 'info@example.com')
+ it "rejects info@example.com" do
+ user = build(:user, email: "info@example.com")
expect(user).not_to be_valid
end
end
end
- context 'owns_notification_email' do
- it 'accepts temp_oauth_email emails' do
+ context "owns_notification_email" do
+ it "accepts temp_oauth_email emails" do
user = build(:user, email: "temp-email-for-oauth@example.com")
expect(user).to be_valid
end
end
- context 'set_commit_email' do
- it 'keeps commit email when private commit email is being used' do
+ context "set_commit_email" do
+ it "keeps commit email when private commit email is being used" do
user = create(:user, commit_email: Gitlab::PrivateCommitEmail::TOKEN)
expect(user.read_attribute(:commit_email)).to eq(Gitlab::PrivateCommitEmail::TOKEN)
end
- it 'keeps the commit email when nil' do
+ it "keeps the commit email when nil" do
user = create(:user, commit_email: nil)
expect(user.read_attribute(:commit_email)).to be_nil
end
- it 'reverts to nil when email is not verified' do
+ it "reverts to nil when email is not verified" do
user = create(:user, commit_email: "foo@bar.com")
expect(user.read_attribute(:commit_email)).to be_nil
end
end
- context 'owns_commit_email' do
- it 'accepts private commit email' do
+ context "owns_commit_email" do
+ it "accepts private commit email" do
user = build(:user, commit_email: Gitlab::PrivateCommitEmail::TOKEN)
expect(user).to be_valid
end
- it 'accepts nil commit email' do
+ it "accepts nil commit email" do
user = build(:user, commit_email: nil)
expect(user).to be_valid
@@ -408,7 +408,7 @@ describe User do
expect(users_with_two_factor).not_to include(user_without_2fa.id)
end
- it 'works with ORDER BY' do
+ it "works with ORDER BY" do
user_with_2fa = create(:user, :two_factor_via_otp, :two_factor_via_u2f)
expect(described_class
@@ -446,8 +446,8 @@ describe User do
end
end
- describe '.limit_to_todo_authors' do
- context 'when filtering by todo authors' do
+ describe ".limit_to_todo_authors" do
+ context "when filtering by todo authors" do
let(:user1) { create(:user) }
let(:user2) { create(:user) }
@@ -456,7 +456,7 @@ describe User do
create(:todo, user: user2, author: user2, state: :pending)
end
- it 'only returns users that have authored todos' do
+ it "only returns users that have authored todos" do
users = described_class.limit_to_todo_authors(
user: user2,
with_todos: true,
@@ -466,7 +466,7 @@ describe User do
expect(users).to eq([user2])
end
- it 'ignores users that do not have a todo in the matching state' do
+ it "ignores users that do not have a todo in the matching state" do
users = described_class.limit_to_todo_authors(
user: user1,
with_todos: true,
@@ -477,8 +477,8 @@ describe User do
end
end
- context 'when not filtering by todo authors' do
- it 'returns the input relation' do
+ context "when not filtering by todo authors" do
+ it "returns the input relation" do
user1 = create(:user)
user2 = create(:user)
rel = described_class.limit_to_todo_authors(user: user1)
@@ -487,8 +487,8 @@ describe User do
end
end
- context 'when no user is provided' do
- it 'returns the input relation' do
+ context "when no user is provided" do
+ it "returns the input relation" do
user1 = create(:user)
user2 = create(:user)
rel = described_class.limit_to_todo_authors
@@ -498,19 +498,19 @@ describe User do
end
end
- describe '.by_username' do
- it 'finds users regardless of the case passed' do
- user = create(:user, username: 'CaMeLcAsEd')
- user2 = create(:user, username: 'UPPERCASE')
+ describe ".by_username" do
+ it "finds users regardless of the case passed" do
+ user = create(:user, username: "CaMeLcAsEd")
+ user2 = create(:user, username: "UPPERCASE")
- expect(described_class.by_username(%w(CAMELCASED uppercase)))
+ expect(described_class.by_username(%w[CAMELCASED uppercase]))
.to contain_exactly(user, user2)
end
- it 'finds a single user regardless of the case passed' do
- user = create(:user, username: 'CaMeLcAsEd')
+ it "finds a single user regardless of the case passed" do
+ user = create(:user, username: "CaMeLcAsEd")
- expect(described_class.by_username('CAMELCASED'))
+ expect(described_class.by_username("CAMELCASED"))
.to contain_exactly(user)
end
end
@@ -522,8 +522,8 @@ describe User do
it { is_expected.to respond_to(:external?) }
end
- describe 'before save hook' do
- context 'when saving an external user' do
+ describe "before save hook" do
+ context "when saving an external user" do
let(:user) { create(:user) }
let(:external_user) { create(:user, external: true) }
@@ -534,11 +534,11 @@ describe User do
end
end
- describe '#check_for_verified_email' do
+ describe "#check_for_verified_email" do
let(:user) { create(:user) }
- let(:secondary) { create(:email, :confirmed, email: 'secondary@example.com', user: user) }
+ let(:secondary) { create(:email, :confirmed, email: "secondary@example.com", user: user) }
- it 'allows a verfied secondary email to be used as the primary without needing reconfirmation' do
+ it "allows a verfied secondary email to be used as the primary without needing reconfirmation" do
user.update!(email: secondary.email)
user.reload
expect(user.email).to eq secondary.email
@@ -548,39 +548,39 @@ describe User do
end
end
- describe 'after commit hook' do
- describe '#update_emails_with_primary_email' do
+ describe "after commit hook" do
+ describe "#update_emails_with_primary_email" do
before do
- @user = create(:user, email: 'primary@example.com').tap do |user|
+ @user = create(:user, email: "primary@example.com").tap do |user|
user.skip_reconfirmation!
end
- @secondary = create :email, email: 'secondary@example.com', user: @user
+ @secondary = create :email, email: "secondary@example.com", user: @user
@user.reload
end
- it 'gets called when email updated' do
+ it "gets called when email updated" do
expect(@user).to receive(:update_emails_with_primary_email)
- @user.update!(email: 'new_primary@example.com')
+ @user.update!(email: "new_primary@example.com")
end
- it 'adds old primary to secondary emails when secondary is a new email ' do
- @user.update!(email: 'new_primary@example.com')
+ it "adds old primary to secondary emails when secondary is a new email " do
+ @user.update!(email: "new_primary@example.com")
@user.reload
expect(@user.emails.count).to eq 2
- expect(@user.emails.pluck(:email)).to match_array([@secondary.email, 'primary@example.com'])
+ expect(@user.emails.pluck(:email)).to match_array([@secondary.email, "primary@example.com"])
end
- it 'adds old primary to secondary emails if secondary is becoming a primary' do
+ it "adds old primary to secondary emails if secondary is becoming a primary" do
@user.update!(email: @secondary.email)
@user.reload
expect(@user.emails.count).to eq 1
- expect(@user.emails.first.email).to eq 'primary@example.com'
+ expect(@user.emails.first.email).to eq "primary@example.com"
end
- it 'transfers old confirmation values into new secondary' do
+ it "transfers old confirmation values into new secondary" do
@user.update!(email: @secondary.email)
@user.reload
@@ -589,177 +589,177 @@ describe User do
end
end
- describe '#update_notification_email' do
+ describe "#update_notification_email" do
# Regression: https://gitlab.com/gitlab-org/gitlab-ce/issues/22846
- context 'when changing :email' do
+ context "when changing :email" do
let(:user) { create(:user) }
- let(:new_email) { 'new-email@example.com' }
+ let(:new_email) { "new-email@example.com" }
- it 'sets :unconfirmed_email' do
- expect do
+ it "sets :unconfirmed_email" do
+ expect {
user.tap { |u| u.update!(email: new_email) }.reload
- end.to change(user, :unconfirmed_email).to(new_email)
+ }.to change(user, :unconfirmed_email).to(new_email)
end
- it 'does not change :notification_email' do
- expect do
+ it "does not change :notification_email" do
+ expect {
user.tap { |u| u.update!(email: new_email) }.reload
- end.not_to change(user, :notification_email)
+ }.not_to change(user, :notification_email)
end
- it 'updates :notification_email to the new email once confirmed' do
+ it "updates :notification_email to the new email once confirmed" do
user.update!(email: new_email)
- expect do
+ expect {
user.tap(&:confirm).reload
- end.to change(user, :notification_email).to eq(new_email)
+ }.to change(user, :notification_email).to eq(new_email)
end
- context 'and :notification_email is set to a secondary email' do
+ context "and :notification_email is set to a secondary email" do
let!(:email_attrs) { attributes_for(:email, :confirmed, user: user) }
- let(:secondary) { create(:email, :confirmed, email: 'secondary@example.com', user: user) }
+ let(:secondary) { create(:email, :confirmed, email: "secondary@example.com", user: user) }
before do
user.emails.create(email_attrs)
user.tap { |u| u.update!(notification_email: email_attrs[:email]) }.reload
end
- it 'does not change :notification_email to :email' do
- expect do
+ it "does not change :notification_email to :email" do
+ expect {
user.tap { |u| u.update!(email: new_email) }.reload
- end.not_to change(user, :notification_email)
+ }.not_to change(user, :notification_email)
end
- it 'does not change :notification_email to :email once confirmed' do
+ it "does not change :notification_email to :email once confirmed" do
user.update!(email: new_email)
- expect do
+ expect {
user.tap(&:confirm).reload
- end.not_to change(user, :notification_email)
+ }.not_to change(user, :notification_email)
end
end
end
end
- describe '#update_invalid_gpg_signatures' do
+ describe "#update_invalid_gpg_signatures" do
let(:user) do
- create(:user, email: 'tula.torphy@abshire.ca').tap do |user|
+ create(:user, email: "tula.torphy@abshire.ca").tap do |user|
user.skip_reconfirmation!
end
end
- it 'does nothing when the name is updated' do
+ it "does nothing when the name is updated" do
expect(user).not_to receive(:update_invalid_gpg_signatures)
- user.update!(name: 'Bette')
+ user.update!(name: "Bette")
end
- it 'synchronizes the gpg keys when the email is updated' do
+ it "synchronizes the gpg keys when the email is updated" do
expect(user).to receive(:update_invalid_gpg_signatures).at_most(:twice)
- user.update!(email: 'shawnee.ritchie@denesik.com')
+ user.update!(email: "shawnee.ritchie@denesik.com")
end
end
end
- describe '#update_tracked_fields!', :clean_gitlab_redis_shared_state do
+ describe "#update_tracked_fields!", :clean_gitlab_redis_shared_state do
let(:request) { OpenStruct.new(remote_ip: "127.0.0.1") }
let(:user) { create(:user) }
- it 'writes trackable attributes' do
- expect do
+ it "writes trackable attributes" do
+ expect {
user.update_tracked_fields!(request)
- end.to change { user.reload.current_sign_in_at }
+ }.to change { user.reload.current_sign_in_at }
end
- it 'does not write trackable attributes when called a second time within the hour' do
+ it "does not write trackable attributes when called a second time within the hour" do
user.update_tracked_fields!(request)
- expect do
+ expect {
user.update_tracked_fields!(request)
- end.not_to change { user.reload.current_sign_in_at }
+ }.not_to change { user.reload.current_sign_in_at }
end
- it 'writes trackable attributes for a different user' do
+ it "writes trackable attributes for a different user" do
user2 = create(:user)
user.update_tracked_fields!(request)
- expect do
+ expect {
user2.update_tracked_fields!(request)
- end.to change { user2.reload.current_sign_in_at }
+ }.to change { user2.reload.current_sign_in_at }
end
- it 'does not write if the DB is in read-only mode' do
+ it "does not write if the DB is in read-only mode" do
expect(Gitlab::Database).to receive(:read_only?).and_return(true)
- expect do
+ expect {
user.update_tracked_fields!(request)
- end.not_to change { user.reload.current_sign_in_at }
+ }.not_to change { user.reload.current_sign_in_at }
end
end
- shared_context 'user keys' do
+ shared_context "user keys" do
let(:user) { create(:user) }
let!(:key) { create(:key, user: user) }
let!(:deploy_key) { create(:deploy_key, user: user) }
end
- describe '#keys' do
- include_context 'user keys'
+ describe "#keys" do
+ include_context "user keys"
- context 'with key and deploy key stored' do
- it 'returns stored key, but not deploy_key' do
+ context "with key and deploy key stored" do
+ it "returns stored key, but not deploy_key" do
expect(user.keys).to include key
expect(user.keys).not_to include deploy_key
end
end
end
- describe '#deploy_keys' do
- include_context 'user keys'
+ describe "#deploy_keys" do
+ include_context "user keys"
- context 'with key and deploy key stored' do
- it 'returns stored deploy key, but not normal key' do
+ context "with key and deploy key stored" do
+ it "returns stored deploy key, but not normal key" do
expect(user.deploy_keys).to include deploy_key
expect(user.deploy_keys).not_to include key
end
end
end
- describe '#confirm' do
+ describe "#confirm" do
before do
allow_any_instance_of(ApplicationSetting).to receive(:send_user_confirmation_email).and_return(true)
end
- let(:user) { create(:user, confirmed_at: nil, unconfirmed_email: 'test@gitlab.com') }
+ let(:user) { create(:user, confirmed_at: nil, unconfirmed_email: "test@gitlab.com") }
- it 'returns unconfirmed' do
+ it "returns unconfirmed" do
expect(user.confirmed?).to be_falsey
end
- it 'confirms a user' do
+ it "confirms a user" do
user.confirm
expect(user.confirmed?).to be_truthy
end
end
- describe '#to_reference' do
+ describe "#to_reference" do
let(:user) { create(:user) }
- it 'returns a String reference to the object' do
+ it "returns a String reference to the object" do
expect(user.to_reference).to eq "@#{user.username}"
end
end
- describe '#generate_password' do
+ describe "#generate_password" do
it "does not generate password by default" do
- user = create(:user, password: 'abcdefghe')
+ user = create(:user, password: "abcdefghe")
- expect(user.password).to eq('abcdefghe')
+ expect(user.password).to eq("abcdefghe")
end
end
- describe 'ensure user preference' do
- it 'has user preference upon user initialization' do
+ describe "ensure user preference" do
+ it "has user preference upon user initialization" do
user = build(:user)
expect(user.user_preference).to be_present
@@ -767,33 +767,33 @@ describe User do
end
end
- describe 'ensure incoming email token' do
- it 'has incoming email token' do
+ describe "ensure incoming email token" do
+ it "has incoming email token" do
user = create(:user)
expect(user.incoming_email_token).not_to be_blank
end
- it 'uses SecureRandom to generate the incoming email token' do
- expect(SecureRandom).to receive(:hex).and_return('3b8ca303')
+ it "uses SecureRandom to generate the incoming email token" do
+ expect(SecureRandom).to receive(:hex).and_return("3b8ca303")
user = create(:user)
- expect(user.incoming_email_token).to eql('gitlab')
+ expect(user.incoming_email_token).to eql("gitlab")
end
end
- describe '#ensure_user_rights_and_limits' do
- describe 'with external user' do
+ describe "#ensure_user_rights_and_limits" do
+ describe "with external user" do
let(:user) { create(:user, external: true) }
- it 'receives callback when external changes' do
+ it "receives callback when external changes" do
expect(user).to receive(:ensure_user_rights_and_limits)
user.update(external: false)
end
- it 'ensures correct rights and limits for user' do
+ it "ensures correct rights and limits for user" do
stub_config_setting(default_can_create_group: true)
expect { user.update(external: false) }.to change { user.can_create_group }.to(true)
@@ -801,24 +801,24 @@ describe User do
end
end
- describe 'without external user' do
+ describe "without external user" do
let(:user) { create(:user, external: false) }
- it 'receives callback when external changes' do
+ it "receives callback when external changes" do
expect(user).to receive(:ensure_user_rights_and_limits)
user.update(external: true)
end
- it 'ensures correct rights and limits for user' do
+ it "ensures correct rights and limits for user" do
expect { user.update(external: true) }.to change { user.can_create_group }.to(false)
.and change { user.projects_limit }.to(0)
end
end
end
- describe 'feed token' do
- it 'ensures a feed token on read' do
+ describe "feed token" do
+ it "ensures a feed token on read" do
user = create(:user, feed_token: nil)
feed_token = user.feed_token
@@ -827,28 +827,28 @@ describe User do
end
end
- describe '#recently_sent_password_reset?' do
- it 'is false when reset_password_sent_at is nil' do
+ describe "#recently_sent_password_reset?" do
+ it "is false when reset_password_sent_at is nil" do
user = build_stubbed(:user, reset_password_sent_at: nil)
expect(user.recently_sent_password_reset?).to eq false
end
- it 'is false when sent more than one minute ago' do
+ it "is false when sent more than one minute ago" do
user = build_stubbed(:user, reset_password_sent_at: 5.minutes.ago)
expect(user.recently_sent_password_reset?).to eq false
end
- it 'is true when sent less than one minute ago' do
+ it "is true when sent less than one minute ago" do
user = build_stubbed(:user, reset_password_sent_at: Time.now)
expect(user.recently_sent_password_reset?).to eq true
end
end
- describe '#disable_two_factor!' do
- it 'clears all 2FA-related fields' do
+ describe "#disable_two_factor!" do
+ it "clears all 2FA-related fields" do
user = create(:user, :two_factor)
expect(user).to be_two_factor_enabled
@@ -867,17 +867,17 @@ describe User do
end
end
- describe 'projects' do
+ describe "projects" do
before do
@user = create(:user)
@project = create(:project, namespace: @user.namespace)
- @project_2 = create(:project, group: create(:group)) do |project|
+ @project_2 = create(:project, group: create(:group)) { |project|
project.add_maintainer(@user)
- end
- @project_3 = create(:project, group: create(:group)) do |project|
+ }
+ @project_3 = create(:project, group: create(:group)) { |project|
project.add_developer(@user)
- end
+ }
end
it { expect(@user.authorized_projects).to include(@project) }
@@ -891,7 +891,7 @@ describe User do
it { expect(@user.personal_projects).not_to include(@project_3) }
end
- describe 'groups' do
+ describe "groups" do
let(:user) { create(:user) }
let(:group) { create(:group) }
@@ -905,45 +905,45 @@ describe User do
it { expect(user.namespaces).to contain_exactly(user.namespace, group) }
it { expect(user.manageable_namespaces).to contain_exactly(user.namespace, group) }
- context 'with child groups', :nested_groups do
+ context "with child groups", :nested_groups do
let!(:subgroup) { create(:group, parent: group) }
- describe '#manageable_namespaces' do
- it 'includes all the namespaces the user can manage' do
+ describe "#manageable_namespaces" do
+ it "includes all the namespaces the user can manage" do
expect(user.manageable_namespaces).to contain_exactly(user.namespace, group, subgroup)
end
end
- describe '#manageable_groups' do
- it 'includes all the namespaces the user can manage' do
+ describe "#manageable_groups" do
+ it "includes all the namespaces the user can manage" do
expect(user.manageable_groups).to contain_exactly(group, subgroup)
end
- it 'does not include duplicates if a membership was added for the subgroup' do
+ it "does not include duplicates if a membership was added for the subgroup" do
subgroup.add_owner(user)
expect(user.manageable_groups).to contain_exactly(group, subgroup)
end
end
- describe '#manageable_groups_with_routes' do
- it 'eager loads routes from manageable groups' do
+ describe "#manageable_groups_with_routes" do
+ it "eager loads routes from manageable groups" do
control_count =
- ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ ActiveRecord::QueryRecorder.new(skip_cached: false) {
user.manageable_groups_with_routes.map(&:route)
- end.count
+ }.count
create(:group, parent: subgroup)
- expect do
+ expect {
user.manageable_groups_with_routes.map(&:route)
- end.not_to exceed_all_query_limit(control_count)
+ }.not_to exceed_all_query_limit(control_count)
end
end
end
end
- describe 'group multiple owners' do
+ describe "group multiple owners" do
before do
@user = create :user
@user2 = create :user
@@ -956,7 +956,7 @@ describe User do
it { expect(@user2.several_namespaces?).to be_truthy }
end
- describe 'namespaced' do
+ describe "namespaced" do
before do
@user = create :user
@project = create(:project, namespace: @user.namespace)
@@ -966,8 +966,8 @@ describe User do
it { expect(@user.namespaces).to eq([@user.namespace]) }
end
- describe 'blocking user' do
- let(:user) { create(:user, name: 'John Smith') }
+ describe "blocking user" do
+ let(:user) { create(:user, name: "John Smith") }
it "blocks user" do
user.block
@@ -976,47 +976,47 @@ describe User do
end
end
- describe '.filter_items' do
+ describe ".filter_items" do
let(:user) { double }
- it 'filters by active users by default' do
+ it "filters by active users by default" do
expect(described_class).to receive(:active).and_return([user])
expect(described_class.filter_items(nil)).to include user
end
- it 'filters by admins' do
+ it "filters by admins" do
expect(described_class).to receive(:admins).and_return([user])
- expect(described_class.filter_items('admins')).to include user
+ expect(described_class.filter_items("admins")).to include user
end
- it 'filters by blocked' do
+ it "filters by blocked" do
expect(described_class).to receive(:blocked).and_return([user])
- expect(described_class.filter_items('blocked')).to include user
+ expect(described_class.filter_items("blocked")).to include user
end
- it 'filters by two_factor_disabled' do
+ it "filters by two_factor_disabled" do
expect(described_class).to receive(:without_two_factor).and_return([user])
- expect(described_class.filter_items('two_factor_disabled')).to include user
+ expect(described_class.filter_items("two_factor_disabled")).to include user
end
- it 'filters by two_factor_enabled' do
+ it "filters by two_factor_enabled" do
expect(described_class).to receive(:with_two_factor).and_return([user])
- expect(described_class.filter_items('two_factor_enabled')).to include user
+ expect(described_class.filter_items("two_factor_enabled")).to include user
end
- it 'filters by wop' do
+ it "filters by wop" do
expect(described_class).to receive(:without_projects).and_return([user])
- expect(described_class.filter_items('wop')).to include user
+ expect(described_class.filter_items("wop")).to include user
end
end
- describe '.without_projects' do
+ describe ".without_projects" do
let!(:project) { create(:project, :public, :access_requestable) }
let!(:user) { create(:user) }
let!(:user_without_project) { create(:user) }
@@ -1027,7 +1027,7 @@ describe User do
project.add_maintainer(user)
# create invite to projet
- create(:project_member, :developer, project: project, invite_token: '1234', invite_email: 'inviteduser1@example.com')
+ create(:project_member, :developer, project: project, invite_token: "1234", invite_email: "inviteduser1@example.com")
# create request to join project
project.request_access(user_without_project2)
@@ -1038,19 +1038,19 @@ describe User do
it { expect(described_class.without_projects).to include user_without_project2 }
end
- describe 'user creation' do
- describe 'normal user' do
- let(:user) { create(:user, name: 'John Smith') }
+ describe "user creation" do
+ describe "normal user" do
+ let(:user) { create(:user, name: "John Smith") }
it { expect(user.admin?).to be_falsey }
it { expect(user.require_ssh_key?).to be_truthy }
it { expect(user.can_create_group?).to be_truthy }
it { expect(user.can_create_project?).to be_truthy }
- it { expect(user.first_name).to eq('John') }
+ it { expect(user.first_name).to eq("John") }
it { expect(user.external).to be_falsey }
end
- describe 'with defaults' do
+ describe "with defaults" do
let(:user) { described_class.new }
it "applies defaults to user" do
@@ -1061,7 +1061,7 @@ describe User do
end
end
- describe 'with default overrides' do
+ describe "with default overrides" do
let(:user) { described_class.new(projects_limit: 123, can_create_group: false, can_create_team: true) }
it "applies defaults to user" do
@@ -1070,7 +1070,7 @@ describe User do
expect(user.theme_id).to eq(1)
end
- it 'does not undo projects_limit setting if it matches old DB default of 10' do
+ it "does not undo projects_limit setting if it matches old DB default of 10" do
# If the real default project limit is 10 then this test is worthless
expect(Gitlab.config.gitlab.default_projects_limit).not_to eq(10)
user = described_class.new(projects_limit: 10)
@@ -1078,7 +1078,7 @@ describe User do
end
end
- context 'when Gitlab::CurrentSettings.user_default_external is true' do
+ context "when Gitlab::CurrentSettings.user_default_external is true" do
before do
stub_application_setting(user_default_external: true)
end
@@ -1091,7 +1091,7 @@ describe User do
expect(user.projects_limit).to be 0
end
- describe 'with default overrides' do
+ describe "with default overrides" do
it "creates a non-external user" do
user = create(:user, external: false)
@@ -1100,11 +1100,11 @@ describe User do
end
end
- describe '#require_ssh_key?', :use_clean_rails_memory_store_caching do
+ describe "#require_ssh_key?", :use_clean_rails_memory_store_caching do
protocol_and_expectation = {
- 'http' => false,
- 'ssh' => true,
- '' => true
+ "http" => false,
+ "ssh" => true,
+ "" => true,
}
protocol_and_expectation.each do |protocol, expected|
@@ -1116,7 +1116,7 @@ describe User do
end
end
- it 'returns false when the user has 1 or more SSH keys' do
+ it "returns false when the user has 1 or more SSH keys" do
key = create(:personal_key)
expect(key.user.require_ssh_key?).to eq(false)
@@ -1124,16 +1124,16 @@ describe User do
end
end
- describe '.find_for_database_authentication' do
- it 'strips whitespace from login' do
+ describe ".find_for_database_authentication" do
+ it "strips whitespace from login" do
user = create(:user)
- expect(described_class.find_for_database_authentication({ login: " #{user.username} " })).to eq user
+ expect(described_class.find_for_database_authentication({login: " #{user.username} "})).to eq user
end
end
- describe '.find_by_any_email' do
- it 'finds user through private commit email' do
+ describe ".find_by_any_email" do
+ it "finds user through private commit email" do
user = create(:user)
private_email = user.private_commit_email
@@ -1141,85 +1141,85 @@ describe User do
expect(described_class.find_by_any_email(private_email, confirmed: true)).to eq(user)
end
- it 'finds by primary email' do
- user = create(:user, email: 'foo@example.com')
+ it "finds by primary email" do
+ user = create(:user, email: "foo@example.com")
expect(described_class.find_by_any_email(user.email)).to eq user
expect(described_class.find_by_any_email(user.email, confirmed: true)).to eq user
end
- it 'finds by uppercased email' do
- user = create(:user, email: 'foo@example.com')
+ it "finds by uppercased email" do
+ user = create(:user, email: "foo@example.com")
expect(described_class.find_by_any_email(user.email.upcase)).to eq user
expect(described_class.find_by_any_email(user.email.upcase, confirmed: true)).to eq user
end
- context 'finds by secondary email' do
+ context "finds by secondary email" do
let(:user) { email.user }
- context 'primary email confirmed' do
- context 'secondary email confirmed' do
- let!(:email) { create(:email, :confirmed, email: 'foo@example.com') }
+ context "primary email confirmed" do
+ context "secondary email confirmed" do
+ let!(:email) { create(:email, :confirmed, email: "foo@example.com") }
- it 'finds user respecting the confirmed flag' do
+ it "finds user respecting the confirmed flag" do
expect(described_class.find_by_any_email(email.email)).to eq user
expect(described_class.find_by_any_email(email.email, confirmed: true)).to eq user
end
end
- context 'secondary email not confirmed' do
- let!(:email) { create(:email, email: 'foo@example.com') }
+ context "secondary email not confirmed" do
+ let!(:email) { create(:email, email: "foo@example.com") }
- it 'finds user respecting the confirmed flag' do
+ it "finds user respecting the confirmed flag" do
expect(described_class.find_by_any_email(email.email)).to eq user
expect(described_class.find_by_any_email(email.email, confirmed: true)).to be_nil
end
end
end
- context 'primary email not confirmed' do
+ context "primary email not confirmed" do
let(:user) { create(:user, confirmed_at: nil) }
- let!(:email) { create(:email, :confirmed, user: user, email: 'foo@example.com') }
+ let!(:email) { create(:email, :confirmed, user: user, email: "foo@example.com") }
- it 'finds user respecting the confirmed flag' do
+ it "finds user respecting the confirmed flag" do
expect(described_class.find_by_any_email(email.email)).to eq user
expect(described_class.find_by_any_email(email.email, confirmed: true)).to be_nil
end
end
end
- it 'returns nil when nothing found' do
- expect(described_class.find_by_any_email('')).to be_nil
+ it "returns nil when nothing found" do
+ expect(described_class.find_by_any_email("")).to be_nil
end
- it 'returns nil when user is not confirmed' do
- user = create(:user, email: 'foo@example.com', confirmed_at: nil)
+ it "returns nil when user is not confirmed" do
+ user = create(:user, email: "foo@example.com", confirmed_at: nil)
expect(described_class.find_by_any_email(user.email, confirmed: false)).to eq(user)
expect(described_class.find_by_any_email(user.email, confirmed: true)).to be_nil
end
end
- describe '.by_any_email' do
- it 'returns an ActiveRecord::Relation' do
- expect(described_class.by_any_email('foo@example.com'))
+ describe ".by_any_email" do
+ it "returns an ActiveRecord::Relation" do
+ expect(described_class.by_any_email("foo@example.com"))
.to be_a_kind_of(ActiveRecord::Relation)
end
- it 'returns a relation of users' do
+ it "returns a relation of users" do
user = create(:user)
expect(described_class.by_any_email(user.email)).to eq([user])
end
- it 'returns a relation of users for confirmed users' do
+ it "returns a relation of users for confirmed users" do
user = create(:user)
expect(described_class.by_any_email(user.email, confirmed: true)).to eq([user])
end
- it 'finds user through a private commit email' do
+ it "finds user through a private commit email" do
user = create(:user)
private_email = user.private_commit_email
@@ -1227,7 +1227,7 @@ describe User do
expect(described_class.by_any_email(private_email, confirmed: true)).to eq([user])
end
- it 'finds user through a private commit email in an array' do
+ it "finds user through a private commit email in an array" do
user = create(:user)
private_email = user.private_commit_email
@@ -1236,268 +1236,268 @@ describe User do
end
end
- describe '.search' do
- let!(:user) { create(:user, name: 'user', username: 'usern', email: 'email@gmail.com') }
- let!(:user2) { create(:user, name: 'user name', username: 'username', email: 'someemail@gmail.com') }
- let!(:user3) { create(:user, name: 'us', username: 'se', email: 'foo@gmail.com') }
+ describe ".search" do
+ let!(:user) { create(:user, name: "user", username: "usern", email: "email@gmail.com") }
+ let!(:user2) { create(:user, name: "user name", username: "username", email: "someemail@gmail.com") }
+ let!(:user3) { create(:user, name: "us", username: "se", email: "foo@gmail.com") }
- describe 'name matching' do
- it 'returns users with a matching name with exact match first' do
+ describe "name matching" do
+ it "returns users with a matching name with exact match first" do
expect(described_class.search(user.name)).to eq([user, user2])
end
- it 'returns users with a partially matching name' do
+ it "returns users with a partially matching name" do
expect(described_class.search(user.name[0..2])).to eq([user, user2])
end
- it 'returns users with a matching name regardless of the casing' do
+ it "returns users with a matching name regardless of the casing" do
expect(described_class.search(user2.name.upcase)).to eq([user2])
end
- it 'returns users with a exact matching name shorter than 3 chars' do
+ it "returns users with a exact matching name shorter than 3 chars" do
expect(described_class.search(user3.name)).to eq([user3])
end
- it 'returns users with a exact matching name shorter than 3 chars regardless of the casing' do
+ it "returns users with a exact matching name shorter than 3 chars regardless of the casing" do
expect(described_class.search(user3.name.upcase)).to eq([user3])
end
end
- describe 'email matching' do
- it 'returns users with a matching Email' do
+ describe "email matching" do
+ it "returns users with a matching Email" do
expect(described_class.search(user.email)).to eq([user])
end
- it 'does not return users with a partially matching Email' do
+ it "does not return users with a partially matching Email" do
expect(described_class.search(user.email[0..2])).not_to include(user, user2)
end
- it 'returns users with a matching Email regardless of the casing' do
+ it "returns users with a matching Email regardless of the casing" do
expect(described_class.search(user2.email.upcase)).to eq([user2])
end
end
- describe 'username matching' do
- it 'returns users with a matching username' do
+ describe "username matching" do
+ it "returns users with a matching username" do
expect(described_class.search(user.username)).to eq([user, user2])
end
- it 'returns users with a partially matching username' do
+ it "returns users with a partially matching username" do
expect(described_class.search(user.username[0..2])).to eq([user, user2])
end
- it 'returns users with a matching username regardless of the casing' do
+ it "returns users with a matching username regardless of the casing" do
expect(described_class.search(user2.username.upcase)).to eq([user2])
end
- it 'returns users with a exact matching username shorter than 3 chars' do
+ it "returns users with a exact matching username shorter than 3 chars" do
expect(described_class.search(user3.username)).to eq([user3])
end
- it 'returns users with a exact matching username shorter than 3 chars regardless of the casing' do
+ it "returns users with a exact matching username shorter than 3 chars regardless of the casing" do
expect(described_class.search(user3.username.upcase)).to eq([user3])
end
end
- it 'returns no matches for an empty string' do
- expect(described_class.search('')).to be_empty
+ it "returns no matches for an empty string" do
+ expect(described_class.search("")).to be_empty
end
- it 'returns no matches for nil' do
+ it "returns no matches for nil" do
expect(described_class.search(nil)).to be_empty
end
end
- describe '.search_with_secondary_emails' do
+ describe ".search_with_secondary_emails" do
delegate :search_with_secondary_emails, to: :described_class
- let!(:user) { create(:user, name: 'John Doe', username: 'john.doe', email: 'john.doe@example.com' ) }
- let!(:another_user) { create(:user, name: 'Albert Smith', username: 'albert.smith', email: 'albert.smith@example.com' ) }
+ let!(:user) { create(:user, name: "John Doe", username: "john.doe", email: "john.doe@example.com") }
+ let!(:another_user) { create(:user, name: "Albert Smith", username: "albert.smith", email: "albert.smith@example.com") }
let!(:email) do
- create(:email, user: another_user, email: 'alias@example.com')
+ create(:email, user: another_user, email: "alias@example.com")
end
- it 'returns users with a matching name' do
+ it "returns users with a matching name" do
expect(search_with_secondary_emails(user.name)).to eq([user])
end
- it 'returns users with a partially matching name' do
+ it "returns users with a partially matching name" do
expect(search_with_secondary_emails(user.name[0..2])).to eq([user])
end
- it 'returns users with a matching name regardless of the casing' do
+ it "returns users with a matching name regardless of the casing" do
expect(search_with_secondary_emails(user.name.upcase)).to eq([user])
end
- it 'returns users with a matching email' do
+ it "returns users with a matching email" do
expect(search_with_secondary_emails(user.email)).to eq([user])
end
- it 'does not return users with a partially matching email' do
+ it "does not return users with a partially matching email" do
expect(search_with_secondary_emails(user.email[0..2])).not_to include([user])
end
- it 'returns users with a matching email regardless of the casing' do
+ it "returns users with a matching email regardless of the casing" do
expect(search_with_secondary_emails(user.email.upcase)).to eq([user])
end
- it 'returns users with a matching username' do
+ it "returns users with a matching username" do
expect(search_with_secondary_emails(user.username)).to eq([user])
end
- it 'returns users with a partially matching username' do
+ it "returns users with a partially matching username" do
expect(search_with_secondary_emails(user.username[0..2])).to eq([user])
end
- it 'returns users with a matching username regardless of the casing' do
+ it "returns users with a matching username regardless of the casing" do
expect(search_with_secondary_emails(user.username.upcase)).to eq([user])
end
- it 'returns users with a matching whole secondary email' do
+ it "returns users with a matching whole secondary email" do
expect(search_with_secondary_emails(email.email)).to eq([email.user])
end
- it 'does not return users with a matching part of secondary email' do
+ it "does not return users with a matching part of secondary email" do
expect(search_with_secondary_emails(email.email[1..4])).not_to include([email.user])
end
- it 'returns no matches for an empty string' do
- expect(search_with_secondary_emails('')).to be_empty
+ it "returns no matches for an empty string" do
+ expect(search_with_secondary_emails("")).to be_empty
end
- it 'returns no matches for nil' do
+ it "returns no matches for nil" do
expect(search_with_secondary_emails(nil)).to be_empty
end
end
- describe '.find_by_ssh_key_id' do
- context 'using an existing SSH key ID' do
+ describe ".find_by_ssh_key_id" do
+ context "using an existing SSH key ID" do
let(:user) { create(:user) }
let(:key) { create(:key, user: user) }
- it 'returns the corresponding User' do
+ it "returns the corresponding User" do
expect(described_class.find_by_ssh_key_id(key.id)).to eq(user)
end
end
- context 'using an invalid SSH key ID' do
- it 'returns nil' do
+ context "using an invalid SSH key ID" do
+ it "returns nil" do
expect(described_class.find_by_ssh_key_id(-1)).to be_nil
end
end
end
- describe '.by_login' do
- let(:username) { 'John' }
+ describe ".by_login" do
+ let(:username) { "John" }
let!(:user) { create(:user, username: username) }
- it 'gets the correct user' do
+ it "gets the correct user" do
expect(described_class.by_login(user.email.upcase)).to eq user
expect(described_class.by_login(user.email)).to eq user
expect(described_class.by_login(username.downcase)).to eq user
expect(described_class.by_login(username)).to eq user
expect(described_class.by_login(nil)).to be_nil
- expect(described_class.by_login('')).to be_nil
+ expect(described_class.by_login("")).to be_nil
end
end
- describe '.find_by_username' do
- it 'returns nil if not found' do
- expect(described_class.find_by_username('JohnDoe')).to be_nil
+ describe ".find_by_username" do
+ it "returns nil if not found" do
+ expect(described_class.find_by_username("JohnDoe")).to be_nil
end
- it 'is case-insensitive' do
- user = create(:user, username: 'JohnDoe')
+ it "is case-insensitive" do
+ user = create(:user, username: "JohnDoe")
- expect(described_class.find_by_username('JOHNDOE')).to eq user
+ expect(described_class.find_by_username("JOHNDOE")).to eq user
end
end
- describe '.find_by_username!' do
- it 'raises RecordNotFound' do
- expect { described_class.find_by_username!('JohnDoe') }
+ describe ".find_by_username!" do
+ it "raises RecordNotFound" do
+ expect { described_class.find_by_username!("JohnDoe") }
.to raise_error(ActiveRecord::RecordNotFound)
end
- it 'is case-insensitive' do
- user = create(:user, username: 'JohnDoe')
+ it "is case-insensitive" do
+ user = create(:user, username: "JohnDoe")
- expect(described_class.find_by_username!('JOHNDOE')).to eq user
+ expect(described_class.find_by_username!("JOHNDOE")).to eq user
end
end
- describe '.find_by_full_path' do
+ describe ".find_by_full_path" do
let!(:user) { create(:user) }
- context 'with a route matching the given path' do
+ context "with a route matching the given path" do
let!(:route) { user.namespace.route }
- it 'returns the user' do
+ it "returns the user" do
expect(described_class.find_by_full_path(route.path)).to eq(user)
end
- it 'is case-insensitive' do
+ it "is case-insensitive" do
expect(described_class.find_by_full_path(route.path.upcase)).to eq(user)
expect(described_class.find_by_full_path(route.path.downcase)).to eq(user)
end
end
- context 'with a redirect route matching the given path' do
- let!(:redirect_route) { user.namespace.redirect_routes.create(path: 'foo') }
+ context "with a redirect route matching the given path" do
+ let!(:redirect_route) { user.namespace.redirect_routes.create(path: "foo") }
- context 'without the follow_redirects option' do
- it 'returns nil' do
+ context "without the follow_redirects option" do
+ it "returns nil" do
expect(described_class.find_by_full_path(redirect_route.path)).to eq(nil)
end
end
- context 'with the follow_redirects option set to true' do
- it 'returns the user' do
+ context "with the follow_redirects option set to true" do
+ it "returns the user" do
expect(described_class.find_by_full_path(redirect_route.path, follow_redirects: true)).to eq(user)
end
- it 'is case-insensitive' do
+ it "is case-insensitive" do
expect(described_class.find_by_full_path(redirect_route.path.upcase, follow_redirects: true)).to eq(user)
expect(described_class.find_by_full_path(redirect_route.path.downcase, follow_redirects: true)).to eq(user)
end
end
end
- context 'without a route or a redirect route matching the given path' do
- context 'without the follow_redirects option' do
- it 'returns nil' do
- expect(described_class.find_by_full_path('unknown')).to eq(nil)
+ context "without a route or a redirect route matching the given path" do
+ context "without the follow_redirects option" do
+ it "returns nil" do
+ expect(described_class.find_by_full_path("unknown")).to eq(nil)
end
end
- context 'with the follow_redirects option set to true' do
- it 'returns nil' do
- expect(described_class.find_by_full_path('unknown', follow_redirects: true)).to eq(nil)
+ context "with the follow_redirects option set to true" do
+ it "returns nil" do
+ expect(described_class.find_by_full_path("unknown", follow_redirects: true)).to eq(nil)
end
end
end
- context 'with a group route matching the given path' do
- let!(:group) { create(:group, path: 'group_path') }
+ context "with a group route matching the given path" do
+ let!(:group) { create(:group, path: "group_path") }
- context 'when the group namespace has an owner_id (legacy data)' do
+ context "when the group namespace has an owner_id (legacy data)" do
before do
group.update!(owner_id: user.id)
end
- it 'returns nil' do
- expect(described_class.find_by_full_path('group_path')).to eq(nil)
+ it "returns nil" do
+ expect(described_class.find_by_full_path("group_path")).to eq(nil)
end
end
- context 'when the group namespace does not have an owner_id' do
- it 'returns nil' do
- expect(described_class.find_by_full_path('group_path')).to eq(nil)
+ context "when the group namespace does not have an owner_id" do
+ it "returns nil" do
+ expect(described_class.find_by_full_path("group_path")).to eq(nil)
end
end
end
end
- describe 'all_ssh_keys' do
+ describe "all_ssh_keys" do
it { is_expected.to have_many(:keys).dependent(:destroy) }
it "has all ssh keys" do
@@ -1508,41 +1508,41 @@ describe User do
end
end
- describe '#avatar_type' do
+ describe "#avatar_type" do
let(:user) { create(:user) }
- it 'is true if avatar is image' do
- user.update_attribute(:avatar, 'uploads/avatar.png')
+ it "is true if avatar is image" do
+ user.update_attribute(:avatar, "uploads/avatar.png")
expect(user.avatar_type).to be_truthy
end
- it 'is false if avatar is html page' do
- user.update_attribute(:avatar, 'uploads/avatar.html')
+ it "is false if avatar is html page" do
+ user.update_attribute(:avatar, "uploads/avatar.html")
- expect(user.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico'])
+ expect(user.avatar_type).to eq(["file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico"])
end
end
- describe '#avatar_url' do
+ describe "#avatar_url" do
let(:user) { create(:user, :with_avatar) }
- context 'when avatar file is uploaded' do
- it 'shows correct avatar url' do
+ context "when avatar file is uploaded" do
+ it "shows correct avatar url" do
expect(user.avatar_url).to eq(user.avatar.url)
expect(user.avatar_url(only_path: false)).to eq([Gitlab.config.gitlab.url, user.avatar.url].join)
end
end
end
- describe '#accept_pending_invitations!' do
- let(:user) { create(:user, email: 'user@email.com') }
+ describe "#accept_pending_invitations!" do
+ let(:user) { create(:user, email: "user@email.com") }
let!(:project_member_invite) { create(:project_member, :invited, invite_email: user.email) }
let!(:group_member_invite) { create(:group_member, :invited, invite_email: user.email) }
- let!(:external_project_member_invite) { create(:project_member, :invited, invite_email: 'external@email.com') }
- let!(:external_group_member_invite) { create(:group_member, :invited, invite_email: 'external@email.com') }
+ let!(:external_project_member_invite) { create(:project_member, :invited, invite_email: "external@email.com") }
+ let!(:external_group_member_invite) { create(:group_member, :invited, invite_email: "external@email.com") }
- it 'accepts all the user members pending invitations and returns the accepted_members' do
+ it "accepts all the user members pending invitations and returns the accepted_members" do
accepted_members = user.accept_pending_invitations!
expect(accepted_members).to match_array([project_member_invite, group_member_invite])
@@ -1553,10 +1553,10 @@ describe User do
end
end
- describe '#all_emails' do
+ describe "#all_emails" do
let(:user) { create(:user) }
- it 'returns all emails' do
+ it "returns all emails" do
email_confirmed = create :email, user: user, confirmed_at: Time.now
email_unconfirmed = create :email, user: user
user.reload
@@ -1570,10 +1570,10 @@ describe User do
end
end
- describe '#verified_emails' do
+ describe "#verified_emails" do
let(:user) { create(:user) }
- it 'returns only confirmed emails' do
+ it "returns only confirmed emails" do
email_confirmed = create :email, user: user, confirmed_at: Time.now
create :email, user: user
@@ -1585,10 +1585,10 @@ describe User do
end
end
- describe '#verified_email?' do
+ describe "#verified_email?" do
let(:user) { create(:user) }
- it 'returns true when the email is verified/confirmed' do
+ it "returns true when the email is verified/confirmed" do
email_confirmed = create :email, user: user, confirmed_at: Time.now
create :email, user: user
user.reload
@@ -1597,19 +1597,19 @@ describe User do
expect(user.verified_email?(email_confirmed.email.titlecase)).to be_truthy
end
- it 'returns true when user is found through private commit email' do
+ it "returns true when user is found through private commit email" do
expect(user.verified_email?(user.private_commit_email)).to be_truthy
end
- it 'returns true for an outdated private commit email' do
+ it "returns true for an outdated private commit email" do
old_email = user.private_commit_email
- user.update!(username: 'changed-username')
+ user.update!(username: "changed-username")
expect(user.verified_email?(old_email)).to be_truthy
end
- it 'returns false when the email is not verified/confirmed' do
+ it "returns false when the email is not verified/confirmed" do
email_unconfirmed = create :email, user: user
user.reload
@@ -1617,10 +1617,10 @@ describe User do
end
end
- describe '#requires_ldap_check?' do
+ describe "#requires_ldap_check?" do
let(:user) { described_class.new }
- it 'is false when LDAP is disabled' do
+ it "is false when LDAP is disabled" do
# Create a condition which would otherwise cause 'true' to be returned
allow(user).to receive(:ldap_user?).and_return(true)
user.last_credential_check_at = nil
@@ -1628,29 +1628,29 @@ describe User do
expect(user.requires_ldap_check?).to be_falsey
end
- context 'when LDAP is enabled' do
+ context "when LDAP is enabled" do
before do
allow(Gitlab.config.ldap).to receive(:enabled).and_return(true)
end
- it 'is false for non-LDAP users' do
+ it "is false for non-LDAP users" do
allow(user).to receive(:ldap_user?).and_return(false)
expect(user.requires_ldap_check?).to be_falsey
end
- context 'and when the user is an LDAP user' do
+ context "and when the user is an LDAP user" do
before do
allow(user).to receive(:ldap_user?).and_return(true)
end
- it 'is true when the user has never had an LDAP check before' do
+ it "is true when the user has never had an LDAP check before" do
user.last_credential_check_at = nil
expect(user.requires_ldap_check?).to be_truthy
end
- it 'is true when the last LDAP check happened over 1 hour ago' do
+ it "is true when the last LDAP check happened over 1 hour ago" do
user.last_credential_check_at = 2.hours.ago
expect(user.requires_ldap_check?).to be_truthy
@@ -1659,39 +1659,39 @@ describe User do
end
end
- context 'ldap synchronized user' do
- describe '#ldap_user?' do
- it 'is true if provider name starts with ldap' do
- user = create(:omniauth_user, provider: 'ldapmain')
+ context "ldap synchronized user" do
+ describe "#ldap_user?" do
+ it "is true if provider name starts with ldap" do
+ user = create(:omniauth_user, provider: "ldapmain")
expect(user.ldap_user?).to be_truthy
end
- it 'is false for other providers' do
- user = create(:omniauth_user, provider: 'other-provider')
+ it "is false for other providers" do
+ user = create(:omniauth_user, provider: "other-provider")
expect(user.ldap_user?).to be_falsey
end
- it 'is false if no extern_uid is provided' do
+ it "is false if no extern_uid is provided" do
user = create(:omniauth_user, extern_uid: nil)
expect(user.ldap_user?).to be_falsey
end
end
- describe '#ldap_identity' do
- it 'returns ldap identity' do
+ describe "#ldap_identity" do
+ it "returns ldap identity" do
user = create :omniauth_user
expect(user.ldap_identity.provider).not_to be_empty
end
end
- describe '#ldap_block' do
- let(:user) { create(:omniauth_user, provider: 'ldapmain', name: 'John Smith') }
+ describe "#ldap_block" do
+ let(:user) { create(:omniauth_user, provider: "ldapmain", name: "John Smith") }
- it 'blocks user flaging the action caming from ldap' do
+ it "blocks user flaging the action caming from ldap" do
user.ldap_block
expect(user.blocked?).to be_truthy
@@ -1700,64 +1700,64 @@ describe User do
end
end
- describe '#full_website_url' do
+ describe "#full_website_url" do
let(:user) { create(:user) }
- it 'begins with http if website url omits it' do
- user.website_url = 'test.com'
+ it "begins with http if website url omits it" do
+ user.website_url = "test.com"
- expect(user.full_website_url).to eq 'http://test.com'
+ expect(user.full_website_url).to eq "http://test.com"
end
- it 'begins with http if website url begins with http' do
- user.website_url = 'http://test.com'
+ it "begins with http if website url begins with http" do
+ user.website_url = "http://test.com"
- expect(user.full_website_url).to eq 'http://test.com'
+ expect(user.full_website_url).to eq "http://test.com"
end
- it 'begins with https if website url begins with https' do
- user.website_url = 'https://test.com'
+ it "begins with https if website url begins with https" do
+ user.website_url = "https://test.com"
- expect(user.full_website_url).to eq 'https://test.com'
+ expect(user.full_website_url).to eq "https://test.com"
end
end
- describe '#short_website_url' do
+ describe "#short_website_url" do
let(:user) { create(:user) }
- it 'does not begin with http if website url omits it' do
- user.website_url = 'test.com'
+ it "does not begin with http if website url omits it" do
+ user.website_url = "test.com"
- expect(user.short_website_url).to eq 'test.com'
+ expect(user.short_website_url).to eq "test.com"
end
- it 'does not begin with http if website url begins with http' do
- user.website_url = 'http://test.com'
+ it "does not begin with http if website url begins with http" do
+ user.website_url = "http://test.com"
- expect(user.short_website_url).to eq 'test.com'
+ expect(user.short_website_url).to eq "test.com"
end
- it 'does not begin with https if website url begins with https' do
- user.website_url = 'https://test.com'
+ it "does not begin with https if website url begins with https" do
+ user.website_url = "https://test.com"
- expect(user.short_website_url).to eq 'test.com'
+ expect(user.short_website_url).to eq "test.com"
end
end
- describe '#sanitize_attrs' do
- let(:user) { build(:user, name: 'test & user', skype: 'test&user') }
+ describe "#sanitize_attrs" do
+ let(:user) { build(:user, name: "test & user", skype: "test&user") }
- it 'encodes HTML entities in the Skype attribute' do
- expect { user.sanitize_attrs }.to change { user.skype }.to('test&amp;user')
+ it "encodes HTML entities in the Skype attribute" do
+ expect { user.sanitize_attrs }.to change { user.skype }.to("test&amp;user")
end
- it 'does not encode HTML entities in the name attribute' do
+ it "does not encode HTML entities in the name attribute" do
expect { user.sanitize_attrs }.not_to change { user.name }
end
end
- describe '#starred?' do
- it 'determines if user starred a project' do
+ describe "#starred?" do
+ it "determines if user starred a project" do
user = create :user
project1 = create(:project, :public)
project2 = create(:project, :public)
@@ -1787,8 +1787,8 @@ describe User do
end
end
- describe '#toggle_star' do
- it 'toggles stars' do
+ describe "#toggle_star" do
+ it "toggles stars" do
user = create :user
project = create(:project, :public)
@@ -1804,67 +1804,67 @@ describe User do
end
end
- describe '.find_by_private_commit_email' do
- context 'with email' do
+ describe ".find_by_private_commit_email" do
+ context "with email" do
set(:user) { create(:user) }
- it 'returns user through private commit email' do
+ it "returns user through private commit email" do
expect(described_class.find_by_private_commit_email(user.private_commit_email)).to eq(user)
end
- it 'returns nil when email other than private_commit_email is used' do
+ it "returns nil when email other than private_commit_email is used" do
expect(described_class.find_by_private_commit_email(user.email)).to be_nil
end
end
- it 'returns nil when email is nil' do
+ it "returns nil when email is nil" do
expect(described_class.find_by_private_commit_email(nil)).to be_nil
end
end
- describe '#sort_by_attribute' do
+ describe "#sort_by_attribute" do
before do
described_class.delete_all
- @user = create :user, created_at: Date.today, current_sign_in_at: Date.today, name: 'Alpha'
- @user1 = create :user, created_at: Date.today - 1, current_sign_in_at: Date.today - 1, name: 'Omega'
- @user2 = create :user, created_at: Date.today - 2, name: 'Beta'
+ @user = create :user, created_at: Date.today, current_sign_in_at: Date.today, name: "Alpha"
+ @user1 = create :user, created_at: Date.today - 1, current_sign_in_at: Date.today - 1, name: "Omega"
+ @user2 = create :user, created_at: Date.today - 2, name: "Beta"
end
- context 'when sort by recent_sign_in' do
- let(:users) { described_class.sort_by_attribute('recent_sign_in') }
+ context "when sort by recent_sign_in" do
+ let(:users) { described_class.sort_by_attribute("recent_sign_in") }
- it 'sorts users by recent sign-in time' do
+ it "sorts users by recent sign-in time" do
expect(users.first).to eq(@user)
expect(users.second).to eq(@user1)
end
- it 'pushes users who never signed in to the end' do
+ it "pushes users who never signed in to the end" do
expect(users.third).to eq(@user2)
end
end
- context 'when sort by oldest_sign_in' do
- let(:users) { described_class.sort_by_attribute('oldest_sign_in') }
+ context "when sort by oldest_sign_in" do
+ let(:users) { described_class.sort_by_attribute("oldest_sign_in") }
- it 'sorts users by the oldest sign-in time' do
+ it "sorts users by the oldest sign-in time" do
expect(users.first).to eq(@user1)
expect(users.second).to eq(@user)
end
- it 'pushes users who never signed in to the end' do
+ it "pushes users who never signed in to the end" do
expect(users.third).to eq(@user2)
end
end
- it 'sorts users in descending order by their creation time' do
- expect(described_class.sort_by_attribute('created_desc').first).to eq(@user)
+ it "sorts users in descending order by their creation time" do
+ expect(described_class.sort_by_attribute("created_desc").first).to eq(@user)
end
- it 'sorts users in ascending order by their creation time' do
- expect(described_class.sort_by_attribute('created_asc').first).to eq(@user2)
+ it "sorts users in ascending order by their creation time" do
+ expect(described_class.sort_by_attribute("created_asc").first).to eq(@user2)
end
- it 'sorts users by id in descending order when nil is passed' do
+ it "sorts users by id in descending order when nil is passed" do
expect(described_class.sort_by_attribute(nil).first).to eq(@user2)
end
end
@@ -1896,7 +1896,7 @@ describe User do
end
end
- describe '#fork_of' do
+ describe "#fork_of" do
let(:user) { create(:user) }
it "returns a user's fork of a project" do
@@ -1906,21 +1906,21 @@ describe User do
expect(user.fork_of(project)).to eq(user_fork)
end
- it 'returns nil if the project does not have a fork network' do
+ it "returns nil if the project does not have a fork network" do
project = create(:project)
expect(user.fork_of(project)).to be_nil
end
end
- describe '#can_be_removed?' do
+ describe "#can_be_removed?" do
subject { create(:user) }
- context 'no owned groups' do
+ context "no owned groups" do
it { expect(subject.can_be_removed?).to be_truthy }
end
- context 'has owned groups' do
+ context "has owned groups" do
before do
group = create(:group)
group.add_owner(subject)
@@ -1935,7 +1935,7 @@ describe User do
let(:project) { build(:project) }
let(:event) { build(:push_event) }
- it 'returns the last push event for the user' do
+ it "returns the last push event for the user" do
expect_any_instance_of(Users::LastPushEventService)
.to receive(:last_event_for_user)
.and_return(event)
@@ -1943,7 +1943,7 @@ describe User do
expect(user.recent_push).to eq(event)
end
- it 'returns the last push event for a project when one is given' do
+ it "returns the last push event for a project when one is given" do
expect_any_instance_of(Users::LastPushEventService)
.to receive(:last_event_for_project)
.and_return(event)
@@ -1952,7 +1952,7 @@ describe User do
end
end
- describe '#authorized_groups' do
+ describe "#authorized_groups" do
let!(:user) { create(:user) }
let!(:private_group) { create(:group) }
let!(:child_group) { create(:group, parent: private_group) }
@@ -1970,7 +1970,7 @@ describe User do
it { is_expected.to contain_exactly private_group, project_group }
end
- describe '#membership_groups' do
+ describe "#membership_groups" do
let!(:user) { create(:user) }
let!(:parent_group) { create(:group) }
let!(:child_group) { create(:group, parent: parent_group) }
@@ -1988,11 +1988,11 @@ describe User do
end
end
- describe '#authorizations_for_projects' do
+ describe "#authorizations_for_projects" do
let!(:user) { create(:user) }
subject { Project.where("EXISTS (?)", user.authorizations_for_projects) }
- it 'includes projects that belong to a user, but no other projects' do
+ it "includes projects that belong to a user, but no other projects" do
owned = create(:project, :private, namespace: user.namespace)
member = create(:project, :private).tap { |p| p.add_maintainer(user) }
other = create(:project)
@@ -2002,18 +2002,18 @@ describe User do
expect(subject).not_to include(other)
end
- it 'includes projects a user has access to, but no other projects' do
+ it "includes projects a user has access to, but no other projects" do
other_user = create(:user)
- accessible = create(:project, :private, namespace: other_user.namespace) do |project|
+ accessible = create(:project, :private, namespace: other_user.namespace) { |project|
project.add_developer(user)
- end
+ }
other = create(:project)
expect(subject).to include(accessible)
expect(subject).not_to include(other)
end
- context 'with min_access_level' do
+ context "with min_access_level" do
let!(:user) { create(:user) }
let!(:project) { create(:project, :private, namespace: user.namespace) }
@@ -2023,27 +2023,27 @@ describe User do
subject { Project.where("EXISTS (?)", user.authorizations_for_projects(min_access_level: min_access_level)) }
- context 'when developer access' do
+ context "when developer access" do
let(:min_access_level) { Gitlab::Access::DEVELOPER }
- it 'includes projects a user has access to' do
+ it "includes projects a user has access to" do
expect(subject).to include(project)
end
end
- context 'when owner access' do
+ context "when owner access" do
let(:min_access_level) { Gitlab::Access::OWNER }
- it 'does not include projects with higher access level' do
+ it "does not include projects with higher access level" do
expect(subject).not_to include(project)
end
end
end
end
- describe '#authorized_projects', :delete do
- context 'with a minimum access level' do
- it 'includes projects for which the user is an owner' do
+ describe "#authorized_projects", :delete do
+ context "with a minimum access level" do
+ it "includes projects for which the user is an owner" do
user = create(:user)
project = create(:project, :private, namespace: user.namespace)
@@ -2051,7 +2051,7 @@ describe User do
.to contain_exactly(project)
end
- it 'includes projects for which the user is a maintainer' do
+ it "includes projects for which the user is a maintainer" do
user = create(:user)
project = create(:project, :private)
@@ -2143,10 +2143,10 @@ describe User do
end
end
- describe '#projects_where_can_admin_issues' do
+ describe "#projects_where_can_admin_issues" do
let(:user) { create(:user) }
- it 'includes projects for which the user access level is above or equal to reporter' do
+ it "includes projects for which the user access level is above or equal to reporter" do
reporter_project = create(:project) { |p| p.add_reporter(user) }
developer_project = create(:project) { |p| p.add_developer(user) }
maintainer_project = create(:project) { |p| p.add_maintainer(user) }
@@ -2157,7 +2157,7 @@ describe User do
expect(user.can?(:admin_issue, reporter_project)).to eq(true)
end
- it 'does not include for which the user access level is below reporter' do
+ it "does not include for which the user access level is below reporter" do
project = create(:project)
guest_project = create(:project) { |p| p.add_guest(user) }
@@ -2166,14 +2166,14 @@ describe User do
expect(user.can?(:admin_issue, project)).to eq(false)
end
- it 'does not include archived projects' do
+ it "does not include archived projects" do
project = create(:project, :archived)
expect(user.projects_where_can_admin_issues.to_a).to be_empty
expect(user.can?(:admin_issue, project)).to eq(false)
end
- it 'does not include projects for which issues are disabled' do
+ it "does not include projects for which issues are disabled" do
project = create(:project, :issues_disabled)
expect(user.projects_where_can_admin_issues.to_a).to be_empty
@@ -2181,27 +2181,27 @@ describe User do
end
end
- describe '#ci_owned_runners' do
+ describe "#ci_owned_runners" do
let(:user) { create(:user) }
let!(:project) { create(:project) }
let(:runner) { create(:ci_runner, :project, projects: [project]) }
- context 'without any projects nor groups' do
- it 'does not load' do
+ context "without any projects nor groups" do
+ it "does not load" do
expect(user.ci_owned_runners).to be_empty
end
end
- context 'with personal projects runners' do
+ context "with personal projects runners" do
let(:namespace) { create(:namespace, owner: user) }
let!(:project) { create(:project, namespace: namespace) }
- it 'loads' do
+ it "loads" do
expect(user.ci_owned_runners).to contain_exactly(runner)
end
end
- context 'with personal group runner' do
+ context "with personal group runner" do
let!(:project) { create(:project) }
let(:group_runner) { create(:ci_runner, :group, groups: [group]) }
let!(:group) do
@@ -2210,12 +2210,12 @@ describe User do
end
end
- it 'loads' do
+ it "loads" do
expect(user.ci_owned_runners).to contain_exactly(group_runner)
end
end
- context 'with personal project and group runner' do
+ context "with personal project and group runner" do
let(:namespace) { create(:namespace, owner: user) }
let!(:project) { create(:project, namespace: namespace) }
let!(:group_runner) { create(:ci_runner, :group, groups: [group]) }
@@ -2226,34 +2226,34 @@ describe User do
end
end
- it 'loads' do
+ it "loads" do
expect(user.ci_owned_runners).to contain_exactly(runner, group_runner)
end
end
shared_examples :member do
- context 'when the user is a maintainer' do
+ context "when the user is a maintainer" do
before do
add_user(:maintainer)
end
- it 'loads' do
+ it "loads" do
expect(user.ci_owned_runners).to contain_exactly(runner)
end
end
- context 'when the user is a developer' do
+ context "when the user is a developer" do
before do
add_user(:developer)
end
- it 'does not load' do
+ it "does not load" do
expect(user.ci_owned_runners).to be_empty
end
end
end
- context 'with groups projects runners' do
+ context "with groups projects runners" do
let(:group) { create(:group) }
let!(:project) { create(:project, group: group) }
@@ -2264,7 +2264,7 @@ describe User do
it_behaves_like :member
end
- context 'with groups runners' do
+ context "with groups runners" do
let!(:runner) { create(:ci_runner, :group, groups: [group]) }
let!(:group) { create(:group) }
@@ -2275,7 +2275,7 @@ describe User do
it_behaves_like :member
end
- context 'with other projects runners' do
+ context "with other projects runners" do
let!(:project) { create(:project) }
def add_user(access)
@@ -2285,7 +2285,7 @@ describe User do
it_behaves_like :member
end
- context 'with subgroup with different owner for project runner', :nested_groups do
+ context "with subgroup with different owner for project runner", :nested_groups do
let(:group) { create(:group) }
let(:another_user) { create(:user) }
let(:subgroup) { create(:group, parent: group) }
@@ -2301,7 +2301,7 @@ describe User do
end
end
- describe '#projects_with_reporter_access_limited_to' do
+ describe "#projects_with_reporter_access_limited_to" do
let(:project1) { create(:project) }
let(:project2) { create(:project) }
let(:user) { create(:user) }
@@ -2311,33 +2311,33 @@ describe User do
project2.add_guest(user)
end
- it 'returns the projects when using a single project ID' do
+ it "returns the projects when using a single project ID" do
projects = user.projects_with_reporter_access_limited_to(project1.id)
expect(projects).to eq([project1])
end
- it 'returns the projects when using an Array of project IDs' do
+ it "returns the projects when using an Array of project IDs" do
projects = user.projects_with_reporter_access_limited_to([project1.id])
expect(projects).to eq([project1])
end
- it 'returns the projects when using an ActiveRecord relation' do
+ it "returns the projects when using an ActiveRecord relation" do
projects = user
.projects_with_reporter_access_limited_to(Project.select(:id))
expect(projects).to eq([project1])
end
- it 'does not return projects you do not have reporter access to' do
+ it "does not return projects you do not have reporter access to" do
projects = user.projects_with_reporter_access_limited_to(project2.id)
expect(projects).to be_empty
end
end
- describe '#all_expanded_groups' do
+ describe "#all_expanded_groups" do
# foo/bar would also match foo/barbaz instead of just foo/bar and foo/bar/baz
let!(:user) { create(:user) }
@@ -2353,20 +2353,20 @@ describe User do
# (baz) (baz)
#
let!(:group) { create :group }
- let!(:nested_group_1) { create :group, parent: group, name: 'bar' }
- let!(:nested_group_1_1) { create :group, parent: nested_group_1, name: 'baz' }
- let!(:nested_group_2) { create :group, parent: group, name: 'barbaz' }
- let!(:nested_group_2_1) { create :group, parent: nested_group_2, name: 'baz' }
+ let!(:nested_group_1) { create :group, parent: group, name: "bar" }
+ let!(:nested_group_1_1) { create :group, parent: nested_group_1, name: "baz" }
+ let!(:nested_group_2) { create :group, parent: group, name: "barbaz" }
+ let!(:nested_group_2_1) { create :group, parent: nested_group_2, name: "baz" }
subject { user.all_expanded_groups }
- context 'user is not a member of any group' do
- it 'returns an empty array' do
+ context "user is not a member of any group" do
+ it "returns an empty array" do
is_expected.to eq([])
end
end
- context 'user is member of all groups' do
+ context "user is member of all groups" do
before do
group.add_reporter(user)
nested_group_1.add_developer(user)
@@ -2375,76 +2375,76 @@ describe User do
nested_group_2_1.add_maintainer(user)
end
- it 'returns all groups' do
+ it "returns all groups" do
is_expected.to match_array [
group,
nested_group_1, nested_group_1_1,
- nested_group_2, nested_group_2_1
+ nested_group_2, nested_group_2_1,
]
end
end
- context 'user is member of the top group' do
+ context "user is member of the top group" do
before do
group.add_owner(user)
end
if Group.supports_nested_objects?
- it 'returns all groups' do
+ it "returns all groups" do
is_expected.to match_array [
group,
nested_group_1, nested_group_1_1,
- nested_group_2, nested_group_2_1
+ nested_group_2, nested_group_2_1,
]
end
else
- it 'returns the top-level groups' do
+ it "returns the top-level groups" do
is_expected.to match_array [group]
end
end
end
- context 'user is member of the first child (internal node), branch 1', :nested_groups do
+ context "user is member of the first child (internal node), branch 1", :nested_groups do
before do
nested_group_1.add_owner(user)
end
- it 'returns the groups in the hierarchy' do
+ it "returns the groups in the hierarchy" do
is_expected.to match_array [
group,
- nested_group_1, nested_group_1_1
+ nested_group_1, nested_group_1_1,
]
end
end
- context 'user is member of the first child (internal node), branch 2', :nested_groups do
+ context "user is member of the first child (internal node), branch 2", :nested_groups do
before do
nested_group_2.add_owner(user)
end
- it 'returns the groups in the hierarchy' do
+ it "returns the groups in the hierarchy" do
is_expected.to match_array [
group,
- nested_group_2, nested_group_2_1
+ nested_group_2, nested_group_2_1,
]
end
end
- context 'user is member of the last child (leaf node)', :nested_groups do
+ context "user is member of the last child (leaf node)", :nested_groups do
before do
nested_group_1_1.add_owner(user)
end
- it 'returns the groups in the hierarchy' do
+ it "returns the groups in the hierarchy" do
is_expected.to match_array [
group,
- nested_group_1, nested_group_1_1
+ nested_group_1, nested_group_1_1,
]
end
end
end
- describe '#refresh_authorized_projects', :clean_gitlab_redis_shared_state do
+ describe "#refresh_authorized_projects", :clean_gitlab_redis_shared_state do
let(:project1) { create(:project) }
let(:project2) { create(:project) }
let(:user) { create(:user) }
@@ -2457,20 +2457,20 @@ describe User do
user.refresh_authorized_projects
end
- it 'refreshes the list of authorized projects' do
+ it "refreshes the list of authorized projects" do
expect(user.project_authorizations.count).to eq(2)
end
- it 'stores the correct access levels' do
+ it "stores the correct access levels" do
expect(user.project_authorizations.where(access_level: Gitlab::Access::GUEST).exists?).to eq(true)
expect(user.project_authorizations.where(access_level: Gitlab::Access::REPORTER).exists?).to eq(true)
end
end
- describe '#access_level=' do
+ describe "#access_level=" do
let(:user) { build(:user) }
- it 'does nothing for an invalid access level' do
+ it "does nothing for an invalid access level" do
user.access_level = :invalid_access_level
expect(user.access_level).to eq(:regular)
@@ -2493,28 +2493,28 @@ describe User do
end
it "accepts string values in addition to symbols" do
- user.access_level = 'admin'
+ user.access_level = "admin"
expect(user.access_level).to eq(:admin)
expect(user.admin).to be true
end
end
- describe '#full_private_access?' do
- it 'returns false for regular user' do
+ describe "#full_private_access?" do
+ it "returns false for regular user" do
user = build(:user)
expect(user.full_private_access?).to be_falsy
end
- it 'returns true for admin user' do
+ it "returns true for admin user" do
user = build(:user, :admin)
expect(user.full_private_access?).to be_truthy
end
end
- describe '.ghost' do
+ describe ".ghost" do
it "creates a ghost user if one isn't already present" do
ghost = described_class.ghost
@@ -2525,48 +2525,48 @@ describe User do
end
it "does not create a second ghost user if one is already present" do
- expect do
+ expect {
described_class.ghost
described_class.ghost
- end.to change { described_class.count }.by(1)
+ }.to change { described_class.count }.by(1)
expect(described_class.ghost).to eq(described_class.ghost)
end
context "when a regular user exists with the username 'ghost'" do
it "creates a ghost user with a non-conflicting username" do
- create(:user, username: 'ghost')
+ create(:user, username: "ghost")
ghost = described_class.ghost
expect(ghost).to be_persisted
- expect(ghost.username).to eq('ghost1')
+ expect(ghost.username).to eq("ghost1")
end
end
context "when a regular user exists with the email 'ghost@example.com'" do
it "creates a ghost user with a non-conflicting email" do
- create(:user, email: 'ghost@example.com')
+ create(:user, email: "ghost@example.com")
ghost = described_class.ghost
expect(ghost).to be_persisted
- expect(ghost.email).to eq('ghost1@example.com')
+ expect(ghost.email).to eq("ghost1@example.com")
end
end
- context 'when a domain whitelist is in place' do
+ context "when a domain whitelist is in place" do
before do
- stub_application_setting(domain_whitelist: ['gitlab.com'])
+ stub_application_setting(domain_whitelist: ["gitlab.com"])
end
- it 'creates a ghost user' do
+ it "creates a ghost user" do
expect(described_class.ghost).to be_persisted
end
end
end
- describe '#update_two_factor_requirement' do
+ describe "#update_two_factor_requirement" do
let(:user) { create :user }
- context 'with 2FA requirement on groups' do
+ context "with 2FA requirement on groups" do
let(:group1) { create :group, require_two_factor_authentication: true, two_factor_grace_period: 23 }
let(:group2) { create :group, require_two_factor_authentication: true, two_factor_grace_period: 32 }
@@ -2577,16 +2577,16 @@ describe User do
user.update_two_factor_requirement
end
- it 'requires 2FA' do
+ it "requires 2FA" do
expect(user.require_two_factor_authentication_from_group).to be true
end
- it 'uses the shortest grace period' do
+ it "uses the shortest grace period" do
expect(user.two_factor_grace_period).to be 23
end
end
- context 'with 2FA requirement on nested parent group', :nested_groups do
+ context "with 2FA requirement on nested parent group", :nested_groups do
let!(:group1) { create :group, require_two_factor_authentication: true }
let!(:group1a) { create :group, require_two_factor_authentication: false, parent: group1 }
@@ -2596,12 +2596,12 @@ describe User do
user.update_two_factor_requirement
end
- it 'requires 2FA' do
+ it "requires 2FA" do
expect(user.require_two_factor_authentication_from_group).to be true
end
end
- context 'with 2FA requirement on nested child group', :nested_groups do
+ context "with 2FA requirement on nested child group", :nested_groups do
let!(:group1) { create :group, require_two_factor_authentication: false }
let!(:group1a) { create :group, require_two_factor_authentication: true, parent: group1 }
@@ -2611,12 +2611,12 @@ describe User do
user.update_two_factor_requirement
end
- it 'requires 2FA' do
+ it "requires 2FA" do
expect(user.require_two_factor_authentication_from_group).to be true
end
end
- context 'without 2FA requirement on groups' do
+ context "without 2FA requirement on groups" do
let(:group) { create :group }
before do
@@ -2625,43 +2625,43 @@ describe User do
user.update_two_factor_requirement
end
- it 'does not require 2FA' do
+ it "does not require 2FA" do
expect(user.require_two_factor_authentication_from_group).to be false
end
- it 'falls back to the default grace period' do
+ it "falls back to the default grace period" do
expect(user.two_factor_grace_period).to be 48
end
end
end
- context '.active' do
+ context ".active" do
before do
described_class.ghost
- create(:user, name: 'user', state: 'active')
- create(:user, name: 'user', state: 'blocked')
+ create(:user, name: "user", state: "active")
+ create(:user, name: "user", state: "blocked")
end
- it 'only counts active and non internal users' do
+ it "only counts active and non internal users" do
expect(described_class.active.count).to eq(1)
end
end
- describe 'preferred language' do
- it 'is English by default' do
+ describe "preferred language" do
+ it "is English by default" do
user = create(:user)
- expect(user.preferred_language).to eq('en')
+ expect(user.preferred_language).to eq("en")
end
end
- context '#invalidate_issue_cache_counts' do
+ context "#invalidate_issue_cache_counts" do
let(:user) { build_stubbed(:user) }
- it 'invalidates cache for issue counter' do
+ it "invalidates cache for issue counter" do
cache_mock = double
- expect(cache_mock).to receive(:delete).with(['users', user.id, 'assigned_open_issues_count'])
+ expect(cache_mock).to receive(:delete).with(["users", user.id, "assigned_open_issues_count"])
allow(Rails).to receive(:cache).and_return(cache_mock)
@@ -2669,13 +2669,13 @@ describe User do
end
end
- context '#invalidate_merge_request_cache_counts' do
+ context "#invalidate_merge_request_cache_counts" do
let(:user) { build_stubbed(:user) }
- it 'invalidates cache for Merge Request counter' do
+ it "invalidates cache for Merge Request counter" do
cache_mock = double
- expect(cache_mock).to receive(:delete).with(['users', user.id, 'assigned_open_merge_requests_count'])
+ expect(cache_mock).to receive(:delete).with(["users", user.id, "assigned_open_merge_requests_count"])
allow(Rails).to receive(:cache).and_return(cache_mock)
@@ -2683,13 +2683,13 @@ describe User do
end
end
- context '#invalidate_personal_projects_count' do
+ context "#invalidate_personal_projects_count" do
let(:user) { build_stubbed(:user) }
- it 'invalidates cache for personal projects counter' do
+ it "invalidates cache for personal projects counter" do
cache_mock = double
- expect(cache_mock).to receive(:delete).with(['users', user.id, 'personal_projects_count'])
+ expect(cache_mock).to receive(:delete).with(["users", user.id, "personal_projects_count"])
allow(Rails).to receive(:cache).and_return(cache_mock)
@@ -2697,52 +2697,52 @@ describe User do
end
end
- describe '#allow_password_authentication_for_web?' do
- context 'regular user' do
+ describe "#allow_password_authentication_for_web?" do
+ context "regular user" do
let(:user) { build(:user) }
- it 'returns true when password authentication is enabled for the web interface' do
+ it "returns true when password authentication is enabled for the web interface" do
expect(user.allow_password_authentication_for_web?).to be_truthy
end
- it 'returns false when password authentication is disabled for the web interface' do
+ it "returns false when password authentication is disabled for the web interface" do
stub_application_setting(password_authentication_enabled_for_web: false)
expect(user.allow_password_authentication_for_web?).to be_falsey
end
end
- it 'returns false for ldap user' do
- user = create(:omniauth_user, provider: 'ldapmain')
+ it "returns false for ldap user" do
+ user = create(:omniauth_user, provider: "ldapmain")
expect(user.allow_password_authentication_for_web?).to be_falsey
end
end
- describe '#allow_password_authentication_for_git?' do
- context 'regular user' do
+ describe "#allow_password_authentication_for_git?" do
+ context "regular user" do
let(:user) { build(:user) }
- it 'returns true when password authentication is enabled for Git' do
+ it "returns true when password authentication is enabled for Git" do
expect(user.allow_password_authentication_for_git?).to be_truthy
end
- it 'returns false when password authentication is disabled Git' do
+ it "returns false when password authentication is disabled Git" do
stub_application_setting(password_authentication_enabled_for_git: false)
expect(user.allow_password_authentication_for_git?).to be_falsey
end
end
- it 'returns false for ldap user' do
- user = create(:omniauth_user, provider: 'ldapmain')
+ it "returns false for ldap user" do
+ user = create(:omniauth_user, provider: "ldapmain")
expect(user.allow_password_authentication_for_git?).to be_falsey
end
end
- describe '#assigned_open_merge_requests_count' do
- it 'returns number of open merge requests from non-archived projects' do
+ describe "#assigned_open_merge_requests_count" do
+ it "returns number of open merge requests from non-archived projects" do
user = create(:user)
project = create(:project, :public)
archived_project = create(:project, :public, :archived)
@@ -2755,8 +2755,8 @@ describe User do
end
end
- describe '#assigned_open_issues_count' do
- it 'returns number of open issues from non-archived projects' do
+ describe "#assigned_open_issues_count" do
+ it "returns number of open issues from non-archived projects" do
user = create(:user)
project = create(:project, :public)
archived_project = create(:project, :public, :archived)
@@ -2769,8 +2769,8 @@ describe User do
end
end
- describe '#personal_projects_count' do
- it 'returns the number of personal projects using a single query' do
+ describe "#personal_projects_count" do
+ it "returns the number of personal projects using a single query" do
user = build(:user)
projects = double(:projects, count: 1)
@@ -2780,8 +2780,8 @@ describe User do
end
end
- describe '#projects_limit_left' do
- it 'returns the number of projects that can be created by the user' do
+ describe "#projects_limit_left" do
+ it "returns the number of projects that can be created by the user" do
user = build(:user)
allow(user).to receive(:projects_limit).and_return(10)
@@ -2791,11 +2791,11 @@ describe User do
end
end
- describe '#ensure_namespace_correct' do
- context 'for a new user' do
+ describe "#ensure_namespace_correct" do
+ context "for a new user" do
let(:user) { build(:user) }
- it 'creates the namespace' do
+ it "creates the namespace" do
expect(user.namespace).to be_nil
user.save!
@@ -2804,79 +2804,79 @@ describe User do
end
end
- context 'for an existing user' do
- let(:username) { 'foo' }
+ context "for an existing user" do
+ let(:username) { "foo" }
let(:user) { create(:user, username: username) }
- context 'when the user is updated' do
- context 'when the username is changed' do
- let(:new_username) { 'bar' }
+ context "when the user is updated" do
+ context "when the username is changed" do
+ let(:new_username) { "bar" }
- it 'changes the namespace (just to compare to when username is not changed)' do
- expect do
+ it "changes the namespace (just to compare to when username is not changed)" do
+ expect {
Timecop.freeze(1.second.from_now) do
user.update!(username: new_username)
end
- end.to change { user.namespace.updated_at }
+ }.to change { user.namespace.updated_at }
end
- it 'updates the namespace name' do
+ it "updates the namespace name" do
user.update!(username: new_username)
expect(user.namespace.name).to eq(new_username)
end
- it 'updates the namespace path' do
+ it "updates the namespace path" do
user.update!(username: new_username)
expect(user.namespace.path).to eq(new_username)
end
- context 'when there is a validation error (namespace name taken) while updating namespace' do
+ context "when there is a validation error (namespace name taken) while updating namespace" do
let!(:conflicting_namespace) { create(:group, path: new_username) }
- it 'causes the user save to fail' do
+ it "causes the user save to fail" do
expect(user.update(username: new_username)).to be_falsey
- expect(user.namespace.errors.messages[:path].first).to eq('has already been taken')
+ expect(user.namespace.errors.messages[:path].first).to eq("has already been taken")
end
- it 'adds the namespace errors to the user' do
+ it "adds the namespace errors to the user" do
user.update(username: new_username)
- expect(user.errors.full_messages.first).to eq('Username has already been taken')
+ expect(user.errors.full_messages.first).to eq("Username has already been taken")
end
end
end
- context 'when the username is not changed' do
- it 'does not change the namespace' do
- expect do
- user.update!(email: 'asdf@asdf.com')
- end.not_to change { user.namespace.updated_at }
+ context "when the username is not changed" do
+ it "does not change the namespace" do
+ expect {
+ user.update!(email: "asdf@asdf.com")
+ }.not_to change { user.namespace.updated_at }
end
end
end
end
end
- describe '#username_changed_hook' do
- context 'for a new user' do
+ describe "#username_changed_hook" do
+ context "for a new user" do
let(:user) { build(:user) }
- it 'does not trigger system hook' do
+ it "does not trigger system hook" do
expect(user).not_to receive(:system_hook_service)
user.save!
end
end
- context 'for an existing user' do
- let(:user) { create(:user, username: 'old-username') }
+ context "for an existing user" do
+ let(:user) { create(:user, username: "old-username") }
- context 'when the username is changed' do
- let(:new_username) { 'very-new-name' }
+ context "when the username is changed" do
+ let(:new_username) { "very-new-name" }
- it 'triggers the rename system hook' do
+ it "triggers the rename system hook" do
system_hook_service = SystemHooksService.new
expect(system_hook_service).to receive(:execute_hooks_for).with(user, :rename)
expect(user).to receive(:system_hook_service).and_return(system_hook_service)
@@ -2885,57 +2885,57 @@ describe User do
end
end
- context 'when the username is not changed' do
- it 'does not trigger system hook' do
+ context "when the username is not changed" do
+ it "does not trigger system hook" do
expect(user).not_to receive(:system_hook_service)
- user.update!(email: 'asdf@asdf.com')
+ user.update!(email: "asdf@asdf.com")
end
end
end
end
- describe '#sync_attribute?' do
+ describe "#sync_attribute?" do
let(:user) { described_class.new }
- context 'oauth user' do
- it 'returns true if name can be synced' do
- stub_omniauth_setting(sync_profile_attributes: %w(name location))
+ context "oauth user" do
+ it "returns true if name can be synced" do
+ stub_omniauth_setting(sync_profile_attributes: %w[name location])
expect(user.sync_attribute?(:name)).to be_truthy
end
- it 'returns true if email can be synced' do
- stub_omniauth_setting(sync_profile_attributes: %w(name email))
+ it "returns true if email can be synced" do
+ stub_omniauth_setting(sync_profile_attributes: %w[name email])
expect(user.sync_attribute?(:email)).to be_truthy
end
- it 'returns true if location can be synced' do
- stub_omniauth_setting(sync_profile_attributes: %w(location email))
+ it "returns true if location can be synced" do
+ stub_omniauth_setting(sync_profile_attributes: %w[location email])
expect(user.sync_attribute?(:email)).to be_truthy
end
- it 'returns false if name can not be synced' do
- stub_omniauth_setting(sync_profile_attributes: %w(location email))
+ it "returns false if name can not be synced" do
+ stub_omniauth_setting(sync_profile_attributes: %w[location email])
expect(user.sync_attribute?(:name)).to be_falsey
end
- it 'returns false if email can not be synced' do
- stub_omniauth_setting(sync_profile_attributes: %w(location email))
+ it "returns false if email can not be synced" do
+ stub_omniauth_setting(sync_profile_attributes: %w[location email])
expect(user.sync_attribute?(:name)).to be_falsey
end
- it 'returns false if location can not be synced' do
- stub_omniauth_setting(sync_profile_attributes: %w(location email))
+ it "returns false if location can not be synced" do
+ stub_omniauth_setting(sync_profile_attributes: %w[location email])
expect(user.sync_attribute?(:name)).to be_falsey
end
- it 'returns true for all syncable attributes if all syncable attributes can be synced' do
+ it "returns true for all syncable attributes if all syncable attributes can be synced" do
stub_omniauth_setting(sync_profile_attributes: true)
expect(user.sync_attribute?(:name)).to be_truthy
@@ -2943,15 +2943,15 @@ describe User do
expect(user.sync_attribute?(:location)).to be_truthy
end
- it 'returns false for all syncable attributes but email if no syncable attributes are declared' do
+ it "returns false for all syncable attributes but email if no syncable attributes are declared" do
expect(user.sync_attribute?(:name)).to be_falsey
expect(user.sync_attribute?(:email)).to be_truthy
expect(user.sync_attribute?(:location)).to be_falsey
end
end
- context 'ldap user' do
- it 'returns true for email if ldap user' do
+ context "ldap user" do
+ it "returns true for email if ldap user" do
allow(user).to receive(:ldap_user?).and_return(true)
expect(user.sync_attribute?(:name)).to be_falsey
@@ -2959,9 +2959,9 @@ describe User do
expect(user.sync_attribute?(:location)).to be_falsey
end
- it 'returns true for email and location if ldap user and location declared as syncable' do
+ it "returns true for email and location if ldap user and location declared as syncable" do
allow(user).to receive(:ldap_user?).and_return(true)
- stub_omniauth_setting(sync_profile_attributes: %w(location))
+ stub_omniauth_setting(sync_profile_attributes: %w[location])
expect(user.sync_attribute?(:name)).to be_falsey
expect(user.sync_attribute?(:email)).to be_truthy
@@ -2970,7 +2970,7 @@ describe User do
end
end
- describe '#confirm_deletion_with_password?' do
+ describe "#confirm_deletion_with_password?" do
where(
password_automatically_set: [true, false],
ldap_user: [true, false],
@@ -2989,25 +2989,25 @@ describe User do
stub_application_setting(password_authentication_enabled_for_git: !password_authentication_disabled)
end
- it 'returns false unless all inputs are true' do
+ it "returns false unless all inputs are true" do
expect(user.confirm_deletion_with_password?).to eq(expected)
end
end
end
- describe '#delete_async' do
+ describe "#delete_async" do
let(:user) { create(:user) }
let(:deleted_by) { create(:user) }
- it 'blocks the user then schedules them for deletion if a hard delete is specified' do
+ it "blocks the user then schedules them for deletion if a hard delete is specified" do
expect(DeleteUserWorker).to receive(:perform_async).with(deleted_by.id, user.id, hard_delete: true)
- user.delete_async(deleted_by: deleted_by, params: { hard_delete: true })
+ user.delete_async(deleted_by: deleted_by, params: {hard_delete: true})
expect(user).to be_blocked
end
- it 'schedules user for deletion without blocking them' do
+ it "schedules user for deletion without blocking them" do
expect(DeleteUserWorker).to receive(:perform_async).with(deleted_by.id, user.id, {})
user.delete_async(deleted_by: deleted_by)
@@ -3016,8 +3016,8 @@ describe User do
end
end
- describe '#max_member_access_for_project_ids' do
- shared_examples 'max member access for projects' do
+ describe "#max_member_access_for_project_ids" do
+ shared_examples "max member access for projects" do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:owner_project) { create(:project, group: group) }
@@ -3038,7 +3038,7 @@ describe User do
reporter_project.id => Gitlab::Access::REPORTER,
developer_project.id => Gitlab::Access::DEVELOPER,
guest_project.id => Gitlab::Access::GUEST,
- no_access_project.id => Gitlab::Access::NO_ACCESS
+ no_access_project.id => Gitlab::Access::NO_ACCESS,
}
end
@@ -3050,19 +3050,19 @@ describe User do
guest_project.add_guest(user)
end
- it 'returns correct roles for different projects' do
+ it "returns correct roles for different projects" do
expect(user.max_member_access_for_project_ids(projects)).to eq(expected)
end
end
- context 'with RequestStore enabled', :request_store do
- include_examples 'max member access for projects'
+ context "with RequestStore enabled", :request_store do
+ include_examples "max member access for projects"
def access_levels(projects)
user.max_member_access_for_project_ids(projects)
end
- it 'does not perform extra queries when asked for projects who have already been found' do
+ it "does not perform extra queries when asked for projects who have already been found" do
access_levels(projects)
expect { access_levels(projects) }.not_to exceed_query_limit(0)
@@ -3070,7 +3070,7 @@ describe User do
expect(access_levels(projects)).to eq(expected)
end
- it 'only requests the extra projects when uncached projects are passed' do
+ it "only requests the extra projects when uncached projects are passed" do
second_maintainer_project = create(:project)
second_developer_project = create(:project)
second_maintainer_project.add_maintainer(user)
@@ -3091,13 +3091,13 @@ describe User do
end
end
- context 'with RequestStore disabled' do
- include_examples 'max member access for projects'
+ context "with RequestStore disabled" do
+ include_examples "max member access for projects"
end
end
- describe '#max_member_access_for_group_ids' do
- shared_examples 'max member access for groups' do
+ describe "#max_member_access_for_group_ids" do
+ shared_examples "max member access for groups" do
let(:user) { create(:user) }
let(:owner_group) { create(:group) }
let(:maintainer_group) { create(:group) }
@@ -3117,7 +3117,7 @@ describe User do
reporter_group.id => Gitlab::Access::REPORTER,
developer_group.id => Gitlab::Access::DEVELOPER,
guest_group.id => Gitlab::Access::GUEST,
- no_access_group.id => Gitlab::Access::NO_ACCESS
+ no_access_group.id => Gitlab::Access::NO_ACCESS,
}
end
@@ -3129,19 +3129,19 @@ describe User do
guest_group.add_guest(user)
end
- it 'returns correct roles for different groups' do
+ it "returns correct roles for different groups" do
expect(user.max_member_access_for_group_ids(groups)).to eq(expected)
end
end
- context 'with RequestStore enabled', :request_store do
- include_examples 'max member access for groups'
+ context "with RequestStore enabled", :request_store do
+ include_examples "max member access for groups"
def access_levels(groups)
user.max_member_access_for_group_ids(groups)
end
- it 'does not perform extra queries when asked for groups who have already been found' do
+ it "does not perform extra queries when asked for groups who have already been found" do
access_levels(groups)
expect { access_levels(groups) }.not_to exceed_query_limit(0)
@@ -3149,7 +3149,7 @@ describe User do
expect(access_levels(groups)).to eq(expected)
end
- it 'only requests the extra groups when uncached groups are passed' do
+ it "only requests the extra groups when uncached groups are passed" do
second_maintainer_group = create(:group)
second_developer_group = create(:group)
second_maintainer_group.add_maintainer(user)
@@ -3170,28 +3170,28 @@ describe User do
end
end
- context 'with RequestStore disabled' do
- include_examples 'max member access for groups'
+ context "with RequestStore disabled" do
+ include_examples "max member access for groups"
end
end
- context 'changing a username' do
- let(:user) { create(:user, username: 'foo') }
+ context "changing a username" do
+ let(:user) { create(:user, username: "foo") }
- it 'creates a redirect route' do
- expect { user.update!(username: 'bar') }
- .to change { RedirectRoute.where(path: 'foo').count }.by(1)
+ it "creates a redirect route" do
+ expect { user.update!(username: "bar") }
+ .to change { RedirectRoute.where(path: "foo").count }.by(1)
end
- it 'deletes the redirect when a user with the old username was created' do
- user.update!(username: 'bar')
+ it "deletes the redirect when a user with the old username was created" do
+ user.update!(username: "bar")
- expect { create(:user, username: 'foo') }
- .to change { RedirectRoute.where(path: 'foo').count }.by(-1)
+ expect { create(:user, username: "foo") }
+ .to change { RedirectRoute.where(path: "foo").count }.by(-1)
end
end
- describe '#required_terms_not_accepted?' do
+ describe "#required_terms_not_accepted?" do
let(:user) { build(:user) }
subject { user.required_terms_not_accepted? }
@@ -3217,81 +3217,81 @@ describe User do
end
end
- describe '#increment_failed_attempts!' do
+ describe "#increment_failed_attempts!" do
subject(:user) { create(:user, failed_attempts: 0) }
- it 'logs failed sign-in attempts' do
+ it "logs failed sign-in attempts" do
expect { user.increment_failed_attempts! }.to change(user, :failed_attempts).from(0).to(1)
end
- it 'does not log failed sign-in attempts when in a GitLab read-only instance' do
+ it "does not log failed sign-in attempts when in a GitLab read-only instance" do
allow(Gitlab::Database).to receive(:read_only?) { true }
expect { user.increment_failed_attempts! }.not_to change(user, :failed_attempts)
end
end
- describe '#requires_usage_stats_consent?' do
+ describe "#requires_usage_stats_consent?" do
let(:user) { create(:user, created_at: 8.days.ago) }
before do
allow(user).to receive(:has_current_license?).and_return false
end
- context 'in single-user environment' do
- it 'requires user consent after one week' do
+ context "in single-user environment" do
+ it "requires user consent after one week" do
create(:user, ghost: true)
expect(user.requires_usage_stats_consent?).to be true
end
- it 'requires user consent after one week if there is another ghost user' do
+ it "requires user consent after one week if there is another ghost user" do
expect(user.requires_usage_stats_consent?).to be true
end
- it 'does not require consent in the first week' do
+ it "does not require consent in the first week" do
user.created_at = 6.days.ago
expect(user.requires_usage_stats_consent?).to be false
end
- it 'does not require consent if usage stats were set by this user' do
+ it "does not require consent if usage stats were set by this user" do
allow(Gitlab::CurrentSettings).to receive(:usage_stats_set_by_user_id).and_return(user.id)
expect(user.requires_usage_stats_consent?).to be false
end
end
- context 'in multi-user environment' do
+ context "in multi-user environment" do
before do
create(:user)
end
- it 'does not require consent' do
+ it "does not require consent" do
expect(user.requires_usage_stats_consent?).to be false
end
end
end
- context 'with uploads' do
- it_behaves_like 'model with uploads', false do
+ context "with uploads" do
+ it_behaves_like "model with uploads", false do
let(:model_object) { create(:user, :with_avatar) }
let(:upload_attribute) { :avatar }
let(:uploader_class) { AttachmentUploader }
end
end
- describe '.union_with_user' do
- context 'when no user ID is provided' do
- it 'returns the input relation' do
+ describe ".union_with_user" do
+ context "when no user ID is provided" do
+ it "returns the input relation" do
user = create(:user)
expect(described_class.union_with_user).to eq([user])
end
end
- context 'when a user ID is provided' do
- it 'includes the user object in the returned relation' do
+ context "when a user ID is provided" do
+ it "includes the user object in the returned relation" do
user1 = create(:user)
user2 = create(:user)
users = described_class.where(id: user1.id).union_with_user(user2.id)
@@ -3300,7 +3300,7 @@ describe User do
expect(users).to include(user2)
end
- it 'does not re-apply any WHERE conditions on the outer query' do
+ it "does not re-apply any WHERE conditions on the outer query" do
relation = described_class.where(id: 1).union_with_user(2)
expect(relation.arel.where_sql).to be_nil
@@ -3308,25 +3308,25 @@ describe User do
end
end
- describe '.optionally_search' do
- context 'using nil as the argument' do
- it 'returns the current relation' do
+ describe ".optionally_search" do
+ context "using nil as the argument" do
+ it "returns the current relation" do
user = create(:user)
expect(described_class.optionally_search).to eq([user])
end
end
- context 'using an empty String as the argument' do
- it 'returns the current relation' do
+ context "using an empty String as the argument" do
+ it "returns the current relation" do
user = create(:user)
- expect(described_class.optionally_search('')).to eq([user])
+ expect(described_class.optionally_search("")).to eq([user])
end
end
- context 'using a non-empty String' do
- it 'returns users matching the search query' do
+ context "using a non-empty String" do
+ it "returns users matching the search query" do
user1 = create(:user)
create(:user)
@@ -3335,17 +3335,17 @@ describe User do
end
end
- describe '.where_not_in' do
- context 'without an argument' do
- it 'returns the current relation' do
+ describe ".where_not_in" do
+ context "without an argument" do
+ it "returns the current relation" do
user = create(:user)
expect(described_class.where_not_in).to eq([user])
end
end
- context 'using a list of user IDs' do
- it 'excludes the users from the returned relation' do
+ context "using a list of user IDs" do
+ it "excludes the users from the returned relation" do
user1 = create(:user)
user2 = create(:user)
@@ -3354,10 +3354,10 @@ describe User do
end
end
- describe '.reorder_by_name' do
- it 'reorders the input relation' do
- user1 = create(:user, name: 'A')
- user2 = create(:user, name: 'B')
+ describe ".reorder_by_name" do
+ it "reorders the input relation" do
+ user1 = create(:user, name: "A")
+ user2 = create(:user, name: "B")
expect(described_class.reorder_by_name).to eq([user1, user2])
end
diff --git a/spec/models/user_status_spec.rb b/spec/models/user_status_spec.rb
index fcc01cdae3d..b6f44d56e1f 100644
--- a/spec/models/user_status_spec.rb
+++ b/spec/models/user_status_spec.rb
@@ -1,18 +1,18 @@
# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe UserStatus do
it { is_expected.to validate_presence_of(:user) }
- it { is_expected.to allow_value('smirk').for(:emoji) }
- it { is_expected.not_to allow_value('hello world').for(:emoji) }
- it { is_expected.not_to allow_value('').for(:emoji) }
+ it { is_expected.to allow_value("smirk").for(:emoji) }
+ it { is_expected.not_to allow_value("hello world").for(:emoji) }
+ it { is_expected.not_to allow_value("").for(:emoji) }
it { is_expected.to validate_length_of(:message).is_at_most(100) }
- it { is_expected.to allow_value('').for(:message) }
+ it { is_expected.to allow_value("").for(:message) }
- it 'is expected to be deleted when the user is deleted' do
+ it "is expected to be deleted when the user is deleted" do
status = create(:user_status)
expect { status.user.destroy }.to change { described_class.count }.from(1).to(0)
diff --git a/spec/models/wiki_directory_spec.rb b/spec/models/wiki_directory_spec.rb
index fb8575cfe2b..c3bbf879674 100644
--- a/spec/models/wiki_directory_spec.rb
+++ b/spec/models/wiki_directory_spec.rb
@@ -1,44 +1,44 @@
-require 'spec_helper'
+require "spec_helper"
RSpec.describe WikiDirectory do
- describe 'validations' do
+ describe "validations" do
subject { build(:wiki_directory) }
it { is_expected.to validate_presence_of(:slug) }
end
- describe '#initialize' do
- context 'when there are pages' do
+ describe "#initialize" do
+ context "when there are pages" do
let(:pages) { [build(:wiki_page)] }
- let(:directory) { described_class.new('/path_up_to/dir', pages) }
+ let(:directory) { described_class.new("/path_up_to/dir", pages) }
- it 'sets the slug attribute' do
- expect(directory.slug).to eq('/path_up_to/dir')
+ it "sets the slug attribute" do
+ expect(directory.slug).to eq("/path_up_to/dir")
end
- it 'sets the pages attribute' do
+ it "sets the pages attribute" do
expect(directory.pages).to eq(pages)
end
end
- context 'when there are no pages' do
- let(:directory) { described_class.new('/path_up_to/dir') }
+ context "when there are no pages" do
+ let(:directory) { described_class.new("/path_up_to/dir") }
- it 'sets the slug attribute' do
- expect(directory.slug).to eq('/path_up_to/dir')
+ it "sets the slug attribute" do
+ expect(directory.slug).to eq("/path_up_to/dir")
end
- it 'sets the pages attribute to an empty array' do
+ it "sets the pages attribute to an empty array" do
expect(directory.pages).to eq([])
end
end
end
- describe '#to_partial_path' do
- it 'returns the relative path to the partial to be used' do
+ describe "#to_partial_path" do
+ it "returns the relative path to the partial to be used" do
directory = build(:wiki_directory)
- expect(directory.to_partial_path).to eq('projects/wikis/wiki_directory')
+ expect(directory.to_partial_path).to eq("projects/wikis/wiki_directory")
end
end
end
diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb
index cba22b2cc4e..93389ef0665 100644
--- a/spec/models/wiki_page_spec.rb
+++ b/spec/models/wiki_page_spec.rb
@@ -7,36 +7,36 @@ describe WikiPage do
subject { described_class.new(wiki) }
- describe '.group_by_directory' do
- context 'when there are no pages' do
- it 'returns an empty array' do
+ describe ".group_by_directory" do
+ context "when there are no pages" do
+ it "returns an empty array" do
expect(described_class.group_by_directory(nil)).to eq([])
expect(described_class.group_by_directory([])).to eq([])
end
end
- context 'when there are pages' do
+ context "when there are pages" do
before do
- create_page('dir_1/dir_1_1/page_3', 'content')
- create_page('dir_1/page_2', 'content')
- create_page('dir_2/page_5', 'content')
- create_page('dir_2/page_4', 'content')
- create_page('page_1', 'content')
+ create_page("dir_1/dir_1_1/page_3", "content")
+ create_page("dir_1/page_2", "content")
+ create_page("dir_2/page_5", "content")
+ create_page("dir_2/page_4", "content")
+ create_page("page_1", "content")
end
- let(:page_1) { wiki.find_page('page_1') }
+ let(:page_1) { wiki.find_page("page_1") }
let(:dir_1) do
- WikiDirectory.new('dir_1', [wiki.find_page('dir_1/page_2')])
+ WikiDirectory.new("dir_1", [wiki.find_page("dir_1/page_2")])
end
let(:dir_1_1) do
- WikiDirectory.new('dir_1/dir_1_1', [wiki.find_page('dir_1/dir_1_1/page_3')])
+ WikiDirectory.new("dir_1/dir_1_1", [wiki.find_page("dir_1/dir_1_1/page_3")])
end
let(:dir_2) do
- pages = [wiki.find_page('dir_2/page_5'),
- wiki.find_page('dir_2/page_4')]
- WikiDirectory.new('dir_2', pages)
+ pages = [wiki.find_page("dir_2/page_5"),
+ wiki.find_page("dir_2/page_4"),]
+ WikiDirectory.new("dir_2", pages)
end
- it 'returns an array with pages and directories' do
+ it "returns an array with pages and directories" do
expected_grouped_entries = [page_1, dir_1, dir_1_1, dir_2]
grouped_entries = described_class.group_by_directory(wiki.pages)
@@ -50,29 +50,29 @@ describe WikiPage do
end
end
- it 'returns an array sorted by alphabetical position' do
+ it "returns an array sorted by alphabetical position" do
# Directories and pages within directories are sorted alphabetically.
# Pages at root come before everything.
- expected_order = ['page_1', 'dir_1/page_2', 'dir_1/dir_1_1/page_3',
- 'dir_2/page_4', 'dir_2/page_5']
+ expected_order = ["page_1", "dir_1/page_2", "dir_1/dir_1_1/page_3",
+ "dir_2/page_4", "dir_2/page_5",]
grouped_entries = described_class.group_by_directory(wiki.pages)
actual_order =
- grouped_entries.map do |page_or_dir|
+ grouped_entries.map { |page_or_dir|
get_slugs(page_or_dir)
- end
- .flatten
+ }
+ .flatten
expect(actual_order).to eq(expected_order)
end
end
end
- describe '.unhyphenize' do
- it 'removes hyphens from a name' do
- name = 'a-name--with-hyphens'
+ describe ".unhyphenize" do
+ it "removes hyphens from a name" do
+ name = "a-name--with-hyphens"
- expect(described_class.unhyphenize(name)).to eq('a name with hyphens')
+ expect(described_class.unhyphenize(name)).to eq("a name with hyphens")
end
end
@@ -112,7 +112,7 @@ describe WikiPage do
describe "validations" do
before do
- subject.attributes = { title: 'title', content: 'content' }
+ subject.attributes = {title: "title", content: "content"}
end
it "validates presence of title" do
@@ -132,7 +132,7 @@ describe WikiPage do
title: "Index",
content: "Home Page",
format: "markdown",
- message: 'Custom Commit Message'
+ message: "Custom Commit Message",
}
end
@@ -150,19 +150,19 @@ describe WikiPage do
expect(subject.create(wiki_attr)).to eq(true)
end
- it 'saves the wiki page with message' do
+ it "saves the wiki page with message" do
subject.create(wiki_attr)
- expect(wiki.find_page("Index").message).to eq 'Custom Commit Message'
+ expect(wiki.find_page("Index").message).to eq "Custom Commit Message"
end
end
end
describe "dot in the title" do
- let(:title) { 'Index v1.2.3' }
+ let(:title) { "Index v1.2.3" }
before do
- @wiki_attr = { title: title, content: "Home Page", format: "markdown" }
+ @wiki_attr = {title: title, content: "Home Page", format: "markdown"}
end
describe "#create" do
@@ -199,24 +199,24 @@ describe WikiPage do
end
end
- describe '#create' do
- context 'with valid attributes' do
- it 'raises an error if a page with the same path already exists' do
- create_page('New Page', 'content')
- create_page('foo/bar', 'content')
- expect { create_page('New Page', 'other content') }.to raise_error Gitlab::Git::Wiki::DuplicatePageError
- expect { create_page('foo/bar', 'other content') }.to raise_error Gitlab::Git::Wiki::DuplicatePageError
+ describe "#create" do
+ context "with valid attributes" do
+ it "raises an error if a page with the same path already exists" do
+ create_page("New Page", "content")
+ create_page("foo/bar", "content")
+ expect { create_page("New Page", "other content") }.to raise_error Gitlab::Git::Wiki::DuplicatePageError
+ expect { create_page("foo/bar", "other content") }.to raise_error Gitlab::Git::Wiki::DuplicatePageError
- destroy_page('New Page')
- destroy_page('bar', 'foo')
+ destroy_page("New Page")
+ destroy_page("bar", "foo")
end
- it 'if the title is preceded by a / it is removed' do
- create_page('/New Page', 'content')
+ it "if the title is preceded by a / it is removed" do
+ create_page("/New Page", "content")
- expect(wiki.find_page('New Page')).not_to be_nil
+ expect(wiki.find_page("New Page")).not_to be_nil
- destroy_page('New Page')
+ destroy_page("New Page")
end
end
end
@@ -255,32 +255,32 @@ describe WikiPage do
end
end
- context 'with same last commit sha' do
- it 'returns true' do
- expect(@page.update(content: 'more content', last_commit_sha: @page.last_commit_sha)).to be_truthy
+ context "with same last commit sha" do
+ it "returns true" do
+ expect(@page.update(content: "more content", last_commit_sha: @page.last_commit_sha)).to be_truthy
end
end
- context 'with different last commit sha' do
- it 'raises exception' do
- expect { @page.update(content: 'more content', last_commit_sha: 'xxx') }.to raise_error(WikiPage::PageChangedError)
+ context "with different last commit sha" do
+ it "raises exception" do
+ expect { @page.update(content: "more content", last_commit_sha: "xxx") }.to raise_error(WikiPage::PageChangedError)
end
end
- context 'when renaming a page' do
- it 'raises an error if the page already exists' do
- create_page('Existing Page', 'content')
+ context "when renaming a page" do
+ it "raises an error if the page already exists" do
+ create_page("Existing Page", "content")
- expect { @page.update(title: 'Existing Page', content: 'new_content') }.to raise_error(WikiPage::PageRenameError)
- expect(@page.title).to eq 'Update'
- expect(@page.content).to eq 'new_content'
+ expect { @page.update(title: "Existing Page", content: "new_content") }.to raise_error(WikiPage::PageRenameError)
+ expect(@page.title).to eq "Update"
+ expect(@page.content).to eq "new_content"
- destroy_page('Existing Page')
+ destroy_page("Existing Page")
end
- it 'updates the content and rename the file' do
- new_title = 'Renamed Page'
- new_content = 'updated content'
+ it "updates the content and rename the file" do
+ new_title = "Renamed Page"
+ new_content = "updated content"
expect(@page.update(title: new_title, content: new_content)).to be_truthy
@@ -291,20 +291,20 @@ describe WikiPage do
end
end
- context 'when moving a page' do
- it 'raises an error if the page already exists' do
- create_page('foo/Existing Page', 'content')
+ context "when moving a page" do
+ it "raises an error if the page already exists" do
+ create_page("foo/Existing Page", "content")
- expect { @page.update(title: 'foo/Existing Page', content: 'new_content') }.to raise_error(WikiPage::PageRenameError)
- expect(@page.title).to eq 'Update'
- expect(@page.content).to eq 'new_content'
+ expect { @page.update(title: "foo/Existing Page", content: "new_content") }.to raise_error(WikiPage::PageRenameError)
+ expect(@page.title).to eq "Update"
+ expect(@page.content).to eq "new_content"
- destroy_page('Existing Page', 'foo')
+ destroy_page("Existing Page", "foo")
end
- it 'updates the content and moves the file' do
- new_title = 'foo/Other Page'
- new_content = 'new_content'
+ it "updates the content and moves the file" do
+ new_title = "foo/Other Page"
+ new_content = "new_content"
expect(@page.update(title: new_title, content: new_content)).to be_truthy
@@ -314,45 +314,45 @@ describe WikiPage do
expect(page.content).to eq new_content
end
- context 'in subdir' do
+ context "in subdir" do
before do
- create_page('foo/Existing Page', 'content')
- @page = wiki.find_page('foo/Existing Page')
+ create_page("foo/Existing Page", "content")
+ @page = wiki.find_page("foo/Existing Page")
end
- it 'moves the page to the root folder if the title is preceded by /' do
- expect(@page.slug).to eq 'foo/Existing-Page'
- expect(@page.update(title: '/Existing Page', content: 'new_content')).to be_truthy
- expect(@page.slug).to eq 'Existing-Page'
+ it "moves the page to the root folder if the title is preceded by /" do
+ expect(@page.slug).to eq "foo/Existing-Page"
+ expect(@page.update(title: "/Existing Page", content: "new_content")).to be_truthy
+ expect(@page.slug).to eq "Existing-Page"
end
- it 'does nothing if it has the same title' do
+ it "does nothing if it has the same title" do
original_path = @page.slug
- expect(@page.update(title: 'Existing Page', content: 'new_content')).to be_truthy
+ expect(@page.update(title: "Existing Page", content: "new_content")).to be_truthy
expect(@page.slug).to eq original_path
end
end
- context 'in root dir' do
- it 'does nothing if the title is preceded by /' do
+ context "in root dir" do
+ it "does nothing if the title is preceded by /" do
original_path = @page.slug
- expect(@page.update(title: '/Update', content: 'new_content')).to be_truthy
+ expect(@page.update(title: "/Update", content: "new_content")).to be_truthy
expect(@page.slug).to eq original_path
end
end
end
context "with invalid attributes" do
- it 'aborts update if title blank' do
- expect(@page.update(title: '', content: 'new_content')).to be_falsey
- expect(@page.content).to eq 'new_content'
+ it "aborts update if title blank" do
+ expect(@page.update(title: "", content: "new_content")).to be_falsey
+ expect(@page.content).to eq "new_content"
- page = wiki.find_page('Update')
- expect(page.content).to eq 'content'
+ page = wiki.find_page("Update")
+ expect(page.content).to eq "content"
- @page.title = 'Update'
+ @page.title = "Update"
end
end
end
@@ -390,8 +390,8 @@ describe WikiPage do
expect(page.versions.count).to eq(4)
end
- it 'returns instances of WikiPageVersion' do
- expect(page.versions).to all( be_a(Gitlab::Git::WikiPageVersion) )
+ it "returns instances of WikiPageVersion" do
+ expect(page.versions).to all(be_a(Gitlab::Git::WikiPageVersion))
end
end
@@ -410,97 +410,97 @@ describe WikiPage do
expect(@page.title).to eq("Import existing repositories into GitLab")
end
- it 'unescapes html' do
- @page.title = 'foo &amp; bar'
+ it "unescapes html" do
+ @page.title = "foo &amp; bar"
- expect(@page.title).to eq('foo & bar')
+ expect(@page.title).to eq("foo & bar")
end
end
- describe '#directory' do
- context 'when the page is at the root directory' do
- it 'returns an empty string' do
- create_page('file', 'content')
- page = wiki.find_page('file')
+ describe "#directory" do
+ context "when the page is at the root directory" do
+ it "returns an empty string" do
+ create_page("file", "content")
+ page = wiki.find_page("file")
- expect(page.directory).to eq('')
+ expect(page.directory).to eq("")
end
end
- context 'when the page is inside an actual directory' do
- it 'returns the full directory hierarchy' do
- create_page('dir_1/dir_1_1/file', 'content')
- page = wiki.find_page('dir_1/dir_1_1/file')
+ context "when the page is inside an actual directory" do
+ it "returns the full directory hierarchy" do
+ create_page("dir_1/dir_1_1/file", "content")
+ page = wiki.find_page("dir_1/dir_1_1/file")
- expect(page.directory).to eq('dir_1/dir_1_1')
+ expect(page.directory).to eq("dir_1/dir_1_1")
end
end
end
- describe '#historical?' do
- let(:page) { wiki.find_page('Update') }
+ describe "#historical?" do
+ let(:page) { wiki.find_page("Update") }
let(:old_version) { page.versions.last.id }
- let(:old_page) { wiki.find_page('Update', old_version) }
+ let(:old_page) { wiki.find_page("Update", old_version) }
let(:latest_version) { page.versions.first.id }
- let(:latest_page) { wiki.find_page('Update', latest_version) }
+ let(:latest_page) { wiki.find_page("Update", latest_version) }
before do
- create_page('Update', 'content')
- @page = wiki.find_page('Update')
+ create_page("Update", "content")
+ @page = wiki.find_page("Update")
3.times { |i| @page.update(content: "content #{i}") }
end
after do
- destroy_page('Update')
+ destroy_page("Update")
end
- it 'returns true when requesting an old version' do
+ it "returns true when requesting an old version" do
expect(old_page.historical?).to be_truthy
end
- it 'returns false when requesting latest version' do
+ it "returns false when requesting latest version" do
expect(latest_page.historical?).to be_falsy
end
- it 'returns false when version is nil' do
+ it "returns false when version is nil" do
expect(latest_page.historical?).to be_falsy
end
- it 'returns false when the last version is nil' do
+ it "returns false when the last version is nil" do
expect(old_page).to receive(:last_version) { nil }
expect(old_page.historical?).to be_falsy
end
- it 'returns false when the version is nil' do
+ it "returns false when the version is nil" do
expect(old_page).to receive(:version) { nil }
expect(old_page.historical?).to be_falsy
end
end
- describe '#to_partial_path' do
- it 'returns the relative path to the partial to be used' do
+ describe "#to_partial_path" do
+ it "returns the relative path to the partial to be used" do
page = build(:wiki_page)
- expect(page.to_partial_path).to eq('projects/wikis/wiki_page')
+ expect(page.to_partial_path).to eq("projects/wikis/wiki_page")
end
end
- describe '#==' do
+ describe "#==" do
let(:original_wiki_page) { create(:wiki_page) }
- it 'returns true for identical wiki page' do
+ it "returns true for identical wiki page" do
expect(original_wiki_page).to eq(original_wiki_page)
end
- it 'returns false for updated wiki page' do
+ it "returns false for updated wiki page" do
updated_wiki_page = original_wiki_page.update(content: "Updated content")
expect(original_wiki_page).not_to eq(updated_wiki_page)
end
end
- describe '#last_commit_sha' do
+ describe "#last_commit_sha" do
before do
create_page("Update", "content")
@page = wiki.find_page("Update")
@@ -510,11 +510,11 @@ describe WikiPage do
destroy_page("Update")
end
- it 'returns commit sha' do
+ it "returns commit sha" do
expect(@page.last_commit_sha).to eq @page.last_version.sha
end
- it 'is changed after page updated' do
+ it "is changed after page updated" do
last_commit_sha_before_update = @page.last_commit_sha
@page.update(content: "new content")
@@ -524,24 +524,24 @@ describe WikiPage do
end
end
- describe '#formatted_content' do
- it 'returns processed content of the page' do
- subject.create({ title: "RDoc", content: "*bold*", format: "rdoc" })
- page = wiki.find_page('RDoc')
+ describe "#formatted_content" do
+ it "returns processed content of the page" do
+ subject.create({title: "RDoc", content: "*bold*", format: "rdoc"})
+ page = wiki.find_page("RDoc")
expect(page.formatted_content).to eq("\n<p><strong>bold</strong></p>\n")
- destroy_page('RDoc')
+ destroy_page("RDoc")
end
end
- describe '#hook_attrs' do
- it 'adds absolute urls for images in the content' do
+ describe "#hook_attrs" do
+ it "adds absolute urls for images in the content" do
create_page("test page", "test![WikiPage_Image](/uploads/abc/WikiPage_Image.png)")
page = wiki.wiki.page(title: "test page")
wiki_page = described_class.new(wiki, page, true)
- expect(wiki_page.hook_attrs['content']).to eq("test![WikiPage_Image](#{Settings.gitlab.url}/uploads/abc/WikiPage_Image.png)")
+ expect(wiki_page.hook_attrs["content"]).to eq("test![WikiPage_Image](#{Settings.gitlab.url}/uploads/abc/WikiPage_Image.png)")
end
end
@@ -559,7 +559,7 @@ describe WikiPage do
wiki.wiki.write_page(name, :markdown, content, commit_details)
end
- def destroy_page(title, dir = '')
+ def destroy_page(title, dir = "")
page = wiki.wiki.page(title: title, dir: dir)
wiki.delete_page(page, "test commit")
end