require_relative '../spec_helper' require 'tempfile' require 'flydata-core/config/user_maintenance' module FlydataCore::Config describe UserMaintenance do let(:temp_dir) { Dir.mktmpdir('flydatads_rspec_home') } let(:user_maintenance_dir_path) { File.join(temp_dir, 'user_maintenance') } let(:default_user_maintenance) { described_class.new(user_maintenance_dir_path) } let(:user_maintenance) { default_user_maintenance } let(:default_params) { { data_port_id: 1, data_entry_id: 2, table_name: 'test_table' } } let(:params) { default_params } describe '#maintenance_mode_file_path' do subject { user_maintenance.maintenance_mode_file_path(params) } context 'with data_port_id' do let(:params) { { data_port_id: 1 } } it { is_expected.to eq(File.join(user_maintenance_dir_path, '1', 'maintenance_1')) } end context 'with data_port_id and data_entry_id' do let(:params) { { data_port_id: 1, data_entry_id: 2 } } it { is_expected.to eq(File.join(user_maintenance_dir_path, '1', 'maintenance_1_2')) } end context 'with data_port_id, data_entry_id and table_name' do it { is_expected.to eq(File.join(user_maintenance_dir_path, '1', 'maintenance_1_2_test_table')) } end context 'with invalid object' do let(:params) { nil } it { expect{subject}.to raise_error(ArgumentError) } end context 'with empty hash' do let(:params) { {} } it { expect{subject}.to raise_error(ArgumentError) } end end describe '#discard_mode_file_path' do subject { user_maintenance.discard_mode_file_path(params) } context 'with data_port_id' do let(:params) { { data_port_id: 1 } } it { is_expected.to eq(File.join(user_maintenance_dir_path, '1', 'discard_1')) } end context 'with data_port_id and data_entry_id' do let(:params) { { data_port_id: 1, data_entry_id: 2 } } it { is_expected.to eq(File.join(user_maintenance_dir_path, '1', 'discard_1_2')) } end context 'with data_port_id, data_entry_id and table_name' do it { is_expected.to eq(File.join(user_maintenance_dir_path, '1', 'discard_1_2_test_table')) } end context 'with invalid object' do let(:params) { nil } it { expect{subject}.to raise_error(ArgumentError) } end context 'with empty hash' do let(:params) { {} } it { expect{subject}.to raise_error(ArgumentError) } end end describe '#mode_file_path' do let(:mode) { nil } subject { user_maintenance.mode_file_path(mode, params) } context 'with invalid mode' do let(:mode) { :unknown } it { expect{ subject }.to raise_error(ArgumentError, "Unsupported mode:unknown") } end end describe '#maintenance_mode?' do subject { user_maintenance.maintenance_mode?(params) } context 'when in maintenance mode per data-port' do end end end end