Skip to content

Commit

Permalink
Merge pull request #6714 from bgeuken/update_arch_controller
Browse files Browse the repository at this point in the history
Refactor architecture controller service
  • Loading branch information
bgeuken committed Jan 23, 2019
2 parents 3a2ed15 + 0214208 commit 2041ae7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/architectures_controller.rb
Expand Up @@ -7,7 +7,7 @@ def index
end

def bulk_update_availability
result = ::ArchitecturesControllerService::ArchitectureUpdater.new(params[:archs]).call
result = ::ArchitecturesControllerService::ArchitectureUpdater.new(params).call

::Configuration.write_to_backend

Expand Down
@@ -1,21 +1,22 @@
module ArchitecturesControllerService
class ArchitectureUpdater
def initialize(archs)
@archs = archs
@all_valid = true
def initialize(params)
@archs = params.require(:archs).permit!
@all_valid = false
end

def call
@archs.each do |name, value|
@all_valid = @archs.to_h.map do |name, value|
arch = Architecture.find_by(name: name)
arch.available = value
@all_valid &&= arch.save
arch.save
end

self
end

def valid?
@all_valid
@all_valid.all?
end
end
end
Expand Up @@ -31,7 +31,7 @@

context 'with valid data but failing to save' do
before do
allow_any_instance_of(Architecture).to receive(:save).and_return(false)
allow_any_instance_of(Architecture).to receive(:valid?).and_return(false)
request.env['HTTP_REFERER'] = root_url # Needed for the redirect_to :back
post :bulk_update_availability, params: { archs: { i586: '1', s390x: '1' } }
end
Expand Down

0 comments on commit 2041ae7

Please sign in to comment.