From 3940db9ab5c36295a0a336a62e7531bdddb584cb Mon Sep 17 00:00:00 2001 From: Luke Barbuto Date: Sat, 25 Apr 2015 22:42:37 -0700 Subject: [PATCH] Move update manager into main controller --- lib/launchpad.rb | 1 - .../gui/controllers/main_controller.rb | 30 ++++++++-- .../gui/controllers/update_manager.rb | 25 --------- .../gui/controllers/main_controller_spec.rb | 55 ++++++++++++++----- .../controllers/options_controller_spec.rb | 4 +- .../gui/controllers/update_manager_spec.rb | 30 ---------- 6 files changed, 68 insertions(+), 77 deletions(-) delete mode 100644 lib/launchpad/gui/controllers/update_manager.rb delete mode 100644 spec/lib/launchpad/gui/controllers/update_manager_spec.rb diff --git a/lib/launchpad.rb b/lib/launchpad.rb index 6a3f3ae..4e54dd8 100644 --- a/lib/launchpad.rb +++ b/lib/launchpad.rb @@ -2,7 +2,6 @@ require 'lib/launchpad/patcher' require 'lib/launchpad/index' require 'lib/launchpad/gui/application' -require 'lib/launchpad/gui/controllers/update_manager' require 'lib/launchpad/gui/controllers/main_controller' require 'lib/launchpad/gui/controllers/options_controller' diff --git a/lib/launchpad/gui/controllers/main_controller.rb b/lib/launchpad/gui/controllers/main_controller.rb index 89d9a0c..a06383a 100644 --- a/lib/launchpad/gui/controllers/main_controller.rb +++ b/lib/launchpad/gui/controllers/main_controller.rb @@ -1,20 +1,28 @@ module Launchpad - # Main application GUI controller + # Main application GUI controller. class MainController include JRubyFX::Controller fxml 'main.fxml' - # @return [UpdateManager] manages client file scans and patches. - attr_reader :update_manager + # @return [Launchpad::Patcher] + attr_reader :patcher + + # @return [Java::JavafxSceneControl::Label] + attr_reader :status def initialize super - @update_manager = UpdateManager.new self - @stage.on_shown { update_manager.scan } + @patcher = Patcher.new + @stage.on_shown { scan } + end + + # Compares local and remote files and updates the UI accordingly. + def scan + patcher.in_sync? ? ready_to_launch : ready_to_update end - # Triggered when the options button is pressed + # Triggered when the options button is pressed. def show_options @options ||= stage title: 'Options', @@ -26,5 +34,15 @@ def show_options @options.show end + + private + + def ready_to_launch + status.set_text 'Ready' + end + + def ready_to_update + status.set_text 'Update required...' + end end end diff --git a/lib/launchpad/gui/controllers/update_manager.rb b/lib/launchpad/gui/controllers/update_manager.rb deleted file mode 100644 index ee7f182..0000000 --- a/lib/launchpad/gui/controllers/update_manager.rb +++ /dev/null @@ -1,25 +0,0 @@ -module Launchpad - # Synchronizes the state of the patcher with the view - class UpdateManager - attr_reader :controller, :patcher - - def initialize(controller) - @controller = controller - @patcher = Patcher.new - end - - def scan - patcher.in_sync? ? ready_to_launch : ready_to_update - end - - private - - def ready_to_launch - controller.status.set_text 'Ready' - end - - def ready_to_update - controller.status.set_text 'Update required...' - end - end -end diff --git a/spec/lib/launchpad/gui/controllers/main_controller_spec.rb b/spec/lib/launchpad/gui/controllers/main_controller_spec.rb index b853275..98b67bd 100644 --- a/spec/lib/launchpad/gui/controllers/main_controller_spec.rb +++ b/spec/lib/launchpad/gui/controllers/main_controller_spec.rb @@ -1,23 +1,48 @@ require 'spec_helper' describe Launchpad::MainController do + let(:patcher) { double 'patcher' } + let(:stage) { double 'stage', on_shown: true } + let(:status) { double 'status', set_text: nil } - before { allow(Launchpad::UpdateManager).to receive :new } + before do + allow(Launchpad::Patcher).to receive(:new).and_return patcher + allow(subject).to receive(:status).and_return status + end describe '#initialize' do - let(:update_manager) { double 'update_manager' } + before { subject } + + it 'sets up an patcher' do + expect(subject.patcher).to be patcher + end + + it 'sets up the on_shown hook' do + expect(stage).to have_received :on_shown + end + end + describe '#scan' do before do - allow(Launchpad::UpdateManager).to receive(:new).and_return update_manager - subject + allow(Launchpad::Patcher).to receive(:new).and_return patcher + subject.scan end - it 'sets up an update manager' do - expect(subject.update_manager).to be update_manager + context 'when files are in sync' do + let(:patcher) { double :patcher, in_sync?: true } + + it 'displays a message that files are synced' do + expect(subject.status).to have_received(:set_text).with 'Ready' + end end - it 'sets up the on_shown hook' do - expect(stage_double).to have_received :on_shown + context 'when files are out of sync' do + let(:patcher) { double :patcher, in_sync?: false } + + it 'displays a message that there are files that need syncing' do + expect(subject.status) + .to have_received(:set_text).with 'Update required...' + end end end @@ -52,11 +77,15 @@ end it 'sets the options stage attributes' do - expect(options_stage).to have_received(:title=).with 'Options' - expect(options_stage).to have_received(:always_on_top=).with true - expect(options_stage).to have_received(:resizable=).with false - expect(options_stage).to have_received(:x=).with 25 - expect(options_stage).to have_received(:y=).with 45 + options = { :title= => 'Options', + :always_on_top= => true, + :resizable= => false, + :x= => 25, + :y= => 45 } + + options.each do |option, setting| + expect(options_stage).to have_received(option).with setting + end end it 'shows the options stage' do diff --git a/spec/lib/launchpad/gui/controllers/options_controller_spec.rb b/spec/lib/launchpad/gui/controllers/options_controller_spec.rb index 9f85bec..8d85d96 100644 --- a/spec/lib/launchpad/gui/controllers/options_controller_spec.rb +++ b/spec/lib/launchpad/gui/controllers/options_controller_spec.rb @@ -31,7 +31,7 @@ before { subject.accept } it 'closes the stage' do - expect(stage_double).to have_received :close + expect(stage).to have_received :close end it 'updates all settings with values from the form' do @@ -48,7 +48,7 @@ before { subject.cancel } it 'closes the stage' do - expect(stage_double).to have_received :close + expect(stage).to have_received :close end end diff --git a/spec/lib/launchpad/gui/controllers/update_manager_spec.rb b/spec/lib/launchpad/gui/controllers/update_manager_spec.rb deleted file mode 100644 index 276c7d7..0000000 --- a/spec/lib/launchpad/gui/controllers/update_manager_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'spec_helper' - -describe Launchpad::UpdateManager do - subject { described_class.new controller } - - let(:controller) { double :controller, status: double(set_text: nil) } - - before { allow(Launchpad::Patcher).to receive(:new).and_return patcher } - - describe '#scan' do - before { subject.scan } - - context 'when fils are in sync' do - let(:patcher) { double :patcher, in_sync?: true } - - it 'displays a message that files are synced' do - expect(controller.status).to have_received(:set_text).with 'Ready' - end - end - - context 'when fils are out of sync' do - let(:patcher) { double :patcher, in_sync?: false } - - it 'displays a message that there are files that need syncing' do - expect(controller.status) - .to have_received(:set_text).with 'Update required...' - end - end - end -end