lunetas 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1,10 @@
1
+ require '../lib/lunetas'
2
+
3
+ class Redirect
4
+ include Lunetas::Candy
5
+ matches '/'
6
+
7
+ def get
8
+ redirect 'http://google.com'
9
+ end
10
+ end
@@ -26,6 +26,14 @@ module Lunetas::Candy::RequestWrapper
26
26
  @req.session
27
27
  end
28
28
 
29
+ # Redirects to some location.
30
+ # @param [String] target the location to redirect to.
31
+ # @param [Fixnum] status the redirect status.
32
+ # @return [nil]
33
+ def redirect(target, status = 302)
34
+ @lunetas_redirect = [status, {'Content-Type' => 'text/plain', 'Location' => target}, []]
35
+ end
36
+
29
37
  # Is lunetas running in development?
30
38
  # @return [true, false]
31
39
  def development?
@@ -60,7 +60,11 @@ module Lunetas::Candy::ResponseHandler
60
60
  # @param [Fixnum] code the response code.
61
61
  # @return [Array] a Rack::Request response.
62
62
  def response(object, code = 200)
63
- [code, {'Content-Type' => self.class.lunetas_content_type}, [object.to_s]]
63
+ if @lunetas_redirect && @lunetas_redirect.is_a?(Array)
64
+ @lunetas_redirect
65
+ else
66
+ [code, {'Content-Type' => self.class.lunetas_content_type}, [object.to_s]]
67
+ end
64
68
  end
65
69
  end
66
70
 
@@ -73,6 +73,14 @@ describe Lunetas::Candy do
73
73
  @instance.bite[1]["Content-Type"].should == "text/plain"
74
74
  end
75
75
 
76
+ it 'should be able to redirect' do
77
+ mock_env = mock_env('/just_a_test')
78
+ mock_env['REQUEST_METHOD'] = 'REDIRECT'
79
+ @instance = TestClass.new(mock_env, ['/just_a_test'])
80
+ @instance.bite[1].keys.should include('Location')
81
+ @instance.bite[1].values.should include('http://example.com')
82
+ end
83
+
76
84
  %w{post put delete head trace options}.each do |verb|
77
85
  it 'should call to the #{verb} method if called with #{verb.upcase}' do
78
86
  mock_env = mock_env('/just_a_test')
@@ -24,6 +24,11 @@ class TestClass
24
24
  def get
25
25
  'Chunky Bacon'
26
26
  end
27
+ def other_verb(verb)
28
+ if verb == 'REDIRECT'
29
+ redirect 'http://example.com'
30
+ end
31
+ end
27
32
  end
28
33
 
29
34
  class TestException < Lunetas::Error::BaseError
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lunetas
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Iv\xC3\xA1n Vald\xC3\xA9s (@ivanvc)"
@@ -94,6 +94,7 @@ files:
94
94
  - VERSION
95
95
  - examples/config.ru
96
96
  - examples/jay_son.rb
97
+ - examples/redirect.rb
97
98
  - examples/testing.rb
98
99
  - lib/lunetas.rb
99
100
  - lib/lunetas/bag.rb
@@ -146,4 +147,5 @@ test_files:
146
147
  - spec/lunetas/candy_spec.rb
147
148
  - spec/spec_helper.rb
148
149
  - examples/jay_son.rb
150
+ - examples/redirect.rb
149
151
  - examples/testing.rb