Skip to content
Permalink
Browse files

More refactoring of media_addon_workflow_spec

  • Loading branch information...
ancorgs committed Apr 22, 2015
1 parent 761288b commit b70af08f179d8e60a48329e03f28c3737c575b49
Showing with 77 additions and 46 deletions.
  1. +77 −46 test/media_addon_workflow_spec.rb
@@ -5,70 +5,101 @@

describe "Registration::UI::MediaAddonWorkflow" do
describe ".run" do
subject(:run) { Registration::UI::MediaAddonWorkflow.run(repo) }

let(:repo) { 42 }
# sle-module-legacy product
let(:products) { [YAML.load_file(fixtures_file("products_legacy_installation.yml")).first] }
let(:legacy_module_products) { [YAML.load_file(fixtures_file("products_legacy_installation.yml")).first] }
let(:remote_addons) { YAML.load_file(fixtures_file("available_addons.yml")) }
let(:products_from_repo) { legacy_module_products }

before do
allow(Registration::UrlHelpers).to receive(:registration_url)
allow(Registration::SwMgmt).to receive(:init).and_return(true)
allow(Yast::Pkg).to receive(:SourceLoad)
allow(Yast::Pkg).to receive(:SourceGeneralData).with(repo).and_return({})
allow(Registration::SwMgmt).to receive(:products_from_repo).with(repo).and_return(products)
allow(Registration::SwMgmt).to receive(:select_product_addons).with(products, remote_addons)
allow(Registration::Addon).to receive(:selected).twice.and_return([remote_addons.first])
allow_any_instance_of(Registration::RegistrationUI).to receive(:get_available_addons)
.and_return(remote_addons)
allow(Registration::Addon).to receive(:find_all).and_return(remote_addons)
# SwMgmt initialization
allow(Registration::SwMgmt).to receive(:init).and_return swmgmt_init
# List of products
allow(Registration::SwMgmt).to receive(:products_from_repo)
.and_return(products_from_repo)
end

it "registers the addon from media" do
expect(Registration::Registration).to receive(:is_registered?).and_return(true)
expect_any_instance_of(Registration::RegistrationUI).to receive(:register_addons)
.and_return(:next)
context "if package management initialization fails" do
let(:swmgmt_init) { false }

expect(Registration::UI::MediaAddonWorkflow.run(repo)).to eq(:next)
it "aborts" do
expect(Yast::Report).to receive(:Error)
expect(run).to eq(:abort)
end
end

context "if package management initialization success" do
let(:swmgmt_init) { true }

it "aborts when package management initialization fails" do
expect(Registration::SwMgmt).to receive(:init).and_return(false)
expect(Yast::Report).to receive(:Error)
before do
# Load source information
allow(Yast::Pkg).to receive(:SourceLoad)
# Information about the source for displaying it
allow(Yast::Pkg).to receive(:SourceGeneralData).and_return({})
# Url of the registration server
allow(Registration::UrlHelpers).to receive(:registration_url)
end

expect(Registration::UI::MediaAddonWorkflow.run(repo)).to eq(:abort)
end
context "and the media addon does not provide any product" do
let(:products_from_repo) { [] }

it "skips registation when the media addon does not provide any product" do
expect(Registration::SwMgmt).to receive(:products_from_repo).with(repo).and_return([])
expect(Registration::UI::MediaAddonWorkflow.run(repo)).to eq(:finish)
end
it "skips registration" do
expect(run).to eq :finish
end
end

it "registers the base system if it is not registered yet" do
# the base system registration skipped then registered (to cover more paths)
expect(Registration::Registration).to receive(:is_registered?).exactly(3).times
.and_return(false, false, true)
allow_any_instance_of(Registration::UI::BaseSystemRegistrationDialog).to receive(
:run).and_return(:skip, :next)
expect(Yast::Popup).to receive(:YesNo).and_return(false)
context "and the media addon provides a list of products" do
before do
# Three calls to mock the selection of addons
allow(Registration::SwMgmt).to receive(:select_product_addons)
allow(Registration::Addon).to receive(:find_all).and_return(remote_addons)
allow(Registration::Addon).to receive(:selected).and_return(remote_addons[0,1])
# List of available addons
allow_any_instance_of(Registration::RegistrationUI).to receive(:get_available_addons)
.and_return(remote_addons)
end

expect_any_instance_of(Registration::RegistrationUI).to receive(:register_addons)
.and_return(:next)
it "registers the base system and the addons" do
# False before calling the Base registration dialog. True afterwards
allow(Registration::Registration).to receive(:is_registered?).and_return(false, true, true)

expect(Registration::UI::MediaAddonWorkflow.run(repo)).to eq(:next)
end
# Base system is registered
expect_any_instance_of(Registration::UI::BaseSystemRegistrationDialog)
.to receive(:run).and_return(:next)
# Addons are registered
expect_any_instance_of(Registration::RegistrationUI).to receive(:register_addons)
.and_return(:next)
expect(run).to eq(:next)
end

it "registers only the addons if base system is already registered" do
allow(Registration::Registration).to receive(:is_registered?)
.and_return(true)

it "skips addon product registration if base product registration is skipped" do
# skip base system registration
expect(Registration::Registration).to receive(:is_registered?).twice.times
.and_return(false)
expect_any_instance_of(Registration::UI::BaseSystemRegistrationDialog).to receive(
:run).and_return(:skip)
expect(Yast::Popup).to receive(:YesNo).and_return(true)
# No base system registration
expect_any_instance_of(Registration::UI::BaseSystemRegistrationDialog)
.to_not receive(:run)
# Registration of addons
expect_any_instance_of(Registration::RegistrationUI).to receive(:register_addons)
.and_return(:next)
expect(run).to eq :next
end

# no addon is registered
expect_any_instance_of(Registration::RegistrationUI).to_not receive(:register_addons)
it "skips addons registration if base system registration is skipped" do
# skip base system registration
allow(Registration::Registration).to receive(:is_registered?).and_return(false)
allow(Yast::Popup).to receive(:YesNo).and_return(true)

expect(Registration::UI::MediaAddonWorkflow.run(repo)).to eq(:skip)
# Skipped attempt to register base system
expect_any_instance_of(Registration::UI::BaseSystemRegistrationDialog)
.to receive(:run).and_return(:skip)
# no addon is registered
expect_any_instance_of(Registration::RegistrationUI).to_not receive(:register_addons)
expect(run).to eq(:skip)
end
end
end
end
end

0 comments on commit b70af08

Please sign in to comment.
You can’t perform that action at this time.