-
Notifications
You must be signed in to change notification settings - Fork 235
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
Miranda Frudd - chitter challenge (unfinished) #235
Open
MirandaFrudd
wants to merge
15
commits into
makersacademy:main
Choose a base branch
from
MirandaFrudd:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2c98eba
Set up database and added a comment to app.rb for first commit
MirandaFrudd 6329b1b
Added plan for first user story to the README file
MirandaFrudd 96908d2
First passing test - unit test Message #all
MirandaFrudd 51209b4
/messages displays hard coded messages. Need to add a form next.
MirandaFrudd 0463a2f
Added form to homepage, directs to /messages but does not make a post…
MirandaFrudd 293d014
Added the message params to POST /messages
MirandaFrudd cb4774f
added session to make sure message shows
MirandaFrudd e1e59a2
Tested the form works with capybara
MirandaFrudd e6fe070
Connected the class to the chitter db. Spent ages trying to connect t…
MirandaFrudd fb5ef0a
all messages using chitter_test db works
MirandaFrudd 0c3031e
Small changes to README - adding how to run the program
MirandaFrudd 5254d32
Tried to make messages #create method work, but ended up commenting i…
MirandaFrudd 0d6b20f
Test passing for Message.create
MirandaFrudd 4e08431
Messages populate from the db
MirandaFrudd 14561ea
Created user table and User class
MirandaFrudd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE TABLE users(id SERIAL PRIMARY KEY, name VARCHAR(150), email VARCHAR(60), password VARCHAR(60)); |
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,22 @@ | ||
require 'pg' | ||
|
||
class Message | ||
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 { |peep| peep['message'] } | ||
end | ||
|
||
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 |
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,22 @@ | ||
require 'pg' | ||
|
||
class User | ||
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 users;') | ||
result.map { |peep| peep['name'] } | ||
end | ||
|
||
def self.create(name, email, password) | ||
if ENV['ENVIRONMENT'] == 'test' | ||
connection = PG.connect(dbname: 'chitter_test') | ||
else | ||
connection = PG.connect(dbname: 'chitter') | ||
end | ||
connection.exec("INSERT INTO users (name, email, password) VALUES ('#{name}', '#{email}', '#{password}');") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
feature '/' do | ||
scenario 'to have a form' do | ||
visit '/' | ||
fill_in 'Message', with: 'First Message' | ||
expect(page).to have_button('Submit') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
feature '/' do | ||
scenario 'to submit a form' do | ||
visit '/' | ||
fill_in 'Message', with: 'First Message' | ||
click_on 'Submit' | ||
visit '/messages' | ||
expect(page).to have_content "First Message" | ||
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. This is a good example of a feature test, well done! |
||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
require 'message' | ||
|
||
RSpec.describe '.all' do | ||
context "so that I can see what people are doing" do | ||
it "#all displays all messages" do | ||
connection = PG.connect(dbname: 'chitter_test') | ||
|
||
connection.exec("INSERT INTO peeps (message) VALUES ('First message')") | ||
connection.exec("INSERT INTO peeps (message) VALUES ('Second message')") | ||
|
||
messages = Message.all | ||
|
||
expect(messages).to include "First message" | ||
expect(messages).to include "Second message" | ||
|
||
end | ||
end | ||
end | ||
|
||
RSpec.describe '.create' do | ||
context "so that I can create a new message" do | ||
it "#create adds a new message" do | ||
message = Message.create('Another message') | ||
expect(Message.all).to include "Another message" | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'user' | ||
|
||
describe User do | ||
context "#all" do | ||
it "returns all users" do | ||
user1 = User.create("example name1", "[email protected]", "password1") | ||
expect(User.all[-1]).to eq "example name1" | ||
end | ||
end | ||
|
||
context "#create" do | ||
it "adds a user" do | ||
User.create("example name2", "[email protected]", "password2") | ||
expect(User.all[-1]).to eq "example name2" | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<form action="/message" method="post" > | ||
<label for="message">Message</label> | ||
<input id="message" name="message" type="text" /> | ||
<input name="submit" type="submit" value="Submit" /> | ||
<label for="start">Post date</label> | ||
<input type="date" id="start" name="start" | ||
required pattern="\d{4}-\d{2}-\d{2}" | ||
value="2022-07-22" | ||
min="2022-01-01" max="2023-12-31"> | ||
</form> |
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,3 @@ | ||
<% @messages.each do | message | %> | ||
<li> <%= message %> </li> | ||
<% end %> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You're using this same piece of code in more than one place in this file. How might you get rid of this duplication?