Project

General

Profile

Revision 7ff105d1

Added by David Davis about 7 years ago

Fixes #12681 - Support rubocop 0.35.1 by fixing broken rules

View differences:

.rubocop.yml
33 33

  
34 34
Style/DotPosition:
35 35
  EnforcedStyle: 'leading'
36

  
37
Rails/Date:
38
  Exclude:
39
   - foreman_docker.gemspec
app/controllers/api/v2/containers_controller.rb
108 108
        render :json => { :logs => Docker::Container.get(@container.uuid)
109 109
          .logs(:stdout => (params[:stdout] || true),
110 110
                :stderr => (params[:stderr] || false),
111
                :tail   => (params[:tail]   || 100)) }
111
                :tail   => (params[:tail] || 100)) }
112 112
      end
113 113

  
114 114
      api :PUT, '/containers/:id/power', N_('Run power operation on a container')
app/controllers/containers/steps_controller.rb
41 41

  
42 42
    def set_form
43 43
      instance_variable_set(
44
          "@docker_container_wizard_states_#{step}",
45
          @state.send(:"#{step}") || @state.send(:"build_#{step}"))
44
        "@docker_container_wizard_states_#{step}",
45
        @state.send(:"#{step}") || @state.send(:"build_#{step}"))
46 46
    end
47 47

  
48 48
    def create_container(start = true)
......
58 58
      else
59 59
        @docker_container_wizard_states_environment = @state.environment
60 60
        process_error(
61
            :error_msg => service.errors.full_messages.join(','),
62
            :object => @state.environment,
63
            :render => 'environment')
61
          :error_msg => service.errors.full_messages.join(','),
62
          :object => @state.environment,
63
          :render => 'environment')
64 64
      end
65 65
    end
66 66
  end
app/controllers/containers_controller.rb
96 96
  def container_deletion
97 97
    # Unmanaged container - only present in Compute Resource
98 98
    if params[:compute_resource_id].present?
99
      @deleted_identifier  = params[:id]
99
      @deleted_identifier = params[:id]
100 100
      destroy_compute_resource_vm(params[:compute_resource_id], params[:id])
101 101
    else # Managed container
102 102
      find_container
app/controllers/image_search_controller.rb
3 3

  
4 4
  def auto_complete_repository_name
5 5
    catch_network_errors do
6
      render :text => (use_hub? ? hub_image_exists?(params[:search]) :
7
          registry_image_exists?(params[:search])).to_s
6
      text = if use_hub?
7
               hub_image_exists?(params[:search])
8
             else
9
               registry_image_exists?(params[:search])
10
             end
11
      render :text => text.to_s
8 12
    end
9 13
  end
10 14

  
11 15
  def auto_complete_image_tag
12 16
    catch_network_errors do
13 17
      # This is the format jQuery UI autocomplete expects
14
      tags = use_hub? ? hub_auto_complete_image_tags(params[:search]) :
15
          registry_auto_complete_image_tags(params[:search])
18
      tags = if use_hub?
19
               hub_auto_complete_image_tags(params[:search])
20
             else
21
               registry_auto_complete_image_tags(params[:search])
22
             end
16 23
      respond_to do |format|
17 24
        format.js do
18 25
          tags.map! { |tag| { :label => CGI.escapeHTML(tag), :value => CGI.escapeHTML(tag) } }
......
24 31

  
25 32
  def search_repository
26 33
    catch_network_errors do
27
      repositories = use_hub? ? hub_search_image(params[:search]) :
28
                                registry_search_image(params[:search])
34
      repositories = if use_hub?
35
                       hub_search_image(params[:search])
36
                     else
37
                       registry_search_image(params[:search])
38
                     end
39

  
29 40
      respond_to do |format|
30 41
        format.js do
31 42
          render :partial => 'repository_search_results',
......
75 86
    result = ::Service::RegistryApi.new(:url => @registry.url,
76 87
                                        :user => @registry.username,
77 88
                                        :password => @registry.password).search(term)
78
    registry_name = term.split('/').size > 1 ? term :
79
        'library/' + term
89
    registry_name = if term.split('/').size > 1
90
                      term
91
                    else
92
                      "library/#{term}"
93
                    end
94

  
80 95
    result['results'].any? { |r| r['name'] == registry_name }
81 96
  end
82 97

  
app/helpers/containers_helper.rb
30 30
  def container_title_actions(container)
31 31
    @compute_resource = container.compute_resource
