Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Your name

Please write your full name here to make it easier to find your pull request.

Abdirizak Idris
# User stories

Please list which user stories you've implemented (delete the ones that don't apply).
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ end
group :development, :test do
gem 'rubocop', '1.20'
end

gem "reloader", "~> 0.1.0"

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?

47 changes: 47 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -88,6 +134,7 @@ PLATFORMS
DEPENDENCIES
capybara
pg
reloader

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sinatra?

rspec
rubocop (= 1.20)
simplecov
Expand Down
19 changes: 18 additions & 1 deletion app.rb
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

Choose a reason for hiding this comment

The 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'

Choose a reason for hiding this comment

The 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
2 changes: 1 addition & 1 deletion db/migrations/01_create_chitter_table.sql
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));
21 changes: 21 additions & 0 deletions lib/messages.rb
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

Choose a reason for hiding this comment

The 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
13 changes: 13 additions & 0 deletions spec/features/messages_spec.rb
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
2 changes: 1 addition & 1 deletion spec/features/test_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
visit('/test')
expect(page).to have_content "Test page"
end
end
end
10 changes: 10 additions & 0 deletions spec/features/veiwing peeps_spec.rb
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
5 changes: 5 additions & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul>
<% @peeps.each do |peeps| %>
<li><%= peeps %></li>
<% end %>
</ul>
4 changes: 4 additions & 0 deletions views/newpeep.erb
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>