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

setup chitter #209

Open
wants to merge 2 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ GEM
mini_mime (1.1.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nokogiri (1.12.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.12.3-x86_64-darwin)
racc (~> 1.4)
parallel (1.20.1)
Expand Down Expand Up @@ -83,6 +85,7 @@ GEM
nokogiri (~> 1.8)

PLATFORMS
arm64-darwin-21
x86_64-darwin-20

DEPENDENCIES
Expand Down
6 changes: 6 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
require 'sinatra/base'
require_relative './lib/little_chits'

class Chitter < Sinatra::Base
get '/test' do
'Test page'
end
Comment on lines 5 to 7
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good practice to remove test code before submitting code for review (anywhere, not just at Makers)


get '/chitter' do
@all_chits = Chits.all
erb(:index)
end

run! if app_file == $0
end
18 changes: 18 additions & 0 deletions lib/little_chits.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'pg'

class Chits

def self.all

if ENV['ENVIRONMENT'] == 'test'
connection = PG.connect(dbname: 'chitter_test')
else
connection = PG.connect(dbname: 'chitter')
end

result = connection.exec("SELECT * FROM peeps;")
result.map { |chit| chit['message'] }

end

end
13 changes: 13 additions & 0 deletions spec/features/test_page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
require 'pg'

feature 'Viewing test page' do
scenario 'visiting the test page' do
visit('/test')
expect(page).to have_content "Test page"
end

scenario 'visit chitter and see chits' do
connection = PG.connect(dbname: 'chitter_test')
connection.exec("INSERT INTO peeps VALUES(1, 'test-peep');")

visit('/chitter')

expect(page).to have_content "Welcome to Chitter!"
expect(page).to have_content "test-peep"
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice feature test!


end
22 changes: 22 additions & 0 deletions spec/little_chits_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'little_chits'

describe Chits do

describe '.all' do

it 'shows all chits' do
connection = PG.connect(dbname: 'chitter_test')

# Add the test data
connection.exec("INSERT INTO peeps (message) VALUES ('Chit One');")
connection.exec("INSERT INTO peeps (message) VALUES('Chit Two');")

all_chits = Chits.all

expect(all_chits).to include("Chit One")
expect(all_chits).to include("Chit Two")
end

end

end
10 changes: 10 additions & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Welcome to Chitter&trade;!</h1>
<p style="text-align:center;">
<img src="https://pbs.twimg.com/profile_images/700881309204238336/v7031RXd_400x400.jpg"></p>
<h2>Here's your list of peeps:</h2>

<ul>
<% @all_chits.each do |chits| %>
<li><%= chits %></li>
<% end %>
</ul>