Sha256: cf7c6b06272cf3227d46da688c8d11453183065cde149bae5c03b1c8fcb0bfdc

Contents?: true

Size: 1.97 KB

Versions: 16

Compression:

Stored size: 1.97 KB

Contents

require 'test_helper'

module Shipit
  class StatusTest < ActiveSupport::TestCase
    setup do
      @commit = shipit_commits(:first)
      @stack = @commit.stack
    end

    test ".replicate_from_github! is idempotent" do
      assert_difference '@commit.statuses.count', 1 do
        @commit.statuses.replicate_from_github!(github_status)
      end

      assert_no_difference '@commit.statuses.count' do
        @commit.statuses.replicate_from_github!(github_status)
      end
    end

    test "once created a commit broadcasts an update event" do
      expect_event(@stack)
      @commit.statuses.create!(state: 'success')
    end

    test ".replicate_from_github! touches the related stack" do
      stack_last_updated_at = @stack.updated_at
      commit_last_updated_at = @commit.updated_at

      @commit.statuses.replicate_from_github!(github_status)

      assert_not_equal commit_last_updated_at, @commit.reload.updated_at
      assert_not_equal stack_last_updated_at, @stack.reload.updated_at
    end

    test ".simple_state returns failure when status is error" do
      assert_equal 'failure', Status.new(state: 'error').simple_state
    end

    test ".simple_state returns status when status is not error" do
      assert_equal 'success', Status.new(state: 'success').simple_state
      assert_equal 'failure', Status.new(state: 'failure').simple_state
    end

    private

    def github_status
      @github_status ||= OpenStruct.new(
        state: 'success',
        description: 'This is a description',
        context: 'default',
        target_url: 'http://example.com',
        created_at: 1.day.ago.to_time,
      )
    end

    def expect_event(stack)
      Pubsubstub::RedisPubSub.expects(:publish).at_least_once
      Pubsubstub::RedisPubSub.expects(:publish).with do |channel, event|
        data = JSON.load(event.data)
        event.name == 'stack.update' &&
          channel == "stack.#{stack.id}" &&
          data['url'] == "/#{stack.to_param}"
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
shipit-engine-0.14.0 test/models/status_test.rb
shipit-engine-0.13.0 test/models/status_test.rb
shipit-engine-0.12.1 test/models/status_test.rb
shipit-engine-0.12.0 test/models/status_test.rb
shipit-engine-0.11.0 test/models/status_test.rb
shipit-engine-0.10.0 test/models/status_test.rb
shipit-engine-0.9.0 test/models/status_test.rb
shipit-engine-0.8.9 test/models/status_test.rb
shipit-engine-0.8.8 test/models/status_test.rb
shipit-engine-0.8.7 test/models/status_test.rb
shipit-engine-0.8.6 test/models/status_test.rb
shipit-engine-0.8.5 test/models/status_test.rb
shipit-engine-0.8.4 test/models/status_test.rb
shipit-engine-0.8.3 test/models/status_test.rb
shipit-engine-0.8.2 test/models/status_test.rb
shipit-engine-0.8.1 test/models/status_test.rb