32 32
    title_actions(
33
        button_group(
34
          link_to(_('Commit'), '#commit-modal', :'data-toggle' => 'modal')
35
        ),
36
        button_group(container_power_action(container.in_fog)),
37
        button_group(
38
          display_delete_if_authorized(
39
            hash_for_container_path(:id => container.id)
40
                                    .merge(:auth_object => container,
41
                                           :auth_action => 'destroy',
42
                                           :authorizer  => authorizer),
43
            :confirm     => _("Delete %s?") % container.name)
44
        )
33
      button_group(
34
        link_to(_('Commit'), '#commit-modal', :'data-toggle' => 'modal')
35
      ),
36
      button_group(container_power_action(container.in_fog)),
37
      button_group(
38
        display_delete_if_authorized(
39
          hash_for_container_path(:id => container.id)
40
                                  .merge(:auth_object => container,
41
                                         :auth_action => 'destroy',
42
                                         :authorizer  => authorizer),
43
          :confirm     => _("Delete %s?") % container.name)
44
      )
45 45
    )
46 46
  end
47 47

  
......
69 69

  
70 70
  def power_on_off_message(vm)
71 71
    _("Are you sure you want to power %{act} %{vm}?") % { :act => action_string(vm).downcase.strip,
72
                                                          :vm => vm  }
72
                                                          :vm => vm }
73 73
  end
74 74

  
75 75
  def auto_complete_docker_search(name, val, options = {})
app/models/docker_container_wizard_states/preliminary.rb
10 10

  
11 11
    def used_location_ids
