This repository has been archived by the owner on May 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
HW 3 Babych Svitlana #19
Open
SvitlanaLana
wants to merge
9
commits into
denysxftr:master
Choose a base branch
from
SvitlanaLana:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+647
−13
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
24a13e6
Final
SvitlanaLana 691d227
Merge remote-tracking branch 'upstream/master'
SvitlanaLana 9c1155e
Add router
SvitlanaLana 7b19597
change method each
SvitlanaLana 3283722
Merge remote-tracking branch 'upstream/master'
SvitlanaLana 7a82bb6
homework 3
SvitlanaLana 6796b80
add tests
SvitlanaLana 08aa134
Homework 4
SvitlanaLana cb6a99e
Create README.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Homework 4 | ||
|
||
- Travis CI for gem: https://travis-ci.org/SvitlanaLana/web_config . | ||
|
||
- Travis CI for app: https://travis-ci.org/SvitlanaLana/kottans_homework4 . | ||
|
||
- Deployed app: https://aqueous-atoll-31147.herokuapp.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Fibonacci | ||
include Enumerable | ||
|
||
def initialize(number) | ||
validate(number) | ||
@n = number | ||
end | ||
|
||
def each(&block) | ||
curr = 1 | ||
prev = 0 | ||
(1..@n).each do |i| | ||
block.call(curr) | ||
curr, prev = prev + curr, curr | ||
end | ||
end | ||
|
||
def validate(number) | ||
raise ArgumentError unless number.is_a?(Integer) && number >=0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,7 @@ source "https://rubygems.org" | |
|
||
gem "rack" | ||
gem "rspec" | ||
|
||
group 'test' do | ||
gem 'pry' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
Application = Router.new do | ||
get '/test', ->(env) { [200, {}, ['get test']] } | ||
post '/test', ->(env) { [200, {}, ['post test']] } | ||
|
||
get '/posts/:id/edit', ->(env) do | ||
[200, {}, ["Post #{env['PARAMS'][:id]}"]] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,49 @@ | ||
require 'spec_helper' | ||
require 'pry' | ||
|
||
RSpec.describe Router do | ||
subject do | ||
Router.new do | ||
get '/test', ->(env) { [200, {}, ['get test']] } | ||
post '/test', ->(env) { [200, {}, ['post test']] } | ||
|
||
## | ||
# TODO: router should match path by pattern like | ||
# Pattern: /posts/:name | ||
# Paths: | ||
# /post/about_ruby | ||
# /post/43 | ||
# Cover this with tests. | ||
# | ||
get '/post/:name', ->(env) { [200, {}, ['post show page']] } | ||
get '/post/:name/edit/:field', ->(env) { [200, {}, ['url include argument'] ] } | ||
end | ||
end | ||
|
||
let(:env) { { 'REQUEST_METHOD' => 'GET'} } | ||
|
||
it 'url have argument' do | ||
env['REQUEST_PATH'] = '/test' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can move this to |
||
subject.call(env) | ||
expect(env.keys).to include('PARAMS') | ||
end | ||
|
||
context 'when request is GET' do | ||
let(:env) { { 'REQUEST_PATH' => '/test', 'REQUEST_METHOD' => 'GET'} } | ||
let(:env) { { 'REQUEST_METHOD' => 'GET'} } | ||
|
||
it 'matches request' do | ||
env['REQUEST_PATH'] = '/test' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this |
||
expect(subject.call(env)).to eq [200, {}, ['get test']] | ||
end | ||
|
||
context 'and have url arguments' do | ||
before { env['REQUEST_PATH'] = '/post/vasya/edit/12' } | ||
|
||
it 'matches url', focue: true do | ||
expect(subject.call(env)).to eq [200, {}, ['url include argument']] | ||
end | ||
|
||
it 'add arguments from url' do | ||
subject.call(env) | ||
expect(env['PARAMS'][:name]).to eq 'vasya' | ||
expect(env['PARAMS'][:field]).to eq '12' | ||
end | ||
|
||
it '404' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here you can have a separate context for |
||
env['REQUEST_PATH'] = '/post/vasya/edit/12/qwe' | ||
expect(subject.call(env)).to eq [404, {}, ['Page not found']] | ||
end | ||
end | ||
end | ||
|
||
context 'when request is POST' do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: ruby | ||
rvm: | ||
- 2.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
source "https://rubygems.org" | ||
|
||
gem "rack" | ||
gem "rspec" | ||
|
||
gem "web_config", path: '../web_config' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
PATH | ||
remote: ../web_config | ||
specs: | ||
web_config (0.1.0) | ||
oj | ||
rack | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.2.5) | ||
oj (2.17.5) | ||
rack (2.0.1) | ||
rspec (3.5.0) | ||
rspec-core (~> 3.5.0) | ||
rspec-expectations (~> 3.5.0) | ||
rspec-mocks (~> 3.5.0) | ||
rspec-core (3.5.4) | ||
rspec-support (~> 3.5.0) | ||
rspec-expectations (3.5.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.5.0) | ||
rspec-mocks (3.5.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.5.0) | ||
rspec-support (3.5.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
rack | ||
rspec | ||
web_config! | ||
|
||
BUNDLED WITH | ||
1.13.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'rack' | ||
require 'web_config' | ||
require 'oj' | ||
|
||
class UsersController < WebConfig::Controller | ||
def show | ||
response(:json, "Hello, #{params['user']}") | ||
end | ||
end | ||
|
||
class BlogsController < WebConfig::Controller | ||
def new | ||
response(:html, 'view/example.html') | ||
end | ||
end | ||
|
||
class WelcomesController < WebConfig::Controller | ||
def show | ||
response(:text, "Request method: #{request.request_method}") | ||
end | ||
end | ||
|
||
Application = WebConfig::Router.new do | ||
get '/example/:user', 'users#show' | ||
get '/example/:user/:blog', 'blogs#new' | ||
get '/example', 'welcomes#show' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require './main' | ||
|
||
run Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require './app/app' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h1>My first Blog</h1> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/Gemfile.lock | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--format documentation | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sudo: false | ||
language: ruby | ||
rvm: | ||
- 2.3.0 | ||
before_install: gem install bundler -v 1.13.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as | ||
contributors and maintainers pledge to making participation in our project and | ||
our community a harassment-free experience for everyone, regardless of age, body | ||
size, disability, ethnicity, gender identity and expression, level of experience, | ||
nationality, personal appearance, race, religion, or sexual identity and | ||
orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment | ||
include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable | ||
behavior and are expected to take appropriate and fair corrective action in | ||
response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, wiki edits, issues, and other contributions | ||
that are not aligned to this Code of Conduct, or to ban temporarily or | ||
permanently any contributor for other behaviors that they deem inappropriate, | ||
threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces | ||
when an individual is representing the project or its community. Examples of | ||
representing a project or community include using an official project e-mail | ||
address, posting via an official social media account, or acting as an appointed | ||
representative at an online or offline event. Representation of a project may be | ||
further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by contacting the project team at [email protected]. All | ||
complaints will be reviewed and investigated and will result in a response that | ||
is deemed necessary and appropriate to the circumstances. The project team is | ||
obligated to maintain confidentiality with regard to the reporter of an incident. | ||
Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good | ||
faith may face temporary or permanent repercussions as determined by other | ||
members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||
available at [http://contributor-covenant.org/version/1/4][version] | ||
|
||
[homepage]: http://contributor-covenant.org | ||
[version]: http://contributor-covenant.org/version/1/4/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in web_config.gemspec | ||
gem "rack" | ||
gem "rspec" | ||
gem 'oj' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in web_config.gemspec | ||
gemspec |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use
lambda ||= ->(env) { [404, {}, ['Page not found']] }