Skip to content

Commit

Permalink
Reverse tasks order
Browse files Browse the repository at this point in the history
  • Loading branch information
esambo committed Jun 19, 2011
1 parent 36dea21 commit f42a803
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/models/task.rb
Expand Up @@ -10,6 +10,7 @@ class Task < ActiveRecord::Base
validates_datetime :start, :on_or_after => '2000-01-01 08:00'
validates_datetime :stop, :allow_blank => true
validate :valid_stop
default_scope order('start desc')

def duration
(self[:stop].blank? ? Time.zone.now.to_i : self[:stop].to_i) - self[:start].to_i
Expand Down
12 changes: 4 additions & 8 deletions app/views/tasks/index.html.erb
Expand Up @@ -3,6 +3,7 @@
<style type="text/css">
.rightSpace {padding-right: 1.5em;}
</style>

<table>
<tr>
<th>Title</th>
Expand All @@ -11,11 +12,10 @@
<th>Stop</th>
<th>Tags</th>
<th>Description</th>
<th></th>
<th></th>
<th></th>
<td colspan='3'>
<%= link_to 'New Task', new_task_path %>
</td>
</tr>

<% @tasks.each do |task| %>
<tr class="vevent">
<td class="rightSpace summary"><%= task.title %></td>
Expand Down Expand Up @@ -43,7 +43,3 @@
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Task', new_task_path %>
16 changes: 16 additions & 0 deletions features/step_definitions/task_steps.rb
Expand Up @@ -4,6 +4,12 @@
@task = Task.create!(:title => title, :start => 5.minutes.ago, :stop => 1.minute.ago, :user => current_user)
end

Given /^I have some tasks$/ do
@task = Task.create!(:title => 'Oldest task', :start => 5.minutes.ago, :stop => 4.minute.ago, :user => current_user)
@task = Task.create!(:title => 'Old task', :start => 4.minutes.ago, :stop => 3.minute.ago, :user => current_user)
@task = Task.create!(:title => 'Most recent task', :start => 3.minutes.ago, :stop => 2.minute.ago, :user => current_user)
end

Given /^I have a "([^\"]*)" task$/ do |duration_in_natural_language|
seconds = ChronicDuration.parse(duration_in_natural_language).round
duration = seconds.seconds.ago
Expand Down Expand Up @@ -42,3 +48,13 @@
raise "\nUnsupported Capybara driver '#{Capybara::current_driver}', path: '#{Capybara::current_path}', url: '#{Capybara::current_url}', use rack::test or selenium/webdriver\n"
end
end

Then /^I should see "([^"]*)" duration in task (\d+)$/ do |duration, number|
durations = page.all(:css, '.duration').map { |e| e.text.strip }
durations[number.to_i - 1].should == duration
end

Then /^I should see more recent tasks first$/ do
starts = page.all(:css, '.dtstart').map { |e| Timeliness.parse(e.text.strip) }
starts.first.should > starts.last
end
5 changes: 5 additions & 0 deletions features/task.feature
Expand Up @@ -22,3 +22,8 @@ Feature: Task
Then I should see "Task was successfully created."
And I should see "A long task description explaining"

Scenario: Descending task order
Given I have some tasks
When I am on the tasks page
Then I should see more recent tasks first

2 changes: 1 addition & 1 deletion features/task_switch.feature
Expand Up @@ -55,5 +55,5 @@ Feature: Task Switch
And I am on the new task page
When I press "Switch Now"
And I follow "Back"
Then I should see "1m" within ".duration"
Then I should see "1m" duration in task 2

7 changes: 7 additions & 0 deletions spec/models/task_spec.rb
Expand Up @@ -88,6 +88,13 @@
t.should be_valid
end

it "should retrieve tasks in descending order" do
t1 = @valid_user.tasks.create!(:title => 'Oldest task', :start => 5.minutes.ago)
t2 = @valid_user.tasks.create!(:title => 'Newest task', :start => 1.minutes.ago)
ts = @valid_user.tasks.all
ts.first.start.should > ts.last.start
end

context "with frozen time" do
before :each do
Time.now = "2010-01-03 9:13:23 AM" #freeze time using time_travel plugin
Expand Down

0 comments on commit f42a803

Please sign in to comment.