Sha256: 53d049a766428e1c29aa415532384a733c41f4d75e1d0b6baa8812b494a7a19a

Contents?: true

Size: 1.65 KB

Versions: 23

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

describe Trackman::Components::Shippable do
  class Test
    extend Trackman::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

23 entries across 23 versions & 1 rubygems

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