require "rspec" require "rspec_helper" RSpec.configure do |c| # declare an exclusion filter c.filter_run_excluding :broken => true end describe "DEPLOY command" do before do @key_chain = DesignShell::KeyChain.new('DesignShellTest') @credentials = Credentials.new('designshell') #key_chain.set('site_user',creds[:site_user]) #key_chain.set('site_password',creds[:site_password]) @context = DesignShell::Context.new( :argv=>[], :env=>{}, :stdout=>$stdout, :stdin=>$stdin, :stderr=>$stderr, :key_chain=>@key_chain, :credentials=>@credentials ) #$stdout.sync=true # no buffer delay end it "should prepare_cache not pre-existing" do core = DesignShellServer::Core.new(@context) site = "happy.com.au" repo_url = "git@github.com:buzzware/underscore_plus.git" wd = core.working_dir_from_site(site) FileUtils.rm_rf wd command = DesignShellServer::Command.new(core,"DEPLOY "+JSON.generate({:repo_url=>repo_url,:site=>site})) command.prepare_cache repo = DesignShell::Repo.new repo.open wd repo.origin.url==repo_url end it "should prepare_cache pre-existing, to given commit" do core = DesignShellServer::Core.new(@context) site = "happy.com.au" repo_url = "git@github.com:buzzware/underscore_plus.git" wd = core.working_dir_from_site(site) commit1 = '4b133ff8825bbd488ba61fa3e3b82a5fa746ac6a' FileUtils.rm_rf wd command = DesignShellServer::Command.new(core,"DEPLOY "+JSON.generate({ :repo_url=>repo_url, :site=>site, :commit=>commit1 })) command.prepare_cache head_commit = command.repo.head.to_s head_commit.should_not==commit1 command.checkout_branch_commit command.repo.head.to_s.should==commit1 # now try checkout_branch_commit with no specified branch or commit - should checkout head command = DesignShellServer::Command.new(core,"DEPLOY "+JSON.generate({ :repo_url=>repo_url, :site=>site })) command.repo = DesignShell::Repo.new command.repo.open wd command.checkout_branch_commit command.repo.head.to_s.should==head_commit end it "should put file when folder doesn't exist" do site_client = DesignShell::SiteClient.new({ :site_url => @context.credentials[:bigcommerce_sandbox_url], :site_username => @context.credentials[:bigcommerce_sandbox_username], :site_password => @context.credentials[:bigcommerce_sandbox_password] }) site_client.delete '/content/deploy_spec' site_client.deploy_status = nil content1 = StringUtils.random_word(8,8) source = MiscUtils.make_temp_file(nil,nil,content1) dest = "/content/deploy_spec/content/content1.txt" site_client.put_file(source,dest) content2 = site_client.get_string(dest) content2.should == content1 end it "should deploy, no existing cache" do # set up scratch repo with basic site @context.pwd = MiscUtils.append_slash(MiscUtils.real_path(MiscUtils.make_temp_dir('deploy_spec'))) Dir.chdir @context.pwd repo = DesignShell::Repo.new repo.clone @context.credentials[:scratch_repo_url],@context.pwd files_to_rm = Dir.glob(@context.pwd+'*').filter_exclude(@context.pwd+'.git') if !files_to_rm.empty? files_to_rm.each {|fp| FileUtils.rm_rf fp} repo.commit_all "cleared" end FileUtils.mkdir_p 'build' FileUtils.mkdir_p 'build/bigcommerce' FileUtils.mkdir_p 'build/bigcommerce/template' MiscUtils.string_to_file "
a bigcommerce template",'build/bigcommerce/template/template.html' FileUtils.mkdir_p 'build/bigcommerce/content' MiscUtils.string_to_file "first content file",'build/bigcommerce/content/content1.txt' MiscUtils.string_to_file "second content file",'build/bigcommerce/content/content2.txt' FileUtils.mkdir_p 'build/tumblr' MiscUtils.string_to_file "a tumblr template",'build/tumblr/template.html' deploy_plan = <