Project

General

Profile

Download (1.83 KB) Statistics
| Branch: | Tag: | Revision:

foreman_docker / test / functionals / api / v2 / registries_controller_test.rb @ f6a9acbd

1
require 'test_plugin_helper'
2

    
3
module Api
4
  module V2
5
    class RegistriesControllerTest < ActionController::TestCase
6
      setup do
7
        @registry = FactoryGirl.create(:docker_registry)
8
      end
9

    
10
      test 'index returns a list of all containers' do
11
        get :index, {}, set_session_user
12
        assert_response :success
13
        assert_template 'index'
14
      end
15

    
16
      test 'index can be filtered by name' do
17
        %w(thomas clayton wolfe).each do |name|
18
          FactoryGirl.create(:docker_registry, :name => name)
19
        end
20
        get :index, { :search => 'name = thomas' }, set_session_user
21
        assert_response :success
22
        assert_equal 1, assigns(:registries).length
23
      end
24

    
25
      test 'creates a new registry with valid params' do
26
        docker_attrs = FactoryGirl.attributes_for(:docker_registry)
27
        DockerRegistry.any_instance.stubs(:attempt_login)
28
        post :create, :registry => docker_attrs
29
        assert_response :success
30
      end
31

    
32
      test 'does not create a new registry with invalid params' do
33
        docker_attrs = FactoryGirl.attributes_for(:docker_registry)
34
        docker_attrs.delete(:name)
35
        post :create, :registry => docker_attrs
36
        assert_response 422
37
      end
38

    
39
      test 'shows a docker registry' do
40
        get :show, :id => @registry.id
41
        assert_response :success
42
      end
43

    
44
      test 'update a docker registry' do
45
        DockerRegistry.any_instance.stubs(:attempt_login)
46
        new_name = 'hello_world'
47
        put :update, :id => @registry.id, :registry => { :name => new_name }
48
        assert_response :success
49
        assert_equal new_name, @registry.reload.name
50
      end
51

    
52
      test 'deletes a docker registry' do
53
        delete :destroy, :id => @registry.id
54
        assert_response :success
55
        assert DockerRegistry.where(:id => @registry.id).blank?
56
      end
57
    end
58
  end
59
end