From 4f6f03deea5845ef99ae047f52ee534936348481 Mon Sep 17 00:00:00 2001 From: jason perez Date: Tue, 14 Jan 2014 19:13:06 -0800 Subject: [PATCH 1/8] add shotgun to gemfile --- Gemfile | 1 + Gemfile.lock | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Gemfile b/Gemfile index 416fe44..9d537b6 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,4 @@ gem 'rake' gem 'activesupport' gem 'sinatra' gem 'sinatra-contrib' +gem 'shotgun' diff --git a/Gemfile.lock b/Gemfile.lock index 3d79568..1f59487 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,6 +14,8 @@ GEM rack-test (0.6.1) rack (>= 1.0) rake (0.9.2.2) + shotgun (0.9) + rack (>= 1.0) sinatra (1.3.2) rack (~> 1.3, >= 1.3.6) rack-protection (~> 1.2) @@ -33,5 +35,6 @@ PLATFORMS DEPENDENCIES activesupport rake + shotgun sinatra sinatra-contrib From dcd5fbe41de5f9f7c186ac35ca690f7925609697 Mon Sep 17 00:00:00 2001 From: jason perez Date: Tue, 14 Jan 2014 19:27:25 -0800 Subject: [PATCH 2/8] add basic about page, add route for about page, update dashboard html --- theweb.rb | 4 ++++ views/about.erb | 21 +++++++++++++++++++++ views/dashboard.erb | 15 +++++++++------ views/layout.erb | 26 ++------------------------ 4 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 views/about.erb diff --git a/theweb.rb b/theweb.rb index a531ce4..fe5304d 100644 --- a/theweb.rb +++ b/theweb.rb @@ -16,3 +16,7 @@ @the_number = rand(number_as_string) erb :number end + +get '/about' do + erb :about +end diff --git a/views/about.erb b/views/about.erb new file mode 100644 index 0000000..20ea3e9 --- /dev/null +++ b/views/about.erb @@ -0,0 +1,21 @@ +
+

About Jason.

+
+ +
+
+

Heading

+

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.

+

View details »

+
+
+

Heading

+

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.

+

View details »

+
+
+

Heading

+

Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

+

View details »

+
+
diff --git a/views/dashboard.erb b/views/dashboard.erb index d2559c0..c3b84aa 100644 --- a/views/dashboard.erb +++ b/views/dashboard.erb @@ -1,6 +1,9 @@ -

OH HAI THERE

-
- - - -
+ +
+

OH HAI THERE

+
+ + + +
+
\ No newline at end of file diff --git a/views/layout.erb b/views/layout.erb index 8797f75..93c17ed 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -46,7 +46,7 @@ @@ -56,29 +56,7 @@
- -
- <%= yield %> -
- - -
-
-

Heading

-

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.

-

View details »

-
-
-

Heading

-

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.

-

View details »

-
-
-

Heading

-

Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

-

View details »

-
-
+ <%= yield %>
From 622e8de7dd0cedf92058d8d14273d405e7779b8f Mon Sep 17 00:00:00 2001 From: jason perez Date: Tue, 14 Jan 2014 22:34:13 -0800 Subject: [PATCH 3/8] update about page --- views/about.erb | 37 ++++++++++++++++++++----------------- views/layout.erb | 8 ++++---- views/number.erb | 4 +++- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/views/about.erb b/views/about.erb index 20ea3e9..fb36ad6 100644 --- a/views/about.erb +++ b/views/about.erb @@ -1,21 +1,24 @@ -
-

About Jason.

-
-
-
-

Heading

-

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.

-

View details »

+
+
+ +
+
+

About Me.

+

+ My name is Jason. I’ve been in the role of Business Analyst for over 10 years now. +

+
-
-

Heading

-

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.

-

View details »

-
-
-

Heading

-

Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

-

View details »

+ + +
+
+

+ I didn’t set out to be a Business Analyst. In fact, I was initially a fine arts major. I like drawing pictures and thought it’d be cool to draw illustrations for a living… but things change, and I switched to a general business major. +

