<source id="4vppl"><ins id="4vppl"></ins></source>
<u id="4vppl"><sub id="4vppl"><label id="4vppl"></label></sub></u>
<object id="4vppl"></object>
  • <u id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></u>

    <object id="4vppl"></object>
    <b id="4vppl"><sub id="4vppl"><tr id="4vppl"></tr></sub></b>

      <i id="4vppl"><thead id="4vppl"></thead></i>

      <thead id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></thead>

      當前位置:首頁 > 網站舊欄目 > 學習園地 > 設計軟件教程 > 每天一劑Rails良藥之Extracting Test Fixtures From Live Data

      每天一劑Rails良藥之Extracting Test Fixtures From Live Data
      2010-01-14 07:09:06  作者:  來源:

       

      Rails做單元測試時,我們自己手動去創建所有的fixtures會是個噩夢,有沒有什么好的方案呢?
      我們可以利用數據庫里已有的數據,寫一個rake tast來把數據庫的數據復制出來到YAML文件里:
      CreateFixturesFromLiveData/lib/tasks/extract_fixtures.rake
      Java代碼 復制代碼
      1. desc 'Create YAML test fixtures from data in an existing database.   
      2. Defaults to development database. Set RAILS_ENV to override.'   
      3.   
      4. task :extract_fixtures => :environment do  
      5.   sql = "SELECT * FROM %s"  
      6.   skip_tables = ["schema_info"]   
      7.   ActiveRecord::Base.establish_connection   
      8.   (ActiveRecord::Base.connection.tables - skip_table).each do |table_name|   
      9.     i = "000"  
      10.     File.open("#{RAILS_ROOT}/test/fixtures/#{table_name}.yml"'w'do |file|   
      11.       data = ActiveRecord::Base.connection.select_all(sql % table_name)   
      12.       file.write data.inject({}) {|hash, record|   
      13.         hash["#{table_name}_#{i.succ!}"] = record   
      14.         hash   
      15.       }.to_yaml   
      16.     end   
      17.   end   
      18. end  

      好了,現在我們運行rake extract_fixtures,則test/fixtures/目錄下將生成每個表的數據的yml文件

      安徽新華電腦學校專業職業規劃師為你提供更多幫助【在線咨詢
      国产午夜福三级在线播放_亚洲精品成a人片在线观看_亚洲自慰一区二区三区_久久棈精品久久久久久噜噜
      <source id="4vppl"><ins id="4vppl"></ins></source>
      <u id="4vppl"><sub id="4vppl"><label id="4vppl"></label></sub></u>
      <object id="4vppl"></object>
    1. <u id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></u>

      <object id="4vppl"></object>
      <b id="4vppl"><sub id="4vppl"><tr id="4vppl"></tr></sub></b>

        <i id="4vppl"><thead id="4vppl"></thead></i>

        <thead id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></thead>
        日韩中文字幕亚洲精品欧美 | 亚洲精品亚洲人成在线 | 亚洲综合色在线观看一区二区 | 精品一区二区久久久久久久 | 思思99热综合在线观看 | 久久99久久99精品免费观看 |