forked from makersacademy/chitter-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed timestamp. added signup page. fixed rspec tests
- Loading branch information
Showing
10 changed files
with
62 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,47 @@ | ||
require 'active_record' | ||
require 'sinatra' | ||
require "sinatra/reloader" | ||
require 'sinatra/reloader' | ||
require 'active_record' | ||
require_relative 'lib/database_connection' | ||
require_relative 'lib/post' | ||
require_relative 'lib/user' | ||
|
||
# Establish the database connection | ||
establish_database_connection | ||
|
||
class Application < Sinatra::Base | ||
configure :development do | ||
register Sinatra::Reloader | ||
also_reload 'lib/database_connection' | ||
also_reload 'lib/post' | ||
also_reload 'lib/user' | ||
end | ||
|
||
configure do | ||
# Set the default timezone to GMT | ||
ENV['TZ'] = 'GMT' | ||
end | ||
|
||
get '/' do | ||
p "Printing from app.rb line 16" | ||
p Post.all_peeps | ||
@posts = Post.all_peeps | ||
@posts = @posts.reverse | ||
return erb(:index) | ||
@posts = Post.all_peeps.reverse | ||
erb :index | ||
end | ||
|
||
post '/' do | ||
# def invalid_request_parameters? | ||
# # Are the params nil? | ||
# return true if params[:message] == nil | ||
|
||
# # Are they empty strings? | ||
# return true if params[:message] | ||
|
||
# return false | ||
# end | ||
# if invalid_request_parameters? | ||
# status 400 | ||
|
||
# return 'Please enter a message' | ||
# end | ||
|
||
# Parameters are valid, | ||
# the rest of the route can execute. | ||
Post.create(time: Time.now, message: params[:message], user_id: 1) | ||
current_time = Time.now + 1 * 60 * 60 # Get the current time with GMT offset | ||
Post.create(time: current_time, message: params[:message], user_id: 1) | ||
redirect '/' | ||
end | ||
|
||
get '/signup' do | ||
erb(:signup) | ||
end | ||
|
||
end | ||
post '/signup' do | ||
User.create(username: params[:username], email: params[:email], password: params[:password]) | ||
redirect '/success' | ||
end | ||
|
||
get '/success' do | ||
erb(:success) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
require 'post' | ||
require 'reset_tables' | ||
|
||
|
||
RSpec.describe Post do | ||
before(:each) do | ||
reset = ResetTables.new | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
require 'user' | ||
require 'reset_tables' | ||
|
||
|
||
RSpec.describe User do | ||
before(:each) do | ||
reset = ResetTables.new | ||
reset.reset_users_table | ||
end | ||
it 'return all users from the database' do | ||
expect(User.all_records.first[:email]).to eq('[email protected]') | ||
expect(User.all_records[0][:email]).to eq('[email protected]') | ||
expect(User.all_records[1][:email]).to eq('[email protected]') | ||
end | ||
it 'creates a new user and returns the table' do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Welcome to Chitter!</h1> | ||
<div>Please register your details below</div> | ||
<div><form action="/signup" method="POST"> | ||
<div>Username</div> | ||
<input type="text" name="username"> | ||
<div>Password</div> | ||
<input type="text" name="password"> | ||
<div>Email</div> | ||
<input type="text" name="email"> | ||
<input type="submit" value="Signup"> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Success!</h1> | ||
<div><a href="http://localhost:9292/">click here to return to the homepage</a></div> | ||
</body> | ||
</html> |