mongify 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGELOG.rdoc +8 -0
  2. data/Gemfile.lock +1 -1
  3. data/README.rdoc +40 -16
  4. data/features/options.feature +3 -7
  5. data/features/print.feature +1 -1
  6. data/features/process.feature +0 -1
  7. data/features/support/env.rb +4 -1
  8. data/lib/mongify.rb +3 -1
  9. data/lib/mongify/cli.rb +0 -1
  10. data/lib/mongify/cli/application.rb +10 -1
  11. data/lib/mongify/cli/help_command.rb +1 -0
  12. data/lib/mongify/cli/options.rb +13 -14
  13. data/lib/mongify/cli/version_command.rb +1 -0
  14. data/lib/mongify/cli/worker_command.rb +15 -7
  15. data/lib/mongify/configuration.rb +14 -12
  16. data/lib/mongify/database.rb +2 -1
  17. data/lib/mongify/database/base_connection.rb +25 -15
  18. data/lib/mongify/database/column.rb +99 -21
  19. data/lib/mongify/database/data_row.rb +67 -0
  20. data/lib/mongify/database/no_sql_connection.rb +48 -10
  21. data/lib/mongify/database/sql_connection.rb +34 -4
  22. data/lib/mongify/database/table.rb +69 -7
  23. data/lib/mongify/exceptions.rb +7 -0
  24. data/lib/mongify/translation.rb +45 -2
  25. data/lib/mongify/translation/printer.rb +4 -3
  26. data/lib/mongify/translation/process.rb +11 -4
  27. data/lib/mongify/ui.rb +10 -1
  28. data/lib/mongify/version.rb +2 -1
  29. data/spec/mongify/cli/worker_command_spec.rb +3 -4
  30. data/spec/mongify/configuration_spec.rb +6 -12
  31. data/spec/mongify/database/base_connection_spec.rb +7 -3
  32. data/spec/mongify/database/column_spec.rb +171 -28
  33. data/spec/mongify/database/data_row_spec.rb +102 -0
  34. data/spec/mongify/database/no_sql_connection_spec.rb +4 -6
  35. data/spec/mongify/database/table_spec.rb +23 -2
  36. data/spec/mongify/translation/printer_spec.rb +3 -3
  37. data/spec/support/config_reader.rb +3 -1
  38. data/spec/support/generate_database.rb +7 -0
  39. metadata +7 -5
  40. data/lib/mongify/cli/report.rb +0 -11
@@ -116,7 +116,7 @@ describe Mongify::Database::Table do
116
116
 
117
117
  context "reference_colums" do
118
118
  before(:each) do
119
- @col1 = Mongify::Database::Column.new('user_id', :integer, :referneces => :users)
119
+ @col1 = Mongify::Database::Column.new('user_id', :integer, :references => 'users')
120
120
  @col2 = Mongify::Database::Column.new('post_id', :integer, :references => 'posts')
121
121
  @columns = [@col1,
122
122
  Mongify::Database::Column.new('body'),
@@ -124,7 +124,7 @@ describe Mongify::Database::Table do
124
124
  @table = Mongify::Database::Table.new('comments', :columns => @columns)
125
125
  end
126
126
  it "should return an array of columns" do
127
- @table.reference_columns.should == [@col1, @col2]
127
+ @table.reference_columns.should =~ [@col1, @col2]
128
128
  end
129
129
  end
130
130
 
@@ -181,6 +181,27 @@ describe Mongify::Database::Table do
181
181
  end
182
182
  end
183
183
 
184
+ context "before_save" do
185
+ before(:each) do
186
+ @table = Mongify::Database::Table.new('users')
187
+ @table.before_save do |row|
188
+ puts "my keys are: #{row.keys}"
189
+ row.admin = row.delete('permission').to_i > 50
190
+ end
191
+ end
192
+ context "run_before_save" do
193
+ it "should create a new DataRow" do
194
+ row = {'first_name' => 'Bob'}
195
+ dr = Mongify::Database::DataRow.new(row)
196
+ Mongify::Database::DataRow.should_receive(:new).and_return(dr)
197
+ @table.send(:run_before_save, row)
198
+ end
199
+ end
200
+ it "should work" do
201
+ @table.translate({'permission' => 51}).should == {'admin' => true}
202
+ end
203
+ end
204
+
184
205
  context "translate" do
185
206
  before(:each) do
186
207
  @column1 = mock(:translate => {'first_name' => 'Timmy'}, :name => 'first_name')
@@ -4,13 +4,13 @@ describe Mongify::Translation do
4
4
  context "print" do
5
5
  before(:each) do
6
6
  cols = [Mongify::Database::Column.new('first_name', :string),
7
- Mongify::Database::Column.new('age', :integer, :default => 18),
7
+ Mongify::Database::Column.new('age', :integer),
8
8
  Mongify::Database::Column.new('bio', :text)]
9
9
  @table = Mongify::Database::Table.new("users", :columns => cols)
10
10
  @translation = Mongify::Translation.new()
11
11
  @translation.add_table(@table)
12
12
  @table2 = Mongify::Database::Table.new('posts')
13
- @table2.column('id', :integer)
13
+ @table2.column('id', :key)
14
14
  @translation.add_table(@table2)
15
15
  end
16
16
 
@@ -20,7 +20,7 @@ describe Mongify::Translation do
20
20
  subject.print.should == <<-EOF
21
21
  table "users" do
22
22
  \tcolumn "first_name", :string
23
- \tcolumn "age", :integer, :default => "18"
23
+ \tcolumn "age", :integer
24
24
  \tcolumn "bio", :text
25
25
  end
26
26
 
@@ -1,18 +1,20 @@
1
+ # Used during testing to read in a config file
1
2
  class ConfigReader
2
3
  def initialize(filepath)
3
4
  if File.exists?(filepath)
4
5
  config = YAML.load_file(filepath)
5
- #puts ">>> READING #{filepath}"
6
6
  config.each { |key, value| instance_variable_set("@#{key}", value) }
7
7
  else
8
8
  raise ">>> Can't find #{filepath} -- unable to read config file <<<"
9
9
  end
10
10
  end
11
11
 
12
+ # Return true if there is an instance variable under that name
12
13
  def responses_to?(key)
13
14
  instance_variable_get("@#{key}") ? instance_variable_get("@#{key}") : super(key)
14
15
  end
15
16
 
17
+ # Returns value of instance variable if set
16
18
  def method_missing(meth, *args, &blk)
17
19
  value = instance_variable_get("@#{meth}")
18
20
  return value if value
@@ -1,4 +1,6 @@
1
+ # Used during testing to generate and load database information and connection strings
1
2
  class GenerateDatabase
3
+ # Returns a mysql connection (using the database.yml)
2
4
  def self.mysql_connection
3
5
  @sql_connection ||= Mongify::Database::SqlConnection.new( :adapter => CONNECTION_CONFIG.mysql['adapter'],
4
6
  :host => CONNECTION_CONFIG.mysql['host'],
@@ -8,11 +10,14 @@ class GenerateDatabase
8
10
  :database => CONNECTION_CONFIG.mysql['database']
9
11
  )
10
12
  end
13
+ # Returns a sqlite connection (using the database.yml )
11
14
  def self.sqlite_connection
12
15
  @db_path = File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), CONNECTION_CONFIG.sqlite['database'])
