Project

General

Profile

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

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

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
        post :create, :registry => docker_attrs
28
        assert_response :success
29
      end
30

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

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

    
43
      test 'update a docker registry' do
44
        put :update, :id => @registry.id, :registry => { :name => 'hello_world' }
45
        assert_response :success
46
        assert DockerRegistry.exists?(:name => 'hello_world')
47
      end
48

    
49
      test 'deletes a docker registry' do
50
        delete :destroy, :id => @registry.id
51
        assert_response :success
52
        refute DockerRegistry.exists?(@registry.id)
53
      end
54
    end
55
  end
56
end