require 'spec_helper' require 'flydata/command/base' module Flydata module Command describe Base do subject { described_class.new } let(:data_entries) { [{"id"=>4, "data_port_id"=>1, "name"=>"flydata_sync_mysql_2", "log_path"=>nil, "created_at"=>"2015-03-02T03:06:25.000Z", "updated_at"=>"2015-03-02T03:08:02.000Z", "log_deletion"=>nil, "display_name"=>"synctest", "heroku_resource_id"=>nil, "heroku_log_type"=>nil, "log_file_type"=>nil, "log_file_delimiter"=>nil, "enabled"=>true, "type"=>"RedshiftMysqlDataEntry", "tag_name"=>"flydata.c5c0eb3d_dp1.flydata_sync_mysql_2", "tag_name_dev"=>"flydata.c5c0eb3d_dp1.flydata_sync_mysql_2.dev", "data_port_key"=>"c5c0eb3d", "schema_name"=>"", "table_name"=>"", "redshift_schema_name"=>"", "redshift_table_name"=>"", "mysql_data_entry_preference"=>{"host"=>"ubertas.flydata.co", "port"=>3306, "username"=>"mak", "password"=>password, "database"=>"mak_development", "tables"=>"items,orders", "tables_append_only"=>""}}] } let(:flydata) { double('flydata') } let(:path) { '/data_entries' } let(:response_body) { data_entries } let(:response) { double('response') } let(:response_code) { 200 } before do allow(response).to receive(:code).and_return(response_code) allow(flydata).to receive(:get).with(path).and_return(response_body) allow(flydata).to receive(:response).and_return(response) allow(subject).to receive(:flydata).and_return(flydata) end describe '#retrieve_data_entries' do context "when MySQL password from server is encrypted" do let(:password) { "8xRe5otrYkrnV5vQhufa6g==" } let(:response_body) { data_entries } before do # instantiate response_body with the encrypted password response_body end # override password which data_entries referes to let(:password) { 'flydata' } it "returns a data entry list with plain MySQL passwords" do expect(subject.retrieve_data_entries).to eq(data_entries) end end end end end end