yaml_db 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: acdb560a3395eccc63e09765a383c21a04989f16
4
+ data.tar.gz: d212a746810f53f432a0f0d0470a0786f69afeae
5
+ SHA512:
6
+ metadata.gz: 7b584320742d6e98d03dc8bc5d83a967a6386b938719d2a67343f6d6197203c0a8fe21dffdc51d1cdd5f1f3ff9fb1aeb161ddeeedb0d3b0a954f66258aa5415b
7
+ data.tar.gz: 6b9e694bd379f5c198316e366af098f3b7e9c94b9397926cc129911cb66182fa218b4586e72eff418909c1734eac04aada3ccda1d68c902569d87fc0c0b25014
@@ -6,7 +6,7 @@ This can be used as a replacement for mysqldump or pg_dump, but only for the dat
6
6
 
7
7
  Any database that has an ActiveRecord adapter should work. This gem is now Rails 3 only. For Rails 2, clone and checkout the Rails2 branch.
8
8
 
9
- [![Build Status](https://secure.travis-ci.org/ludicast/yaml_db.png)](http://travis-ci.org/ludicast/yaml_db)
9
+ [![Build Status](https://travis-ci.org/yamldb/yaml_db.svg?branch=master)](https://travis-ci.org/yamldb/yaml_db)
10
10
 
11
11
  ## Installation
12
12
 
@@ -45,6 +45,3 @@ One common use would be to switch your data from one database backend to another
45
45
  Created by Orion Henry and Adam Wiggins. Major updates by Ricardo Chimal, Jr.
46
46
 
47
47
  Patches contributed by Michael Irwin, Tom Locke, and Tim Galeckas.
48
-
49
- Send questions, feedback, or patches to the Heroku mailing list: http://groups.google.com/group/heroku
50
-
@@ -4,8 +4,8 @@ module SerializationHelper
4
4
  attr_reader :extension
5
5
 
6
6
  def initialize(helper)
7
- @dumper = helper.dumper
8
- @loader = helper.loader
7
+ @dumper = helper.dumper
8
+ @loader = helper.loader
9
9
  @extension = helper.extension
10
10
  end
11
11
 
@@ -22,7 +22,7 @@ module SerializationHelper
22
22
  io = File.new "#{dirname}/#{table}.#{@extension}", "w"
23
23
  @dumper.before_table(io, table)
24
24
  @dumper.dump_table io, table
25
- @dumper.after_table(io, table)
25
+ @dumper.after_table(io, table)
26
26
  end
27
27
  end
28
28
 
@@ -38,7 +38,7 @@ module SerializationHelper
38
38
  next
39
39
  end
40
40
  @loader.load(File.new("#{dirname}/#{filename}", "r"), truncate)
41
- end
41
+ end
42
42
  end
43
43
 
44
44
  def disable_logger
@@ -50,7 +50,7 @@ module SerializationHelper
50
50
  ActiveRecord::Base.logger = @@old_logger
51
51
  end
52
52
  end
53
-
53
+
54
54
  class Load
55
55
  def self.load(io, truncate = true)
56
56
  ActiveRecord::Base.connection.transaction do
@@ -92,9 +92,8 @@ module SerializationHelper
92
92
  if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
93
93
  ActiveRecord::Base.connection.reset_pk_sequence!(table_name)
94
94
  end
95
- end
95
+ end
96
96
 
97
-
98
97
  end
99
98
 
100
99
  module Utils
@@ -181,8 +180,8 @@ module SerializationHelper
181
180
  quoted_table_name = SerializationHelper::Utils.quote_table(table)
182
181
 
183
182
  (0..pages).to_a.each do |page|
184
- query = Arel::Table.new(table).order(id).skip(records_per_page*page).take(records_per_page).project(Arel.sql('*'))
185
- records = ActiveRecord::Base.connection.select_all(query)
183
+ query = Arel::Table.new(table, ActiveRecord::Base).order(id).skip(records_per_page*page).take(records_per_page).project(Arel.sql('*'))
184
+ records = ActiveRecord::Base.connection.select_all(query.to_sql)
186
185
  records = SerializationHelper::Utils.convert_booleans(records, boolean_columns)
187
186
  yield records
188
187
  end
@@ -4,6 +4,7 @@ require 'active_record'
4
4
  require 'serialization_helper'
5
5
  require 'active_support/core_ext/kernel/reporting'
6
6
  require 'rails/railtie'
7
+ require 'yaml_db/version'
7
8
 
8
9
  module YamlDb
9
10
  module Helper
@@ -44,8 +45,8 @@ module YamlDb
44
45
  column_names = table_column_names(table)
45
46
 
46
47
  each_table_page(table) do |records|
47
- rows = SerializationHelper::Utils.unhash_records(records, column_names)
48
- io.write(YamlDb::Utils.chunk_records(records))
48
+ rows = SerializationHelper::Utils.unhash_records(records.to_a, column_names)
49
+ io.write(YamlDb::Utils.chunk_records(rows))
49
50
  end
50
51
  end
51
52
 
@@ -0,0 +1,3 @@
1
+ module YamlDb
2
+ VERSION = "0.3.0"
3
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adam Wiggins
@@ -10,68 +9,124 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-04-30 00:00:00.000000000 Z
14
- dependencies: []
15
- description: ! '
12
+ date: 2014-11-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '4.3'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '3.0'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.3'
34
+ - !ruby/object:Gem::Dependency
35
+ name: rake
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.7
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.7
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: sqlite3
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ description: |2
16
91
 
17
- YamlDb is a database-independent format for dumping and restoring data. It complements
18
- the the database-independent schema format found in db/schema.rb. The data is saved
19
- into db/data.yml.
20
-
21
- This can be used as a replacement for mysqldump or pg_dump, but only for the databases
22
- typically used by Rails apps. Users, permissions, schemas, triggers, and other
23
- advanced database features are not supported - by design.
24
-
25
- Any database that has an ActiveRecord adapter should work
26
-
27
- '
28
- email: nate@ludicast.com
92
+ YamlDb is a database-independent format for dumping and restoring data. It complements the the database-independent schema format found in db/schema.rb. The data is saved into db/data.yml.
93
+ This can be used as a replacement for mysqldump or pg_dump, but only for the databases typically used by Rails apps. Users, permissions, schemas, triggers, and other advanced database features are not supported - by design.
94
+ Any database that has an ActiveRecord adapter should work.
95
+ email:
29
96
  executables: []
30
97
  extensions: []
31
98
  extra_rdoc_files:
32
- - README.markdown
99
+ - README.md
33
100
  files:
34
- - .travis.yml
35
- - README.markdown
36
- - Rakefile
37
- - VERSION
38
- - about.yml
101
+ - README.md
39
102
  - init.rb
40
103
  - lib/csv_db.rb
41
104
  - lib/serialization_helper.rb
42
105
  - lib/tasks/yaml_db_tasks.rake
43
106
  - lib/yaml_db.rb
44
- - spec/base.rb
45
- - spec/serialization_helper_base_spec.rb
46
- - spec/serialization_helper_dump_spec.rb
47
- - spec/serialization_helper_load_spec.rb
48
- - spec/serialization_utils_spec.rb
49
- - spec/yaml_dump_spec.rb
50
- - spec/yaml_load_spec.rb
51
- - spec/yaml_utils_spec.rb
52
- - yaml_db.gemspec
53
- homepage: http://github.com/ludicast/yaml_db
54
- licenses: []
107
+ - lib/yaml_db/version.rb
108
+ homepage: https://github.com/yamldb/yaml_db
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
55
112
  post_install_message:
56
113
  rdoc_options: []
57
114
  require_paths:
58
115
  - lib
59
116
  required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
117
  requirements:
62
- - - ! '>='
118
+ - - ">="
63
119
  - !ruby/object:Gem::Version
64
- version: '0'
120
+ version: 1.8.7
65
121
  required_rubygems_version: !ruby/object:Gem::Requirement
66
- none: false
67
122
  requirements:
68
- - - ! '>='
123
+ - - ">="
69
124
  - !ruby/object:Gem::Version
70
125
  version: '0'
71
126
  requirements: []
72
127
  rubyforge_project:
73
- rubygems_version: 1.8.17
128
+ rubygems_version: 2.4.2
74
129
  signing_key:
75
- specification_version: 3
130
+ specification_version: 4
76
131
  summary: yaml_db allows export/import of database into/from yaml files
77
132
  test_files: []
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.8.7
4
- - 1.9.3
data/Rakefile DELETED
@@ -1,30 +0,0 @@
1
- require 'rake'
2
- require "rspec/core/rake_task"
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "yaml_db"
8
- gem.summary = %Q{yaml_db allows export/import of database into/from yaml files}
9
- gem.description = %Q{
10
- YamlDb is a database-independent format for dumping and restoring data. It complements the the database-independent schema format found in db/schema.rb. The data is saved into db/data.yml.
11
- This can be used as a replacement for mysqldump or pg_dump, but only for the databases typically used by Rails apps. Users, permissions, schemas, triggers, and other advanced database features are not supported - by design.
12
- Any database that has an ActiveRecord adapter should work
13
- }
14
- gem.email = "nate@ludicast.com"
15
- gem.homepage = "http://github.com/ludicast/yaml_db"
16
- gem.authors = ["Adam Wiggins","Orion Henry"]
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
- end
22
-
23
-
24
- RSpec::Core::RakeTask.new(:spec) do |spec|
25
- spec.pattern = 'spec/*_spec.rb'
26
- spec.rspec_opts = ['--backtrace']
27
- end
28
-
29
- task :default => :spec
30
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.3
data/about.yml DELETED
@@ -1,5 +0,0 @@
1
- author: Orion Henry and Adam Wiggins of Heroku
2
- summary: Dumps and loads a database-independent data dump format in db/data.yml.
3
- homepage: http://opensource.heroku.com/
4
- license: MIT
5
- rails_version: 1.2+
@@ -1,4 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rspec'
4
- require 'yaml_db'
@@ -1,56 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
-
3
- describe SerializationHelper::Base do
4
- def prestub_active_record
5
-
6
- end
7
-
8
- before do
9
- @io = StringIO.new
10
- silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
11
- ActiveRecord::Base.stub(:connection).and_return(mock('connection'))
12
- ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable', 'schema_info', 'schema_migrations' ])
13
- end
14
-
15
- def stub_helper!
16
- @helper = mock("MyHelper")
17
- @dumper = mock("MyDumper");
18
- @loader = mock("MyLoader");
19
- @helper.stub!(:dumper).and_return(@dumper)
20
- @helper.stub!(:loader).and_return(@loader)
21
- @helper.stub!(:extension).and_return("yml")
22
- @dumper.stub!(:tables).and_return([ActiveRecord::Base.connection.tables[0]])
23
- @dumper.stub!(:before_table).and_return(nil)
24
- @dumper.stub!(:after_table).and_return(nil)
25
- end
26
-
27
- context "for multi-file dumps" do
28
- before do
29
- File.should_receive(:new).once.with("dir_name/mytable.yml", "w").and_return(@io)
30
- Dir.should_receive(:mkdir).once.with("dir_name")
31
- stub_helper!
32
- @dumper.should_receive(:dump_table).once.with(@io, "mytable")
33
- end
34
-
35
- it "should create the number of files that there are tables" do
36
- SerializationHelper::Base.new(@helper).dump_to_dir "dir_name"
37
- end
38
-
39
- end
40
-
41
- context "for multi-file loads" do
42
-
43
- before do
44
- stub_helper!
45
- @loader.should_receive(:load).once.with(@io, true)
46
- File.should_receive(:new).once.with("dir_name/mytable.yml", "r").and_return(@io)
47
- Dir.stub!(:entries).and_return(["mytable.yml"])
48
- end
49
-
50
- it "should insert into then umber of tables that there are files" do
51
- SerializationHelper::Base.new(@helper).load_from_dir "dir_name"
52
- end
53
-
54
- end
55
-
56
- end
@@ -1,65 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
-
3
- describe SerializationHelper::Dump do
4
-
5
- before do
6
- silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
7
- ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
8
- ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable', 'schema_info', 'schema_migrations' ])
9
- ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a', :name => 'a', :type => :string), mock('b', :name => 'b', :type => :string) ])
10
- ActiveRecord::Base.connection.stub!(:select_one).and_return({"count"=>"2"})
11
- ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ])
12
- SerializationHelper::Utils.stub!(:quote_table).with('mytable').and_return('mytable')
13
- end
14
-
15
- before(:each) do
16
- File.stub!(:new).with('dump.yml', 'w').and_return(StringIO.new)
17
- @io = StringIO.new
18
- end
19
-
20
- it "should return a list of column names" do
21
- SerializationHelper::Dump.table_column_names('mytable').should == [ 'a', 'b' ]
22
- end
23
-
24
- it "should return a list of tables without the rails schema table" do
25
- SerializationHelper::Dump.tables.should == ['mytable']
26
- end
27
-
28
- it "should return the total number of records in a table" do
29
- SerializationHelper::Dump.table_record_count('mytable').should == 2
30
- end
31
-
32
- it "should return all records from the database and return them when there is only 1 page" do
33
- SerializationHelper::Dump.each_table_page('mytable') do |records|
34
- records.should == [ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ]
35
- end
36
- end
37
-
38
- it "should paginate records from the database and return them" do
39
- ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 } ], [ { 'a' => 3, 'b' => 4 } ])
40
-
41
- records = [ ]
42
- SerializationHelper::Dump.each_table_page('mytable', 1) do |page|
43
- page.size.should == 1
44
- records.concat(page)
45
- end
46
-
47
- records.should == [ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ]
48
- end
49
-
50
- it "should dump a table's contents to yaml" do
51
- SerializationHelper::Dump.should_receive(:dump_table_columns)
52
- SerializationHelper::Dump.should_receive(:dump_table_records)
53
- SerializationHelper::Dump.dump_table(@io, 'mytable')
54
- end
55
-
56
- it "should not dump a table's contents when the record count is zero" do
57
- SerializationHelper::Dump.stub!(:table_record_count).with('mytable').and_return(0)
58
- SerializationHelper::Dump.should_not_receive(:dump_table_columns)
59
- SerializationHelper::Dump.should_not_receive(:dump_table_records)
60
- SerializationHelper::Dump.dump_table(@io, 'mytable')
61
- end
62
-
63
-
64
-
65
- end
@@ -1,77 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
-
3
- describe SerializationHelper::Load do
4
- before do
5
- SerializationHelper::Utils.stub!(:quote_table).with('mytable').and_return('mytable')
6
-
7
- silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
8
- ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
9
- ActiveRecord::Base.connection.stub!(:transaction).and_yield
10
- @io = StringIO.new
11
- end
12
-
13
- it "should truncate the table" do
14
- ActiveRecord::Base.connection.stub!(:execute).with("TRUNCATE mytable").and_return(true)
15
- ActiveRecord::Base.connection.should_not_receive(:execute).with("DELETE FROM mytable")
16
- SerializationHelper::Load.truncate_table('mytable')
17
- end
18
-
19
- it "should delete the table if truncate throws an exception" do
20
- ActiveRecord::Base.connection.should_receive(:execute).with("TRUNCATE mytable").and_raise()
21
- ActiveRecord::Base.connection.should_receive(:execute).with("DELETE FROM mytable").and_return(true)
22
- SerializationHelper::Load.truncate_table('mytable')
23
- end
24
-
25
-
26
- it "should call reset pk sequence if the connection adapter is postgres" do
27
- ActiveRecord::Base.connection.should_receive(:respond_to?).with(:reset_pk_sequence!).and_return(true)
28
- ActiveRecord::Base.connection.should_receive(:reset_pk_sequence!).with('mytable')
29
- SerializationHelper::Load.reset_pk_sequence!('mytable')
30
- end
31
-
32
- it "should not call reset pk sequence for other adapters" do
33
- ActiveRecord::Base.connection.should_receive(:respond_to?).with(:reset_pk_sequence!).and_return(false)
34
- ActiveRecord::Base.connection.should_not_receive(:reset_pk_sequence!)
35
- SerializationHelper::Load.reset_pk_sequence!('mytable')
36
- end
37
-
38
- it "should insert records into a table" do
39
- mca = mock('a',:name => 'a')
40
- mcb = mock('b', :name => 'b')
41
- ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([mca , mcb ])
42
- ActiveRecord::Base.connection.stub!(:quote_column_name).with('a').and_return('a')
43
- ActiveRecord::Base.connection.stub!(:quote_column_name).with('b').and_return('b')
44
- ActiveRecord::Base.connection.stub!(:quote).with(1, mca).and_return("'1'")
45
- ActiveRecord::Base.connection.stub!(:quote).with(2, mcb).and_return("'2'")
46
- ActiveRecord::Base.connection.stub!(:quote).with(3, mca).and_return("'3'")
47
- ActiveRecord::Base.connection.stub!(:quote).with(4, mcb).and_return("'4'")
48
- ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,b) VALUES ('1','2')")
49
- ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,b) VALUES ('3','4')")
50
-
51
- SerializationHelper::Load.load_records('mytable', ['a', 'b'], [[1, 2], [3, 4]])
52
- end
53
-
54
- it "should quote column names that correspond to sql keywords" do
55
- mca = mock('a',:name => 'a')
56
- mccount = mock('count', :name => 'count')
57
- ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([mca , mccount ])
58
- ActiveRecord::Base.connection.stub!(:quote_column_name).with('a').and_return('a')
59
- ActiveRecord::Base.connection.stub!(:quote_column_name).with('count').and_return('"count"')
60
- ActiveRecord::Base.connection.stub!(:quote).with(1, mca).and_return("'1'")
61
- ActiveRecord::Base.connection.stub!(:quote).with(2, mccount).and_return("'2'")
62
- ActiveRecord::Base.connection.stub!(:quote).with(3, mca).and_return("'3'")
63
- ActiveRecord::Base.connection.stub!(:quote).with(4, mccount).and_return("'4'")
64
- ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,\"count\") VALUES ('1','2')")
65
- ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,\"count\") VALUES ('3','4')")
66
-
67
- SerializationHelper::Load.load_records('mytable', ['a', 'count'], [[1, 2], [3, 4]])
68
- end
69
-
70
- it "should truncate the table and then load the records into the table" do
71
- SerializationHelper::Load.should_receive(:truncate_table).with('mytable')
72
- SerializationHelper::Load.should_receive(:load_records).with('mytable', ['a', 'b'], [[1, 2], [3, 4]])
73
- SerializationHelper::Load.should_receive(:reset_pk_sequence!).with('mytable')
74
-
75
- SerializationHelper::Load.load_table('mytable', { 'columns' => [ 'a', 'b' ], 'records' => [[1, 2], [3, 4]] })
76
- end
77
- end
@@ -1,51 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
-
3
- describe SerializationHelper::Utils, " convert records utility method" do
4
- before do
5
- silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
6
- ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
7
- end
8
-
9
- it "returns an array of hash values using an array of ordered keys" do
10
- SerializationHelper::Utils.unhash({ 'a' => 1, 'b' => 2 }, [ 'b', 'a' ]).should == [ 2, 1 ]
11
- end
12
-
13
- it "should unhash each hash an array using an array of ordered keys" do
14
- SerializationHelper::Utils.unhash_records([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ], [ 'b', 'a' ]).should == [ [ 2, 1 ], [ 4, 3 ] ]
15
- end
16
-
17
- it "should return true if it is a boolean type" do
18
- SerializationHelper::Utils.is_boolean(true).should == true
19
- SerializationHelper::Utils.is_boolean('true').should_not == true
20
- end
21
-
22
- it "should return an array of boolean columns" do
23
- ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a',:type => :string), mock('b', :name => 'b',:type => :boolean) ])
24
- SerializationHelper::Utils.boolean_columns('mytable').should == ['b']
25
- end
26
-
27
- it "should quote the table name" do
28
- ActiveRecord::Base.connection.should_receive(:quote_table_name).with('values').and_return('`values`')
29
- SerializationHelper::Utils.quote_table('values').should == '`values`'
30
- end
31
-
32
- it "should convert ruby booleans to true and false" do
33
- SerializationHelper::Utils.convert_boolean(true).should == true
34
- SerializationHelper::Utils.convert_boolean(false).should == false
35
- end
36
-
37
- it "should convert ruby string t and f to true and false" do
38
- SerializationHelper::Utils.convert_boolean('t').should == true
39
- SerializationHelper::Utils.convert_boolean('f').should == false
40
- end
41
-
42
- it "should convert ruby string 1 and 0 to true and false" do
43
- SerializationHelper::Utils.convert_boolean('1').should == true
44
- SerializationHelper::Utils.convert_boolean('0').should == false
45
- end
46
-
47
- it "should convert ruby integer 1 and 0 to true and false" do
48
- SerializationHelper::Utils.convert_boolean(1).should == true
49
- SerializationHelper::Utils.convert_boolean(0).should == false
50
- end
51
- end
@@ -1,55 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
-
3
- describe YamlDb::Dump do
4
-
5
- before do
6
- silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
7
- ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
8
- ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable', 'schema_info', 'schema_migrations' ])
9
- ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a', :type => :string), mock('b', :name => 'b', :type => :string) ])
10
- ActiveRecord::Base.connection.stub!(:select_one).and_return({"count"=>"2"})
11
- ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ])
12
- YamlDb::Utils.stub!(:quote_table).with('mytable').and_return('mytable')
13
- end
14
-
15
- before(:each) do
16
- File.stub!(:new).with('dump.yml', 'w').and_return(StringIO.new)
17
- @io = StringIO.new
18
- end
19
-
20
- it "should return a formatted string" do
21
- YamlDb::Dump.table_record_header(@io)
22
- @io.rewind
23
- @io.read.should == " records: \n"
24
- end
25
-
26
-
27
- it "should return a yaml string that contains a table header and column names" do
28
- YamlDb::Dump.stub!(:table_column_names).with('mytable').and_return([ 'a', 'b' ])
29
- YamlDb::Dump.dump_table_columns(@io, 'mytable')
30
- @io.rewind
31
- @io.read.should == <<EOYAML
32
-
33
- ---
34
- mytable:
35
- columns:
36
- - a
37
- - b
38
- EOYAML
39
- end
40
-
41
- it "should return dump the records for a table in yaml to a given io stream" do
42
- YamlDb::Dump.dump_table_records(@io, 'mytable')
43
- @io.rewind
44
- @io.read.should == <<EOYAML
45
- records:
46
- - - 1
47
- - 2
48
- - - 3
49
- - 4
50
- EOYAML
51
- end
52
-
53
-
54
-
55
- end
@@ -1,33 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
- require 'active_support/core_ext/kernel/debugger'
3
-
4
- describe YamlDb::Load do
5
- before do
6
- SerializationHelper::Utils.stub!(:quote_table).with('mytable').and_return('mytable')
7
-
8
- silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
9
- ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
10
- ActiveRecord::Base.connection.stub!(:transaction).and_yield
11
- end
12
-
13
- before(:each) do
14
- @io = StringIO.new
15
- end
16
-
17
-
18
- it "should call load structure for each document in the file" do
19
- YAML.should_receive(:load_documents).with(@io).and_yield({ 'mytable' => {
20
- 'columns' => [ 'a', 'b' ],
21
- 'records' => [[1, 2], [3, 4]]
22
- } } )
23
- YamlDb::Load.should_receive(:load_table).with('mytable', { 'columns' => [ 'a', 'b' ], 'records' => [[1, 2], [3, 4]] },true)
24
- YamlDb::Load.load(@io)
25
- end
26
-
27
- it "should not call load structure when the document in the file contains no records" do
28
- YAML.should_receive(:load_documents).with(@io).and_yield({ 'mytable' => nil })
29
- YamlDb::Load.should_not_receive(:load_table)
30
- YamlDb::Load.load(@io)
31
- end
32
-
33
- end
@@ -1,21 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
-
3
- describe YamlDb::Utils, " convert records utility method" do
4
-
5
- it "turns an array with one record into a yaml chunk" do
6
- YamlDb::Utils.chunk_records([ %w(a b) ]).should == <<EOYAML
7
- - - a
8
- - b
9
- EOYAML
10
- end
11
-
12
- it "turns an array with two records into a yaml chunk" do
13
- YamlDb::Utils.chunk_records([ %w(a b), %w(x y) ]).should == <<EOYAML
14
- - - a
15
- - b
16
- - - x
17
- - y
18
- EOYAML
19
- end
20
-
21
- end
@@ -1,53 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "yaml_db"
8
- s.version = "0.2.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Adam Wiggins", "Orion Henry"]
12
- s.date = "2012-04-30"
13
- s.description = "\nYamlDb is a database-independent format for dumping and restoring data. It complements the the database-independent schema format found in db/schema.rb. The data is saved into db/data.yml.\nThis can be used as a replacement for mysqldump or pg_dump, but only for the databases typically used by Rails apps. Users, permissions, schemas, triggers, and other advanced database features are not supported - by design.\nAny database that has an ActiveRecord adapter should work\n"
14
- s.email = "nate@ludicast.com"
15
- s.extra_rdoc_files = [
16
- "README.markdown"
17
- ]
18
- s.files = [
19
- ".travis.yml",
20
- "README.markdown",
21
- "Rakefile",
22
- "VERSION",
23
- "about.yml",
24
- "init.rb",
25
- "lib/csv_db.rb",
26
- "lib/serialization_helper.rb",
27
- "lib/tasks/yaml_db_tasks.rake",
28
- "lib/yaml_db.rb",
29
- "spec/base.rb",
30
- "spec/serialization_helper_base_spec.rb",
31
- "spec/serialization_helper_dump_spec.rb",
32
- "spec/serialization_helper_load_spec.rb",
33
- "spec/serialization_utils_spec.rb",
34
- "spec/yaml_dump_spec.rb",
35
- "spec/yaml_load_spec.rb",
36
- "spec/yaml_utils_spec.rb",
37
- "yaml_db.gemspec"
38
- ]
39
- s.homepage = "http://github.com/ludicast/yaml_db"
40
- s.require_paths = ["lib"]
41
- s.rubygems_version = "1.8.17"
42
- s.summary = "yaml_db allows export/import of database into/from yaml files"
43
-
44
- if s.respond_to? :specification_version then
45
- s.specification_version = 3
46
-
47
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
- else
49
- end
50
- else
51
- end
52
- end
53
-