merge_request.rb 2.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# frozen_string_literal: true

require 'securerandom'

module QA
  module Resource
    class MergeRequest < Base
      attr_accessor :title,
                    :description,
                    :source_branch,
                    :target_branch,
                    :assignee,
                    :milestone,
14 15 16
                    :labels,
                    :file_name,
                    :file_content
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

      attribute :project do
        Project.fabricate! do |resource|
          resource.name = 'project-with-merge-request'
        end
      end

      attribute :target do
        project.visit!

        Repository::ProjectPush.fabricate! do |resource|
          resource.project = project
          resource.branch_name = 'master'
          resource.remote_branch = target_branch
        end
      end

      attribute :source do
        Repository::ProjectPush.fabricate! do |resource|
          resource.project = project
          resource.branch_name = target_branch
          resource.remote_branch = source_branch
          resource.new_branch = false
40 41
          resource.file_name = file_name
          resource.file_content = file_content
42 43 44 45 46 47 48 49 50 51 52
        end
      end

      def initialize
        @title = 'QA test - merge request'
        @description = 'This is a test merge request'
        @source_branch = "qa-test-feature-#{SecureRandom.hex(8)}"
        @target_branch = "master"
        @assignee = nil
        @milestone = nil
        @labels = []
53 54
        @file_name = "added_file.txt"
        @file_content = "File Added"
55 56 57 58 59 60
      end

      def fabricate!
        populate(:target, :source)

        project.visit!
61 62 63 64
        Page::Project::Show.perform do |project|
          project.wait_for_push
          project.new_merge_request
        end
65 66 67 68
        Page::MergeRequest::New.perform do |page|
          page.fill_title(@title)
          page.fill_description(@description)
          page.choose_milestone(@milestone) if @milestone
69
          page.assign_to_me if @assignee == 'me'
70 71 72 73 74 75 76 77 78 79
          labels.each do |label|
            page.select_label(label)
          end

          page.create_merge_request
        end
      end
    end
  end
end