+

+ I've always enjoyed solving the tough problems thrown my way as an analyst. There are patterns that are predictable, but there's always enough variability to keep it interesting. It's a bit like solving a puzzle. +

diff --git a/views/layout.erb b/views/layout.erb index 93c17ed..e749ea1 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -60,10 +60,10 @@
-
-

Number of Randoms: <%= @number_of_randoms %>

- OH HAI THERE -

© Company 2012

+
+
© Company 2012

+
diff --git a/views/number.erb b/views/number.erb index 8cdbad4..1398cbc 100644 --- a/views/number.erb +++ b/views/number.erb @@ -1,2 +1,4 @@

OH HAI THERE

-

The number is <%= @the_number %> +

The number is <%= @the_number %>

+ +

Number of Randoms: <%= @number_of_randoms %>

From 6e46c00a96df3bf4f7005b96f9cf78ac86db52d4 Mon Sep 17 00:00:00 2001 From: jason perez Date: Tue, 14 Jan 2014 23:43:02 -0800 Subject: [PATCH 4/8] add random cookbook recommendation picker to about page --- my_picks.yml | 37 +++++++++++++++++++++++++++++++++++++ theweb.rb | 3 +++ views/about.erb | 39 +++++++++++++++++++++++++++++---------- 3 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 my_picks.yml diff --git a/my_picks.yml b/my_picks.yml new file mode 100644 index 0000000..1b25027 --- /dev/null +++ b/my_picks.yml @@ -0,0 +1,37 @@ +- + book_name: The New Making of a Cook + author: Madeleine Kamman + description: The Making of a Cook became an instant classic upon its publication in 1971. Since then much has changed in the way America cooks and The New Making of a Cook meets these changes head-on. This fully revised edition teaches every technique used in today's homes and professional kitchens, from julienning vegetables to roasting meats to steaming fish to baking bread. With years of experience teaching America's top chefs how to cook, Madeleine knows what works and why. + url: http://www.amazon.com/The-New-Making-Cook-Techniques/dp/0688152546 + image: http://ecx.images-amazon.com/images/I/512WPH9QP0L._SX258_BO1,204,203,200_.jpg +- + book_name: The Food and Life of Oaxaca, Mexico + author: Zarela Martinez + description: The Food and Life of Oaxaca, by New York restaurateur Zarela Martinez, is a fascinating cultural study disguised as a great cookbook. Martinez is part of the new renaissance of Mexican food writers and chefs, including Rick Bayless and Diana Kennedy, who reaffirm that culinary awareness goes hand in hand with cultural awareness. + url: http://www.amazon.com/The-Food-Life-Oaxaca-Mexico/dp/0028603508 + image: http://ecx.images-amazon.com/images/I/51za6Qork%2BL._SX258_PJlook-inside-v2,TopRight,1,0_SH20_BO1,204,203,200_.jpg +- + book_name: Larousse Gastronomique + author: Prosper Montagne + description: Since its first publication in 1938, Larousse Gastronomique has been an unparalleled resource. In one volume, it presents the history of foods, eating, and restaurants; cooking terms; techniques from elementary to advanced; a review of basic ingredients with advice on recognizing, buying, storing, and using them; biographies of important culinary figures; and recommendations for cooking nearly everything. + + url: http://www.amazon.com/Larousse-Gastronomique-Prosper-Montagne/dp/0609609718 + image: http://ecx.images-amazon.com/images/I/41eqmG3PX2L._SY344_PJlook-inside-v2,TopRight,1,0_SH20_BO1,204,203,200_.jpg +- + book_name: Peace, Love, & Barbecue + author: Mike Mills + description: In this unique combination of cookbook, memoir, and travelogue, Mike Mills, the unrivalled king of barbecue, shares his passion for America's favorite cuisine--its intense smoky flavors, its lore and traditions, and its wild cast of characters. + url: http://www.amazon.com/Peace-Love-Barbecue-Recipes-Outright/dp/1594861099 + image: http://ecx.images-amazon.com/images/I/51hJChNUmEL._SX258_PJlook-inside-v2,TopRight,1,0_SH20_BO1,204,203,200_.jpg +- + book_name: Authentic Mexican + author: Rick Bayless + description: Americans have at last discovered Mexico's passion for exciting food. We've fallen in love with the great Mexican combination of rich, earthy flavors and casual, festive dining. But we don't begin to imagine how sumptuous and varied the cooking of Mexico really is. + url: http://www.amazon.com/Authentic-Mexican-20th-Anniversary-Ed/dp/0061373265 + image: http://ecx.images-amazon.com/images/I/51oZlXhw0NL._SY344_PJlook-inside-v2,TopRight,1,0_SH20_BO1,204,203,200_.jpg +- + book_name: The Art of Cooking Omelettes + author: Madame Romaine De Lyon + description: For 65 years, Madame Romaine de Lyon ran a popular restaurant in midtown New York that served only eggs. But not just any eggs! Mme de Lyon, was a master omelette chef. The walls of her restaurant were covered with signed photos of famous customers, such as Joan Rivers, Mary Tyler Moore, Anne Bancroft, and Mel Brooks (who wrote the screenplay for The Producers at his regular table in the back of the restaurant). + url: http://www.amazon.com/Cooking-Omelettes-Madame-Romaine-Lyon/dp/1626549508 + image: http://ecx.images-amazon.com/images/I/51FmlfPHikL._SY344_BO1,204,203,200_.jpg \ No newline at end of file diff --git a/theweb.rb b/theweb.rb index fe5304d..1651283 100644 --- a/theweb.rb +++ b/theweb.rb @@ -2,6 +2,7 @@ require 'bundler/setup' require 'sinatra' require 'sinatra/reloader' +require 'yaml' enable :sessions get '/' do @@ -18,5 +19,7 @@ end get '/about' do + my_picks = YAML.load(File.read("./my_picks.yml")) + @featured_pick = my_picks.sample erb :about end diff --git a/views/about.erb b/views/about.erb index fb36ad6..524fbae 100644 --- a/views/about.erb +++ b/views/about.erb @@ -1,15 +1,15 @@ -
-
- -
-
-

