Sha256: 19aefe57450530024d69766a02543412f66b9526a371af04a4e6611dc67ea2c7

Contents?: true

Size: 1.8 KB

Versions: 15

Compression:

Stored size: 1.8 KB

Contents

require File.dirname(__FILE__) + '/base'

describe SerializationHelper::Base do
  def prestub_active_record

  end

	before do
    @io = StringIO.new
  	silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
  	ActiveRecord::Base.stub(:connection).and_return(mock('connection'))
		ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable', 'schema_info', 'schema_migrations' ])
  end

    def stub_helper!
        @helper = mock("MyHelper")
        @dumper = mock("MyDumper");
        @loader = mock("MyLoader");
        @helper.stub!(:dumper).and_return(@dumper)
        @helper.stub!(:loader).and_return(@loader)
        @helper.stub!(:extension).and_return("yml")
        @dumper.stub!(:tables).and_return([ActiveRecord::Base.connection.tables[0]])
        @dumper.stub!(:before_table).and_return(nil)
        @dumper.stub!(:after_table).and_return(nil)
    end

    context "for multi-file dumps" do
      before do
        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::Base.new(@helper).dump_to_dir "dir_name"
      end   

    end

    context "for multi-file loads" do

      before do
        stub_helper!
        @loader.should_receive(:load).once.with(@io, true)
        File.should_receive(:new).once.with("dir_name/mytable.yml", "r").and_return(@io)
        Dir.stub!(:entries).and_return(["mytable.yml"])
      end

      it "should insert into then umber of tables that there are files" do
        SerializationHelper::Base.new(@helper).load_from_dir "dir_name"        
      end

    end

end

Version data entries

15 entries across 15 versions & 7 rubygems

Version Path
yaml_db_with_schema_tables-0.3.4 spec/serialization_helper_base_spec.rb
yaml_db_with_schema_tables-0.3.3 spec/serialization_helper_base_spec.rb
yaml_db_with_schema_tables-0.3.2 spec/serialization_helper_base_spec.rb
mfpiccolo_yaml_db-0.2.3 spec/serialization_helper_base_spec.rb
yaml_db_with_schema_tables-0.2.4 spec/serialization_helper_base_spec.rb
irm_yaml_db-0.0.4 spec/serialization_helper_base_spec.rb
irm_yaml_db-0.0.3 spec/serialization_helper_base_spec.rb
irm_yaml_db-0.0.2 spec/serialization_helper_base_spec.rb
irm_yaml_db-0.0.1 spec/serialization_helper_base_spec.rb
keeguon-yaml_db-0.2.4 spec/serialization_helper_base_spec.rb
gitlab_yaml_db-1.0.0 spec/serialization_helper_base_spec.rb
yaml_db-0.2.3 spec/serialization_helper_base_spec.rb
yaml_db_arel-0.2.2 spec/serialization_helper_base_spec.rb
yaml_db-0.2.2 spec/serialization_helper_base_spec.rb
yaml_db-0.2.1 spec/serialization_helper_base_spec.rb