Sha256: 6fee84b0f3b51df82794b4b891b4ce9b52daeec692db19a7c20c6fa53e1c053a

Contents?: true

Size: 1.88 KB

Versions: 23

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'

describe Trackman::Assets::Asset do
  
  class MyTestAsset < Asset
  end

  before :each do
    class Env
      def production?
        true
      end
    end
  end

  after :each do
    ENV['TRACKMAN_AUTOSYNC'] = nil
    begin
      Object.send(:remove_const, :Rails)
    rescue
    end
  end
  
  it "syncs without any special config" do
    MyTestAsset.should_receive(:sync)

    MyTestAsset.autosync
  end  
  
  it "doesnt autosync if ENV is set to false/0/FALSE" do
    MyTestAsset.should_not_receive(:sync)

    ['false', '0', 'FALSE'].each do |v|
      ENV['TRACKMAN_AUTOSYNC'] = v
      MyTestAsset.autosync
    end
  end
  
  it "doesn't autosync if the env is dev or test" do
    class Rails
      def self.env
        Env.new
      end  
    end
    
    class Env
      def production?
        false
      end
      def development?
        true
      end
      def test?
        false
      end
    end
    MyTestAsset.should_not_receive(:sync)

    MyTestAsset.autosync
  end
  
  it "doesn't blow up when I autosync even though something is broken" do
    def MyTestAsset.sync
      raise "something is wrong"
    end
    result = true
    MyTestAsset.should_receive(:sync)

    lambda { result = MyTestAsset.autosync }.should_not raise_error
    
    result.should be_false
  end

  it "logs the error when sync is broken" do
    MyTestAsset.stub!(:sync).and_raise("something is wrong")

    Trackman::Utility::Debugger.should_receive(:log_exception).once

    lambda { result = MyTestAsset.autosync }.should_not raise_error
  end

  it "syncs if the env is not development or test" do
    class Rails
      def self.env
        Env.new
      end  
    end
    
    class Env
      def production?
        false
      end
      def development?
        false
      end
      def test?
        false
      end
    end
    MyTestAsset.should_receive(:sync)

    MyTestAsset.autosync
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
trackman-0.6.18 spec/sync_spec.rb
trackman-0.6.17 spec/sync_spec.rb
trackman-0.6.16 spec/sync_spec.rb
trackman-0.6.15 spec/sync_spec.rb
trackman-0.6.14 spec/sync_spec.rb
trackman-0.6.13 spec/sync_spec.rb
trackman-0.6.12 spec/sync_spec.rb
trackman-0.6.11 spec/sync_spec.rb
trackman-0.6.10 spec/sync_spec.rb
trackman-0.6.9 spec/sync_spec.rb
trackman-0.6.8 spec/sync_spec.rb
trackman-0.6.7 spec/sync_spec.rb
trackman-0.6.6 spec/sync_spec.rb
trackman-0.6.5 spec/sync_spec.rb
trackman-0.6.4 spec/sync_spec.rb
trackman-0.6.3 spec/sync_spec.rb
trackman-0.6.2 spec/sync_spec.rb
trackman-0.6.1 spec/sync_spec.rb
trackman-0.6.0 spec/sync_spec.rb
trackman-0.5.8 spec/sync_spec.rb