From e9b1d48f6cad9c2eca256fbeffc0a8565227ddca Mon Sep 17 00:00:00 2001 From: meltar Date: Sun, 31 Mar 2013 17:58:26 -0400 Subject: [PATCH 1/5] Panda level --- Gemfile.lock | 46 ++++++++++++++++++---------------- adventure.rb | 18 +++++++------ config/database.yml.sample | 6 ----- db/migrate/001_creates_page.rb | 1 + 4 files changed, 36 insertions(+), 35 deletions(-) delete mode 100644 config/database.yml.sample diff --git a/Gemfile.lock b/Gemfile.lock index 0facad0..1f2cb79 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,36 +1,38 @@ GEM remote: http://rubygems.org/ specs: - activemodel (3.2.3) - activesupport (= 3.2.3) + activemodel (3.2.13) + activesupport (= 3.2.13) builder (~> 3.0.0) - activerecord (3.2.3) - activemodel (= 3.2.3) - activesupport (= 3.2.3) + activerecord (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activesupport (3.2.3) - i18n (~> 0.6) + activesupport (3.2.13) + i18n (= 0.6.1) multi_json (~> 1.0) arel (3.0.2) - builder (3.0.0) - diff-lcs (1.1.3) - i18n (0.6.0) - multi_json (1.3.4) - pg (0.13.2) - rake (0.9.2.2) - rspec (2.10.0) - rspec-core (~> 2.10.0) - rspec-expectations (~> 2.10.0) - rspec-mocks (~> 2.10.0) - rspec-core (2.10.0) - rspec-expectations (2.10.0) - diff-lcs (~> 1.1.3) - rspec-mocks (2.10.1) - tzinfo (0.3.33) + builder (3.0.4) + diff-lcs (1.2.2) + i18n (0.6.1) + multi_json (1.7.2) + pg (0.15.0) + pg (0.15.0-x86-mingw32) + rake (10.0.4) + rspec (2.13.0) + rspec-core (~> 2.13.0) + rspec-expectations (~> 2.13.0) + rspec-mocks (~> 2.13.0) + rspec-core (2.13.1) + rspec-expectations (2.13.0) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.13.0) + tzinfo (0.3.37) PLATFORMS ruby + x86-mingw32 DEPENDENCIES activerecord diff --git a/adventure.rb b/adventure.rb index d65f616..29a6ca5 100644 --- a/adventure.rb +++ b/adventure.rb @@ -5,22 +5,28 @@ require_relative 'models/page' require_relative 'models/book' -page = Page.create(starting_point: true, content: "You wake up on a road. It's foggy and dampy. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?") -Page.create(conclusion: true, parent_id: page.id, content: "Go into the forest") -Page.create(conclusion: true, parent_id: page.id, content: "Walk down the road") +page = Page.create(starting_point: true, preview: "Welcome, adventurer.", + content: "You wake up on a road. It's foggy and dampy. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?") +Page.create(conclusion: true, parent_id: page.id, preview: "Go into the forest", + content: "You are attacked by a hungry bear who wants your sandwich. You lose.") +Page.create(conclusion: true, parent_id: page.id, preview: "Walk down the road", + content: "You made it back to the inn safely. You win 100 gold pieces!!") book = Book.new(page) until book.complete_game? do puts book.current_page.content puts "your options: " - puts " - [#{book.current_page.options.first.content}]" - puts " - [#{book.current_page.options.last.content}]" + puts " - [#{book.current_page.options.first.preview}]" + puts " - [#{book.current_page.options.last.preview}]" puts "What do you want to do? Enter A or B" book.input( gets ) end +puts book.current_page.content + +puts book.current_page.conclusion puts "------------------------------------------" puts "| |" puts "| |" @@ -30,6 +36,4 @@ puts "------------------------------------------" -puts book.current_page.content - puts "hope you won!" diff --git a/config/database.yml.sample b/config/database.yml.sample deleted file mode 100644 index 2e5c2a9..0000000 --- a/config/database.yml.sample +++ /dev/null @@ -1,6 +0,0 @@ -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 index 8a293c0..9826e24 100644 --- a/db/migrate/001_creates_page.rb +++ b/db/migrate/001_creates_page.rb @@ -2,6 +2,7 @@ class CreatesPage < ActiveRecord::Migration def change create_table :pages do |t| t.text :content + t.text :preview t.integer :parent_id t.boolean :starting_point, default: false t.boolean :conclusion, default: false From 11c1395ed0adf9162448e04a4587bbe87b5bacf3 Mon Sep 17 00:00:00 2001 From: meltar Date: Thu, 4 Apr 2013 19:58:07 -0400 Subject: [PATCH 2/5] tiger --- adventure.rb | 13 +++---------- db/seed.rb | 8 +++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/adventure.rb b/adventure.rb index 29a6ca5..b6a34fb 100644 --- a/adventure.rb +++ b/adventure.rb @@ -4,15 +4,9 @@ require_relative 'db/setup' require_relative 'models/page' require_relative 'models/book' +require "./db/seed" -page = Page.create(starting_point: true, preview: "Welcome, adventurer.", - content: "You wake up on a road. It's foggy and dampy. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?") -Page.create(conclusion: true, parent_id: page.id, preview: "Go into the forest", - content: "You are attacked by a hungry bear who wants your sandwich. You lose.") -Page.create(conclusion: true, parent_id: page.id, preview: "Walk down the road", - content: "You made it back to the inn safely. You win 100 gold pieces!!") - -book = Book.new(page) +book = Book.new(Page.starting_point) until book.complete_game? do puts book.current_page.content @@ -21,12 +15,11 @@ puts " - [#{book.current_page.options.last.preview}]" puts "What do you want to do? Enter A or B" - book.input( gets ) + book.input( gets.chomp().capitalize ) end puts book.current_page.content -puts book.current_page.conclusion puts "------------------------------------------" puts "| |" puts "| |" diff --git a/db/seed.rb b/db/seed.rb index 1abe902..3950260 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1 +1,7 @@ -# Cleaning Out +Page.delete_all +start = Page.create(starting_point: true, preview: "Welcome, adventurer.", + content: "You wake up on a road. It's foggy and dampy. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?") +Page.create(conclusion: true, parent_id: start.id, preview: "Sit down to eat your sandwich", + content: "You are attacked by a hungry bear who smells bacon. You lose.") +Page.create(conclusion: true, parent_id: start.id, preview: "Keep walking", + content: "You made it back to the inn safely. You win 100 gold pieces!!") \ No newline at end of file From 48ed4445655b01e02da44820f90fb556fe2e8f3a Mon Sep 17 00:00:00 2001 From: meltar Date: Thu, 4 Apr 2013 20:04:25 -0400 Subject: [PATCH 3/5] added more pages --- db/seed.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/db/seed.rb b/db/seed.rb index 3950260..b2240b3 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,7 +1,15 @@ Page.delete_all start = Page.create(starting_point: true, preview: "Welcome, adventurer.", content: "You wake up on a road. It's foggy and dampy. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?") -Page.create(conclusion: true, parent_id: start.id, preview: "Sit down to eat your sandwich", +forest = Page.create(parent_id: start.id, preview: "Go into the forest", + content: "You see a campfire in the distance.") +road = Page.create(parent_id: start.id, preview: "Walk down the road", + content: "You are hungry.") +woods = Page.create(conclusion: true, parent_id: forest.id, preview: "Explore the woods", content: "You are attacked by a hungry bear who smells bacon. You lose.") -Page.create(conclusion: true, parent_id: start.id, preview: "Keep walking", +campfire = Page.create(conclusion: true, parent_id: forest.id, preview: "Approach the campfire", + content: "Bandits steal your bag. You lose everything!!.") +sit = Page.create(conclusion: true, parent_id: road.id, preview: "Sit down to eat your sandwich", + content: "You are attacked by a hungry bear who smells bacon. You lose.") +walk = Page.create(conclusion: true, parent_id: road.id, preview: "Keep walking", content: "You made it back to the inn safely. You win 100 gold pieces!!") \ No newline at end of file From c9590d3f6f9985eb3eddcb164d15c547278561ca Mon Sep 17 00:00:00 2001 From: meltar Date: Thu, 4 Apr 2013 22:22:54 -0400 Subject: [PATCH 4/5] added test for preview --- adventure.rb | 6 +++--- db/migrate/001_creates_page.rb | 2 ++ db/setup.rb | 2 +- spec/page_spec.rb | 5 +++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/adventure.rb b/adventure.rb index b6a34fb..cac320b 100644 --- a/adventure.rb +++ b/adventure.rb @@ -10,12 +10,12 @@ until book.complete_game? do puts book.current_page.content - puts "your options: " + puts "Your options: " puts " - [#{book.current_page.options.first.preview}]" puts " - [#{book.current_page.options.last.preview}]" puts "What do you want to do? Enter A or B" - book.input( gets.chomp().capitalize ) + book.input(gets.chomp().capitalize) end puts book.current_page.content @@ -29,4 +29,4 @@ puts "------------------------------------------" -puts "hope you won!" +puts "Hope you won!" diff --git a/db/migrate/001_creates_page.rb b/db/migrate/001_creates_page.rb index 9826e24..0f3b6bd 100644 --- a/db/migrate/001_creates_page.rb +++ b/db/migrate/001_creates_page.rb @@ -4,6 +4,8 @@ def change t.text :content t.text :preview t.integer :parent_id + t.integer :option_a_id + t.integer :option_b_id t.boolean :starting_point, default: false t.boolean :conclusion, default: false end diff --git a/db/setup.rb b/db/setup.rb index 0e80690..1cbf7ce 100644 --- a/db/setup.rb +++ b/db/setup.rb @@ -12,4 +12,4 @@ # connect to it ActiveRecord::Base.establish_connection(connection_details) # Migrate all the things -ActiveRecord::Migrator.migrate("db/migrate/") +ActiveRecord::Migrator.migrate("db/migrate/") \ No newline at end of file diff --git a/spec/page_spec.rb b/spec/page_spec.rb index 5951cdd..8e389b0 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -16,6 +16,11 @@ Page.find(page.id).content.should eq("The fox and hound get along") end + it "should have a preview" do + page = Page.create(preview: "Awesome preview") + Page.find(page.id).preview.should eq("Awesome preview") + end + context "#options" do subject {Page.create} let(:option_a) {Page.create(parent_id: subject.id) } From 3b2b65f0c305ba6ef389a10d1db61d9ff458775d Mon Sep 17 00:00:00 2001 From: meltar Date: Sat, 6 Apr 2013 17:49:49 -0400 Subject: [PATCH 5/5] Eagle complete --- db/seed.rb | 30 ++++++++++++++++++------------ models/page.rb | 4 +++- spec/book_spec.rb | 7 ++++--- spec/page_spec.rb | 8 ++++---- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/db/seed.rb b/db/seed.rb index b2240b3..39d2708 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,15 +1,21 @@ Page.delete_all -start = Page.create(starting_point: true, preview: "Welcome, adventurer.", - content: "You wake up on a road. It's foggy and dampy. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?") -forest = Page.create(parent_id: start.id, preview: "Go into the forest", + +#woods = Page.create(conclusion: true, preview: "Explore the woods", +# content: "You are attacked by a hungry bear who smells bacon. You lose.") +campfire = Page.create(conclusion: true, preview: "Approach the campfire", + content: "Bandits steal your bag. You lose everything!!") +sit = Page.create(conclusion: true, preview: "Sit down to eat your sandwich", + content: "You are attacked by a hungry bear who smells bacon. You lose.") +walk = Page.create(conclusion: true, preview: "Keep walking", + content: "You made it back to the inn safely. You win 100 gold pieces!!") + +forest = Page.create(option_a_id: sit.id, option_b_id: campfire.id, + preview: "Go into the forest", content: "You see a campfire in the distance.") -road = Page.create(parent_id: start.id, preview: "Walk down the road", +road = Page.create(option_a_id: sit.id, option_b_id: walk.id, + preview: "Walk down the road", content: "You are hungry.") -woods = Page.create(conclusion: true, parent_id: forest.id, preview: "Explore the woods", - content: "You are attacked by a hungry bear who smells bacon. You lose.") -campfire = Page.create(conclusion: true, parent_id: forest.id, preview: "Approach the campfire", - content: "Bandits steal your bag. You lose everything!!.") -sit = Page.create(conclusion: true, parent_id: road.id, preview: "Sit down to eat your sandwich", - content: "You are attacked by a hungry bear who smells bacon. You lose.") -walk = Page.create(conclusion: true, parent_id: road.id, preview: "Keep walking", - content: "You made it back to the inn safely. You win 100 gold pieces!!") \ No newline at end of file + +start = Page.create(starting_point: true, option_a_id: forest.id, option_b_id: road.id, + preview: "Welcome, adventurer.", + content: "You wake up on a road. It's foggy and dampy. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?") diff --git a/models/page.rb b/models/page.rb index 2b88343..dccb93a 100644 --- a/models/page.rb +++ b/models/page.rb @@ -5,7 +5,9 @@ def self.starting_point end def options - Page.where(:parent_id => id).limit(2) + #Page.where(:parent_id => id).limit(2) + #[ Page.where(:id => option_a_id).limit(1), Page.where(:id => option_b_id).limit(1)] + Page.find(option_a_id, option_b_id) end end diff --git a/spec/book_spec.rb b/spec/book_spec.rb index b429112..2152929 100644 --- a/spec/book_spec.rb +++ b/spec/book_spec.rb @@ -1,7 +1,10 @@ require_relative "spec_helper" describe Book do - let!(:page) {Page.create(starting_point: true)} + 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 @@ -9,8 +12,6 @@ end describe "#input" do - let!(:option_a) { Page.create(parent_id: page.id)} - let!(:option_b) { Page.create(parent_id: page.id)} it "should receive input and opens page" do subject.input("A") diff --git a/spec/page_spec.rb b/spec/page_spec.rb index 8e389b0..d89f268 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -22,10 +22,10 @@ end context "#options" do - subject {Page.create} - let(:option_a) {Page.create(parent_id: subject.id) } - let(:option_b) {Page.create(parent_id: subject.id) } - let(:option_c) {Page.create(parent_id: subject.id) } + let(:option_a) {Page.create(preview: "Preview for option_a")} + let(:option_b) {Page.create(preview: "Preview for option_b") } + let(:option_c) {Page.create(preview: "Preview for option_c") } + 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])