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-10.0.2 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-10.0.1 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-10.0.0 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-9.2.3 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-9.2.2 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-9.2.1 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-9.2.0 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-9.1.1 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-9.0.4 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-9.1.0 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-9.0.2 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-9.0.1 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-8.3.3 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-9.0.0 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-8.2.1 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-8.1.4 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-8.3.2 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-8.3.1 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-8.1.3 test/lib/actions/middleware/keep_current_timezone_test.rb
foreman-tasks-8.3.0 test/lib/actions/middleware/keep_current_timezone_test.rb