mongify 1.2.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG.rdoc +10 -0
- data/Gemfile.lock +94 -87
- data/README.rdoc +7 -0
- data/Rakefile +59 -32
- data/features/step_definitions/process_steps.rb +1 -1
- data/lib/mongify/database/column.rb +7 -9
- data/lib/mongify/translation/sync.rb +3 -1
- data/lib/mongify/version.rb +1 -1
- data/mongify.gemspec +9 -8
- data/spec/mongify/cli/command/help_spec.rb +1 -1
- data/spec/mongify/cli/command/version_spec.rb +1 -1
- data/spec/mongify/cli/worker_command_spec.rb +8 -8
- data/spec/mongify/database/base_connection_spec.rb +1 -1
- data/spec/mongify/database/column_spec.rb +6 -6
- data/spec/mongify/database/data_row_spec.rb +3 -3
- data/spec/mongify/database/no_sql_connection_spec.rb +6 -6
- data/spec/mongify/database/sql_connection_spec.rb +5 -5
- data/spec/mongify/database/table_spec.rb +5 -5
- data/spec/mongify/status_spec.rb +1 -1
- data/spec/mongify/translation/process_spec.rb +24 -24
- data/spec/mongify/translation/sync_spec.rb +12 -12
- data/spec/mongify/translation_spec.rb +8 -8
- data/spec/mongify/ui_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/support/database.example +9 -0
- data/spec/support/database_generator.rb +7 -7
- metadata +67 -53
@@ -63,7 +63,8 @@ module Mongify
|
|
63
63
|
max_updated_at, max_updated_at_id = Time.new(1970), nil
|
64
64
|
rows.each do |row|
|
65
65
|
row_hash = t.translate(row)
|
66
|
-
updated_at =
|
66
|
+
updated_at = row['updated_at']
|
67
|
+
updated_at = Time.parse(updated_at) if updated_at.instance_of?(String)
|
67
68
|
if updated_at > max_updated_at
|
68
69
|
max_updated_at = updated_at
|
69
70
|
max_updated_at_id = row_hash['pre_mongified_id']
|
@@ -71,6 +72,7 @@ module Mongify
|
|
71
72
|
no_sql_connection.upsert(t.name, row_hash.merge({DRAFT_KEY => true}))
|
72
73
|
Mongify::Status.publish('copy_data')
|
73
74
|
end
|
75
|
+
raise "Table #{t.sql_name} must have a primary key denoted by :key in the translation file" if t.key_column.nil?
|
74
76
|
(self.max_updated_at ||= {})[t.sql_name] = {'max_updated_at_id' => max_updated_at_id, 'key_column' => t.key_column.name}
|
75
77
|
Mongify::Status.publish('copy_data', :action => 'finish')
|
76
78
|
end
|
data/lib/mongify/version.rb
CHANGED
data/mongify.gemspec
CHANGED
@@ -12,24 +12,25 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = %q{Mongify allows you to map your sql data into a mongodb document database with a simple DSL.}
|
13
13
|
s.required_ruby_version = ">= 1.8.7"
|
14
14
|
|
15
|
-
s.add_dependency('activerecord', "
|
16
|
-
s.add_dependency('activesupport', "
|
17
|
-
s.add_dependency('mongo', "
|
18
|
-
s.add_dependency('bson', "
|
19
|
-
s.add_dependency('bson_ext', "
|
15
|
+
s.add_dependency('activerecord', ">= 4.2")
|
16
|
+
s.add_dependency('activesupport', ">= 4.2")
|
17
|
+
s.add_dependency('mongo', ">= 1.10.2")
|
18
|
+
s.add_dependency('bson', ">= 1.10.2")
|
19
|
+
s.add_dependency('bson_ext', ">= 1.10.2") unless RUBY_PLATFORM == 'java'
|
20
20
|
s.add_dependency('highline', '>= 1.6.1')
|
21
21
|
|
22
22
|
|
23
23
|
s.add_development_dependency('rspec', '~> 2.0')
|
24
|
+
s.add_development_dependency('rspec-collection_matchers', '~> 1.0')
|
24
25
|
s.add_development_dependency('cucumber', '>= 0.10')
|
25
26
|
s.add_development_dependency('mocha', '>= 0.9.8')
|
26
|
-
s.add_development_dependency('yard', '>= 0.
|
27
|
+
s.add_development_dependency('yard', '>= 0.8')
|
27
28
|
s.add_development_dependency('sqlite3', '>= 1.3')
|
28
29
|
s.add_development_dependency('pg', '>= 0.17')
|
29
|
-
s.add_development_dependency('mysql2', '
|
30
|
+
s.add_development_dependency('mysql2', '>= 0.4')
|
30
31
|
s.add_development_dependency('watchr', '>= 0.6')
|
31
32
|
s.add_development_dependency('rake')
|
32
|
-
s.add_development_dependency('
|
33
|
+
s.add_development_dependency('jazz_fingers')
|
33
34
|
|
34
35
|
s.files = `git ls-files`.split("\n")
|
35
36
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -3,7 +3,7 @@ describe Mongify::CLI::Command::Help do
|
|
3
3
|
before :each do
|
4
4
|
@text = 'Piece of interesting text'
|
5
5
|
@cmd = Mongify::CLI::Command::Help.new(@text)
|
6
|
-
@view =
|
6
|
+
@view = double('view').as_null_object
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'displays the correct text on the view' do
|
@@ -4,7 +4,7 @@ describe Mongify::CLI::Command::Version do
|
|
4
4
|
before :each do
|
5
5
|
@text = 'Piece of interesting text'
|
6
6
|
@cmd = Mongify::CLI::Command::Version.new(@text)
|
7
|
-
@view =
|
7
|
+
@view = double('view').as_null_object
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'displays the text on the view' do
|
@@ -14,8 +14,8 @@ describe Mongify::CLI::Command::Worker do
|
|
14
14
|
|
15
15
|
@translation_file = 'spec/files/translation.rb'
|
16
16
|
|
17
|
-
Mongify::Translation.stub(:load).and_return(
|
18
|
-
@view =
|
17
|
+
Mongify::Translation.stub(:load).and_return(double(:print => 'worked'))
|
18
|
+
@view = double('view').as_null_object
|
19
19
|
end
|
20
20
|
|
21
21
|
context "list_commands" do
|
@@ -62,7 +62,7 @@ describe Mongify::CLI::Command::Worker do
|
|
62
62
|
context "translation command" do
|
63
63
|
before(:each) do
|
64
64
|
@command = Mongify::CLI::Command::Worker.new('translation', @config)
|
65
|
-
Mongify::Translation.stub(:load).with(@sql_connection).and_return(
|
65
|
+
Mongify::Translation.stub(:load).with(@sql_connection).and_return(double(:print => 'worked'))
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should require configuration file" do
|
@@ -75,7 +75,7 @@ describe Mongify::CLI::Command::Worker do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should call load on Translation" do
|
78
|
-
Mongify::Translation.should_receive(:load).with(@sql_connection).and_return(
|
78
|
+
Mongify::Translation.should_receive(:load).with(@sql_connection).and_return(double(:print => 'worked'))
|
79
79
|
@command.execute(@view)
|
80
80
|
end
|
81
81
|
end
|
@@ -83,7 +83,7 @@ describe Mongify::CLI::Command::Worker do
|
|
83
83
|
context "process command" do
|
84
84
|
before(:each) do
|
85
85
|
@command = Mongify::CLI::Command::Worker.new('process', @config, 'spec/files/translation.rb')
|
86
|
-
Mongify::Translation.stub(:parse).and_return(
|
86
|
+
Mongify::Translation.stub(:parse).and_return(double(:process => true))
|
87
87
|
end
|
88
88
|
it "should report success" do
|
89
89
|
@view.should_receive(:report_error).never
|
@@ -105,7 +105,7 @@ describe Mongify::CLI::Command::Worker do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should call process on translation" do
|
108
|
-
Mongify::Translation.should_receive(:parse).and_return(
|
108
|
+
Mongify::Translation.should_receive(:parse).and_return(double(:process => true))
|
109
109
|
@command.execute(@view)
|
110
110
|
end
|
111
111
|
end
|
@@ -113,7 +113,7 @@ describe Mongify::CLI::Command::Worker do
|
|
113
113
|
context "sync command" do
|
114
114
|
before(:each) do
|
115
115
|
@command = Mongify::CLI::Command::Worker.new('sync', @config, 'spec/files/translation.rb')
|
116
|
-
Mongify::Translation.stub(:parse).and_return(
|
116
|
+
Mongify::Translation.stub(:parse).and_return(double(:sync => true))
|
117
117
|
end
|
118
118
|
it "should report success" do
|
119
119
|
@view.should_receive(:report_error).never
|
@@ -135,7 +135,7 @@ describe Mongify::CLI::Command::Worker do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should call sync on translation" do
|
138
|
-
Mongify::Translation.should_receive(:parse).and_return(
|
138
|
+
Mongify::Translation.should_receive(:parse).and_return(double(:sync => true))
|
139
139
|
@command.execute(@view)
|
140
140
|
end
|
141
141
|
end
|
@@ -39,7 +39,7 @@ describe Mongify::Database::BaseConnection do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should respond to available settings" do
|
42
|
-
@base_connection.respond_to?(:host).should
|
42
|
+
@base_connection.respond_to?(:host).should be_truthy
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should force adapter to a string" do
|
@@ -41,7 +41,7 @@ describe Mongify::Database::Column do
|
|
41
41
|
|
42
42
|
context "id column" do
|
43
43
|
before(:each) do
|
44
|
-
@col =
|
44
|
+
@col = double(:sql_name => 'id')
|
45
45
|
end
|
46
46
|
it "should detect column with type :integer as a :key column" do
|
47
47
|
@col.stub(:type).and_return(:integer)
|
@@ -64,7 +64,7 @@ describe Mongify::Database::Column do
|
|
64
64
|
end
|
65
65
|
context "references" do
|
66
66
|
before(:each) do
|
67
|
-
@col =
|
67
|
+
@col = double(:sql_name => 'post_id', :type => :integer, :referenced? => false)
|
68
68
|
end
|
69
69
|
it "should detect column references" do
|
70
70
|
@col.should_receive('references=').with('posts')
|
@@ -242,7 +242,7 @@ describe Mongify::Database::Column do
|
|
242
242
|
@column = Mongify::Database::Column.new('created_at', :datetime)
|
243
243
|
end
|
244
244
|
it "should return a datetime format" do
|
245
|
-
@column.send(:type_cast, '2011-01-14 21:23:39').should == Time.
|
245
|
+
@column.send(:type_cast, '2011-01-14 21:23:39').should == Time.utc(2011, 01, 14, 21, 23,39)
|
246
246
|
end
|
247
247
|
it "should return nil if input is nil" do
|
248
248
|
@column.send(:type_cast, nil).should == nil
|
@@ -326,7 +326,7 @@ describe Mongify::Database::Column do
|
|
326
326
|
@column = Mongify::Database::Column.new('created_at', :timestamp)
|
327
327
|
end
|
328
328
|
it "should return a datetime format" do
|
329
|
-
@column.send(:type_cast, '2011-01-14 21:23:39').should == Time.
|
329
|
+
@column.send(:type_cast, '2011-01-14 21:23:39').should == Time.utc(2011, 01, 14, 21, 23,39)
|
330
330
|
end
|
331
331
|
it "should return nil if input is nil" do
|
332
332
|
@column.send(:type_cast, nil).should == nil
|
@@ -337,7 +337,7 @@ describe Mongify::Database::Column do
|
|
337
337
|
@column = Mongify::Database::Column.new('created_at', :time)
|
338
338
|
end
|
339
339
|
it "should return a time format" do
|
340
|
-
@column.send(:type_cast, '21:23:39').should == Time.
|
340
|
+
@column.send(:type_cast, '21:23:39').should == Time.utc(2000, 01, 01, 21, 23,39)
|
341
341
|
end
|
342
342
|
it "should return nil if input is nil" do
|
343
343
|
@column.send(:type_cast, nil).should == nil
|
@@ -348,7 +348,7 @@ describe Mongify::Database::Column do
|
|
348
348
|
@column = Mongify::Database::Column.new('created_at', :date)
|
349
349
|
end
|
350
350
|
it "should return a time format" do
|
351
|
-
@column.send(:type_cast, '2011-01-14').should == Time.
|
351
|
+
@column.send(:type_cast, '2011-01-14').should == Time.utc(2011, 01, 14)
|
352
352
|
end
|
353
353
|
it "should return nil if input is nil" do
|
354
354
|
@column.send(:type_cast, nil).should == nil
|
@@ -65,10 +65,10 @@ describe Mongify::Database::DataRow do
|
|
65
65
|
|
66
66
|
context "respond_to" do
|
67
67
|
it "should be true for first_name" do
|
68
|
-
@datarow.respond_to?('first_name').should
|
68
|
+
@datarow.respond_to?('first_name').should be_truthy
|
69
69
|
end
|
70
70
|
it "should be true for first_name=" do
|
71
|
-
@datarow.respond_to?('first_name=').should
|
71
|
+
@datarow.respond_to?('first_name=').should be_truthy
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -78,7 +78,7 @@ describe Mongify::Database::DataRow do
|
|
78
78
|
end
|
79
79
|
it "should read attributes like delete" do
|
80
80
|
@datarow.delete=true
|
81
|
-
@datarow.read_attribute('delete').should
|
81
|
+
@datarow.read_attribute('delete').should be_truthy
|
82
82
|
end
|
83
83
|
it "should read non existing attributes" do
|
84
84
|
@datarow.read_attributes('monkey').should be_nil
|
@@ -48,7 +48,7 @@ describe Mongify::Database::NoSqlConnection do
|
|
48
48
|
|
49
49
|
context "connection" do
|
50
50
|
before(:each) do
|
51
|
-
@mock_connection =
|
51
|
+
@mock_connection = double(:connected? => true)
|
52
52
|
Mongo::Connection.stub(:new).and_return(@mock_connection)
|
53
53
|
end
|
54
54
|
|
@@ -70,8 +70,8 @@ describe Mongify::Database::NoSqlConnection do
|
|
70
70
|
|
71
71
|
context "database action:" do
|
72
72
|
before(:each) do
|
73
|
-
@collection =
|
74
|
-
@db =
|
73
|
+
@collection = double
|
74
|
+
@db = double
|
75
75
|
@db.stub(:[]).with('users').and_return(@collection)
|
76
76
|
@mongodb_connection.stub(:db).and_return(@db)
|
77
77
|
end
|
@@ -95,7 +95,7 @@ describe Mongify::Database::NoSqlConnection do
|
|
95
95
|
|
96
96
|
context "select_rows" do
|
97
97
|
it "should return all records" do
|
98
|
-
@collection.should_receive(:find).with().and_return([])
|
98
|
+
@collection.should_receive(:find).with(no_args).and_return([])
|
99
99
|
@mongodb_connection.select_rows('users')
|
100
100
|
end
|
101
101
|
end
|
@@ -120,7 +120,7 @@ describe Mongify::Database::NoSqlConnection do
|
|
120
120
|
it "should update the record if its pre_mongified_id exists" do
|
121
121
|
attributes = {'pre_mongified_id' => 1, 'post_id' => 123}
|
122
122
|
id = 10
|
123
|
-
duplicate =
|
123
|
+
duplicate = double
|
124
124
|
duplicate.stub(:[]).with(:_id).and_return(id)
|
125
125
|
@mongodb_connection.stub(:find_one).with('users', {"pre_mongified_id" => 1}).and_return(duplicate)
|
126
126
|
@mongodb_connection.should_receive(:find_one).with('users', {"pre_mongified_id" => 1})
|
@@ -174,7 +174,7 @@ describe Mongify::Database::NoSqlConnection do
|
|
174
174
|
|
175
175
|
context "force" do
|
176
176
|
before(:each) do
|
177
|
-
@mock_connection =
|
177
|
+
@mock_connection = double(:connected? => true, :drop_database => true)
|
178
178
|
Mongo::Connection.stub(:new).and_return(@mock_connection)
|
179
179
|
@mongodb_connection = Mongify::Database::NoSqlConnection.new(:host => 'localhost', :database => 'blue', :force => true)
|
180
180
|
Mongify::UI.stub(:ask).and_return(true)
|
@@ -91,7 +91,7 @@ describe Mongify::Database::SqlConnection do
|
|
91
91
|
|
92
92
|
context "select_all" do
|
93
93
|
it "should generate correct select statement" do
|
94
|
-
@mock_conn =
|
94
|
+
@mock_conn = double
|
95
95
|
@mock_conn.should_receive(:select_all).with('SELECT * FROM users')
|
96
96
|
sqlite_connection.stub(:connection).and_return(@mock_conn)
|
97
97
|
sqlite_connection.select_rows('users')
|
@@ -101,7 +101,7 @@ describe Mongify::Database::SqlConnection do
|
|
101
101
|
context "select_by_query" do
|
102
102
|
it "should select rows based on a query" do
|
103
103
|
query = "SELECT * FROM users WHERE true"
|
104
|
-
@mock_conn =
|
104
|
+
@mock_conn = double
|
105
105
|
@mock_conn.should_receive(:select_all).with(query)
|
106
106
|
sqlite_connection.stub(:connection).and_return(@mock_conn)
|
107
107
|
sqlite_connection.select_by_query(query)
|
@@ -111,7 +111,7 @@ describe Mongify::Database::SqlConnection do
|
|
111
111
|
context "count" do
|
112
112
|
it "should get count of all rows in a table" do
|
113
113
|
query = "SELECT COUNT(*) FROM users"
|
114
|
-
@mock_conn =
|
114
|
+
@mock_conn = double
|
115
115
|
@mock_conn.should_receive(:select_value).with(query)
|
116
116
|
sqlite_connection.stub(:connection).and_return(@mock_conn)
|
117
117
|
sqlite_connection.count('users')
|
@@ -119,7 +119,7 @@ describe Mongify::Database::SqlConnection do
|
|
119
119
|
|
120
120
|
it "should get count of rows in a table filtered by a query" do
|
121
121
|
query = "SELECT COUNT(*) FROM users WHERE true"
|
122
|
-
@mock_conn =
|
122
|
+
@mock_conn = double
|
123
123
|
@mock_conn.should_receive(:select_value).with(query)
|
124
124
|
sqlite_connection.stub(:connection).and_return(@mock_conn)
|
125
125
|
sqlite_connection.count('users', 'true')
|
@@ -129,7 +129,7 @@ describe Mongify::Database::SqlConnection do
|
|
129
129
|
context "execute" do
|
130
130
|
it "should execute an arbitrary query" do
|
131
131
|
query = "CREATE TABLE x(int y);"
|
132
|
-
@mock_conn =
|
132
|
+
@mock_conn = double
|
133
133
|
@mock_conn.should_receive(:execute).with(query)
|
134
134
|
sqlite_connection.stub(:connection).and_return(@mock_conn)
|
135
135
|
sqlite_connection.execute(query)
|
@@ -94,14 +94,14 @@ describe Mongify::Database::Table do
|
|
94
94
|
|
95
95
|
context "add_column" do
|
96
96
|
it "should require Mongify::Database::Column" do
|
97
|
-
|
97
|
+
expect { @table.add_column("Not a column") }.to raise_error(Mongify::DatabaseColumnExpected)
|
98
98
|
end
|
99
99
|
it "shold except Mongify::Database::Column as a parameter" do
|
100
|
-
|
100
|
+
expect { @table.add_column(Mongify::Database::Column.new('test')) }.to_not raise_error
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should add to the column count" do
|
104
|
-
|
104
|
+
expect { @table.add_column(Mongify::Database::Column.new('test')) }.to change{@table.columns.count}.by(1)
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should be indexed" do
|
@@ -286,8 +286,8 @@ describe Mongify::Database::Table do
|
|
286
286
|
|
287
287
|
context "translate" do
|
288
288
|
before(:each) do
|
289
|
-
@column1 =
|
290
|
-
@column2 =
|
289
|
+
@column1 = double(:translate => {'first_name' => 'Timmy'}, :name => 'first_name')
|
290
|
+
@column2 = double(:translate => {'last_name' => 'Zuza'}, :name => 'last_name')
|
291
291
|
@table.stub(:find_column).with(anything).and_return(nil)
|
292
292
|
@table.stub(:find_column).with('first_name').and_return(@column1)
|
293
293
|
@table.stub(:find_column).with('last_name').and_return(@column2)
|
data/spec/mongify/status_spec.rb
CHANGED
@@ -46,7 +46,7 @@ describe Mongify::Translation::Process do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should add pre_mongified_id index to database" do
|
49
|
-
tables = [
|
49
|
+
tables = [double(:name => 'users')]
|
50
50
|
@translation.stub(:copy_tables).and_return(tables)
|
51
51
|
@no_sql_connection.should_receive(:create_pre_mongified_id_index).with('users')
|
52
52
|
@translation.process(@sql_connection, @no_sql_connection)
|
@@ -61,20 +61,20 @@ describe Mongify::Translation::Process do
|
|
61
61
|
|
62
62
|
context "fetch_reference_ids" do
|
63
63
|
it "should get correct information" do
|
64
|
-
@no_sql_connection =
|
64
|
+
@no_sql_connection = double()
|
65
65
|
@translation.stub(:no_sql_connection).and_return(@no_sql_connection)
|
66
|
-
@table =
|
67
|
-
@column =
|
66
|
+
@table = double(:translate => {}, :name => 'users', :embedded? => false, :find_column => nil)
|
67
|
+
@column = double(:name => 'user_id', :references => 'users')
|
68
68
|
@table.stub(:reference_columns).and_return([@column])
|
69
69
|
@no_sql_connection.should_receive(:get_id_using_pre_mongified_id).with('users', 1).once.and_return(500)
|
70
70
|
@translation.send(:fetch_reference_ids, @table, {'user_id' => 1}).should == {'user_id' => 500}
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should get correct information for arrays" do
|
74
|
-
@no_sql_connection =
|
74
|
+
@no_sql_connection = double()
|
75
75
|
@translation.stub(:no_sql_connection).and_return(@no_sql_connection)
|
76
|
-
@table =
|
77
|
-
@column =
|
76
|
+
@table = double(:translate => {}, :name => 'users', :embedded? => false)
|
77
|
+
@column = double(:name => 'user_ids', :references => 'users')
|
78
78
|
@table.stub(:reference_columns).and_return([@column])
|
79
79
|
@no_sql_connection.should_receive(:get_id_using_pre_mongified_id).with('users', 1).once.and_return(500)
|
80
80
|
@no_sql_connection.should_receive(:get_id_using_pre_mongified_id).with('users', 2).once.and_return(501)
|
@@ -87,10 +87,10 @@ describe Mongify::Translation::Process do
|
|
87
87
|
@sql_connection.stub(:select_paged_rows).and_return([{'first_name'=> 'Timmy', 'last_name' => 'Zuza', 'preference_id' => 1}])
|
88
88
|
@translation.stub(:sql_connection).and_return(@sql_connection)
|
89
89
|
|
90
|
-
@no_sql_connection =
|
90
|
+
@no_sql_connection = double()
|
91
91
|
@translation.stub(:no_sql_connection).and_return(@no_sql_connection)
|
92
92
|
|
93
|
-
@table =
|
93
|
+
@table = double(:translate => {'first_name'=> 'Timmy', 'last_name' => 'Zuza', 'preference_id' => 1},
|
94
94
|
:name => 'users',
|
95
95
|
:embedded? => false,
|
96
96
|
:sql_name => 'users')
|
@@ -113,8 +113,8 @@ describe Mongify::Translation::Process do
|
|
113
113
|
context "copy_embed_tables" do
|
114
114
|
before(:each) do
|
115
115
|
@sql_connection.stub(:select_paged_rows).and_return([{'first_name'=> 'Timmy', 'last_name' => 'Zuza', 'preference_id' => 1}])
|
116
|
-
@target_table =
|
117
|
-
@embed_table =
|
116
|
+
@target_table = double(:name => 'posts', :embedded? => false, :sql_name => 'posts')
|
117
|
+
@embed_table = double(:translate => {}, :name => 'comments', :embedded? => true, :embed_on => 'post_id', :embed_in => 'posts', :embedded_as_object? => false, :sql_name => 'comments', :find_column => nil)
|
118
118
|
@no_sql_connection.stub(:find_one).and_return({'_id' => 500})
|
119
119
|
@translation.stub(:tables).and_return([@target_table, @embed_table])
|
120
120
|
@translation.stub(:fetch_reference_ids).and_return({})
|
@@ -126,25 +126,25 @@ describe Mongify::Translation::Process do
|
|
126
126
|
@translation.send(:copy_embedded_tables)
|
127
127
|
end
|
128
128
|
it "should remove the pre_mongified_id before embedding" do
|
129
|
-
@embed_table =
|
129
|
+
@embed_table = double(:translate => {'first_name' => 'bob', 'pre_mongified_id' => 1}, :name => 'comments', :sql_name => 'comments', :embedded? => true, :embed_on => 'post_id', :embed_in => 'posts', :embedded_as_object? => false, :find_column => nil)
|
130
130
|
@translation.stub(:tables).and_return([@target_table, @embed_table])
|
131
131
|
@no_sql_connection.should_receive(:update).with("posts", 500, {"$addToSet"=>{"comments"=>{'first_name' => 'bob'}}})
|
132
132
|
@translation.send(:copy_embedded_tables)
|
133
133
|
end
|
134
134
|
it "should remove the parent_id from the embedding row" do
|
135
|
-
@embed_table =
|
135
|
+
@embed_table = double(:translate => {'first_name' => 'bob', 'post_id' => 1}, :name => 'comments', :sql_name => 'comments', :embedded? => true, :embed_on => 'post_id', :embed_in => 'posts', :embedded_as_object? => false, :find_column => nil)
|
136
136
|
@translation.stub(:tables).and_return([@target_table, @embed_table])
|
137
137
|
@no_sql_connection.should_receive(:update).with("posts", 500, {"$addToSet"=>{"comments"=>{'first_name' => 'bob'}}})
|
138
138
|
@translation.send(:copy_embedded_tables)
|
139
139
|
end
|
140
140
|
it "should call $addToSet on update of an embed_as_object table" do
|
141
|
-
@embed_table =
|
141
|
+
@embed_table = double(:translate => {'first_name' => 'bob', 'post_id' => 1}, :name => 'comments', :sql_name => 'comments', :embedded? => true, :embed_on => 'post_id', :embed_in => 'posts', :embedded_as_object? => true, :find_column => nil)
|
142
142
|
@translation.stub(:tables).and_return([@target_table, @embed_table])
|
143
143
|
@no_sql_connection.should_receive(:update).with("posts", 500, {"$set"=>{"comments"=>{'first_name' => 'bob'}}})
|
144
144
|
@translation.send(:copy_embedded_tables)
|
145
145
|
end
|
146
146
|
it "should allow rename of table" do
|
147
|
-
@embed_table =
|
147
|
+
@embed_table = double(:translate => {'first_name' => 'bob', 'post_id' => 1}, :name => 'notes', :sql_name => 'comments', :embedded? => true, :embed_on => 'post_id', :embed_in => 'posts', :embedded_as_object? => true, :find_column => nil)
|
148
148
|
@translation.stub(:tables).and_return([@target_table, @embed_table])
|
149
149
|
@no_sql_connection.should_receive(:update).with("posts", 500, {"$set"=>{"notes"=>{'first_name' => 'bob'}}})
|
150
150
|
@translation.send(:copy_embedded_tables)
|
@@ -152,25 +152,25 @@ describe Mongify::Translation::Process do
|
|
152
152
|
|
153
153
|
context "parent modification" do
|
154
154
|
it 'should unset fields deleted in the parent row' do
|
155
|
-
@embed_table =
|
155
|
+
@embed_table = double(:translate => [{}, {'email' => 'true'}, {'field_1' => '1'}], :name => 'preferences', :sql_name => 'preferences', :embedded? => true, :embed_on => 'post_id', :embed_in => 'posts', :embedded_as_object? => true, :find_column => nil)
|
156
156
|
@translation.stub(:tables).and_return([@target_table, @embed_table])
|
157
157
|
@no_sql_connection.should_receive(:update).with("posts", 500, {"$set"=>{"preferences"=>{}, "email"=>"true"}, "$unset"=>{'field_1' => '1'}})
|
158
158
|
@translation.send(:copy_embedded_tables)
|
159
159
|
end
|
160
160
|
it "should work with embedded objects" do
|
161
|
-
@embed_table =
|
161
|
+
@embed_table = double(:translate => [{}, {'email' => 'true'}, {}], :name => 'preferences', :sql_name => 'preferences', :embedded? => true, :embed_on => 'post_id', :embed_in => 'posts', :embedded_as_object? => true, :find_column => nil)
|
162
162
|
@translation.stub(:tables).and_return([@target_table, @embed_table])
|
163
163
|
@no_sql_connection.should_receive(:update).with("posts", 500, {"$set"=>{"preferences"=>{}, "email"=>"true"}})
|
164
164
|
@translation.send(:copy_embedded_tables)
|
165
165
|
end
|
166
166
|
it "should work with embedded arrays" do
|
167
|
-
@embed_table =
|
167
|
+
@embed_table = double(:translate => [{}, {'email' => 'true'}, {}], :name => 'preferences', :sql_name => 'preferences', :embedded? => true, :embed_on => 'post_id', :embed_in => 'posts', :embedded_as_object? => false, :find_column => nil)
|
168
168
|
@translation.stub(:tables).and_return([@target_table, @embed_table])
|
169
169
|
@no_sql_connection.should_receive(:update).with("posts", 500, {"$addToSet"=>{"preferences"=>{}}, "$set" => {"email"=>"true"}})
|
170
170
|
@translation.send(:copy_embedded_tables)
|
171
171
|
end
|
172
172
|
it "should not set embedded attribute in parent" do
|
173
|
-
@embed_table =
|
173
|
+
@embed_table = double(:translate => [{'first_name' => 'joe'}, {'email' => 'true', 'comments' => [{'first_name' => 'bob'}]}, {}], :name => 'comments', :sql_name => 'comments', :embedded? => true, :embed_on => 'post_id', :embed_in => 'posts', :embedded_as_object? => false, :find_column => nil)
|
174
174
|
@translation.stub(:tables).and_return([@target_table, @embed_table])
|
175
175
|
@no_sql_connection.should_receive(:update).with("posts", 500, {"$addToSet" => {"comments" => {"first_name" => "joe"}}, "$set" => {"email" => "true"}})
|
176
176
|
@translation.send(:copy_embedded_tables)
|
@@ -210,14 +210,14 @@ describe Mongify::Translation::Process do
|
|
210
210
|
it "should work correctly" do
|
211
211
|
@no_sql_connection.should_receive(:select_rows).and_return([{'_id' => 100, 'user_id' => 1}, {'_id'=> 101, 'user_id' => 2}])
|
212
212
|
@no_sql_connection.stub(:get_id_using_pre_mongified_id).twice.and_return(500)
|
213
|
-
@table.should_receive(:reference_columns).twice.and_return([
|
213
|
+
@table.should_receive(:reference_columns).twice.and_return([double(:name => 'user_id', :references=>'users')])
|
214
214
|
@no_sql_connection.should_receive(:update).twice
|
215
215
|
@translation.send(:update_reference_ids)
|
216
216
|
end
|
217
217
|
it "should only update when new_id is present" do
|
218
218
|
@no_sql_connection.should_receive(:select_rows).and_return([{'_id' => 100, 'user_id' => 1}, {'_id'=> 101, 'user_id' => 2}])
|
219
219
|
@no_sql_connection.stub(:get_id_using_pre_mongified_id).twice.and_return(nil)
|
220
|
-
@table.should_receive(:reference_columns).twice.and_return([
|
220
|
+
@table.should_receive(:reference_columns).twice.and_return([double(:name => 'user_id', :references=>'users')])
|
221
221
|
@no_sql_connection.should_receive(:update).never
|
222
222
|
@translation.send(:update_reference_ids)
|
223
223
|
end
|
@@ -225,7 +225,7 @@ describe Mongify::Translation::Process do
|
|
225
225
|
|
226
226
|
context "copy_polymorphic_tables" do
|
227
227
|
before(:each) do
|
228
|
-
@ref_table =
|
228
|
+
@ref_table = double(:name => 'user_accounts',
|
229
229
|
:embedded? => false,
|
230
230
|
:ignored? => false,
|
231
231
|
:sql_name => 'user_accounts')
|
@@ -236,7 +236,7 @@ describe Mongify::Translation::Process do
|
|
236
236
|
end
|
237
237
|
context "embedded" do
|
238
238
|
it "should work correctly" do
|
239
|
-
@table =
|
239
|
+
@table = double(:translate => {'data' => 123},
|
240
240
|
:name => 'comments',
|
241
241
|
:embedded? => true,
|
242
242
|
:polymorphic_as => 'commentable',
|
@@ -255,7 +255,7 @@ describe Mongify::Translation::Process do
|
|
255
255
|
end
|
256
256
|
context "not embedded" do
|
257
257
|
before(:each) do
|
258
|
-
@table =
|
258
|
+
@table = double(:translate => {'data' => 123, 'commentable_type' => 'UserAccount', 'commentable_id' => 1},
|
259
259
|
:name => 'comments',
|
260
260
|
:embedded? => false,
|
261
261
|
:polymorphic_as => 'commentable',
|