-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
first try #224
base: main
Are you sure you want to change the base?
first try #224
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ end | |
group :development, :test do | ||
gem 'rubocop', '1.20' | ||
end | ||
|
||
gem "reloader", "~> 0.1.0" | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,32 @@ GEM | |
rack-test (>= 0.6.3) | ||
regexp_parser (>= 1.5, < 3.0) | ||
xpath (~> 3.2) | ||
cookiejar (0.3.3) | ||
daemons (1.4.1) | ||
diff-lcs (1.4.4) | ||
docile (1.4.0) | ||
em-http-request (1.1.7) | ||
addressable (>= 2.3.4) | ||
cookiejar (!= 0.3.1) | ||
em-socksify (>= 0.3) | ||
eventmachine (>= 1.0.3) | ||
http_parser.rb (>= 0.6.0) | ||
em-socksify (0.3.2) | ||
eventmachine (>= 1.0.0.beta.4) | ||
eventmachine (1.2.7) | ||
faye (0.5.0) | ||
em-http-request (>= 0.2) | ||
eventmachine (>= 0.12) | ||
json (>= 1.0) | ||
rack (>= 1.0) | ||
thin (>= 1.2) | ||
ffi (1.15.5) | ||
growl (1.0.3) | ||
http_parser.rb (0.8.0) | ||
iobuffer (1.1.2) | ||
json (2.6.1) | ||
libnotify (0.9.4) | ||
ffi (>= 1.0.11) | ||
mini_mime (1.1.1) | ||
mustermann (1.1.1) | ||
ruby2_keywords (~> 0.0.1) | ||
|
@@ -32,8 +56,23 @@ GEM | |
rack-test (1.1.0) | ||
rack (>= 1.0, < 3) | ||
rainbow (3.0.0) | ||
rb-inotify (0.10.1) | ||
ffi (~> 1.0) | ||
regexp_parser (2.1.1) | ||
reloader (0.1.0) | ||
faye (= 0.5.0) | ||
rev (= 0.3.2) | ||
rspactor (= 0.7.0.beta.5) | ||
thin (= 1.2.7) | ||
rev (0.3.2) | ||
iobuffer (>= 0.1.3) | ||
rexml (3.2.5) | ||
rspactor (0.7.0.beta.5) | ||
growl (>= 1.0.3) | ||
libnotify (>= 0.1.3) | ||
rb-inotify | ||
sys-uname (>= 0.8.4) | ||
trollop (>= 1.16.2) | ||
rspec (3.10.0) | ||
rspec-core (~> 3.10.0) | ||
rspec-expectations (~> 3.10.0) | ||
|
@@ -75,9 +114,16 @@ GEM | |
rack (~> 2.2) | ||
rack-protection (= 2.1.0) | ||
tilt (~> 2.0) | ||
sys-uname (1.2.2) | ||
ffi (~> 1.1) | ||
terminal-table (3.0.1) | ||
unicode-display_width (>= 1.1.1, < 3) | ||
thin (1.2.7) | ||
daemons (>= 1.0.9) | ||
eventmachine (>= 0.12.6) | ||
rack (>= 1.0.0) | ||
tilt (2.0.10) | ||
trollop (2.9.10) | ||
unicode-display_width (2.0.0) | ||
xpath (3.2.0) | ||
nokogiri (~> 1.8) | ||
|
@@ -88,6 +134,7 @@ PLATFORMS | |
DEPENDENCIES | ||
capybara | ||
pg | ||
reloader | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sinatra? |
||
rspec | ||
rubocop (= 1.20) | ||
simplecov | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
require 'sinatra/base' | ||
require './lib/messages' | ||
|
||
class Chitter < Sinatra::Base | ||
get '/test' do | ||
'Test page' | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice restful routes |
||
get '/peeps' do | ||
@peeps = Messages.all | ||
erb :index | ||
end | ||
|
||
get '/peeps/new' do | ||
erb :newpeep | ||
end | ||
|
||
post'/peeps' do | ||
# erb :'newpeep' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note required? |
||
message = params["message"] | ||
Messages.create(message) | ||
redirect '/peeps' | ||
end | ||
|
||
run! if app_file == $0 | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
CREATE TABLE peeps(id SERIAL PRIMARY KEY, message VARCHAR(60)); | ||
CREATE TABLE peeps(id SERIAL PRIMARY KEY, message VARCHAR(60)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'pg' | ||
|
||
class Messages | ||
|
||
def self.all | ||
connection = PG.connect(dbname: 'chitter') | ||
result = connection.exec("SELECT * FROM peeps;") | ||
result.map { |peeps| peeps['message'] } | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep indentation consistent |
||
|
||
def self.create(message) | ||
if ENV['ENVIRONMENT'] == 'test' | ||
connection = PG.connect(dbname: 'chitter_test') | ||
else | ||
connection = PG.connect(dbname: 'chitter') | ||
end | ||
connection.exec("INSERT INTO peeps (message) VALUES('#{message}')") | ||
end | ||
|
||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'messages' | ||
|
||
describe Messages do | ||
describe '.all' do | ||
it 'returns all the peeps' do | ||
peeps = Messages.all | ||
|
||
expect(peeps).to include("This is a message") | ||
expect(peeps).to include("this is also another message") | ||
expect(peeps).to include("I'm learning ruby") | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
visit('/test') | ||
expect(page).to have_content "Test page" | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
feature 'Viewing peeps' do | ||
scenario 'visiting the page shows peeps' do | ||
visit('/peeps') | ||
|
||
expect(page).to have_content "This is a message" | ||
expect(page).to have_content "this is also another message" | ||
expect(page).to have_content "I'm learning ruby" | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<ul> | ||
<% @peeps.each do |peeps| %> | ||
<li><%= peeps %></li> | ||
<% end %> | ||
</ul> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<form action="/peeps" method="post"> | ||
<input type="text" name="message" placeholder="peep"/> | ||
<input type="submit" value="Submit" /> | ||
</form> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this? Did you mean sinatra?