-
-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configuration of Cookies. #51
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
14f40de
Document support for Configuration#mapping.
gotjosh fce64dc
Allow configuration of Cookies.
gotjosh a49cd1c
Improve `Configuration#cookies` documentation.
gotjosh a8b61ee
Did not ship with 0.1.0.
gotjosh 56469e7
Proper describe naming for #cookies.
gotjosh 7da7370
`Configuration#cookies` integration tests and fixture.
gotjosh 0ebd337
Revert "Document support for Configuration#mapping."
gotjosh 90ce4c7
Homogenize cookie key.
gotjosh bf34344
Document support for cookies in the README.
gotjosh File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module CookiesApp | ||
class Application < Lotus::Application | ||
configure do | ||
# Activate Cookies | ||
cookies true | ||
|
||
routes do | ||
get '/get_cookies', to: 'cookies#get' | ||
get '/set_cookies', to: 'cookies#set' | ||
get '/set_cookies_with_options', to: 'cookies#set_with_options' | ||
get '/del_cookies', to: 'cookies#del' | ||
end | ||
end | ||
|
||
load! | ||
end | ||
|
||
|
||
module Controllers::Cookies | ||
include CookiesApp::Controller | ||
|
||
action 'Get' do | ||
def call(params) | ||
self.body = cookies[:foo] | ||
end | ||
end | ||
|
||
action 'Set' do | ||
def call(params) | ||
self.body = 'yummy!' | ||
cookies[:big_cookie] = 'nomnomnom!' | ||
end | ||
end | ||
|
||
action 'SetWithOptions' do | ||
def call(params) | ||
self.body = 'with options!' | ||
expire_date = Time.parse params[:expires] | ||
|
||
cookies[:with_options] = { | ||
value: 'nomnomnom!', | ||
domain: 'lotusrocks.com', | ||
path: '/controller', | ||
expires: expire_date, | ||
secure: true, | ||
httponly: true | ||
} | ||
end | ||
end | ||
|
||
action 'Del' do | ||
def call(params) | ||
self.body = 'deleted!' | ||
cookies[:delete] = nil | ||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'test_helper' | ||
require 'rack/test' | ||
require 'fixtures/cookies/application' | ||
|
||
describe 'Cookies' do | ||
include Rack::Test::Methods | ||
|
||
before do | ||
@current_dir = Dir.pwd | ||
Dir.chdir FIXTURES_ROOT.join('cookies') | ||
@app = CookiesApp::Application.new | ||
end | ||
|
||
after do | ||
Dir.chdir @current_dir | ||
@current_dir = nil | ||
end | ||
|
||
def app | ||
@app | ||
end | ||
|
||
def response | ||
last_response | ||
end | ||
|
||
def request | ||
last_request | ||
end | ||
|
||
it 'sucessfully gets cookies' do | ||
get '/get_cookies', nil, {'HTTP_COOKIE' => 'foo=bar'} | ||
|
||
request.cookies.must_equal({ 'foo' => 'bar' }) | ||
|
||
response.body.must_equal('bar') | ||
response.headers['Set-Cookie'].must_equal('foo=bar') | ||
end | ||
|
||
it 'succesfully sets cookies' do | ||
get '/set_cookies' | ||
|
||
response.body.must_equal('yummy!') | ||
response.headers['Set-Cookie'].must_equal('big_cookie=nomnomnom%21') | ||
end | ||
|
||
it 'sucessfully sets cookies with options' do | ||
next_week = Time.now + 60 * 60 * 24 * 7 | ||
get '/set_cookies_with_options', { expires: next_week } | ||
|
||
response.body.must_equal('with options!') | ||
response.headers['Set-Cookie'].must_equal("with_options=nomnomnom%21; domain=lotusrocks.com; path=/controller; expires=#{next_week.gmtime.rfc2822}; secure; HttpOnly") | ||
end | ||
|
||
it 'sucessfully deletes cookies' do | ||
get '/del_cookies', nil, {'HTTP_COOKIE' => 'foo=bar;delete=cookie'} | ||
|
||
request.cookies.must_equal({ 'foo' => 'bar', 'delete' => 'cookie' }) | ||
|
||
response.body.must_equal('deleted!') | ||
response.headers['Set-Cookie'].must_equal("foo=bar\ndelete=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000") | ||
end | ||
|
||
end |
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.
This is out of scope here, can you please remove it?