我正在製作一個名爲「圖書俱樂部」的應用程序。系統中將有很多書和票。每個月,在本月的第一天,我需要系統自動將具有最高票數的書籍推薦爲「本月書」。推銷一本書並確保每月只有一本書的邏輯已經實施。Rails應用程序需要每月執行一次任務
book.promote!
可愛吧?
我有我的測試情況下hurr
Given the following books exist:
| title | author | year_published | votes | created_at |
| Lord of the Flies | William Golding | 1954 | 18 | January 12, 2010 |
| The Virgin Suicides | Jeffrey Eugenides | 1993 | 12 | February 15, 2010 |
| Island | Richard Laymon | 1991 | 6 | November 22, 2009 |
And the book "Lord of the Flies" is the current book of the month
And the date is "February 24, 2010"
Then the book "Lord of the Flies" should be the current book of the month
When the date is "March 1, 2010"
And I am on the home page
Then I should see "This Month's Book of the Month Club Book"
And I should see "The Virgin Suicides"
And the book "The Virgin Suicides" should be the current book of the month
And the book "Lord of the Flies" should not be the current book of the month
And the book "Island" should not be the current book of the month
而我試圖讓通過。
所以問題是,我該如何最好地實現自動的,每月一次的更新,可以通過這種情況來測試?
克朗對我的口味有點過於sl。。我想要一個更便攜的解決方案。
delayed_job/Resque對於這種情況似乎有點過重。此外,我還不確定如何讓他們每月運行一次工作。
只是尋找一個簡單,但強大的TESTABLE解決方案。
歡呼,一如既往!
如果你可以解釋爲什麼'cron'對你來說太sl I,我可以建議更好的選擇。 – Swanand 2010-12-15 04:13:41
要使用cron,我必須在我的測試套件中開始做出假設。我可以完成cron作業調用並測試的rake任務,但是我仍然假定cron作業將在我的環境中設置。也許我在那個時候有點兒迂腐,但它不能覆蓋這個系統的關鍵方面並不合適。 – drmanitoba 2010-12-15 15:37:18