<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良藥之Creating Dynamic Test Fixtures

      每天一劑Rails良藥之Creating Dynamic Test Fixtures
      2010-01-14 07:08:35  作者:  來源:
      Rails的fixture文件在傳遞給YAML解析之前先用ERB解析,這樣一來我們就可以使用Ruby代碼動態生成測試數據,而不用一條數據一條數據的寫了:
      Java代碼 復制代碼
      1. <% 1.upto(50do |number| %>   
      2. child_post_<%= number %>:   
      3.   id: <%= number + 3 %>   
      4.   title: This is auto-generated reply number <%= number %>   
      5.   body: We're on number <%= number %>   
      6.   created_at: 2006-01-30 08:03:56  
      7.   updated_at: 2006-01-30 08:03:56  
      8.   <%# Randomly choose a parent from a post we've already generated -%>   
      9.   parent_id: <%= rand(number - 1) + 1 %>   
      10.   user_id: <%= rand(5) + 1 %>   
      11. <% end %>  

      我們還可以定義一些helper方法:
      Java代碼 復制代碼
      1. <%   
      2.   def today   
      3.     Time.now.to_s(:db)   
      4.   end   
      5.   def next_week   
      6.     1.week.from_now.to_s(:db)   
      7.   end   
      8.   def last_week   
      9.     1.week.ago.to_s(:db)   
      10.   end   
      11. post_from_last_week:   
      12.   id: 60  
      13.   title: pizza   
      14.   body: Last night I had pizza. I readlly liked that story from AWDWR.   
      15.   created_at: <%= last_week %>   
      16.   updated_at: <%= last_week %>   
      17.   user_id: 1  
      18. post_created_in_future_should_not_display:   
      19.   id: 61  
      20.   title: Prognostication   
      21.   body: I predict that this post will show up next week.   
      22.   created_at: <%= next_week %>   
      23.   updated_at: <%= next_week %>   
      24. updated_post_displays_based_on_updated_time:   
      25.   id: 62  
      26.   title: This should show up as posted today.   
      27.   body: blah blah blah   
      28.   created_at: <%= last_week %>   
      29.   updated_at: <%= today %>   
      30.   user_id: 2  

      安徽新華電腦學校專業職業規劃師為你提供更多幫助【在線咨詢
      国产午夜福三级在线播放_亚洲精品成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>
        亚洲欧美日韩中文字幕无线码 | 中文字幕久久35一 | 在线观看日韩精品一区二区 | 亚洲中文字幕一区二区在线看 | 香蕉成人人多人视频 | 一本在线视频在线观看 |