From a523bcd60335cb7161a7f167fb501c26827809f7 Mon Sep 17 00:00:00 2001 From: Ronan Hughes Date: Fri, 15 Jul 2022 12:37:40 +0100 Subject: [PATCH] MVC installation and RSpec test to suit --- Gemfile | 1 + Gemfile.lock | 11 +++++++++++ README2.md | 26 +++++++++++++++++++++++++ app.rb | 29 ++++++++++++++++++++++++++-- lib/peeps.rb | 8 ++++++++ spec/features/date_of_peep.rb | 0 spec/features/list_peeps_spec.rb | 31 ++++++++++++++++++++++++++++++ spec/features/posting_peep_spec.rb | 0 spec/features/test_page_spec.rb | 8 ++++---- spec/peep_spec.rb | 0 views/homepage/index.erb | 5 +++++ views/new.erb | 0 12 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 README2.md create mode 100644 lib/peeps.rb create mode 100644 spec/features/date_of_peep.rb create mode 100644 spec/features/list_peeps_spec.rb create mode 100644 spec/features/posting_peep_spec.rb create mode 100644 spec/peep_spec.rb create mode 100644 views/homepage/index.erb create mode 100644 views/new.erb diff --git a/Gemfile b/Gemfile index 99d8e519..d0d971e8 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ ruby '3.0.2' gem 'pg' gem 'sinatra' +gem 'sinatra-contrib' group :test do gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index 7d4eb449..89504308 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,8 +16,11 @@ GEM diff-lcs (1.4.4) docile (1.4.0) mini_mime (1.1.1) + multi_json (1.15.0) 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) @@ -75,6 +78,12 @@ GEM rack (~> 2.2) rack-protection (= 2.1.0) tilt (~> 2.0) + sinatra-contrib (2.1.0) + multi_json + mustermann (~> 1.0) + rack-protection (= 2.1.0) + sinatra (= 2.1.0) + tilt (~> 2.0) terminal-table (3.0.1) unicode-display_width (>= 1.1.1, < 3) tilt (2.0.10) @@ -83,6 +92,7 @@ GEM nokogiri (~> 1.8) PLATFORMS + arm64-darwin-21 x86_64-darwin-20 DEPENDENCIES @@ -93,6 +103,7 @@ DEPENDENCIES simplecov simplecov-console sinatra + sinatra-contrib RUBY VERSION ruby 3.0.2p107 diff --git a/README2.md b/README2.md new file mode 100644 index 00000000..787aec72 --- /dev/null +++ b/README2.md @@ -0,0 +1,26 @@ +As a Maker +So that I can see what people are doing +I want to see all the messages (peeps) +in a browser + +As a Maker +So that I can let people know what I am doing +I want to post a message (peep) to chitter + +As a Maker +So that I can see when people are doing things +I want to see the date the message was posted + + + + + +DATABASE TABLE +As a Maker +So that I can easily see the latest peeps +I want to see a list of peeps in reverse chronological order + + +As a Maker +So that I can find relevant peeps +I want to filter on a specific keyword \ No newline at end of file diff --git a/app.rb b/app.rb index 2450fb92..0c1f42cf 100644 --- a/app.rb +++ b/app.rb @@ -1,9 +1,34 @@ require 'sinatra/base' +require 'sinatra/reloader' class Chitter < Sinatra::Base - get '/test' do - 'Test page' + configure :development do + register Sinatra::Reloader end + get '/' do + "Welcome to Chitter! It's like Twitter, but with Ch :P" + end + + + get '/homepage' do + @peep_posts = ["look at my new car!", + "Check out my new puppy!", + "Look at the sky today!"] + erb :'homepage/index' + end + + + + + + + + + + + + + run! if app_file == $0 end diff --git a/lib/peeps.rb b/lib/peeps.rb new file mode 100644 index 00000000..ec9ce021 --- /dev/null +++ b/lib/peeps.rb @@ -0,0 +1,8 @@ +class Peeps + def self.all + [ "look at my new car!", + "Check out my new puppy!", + "Look at the sky today!" ] + + end +end diff --git a/spec/features/date_of_peep.rb b/spec/features/date_of_peep.rb new file mode 100644 index 00000000..e69de29b diff --git a/spec/features/list_peeps_spec.rb b/spec/features/list_peeps_spec.rb new file mode 100644 index 00000000..f9985406 --- /dev/null +++ b/spec/features/list_peeps_spec.rb @@ -0,0 +1,31 @@ +# feature 'Viewing Peeps' do +# scenario 'A user can see messages' do +# visit('/homepage') + +# expect(page).to have_content "look at my new car!" +# expect(page).to have_content "Check out my new puppy!" +# expect(page).to have_content "Look at the sky today!" +# end +# end + + require 'peeps' + + describe Peeps do + describe '.all' do + it 'returns all peeps' do + all_peeps = Peeps.all + + expect(all_peeps).to include("look at my new car!") + expect(all_peeps).to include("Check out my new puppy!") + expect(all_peeps).to include("Look at the sky today!") + end + end + end + + + + + + + + diff --git a/spec/features/posting_peep_spec.rb b/spec/features/posting_peep_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/spec/features/test_page_spec.rb b/spec/features/test_page_spec.rb index b65ac196..55c273ed 100644 --- a/spec/features/test_page_spec.rb +++ b/spec/features/test_page_spec.rb @@ -1,6 +1,6 @@ -feature 'Viewing test page' do - scenario 'visiting the test page' do - visit('/test') - expect(page).to have_content "Test page" +feature 'Viewing welcome page' do + scenario 'visiting the welcome page' do + visit('/') + expect(page).to have_content "Welcome to Chitter! It's like Twitter, but with Ch :P" end end diff --git a/spec/peep_spec.rb b/spec/peep_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/views/homepage/index.erb b/views/homepage/index.erb new file mode 100644 index 00000000..d2e7a26d --- /dev/null +++ b/views/homepage/index.erb @@ -0,0 +1,5 @@ + diff --git a/views/new.erb b/views/new.erb new file mode 100644 index 00000000..e69de29b