Skip to content

Commit

Permalink
change time delta so the end date is one second earlier, so a search …
Browse files Browse the repository at this point in the history
…doesn't include the articles on the next month. [Jon Leighton]

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2371 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information
technoweenie committed Oct 15, 2006
1 parent ba574f6 commit 9a7b1d2
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
@@ -1,5 +1,11 @@
* SVN *

* change time delta so the end date is one second earlier, so a search doesn't include the articles on the next month. [Jon Leighton]

* use precise time methods when calculating time deltas [Jon Leighton]

* remove .svn dirs when copying default them [Cristi Balan]

* Added linked_tag_list(article, separator). Use like linked_section_list.

* Enhanced the theme preview slightly
Expand Down
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2005 Rick Olson

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion lib/mephisto_init.rb
Expand Up @@ -109,7 +109,7 @@ def self.delta(year, month = nil, day = nil)
else
from.advance :years => 1
end
return [from.midnight, to.midnight]
return [from.midnight, to.midnight-1]
end
end

Expand Down
52 changes: 52 additions & 0 deletions test/fixtures/contents.yml
Expand Up @@ -152,4 +152,56 @@ draft:
updated_at: <%= 1.day.ago.utc.to_s(:db) %>
comment_age: 30
user_id: 1
type: Article
at_beginning_of_month:
id: 12
site_id: 1
title: At beginning of the month
permalink: at-beginning-of-the-month
body: Lalala
body_html: Lalala
created_at: <%= date = Time.now.utc.beginning_of_month.advance(:months => -2).to_s(:db) %>
updated_at: <%= date %>
published_at: <%= date %>
comment_age: 30
user_id: 1
type: Article
at_middle_of_month:
id: 13
site_id: 1
title: At middle of the month
permalink: at-middle-of-the-month
body: Lalala
body_html: Lalala
created_at: <%= date = Time.now.utc.beginning_of_month.advance(:months => -1, :days => -15).to_s(:db) %>
updated_at: <%= date %>
published_at: <%= date %>
comment_age: 30
user_id: 1
type: Article
at_end_of_month:
id: 14
site_id: 1
title: At end of the month
permalink: at-end-of-the-month
body: Lalala
body_html: Lalala
created_at: <%= date = (Time.now.utc.beginning_of_month.advance(:months => -1) -1).to_s(:db) %>
updated_at: <%= date %>
published_at: <%= date %>
comment_age: 30
user_id: 1
type: Article
at_beginning_of_next_month:
id: 15
site_id: 1
title: At beginning of next month
permalink: at-beginning-of-next-month
body: Lalala
body_html: Lalala
created_at: <%= date = Time.now.utc.beginning_of_month.advance(:months => -1).to_s(:db) %>
updated_at: <%= date %>
published_at: <%= date %>
comment_age: 30
user_id: 1
type: Article
Expand Up @@ -16,7 +16,7 @@ def setup

def test_should_show_articles
get :index
assert_equal 6, assigns(:articles).length
assert_equal 10, assigns(:articles).length
end

def test_should_show_new_article_form
Expand Down
4 changes: 2 additions & 2 deletions test/functional/admin/articles_controller_test.rb
Expand Up @@ -28,12 +28,12 @@ def test_should_accept_cookie_login

def test_should_show_articles
get :index
assert_equal 6, assigns(:articles).length
assert_equal 10, assigns(:articles).length
end

def test_should_show_articles_with_empty_seartest_should_show_checked_sectionsch
get :index, :q => '', :filter => 'title', :section => '0'
assert_equal 6, assigns(:articles).length
assert_equal 10, assigns(:articles).length
end

def test_should_search_article_titles
Expand Down
10 changes: 10 additions & 0 deletions test/unit/article_test.rb
Expand Up @@ -153,6 +153,16 @@ def test_should_find_article_by_permalink
assert_equal contents(:welcome), sites(:first).articles.find_by_permalink(:year => contents(:welcome).year, :permalink => contents(:welcome).permalink)
end

def test_should_find_all_in_month
two_months_ago = Time.now.utc.advance(:months => -2)
articles = Article.find_all_in_month(two_months_ago.year, two_months_ago.month)

assert_equal 3, articles.length
[:at_beginning_of_month, :at_end_of_month, :at_middle_of_month].each do |article|
assert articles.include?(contents(article))
end
end

protected
def create_article(options = {})
Article.create options.reverse_merge(:user_id => 1, :site_id => 1, :title => 'foo')
Expand Down
3 changes: 2 additions & 1 deletion test/unit/drop_filters_test.rb
Expand Up @@ -32,7 +32,8 @@ def setup
end

specify "should find latest articles by site" do
assert_models_equal [contents(:welcome), contents(:about), contents(:site_map), contents(:another)], latest_articles(@site).collect(&:source)
assert_models_equal [contents(:welcome), contents(:about), contents(:site_map), contents(:another), contents(:at_beginning_of_next_month), contents(:at_end_of_month), contents(:at_middle_of_month), contents(:at_beginning_of_month)],
latest_articles(@site).collect(&:source)
assert_models_equal [contents(:welcome), contents(:about)], latest_articles(@site, 2).collect(&:source)
end

Expand Down
3 changes: 2 additions & 1 deletion test/unit/site_drop_test.rb
Expand Up @@ -54,7 +54,8 @@ def test_should_find_section_by_path
end

def test_should_find_latest_articles
assert_models_equal [contents(:welcome), contents(:about), contents(:site_map), contents(:another)], @site.latest_articles.collect(&:source)
assert_models_equal [contents(:welcome), contents(:about), contents(:site_map), contents(:another), contents(:at_beginning_of_next_month), contents(:at_end_of_month), contents(:at_middle_of_month), contents(:at_beginning_of_month)],
@site.latest_articles.collect(&:source)
assert_models_equal [contents(:welcome), contents(:about)], @site.latest_articles(2).collect(&:source)
end

Expand Down
10 changes: 5 additions & 5 deletions test/unit/time_test.rb
Expand Up @@ -2,16 +2,16 @@

class TimeTest < Test::Unit::TestCase
def test_should_show_year_delta
assert_equal [Time.local(2006, 1, 1), Time.local(2007,1,1)], Time.local(2006,7,1).to_delta(:year)
assert_equal [Time.local(2006, 1, 1), Time.local(2007,1,1)-1], Time.local(2006,7,1).to_delta(:year)
end

def test_should_show_month_delta
assert_equal [Time.local(2006, 7, 1), Time.local(2006, 8, 1)], Time.local(2006, 7, 15).to_delta(:month)
assert_equal [Time.local(2006, 11, 1), Time.local(2006, 12, 1)], Time.local(2006, 11, 1).to_delta(:month)
assert_equal [Time.local(2006, 12, 1), Time.local(2007, 1, 1)], Time.local(2006, 12, 1).to_delta(:month)
assert_equal [Time.local(2006, 7, 1), Time.local(2006, 8, 1)-1], Time.local(2006, 7, 15).to_delta(:month)
assert_equal [Time.local(2006, 11, 1), Time.local(2006, 12, 1)-1], Time.local(2006, 11, 1).to_delta(:month)
assert_equal [Time.local(2006, 12, 1), Time.local(2007, 1, 1)-1], Time.local(2006, 12, 1).to_delta(:month)
end

def test_should_show_daily_delta
assert_equal [Time.local(2006, 7, 15), Time.local(2006,7,16)], Time.local(2006,7,15).to_delta
assert_equal [Time.local(2006, 7, 15), Time.local(2006,7,16)-1], Time.local(2006,7,15).to_delta
end
end

0 comments on commit 9a7b1d2

Please sign in to comment.