Commit a10d8adf authored by Lin Jen-Shin's avatar Lin Jen-Shin

Rename location to uri; Handle uri for HTTP; Fix pushing remote

parent 1421469e
...@@ -2,7 +2,8 @@ module QA ...@@ -2,7 +2,8 @@ module QA
module Factory module Factory
module Repository module Repository
class Push < Factory::Base class Push < Factory::Base
attr_writer :file_name, :file_content, :commit_message, :branch_name, :new_branch attr_accessor :file_name, :file_content, :commit_message,
:branch_name, :new_branch, :remote_branch
dependency Factory::Resource::Project, as: :project do |project| dependency Factory::Resource::Project, as: :project do |project|
project.name = 'project-with-code' project.name = 'project-with-code'
...@@ -17,28 +18,32 @@ module QA ...@@ -17,28 +18,32 @@ module QA
@new_branch = true @new_branch = true
end end
def remote_branch
@remote_branch ||= branch_name
end
def fabricate! def fabricate!
project.visit! project.visit!
Git::Repository.perform do |repository| Git::Repository.perform do |repository|
repository.location = Page::Project::Show.act do repository.uri = Page::Project::Show.act do
choose_repository_clone_http choose_repository_clone_http
repository_location.git_uri repository_location.uri
end end
repository.use_default_credentials repository.use_default_credentials
repository.clone repository.clone
repository.configure_identity('GitLab QA', 'root@gitlab.com') repository.configure_identity('GitLab QA', 'root@gitlab.com')
if @new_branch if new_branch
repository.checkout_new_branch(@branch_name) repository.checkout_new_branch(branch_name)
else else
repository.checkout(@branch_name) repository.checkout(branch_name)
end end
repository.add_file(@file_name, @file_content) repository.add_file(file_name, file_content)
repository.commit(@commit_message) repository.commit(commit_message)
repository.push_changes(@branch_name) repository.push_changes("#{branch_name}:#{remote_branch}")
end end
end end
end end
......
...@@ -39,7 +39,9 @@ module QA ...@@ -39,7 +39,9 @@ module QA
resource.project = project resource.project = project
resource.file_name = 'README.md' resource.file_name = 'README.md'
resource.commit_message = 'Add readme' resource.commit_message = 'Add readme'
resource.branch_name = "master:#{@branch_name}" resource.branch_name = 'master'
resource.new_branch = false
resource.remote_branch = @branch_name
end end
Page::Project::Show.act { wait_for_push } Page::Project::Show.act { wait_for_push }
......
...@@ -14,7 +14,7 @@ module QA ...@@ -14,7 +14,7 @@ module QA
def initialize(git_uri) def initialize(git_uri)
@git_uri = git_uri @git_uri = git_uri
@uri = @uri =
if git_uri.start_with?('ssh://') if git_uri =~ %r{\A(?:ssh|http|https)://}
URI.parse(git_uri) URI.parse(git_uri)
else else
*rest, path = git_uri.split(':') *rest, path = git_uri.split(':')
......
...@@ -15,8 +15,7 @@ module QA ...@@ -15,8 +15,7 @@ module QA
end end
end end
def location=(address) def uri=(address)
@location = address
@uri = URI(address) @uri = URI(address)
end end
......
...@@ -4,7 +4,7 @@ module QA ...@@ -4,7 +4,7 @@ module QA
given(:location) do given(:location) do
Page::Project::Show.act do Page::Project::Show.act do
choose_repository_clone_http choose_repository_clone_http
repository_location.git_uri repository_location
end end
end end
...@@ -18,7 +18,7 @@ module QA ...@@ -18,7 +18,7 @@ module QA
end end
Git::Repository.perform do |repository| Git::Repository.perform do |repository|
repository.location = location repository.uri = location.uri
repository.use_default_credentials repository.use_default_credentials
repository.act do repository.act do
...@@ -33,7 +33,7 @@ module QA ...@@ -33,7 +33,7 @@ module QA
scenario 'user performs a deep clone' do scenario 'user performs a deep clone' do
Git::Repository.perform do |repository| Git::Repository.perform do |repository|
repository.location = location repository.uri = location.uri
repository.use_default_credentials repository.use_default_credentials
repository.act { clone } repository.act { clone }
...@@ -44,7 +44,7 @@ module QA ...@@ -44,7 +44,7 @@ module QA
scenario 'user performs a shallow clone' do scenario 'user performs a shallow clone' do
Git::Repository.perform do |repository| Git::Repository.perform do |repository|
repository.location = location repository.uri = location.uri
repository.use_default_credentials repository.use_default_credentials
repository.act { shallow_clone } repository.act { shallow_clone }
......
...@@ -42,7 +42,7 @@ module QA ...@@ -42,7 +42,7 @@ module QA
project.visit! project.visit!
Git::Repository.perform do |repository| Git::Repository.perform do |repository|
repository.location = location repository.uri = location.uri
repository.use_default_credentials repository.use_default_credentials
repository.act do repository.act do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment