rutter 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.rubocop.yml +14 -4
- data/.travis.yml +12 -2
- data/Gemfile +4 -1
- data/LICENSE.txt +1 -1
- data/README.md +17 -102
- data/Rakefile +7 -1
- data/bench/config.ru +10 -9
- data/lib/rutter.rb +10 -7
- data/lib/rutter/builder.rb +180 -221
- data/lib/rutter/mount.rb +21 -0
- data/lib/rutter/naming.rb +95 -0
- data/lib/rutter/route.rb +69 -126
- data/lib/rutter/routes.rb +36 -9
- data/lib/rutter/scope.rb +39 -40
- data/lib/rutter/verbs.rb +8 -0
- data/lib/rutter/version.rb +1 -1
- data/rutter.gemspec +4 -3
- data/spec/integration/rack_spec.rb +21 -13
- data/spec/spec_helper.rb +6 -48
- data/spec/support/rack.rb +20 -0
- data/spec/unit/builder_spec.rb +86 -74
- data/spec/unit/namespace_spec.rb +26 -0
- data/spec/unit/route_spec.rb +33 -50
- data/spec/unit/routes_spec.rb +20 -11
- data/spec/unit/rutter_spec.rb +3 -2
- data/spec/unit/scope_spec.rb +49 -56
- metadata +25 -17
- data/bench/dynamic_routes +0 -20
- data/bench/expand +0 -19
- data/bench/helper.rb +0 -19
- data/bench/mount +0 -32
- data/bench/routes_helper +0 -24
- data/bench/static_routes +0 -20
- data/spec/integration/mount_spec.rb +0 -18
- data/spec/integration/params_spec.rb +0 -28
- data/spec/integration/redirect_spec.rb +0 -36
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "json"
|
4
|
-
require "spec_helper"
|
5
|
-
|
6
|
-
class TestController
|
7
|
-
def self.call(env)
|
8
|
-
hash = env["rutter.params"]
|
9
|
-
hash["action"] = env["rutter.action"]
|
10
|
-
[100, {}, [JSON.generate(hash)]]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
RSpec.describe "ramverk.router_params" do
|
15
|
-
let(:router) { Rutter.new(controller_suffix: "Controller") }
|
16
|
-
|
17
|
-
def app
|
18
|
-
router.freeze
|
19
|
-
end
|
20
|
-
|
21
|
-
it "calls the endpoint (controller)" do
|
22
|
-
router.get "/books/:title", to: "Test#index"
|
23
|
-
get "/books/eloquent-ruby"
|
24
|
-
expect(last_response.status).to eq(100)
|
25
|
-
expect(last_response.body)
|
26
|
-
.to eq('{"title":"eloquent-ruby","action":"index"}')
|
27
|
-
end
|
28
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
RSpec.describe "Rutter::Builder#redirect" do
|
6
|
-
let(:router) do
|
7
|
-
Rutter.new do
|
8
|
-
get "/legacy-path", to: redirect("/new_path")
|
9
|
-
get "/legacy-path-custom-status", to: redirect("/new_path", status: 301)
|
10
|
-
get "/new_path", to: ->(_env) { [200, {}, ["Redirected"]] }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def app
|
15
|
-
router.freeze
|
16
|
-
end
|
17
|
-
|
18
|
-
it "redirect the request to the new path" do
|
19
|
-
get "/legacy-path"
|
20
|
-
|
21
|
-
expect(last_response.status).to eq(302)
|
22
|
-
expect(last_response.body).to eq("")
|
23
|
-
|
24
|
-
follow_redirect!
|
25
|
-
|
26
|
-
expect(last_response.status).to eq(200)
|
27
|
-
expect(last_response.body).to eq("Redirected")
|
28
|
-
end
|
29
|
-
|
30
|
-
it "support setting custom status" do
|
31
|
-
get "/legacy-path-custom-status"
|
32
|
-
expect(last_response.status).to eq(301)
|
33
|
-
follow_redirect!
|
34
|
-
expect(last_response.status).to eq(200)
|
35
|
-
end
|
36
|
-
end
|