Sha256: 459c5ea7f40c268980c135d92aa0b605c1329da8c8b7418f3d6fabb5bc52cc4c

Contents?: true

Size: 1.45 KB

Versions: 97

Compression:

Stored size: 1.45 KB

Contents

require 'foreman_tasks_test_helper'

module Actions
  module Middleware
    class KeepCurrentTimezoneTest < ActiveSupport::TestCase
      include ::Dynflow::Testing

      class TestAction < Support::DummyDynflowAction
        middleware.use KeepCurrentTimezone

        def run; end
      end

      describe 'plan' do
        let(:zone) { Time.find_zone('Pacific/Honolulu') }
        test 'with current user set' do
          Time.expects(:zone).returns(zone)
          action = create_and_plan_action(TestAction)
          assert_equal(zone.name, action.input['current_timezone'])
        end
      end

      describe 'run' do
        let(:zone) { Time.find_zone('Pacific/Honolulu') }

        before do
          @real_zone = Time.zone
          @action = create_and_plan_action(TestAction)
        end

        test 'when timezone is not set in input' do
          # It saves and restore the real zone
          Time.expects(:zone=).with(@real_zone)
          @action.stubs(:input).returns({})
          run_action(@action)
        end

        test 'with current timezone as input' do
          # We plan the @action in @real_zone
          # We run the action in Pacific/Honolulu
          Time.stubs(:zone).returns(zone)
          # It restores the orinal time zone
          Time.expects(:zone=).with(zone)

          # It restores the saved time zone
          Time.expects(:zone=).with(@real_zone)
          run_action(@action)
        end
      end
    end
  end
end

Version data entries

97 entries across 97 versions & 1 rubygems

Version Path
foreman-tasks-3.0.0 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-2.0.2 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-1.1.3 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-1.1.2 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-2.0.1 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-2.0.0 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-1.2.0 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-1.1.1 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-1.1.0 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-0.17.6 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-1.0.1 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-1.0.0 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-0.17.5 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-0.17.4 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-0.17.3 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-0.17.2 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-0.16.3 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-0.17.1 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-0.15.11 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-0.16.2 test/lib/actions/middleware/keep_current_timezone_test.rb