Sha256: 853d5abaf11ff2a3f6eef79e8fd5b42e3b0e97b8ca6deab104dc296464b70a1e

Contents?: true

Size: 1.66 KB

Versions: 54

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

describe Trackman::Assets::Components::Shippable do
  class Test
    extend Trackman::Assets::Components::Shippable

    @@events = []
    def self.events
      @@events
    end
    def self.created?
      @@events.any?{|h| h.has_key? :create }
    end
    def self.updated?
      @@events.any?{|h| h.has_key? :update }
    end
    def self.deleted?
      @@events.any?{|h| h.has_key? :delete }
    end

    def self.created(value)
      @@events << { :create => value }
    end

    def self.updated(value)
      @@events << { :update => value }
    end
    
    def self.deleted(value)
      @@events << { :delete => value }
    end
    
    def Test.build_proc symbol, instance 
      case symbol
      when :update
        proc = Proc.new { self.updated instance }
      when :create
        proc = Proc.new { self.created instance }
      when :delete
        proc = Proc.new { self.deleted instance }
      else
        raise 'zomg'
      end
      proc
    end
  end

  before :each do
    Test.events.clear
  end
  
  it "ships the create" do
    diff = {:create => ["test"], :update => [], :delete => []}
    
    Test.ship diff

    Test.created?.should be_true
    Test.deleted?.should be_false
    Test.updated?.should be_false
  end 

  it "ships all of them" do
    diff = {:create => ["test"], :update => ["wassup"], :delete => ["dododo"]}
    
    Test.ship diff

    Test.created?.should be_true
    Test.deleted?.should be_true
    Test.updated?.should be_true
  end

  it "sorts them before execution" do
    diff = {:create => [3], :update => [2], :delete => [1]}
    
    Test.ship diff

    Test.events.map{|x| x.values.first }.should eq([1,2,3])
  end 
end  

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
trackman-0.5.4 spec/shippable_spec.rb
trackman-0.5.3 spec/shippable_spec.rb
trackman-0.5.2 spec/shippable_spec.rb
trackman-0.5.1 spec/shippable_spec.rb
trackman-0.5.0 spec/shippable_spec.rb
trackman-0.4.8 spec/shippable_spec.rb
trackman-0.4.7 spec/shippable_spec.rb
trackman-0.4.6 spec/shippable_spec.rb
trackman-0.4.5 spec/shippable_spec.rb
trackman-0.4.4 spec/shippable_spec.rb
trackman-0.4.3 spec/shippable_spec.rb
trackman-0.4.2 spec/shippable_spec.rb
trackman-0.4.1 spec/shippable_spec.rb
trackman-0.4.0 spec/shippable_spec.rb
trackman-0.3.5 spec/shippable_spec.rb
trackman-0.3.4 spec/shippable_spec.rb
trackman-0.3.2 spec/shippable_spec.rb
trackman-0.3.1 spec/shippable_spec.rb
trackman-0.3.0 spec/shippable_spec.rb
trackman-0.2.90 spec/shippable_spec.rb