11-02-2022
Meta Stuff
Maybe have yet another crack at the bspwm config ( maybe commentout all monitors and then start again? idk ) - but only after having finished this challenge
Postscript I wasn't consistent with past weeks walkthroughs which was a shame. I will try again in the future - if there are such oppportunities.
Interesting video against OOP
InfoQ - Rich Hickey - Simple Made Easy
Makes me want to reimplement today's task in Clojure...
My interest is further piqued...
Today's Foci
Focus 1
- UML for Class, Class(ER), and Sequences for the user stories
- Create a programme from those plans
Topic
Friday Challenge Twitter Clone
Create a twitter clone using the TDD paradigm. Implement a Postgres database.
Using tools: Ruby, Sinatra web-framework, Capybara testing-framework (selenium interface), PostgreSQL.
Setup
I was about to jump into diagramming, but I'm gonna run the setup first
scratch that - figure everything out, then run the setup. Read through - include implications of setup in the diagramming - possibly?
Remember
PSQL DB
PSQL DB_test
bundle
rspec - one passing
User Stories
As a User
So that I can see what people are doing
I want to see all the messages (peeps)
in a browser
As a User
So that I can let people know what I am doing
I want to post a message (peep) to chitter
As a User
So that I can see when people are doing things
I want to see the date the message was posted
As a User
So that I can easily see the latest peeps
I want to see a list of peeps in reverse chronological order
As a User
So that I can find relevant peeps
I want to filter on a specific keyword
I have been distracted by the hot air balloon outside my window. Pretty in the morning sun! :)
( There were three of them! again, I need to figure out photos on Zola... )
Object | Method | Attribute |
---|---|---|
Message | list | date |
post | message | |
latest | ||
search_text | ||
DatabaseConnection | setup | |
connection | ||
query |
There should be a better diagram available at the repo - i'll try and link it here but again; Zola images have confunfdled me.
Apparently TIMESTAMP is for updating records; DATETIME is for inserting those records - use TIMESTAMP for updates/edits to such a message? not implementing here however
In planning, I'm thinking - amend the list, to take an optional argument, ( by kword ) which pass an array of search by kword in kwords? is that doable? hmm...
also?
def list(latest=false)
return all_messages unless latest=true
all_messages.by_datetime_reversed
end
saves making another function? idk. perhaps not, breaks srp?
Both below examples are wrong
But they pushed me in the right direction
- find dates by latest using SQL
SELECT * FROM table_name WHERE dates_column IN (SELECT max(dates_column) FROM table_name);
- search VARCHAR for a single keyword
SELECT * FROM table_name WHERE search_column LIKE %keyword%
I think all diagrams and planning are done! Had a break. Time for the setup and implementation.
had to run dos2unix on the svgs again - should probably make a bash script for that at a later date
Setup
I'm gonna be cheeky and add the auto-datefield in advance. I've got a life to live! :cry_laughing:
Hmm, the above SQL was wrong & outdated - here's something closer
CREATE TABLE peeps(id SERIAL PRIMARY KEY, message VARCHAR(160), created_date timestamp default CURRENT_TIMESTAMP);
might cause some problems using CURRENT_TIMESTAMP instead of LOCALTIMESTAMP, but i'll cross that bridge when I come to it I suppose. Probably going to come to it immediately, knowing my luck!
Well, seems to have worked, and I'm not seeing the timezone value - so maybe this won't be a big a problem as I had originally thought?
I have a single passing test! Ace!
Tests
Time to design some tests
If I were to test the model first, I'd check the database is working properly... this will require some work
First test is - does the user see what's in the browser? well, to do that I will need to implement the DatabaseConnector, and the Peeps classes.
And the app.rb route.
so in one test, I will attempt to inspect the database ( I need to clean it beforehand )
fundamentally, I'm gonna steal the database connector and a lot of code from the pair project - oh wait, it's already provided. Saves me working!
Retro
Learn Good Git Hygeine
On Task
Get the homepage working
Right, so that took me a good amount of time to sort out - had to fix several bugs, the final hurdle being a missing semi-colon in a testing statement, and my assuming that I was using a route already - I missed placing the 'visit('/')' in the RSpec.
Need to cook dinner, but UStories 1 & 3 are now completed - Now to implement a post, which won't take too long, I hope.
Post route, via a Message.create function, using the DatabaseConnection interface, before returning the user to the homepage.
okay... that actually worked.
simply writing it out above helped too, actually. huh.
Post Din-Dins
What's next?
Sort by latest.
Perhaps I can figure out how to extract the timestamp from postgres without the fraction
ooo found
date_trunc('minute', timestamp_field)
an interesting way to use matchers to find the first field!
expect(find.("h4", match: :first)).to have_content "something")
another one done - now I need to implement the search function
search functionality
add searchbar to homepage
form to GET a keyword within SQL
redirect to search
found away to use exec_params interpolation in PostgreSQL LIKE Statement!
and in postgres
ILIKE
allows for case insensitive searching!
huh, I think it's all working! could do with a little TLC, but its midnight, so I'm done!