Skip to content

Commit 3dbc0bf

Browse files
committed
Added api/v1 path in request. routing
1 parent e323b89 commit 3dbc0bf

16 files changed

+142
-142
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: spec/routing/api/v1/authentication_routing_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Api::V1::AuthenticationController, type: :routing do
4+
describe "routing" do
5+
it "routes to #login" do
6+
expect(:post => "/api/v1/auth/login").to route_to("api/v1/authentication#login")
7+
end
8+
end
9+
end

Diff for: spec/routing/api/v1/categories_routing_spec.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Api::V1::CategoriesController, type: :routing do
4+
describe "routing" do
5+
it "routes to #index" do
6+
expect(:get => "/api/v1/categories").to route_to("api/v1/categories#index")
7+
end
8+
9+
it "routes to #show" do
10+
expect(:get => "/api/v1/categories/1").to route_to("api/v1/categories#show", :id => "1")
11+
end
12+
13+
14+
it "routes to #create" do
15+
expect(:post => "/api/v1/categories").to route_to("api/v1/categories#create")
16+
end
17+
18+
it "routes to #update via put" do
19+
expect(:put => "/api/v1/categories/1").to route_to("api/v1/categories#update", :id => "1")
20+
end
21+
22+
it "routes to #update via patch" do
23+
expect(:patch => "/api/v1/categories/1").to route_to("api/v1/categories#update", :id => "1")
24+
end
25+
26+
it "routes to #destroy" do
27+
expect(:delete => "/api/v1/categories/1").to route_to("api/v1/categories#destroy", :id => "1")
28+
end
29+
end
30+
end

Diff for: spec/routing/api/v1/comments_routing_spec.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Api::V1::CommentsController, type: :routing do
4+
describe "routing" do
5+
it "routes to #index" do
6+
expect(:get => "/api/v1/comments").to route_to("api/v1/comments#index")
7+
end
8+
9+
it "routes to #show" do
10+
expect(:get => "/api/v1/comments/1").to route_to("api/v1/comments#show", :id => "1")
11+
end
12+
13+
14+
it "routes to #create" do
15+
expect(:post => "/api/v1/comments").to route_to("api/v1/comments#create")
16+
end
17+
18+
it "routes to #update via PUT" do
19+
expect(:put => "/api/v1/comments/1").to route_to("api/v1/comments#update", :id => "1")
20+
end
21+
22+
it "routes to #update via PATCH" do
23+
expect(:patch => "/api/v1/comments/1").to route_to("api/v1/comments#update", :id => "1")
24+
end
25+
26+
it "routes to #destroy" do
27+
expect(:delete => "/api/v1/comments/1").to route_to("api/v1/comments#destroy", :id => "1")
28+
end
29+
end
30+
end

Diff for: spec/routing/api/v1/posts_routing_spec.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Api::V1::PostsController, type: :routing do
4+
describe "routing" do
5+
it "routes to #index" do
6+
expect(:get => "/api/v1/posts").to route_to("api/v1/posts#index")
7+
end
8+
9+
it "routes to #show" do
10+
expect(:get => "/api/v1/posts/1").to route_to("api/v1/posts#show", :id => "1")
11+
end
12+
13+
14+
it "routes to #create" do
15+
expect(:post => "/api/v1/posts").to route_to("api/v1/posts#create")
16+
end
17+
18+
it "routes to #update via PUT" do
19+
expect(:put => "/api/v1/posts/1").to route_to("api/v1/posts#update", :id => "1")
20+
end
21+
22+
it "routes to #update via PATCH" do
23+
expect(:patch => "/api/v1/posts/1").to route_to("api/v1/posts#update", :id => "1")
24+
end
25+
26+
it "routes to #destroy" do
27+
expect(:delete => "/api/v1/posts/1").to route_to("api/v1/posts#destroy", :id => "1")
28+
end
29+
end
30+
end

Diff for: spec/routing/api/v1/users_routing_spec.rb

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Api::V1::UsersController, type: :routing do
4+
5+
let(:user){
6+
create(:user)
7+
}
8+
# let(:user) {
9+
# create({user: {name: "aa", username:"aas", email: "[email protected]", password: "password123", password_confirmation: "password123"}})
10+
# }
11+
12+
describe "routing" do
13+
it "routes to #index" do
14+
expect(:get => "/api/v1/users").to route_to("api/v1/users#index")
15+
end
16+
17+
it "routes to #show" do
18+
expect(:get => "/api/v1/users/#{user.username}").to route_to("api/v1/users#show", :_username => user.username)
19+
end
20+
21+
it "routes to #create" do
22+
expect(:post => "/api/v1/users").to route_to("api/v1/users#create")
23+
end
24+
25+
it "routes to #update via PUT" do
26+
expect(:put => "/api/v1/users/#{user.username}").to route_to("api/v1/users#update", :_username => user.username)
27+
end
28+
29+
it "routes to #update via PATCH" do
30+
expect(:patch => "/api/v1/users/#{user.username}").to route_to("api/v1/users#update", :_username => user.username)
31+
end
32+
33+
it "routes to #destroy" do
34+
expect(:delete => "/api/v1/users/#{user.username}").to route_to("api/v1/users#destroy", :_username => user.username)
35+
end
36+
end
37+
end

Diff for: spec/routing/authentication_routing_spec.rb

-9
This file was deleted.

Diff for: spec/routing/categories_routing_spec.rb

-30
This file was deleted.

Diff for: spec/routing/comments_routing_spec.rb

-30
This file was deleted.

Diff for: spec/routing/posts_routing_spec.rb

-30
This file was deleted.

Diff for: spec/routing/users_routing_spec.rb

-37
This file was deleted.

Diff for: unit_testing_with_rspec.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,28 @@
110110
RSpec.describe PostsController, type: :routing do
111111
describe "routing" do
112112
it "routes to #index" do
113-
expect(:get => "/posts").to route_to("posts#index")
113+
expect(:get => "/api/v1/posts").to route_to("api/v1/posts#index")
114114
end
115115
116116
it "routes to #show" do
117-
expect(:get => "/posts/1").to route_to("posts#show", :id => "1")
117+
expect(:get => "/api/v1/posts/1").to route_to("api/v1/posts#show", :id => "1")
118118
end
119119
120120
121121
it "routes to #create" do
122-
expect(:post => "/posts").to route_to("posts#create")
122+
expect(:post => "/api/v1/posts").to route_to("api/v1/posts#create")
123123
end
124124
125125
it "routes to #update via PUT" do
126-
expect(:put => "/posts/1").to route_to("posts#update", :id => "1")
126+
expect(:put => "/api/v1/posts/1").to route_to("api/v1/posts#update", :id => "1")
127127
end
128128
129129
it "routes to #update via PATCH" do
130-
expect(:patch => "/posts/1").to route_to("posts#update", :id => "1")
130+
expect(:patch => "/api/v1/posts/1").to route_to("api/v1/posts#update", :id => "1")
131131
end
132132
133133
it "routes to #destroy" do
134-
expect(:delete => "/posts/1").to route_to("posts#destroy", :id => "1")
134+
expect(:delete => "/api/v1/posts/1").to route_to("api/v1/posts#destroy", :id => "1")
135135
end
136136
end
137137
end

0 commit comments

Comments
 (0)