12 12
      Location.joins(:taxable_taxonomies).where(
13
          'taxable_taxonomies.taxable_type' => 'DockerContainerWizardStates::Preliminary',
14
          'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
13
        'taxable_taxonomies.taxable_type' => 'DockerContainerWizardStates::Preliminary',
14
        'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
15 15
    end
16 16

  
17 17
    def used_organization_ids
18 18
      Organization.joins(:taxable_taxonomies).where(
19
          'taxable_taxonomies.taxable_type' => 'DockerContainerWizardStates::Preliminary',
20
          'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
19
        'taxable_taxonomies.taxable_type' => 'DockerContainerWizardStates::Preliminary',
20
        'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
21 21
    end
22 22
  end
23 23
end
app/models/docker_registry.rb
15 15

  
16 16
  def used_location_ids
17 17
    Location.joins(:taxable_taxonomies).where(
18
        'taxable_taxonomies.taxable_type' => 'DockerRegistry',
19
        'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
18
      'taxable_taxonomies.taxable_type' => 'DockerRegistry',
19
      'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
20 20
  end
21 21

  
22 22
  def used_organization_ids
23 23
    Organization.joins(:taxable_taxonomies).where(
24
        'taxable_taxonomies.taxable_type' => 'DockerRegistry',
25
        'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
24
      'taxable_taxonomies.taxable_type' => 'DockerRegistry',
25
      'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
26 26
  end
27 27

  
28 28
  def prefixed_url(image_name)
app/models/service/containers.rb
27 27
      container = Container.new(wizard_state.container_attributes) do |r|
28 28
        # eagerly load environment variables and exposed ports configuration
29 29
        state = DockerContainerWizardState.includes(
30
            :environment => [:environment_variables, :exposed_ports]).find(wizard_state.id)
30
          :environment => [:environment_variables, :exposed_ports]).find(wizard_state.id)
31 31

  
32 32
        load_environment_variables(state, r)
33 33
        load_exposed_ports(state, r)
......
66 66

  
67 67
    def destroy_wizard_state(wizard_state)
68 68
      wizard_state.destroy
69
      DockerContainerWizardState.destroy_all(["updated_at < ?", (Time.now - 24.hours)])
69
      DockerContainerWizardState.destroy_all(["updated_at < ?", (Time.now.utc - 24.hours)])
70 70
    end
71 71

  
72 72
    def load_environment_variables(state, r)
db/migrate/20141010173220_create_docker_images.rb
7 7
    end
8 8

  
9 9
    create_table :docker_tags do |t|
10
      t.string  :tag
10
      t.string :tag
11 11
      t.references :docker_image, :null => false
12 12
      t.timestamps
13 13
    end
db/migrate/20141209182008_remove_docker_tables.rb
44 44
      t.timestamps
45 45
    end
46 46
    create_table :docker_tags do |t|
47
      t.string  :tag
47
      t.string :tag
48 48
      t.references :docker_image, :null => false
49 49
      t.timestamps
50 50
    end
db/migrate/20141222113313_create_wizard_states.rb
1 1
class CreateWizardStates < ActiveRecord::Migration
2 2
  # rubocop:disable Metrics/MethodLength
3 3
  def change
4
    create_table :docker_container_wizard_states do |t|
5
      t.timestamps
6
    end
4
    create_table :docker_container_wizard_states, &:timestamps
7 5

  
8 6
    create_table :docker_container_wizard_states_preliminaries do |t|
9 7
      t.integer :compute_resource_id, :null => false
......
11 9
      t.timestamps
12 10
    end
13 11

  
14
    create_table  :docker_container_wizard_states_images do |t|
12
    create_table :docker_container_wizard_states_images do |t|
15 13
      t.integer :registry_id
16 14
      t.string :repository_name, :null => false
17 15
      t.string :tag, :null => false
......
19 17
      t.timestamps
20 18
    end
21 19

  
22
    create_table  :docker_container_wizard_states_configurations do |t|
20
    create_table :docker_container_wizard_states_configurations do |t|
23 21
      t.string :name
24 22
      t.string :command
25 23
      t.string :entrypoint
release/changelog
3 3
# changelog generates two files, Contributors and CHANGELOG with all changes
4 4
# from git. These should be included in every foreman-docker release.
5 5

  
6

  
7
cmd=`git log --pretty='format:%ci::%an <%ae>::%s'`
6
cmd = `git log --pretty='format:%ci::%an <%ae>::%s'`
8 7

  
9 8
list = {}
10 9
list_order = []
......
17 16
  date, _time, _zone = date.split(" ")
18 17

  
19 18
  id = "#{date}\t#{author}"
20
  if not list[id]
19
  unless list[id]
21 20
    list[id] = []
22
    list_order << {:id => id, :value => list[id]}
21
    list_order << { :id => id, :value => list[id] }
23 22
  end
24 23
  list[id] << subject
25 24
  contributors << author
26 25
end
27 26

  
28 27
# list.each do |id, value|
29
file = File.new(changelog_file,"w")
28
file = File.new(changelog_file, "w")
30 29
list_order.each do |i|
31 30
  id = i[:id]
32 31
  value = i[:value]
......
36 35
  file.puts "\n"
37 36
end
38 37
file.close
39
file = File.new(contributors_file,"w")
38
file = File.new(contributors_file, "w")
40 39
file.puts "Contributors (sorted alphabetically)"
41 40
file.puts "\n"
42 41
file.puts contributors.sort.uniq.join("\n")
test/functionals/api/v2/containers_controller_test.rb
34 34
          assert_equal ActiveSupport::JSON.decode(response.body)['logs'], fake_container.logs
35 35
        end
36 36

  
37
        test 'show returns information about container'  do
37
        test 'show returns information about container' do
38 38
          get :show, :id => @container.id
39 39
          assert_response :success
40 40
          assert_equal ActiveSupport::JSON.decode(response.body)['name'], 'foo'
test/integration/container_steps_test.rb
1 1
require 'test_helper'
2 2

  
3 3
class ContainerStepsTest < ActionDispatch::IntegrationTest
4
  test 'shows a link to a new compute resource if none is available'  do
4
  test 'shows a link to a new compute resource if none is available' do
5 5
    visit new_container_path
6 6
    assert has_selector?("div.alert", :text => 'Please add a new one')
7 7
  end
8 8

  
9
  test 'shows taxonomies tabs'  do
9
  test 'shows taxonomies tabs' do
10 10
    visit new_container_path
11 11
    assert has_selector?("a", :text => 'Locations') if SETTINGS[:locations_enabled]
12 12
    assert has_selector?("a", :text => 'Organizations') if SETTINGS[:organizations_enabled]
test/integration/container_test.rb
1 1
require 'test_helper'
2 2

  
3 3
class ContainerIntegrationTest < ActionDispatch::IntegrationTest
4
  test 'redirects to a new compute resource if none is available'  do
4
  test 'redirects to a new compute resource if none is available' do
5 5
    visit containers_path
6 6
    assert_equal current_path, new_compute_resource_path
7 7
  end
test/units/containers_service_test.rb
1 1
require 'test_plugin_helper'
2 2

  
3
class ContainersServiceTest <  ActiveSupport::TestCase
3
class ContainersServiceTest < ActiveSupport::TestCase
4 4
  setup do
5 5
    @state = DockerContainerWizardState.create! do |s|
6 6
      s.build_preliminary(:compute_resource_id => FactoryGirl.create(:docker_cr).id,
test/units/registry_api_test.rb
1 1
require 'test_plugin_helper'
2 2

  
3
class RegistryApiTest <  ActiveSupport::TestCase
3
class RegistryApiTest < ActiveSupport::TestCase
4 4
  test "initialize handles username password info correctly" do
5 5
    uname = "tardis"
6 6
    password = "boo"

Also available in: Unified diff