sandbox.rb 1.3 KB
Newer Older
1 2 3 4 5 6 7 8
module QA
  module Factory
    module Resource
      ##
      # Ensure we're in our sandbox namespace, either by navigating to it or by
      # creating it if it doesn't yet exist.
      #
      class Sandbox < Factory::Base
9 10
        attr_reader :path

11
        attribute :id
12

13
        def initialize
14
          @path = Runtime::Namespace.sandbox_name
15 16
        end

17
        def fabricate!
18
          Page::Main::Menu.perform(&:go_to_groups)
19 20

          Page::Dashboard::Groups.perform do |page|
21 22
            if page.has_group?(path)
              page.go_to_group(path)
23 24 25
            else
              page.go_to_new_group

26
              Page::Group::New.perform do |group|
27
                group.set_path(path)
28 29
                group.set_description('GitLab QA Sandbox Group')
                group.set_visibility('Public')
30
                group.create
31 32 33 34
              end
            end
          end
        end
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

        def fabricate_via_api!
          resource_web_url(api_get)
        rescue ResourceNotFoundError
          super
        end

        def api_get_path
          "/groups/#{path}"
        end

        def api_post_path
          '/groups'
        end

        def api_post_body
          {
            path: path,
            name: path,
            visibility: 'public'
          }
        end
57 58 59 60
      end
    end
  end
end