About Me.

-

- My name is Jason. I’ve been in the role of Business Analyst for over 10 years now. -

-
+
+
+
+
+

About Me.

+

+ My name is Jason. I’ve been in the role of Business Analyst for over 10 years now. +

+
+
@@ -22,3 +22,22 @@

+ +
+
+
+

Featured cookbook recommendation:

+
+
+ "> +
+
+

<%= @featured_pick["book_name"] %>

+

by <%= @featured_pick["author"] %>

+

+ <%= @featured_pick["description"] %> +

+
+
+
+
From 6c679c6d8c462c4af2f09b1227de735820f57fb0 Mon Sep 17 00:00:00 2001 From: jason perez Date: Tue, 14 Jan 2014 23:47:03 -0800 Subject: [PATCH 5/8] move about page to the home page --- theweb.rb | 6 +----- views/layout.erb | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/theweb.rb b/theweb.rb index 1651283..0b2a880 100644 --- a/theweb.rb +++ b/theweb.rb @@ -5,10 +5,6 @@ require 'yaml' enable :sessions -get '/' do - erb :dashboard -end - post '/number' do @number_of_randoms = session[:number_of_randoms] || 0 @number_of_randoms += 1 @@ -18,7 +14,7 @@ erb :number end -get '/about' do +get '/' do my_picks = YAML.load(File.read("./my_picks.yml")) @featured_pick = my_picks.sample erb :about diff --git a/views/layout.erb b/views/layout.erb index e749ea1..a4f55ba 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -46,7 +46,7 @@ From eb8add9a74ad47a55e959ebf0fdfff7e0b60f592 Mon Sep 17 00:00:00 2001 From: jason perez Date: Wed, 15 Jan 2014 22:44:14 -0800 Subject: [PATCH 6/8] update the assignment of picks so that it doesn't load the YAML file every time you visit the page --- theweb.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/theweb.rb b/theweb.rb index 0b2a880..1665acf 100644 --- a/theweb.rb +++ b/theweb.rb @@ -15,7 +15,13 @@ end get '/' do - my_picks = YAML.load(File.read("./my_picks.yml")) + my_picks ||= Picks.new.get_picks @featured_pick = my_picks.sample erb :about end + +class Picks + def get_picks + YAML.load(File.read("./my_picks.yml")) + end +end From 1de352b08f235a9330d017da1cd034337e9430db Mon Sep 17 00:00:00 2001 From: jason perez Date: Tue, 28 Jan 2014 16:14:53 -0800 Subject: [PATCH 7/8] add adventure game from Episode5 --- Gemfile | 3 ++ Gemfile.lock | 24 ++++++++++++++++ adventure.rb | 32 +++++++++++++++++++++ config/database.yml.sample | 6 ++++ db/migrate/001_creates_page.rb | 13 +++++++++ db/seed.rb | 29 +++++++++++++++++++ db/setup.rb | 15 ++++++++++ models/book.rb | 21 ++++++++++++++ models/page.rb | 11 +++++++ spec/.gitkeep | 0 spec/book_spec.rb | 34 ++++++++++++++++++++++ spec/page_spec.rb | 52 ++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 5 ++++ theweb.rb | 5 ++-- 14 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 adventure.rb create mode 100644 config/database.yml.sample create mode 100644 db/migrate/001_creates_page.rb create mode 100644 db/seed.rb create mode 100644 db/setup.rb create mode 100644 models/book.rb create mode 100644 models/page.rb create mode 100644 spec/.gitkeep create mode 100644 spec/book_spec.rb create mode 100644 spec/page_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/Gemfile b/Gemfile index 9d537b6..680f570 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,10 @@ source 'http://rubygems.org' gem 'rake' +gem 'activerecord' gem 'activesupport' gem 'sinatra' gem 'sinatra-contrib' gem 'shotgun' +gem 'rspec' +gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index 1f59487..d3964be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,19 +1,39 @@ GEM remote: http://rubygems.org/ specs: + activemodel (3.2.3) + activesupport (= 3.2.3) + builder (~> 3.0.0) + activerecord (3.2.3) + activemodel (= 3.2.3) + activesupport (= 3.2.3) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) activesupport (3.2.3) i18n (~> 0.6) multi_json (~> 1.0) + arel (3.0.2) backports (2.5.3) + builder (3.0.0) + diff-lcs (1.2.5) eventmachine (0.12.10) i18n (0.6.0) multi_json (1.3.5) + pg (0.17.1) rack (1.4.1) rack-protection (1.2.0) rack rack-test (0.6.1) rack (>= 1.0) rake (0.9.2.2) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.7) + rspec-expectations (2.14.4) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.4) shotgun (0.9) rack (>= 1.0) sinatra (1.3.2) @@ -28,13 +48,17 @@ GEM sinatra (~> 1.3.0) tilt (~> 1.3) tilt (1.3.3) + tzinfo (0.3.38) PLATFORMS ruby DEPENDENCIES + activerecord activesupport + pg rake + rspec shotgun sinatra sinatra-contrib diff --git a/adventure.rb b/adventure.rb new file mode 100644 index 0000000..4209f7c --- /dev/null +++ b/adventure.rb @@ -0,0 +1,32 @@ +require 'rubygems' +require 'bundler/setup' + +require_relative 'db/setup' +require_relative 'models/page' +require_relative 'models/book' +require "./db/seed" + +page = Page.starting_point +book = Book.new(page) + +until book.complete_game? do + puts "------------------------------------------" + puts book.current_page.content + puts "your options: " + puts "A - [#{book.current_page.options.first.preview}]" + puts "B - [#{book.current_page.options.last.preview}]" + puts "What do you want to do? Enter A or B" + + book.input( gets ) + puts "------------------------------------------" + puts book.current_page.outcome + puts "------------------------------------------" +end +puts book.current_page.content +puts "------------------------------------------" +puts "| |" +puts "| |" +puts "| ADVENTURE COMPLETE |" +puts "| |" +puts "| |" +puts "------------------------------------------" diff --git a/config/database.yml.sample b/config/database.yml.sample new file mode 100644 index 0000000..2e5c2a9 --- /dev/null +++ b/config/database.yml.sample @@ -0,0 +1,6 @@ +host: 'localhost' +adapter: 'postgresql' +database: 'episode5' +username: XXXXXXX +encoding: 'utf8' +pool: 5 diff --git a/db/migrate/001_creates_page.rb b/db/migrate/001_creates_page.rb new file mode 100644 index 0000000..325cba3 --- /dev/null +++ b/db/migrate/001_creates_page.rb @@ -0,0 +1,13 @@ +class CreatesPage < ActiveRecord::Migration + def change + create_table :pages do |t| + t.text :content + t.string :preview + t.string :outcome + t.integer :option_a_id + t.integer :option_b_id + t.boolean :starting_point, default: false + t.boolean :conclusion, default: false + end + end +end diff --git a/db/seed.rb b/db/seed.rb new file mode 100644 index 0000000..89a99a2 --- /dev/null +++ b/db/seed.rb @@ -0,0 +1,29 @@ +# Cleaning Out +Page.delete_all +page_two = Page.create(conclusion: true, + preview: "Go into the forest", + outcome: "You were methodically consumed by ZOMBIE DEER!!!", + content: "As soon as you stepped off the road, darkness consumed you. You tripped, fell to the ground, and a hoard of zombie deer proceeded to gobble you up.") +page_three = Page.create(conclusion: true, + preview: "Walk down the road", + outcome: "You found the circle of life (can be traded at Trapper's Den for 2 gold pieces)!", + content: "Apparently, after receiving it from his father, Simba dropped the circle of life while chasing a zombie deer.") +page_six = Page.create(option_a_id: page_two.id, + option_b_id: page_three.id, + preview: "Take a moment and taste the bacon fat in your mouth", + outcome: "Your spirits are lifted and you are ready to take on the world!", + content: "Armed with the power to take on the known world, you set forth.") +page_four = Page.create(option_a_id: page_six.id, + option_b_id: page_two.id, + preview: "Admire the 30 gold pieces", + outcome: "You were ransacked and robbed by a hoard of geriatric orcs!", + content: "They came at you slow, but because you were sucked into the glow of the gold you didn't notice 3 old orcs guided by walkers(with the little tennis balls on the fronts). You eat the bacon sandwich.") +page_five = Page.create(option_a_id: page_two.id, + option_b_id: page_six.id, + preview: "Eat the bacon sandwich", + outcome: "Your belly is happy and your mind is clear.", + content: "Obviously the only choice. Now that you've chosen wiser than Indiana Jones and the Quest For the Holy Grail, you are left with only the best decisions.") +page = Page.create(starting_point: true, + option_a_id: page_four.id, + option_b_id: page_five.id, + content: "You wake up on a road. It's foggy and damp. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?") diff --git a/db/setup.rb b/db/setup.rb new file mode 100644 index 0000000..0e80690 --- /dev/null +++ b/db/setup.rb @@ -0,0 +1,15 @@ +require 'pg' +require 'active_record' +require 'yaml' + +connection_details = YAML::load(File.open('config/database.yml')) + +# Setup out connection details +ActiveRecord::Base.establish_connection(connection_details.merge({'database'=> 'postgres', 'schema_search_path'=> 'public'})) +# create the 'tv' database +ActiveRecord::Base.connection.drop_database (connection_details.fetch('database')) rescue nil +ActiveRecord::Base.connection.create_database(connection_details.fetch('database')) rescue nil +# connect to it +ActiveRecord::Base.establish_connection(connection_details) +# Migrate all the things +ActiveRecord::Migrator.migrate("db/migrate/") diff --git a/models/book.rb b/models/book.rb new file mode 100644 index 0000000..3c14935 --- /dev/null +++ b/models/book.rb @@ -0,0 +1,21 @@ +class Book + + attr_reader :current_page + + def initialize(starting_page) + @current_page = starting_page + end + + def input(input_string) + if input_string.chomp == "A" + @current_page = current_page.options.first + elsif input_string.chomp == "B" + @current_page = current_page.options.last + end + end + + def complete_game? + current_page.conclusion? + end + +end diff --git a/models/page.rb b/models/page.rb new file mode 100644 index 0000000..6ce2772 --- /dev/null +++ b/models/page.rb @@ -0,0 +1,11 @@ +class Page < ActiveRecord::Base + + def self.starting_point + Page.where(starting_point: true).first + end + + def options + Page.find(option_a_id, option_b_id) + end + +end diff --git a/spec/.gitkeep b/spec/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/book_spec.rb b/spec/book_spec.rb new file mode 100644 index 0000000..ad0a4b7 --- /dev/null +++ b/spec/book_spec.rb @@ -0,0 +1,34 @@ +require_relative "spec_helper" + +describe Book do + let!(:option_a) { Page.create } + let!(:option_b) { Page.create } + let!(:page) {Page.create(starting_point: true, + option_a_id: option_a.id, + option_b_id: option_b.id)} + subject { Book.new(page) } + + it "should have a page" do + subject.current_page.should eq(page) + end + + describe "#input" do + it "should receive input and opens page" do + subject.input("A") + subject.current_page.should eq(option_a) + end + it "should receive input and opens page" do + subject.input("B") + subject.current_page.should eq(option_b) + end + + end + + describe "#complete_game?" do + + it "should know when it's done" do + subject.stub(:current_page) { stub(:conclusion? => true)} + subject.complete_game?.should be_true + end + end +end diff --git a/spec/page_spec.rb b/spec/page_spec.rb new file mode 100644 index 0000000..6af65f5 --- /dev/null +++ b/spec/page_spec.rb @@ -0,0 +1,52 @@ +require_relative "spec_helper" + +describe Page do + + before(:each) do + Page.delete_all + end + + it "should know if it's at the end of the road" do + page = Page.create(conclusion: true) + page.conclusion?.should be_true + end + + it "should have awesome content" do + page = Page.create(content: "The fox and hound get along") + Page.find(page.id).content.should eq("The fox and hound get along") + end + + it "should have a preview" do + page = Page.create(preview: "Walk down the road") + page.preview.should eq("Walk down the road") + end + + it "should be clear about being a winner or a loser" do + page = Page.create(outcome: "You be dead!") + page.outcome.should eq("You be dead!") + end + + context "#options" do + let(:option_a) { Page.create } + let(:option_b) { Page.create } + subject {Page.create(option_a_id: option_a.id, option_b_id: option_b.id )} + + it "should have options for the next pages" do + subject.options.should eq([option_a, option_b]) + end + end + + it "should not be a starting point by default" do + Page.create.starting_point.should eq(false) + end + it "should not be a conclusion by default" do + Page.create.conclusion.should eq(false) + end + + + it "should have a starting point" do + the_page = Page.create(starting_point: true) + Page.starting_point.should eq(the_page) + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..bdb95b8 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,5 @@ +require "rspec" +require 'bundler/setup' +require_relative '../db/setup' +require_relative "../models/page" +require_relative "../models/book" diff --git a/theweb.rb b/theweb.rb index 1665acf..33f2854 100644 --- a/theweb.rb +++ b/theweb.rb @@ -15,13 +15,14 @@ end get '/' do - my_picks ||= Picks.new.get_picks + my_picks ||= Picks.get_picks @featured_pick = my_picks.sample erb :about end class Picks - def get_picks + @@picks = [] + def self.get_picks YAML.load(File.read("./my_picks.yml")) end end From 242128ff564510cbf547f5f92f279e5ceaef3fcf Mon Sep 17 00:00:00 2001 From: jason perez Date: Wed, 29 Jan 2014 22:47:40 -0800 Subject: [PATCH 8/8] add adventure game --- theweb.rb | 45 ++++++++++++++++++++++++++++++++++++ views/about.erb | 1 - views/adventure.erb | 15 ++++++++++++ views/adventure/complete.erb | 10 ++++++++ views/adventure/my_game.erb | 15 ++++++++++++ views/layout.erb | 8 +++---- views/number.erb | 6 +++++ 7 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 views/adventure.erb create mode 100644 views/adventure/complete.erb create mode 100644 views/adventure/my_game.erb diff --git a/theweb.rb b/theweb.rb index 33f2854..caea9a8 100644 --- a/theweb.rb +++ b/theweb.rb @@ -3,8 +3,17 @@ require 'sinatra' require 'sinatra/reloader' require 'yaml' + +require_relative 'db/setup' +require_relative 'models/page' +require_relative 'models/book' +require "./db/seed" enable :sessions +get '/number' do + erb :number +end + post '/number' do @number_of_randoms = session[:number_of_randoms] || 0 @number_of_randoms += 1 @@ -20,9 +29,45 @@ erb :about end +get '/adventure' do + @page = Page.starting_point + @book = Book.new(@page) + session[:book] = @book + erb :adventure +end + +get '/adventure/my_game' do + erb :"adventure/my_game" +end + +post '/adventure/my_game' do + selected_option = params.fetch('selected_option') + session[:book].input(selected_option) + if session[:book].complete_game? + erb :"adventure/complete" + else + redirect :"adventure/my_game" + end +end + +get '/adventure/complete' do + erb :"adventure/complete" +end + class Picks @@picks = [] def self.get_picks YAML.load(File.read("./my_picks.yml")) end end + + + + + + + + + + + diff --git a/views/about.erb b/views/about.erb index 524fbae..8ff33ff 100644 --- a/views/about.erb +++ b/views/about.erb @@ -39,5 +39,4 @@

