Sha256: 6a4eae127f65c8010658a0b57095864e1b27fc4d64da9b0107061cbcee1359e7

Contents?: true

Size: 1.77 KB

Versions: 9

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'
require 'morale/connection_store'

describe Morale::ConnectionStore do
  
  class Dummy; end
  before (:each) do
    @dummy = Dummy.new
    @dummy.extend(Morale::ConnectionStore)
  end
  
  after (:each) do
    @dummy.delete_connection
  end
  
  describe "#location" do
    it "should return the correct location of the connection file" do
      @dummy.location.should == "#{ENV['HOME']}/.morale/connection"
    end
  end
  
  describe "#base_url" do
    it "should store the default base url if it is not set" do
      @dummy.base_url.should == "teammorale.com"
      File.read(@dummy.location).should =~ /teammorale.com/
    end
    
    it "should return the environment variable for the default base url" do
      @dummy.delete_connection
      ENV['DEFAULT_BASE_URL'] = "somewhere-else.com"
      @dummy.base_url.should == "somewhere-else.com"
    end
    
    it "should store the base url when it is set" do
      @dummy.base_url = "somewhere-else.com"
      File.read(@dummy.location).should =~ /somewhere-else.com/
    end
  end
  
  describe "#delete_connection" do
    it "should clear the base_url field" do
      ENV['DEFAULT_BASE_URL'] = nil
      @dummy.base_url = "Blah!"
      @dummy.delete_connection
      @dummy.base_url.should == "teammorale.com"
    end
    
    it "should delete the connection file" do
      FileUtils.mkdir_p(File.dirname(@dummy.location))
      f = File.open(@dummy.location, 'w')
      f.puts "Blah!"
      
      @dummy.delete_connection
      File.exists?(@dummy.location).should be_false
    end
  end
  
  describe "#write_connection" do
    it "should write data to the location of the connection file" do
      @dummy.base_url = "Blah!"
      @dummy.write_connection
      File.read(@dummy.location).should =~ /Blah!/
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
morale-client-1.0.3 spec/morale/connection_store_spec.rb
morale-client-1.0.2 spec/morale/connection_store_spec.rb
morale-client-1.0.1 spec/morale/connection_store_spec.rb
morale-client-1.0.0 spec/morale/connection_store_spec.rb
morale-client-0.0.1 spec/morale/connection_store_spec.rb
morale-1.0.0 spec/morale/connection_store_spec.rb
morale-0.1.3 spec/morale/connection_store_spec.rb
morale-0.1.2 spec/morale/connection_store_spec.rb
morale-0.1.1 spec/morale/connection_store_spec.rb