From 3037ff4f3a3cabed0a0caa194c6bc07420cb2435 Mon Sep 17 00:00:00 2001 From: Joe Burgess Date: Sat, 28 Nov 2015 17:15:24 -0500 Subject: [PATCH] Adding basics --- .learn | 6 ++++++ CONTRIBUTING.md | 37 +++++++++++++++++++++++++++++++++++++ Gemfile | 5 +++++ Gemfile.lock | 28 ++++++++++++++++++++++++++++ LICENSE.md | 7 +++++++ README.md | 11 +++++++++++ app/item.rb | 8 ++++++++ config.ru | 2 ++ config/environment.rb | 5 +++++ spec/dynamic_routes_spec.rb | 30 ++++++++++++++++++++++++++++++ spec/spec_helper.rb | 9 +++++++++ 11 files changed, 148 insertions(+) create mode 100644 .learn create mode 100644 CONTRIBUTING.md create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 app/item.rb create mode 100644 config.ru create mode 100644 config/environment.rb create mode 100644 spec/dynamic_routes_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.learn b/.learn new file mode 100644 index 000000000..0434998cc --- /dev/null +++ b/.learn @@ -0,0 +1,6 @@ +tags: + - http + - internet +languages: + - english +resources: 0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..9eef40f29 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,37 @@ +# Contributing to Learn.co Curriculum + +We're really exited that you're about to contribute to the [open curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co). If this is your first time contributing, please continue reading to learn how to make the most meaningful and useful impact possible. + +## Raising an Issue to Encourage a Contribution + +If you notice a problem with the curriculum that you believe needs improvement +but you're unable to make the change yourself, you should raise a Github issue +containing a clear description of the problem. Include relevant snippets of +the content and/or screenshots if applicable. Curriculum owners regularly review +issue lists and your issue will be prioritized and addressed as appropriate. + +## Submitting a Pull Request to Suggest an Improvement + +If you see an opportunity for improvement and can make the change yourself go +ahead and use a typical git workflow to make it happen: + +* Fork this curriculum repository +* Make the change on your fork, with descriptive commits in the standard format +* Open a Pull Request against this repo + +A curriculum owner will review your change and approve or comment on it in due +course. + +# Why Contribute? + +Curriculum on Learn is publicly and freely available under Learn's +[Educational Content License](https://learn.co/content-license). By +embracing an open-source contribution model, our goal is for the curriculum +on Learn to become, in time, the best educational content the world has +ever seen. + +We need help from the community of Learners to maintain and improve the +educational content. Everything from fixing typos, to correcting +out-dated information, to improving exposition, to adding better examples, +to fixing tests—all contributions to making the curriculum more effective are +welcome. \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..65300a9b1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + +gem 'rack' +gem 'rack-test' +gem 'rspec' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..f44c34299 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,28 @@ +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.2.5) + rack (1.6.4) + rack-test (0.6.3) + rack (>= 1.0) + rspec (3.3.0) + rspec-core (~> 3.3.0) + rspec-expectations (~> 3.3.0) + rspec-mocks (~> 3.3.0) + rspec-core (3.3.2) + rspec-support (~> 3.3.0) + rspec-expectations (3.3.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-mocks (3.3.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-support (3.3.0) + +PLATFORMS + ruby + +DEPENDENCIES + rack + rack-test + rspec diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 000000000..ad734faeb --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,7 @@ +#Learn.co Educational Content License + +Copyright (c) 2015 Flatiron School, Inc + +The Flatiron School, Inc. owns this Educational Content. However, the Flatiron School supports the development and availability of educational materials in the public domain. Therefore, the Flatiron School grants Users of the Flatiron Educational Content set forth in this repository certain rights to reuse, build upon and share such Educational Content subject to the terms of the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). You must read carefully the terms and conditions contained in the Educational Content License as such terms govern access to and use of the Educational Content. + +Flatiron School is willing to allow you access to and use of the Educational Content only on the condition that you accept all of the terms and conditions contained in the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). By accessing and/or using the Educational Content, you are agreeing to all of the terms and conditions contained in the Educational Content License. If you do not agree to any or all of the terms of the Educational Content License, you are prohibited from accessing, reviewing or using in any way the Educational Content. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 000000000..32cc69658 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Rack Routes and GET Params + +We've provided the code for a basic list of items. Now it's your turn to extend +it. + +## Instructions + + 1. Create a new class array called `@@cart` to hold any items in your cart + 2. Create a new route called `/cart` to show the items in your cart + 3. Create a new route called `/add` that takes in a `GET` param with the key `item`. This should check to see if that item is in `@@items` and then add it to the cart if it is. Otherwise give an error + diff --git a/app/item.rb b/app/item.rb new file mode 100644 index 000000000..f9107bf2f --- /dev/null +++ b/app/item.rb @@ -0,0 +1,8 @@ +class Item + attr_accessor :name, :price + + def initialize(name,price) + @name = name + @price = price + end +end diff --git a/config.ru b/config.ru new file mode 100644 index 000000000..777fdbdc6 --- /dev/null +++ b/config.ru @@ -0,0 +1,2 @@ +require_relative "./config/environment.rb" +run Application.new diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 000000000..b76605abc --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +require 'bundler/setup' +Bundler.require + +require_relative "../app/item.rb" +require_relative '../app/application' diff --git a/spec/dynamic_routes_spec.rb b/spec/dynamic_routes_spec.rb new file mode 100644 index 000000000..a671a4be4 --- /dev/null +++ b/spec/dynamic_routes_spec.rb @@ -0,0 +1,30 @@ +require_relative './spec_helper' + +describe "Shopping Cart Rack App" do + def app() + Application.new + end + + it 'Returns 404 for a bad route' do + get '/testing' + expect(last_response.body).to include("Route not found") + expect(last_response.status).to be(404) + end + describe "/items" do + + it 'Returns item price if it is in @@item' do + Application.class_variable_set(:@@items, [Item.new("Figs",3.42),Item.new("Pears",0.99)]) + get '/items/Figs' + expect(last_response.body).to include("3.42") + expect(last_response.status).to be(200) + end + + it 'Returns an error and 400 if the item is not there' do + Application.class_variable_set(:@@items, [Item.new("Figs",3.42),Item.new("Pears",0.99)]) + get '/items/Apples' + expect(last_response.body).to include("Item not found") + expect(last_response.status).to be(400) + end + + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 000000000..19a80b639 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,9 @@ +require_relative '../config/environment' +require 'rack/test' + +RSpec.configure do |config| + + config.include Rack::Test::Methods + + config.order = 'default' +end