-
diff --git a/views/adventure.erb b/views/adventure.erb new file mode 100644 index 0000000..ffab4cb --- /dev/null +++ b/views/adventure.erb @@ -0,0 +1,15 @@ +
+
+

Adventure Time!

+

<%= session[:book].current_page.content %>

+ +
+ + +
+
+
\ No newline at end of file diff --git a/views/adventure/complete.erb b/views/adventure/complete.erb new file mode 100644 index 0000000..915a8a4 --- /dev/null +++ b/views/adventure/complete.erb @@ -0,0 +1,10 @@ + +
+
+

<%= session[:book].current_page.outcome %>

+

<%= session[:book].current_page.content %>

+

+ Play Again +

+
+
\ No newline at end of file diff --git a/views/adventure/my_game.erb b/views/adventure/my_game.erb new file mode 100644 index 0000000..a881f2e --- /dev/null +++ b/views/adventure/my_game.erb @@ -0,0 +1,15 @@ +
+
+

<%= session[:book].current_page.outcome %>

+

<%= session[:book].current_page.content %>

+ +
+ + +
+
+
\ No newline at end of file diff --git a/views/layout.erb b/views/layout.erb index a4f55ba..bb1f2f0 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -4,7 +4,7 @@ - Bootstrap, from Twitter + Jason's Adventure Time! @@ -45,9 +45,9 @@ Randomizer diff --git a/views/number.erb b/views/number.erb index 1398cbc..6a451b7 100644 --- a/views/number.erb +++ b/views/number.erb @@ -2,3 +2,9 @@

The number is <%= @the_number %>

Number of Randoms: <%= @number_of_randoms %>

+ +
+ + + +