spec/flydata/command/sync_spec.rb in flydata-0.3.16 vs spec/flydata/command/sync_spec.rb in flydata-0.3.17

- old
+ new

@@ -3,10 +3,13 @@ require 'flydata/command/sync' module Flydata module Command describe Sync do + let(:subject_object){ described_class.new } + subject { subject_object } + let(:default_mysqldump_dir) do File.join('/tmp', "sync_dump_#{Time.now.to_i}") end let(:default_data_entry) do {"id"=>93, @@ -33,21 +36,28 @@ "password"=>"welcome", "database"=>"sync_test", "tables"=>["table1", " table2"], "mysqldump_dir"=>default_mysqldump_dir, "forwarder" => "tcpforwarder", "data_servers"=>"localhost:9905" } } end + let(:mysql_table_columns) { + {"id"=>{:column_name=>"id", :format_type_str=>"int(11)", :format_type=>"int", :format_size=>11}, "name"=>{:column_name=>"name", :format_type_str=>"varchar(40)", :format_type=>"varchar", :format_size=>40, :default=>nil}, "created_at"=>{:column_name=>"created_at", :format_type_str=>"timestamp", :format_type=>"timestamp", :default=>"CURRENT_TIMESTAMP"}, "bin"=>{:column_name=>"bin", :format_type_str=>"binary(34)", :format_type=>"binary", :format_size=>34, :default=>nil}, "bin2"=>{:column_name=>"bin2", :format_type_str=>"blob", :format_type=>"blob"}, "varbin"=>{:column_name=>"varbin", :format_type_str=>"varchar(34)", :format_type=>"varchar", :format_size=>34, :default=>nil}} + } + let(:mysql_table) do + mt = double('mysql_table') + allow(mt).to receive(:columns).and_return(mysql_table_columns) + mt + end after :each do if Dir.exists?(default_mysqldump_dir) Dir.delete(default_mysqldump_dir) rescue nil end if File.exists?(default_mysqldump_dir) File.delete(default_mysqldump_dir) rescue nil end end - subject { Sync.new } describe '#cleanup_sync_server' do let(:rest_client) { double('rest_client') } context "when rest client throws timeout errors" do before do @@ -228,9 +238,20 @@ context 'with empty tables' do before do default_data_entry['mysql_data_entry_preference']['tables'] = "" end include_examples 'throws an error' + end + end + describe '#convert_to_flydata_values' do + subject { subject_object.send(:convert_to_flydata_values, mysql_table, values) } + let(:values) { [4, 'John', nil, '0xC0448200', nil, nil] } + + it 'calls convert_to_valydata_value for each value' do + mysql_table.columns.values.each_with_index do |col_info, i| + expect(FlydataCore::TableDef::MysqlTableDef).to receive(:convert_to_flydata_value).with(values[i], col_info[:format_type]).and_return(values[i]) + end + is_expected.to eq values end end end end end