forked from yamldb/yaml_db
/
serialization_helper_spec.rb
42 lines (31 loc) · 1.16 KB
/
serialization_helper_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require File.dirname(__FILE__) + '/base'
describe SerializationHelper do
before do
ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
ActiveRecord::Base.connection = mock('connection')
ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable', 'schema_info', 'schema_migrations' ])
end
def stub_helper!
@helper = mock("MyHelper")
@helper.stub!(:dumper).and_return(@dumper)
@helper.stub!(:loader)
@helper.stub!(:extension).and_return("yml")
@dumper.stub!(:tables).and_return([ActiveRecord::Base.connection.tables[0]])
end
context "for multi-file dumps" do
before do
@io = StringIO.new
File.should_receive(:new).once.with("dir_name/mytable.yml", "w").and_return(@io)
Dir.should_receive(:mkdir).once.with("dir_name")
stub_helper!
@dumper.should_receive(:dump_table).once.with(@io, "mytable")
end
it "should create the number of files that there are tables" do
SerializationHelper.new(@helper).dump_to_dir "dir_name"
end
end
context "for multi-file loads" do
before do
end
end
end