require 'eon/deploy/dsl/app'

module Eon::Deploy

  describe DSL::App do
    subject do
      StubTask.new(application: 'my_app', stage: 'staging').extend DSL::App
    end

    it { expect(subject.send(:app_defaults)).to be_a Hash }

    it "#app_config_path returns shared path with config" do
      expect(subject.app_config_path.to_s).to match "config"
    end

    context "when option is set by developer" do
      it "#app_user returns developer value" do
        subject.set :app_user, 'user'
        expect(subject.app_user).to eq 'user'
      end

      it "#app_conf_domain returns developer value"  do
        subject.set :app_conf_domain, 'conf_domain'
        expect(subject.app_conf_domain).to eq 'conf_domain'
      end

      it "#app_full_name returns developer value" do
        subject.set :app_full_name, 'my_app'
        expect(subject.app_full_name).to eq 'my_app'
      end

      it "#app_services_path returns developer value" do
        subject.set :app_services_path, '/path'
        expect(subject.app_services_path).to eq '/path'
      end
    end

    context "when option is empty" do
      it { expect(subject.app_user).to eq 'deployer' }

      it "#app_conf_domain returns default value" do
        expect(subject.app_conf_domain)
          .to eq "my_app_staging.deployer"
      end

      it { expect(subject.app_full_name).to eq "my_app_staging" }
      it { expect(subject.app_services_path).to eq "/etc/init.d" }
    end
  end

end

