mongify 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +8 -0
- data/Gemfile.lock +1 -1
- data/README.rdoc +40 -16
- data/features/options.feature +3 -7
- data/features/print.feature +1 -1
- data/features/process.feature +0 -1
- data/features/support/env.rb +4 -1
- data/lib/mongify.rb +3 -1
- data/lib/mongify/cli.rb +0 -1
- data/lib/mongify/cli/application.rb +10 -1
- data/lib/mongify/cli/help_command.rb +1 -0
- data/lib/mongify/cli/options.rb +13 -14
- data/lib/mongify/cli/version_command.rb +1 -0
- data/lib/mongify/cli/worker_command.rb +15 -7
- data/lib/mongify/configuration.rb +14 -12
- data/lib/mongify/database.rb +2 -1
- data/lib/mongify/database/base_connection.rb +25 -15
- data/lib/mongify/database/column.rb +99 -21
- data/lib/mongify/database/data_row.rb +67 -0
- data/lib/mongify/database/no_sql_connection.rb +48 -10
- data/lib/mongify/database/sql_connection.rb +34 -4
- data/lib/mongify/database/table.rb +69 -7
- data/lib/mongify/exceptions.rb +7 -0
- data/lib/mongify/translation.rb +45 -2
- data/lib/mongify/translation/printer.rb +4 -3
- data/lib/mongify/translation/process.rb +11 -4
- data/lib/mongify/ui.rb +10 -1
- data/lib/mongify/version.rb +2 -1
- data/spec/mongify/cli/worker_command_spec.rb +3 -4
- data/spec/mongify/configuration_spec.rb +6 -12
- data/spec/mongify/database/base_connection_spec.rb +7 -3
- data/spec/mongify/database/column_spec.rb +171 -28
- data/spec/mongify/database/data_row_spec.rb +102 -0
- data/spec/mongify/database/no_sql_connection_spec.rb +4 -6
- data/spec/mongify/database/table_spec.rb +23 -2
- data/spec/mongify/translation/printer_spec.rb +3 -3
- data/spec/support/config_reader.rb +3 -1
- data/spec/support/generate_database.rb +7 -0
- metadata +7 -5
- data/lib/mongify/cli/report.rb +0 -11
data/lib/mongify/version.rb
CHANGED
@@ -59,14 +59,14 @@ describe Mongify::CLI::WorkerCommand do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
context "
|
62
|
+
context "translation command" do
|
63
63
|
before(:each) do
|
64
|
-
@command = Mongify::CLI::WorkerCommand.new('
|
64
|
+
@command = Mongify::CLI::WorkerCommand.new('translation', @config)
|
65
65
|
Mongify::Translation.stub(:load).with(@sql_connection).and_return(stub(:print => 'worked'))
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should require configuration file" do
|
69
|
-
lambda { Mongify::CLI::WorkerCommand.new('
|
69
|
+
lambda { Mongify::CLI::WorkerCommand.new('translation').execute(@view) }.should raise_error(Mongify::ConfigurationFileNotFound)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should check sql connection" do
|
@@ -105,7 +105,6 @@ describe Mongify::CLI::WorkerCommand do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should call process on translation" do
|
108
|
-
puts @config.no_sql_connection.inspect
|
109
108
|
Mongify::Translation.should_receive(:parse).and_return(mock(:process => true))
|
110
109
|
@command.execute(@view)
|
111
110
|
end
|
@@ -2,23 +2,17 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Mongify::Configuration do
|
4
4
|
before(:each) do
|
5
|
-
Mongify::Translation.stub(:parse)
|
6
|
-
@translation_file = File.expand_path(File.dirname(__FILE__) + '/../files/empty_translation.rb')
|
7
5
|
@configuration_file = File.expand_path(File.dirname(__FILE__) + '/../files/base_configuration.rb')
|
8
6
|
end
|
9
|
-
it "should parse file for transaltion" do
|
10
|
-
Mongify::Translation.should_receive(:parse).and_return(true)
|
11
|
-
Mongify::Configuration.parse_translation(@translation_file)
|
12
|
-
end
|
13
7
|
|
14
|
-
context "
|
15
|
-
it "should parse
|
16
|
-
Mongify::Configuration.
|
17
|
-
|
8
|
+
context "parse" do
|
9
|
+
it "should parse correctly" do
|
10
|
+
c = Mongify::Configuration.parse(@configuration_file)
|
11
|
+
c.sql_connection.should be_valid
|
12
|
+
c.no_sql_connection.should be_valid
|
18
13
|
end
|
19
|
-
|
20
14
|
it "should validate file exists" do
|
21
|
-
lambda { Mongify::Configuration.
|
15
|
+
lambda { Mongify::Configuration.parse("../missing_file.rb") }.should raise_error(Mongify::FileNotFound)
|
22
16
|
end
|
23
17
|
|
24
18
|
end
|
@@ -4,9 +4,13 @@ describe Mongify::Database::BaseConnection do
|
|
4
4
|
before(:each) do
|
5
5
|
@base_connection = Mongify::Database::BaseConnection.new
|
6
6
|
end
|
7
|
-
it "should set any variable name that's passed" do
|
8
|
-
@base_connection = Mongify::Database::BaseConnection.new(:
|
9
|
-
@base_connection.instance_variables.should =~ ['@
|
7
|
+
it "should set any allowed variable name that's passed" do
|
8
|
+
@base_connection = Mongify::Database::BaseConnection.new(:host => 'blue', :adapter => 'good')
|
9
|
+
@base_connection.instance_variables.should =~ ['@host', '@adapter']
|
10
|
+
end
|
11
|
+
it "should not set unknown variables on init" do
|
12
|
+
@base_connection = Mongify::Database::BaseConnection.new(:apple => 'blue')
|
13
|
+
@base_connection.instance_variables.should == []
|
10
14
|
end
|
11
15
|
|
12
16
|
context "validation" do
|
@@ -12,6 +12,11 @@ describe Mongify::Database::Column do
|
|
12
12
|
@column.sql_name.should == 'first_name'
|
13
13
|
end
|
14
14
|
|
15
|
+
it "should allow you to omit the type while giving options" do
|
16
|
+
@column = Mongify::Database::Column.new('account_id', :references => 'accounts')
|
17
|
+
@column.options.should == {'references' => 'accounts'}
|
18
|
+
end
|
19
|
+
|
15
20
|
it "should get setup options" do
|
16
21
|
@column = Mongify::Database::Column.new('account_id', :integer, :references => 'accounts')
|
17
22
|
@column.options.should == {'references' => 'accounts'}
|
@@ -22,6 +27,53 @@ describe Mongify::Database::Column do
|
|
22
27
|
@column.type.should == :string
|
23
28
|
end
|
24
29
|
|
30
|
+
context "auto_detect!" do
|
31
|
+
it "should not auto detect automatically" do
|
32
|
+
Mongify::Database::Column.should_receive(:auto_detect).never
|
33
|
+
@column = Mongify::Database::Column.new('id', :integer)
|
34
|
+
@column.should_not be_key
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should auto_detect when option is passed in" do
|
38
|
+
@column = Mongify::Database::Column.new('id', :integer, :auto_detect => true)
|
39
|
+
@column.should be_key
|
40
|
+
end
|
41
|
+
|
42
|
+
context "id column" do
|
43
|
+
before(:each) do
|
44
|
+
@col = mock(:sql_name => 'id', :type => :integer)
|
45
|
+
end
|
46
|
+
it "should detect column with type :integer as a :key column" do
|
47
|
+
@col.should_receive('type=').with(:key)
|
48
|
+
Mongify::Database::Column.auto_detect(@col)
|
49
|
+
end
|
50
|
+
it "should not detect column with type other then :integer as a :key column" do
|
51
|
+
@col.stub(:type).and_return(:string)
|
52
|
+
@col.should_receive('type=').never
|
53
|
+
Mongify::Database::Column.auto_detect(@col)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
context "references" do
|
57
|
+
before(:each) do
|
58
|
+
@col = mock(:sql_name => 'post_id', :type => :integer, :referenced? => false)
|
59
|
+
end
|
60
|
+
it "should detect column references" do
|
61
|
+
@col.should_receive('references=').with('posts')
|
62
|
+
Mongify::Database::Column.auto_detect(@col)
|
63
|
+
end
|
64
|
+
it "should not detect column references if it's already referenced" do
|
65
|
+
@col.stub(:referenced?).and_return(true)
|
66
|
+
@col.should_receive('references=').never
|
67
|
+
Mongify::Database::Column.auto_detect(@col)
|
68
|
+
end
|
69
|
+
it "should not detect column referneces if column type is not :integer" do
|
70
|
+
@col.stub(:type).and_return(:string)
|
71
|
+
@col.should_receive('references=').never
|
72
|
+
Mongify::Database::Column.auto_detect(@col)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
25
77
|
context "key?" do
|
26
78
|
it "should be true" do
|
27
79
|
@column = Mongify::Database::Column.new('id', :key)
|
@@ -70,24 +122,6 @@ describe Mongify::Database::Column do
|
|
70
122
|
end
|
71
123
|
end
|
72
124
|
|
73
|
-
context "auto_detect" do
|
74
|
-
context "id" do
|
75
|
-
it "should type to key" do
|
76
|
-
@column = Mongify::Database::Column.new('id', :integer)
|
77
|
-
@column.type.should == :key
|
78
|
-
end
|
79
|
-
it "should not set type to key if original type is not integer" do
|
80
|
-
@column = Mongify::Database::Column.new('id', :string)
|
81
|
-
@column.type.should == :string
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should detect references" do
|
86
|
-
@column = Mongify::Database::Column.new('user_id', :integer)
|
87
|
-
@column.references.should == "users"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
125
|
context :to_print do
|
92
126
|
before(:each) do
|
93
127
|
@column = Mongify::Database::Column.new('first_name', :string)
|
@@ -95,8 +129,11 @@ describe Mongify::Database::Column do
|
|
95
129
|
it "should output column name and type" do
|
96
130
|
@column.to_print.should == %Q[column "first_name", :string]
|
97
131
|
end
|
132
|
+
it "should output the same when called .to_s" do
|
133
|
+
@column.to_s.should == %Q[column "first_name", :string]
|
134
|
+
end
|
98
135
|
it "should detect references" do
|
99
|
-
@column = Mongify::Database::Column.new('user_id', :integer)
|
136
|
+
@column = Mongify::Database::Column.new('user_id', :integer, :auto_detect => true)
|
100
137
|
@column.to_print.should == %Q[column "user_id", :integer, :references => "users"]
|
101
138
|
end
|
102
139
|
end
|
@@ -118,14 +155,26 @@ describe Mongify::Database::Column do
|
|
118
155
|
@column.should be_ignored
|
119
156
|
@column.translate('bob').should == {}
|
120
157
|
end
|
158
|
+
|
159
|
+
it "should return pre_mongified_id when type is a key" do
|
160
|
+
@column = Mongify::Database::Column.new('id', :key)
|
161
|
+
@column.translate(123123).should == {"pre_mongified_id" => 123123}
|
162
|
+
end
|
163
|
+
end
|
164
|
+
context :type_cast do
|
165
|
+
it "should return value if unknown type" do
|
166
|
+
@column = Mongify::Database::Column.new('first_name', :car)
|
167
|
+
@column.send(:type_cast, 'bob').should == 'bob'
|
168
|
+
end
|
121
169
|
context "datetime" do
|
122
|
-
|
170
|
+
before(:each) do
|
123
171
|
@column = Mongify::Database::Column.new('created_at', :datetime)
|
124
|
-
|
172
|
+
end
|
173
|
+
it "should return a datetime format" do
|
174
|
+
@column.send(:type_cast, '2011-01-14 21:23:39').should == Time.local(2011, 01, 14, 21, 23,39)
|
125
175
|
end
|
126
176
|
it "should return nil if input is nil" do
|
127
|
-
@column
|
128
|
-
@column.translate(nil).should == {'created_at' => nil}
|
177
|
+
@column.send(:type_cast, nil).should == nil
|
129
178
|
end
|
130
179
|
end
|
131
180
|
context :integer do
|
@@ -133,13 +182,107 @@ describe Mongify::Database::Column do
|
|
133
182
|
@column = Mongify::Database::Column.new('account_id', :integer)
|
134
183
|
end
|
135
184
|
it "should return 10" do
|
136
|
-
@column.
|
185
|
+
@column.send(:type_cast, "10").should == 10
|
186
|
+
end
|
187
|
+
it "should return 0 when string given" do
|
188
|
+
@column.send(:type_cast, "bob").should == 0
|
137
189
|
end
|
138
190
|
end
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
191
|
+
context :text do
|
192
|
+
it "should return a string" do
|
193
|
+
@column = Mongify::Database::Column.new('body', :text)
|
194
|
+
@column.send(:type_cast, "Something of a body").should == "Something of a body"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
context :float do
|
198
|
+
before(:each) do
|
199
|
+
@column = Mongify::Database::Column.new('price', :float)
|
200
|
+
end
|
201
|
+
it "should convert numbers to floats" do
|
202
|
+
@column.send(:type_cast, 101.43).should == 101.43
|
203
|
+
end
|
204
|
+
it "should convert integers to floats" do
|
205
|
+
@column.send(:type_cast, 101).should == 101.0
|
206
|
+
end
|
207
|
+
it "should convert strings to 0.0" do
|
208
|
+
@column.send(:type_cast, 'zuza').should == 0.0
|
209
|
+
end
|
210
|
+
end
|
211
|
+
context :decimal do
|
212
|
+
before(:each) do
|
213
|
+
@column = Mongify::Database::Column.new('price', :decimal)
|
214
|
+
end
|
215
|
+
it "should convert numbers to decimal" do
|
216
|
+
@column.send(:type_cast, 101.43).should == BigDecimal.new("101.43")
|
217
|
+
end
|
218
|
+
it "should convert integers to decimal" do
|
219
|
+
@column.send(:type_cast, 101).should == BigDecimal.new("101.0")
|
220
|
+
end
|
221
|
+
it "should convert strings to 0.0" do
|
222
|
+
@column.send(:type_cast, 'zuza').should == BigDecimal.new("0")
|
223
|
+
end
|
224
|
+
end
|
225
|
+
context :timestamp do
|
226
|
+
before(:each) do
|
227
|
+
@column = Mongify::Database::Column.new('created_at', :timestamp)
|
228
|
+
end
|
229
|
+
it "should return a datetime format" do
|
230
|
+
@column.send(:type_cast, '2011-01-14 21:23:39').should == Time.local(2011, 01, 14, 21, 23,39)
|
231
|
+
end
|
232
|
+
it "should return nil if input is nil" do
|
233
|
+
@column.send(:type_cast, nil).should == nil
|
234
|
+
end
|
235
|
+
end
|
236
|
+
context :time do
|
237
|
+
before(:each) do
|
238
|
+
@column = Mongify::Database::Column.new('created_at', :time)
|
239
|
+
end
|
240
|
+
it "should return a time format" do
|
241
|
+
@column.send(:type_cast, '21:23:39').should == Time.local(2000, 01, 01, 21, 23,39)
|
242
|
+
end
|
243
|
+
it "should return nil if input is nil" do
|
244
|
+
@column.send(:type_cast, nil).should == nil
|
245
|
+
end
|
246
|
+
end
|
247
|
+
context :date do
|
248
|
+
before(:each) do
|
249
|
+
@column = Mongify::Database::Column.new('created_at', :date)
|
250
|
+
end
|
251
|
+
it "should return a time format" do
|
252
|
+
@column.send(:type_cast, '2011-01-14').should == Time.local(2011, 01, 14)
|
253
|
+
end
|
254
|
+
it "should return nil if input is nil" do
|
255
|
+
@column.send(:type_cast, nil).should == nil
|
256
|
+
end
|
257
|
+
end
|
258
|
+
context :binary do
|
259
|
+
it "should return a string" do
|
260
|
+
@column = Mongify::Database::Column.new('body', :binary)
|
261
|
+
@column.send(:type_cast, "Something of a body").should == "Something of a body"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
context :boolean do
|
265
|
+
before(:each) do
|
266
|
+
@column = Mongify::Database::Column.new('email_me', :boolean)
|
267
|
+
end
|
268
|
+
it "should be true when true" do
|
269
|
+
result = true
|
270
|
+
@column.send(:type_cast, "true").should == result
|
271
|
+
@column.send(:type_cast, "1").should == result
|
272
|
+
@column.send(:type_cast, "T").should == result
|
273
|
+
end
|
274
|
+
it "should be false when false" do
|
275
|
+
result = false
|
276
|
+
@column.send(:type_cast, "false").should == result
|
277
|
+
@column.send(:type_cast, "0").should == result
|
278
|
+
@column.send(:type_cast, "F").should == result
|
279
|
+
end
|
280
|
+
it "should be nil if nil or blank" do
|
281
|
+
result = nil
|
282
|
+
@column.send(:type_cast, nil).should == result
|
283
|
+
@column.send(:type_cast, "").should == result
|
284
|
+
end
|
285
|
+
|
143
286
|
end
|
144
287
|
end
|
145
288
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongify::Database::DataRow do
|
4
|
+
before(:each) do
|
5
|
+
@hash = {'first_name' => 'Timmy', 'last_name' => 'Zuza', 'age' => 21, 'create_at' => Time.now}
|
6
|
+
@datarow = Mongify::Database::DataRow.new(@hash)
|
7
|
+
end
|
8
|
+
it "should have method access to hash values" do
|
9
|
+
@datarow.first_name.should == 'Timmy'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should dup the hash" do
|
13
|
+
@hash = {:first_name => 'Bob'}
|
14
|
+
@hash.should_receive(:dup).and_return(@hash)
|
15
|
+
dr = Mongify::Database::DataRow.new(@hash)
|
16
|
+
end
|
17
|
+
it "should strigify_keys!" do
|
18
|
+
@hash = {:first_name => 'Bob'}
|
19
|
+
@hash.stub(:dup).and_return(@hash)
|
20
|
+
@hash.should_receive(:stringify_keys!)
|
21
|
+
dr = Mongify::Database::DataRow.new(@hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have a working include? method" do
|
25
|
+
@datarow.should include('first_name')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be able to set a value" do
|
29
|
+
@datarow.first_name = 'Bob'
|
30
|
+
@datarow.first_name.should == 'Bob'
|
31
|
+
end
|
32
|
+
it "should allow me to set a new key" do
|
33
|
+
@datarow.height = 6
|
34
|
+
@datarow.should include('height')
|
35
|
+
@datarow.height.should == 6
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should to_hash" do
|
39
|
+
@datarow.to_hash.should == @hash
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should allow inspect" do
|
43
|
+
@datarow.inspect.should == @hash.inspect
|
44
|
+
end
|
45
|
+
|
46
|
+
context "delete" do
|
47
|
+
it "should delete key" do
|
48
|
+
@datarow.delete('age')
|
49
|
+
@datarow.should_not include('age')
|
50
|
+
end
|
51
|
+
it "should return value of item being delete" do
|
52
|
+
age = @datarow.age
|
53
|
+
@datarow.delete('age').should == age
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should work with an empty hash" do
|
58
|
+
dr = Mongify::Database::DataRow.new({})
|
59
|
+
dr.keys.should be_empty
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return all keys in object" do
|
63
|
+
@datarow.keys.should == @hash.keys
|
64
|
+
end
|
65
|
+
|
66
|
+
context "respond_to" do
|
67
|
+
it "should be true for first_name" do
|
68
|
+
@datarow.respond_to?('first_name').should be_true
|
69
|
+
end
|
70
|
+
it "should be true for first_name=" do
|
71
|
+
@datarow.respond_to?('first_name=').should be_true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "read_attributes" do
|
76
|
+
it "should read attributes" do
|
77
|
+
@datarow.read_attribute('first_name').should == @hash['first_name']
|
78
|
+
end
|
79
|
+
it "should read attributes like delete" do
|
80
|
+
@datarow.delete=true
|
81
|
+
@datarow.read_attribute('delete').should be_true
|
82
|
+
end
|
83
|
+
it "should read non existing attributes" do
|
84
|
+
@datarow.read_attributes('monkey').should be_nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "write_attribute" do
|
89
|
+
it "should write attributes" do
|
90
|
+
@datarow.write_attribute('first_name', 'Sam')
|
91
|
+
@datarow.first_name.should == 'Sam'
|
92
|
+
end
|
93
|
+
it "should write non existing attributes" do
|
94
|
+
@datarow.write_attribute('apple', 'good')
|
95
|
+
@datarow.apple.should == "good"
|
96
|
+
end
|
97
|
+
it "should write attributes like delete" do
|
98
|
+
@datarow.write_attribute('delete', 'yes')
|
99
|
+
@datarow.read_attribute('delete').should == "yes"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -24,6 +24,10 @@ describe Mongify::Database::NoSqlConnection do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
it "should rename mongo to mongodb for adapter" do
|
28
|
+
Mongify::Database::NoSqlConnection.new(:host => 'localhost', :database => 'blue', :adapter => 'mongo').adapter.should == 'mongodb'
|
29
|
+
end
|
30
|
+
|
27
31
|
context "connection string" do
|
28
32
|
before(:each) do
|
29
33
|
@mongodb_connection.host @host
|
@@ -61,12 +65,6 @@ describe Mongify::Database::NoSqlConnection do
|
|
61
65
|
@mongodb_connection.connection
|
62
66
|
end
|
63
67
|
|
64
|
-
it "should reset connection on reset" do
|
65
|
-
Mongo::Connection.should_receive(:new).twice
|
66
|
-
@mongodb_connection.connection
|
67
|
-
@mongodb_connection.reset!
|
68
|
-
@mongodb_connection.connection
|
69
|
-
end
|
70
68
|
end
|
71
69
|
|
72
70
|
|