Skip to content

Commit 05ef672

Browse files
author
lindsey
committed
Add to do project
0 parents  commit 05ef672

File tree

13 files changed

+265
-0
lines changed

13 files changed

+265
-0
lines changed

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'sinatra'
4+
gem 'pg'
5+
gem 'launchy'

Gemfile.lock

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
addressable (2.7.0)
5+
public_suffix (>= 2.0.2, < 5.0)
6+
launchy (2.4.3)
7+
addressable (~> 2.3)
8+
mustermann (1.0.3)
9+
pg (1.1.4)
10+
public_suffix (4.0.1)
11+
rack (2.0.7)
12+
rack-protection (2.0.7)
13+
rack
14+
sinatra (2.0.7)
15+
mustermann (~> 1.0)
16+
rack (~> 2.0)
17+
rack-protection (= 2.0.7)
18+
tilt (~> 2.0)
19+
tilt (2.0.10)
20+
21+
PLATFORMS
22+
ruby
23+
24+
DEPENDENCIES
25+
launchy
26+
pg
27+
sinatra
28+
29+
BUNDLED WITH
30+
2.0.2

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# TodoList App
2+
3+
Getting started:
4+
5+
```
6+
cd to-do-list-db
7+
psql -f db/migrations/01_create_todolist_table.sql
8+
psql -f db/migrations/02_create_todolist_test_table.sql
9+
rspec
10+
```
11+
12+
There is a green feature test that can view a list of todo items
13+
14+
There is a failing feature test which (when green) can insert
15+
a new todo item from the browser and then displays the list of
16+
all the todo lists
17+
18+
### Step 1
19+
Implement the code to make the failing test green.
20+
21+
You will need to think about how to add data from the browser and how to store this in the database. You will also need to think about what unit tests you need to write.
22+
23+
### Step 2
24+
Add this feature. Remember to write a feature test
25+
26+
```
27+
As a user I would like to be able to set an optional deadline on
28+
my to do items
29+
```

app.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'sinatra/base'
2+
require_relative 'lib/todo.rb'
3+
4+
class TodoListApp < Sinatra::Base
5+
get '/' do
6+
"hello world"
7+
end
8+
get '/todos' do
9+
@items = Todo.all
10+
erb :todos
11+
end
12+
end

config.ru

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require_relative 'app.rb'
2+
3+
run TodoListApp
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE DATABASE TodoList;
2+
\c todolist;
3+
CREATE TABLE Todo(id SERIAL PRIMARY KEY, title VARCHAR, body VARCHAR);
4+
INSERT INTO TODO (title, body) VALUES ('Today', 'Buy milk');
5+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE DATABASE TodoList_test;
2+
\c todolist_test;
3+
CREATE TABLE todo(id SERIAL PRIMARY KEY, title VARCHAR, body VARCHAR);

lib/todo.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'pg'
2+
class Todo
3+
4+
attr_reader :title, :body
5+
6+
def initialize(title, body)
7+
@title = title
8+
@body = body
9+
end
10+
11+
def self.all
12+
if ENV['RACK_ENV'] == 'test'
13+
conn = PG.connect(dbname: 'todolist_test')
14+
else
15+
conn = PG.connect(dbname: 'todolist')
16+
end
17+
rows = conn.query("SELECT * FROM TODO;")
18+
conn.close
19+
rows.map { |r|
20+
Todo.new(r["title"], r["body"])
21+
}
22+
end
23+
24+
end

spec/features/helloworld_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require 'capybara/rspec'
2+
3+
feature "app" do
4+
5+
scenario 'can call the index page' do
6+
visit("/")
7+
expect(page).to have_content("hello world")
8+
end
9+
10+
end

0 commit comments

Comments
 (0)