13
16
 
14
17
  @sqlite_connecton ||= Mongify::Database::SqlConnection.new(:adapter => CONNECTION_CONFIG.sqlite['adapter'], :database => @db_path)
15
18
  end
19
+
20
+ # Creates a new mysql database (and deletes the old one)
16
21
  def self.sqlite(include_data=true)
17
22
  File.delete(sqlite_connection.database) if File.exists?(sqlite_connection.database)
18
23
 
@@ -90,10 +95,12 @@ class GenerateDatabase
90
95
  sqlite_connection.database
91
96
  end
92
97
 
98
+ # Drops the database in mongo
93
99
  def self.clear_mongodb
94
100
  mongo_connection.connection.drop_database mongo_connection.database
95
101
  end
96
102
 
103
+ # Returns a mongo connection (based on the database.yml)
97
104
  def self.mongo_connection
98
105
  @mongodb_connection ||= Mongify::Database::NoSqlConnection.new(:host => CONNECTION_CONFIG.mongo['host'],
99
106
  :port => CONNECTION_CONFIG.mongo['port'],
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 9
10
- version: 0.0.9
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Kalek
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-19 00:00:00 -05:00
18
+ date: 2011-01-21 00:00:00 -05:00
19
19
  default_executable: mongify
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -265,13 +265,13 @@ files:
265
265
  - lib/mongify/cli/application.rb
266
266
  - lib/mongify/cli/help_command.rb
267
267
  - lib/mongify/cli/options.rb
268
- - lib/mongify/cli/report.rb
269
268
  - lib/mongify/cli/version_command.rb
270
269
  - lib/mongify/cli/worker_command.rb
271
270
  - lib/mongify/configuration.rb
272
271
  - lib/mongify/database.rb
273
272
  - lib/mongify/database/base_connection.rb
274
273
  - lib/mongify/database/column.rb
274
+ - lib/mongify/database/data_row.rb
275
275
  - lib/mongify/database/no_sql_connection.rb
276
276
  - lib/mongify/database/sql_connection.rb
277
277
  - lib/mongify/database/table.rb
@@ -294,6 +294,7 @@ files:
294
294
  - spec/mongify/configuration_spec.rb
295
295
  - spec/mongify/database/base_connection_spec.rb
296
296
  - spec/mongify/database/column_spec.rb
297
+ - spec/mongify/database/data_row_spec.rb
297
298
  - spec/mongify/database/no_sql_connection_spec.rb
298
299
  - spec/mongify/database/sql_connection_spec.rb
299
300
  - spec/mongify/database/table_spec.rb
@@ -367,6 +368,7 @@ test_files:
367
368
  - spec/mongify/configuration_spec.rb
368
369
  - spec/mongify/database/base_connection_spec.rb
369
370
  - spec/mongify/database/column_spec.rb
371
+ - spec/mongify/database/data_row_spec.rb
370
372
  - spec/mongify/database/no_sql_connection_spec.rb
371
373
  - spec/mongify/database/sql_connection_spec.rb
372
374
  - spec/mongify/database/table_spec.rb
@@ -1,11 +0,0 @@
1
- module Mongify
2
- module CLI
3
- class QuietReport
4
-
5
- end
6
-
7
- class VerboseReport
8
-
9
- end
10
- end
11
- end