File: todo.rb

package info (click to toggle)
libinnate-ruby 2010.07-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 812 kB
  • ctags: 621
  • sloc: ruby: 4,242; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,871 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'innate/spec'

FileUtils.rm_f('todo.pstore')

require 'start'
require 'hpricot'

describe Todo do
  behaves_like :mock, :multipart

  it 'starts out without tasks' do
    doc = Hpricot(get('/').body)
    doc.at(:table).inner_text.strip.should.be.empty
  end

  it 'adds a task and redirects back' do
    got = post('/create', multipart('title' => 'first task'))
    got.status.should == 302
    got['Location'].should == 'http://example.org/'
  end

  it 'shows the task as pending' do
    doc = Hpricot(get('/').body)
    doc.at('td/input[@name=title]')['value'].should == 'first task'
    doc.at('td/input[@name=done]')['checked'].should.be.nil
  end

  it 'updates the task title and redirects back' do
    got = post('/update', multipart('id' => 'first task', 'title' => 'wash dishes'))
    got.status.should == 302
    got['Location'].should == 'http://example.org/'
  end

  it 'shows the changed task title' do
    doc = Hpricot(get('/').body)
    doc.at('td/input[@name=title]')['value'].should == 'wash dishes'
    doc.at('td/input[@name=done]')['checked'].should.be.nil
  end

  it 'marks the task as done and redirects back' do
    mp = multipart('id' => 'wash dishes', 'title' => 'wash dishes', 'done' => 'on')
    got = post('/update', mp)
    got.status.should == 302
    got['Location'].should == 'http://example.org/'
  end

  it 'shows the task as done' do
    doc = Hpricot(get('/').body)
    doc.at('td/input[@name=title]')['value'].should == 'wash dishes'
    doc.at('td/input[@name=done]')['checked'].should == 'checked'
  end

  it 'deletes the task and redirects back' do
    got = post('/delete', multipart('id' => 'wash dishes'))
    got.status.should == 302
    got['Location'].should == 'http://example.org/'
  end

  it 'shows no tasks' do
    doc = Hpricot(get('/').body)
    doc.at(:table).inner_text.strip.should.be.empty
  end
end